Bump deps

This commit is contained in:
Aleksandr Kraiz
2023-02-17 19:21:21 +04:00
parent 2c24f71453
commit 151477d40e
4 changed files with 1105 additions and 973 deletions

View File

@@ -23,6 +23,7 @@ export type SwapMarketParams = {
signer: ethers.Signer
orionUnit: OrionUnit
options?: {
// rounding?: 'up' | 'down' TODO
poolOnly?: boolean
instantSettlement?: boolean
logger?: (message: string) => void
@@ -34,12 +35,14 @@ export type SwapMarketParams = {
}
type AggregatorOrder = {
amountOut: number
through: 'aggregator'
id: string
wait: () => Promise<z.infer<typeof orderSchema>>
}
type PoolSwap = {
amountOut: number
through: 'orion_pool'
txHash: string
wait: (confirmations?: number | undefined) => Promise<ethers.providers.TransactionReceipt>
@@ -165,7 +168,7 @@ export default async function swapMarket({
if (qtyPrecisionBN.lt(qtyDecimalPlaces)) {
throw new Error(
`Actual amount decimal places (${qtyDecimalPlaces}) is greater than max allowed decimal places (${qtyPrecisionBN.toString()}) on pair ${baseAssetName}-${quoteAssetName}`
`Actual amount decimal places (${qtyDecimalPlaces}) is greater than max allowed decimal places (${qtyPrecisionBN.toString()}) on pair ${baseAssetName}-${quoteAssetName}.`
);
}
@@ -297,6 +300,7 @@ export default async function swapMarket({
const swapThroughOrionPoolTxResponse = await signer.sendTransaction(unsignedSwapThroughOrionPoolTx);
options?.logger?.(`Transaction sent. Tx hash: ${swapThroughOrionPoolTxResponse.hash}`);
return {
amountOut: swapInfo.amountOut,
wait: swapThroughOrionPoolTxResponse.wait,
through: 'orion_pool',
txHash: swapThroughOrionPoolTxResponse.hash,
@@ -413,6 +417,7 @@ export default async function swapMarket({
options?.logger?.(`Order placed. Order id: ${orderId}`);
return {
amountOut: swapInfo.amountOut,
wait: () => new Promise<z.infer<typeof orderSchema>>((resolve, reject) => {
const timeout = setTimeout(() => {
reject(new Error('Timeout'))

View File

@@ -63,7 +63,7 @@ describe('Spot trading', () => {
bscUnit.provider
);
const result = await bscUnit.exchange.swapMarket({
const resultExactSpend = await bscUnit.exchange.swapMarket({
assetIn: 'USDT',
assetOut: 'BNB',
amount: 40,
@@ -75,29 +75,32 @@ describe('Spot trading', () => {
// logger: console.log
// }
})
await result.wait();
});
await resultExactSpend.wait();
test('Sell. Complex', async () => {
const orion = new Orion('testing');
const bscUnit = orion.getUnit('bsc');
const wallet = new ethers.Wallet(
privateKey,
bscUnit.provider
);
const result = await bscUnit.exchange.swapMarket({
const resultExactReceive = await bscUnit.exchange.swapMarket({
assetIn: 'BNB',
assetOut: 'ETH',
amount: 0.01,
assetOut: 'BTC',
amount: resultExactSpend.amountOut.toPrecision(3),
type: 'exactSpend',
signer: wallet,
feeAsset: 'USDT',
slippagePercent: 1,
options: {
logger: console.log
}
});
await resultExactReceive.wait();
// Return back to USDT
const returnBackUsdt = await bscUnit.exchange.swapMarket({
amount: 40,
assetIn: 'BTC',
assetOut: 'USDT',
type: 'exactReceive',
signer: wallet,
feeAsset: 'USDT',
slippagePercent: 1,
// options: {
// logger: console.log
// }
});
await result.wait();
await returnBackUsdt.wait();
});
});