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

@@ -1,6 +1,8 @@
{
"cSpell.words": [
"ASCENDEX",
"bignumber",
"denormalized"
"denormalized",
"KUCOIN"
]
}

View File

@@ -81,6 +81,8 @@ orionUnit.exchange
slippagePercent: 1,
signer: wallet, // or signer when UI
options: {
// All options are optional 🙂
poolOnly: true, // You can specify whether you want to perform the exchange only through the pool
logger: console.log,
// Set it to true if you want the issues associated with
// the lack of allowance to be automatically corrected
@@ -252,6 +254,7 @@ orionUnit.orionAggregator.ws.subscribe(
i: assetIn, // asset in
o: assetOut, // asset out
e: true, // true when type of swap is exactSpend, can be omitted (true by default)
es: ['ORION_POOL'] // OPTIONAL! Specify ['ORION_POOL'] if you want "pool only" swap execution
a: 5.62345343, // amount
},
// Handle data update in your way

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.10.4-rc.2",
"version": "0.10.4-rc.3",
"description": "Orion Protocol SDK",
"main": "./lib/esm/index.js",
"module": "./lib/esm/index.js",

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];