mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-31 01:58:06 +03:00
Strictest / tests / minor improvements
This commit is contained in:
@@ -116,12 +116,19 @@ export default async function deposit({
|
||||
unsignedTx.nonce = nonce;
|
||||
|
||||
const signedTx = await signer.signTransaction(unsignedTx);
|
||||
const txResponse = await provider.sendTransaction(signedTx);
|
||||
console.log(`Deposit tx sent: ${txResponse.hash}. Waiting for confirmation...`);
|
||||
const txReceipt = await txResponse.wait();
|
||||
if (txReceipt.status !== undefined) {
|
||||
console.log('Deposit tx confirmed');
|
||||
} else {
|
||||
console.log('Deposit tx failed');
|
||||
try {
|
||||
const txResponse = await provider.sendTransaction(signedTx);
|
||||
console.log(`Deposit tx sent: ${txResponse.hash}. Waiting for confirmation...`);
|
||||
const txReceipt = await txResponse.wait();
|
||||
if (txReceipt.status !== undefined) {
|
||||
console.log('Deposit tx confirmed');
|
||||
} else {
|
||||
console.log('Deposit tx failed');
|
||||
}
|
||||
} catch (e) {
|
||||
if (!(e instanceof Error)) throw new Error('e is not an Error');
|
||||
console.error(`Deposit tx failed: ${e.message}`, {
|
||||
unsignedTx,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import BigNumber from 'bignumber.js';
|
||||
import { ethers } from 'ethers';
|
||||
import { NATIVE_CURRENCY_PRECISION, SWAP_THROUGH_ORION_POOL_GAS_LIMIT } from '../../constants';
|
||||
import { type OrionAggregator } from '../../services/OrionAggregator';
|
||||
import { type OrionBlockchain } from '../../services/OrionBlockchain';
|
||||
import type { OrionAggregator } from '../../services/OrionAggregator';
|
||||
import type { OrionBlockchain } from '../../services/OrionBlockchain';
|
||||
|
||||
import simpleFetch from '../../simpleFetch';
|
||||
import { calculateFeeInFeeAsset, denormalizeNumber, getNativeCryptocurrency } from '../../utils';
|
||||
|
||||
@@ -10,6 +10,8 @@ import getNativeCryptocurrency from '../../utils/getNativeCryptocurrency';
|
||||
import simpleFetch from '../../simpleFetch';
|
||||
import { calculateFeeInFeeAsset, denormalizeNumber, normalizeNumber } from '../../utils';
|
||||
import { signOrder } from '../../crypt';
|
||||
import type orderSchema from '../../services/OrionAggregator/schemas/orderSchema';
|
||||
import type { z } from 'zod';
|
||||
|
||||
export type SwapMarketParams = {
|
||||
type: 'exactSpend' | 'exactReceive'
|
||||
@@ -34,11 +36,13 @@ export type SwapMarketParams = {
|
||||
type AggregatorOrder = {
|
||||
through: 'aggregator'
|
||||
id: string
|
||||
wait: () => Promise<z.infer<typeof orderSchema>>
|
||||
}
|
||||
|
||||
type PoolSwap = {
|
||||
through: 'orion_pool'
|
||||
txHash: string
|
||||
wait: (confirmations?: number | undefined) => Promise<ethers.providers.TransactionReceipt>
|
||||
}
|
||||
|
||||
export type Swap = AggregatorOrder | PoolSwap;
|
||||
@@ -293,6 +297,7 @@ export default async function swapMarket({
|
||||
const swapThroughOrionPoolTxResponse = await signer.sendTransaction(unsignedSwapThroughOrionPoolTx);
|
||||
options?.logger?.(`Transaction sent. Tx hash: ${swapThroughOrionPoolTxResponse.hash}`);
|
||||
return {
|
||||
wait: swapThroughOrionPoolTxResponse.wait,
|
||||
through: 'orion_pool',
|
||||
txHash: swapThroughOrionPoolTxResponse.hash,
|
||||
};
|
||||
@@ -408,6 +413,26 @@ export default async function swapMarket({
|
||||
options?.logger?.(`Order placed. Order id: ${orderId}`);
|
||||
|
||||
return {
|
||||
wait: () => new Promise<z.infer<typeof orderSchema>>((resolve, reject) => {
|
||||
const timeout = setTimeout(() => {
|
||||
reject(new Error('Timeout'))
|
||||
}, 60000);
|
||||
const interval = setInterval(() => {
|
||||
simpleFetch(orionAggregator.getOrder)(orderId).then((data) => {
|
||||
if (data.order.status === 'SETTLED') {
|
||||
options?.logger?.(`Order ${orderId} settled`);
|
||||
clearTimeout(timeout);
|
||||
clearInterval(interval);
|
||||
resolve(data);
|
||||
} else {
|
||||
options?.logger?.(`Order ${orderId} status: ${data.order.status}`);
|
||||
}
|
||||
}).catch((e) => {
|
||||
if (!(e instanceof Error)) throw new Error('Not an error');
|
||||
options?.logger?.(`Error while getting order status: ${e.message}`);
|
||||
});
|
||||
}, 1000);
|
||||
}),
|
||||
through: 'aggregator',
|
||||
id: orderId,
|
||||
};
|
||||
|
||||
@@ -109,10 +109,17 @@ export default async function withdraw({
|
||||
const signedTx = await signer.signTransaction(unsignedTx);
|
||||
const txResponse = await provider.sendTransaction(signedTx);
|
||||
console.log(`Withdraw tx sent: ${txResponse.hash}. Waiting for confirmation...`);
|
||||
const txReceipt = await txResponse.wait();
|
||||
if (txReceipt.status !== undefined) {
|
||||
console.log('Withdraw tx confirmed');
|
||||
} else {
|
||||
console.log('Withdraw tx failed');
|
||||
try {
|
||||
const txReceipt = await txResponse.wait();
|
||||
if (txReceipt.status !== undefined) {
|
||||
console.log('Withdraw tx confirmed');
|
||||
} else {
|
||||
console.log('Withdraw tx failed');
|
||||
}
|
||||
} catch (e) {
|
||||
if (!(e instanceof Error)) throw new Error('e is not an Error');
|
||||
console.error(`Deposit tx failed: ${e.message}`, {
|
||||
unsignedTx,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user