This commit is contained in:
Aleksandr Kraiz
2022-05-28 11:17:18 +04:00
parent 1b660c9ada
commit fd212d2366
7 changed files with 30 additions and 5 deletions

View File

@@ -21,6 +21,7 @@ export type SwapMarketParams = {
signer: ethers.Signer,
orionUnit: OrionUnit,
options?: {
poolOnly?: boolean,
logger?: (message: string) => void,
autoApprove?: boolean,
developer?: {
@@ -115,7 +116,17 @@ export default async function swapMarket({
signer,
);
const swapInfo = await simpleFetch(orionAggregator.getSwapInfo)(type, assetIn, assetOut, amount.toString());
const swapInfo = await simpleFetch(orionAggregator.getSwapInfo)(
type,
assetIn,
assetOut,
amount.toString(),
options?.poolOnly ? ['ORION_POOL'] : undefined,
);
if (options?.poolOnly === true && options.poolOnly !== swapInfo.isThroughPoolOptimal) {
throw new Error(`Unexpected Orion Aggregator response. Please, contact support. Report swap request id: ${swapInfo.id}`);
}
if (swapInfo.type === 'exactReceive' && amountBN.lt(swapInfo.minAmountOut)) {
throw new Error(`Amount is too low. Min amountOut is ${swapInfo.minAmountOut} ${assetOut}`);

View File

@@ -9,7 +9,7 @@ import errorSchema from './schemas/errorSchema';
import placeAtomicSwapSchema from './schemas/placeAtomicSwapSchema';
import { OrionAggregatorWS } from './ws';
import { atomicSwapHistorySchema } from './schemas/atomicSwapHistorySchema';
import { SignedCancelOrderRequest, SignedOrder } from '../../types';
import { Exchange, SignedCancelOrderRequest, SignedOrder } from '../../types';
import { pairConfigSchema } from './schemas';
import {
aggregatedOrderbookSchema, exchangeOrderbookSchema,
@@ -151,6 +151,7 @@ class OrionAggregator {
assetIn: string,
assetOut: string,
amount: string,
exchanges?: Exchange[],
) => {
const url = new URL(`${this.apiUrl}/api/v1/swap`);
url.searchParams.append('assetIn', assetIn);
@@ -160,6 +161,9 @@ class OrionAggregator {
} else {
url.searchParams.append('amountOut', amount);
}
if (exchanges) {
url.searchParams.append('exchanges', exchanges.join(','));
}
return fetchWithValidation(
url.toString(),

View File

@@ -12,7 +12,7 @@ import {
import UnsubscriptionType from './UnsubscriptionType';
import {
SwapInfoByAmountIn, SwapInfoByAmountOut, SwapInfoBase,
FullOrder, OrderUpdate, AssetPairUpdate, OrderbookItem, Balance,
FullOrder, OrderUpdate, AssetPairUpdate, OrderbookItem, Balance, Exchange,
} from '../../../types';
import unsubscriptionDoneSchema from './schemas/unsubscriptionDoneSchema';
// import errorSchema from './schemas/errorSchema';
@@ -69,6 +69,7 @@ type SwapSubscriptionRequest = {
i: string, // asset in
o: string, // asset out
a: number // amount IN/OUT
es?: Exchange[], // exchange list
e?: boolean; // is amount IN? Value `false` means a = amount OUT, `true` if omitted
}

View File

@@ -195,3 +195,7 @@ export type BalanceIssue = {
readonly sources: Source[],
readonly fixes?: Fix[],
}
const availableExchanges = ['ORION_POOL', 'ASCENDEX', 'BINANCE', 'KUCOIN'] as const;
export type Exchange = typeof availableExchanges[number];