@suilend/sdk 1.1.63 → 1.1.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.d.ts +7 -4
- package/client.js +17 -18
- package/lib/initialize.js +11 -4
- package/package.json +1 -1
- package/swap/quote.d.ts +4 -5
- package/swap/quote.js +45 -34
- package/swap/transaction.js +2 -2
package/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SuiClient } from "@mysten/sui/client";
|
|
2
|
-
import { Transaction, TransactionObjectInput, TransactionResult } from "@mysten/sui/transactions";
|
|
2
|
+
import { Transaction, TransactionObjectArgument, TransactionObjectInput, TransactionResult } from "@mysten/sui/transactions";
|
|
3
3
|
import { SuiPriceServiceConnection, SuiPythClient } from "@pythnetwork/pyth-sui-js";
|
|
4
4
|
import { FeeReceivers, LendingMarket, ObligationOwnerCap } from "./_generated/suilend/lending-market/structs";
|
|
5
5
|
import { Obligation } from "./_generated/suilend/obligation/structs";
|
|
@@ -48,9 +48,12 @@ export declare class SuilendClient {
|
|
|
48
48
|
closeReward(lendingMarketOwnerCapId: string, reserveArrayIndex: bigint, isDepositReward: boolean, rewardIndex: bigint, rewardCoinType: string, transaction: Transaction): TransactionResult;
|
|
49
49
|
claimReward(obligationOwnerCapId: string, reserveArrayIndex: bigint, rewardIndex: bigint, rewardType: string, side: Side, transaction: Transaction): TransactionResult;
|
|
50
50
|
claimRewardAndDeposit(obligationId: string, rewardReserveArrayIndex: bigint, rewardIndex: bigint, rewardType: string, side: Side, depositReserveArrayIndex: bigint, transaction: Transaction): TransactionResult;
|
|
51
|
-
claimRewards(ownerId: string, obligationOwnerCapId: string, rewards: ClaimRewardsReward[], transaction: Transaction
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
claimRewards(ownerId: string, obligationOwnerCapId: string, rewards: ClaimRewardsReward[], transaction: Transaction): {
|
|
52
|
+
transaction: Transaction;
|
|
53
|
+
mergedCoinsMap: Record<string, TransactionObjectArgument>;
|
|
54
|
+
};
|
|
55
|
+
claimRewardsAndSendToUser(ownerId: string, obligationOwnerCapId: string, rewards: ClaimRewardsReward[], transaction: Transaction): Transaction;
|
|
56
|
+
claimRewardsAndDeposit(ownerId: string, obligationOwnerCapId: string, rewards: ClaimRewardsReward[], transaction: Transaction): Transaction;
|
|
54
57
|
findReserveArrayIndex(coinType: string): bigint;
|
|
55
58
|
updateReserveConfig(lendingMarketOwnerCapId: string, transaction: Transaction, coinType: string, createReserveConfigArgs: CreateReserveConfigArgs): TransactionResult;
|
|
56
59
|
newObligationOwnerCap(transaction: Transaction, lendingMarketOwnerCapId: string, destinationAddress: string, obligationId: string): void;
|
package/client.js
CHANGED
|
@@ -303,37 +303,36 @@ class SuilendClient {
|
|
|
303
303
|
depositReserveId: transaction.pure.u64(depositReserveArrayIndex),
|
|
304
304
|
});
|
|
305
305
|
}
|
|
306
|
-
claimRewards(ownerId, obligationOwnerCapId, rewards, transaction
|
|
306
|
+
claimRewards(ownerId, obligationOwnerCapId, rewards, transaction) {
|
|
307
307
|
const mergeCoinsMap = {};
|
|
308
308
|
for (const reward of rewards) {
|
|
309
|
-
if (isDepositing) {
|
|
310
|
-
const depositReserveArrayIndex = this.findReserveArrayIndex(reward.rewardCoinType);
|
|
311
|
-
if (Number(depositReserveArrayIndex) === -1)
|
|
312
|
-
continue;
|
|
313
|
-
}
|
|
314
309
|
const [claimedCoin] = this.claimReward(obligationOwnerCapId, reward.reserveArrayIndex, reward.rewardIndex, reward.rewardCoinType, reward.side, transaction);
|
|
315
310
|
if (mergeCoinsMap[reward.rewardCoinType] === undefined)
|
|
316
311
|
mergeCoinsMap[reward.rewardCoinType] = [];
|
|
317
312
|
mergeCoinsMap[reward.rewardCoinType].push(claimedCoin);
|
|
318
313
|
}
|
|
314
|
+
const mergedCoinsMap = {};
|
|
319
315
|
for (const [rewardCoinType, coins] of Object.entries(mergeCoinsMap)) {
|
|
320
|
-
const
|
|
321
|
-
if (coins.length > 1)
|
|
322
|
-
transaction.mergeCoins(
|
|
323
|
-
|
|
324
|
-
if (isDepositing) {
|
|
325
|
-
this.deposit(mergeCoin, rewardCoinType, obligationOwnerCapId, transaction);
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
transaction.transferObjects([mergeCoin], transaction.pure.address(ownerId));
|
|
329
|
-
}
|
|
316
|
+
const mergedCoin = coins[0];
|
|
317
|
+
if (coins.length > 1)
|
|
318
|
+
transaction.mergeCoins(mergedCoin, coins.slice(1));
|
|
319
|
+
mergedCoinsMap[rewardCoinType] = mergedCoin;
|
|
330
320
|
}
|
|
321
|
+
return { transaction, mergedCoinsMap };
|
|
331
322
|
}
|
|
332
323
|
claimRewardsAndSendToUser(ownerId, obligationOwnerCapId, rewards, transaction) {
|
|
333
|
-
this.claimRewards(ownerId, obligationOwnerCapId, rewards, transaction
|
|
324
|
+
const { transaction: transaction_, mergedCoinsMap } = this.claimRewards(ownerId, obligationOwnerCapId, rewards, transaction);
|
|
325
|
+
for (const [coinType, coin] of Object.entries(mergedCoinsMap)) {
|
|
326
|
+
transaction_.transferObjects([coin], transaction_.pure.address(ownerId));
|
|
327
|
+
}
|
|
328
|
+
return transaction_;
|
|
334
329
|
}
|
|
335
330
|
claimRewardsAndDeposit(ownerId, obligationOwnerCapId, rewards, transaction) {
|
|
336
|
-
this.claimRewards(ownerId, obligationOwnerCapId, rewards, transaction
|
|
331
|
+
const { transaction: transaction_, mergedCoinsMap } = this.claimRewards(ownerId, obligationOwnerCapId, rewards, transaction);
|
|
332
|
+
for (const [coinType, coin] of Object.entries(mergedCoinsMap)) {
|
|
333
|
+
this.deposit(coin, coinType, obligationOwnerCapId, transaction_);
|
|
334
|
+
}
|
|
335
|
+
return transaction_;
|
|
337
336
|
}
|
|
338
337
|
findReserveArrayIndex(coinType) {
|
|
339
338
|
const arrayIndex = this.lendingMarket.reserves.findIndex((r) => (0, utils_1.normalizeStructTag)(r.coinType.name) === (0, utils_1.normalizeStructTag)(coinType));
|
package/lib/initialize.js
CHANGED
|
@@ -77,10 +77,10 @@ exports.RESERVES_CUSTOM_ORDER = [
|
|
|
77
77
|
sui_fe_1.NORMALIZED_suiETH_COINTYPE,
|
|
78
78
|
sui_fe_1.NORMALIZED_WETH_COINTYPE,
|
|
79
79
|
sui_fe_1.NORMALIZED_SOL_COINTYPE,
|
|
80
|
-
// ISOLATED ASSETS
|
|
81
|
-
sui_fe_1.NORMALIZED_SEND_COINTYPE,
|
|
82
80
|
sui_fe_1.NORMALIZED_DEEP_COINTYPE,
|
|
83
81
|
sui_fe_1.NORMALIZED_WAL_COINTYPE,
|
|
82
|
+
// ISOLATED ASSETS
|
|
83
|
+
sui_fe_1.NORMALIZED_SEND_COINTYPE,
|
|
84
84
|
sui_fe_1.NORMALIZED_HAEDAL_COINTYPE,
|
|
85
85
|
sui_fe_1.NORMALIZED_BLUE_COINTYPE,
|
|
86
86
|
sui_fe_1.NORMALIZED_NS_COINTYPE,
|
|
@@ -103,6 +103,11 @@ const initializeSuilend = (suiClient, suilendClient) => __awaiter(void 0, void 0
|
|
|
103
103
|
const nowMs = Date.now();
|
|
104
104
|
const nowS = Math.floor(nowMs / 1000);
|
|
105
105
|
const refreshedRawReserves = yield simulate.refreshReservePrice(suilendClient.lendingMarket.reserves.map((r) => simulate.compoundReserveInterest(r, nowS)), new pyth_sui_js_1.SuiPriceServiceConnection("https://hermes.pyth.network"));
|
|
106
|
+
const miscCoinTypes = [
|
|
107
|
+
sui_fe_1.NORMALIZED_SEND_POINTS_S1_COINTYPE,
|
|
108
|
+
sui_fe_1.NORMALIZED_SEND_POINTS_S2_COINTYPE,
|
|
109
|
+
sui_fe_1.NORMALIZED_SEND_COINTYPE,
|
|
110
|
+
];
|
|
106
111
|
const reserveCoinTypes = [];
|
|
107
112
|
const rewardCoinTypes = [];
|
|
108
113
|
const activeRewardCoinTypes = [];
|
|
@@ -120,14 +125,16 @@ const initializeSuilend = (suiClient, suilendClient) => __awaiter(void 0, void 0
|
|
|
120
125
|
activeRewardCoinTypes.push((0, utils_1.normalizeStructTag)(pr.coinType.name));
|
|
121
126
|
});
|
|
122
127
|
});
|
|
128
|
+
const uniqueMiscCoinTypes = Array.from(new Set(miscCoinTypes));
|
|
123
129
|
const uniqueReserveCoinTypes = Array.from(new Set(reserveCoinTypes));
|
|
124
130
|
const uniqueRewardCoinTypes = Array.from(new Set(rewardCoinTypes));
|
|
125
131
|
const uniqueActiveRewardsCoinTypes = Array.from(new Set(activeRewardCoinTypes));
|
|
126
|
-
const [reserveCoinMetadataMap, rewardCoinMetadataMap] = yield Promise.all([
|
|
132
|
+
const [miscCoinMetadataMap, reserveCoinMetadataMap, rewardCoinMetadataMap] = yield Promise.all([
|
|
133
|
+
(0, sui_fe_1.getCoinMetadataMap)(uniqueMiscCoinTypes),
|
|
127
134
|
(0, sui_fe_1.getCoinMetadataMap)(uniqueReserveCoinTypes),
|
|
128
135
|
(0, sui_fe_1.getCoinMetadataMap)(uniqueRewardCoinTypes),
|
|
129
136
|
]);
|
|
130
|
-
const coinMetadataMap = Object.assign(Object.assign({}, reserveCoinMetadataMap), rewardCoinMetadataMap);
|
|
137
|
+
const coinMetadataMap = Object.assign(Object.assign(Object.assign({}, miscCoinMetadataMap), reserveCoinMetadataMap), rewardCoinMetadataMap);
|
|
131
138
|
const reservesWithTemporaryPythPriceFeeds = refreshedRawReserves.filter((r) => sui_fe_1.TEMPORARY_PYTH_PRICE_FEED_COINTYPES.includes((0, utils_1.normalizeStructTag)(r.coinType.name)));
|
|
132
139
|
for (const reserve of reservesWithTemporaryPythPriceFeeds) {
|
|
133
140
|
let cachedUsdPrice = yield (0, sui_fe_1.getPrice)((0, utils_1.normalizeStructTag)(reserve.coinType.name));
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sdk","version":"1.1.
|
|
1
|
+
{"name":"@suilend/sdk","version":"1.1.65","private":false,"description":"A TypeScript SDK for interacting with the Suilend program","author":"Suilend","license":"MIT","main":"./index.js","exports":{".":"./index.js","./client":"./client.js","./api/events":"./api/events.js","./api":"./api/index.js","./lib/constants":"./lib/constants.js","./lib":"./lib/index.js","./lib/initialize":"./lib/initialize.js","./lib/liquidityMining":"./lib/liquidityMining.js","./lib/transactions":"./lib/transactions.js","./lib/types":"./lib/types.js","./parsers/apiReserveAssetDataEvent":"./parsers/apiReserveAssetDataEvent.js","./parsers":"./parsers/index.js","./parsers/lendingMarket":"./parsers/lendingMarket.js","./parsers/obligation":"./parsers/obligation.js","./parsers/rateLimiter":"./parsers/rateLimiter.js","./parsers/reserve":"./parsers/reserve.js","./swap":"./swap/index.js","./swap/okxDex":"./swap/okxDex.js","./swap/quote":"./swap/quote.js","./swap/transaction":"./swap/transaction.js","./utils/events":"./utils/events.js","./utils":"./utils/index.js","./utils/obligation":"./utils/obligation.js","./utils/simulate":"./utils/simulate.js","./_generated/_framework/reified":"./_generated/_framework/reified.js","./_generated/_framework/util":"./_generated/_framework/util.js","./_generated/_framework/vector":"./_generated/_framework/vector.js","./_generated/suilend":"./_generated/suilend/index.js","./_generated/suilend/cell/structs":"./_generated/suilend/cell/structs.js","./_generated/suilend/decimal/structs":"./_generated/suilend/decimal/structs.js","./_generated/suilend/lending-market/functions":"./_generated/suilend/lending-market/functions.js","./_generated/suilend/lending-market/structs":"./_generated/suilend/lending-market/structs.js","./_generated/suilend/lending-market-registry/functions":"./_generated/suilend/lending-market-registry/functions.js","./_generated/suilend/liquidity-mining/structs":"./_generated/suilend/liquidity-mining/structs.js","./_generated/suilend/obligation/structs":"./_generated/suilend/obligation/structs.js","./_generated/suilend/rate-limiter/functions":"./_generated/suilend/rate-limiter/functions.js","./_generated/suilend/rate-limiter/structs":"./_generated/suilend/rate-limiter/structs.js","./_generated/suilend/reserve/structs":"./_generated/suilend/reserve/structs.js","./_generated/suilend/reserve-config/functions":"./_generated/suilend/reserve-config/functions.js","./_generated/suilend/reserve-config/structs":"./_generated/suilend/reserve-config/structs.js","./_generated/_dependencies/source/0x1":"./_generated/_dependencies/source/0x1/index.js","./_generated/_dependencies/source/0x2":"./_generated/_dependencies/source/0x2/index.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/index.js","./_generated/_dependencies/source/0x1/ascii/structs":"./_generated/_dependencies/source/0x1/ascii/structs.js","./_generated/_dependencies/source/0x1/option/structs":"./_generated/_dependencies/source/0x1/option/structs.js","./_generated/_dependencies/source/0x1/type-name/structs":"./_generated/_dependencies/source/0x1/type-name/structs.js","./_generated/_dependencies/source/0x2/bag/structs":"./_generated/_dependencies/source/0x2/bag/structs.js","./_generated/_dependencies/source/0x2/balance/structs":"./_generated/_dependencies/source/0x2/balance/structs.js","./_generated/_dependencies/source/0x2/object/structs":"./_generated/_dependencies/source/0x2/object/structs.js","./_generated/_dependencies/source/0x2/object-table/structs":"./_generated/_dependencies/source/0x2/object-table/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs.js"},"types":"./index.js","scripts":{"build":"rm -rf ./dist && bun tsc","eslint":"eslint --fix \"./src/**/*.ts\"","prettier":"prettier --write \"./src/**/*\"","lint":"bun eslint && bun prettier && bun tsc --noEmit","release":"bun run build && bun ts-node ./release.ts && cd ./dist && npm publish --access public"},"repository":{"type":"git","url":"git+https://github.com/suilend/suilend-fe-public.git"},"bugs":{"url":"https://github.com/suilend/suilend-fe-public/issues"},"dependencies":{"@7kprotocol/sdk-ts":"^3.0.2","@cetusprotocol/aggregator-sdk":"^0.12.1","@flowx-finance/sdk":"^1.11.0","@pythnetwork/pyth-sui-js":"^2.1.0","aftermath-ts-sdk":"^1.3.11","bignumber.js":"^9.1.2","bn.js":"^5.2.2","crypto-js":"^4.2.0","p-limit":"3.1.0","uuid":"^11.0.3"},"devDependencies":{"ts-node":"^10.9.2"},"peerDependencies":{"@mysten/bcs":"1.6.0","@mysten/sui":"1.28.2","@suilend/sui-fe":"^0.2.82"}}
|
package/swap/quote.d.ts
CHANGED
|
@@ -71,14 +71,13 @@ export type StandardizedQuote = {
|
|
|
71
71
|
provider: QuoteProvider.OKX_DEX;
|
|
72
72
|
quote: OkxDexQuote;
|
|
73
73
|
});
|
|
74
|
-
export declare const
|
|
75
|
-
export declare const fetchAggQuotes: (sdkMap: {
|
|
74
|
+
export declare const getAggQuotes: (sdkMap: {
|
|
76
75
|
[QuoteProvider.AFTERMATH]: AftermathSdk;
|
|
77
76
|
[QuoteProvider.CETUS]: CetusSdk;
|
|
78
77
|
[QuoteProvider.FLOWX]: FlowXAggregatorQuoter;
|
|
79
|
-
}, activeProviders: QuoteProvider[],
|
|
80
|
-
export declare const
|
|
78
|
+
}, activeProviders: QuoteProvider[], onGetAggQuote: (quote: StandardizedQuote | null) => void, tokenIn: Token, tokenOut: Token, amountIn: string) => Promise<void>;
|
|
79
|
+
export declare const getAggSortedQuotesAll: (sdkMap: {
|
|
81
80
|
[QuoteProvider.AFTERMATH]: AftermathSdk;
|
|
82
81
|
[QuoteProvider.CETUS]: CetusSdk;
|
|
83
82
|
[QuoteProvider.FLOWX]: FlowXAggregatorQuoter;
|
|
84
|
-
}, activeProviders: QuoteProvider[], tokenIn: Token, tokenOut: Token, amountIn: string) => Promise<
|
|
83
|
+
}, activeProviders: QuoteProvider[], tokenIn: Token, tokenOut: Token, amountIn: string) => Promise<StandardizedQuote[]>;
|
package/swap/quote.js
CHANGED
|
@@ -45,7 +45,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
45
45
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
46
|
};
|
|
47
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.
|
|
48
|
+
exports.getAggSortedQuotesAll = exports.getAggQuotes = exports.QUOTE_PROVIDER_NAME_MAP = exports.QuoteProvider = void 0;
|
|
49
49
|
const cjs_1 = require("@7kprotocol/sdk-ts/cjs");
|
|
50
50
|
const utils_1 = require("@mysten/sui/utils");
|
|
51
51
|
const Sentry = __importStar(require("@sentry/nextjs"));
|
|
@@ -75,14 +75,19 @@ const getPoolProviders = (standardizedQuote) => {
|
|
|
75
75
|
...route.path.reduce((acc2, p) => [...acc2, p.provider], []),
|
|
76
76
|
], [])));
|
|
77
77
|
};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
console.log(`[fetchAggQuoteWrapper] fetching ${provider} quote`);
|
|
78
|
+
const getAggQuoteWrapper = (provider, getAggQuote, timeoutMs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
+
console.log(`[getAggQuoteWrapper] getting ${provider} quote`);
|
|
81
80
|
try {
|
|
82
|
-
const
|
|
81
|
+
const timeoutPromise = new Promise((resolve) => {
|
|
82
|
+
setTimeout(() => resolve(null), timeoutMs);
|
|
83
|
+
});
|
|
84
|
+
const standardizedQuote = yield Promise.race([
|
|
85
|
+
getAggQuote(),
|
|
86
|
+
timeoutPromise,
|
|
87
|
+
]);
|
|
83
88
|
if (!standardizedQuote)
|
|
84
|
-
throw new Error(
|
|
85
|
-
console.log(`[
|
|
89
|
+
throw new Error(`No ${provider} quote returned within ${timeoutMs}ms`);
|
|
90
|
+
console.log(`[getAggQuoteWrapper] got ${provider} quote`, +standardizedQuote.out.amount, "pool providers:", standardizedQuote, "quote:", standardizedQuote.quote);
|
|
86
91
|
return standardizedQuote;
|
|
87
92
|
}
|
|
88
93
|
catch (err) {
|
|
@@ -91,7 +96,7 @@ const fetchAggQuoteWrapper = (provider, fetchAggQuote) => __awaiter(void 0, void
|
|
|
91
96
|
return null;
|
|
92
97
|
}
|
|
93
98
|
});
|
|
94
|
-
const
|
|
99
|
+
const getAftermathQuote = (sdk, tokenIn, tokenOut, amountIn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
100
|
const quote = yield sdk.Router().getCompleteTradeRouteGivenAmountIn({
|
|
96
101
|
coinInType: tokenIn.coinType,
|
|
97
102
|
coinOutType: tokenOut.coinType,
|
|
@@ -129,7 +134,7 @@ const fetchAftermathQuote = (sdk, tokenIn, tokenOut, amountIn) => __awaiter(void
|
|
|
129
134
|
};
|
|
130
135
|
return standardizedQuote;
|
|
131
136
|
});
|
|
132
|
-
const
|
|
137
|
+
const getCetusQuote = (sdk, tokenIn, tokenOut, amountIn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
133
138
|
const quote = yield sdk.findRouters({
|
|
134
139
|
from: tokenIn.coinType,
|
|
135
140
|
target: tokenOut.coinType,
|
|
@@ -172,7 +177,7 @@ const fetchCetusQuote = (sdk, tokenIn, tokenOut, amountIn) => __awaiter(void 0,
|
|
|
172
177
|
};
|
|
173
178
|
return standardizedQuote;
|
|
174
179
|
});
|
|
175
|
-
const
|
|
180
|
+
const get7kQuote = (tokenIn, tokenOut, amountIn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
176
181
|
var _a;
|
|
177
182
|
const quote = yield (0, cjs_1.getQuote)({
|
|
178
183
|
tokenIn: tokenIn.coinType,
|
|
@@ -213,7 +218,7 @@ const fetch7kQuote = (tokenIn, tokenOut, amountIn) => __awaiter(void 0, void 0,
|
|
|
213
218
|
};
|
|
214
219
|
return standardizedQuote;
|
|
215
220
|
});
|
|
216
|
-
const
|
|
221
|
+
const getFlowXQuote = (sdk, tokenIn, tokenOut, amountIn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
217
222
|
var _a;
|
|
218
223
|
const quote = yield sdk.getRoutes({
|
|
219
224
|
tokenIn: tokenIn.coinType,
|
|
@@ -254,7 +259,7 @@ const fetchFlowXQuote = (sdk, tokenIn, tokenOut, amountIn) => __awaiter(void 0,
|
|
|
254
259
|
};
|
|
255
260
|
return standardizedQuote;
|
|
256
261
|
});
|
|
257
|
-
const
|
|
262
|
+
const getOkxDexQuote = (amountIn, tokenIn, tokenOut) => __awaiter(void 0, void 0, void 0, function* () {
|
|
258
263
|
const quote = yield (0, okxDex_1.getOkxDexQuote)(amountIn, tokenIn.coinType, tokenOut.coinType);
|
|
259
264
|
const flattenedDexRouterList = [];
|
|
260
265
|
for (const dexRouter of quote.dexRouterList) {
|
|
@@ -308,63 +313,69 @@ const fetchOkxDexQuote = (amountIn, tokenIn, tokenOut) => __awaiter(void 0, void
|
|
|
308
313
|
};
|
|
309
314
|
return standardizedQuote;
|
|
310
315
|
});
|
|
311
|
-
const
|
|
312
|
-
|
|
316
|
+
const getAggQuotes = (sdkMap, activeProviders, onGetAggQuote, tokenIn, tokenOut, amountIn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
317
|
+
const timeoutMs = 5000;
|
|
318
|
+
// Get quotes in parallel
|
|
313
319
|
// Aftermath
|
|
314
320
|
if (activeProviders.includes(QuoteProvider.AFTERMATH)) {
|
|
315
321
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
316
|
-
const standardizedQuote = yield
|
|
317
|
-
|
|
322
|
+
const standardizedQuote = yield getAggQuoteWrapper(QuoteProvider.AFTERMATH, () => getAftermathQuote(sdkMap[QuoteProvider.AFTERMATH], tokenIn, tokenOut, amountIn), timeoutMs);
|
|
323
|
+
onGetAggQuote(standardizedQuote);
|
|
318
324
|
}))();
|
|
319
325
|
}
|
|
320
326
|
// Cetus
|
|
321
327
|
if (activeProviders.includes(QuoteProvider.CETUS)) {
|
|
322
328
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
323
|
-
const standardizedQuote = yield
|
|
324
|
-
|
|
329
|
+
const standardizedQuote = yield getAggQuoteWrapper(QuoteProvider.CETUS, () => getCetusQuote(sdkMap[QuoteProvider.CETUS], tokenIn, tokenOut, amountIn), timeoutMs);
|
|
330
|
+
onGetAggQuote(standardizedQuote);
|
|
325
331
|
}))();
|
|
326
332
|
}
|
|
327
333
|
// 7K
|
|
328
334
|
if (activeProviders.includes(QuoteProvider._7K)) {
|
|
329
335
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
330
|
-
const standardizedQuote = yield
|
|
331
|
-
|
|
336
|
+
const standardizedQuote = yield getAggQuoteWrapper(QuoteProvider._7K, () => get7kQuote(tokenIn, tokenOut, amountIn), timeoutMs);
|
|
337
|
+
onGetAggQuote(standardizedQuote);
|
|
332
338
|
}))();
|
|
333
339
|
}
|
|
334
340
|
// FlowX
|
|
335
341
|
if (activeProviders.includes(QuoteProvider.FLOWX)) {
|
|
336
342
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
337
|
-
const standardizedQuote = yield
|
|
338
|
-
|
|
343
|
+
const standardizedQuote = yield getAggQuoteWrapper(QuoteProvider.FLOWX, () => getFlowXQuote(sdkMap[QuoteProvider.FLOWX], tokenIn, tokenOut, amountIn), timeoutMs);
|
|
344
|
+
onGetAggQuote(standardizedQuote);
|
|
339
345
|
}))();
|
|
340
346
|
}
|
|
341
347
|
// OKX DEX
|
|
342
348
|
if (activeProviders.includes(QuoteProvider.OKX_DEX)) {
|
|
343
349
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
344
|
-
const standardizedQuote = yield
|
|
345
|
-
|
|
350
|
+
const standardizedQuote = yield getAggQuoteWrapper(QuoteProvider.OKX_DEX, () => getOkxDexQuote(amountIn, tokenIn, tokenOut), timeoutMs);
|
|
351
|
+
onGetAggQuote(standardizedQuote);
|
|
346
352
|
}))();
|
|
347
353
|
}
|
|
348
354
|
});
|
|
349
|
-
exports.
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
|
|
355
|
+
exports.getAggQuotes = getAggQuotes;
|
|
356
|
+
const getAggSortedQuotesAll = (sdkMap, activeProviders, tokenIn, tokenOut, amountIn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
357
|
+
const timeoutMs = 2500;
|
|
358
|
+
// Get quotes in parallel
|
|
359
|
+
const quotes = yield Promise.all([
|
|
353
360
|
activeProviders.includes(QuoteProvider.AFTERMATH)
|
|
354
|
-
?
|
|
361
|
+
? getAggQuoteWrapper(QuoteProvider.AFTERMATH, () => getAftermathQuote(sdkMap[QuoteProvider.AFTERMATH], tokenIn, tokenOut, amountIn), timeoutMs)
|
|
355
362
|
: null,
|
|
356
363
|
activeProviders.includes(QuoteProvider.CETUS)
|
|
357
|
-
?
|
|
364
|
+
? getAggQuoteWrapper(QuoteProvider.CETUS, () => getCetusQuote(sdkMap[QuoteProvider.CETUS], tokenIn, tokenOut, amountIn), timeoutMs)
|
|
358
365
|
: null,
|
|
359
366
|
activeProviders.includes(QuoteProvider._7K)
|
|
360
|
-
?
|
|
367
|
+
? getAggQuoteWrapper(QuoteProvider._7K, () => get7kQuote(tokenIn, tokenOut, amountIn), timeoutMs)
|
|
361
368
|
: null,
|
|
362
369
|
activeProviders.includes(QuoteProvider.FLOWX)
|
|
363
|
-
?
|
|
370
|
+
? getAggQuoteWrapper(QuoteProvider.FLOWX, () => getFlowXQuote(sdkMap[QuoteProvider.FLOWX], tokenIn, tokenOut, amountIn), timeoutMs)
|
|
364
371
|
: null,
|
|
365
372
|
activeProviders.includes(QuoteProvider.OKX_DEX)
|
|
366
|
-
?
|
|
373
|
+
? getAggQuoteWrapper(QuoteProvider.OKX_DEX, () => getOkxDexQuote(amountIn, tokenIn, tokenOut), timeoutMs)
|
|
367
374
|
: null,
|
|
368
375
|
].filter(Boolean));
|
|
376
|
+
const sortedQuotes = quotes.filter(Boolean)
|
|
377
|
+
.slice()
|
|
378
|
+
.sort((a, b) => +b.out.amount.minus(a.out.amount));
|
|
379
|
+
return sortedQuotes;
|
|
369
380
|
});
|
|
370
|
-
exports.
|
|
381
|
+
exports.getAggSortedQuotesAll = getAggSortedQuotesAll;
|
package/swap/transaction.js
CHANGED
|
@@ -53,8 +53,8 @@ const quote_1 = require("./quote");
|
|
|
53
53
|
const getSwapTransactionWrapper = (provider, getSwapTransaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
54
|
console.log(`[getSwapTransactionWrapper] fetching transaction for ${provider} quote`);
|
|
55
55
|
try {
|
|
56
|
-
const res = getSwapTransaction();
|
|
57
|
-
console.log(`[getSwapTransactionWrapper] fetched transaction for ${provider} quote
|
|
56
|
+
const res = yield getSwapTransaction();
|
|
57
|
+
console.log(`[getSwapTransactionWrapper] fetched transaction for ${provider} quote`);
|
|
58
58
|
return res;
|
|
59
59
|
}
|
|
60
60
|
catch (err) {
|