@suilend/sdk 1.1.56 → 1.1.58

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.js CHANGED
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.SuilendClient = exports.LENDING_MARKET_TYPE = exports.LENDING_MARKET_ID = exports.LENDING_MARKETS = exports.LENDING_MARKET_REGISTRY_ID = exports.ADMIN_ADDRESS = void 0;
13
13
  const utils_1 = require("@mysten/sui/utils");
14
14
  const pyth_sui_js_1 = require("@pythnetwork/pyth-sui-js");
15
- const frontend_sui_1 = require("@suilend/frontend-sui");
15
+ const sui_fe_1 = require("@suilend/sui-fe");
16
16
  const structs_1 = require("./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs");
17
17
  const reified_1 = require("./_generated/_framework/reified");
18
18
  const suilend_1 = require("./_generated/suilend");
@@ -682,7 +682,7 @@ class SuilendClient {
682
682
  if (mergeCoins.length > 1) {
683
683
  transaction.mergeCoins(transaction.object(mergeCoin.coinObjectId), mergeCoins.map((mc) => transaction.object(mc.coinObjectId)).slice(1));
684
684
  }
685
- const coinType = (0, frontend_sui_1.extractCTokenCoinType)(ctokenCoinType);
685
+ const coinType = (0, sui_fe_1.extractCTokenCoinType)(ctokenCoinType);
686
686
  const [exemption] = transaction.moveCall({
687
687
  target: `0x1::option::none`,
688
688
  typeArguments: [
package/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./api";
2
2
  export * from "./lib";
3
3
  export * from "./parsers";
4
+ export * from "./swap";
4
5
  export * from "./utils";
5
6
  export * from "./client";
package/index.js CHANGED
@@ -17,5 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./api"), exports);
18
18
  __exportStar(require("./lib"), exports);
19
19
  __exportStar(require("./parsers"), exports);
20
+ __exportStar(require("./swap"), exports);
20
21
  __exportStar(require("./utils"), exports);
21
22
  __exportStar(require("./client"), exports);
@@ -140,6 +140,7 @@ export declare const initializeSuilend: (suiClient: SuiClient, suilendClient: Su
140
140
  tvlUsd: BigNumber;
141
141
  name: string;
142
142
  slug: string;
143
+ isHidden: boolean;
143
144
  ownerCapId: string;
144
145
  totalSupplyUsd: BigNumber;
145
146
  totalBorrowUsd: BigNumber;
@@ -255,10 +256,10 @@ export declare const initializeSuilend: (suiClient: SuiClient, suilendClient: Su
255
256
  totalDeposits: BigNumber;
256
257
  }>;
257
258
  reserveCoinTypes: string[];
258
- reserveCoinMetadataMap: Record<string, import("@suilend/frontend-sui").Token>;
259
+ reserveCoinMetadataMap: Record<string, import("@suilend/sui-fe").Token>;
259
260
  rewardCoinTypes: string[];
260
261
  activeRewardCoinTypes: string[];
261
- rewardCoinMetadataMap: Record<string, import("@suilend/frontend-sui").Token>;
262
+ rewardCoinMetadataMap: Record<string, import("@suilend/sui-fe").Token>;
262
263
  }>;
263
264
  export declare const initializeSuilendRewards: (reserveMap: Record<string, ParsedReserve>, activeRewardCoinTypes: string[]) => Promise<{
264
265
  rewardPriceMap: Record<string, BigNumber | undefined>;
package/lib/initialize.js CHANGED
@@ -49,49 +49,49 @@ exports.initializeObligations = exports.initializeSuilendRewards = exports.initi
49
49
  const utils_1 = require("@mysten/sui/utils");
50
50
  const pyth_sui_js_1 = require("@pythnetwork/pyth-sui-js");
51
51
  const bignumber_js_1 = __importDefault(require("bignumber.js"));
52
- const frontend_sui_1 = require("@suilend/frontend-sui");
52
+ const sui_fe_1 = require("@suilend/sui-fe");
53
53
  const client_1 = require("../client");
54
54
  const parsers_1 = require("../parsers");
55
55
  const simulate = __importStar(require("../utils/simulate"));
56
56
  const constants_1 = require("./constants");
57
57
  exports.RESERVES_CUSTOM_ORDER = [
58
58
  // MAIN ASSETS
59
- frontend_sui_1.NORMALIZED_sSUI_COINTYPE,
59
+ sui_fe_1.NORMALIZED_sSUI_COINTYPE,
60
60
  // MAIN ASSETS - Ecosystem LSTs
61
- frontend_sui_1.NORMALIZED_kSUI_COINTYPE,
62
- frontend_sui_1.NORMALIZED_iSUI_COINTYPE,
63
- frontend_sui_1.NORMALIZED_mSUI_COINTYPE,
64
- frontend_sui_1.NORMALIZED_fudSUI_COINTYPE,
65
- frontend_sui_1.NORMALIZED_trevinSUI_COINTYPE,
66
- frontend_sui_1.NORMALIZED_upSUI_COINTYPE,
67
- frontend_sui_1.NORMALIZED_yapSUI_COINTYPE,
68
- frontend_sui_1.NORMALIZED_flSUI_COINTYPE,
69
- frontend_sui_1.NORMALIZED_SUI_COINTYPE,
70
- frontend_sui_1.NORMALIZED_USDC_COINTYPE,
71
- frontend_sui_1.NORMALIZED_wUSDC_COINTYPE,
72
- frontend_sui_1.NORMALIZED_suiUSDT_COINTYPE,
73
- frontend_sui_1.NORMALIZED_wUSDT_COINTYPE,
74
- frontend_sui_1.NORMALIZED_AUSD_COINTYPE,
75
- frontend_sui_1.NORMALIZED_LBTC_COINTYPE,
76
- frontend_sui_1.NORMALIZED_wBTC_COINTYPE,
77
- frontend_sui_1.NORMALIZED_suiETH_COINTYPE,
78
- frontend_sui_1.NORMALIZED_WETH_COINTYPE,
79
- frontend_sui_1.NORMALIZED_SOL_COINTYPE,
61
+ sui_fe_1.NORMALIZED_kSUI_COINTYPE,
62
+ sui_fe_1.NORMALIZED_iSUI_COINTYPE,
63
+ sui_fe_1.NORMALIZED_mSUI_COINTYPE,
64
+ sui_fe_1.NORMALIZED_fudSUI_COINTYPE,
65
+ sui_fe_1.NORMALIZED_trevinSUI_COINTYPE,
66
+ sui_fe_1.NORMALIZED_upSUI_COINTYPE,
67
+ sui_fe_1.NORMALIZED_yapSUI_COINTYPE,
68
+ sui_fe_1.NORMALIZED_flSUI_COINTYPE,
69
+ sui_fe_1.NORMALIZED_SUI_COINTYPE,
70
+ sui_fe_1.NORMALIZED_USDC_COINTYPE,
71
+ sui_fe_1.NORMALIZED_wUSDC_COINTYPE,
72
+ sui_fe_1.NORMALIZED_suiUSDT_COINTYPE,
73
+ sui_fe_1.NORMALIZED_wUSDT_COINTYPE,
74
+ sui_fe_1.NORMALIZED_AUSD_COINTYPE,
75
+ sui_fe_1.NORMALIZED_LBTC_COINTYPE,
76
+ sui_fe_1.NORMALIZED_wBTC_COINTYPE,
77
+ sui_fe_1.NORMALIZED_suiETH_COINTYPE,
78
+ sui_fe_1.NORMALIZED_WETH_COINTYPE,
79
+ sui_fe_1.NORMALIZED_SOL_COINTYPE,
80
80
  // ISOLATED ASSETS
81
- frontend_sui_1.NORMALIZED_SEND_COINTYPE,
82
- frontend_sui_1.NORMALIZED_DEEP_COINTYPE,
83
- frontend_sui_1.NORMALIZED_WAL_COINTYPE,
84
- frontend_sui_1.NORMALIZED_HAEDAL_COINTYPE,
85
- frontend_sui_1.NORMALIZED_BLUE_COINTYPE,
86
- frontend_sui_1.NORMALIZED_NS_COINTYPE,
87
- frontend_sui_1.NORMALIZED_UP_COINTYPE,
88
- frontend_sui_1.NORMALIZED_KOBAN_COINTYPE,
89
- frontend_sui_1.NORMALIZED_mUSD_COINTYPE,
90
- frontend_sui_1.NORMALIZED_BUCK_COINTYPE,
81
+ sui_fe_1.NORMALIZED_SEND_COINTYPE,
82
+ sui_fe_1.NORMALIZED_DEEP_COINTYPE,
83
+ sui_fe_1.NORMALIZED_WAL_COINTYPE,
84
+ sui_fe_1.NORMALIZED_HAEDAL_COINTYPE,
85
+ sui_fe_1.NORMALIZED_BLUE_COINTYPE,
86
+ sui_fe_1.NORMALIZED_NS_COINTYPE,
87
+ sui_fe_1.NORMALIZED_UP_COINTYPE,
88
+ sui_fe_1.NORMALIZED_KOBAN_COINTYPE,
89
+ sui_fe_1.NORMALIZED_mUSD_COINTYPE,
90
+ sui_fe_1.NORMALIZED_BUCK_COINTYPE,
91
91
  // ISOLATED ASSETS - Memecoins
92
- frontend_sui_1.NORMALIZED_HIPPO_COINTYPE,
93
- frontend_sui_1.NORMALIZED_LOFI_COINTYPE, // Not listed
94
- frontend_sui_1.NORMALIZED_FUD_COINTYPE,
92
+ sui_fe_1.NORMALIZED_HIPPO_COINTYPE,
93
+ sui_fe_1.NORMALIZED_LOFI_COINTYPE, // Not listed
94
+ sui_fe_1.NORMALIZED_FUD_COINTYPE,
95
95
  ];
96
96
  const MAYA_COINTYPE = "0x3bf0aeb7b9698b18ec7937290a5701088fcd5d43ad11a2564b074d022a6d71ec::maya::MAYA";
97
97
  const mPOINTS_COINTYPE = "0x7bae0b3b7b6c3da899fe3f4af95b7110633499c02b8c6945110d799d99deaa68::mpoints::MPOINTS";
@@ -124,20 +124,20 @@ const initializeSuilend = (suiClient, suilendClient) => __awaiter(void 0, void 0
124
124
  const uniqueRewardCoinTypes = Array.from(new Set(rewardCoinTypes));
125
125
  const uniqueActiveRewardsCoinTypes = Array.from(new Set(activeRewardCoinTypes));
126
126
  const [reserveCoinMetadataMap, rewardCoinMetadataMap] = yield Promise.all([
127
- (0, frontend_sui_1.getCoinMetadataMap)(uniqueReserveCoinTypes),
128
- (0, frontend_sui_1.getCoinMetadataMap)(uniqueRewardCoinTypes),
127
+ (0, sui_fe_1.getCoinMetadataMap)(uniqueReserveCoinTypes),
128
+ (0, sui_fe_1.getCoinMetadataMap)(uniqueRewardCoinTypes),
129
129
  ]);
130
130
  const coinMetadataMap = Object.assign(Object.assign({}, reserveCoinMetadataMap), rewardCoinMetadataMap);
131
- const reservesWithTemporaryPythPriceFeeds = refreshedRawReserves.filter((r) => frontend_sui_1.TEMPORARY_PYTH_PRICE_FEED_COINTYPES.includes((0, utils_1.normalizeStructTag)(r.coinType.name)));
131
+ const reservesWithTemporaryPythPriceFeeds = refreshedRawReserves.filter((r) => sui_fe_1.TEMPORARY_PYTH_PRICE_FEED_COINTYPES.includes((0, utils_1.normalizeStructTag)(r.coinType.name)));
132
132
  for (const reserve of reservesWithTemporaryPythPriceFeeds) {
133
- let birdeyePrice = yield (0, frontend_sui_1.getPrice)((0, utils_1.normalizeStructTag)(reserve.coinType.name));
134
- if (birdeyePrice === undefined)
135
- birdeyePrice = 0.0001; // Non-zero price override for coinTypes with price feed overrides
136
- const parsedBirdeyePrice = BigInt(+new bignumber_js_1.default(birdeyePrice)
133
+ let cachedUsdPrice = yield (0, sui_fe_1.getPrice)((0, utils_1.normalizeStructTag)(reserve.coinType.name));
134
+ if (cachedUsdPrice === undefined)
135
+ cachedUsdPrice = 0.0001; // Non-zero price override for coinTypes with price feed overrides
136
+ const parsedCachedUsdPrice = BigInt(+new bignumber_js_1.default(cachedUsdPrice)
137
137
  .times(constants_1.WAD)
138
138
  .integerValue(bignumber_js_1.default.ROUND_DOWN));
139
- reserve.price.value = parsedBirdeyePrice;
140
- reserve.smoothedPrice.value = parsedBirdeyePrice;
139
+ reserve.price.value = parsedCachedUsdPrice;
140
+ reserve.smoothedPrice.value = parsedCachedUsdPrice;
141
141
  }
142
142
  // const walReserve = refreshedRawReserves.find(
143
143
  // (r) => normalizeStructTag(r.coinType.name) === NORMALIZED_WAL_COINTYPE,
@@ -177,16 +177,16 @@ exports.initializeSuilend = initializeSuilend;
177
177
  const initializeSuilendRewards = (reserveMap, activeRewardCoinTypes) => __awaiter(void 0, void 0, void 0, function* () {
178
178
  const rewardPriceMap = Object.entries(reserveMap).reduce((acc, [coinType, reserve]) => (Object.assign(Object.assign({}, acc), { [coinType]: reserve.price })), {});
179
179
  rewardPriceMap[exports.NORMALIZED_TREATS_COINTYPE] = new bignumber_js_1.default(0.1);
180
- const reservelessActiveRewardCoinTypes = activeRewardCoinTypes.filter((coinType) => !((0, frontend_sui_1.isSendPoints)(coinType) ||
181
- (0, frontend_sui_1.isSteammPoints)(coinType) ||
180
+ const reservelessActiveRewardCoinTypes = activeRewardCoinTypes.filter((coinType) => !((0, sui_fe_1.isSendPoints)(coinType) ||
181
+ (0, sui_fe_1.isSteammPoints)(coinType) ||
182
182
  coinType === exports.NORMALIZED_MAYA_COINTYPE ||
183
183
  coinType === exports.NORMALIZED_mPOINTS_COINTYPE) && !rewardPriceMap[coinType]);
184
- const reservelessActiveRewardBirdeyePrices = yield Promise.all(reservelessActiveRewardCoinTypes.map((coinType) => (0, frontend_sui_1.getPrice)(coinType)));
184
+ const reservelessActiveRewardCachedUsdPrices = yield Promise.all(reservelessActiveRewardCoinTypes.map((coinType) => (0, sui_fe_1.getPrice)(coinType)));
185
185
  for (let i = 0; i < reservelessActiveRewardCoinTypes.length; i++) {
186
- const birdeyePrice = reservelessActiveRewardBirdeyePrices[i];
187
- if (birdeyePrice === undefined)
186
+ const cachedUsdPrice = reservelessActiveRewardCachedUsdPrices[i];
187
+ if (cachedUsdPrice === undefined)
188
188
  continue;
189
- rewardPriceMap[reservelessActiveRewardCoinTypes[i]] = new bignumber_js_1.default(birdeyePrice);
189
+ rewardPriceMap[reservelessActiveRewardCoinTypes[i]] = new bignumber_js_1.default(cachedUsdPrice);
190
190
  }
191
191
  return { rewardPriceMap };
192
192
  });
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getNetAprPercent = exports.getTotalAprPercent = exports.getStakingYieldAprPercent = exports.getRewardsAprPercent = exports.getDedupedPerDayRewards = exports.getDedupedAprRewards = exports.getFilteredRewards = exports.formatRewards = exports.getBorrowShare = exports.getDepositShare = void 0;
7
7
  const bignumber_js_1 = __importDefault(require("bignumber.js"));
8
8
  const lodash_1 = require("lodash");
9
- const frontend_sui_1 = require("@suilend/frontend-sui");
9
+ const sui_fe_1 = require("@suilend/sui-fe");
10
10
  const constants_1 = require("./constants");
11
11
  const types_1 = require("./types");
12
12
  const getDepositShare = (reserve, share) => share.div(10 ** reserve.mintDecimals).times(reserve.cTokenExchangeRate);
@@ -27,7 +27,7 @@ const formatRewards = (parsedReserveMap, coinMetadataMap, priceMap, obligations)
27
27
  ? new bignumber_js_1.default(0)
28
28
  : poolReward.totalRewards
29
29
  .times(rewardPrice)
30
- .times(new bignumber_js_1.default(frontend_sui_1.MS_PER_YEAR).div(poolReward.endTimeMs - poolReward.startTimeMs))
30
+ .times(new bignumber_js_1.default(sui_fe_1.MS_PER_YEAR).div(poolReward.endTimeMs - poolReward.startTimeMs))
31
31
  .div(side === types_1.Side.DEPOSIT
32
32
  ? getDepositShareUsd(reserve, new bignumber_js_1.default(reserve.depositsPoolRewardManager.totalShares.toString()))
33
33
  : getBorrowShareUsd(reserve, new bignumber_js_1.default(reserve.borrowsPoolRewardManager.totalShares.toString())))
@@ -36,7 +36,7 @@ const formatRewards = (parsedReserveMap, coinMetadataMap, priceMap, obligations)
36
36
  const perDay = rewardPrice
37
37
  ? undefined
38
38
  : poolReward.totalRewards
39
- .times(new bignumber_js_1.default(frontend_sui_1.MS_PER_YEAR).div(poolReward.endTimeMs - poolReward.startTimeMs))
39
+ .times(new bignumber_js_1.default(sui_fe_1.MS_PER_YEAR).div(poolReward.endTimeMs - poolReward.startTimeMs))
40
40
  .div(365)
41
41
  .div(side === types_1.Side.DEPOSIT
42
42
  ? (0, exports.getDepositShare)(reserve, new bignumber_js_1.default(reserve.depositsPoolRewardManager.totalShares.toString()))
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@suilend/sdk","version":"1.1.56","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","./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/solendprotocol/suilend-public.git"},"bugs":{"url":"https://github.com/solendprotocol/suilend-public/issues"},"dependencies":{"@pythnetwork/pyth-sui-js":"^2.1.0","bignumber.js":"^9.1.2","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/frontend-sui":"^0.2.71"}}
1
+ {"name":"@suilend/sdk","version":"1.1.58","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.0","@flowx-finance/sdk":"^1.10.24","@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.79"}}
@@ -135,6 +135,7 @@ export declare const parseLendingMarket: (lendingMarket: LendingMarket<string>,
135
135
  tvlUsd: BigNumber;
136
136
  name: string;
137
137
  slug: string;
138
+ isHidden: boolean;
138
139
  ownerCapId: string;
139
140
  /**
140
141
  * @deprecated since version 1.0.3. Use `depositedAmountUsd` instead.
@@ -9,7 +9,7 @@ const client_1 = require("../client");
9
9
  const rateLimiter_1 = require("./rateLimiter");
10
10
  const reserve_1 = require("./reserve");
11
11
  const parseLendingMarket = (lendingMarket, reserves, coinMetadataMap, nowS) => {
12
- var _a, _b, _c;
12
+ var _a, _b, _c, _d;
13
13
  const id = lendingMarket.id;
14
14
  const type = lendingMarket.$typeArgs[0];
15
15
  const version = lendingMarket.version;
@@ -33,7 +33,8 @@ const parseLendingMarket = (lendingMarket, reserves, coinMetadataMap, nowS) => {
33
33
  console.error(`Missing LENDING_MARKETS definition for lending market with id: ${id}`);
34
34
  const name = (_a = LENDING_MARKET === null || LENDING_MARKET === void 0 ? void 0 : LENDING_MARKET.name) !== null && _a !== void 0 ? _a : "Unknown";
35
35
  const slug = (_b = LENDING_MARKET === null || LENDING_MARKET === void 0 ? void 0 : LENDING_MARKET.slug) !== null && _b !== void 0 ? _b : "unknown";
36
- const ownerCapId = (_c = LENDING_MARKET === null || LENDING_MARKET === void 0 ? void 0 : LENDING_MARKET.ownerCapId) !== null && _c !== void 0 ? _c : "Unknown";
36
+ const isHidden = (_c = LENDING_MARKET === null || LENDING_MARKET === void 0 ? void 0 : LENDING_MARKET.isHidden) !== null && _c !== void 0 ? _c : false;
37
+ const ownerCapId = (_d = LENDING_MARKET === null || LENDING_MARKET === void 0 ? void 0 : LENDING_MARKET.ownerCapId) !== null && _d !== void 0 ? _d : "Unknown";
37
38
  return {
38
39
  id,
39
40
  type,
@@ -49,6 +50,7 @@ const parseLendingMarket = (lendingMarket, reserves, coinMetadataMap, nowS) => {
49
50
  tvlUsd,
50
51
  name,
51
52
  slug,
53
+ isHidden,
52
54
  ownerCapId,
53
55
  /**
54
56
  * @deprecated since version 1.0.3. Use `depositedAmountUsd` instead.
@@ -82,6 +82,8 @@ const parseObligation = (obligation, parsedReserveMap) => {
82
82
  };
83
83
  });
84
84
  const netValueUsd = totalDepositedAmountUsd.minus(totalBorrowedAmountUsd);
85
+ // Cap `minPriceBorrowLimitUsd` at $20m (account borrow limit)
86
+ minPriceBorrowLimitUsd = bignumber_js_1.default.min(minPriceBorrowLimitUsd, 20 * 10 ** 6);
85
87
  const weightedConservativeBorrowUtilizationPercent = minPriceBorrowLimitUsd.eq(0)
86
88
  ? new bignumber_js_1.default(0)
87
89
  : maxPriceWeightedBorrowsUsd.div(minPriceBorrowLimitUsd).times(100);
@@ -0,0 +1,3 @@
1
+ export * from "./okxDex";
2
+ export * from "./quote";
3
+ export * from "./transaction";
package/swap/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./okxDex"), exports);
18
+ __exportStar(require("./quote"), exports);
19
+ __exportStar(require("./transaction"), exports);
@@ -0,0 +1,47 @@
1
+ import { Transaction } from "@mysten/sui/transactions";
2
+ export declare const cartesianProduct: (arrays: number[][]) => number[][];
3
+ export type OkxDexQuote = {
4
+ fromTokenAmount: string;
5
+ toTokenAmount: string;
6
+ dexRouterList: {
7
+ router: string;
8
+ routerPercent: string;
9
+ subRouterList: {
10
+ dexProtocol: {
11
+ percent: string;
12
+ dexName: string;
13
+ }[];
14
+ fromToken: {
15
+ tokenContractAddress: string;
16
+ };
17
+ toToken: {
18
+ tokenContractAddress: string;
19
+ };
20
+ }[];
21
+ }[];
22
+ };
23
+ export type OkxDexSwap = {
24
+ tx: {
25
+ signatureData: string[];
26
+ from: string;
27
+ gas: string;
28
+ gasPrice: string;
29
+ maxPriorityFeePerGas: string;
30
+ to: string;
31
+ value: string;
32
+ maxSpendAmount: string;
33
+ minReceiveAmount: string;
34
+ data: string;
35
+ slippage: string;
36
+ };
37
+ };
38
+ export declare const getOkxDexQuote: (amountIn: string, tokenInCoinType: string, tokenOutCoinType: string) => Promise<OkxDexQuote>;
39
+ export declare const getOkxDexSwapTransaction: (amountIn: string, tokenInCoinType: string, tokenOutCoinType: string, slippagePercent: number, address: string) => Promise<Transaction>;
40
+ export declare const getHeaders: (timestamp: string, method: string, requestPath: string, queryString: string) => {
41
+ "Content-Type": string;
42
+ "OK-ACCESS-KEY": string;
43
+ "OK-ACCESS-SIGN": string;
44
+ "OK-ACCESS-TIMESTAMP": string;
45
+ "OK-ACCESS-PASSPHRASE": string;
46
+ "OK-ACCESS-PROJECT": string;
47
+ };
package/swap/okxDex.js ADDED
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getHeaders = exports.getOkxDexSwapTransaction = exports.getOkxDexQuote = exports.cartesianProduct = void 0;
16
+ const transactions_1 = require("@mysten/sui/transactions");
17
+ const crypto_js_1 = __importDefault(require("crypto-js"));
18
+ const cartesianProduct = (arrays) => {
19
+ return arrays.reduce((a, b) => a.map((x) => b.map((y) => [...x, y])).reduce((a, b) => [...a, ...b], []), [[]]);
20
+ };
21
+ exports.cartesianProduct = cartesianProduct;
22
+ const getOkxDexQuote = (amountIn, tokenInCoinType, tokenOutCoinType) => __awaiter(void 0, void 0, void 0, function* () {
23
+ var _a;
24
+ const res = yield fetch("/api/okx-dex/quote", {
25
+ method: "POST",
26
+ body: JSON.stringify({
27
+ amountIn,
28
+ tokenInCoinType,
29
+ tokenOutCoinType,
30
+ }),
31
+ headers: {
32
+ "Content-Type": "application/json",
33
+ },
34
+ });
35
+ if (!res.ok)
36
+ throw new Error(`Failed to get OKX DEX quote: ${(_a = (yield res.json())) === null || _a === void 0 ? void 0 : _a.error}`);
37
+ const json = yield res.json();
38
+ return json;
39
+ });
40
+ exports.getOkxDexQuote = getOkxDexQuote;
41
+ const getOkxDexSwapTransaction = (amountIn, tokenInCoinType, tokenOutCoinType, slippagePercent, address) => __awaiter(void 0, void 0, void 0, function* () {
42
+ var _a;
43
+ const res = yield fetch("/api/okx-dex/swap", {
44
+ method: "POST",
45
+ body: JSON.stringify({
46
+ amountIn,
47
+ tokenInCoinType,
48
+ tokenOutCoinType,
49
+ slippagePercent,
50
+ address,
51
+ }),
52
+ headers: {
53
+ "Content-Type": "application/json",
54
+ },
55
+ });
56
+ if (!res.ok)
57
+ throw new Error(`Failed to get OKX DEX swap transaction: ${(_a = (yield res.json())) === null || _a === void 0 ? void 0 : _a.error}`);
58
+ const json = yield res.json();
59
+ return transactions_1.Transaction.from(json.tx.data);
60
+ });
61
+ exports.getOkxDexSwapTransaction = getOkxDexSwapTransaction;
62
+ // Used on server-side only
63
+ const getHeaders = (timestamp, method, requestPath, queryString) => {
64
+ const stringToSign = `${timestamp}${method}${requestPath}${queryString}`;
65
+ return {
66
+ "Content-Type": "application/json",
67
+ "OK-ACCESS-KEY": process.env.OKX_API_KEY,
68
+ "OK-ACCESS-SIGN": crypto_js_1.default.enc.Base64.stringify(crypto_js_1.default.HmacSHA256(stringToSign, process.env.OKX_SECRET_KEY)),
69
+ "OK-ACCESS-TIMESTAMP": timestamp,
70
+ "OK-ACCESS-PASSPHRASE": process.env.OKX_API_PASSPHRASE,
71
+ "OK-ACCESS-PROJECT": process.env.OKX_PROJECT_ID,
72
+ };
73
+ };
74
+ exports.getHeaders = getHeaders;
@@ -0,0 +1,79 @@
1
+ import { QuoteResponse as _7kQuote } from "@7kprotocol/sdk-ts/cjs";
2
+ import { RouterData as CetusQuote, AggregatorClient as CetusSdk } from "@cetusprotocol/aggregator-sdk";
3
+ import { AggregatorQuoter as FlowXAggregatorQuoter, GetRoutesResult as FlowXGetRoutesResult } from "@flowx-finance/sdk";
4
+ import { RouterCompleteTradeRoute as AftermathQuote, Aftermath as AftermathSdk } from "aftermath-ts-sdk";
5
+ import BigNumber from "bignumber.js";
6
+ import { Token } from "@suilend/sui-fe";
7
+ import { OkxDexQuote } from "./okxDex";
8
+ export declare const getPoolProviders: (standardizedQuote: StandardizedQuote) => string[];
9
+ export declare enum QuoteProvider {
10
+ AFTERMATH = "aftermath",
11
+ CETUS = "cetus",
12
+ _7K = "7k",
13
+ FLOWX = "flowx",
14
+ OKX_DEX = "okxDex"
15
+ }
16
+ export declare const QUOTE_PROVIDER_NAME_MAP: {
17
+ aftermath: string;
18
+ cetus: string;
19
+ "7k": string;
20
+ flowx: string;
21
+ okxDex: string;
22
+ };
23
+ export type StandardizedRoutePath = {
24
+ id: string;
25
+ poolId?: string;
26
+ routeIndex: number;
27
+ provider: string;
28
+ in: {
29
+ coinType: string;
30
+ amount: BigNumber;
31
+ };
32
+ out: {
33
+ coinType: string;
34
+ amount: BigNumber;
35
+ };
36
+ };
37
+ export type StandardizedPathWithToken = StandardizedRoutePath & {
38
+ in: StandardizedRoutePath["in"] & {
39
+ token: Token;
40
+ };
41
+ out: StandardizedRoutePath["out"] & {
42
+ token: Token;
43
+ };
44
+ };
45
+ export type StandardizedQuote = {
46
+ id: string;
47
+ in: {
48
+ coinType: string;
49
+ amount: BigNumber;
50
+ };
51
+ out: {
52
+ coinType: string;
53
+ amount: BigNumber;
54
+ };
55
+ routes: {
56
+ percent: BigNumber;
57
+ path: StandardizedRoutePath[];
58
+ }[];
59
+ } & ({
60
+ provider: QuoteProvider.AFTERMATH;
61
+ quote: AftermathQuote;
62
+ } | {
63
+ provider: QuoteProvider.CETUS;
64
+ quote: CetusQuote;
65
+ } | {
66
+ provider: QuoteProvider._7K;
67
+ quote: _7kQuote;
68
+ } | {
69
+ provider: QuoteProvider.FLOWX;
70
+ quote: FlowXGetRoutesResult<any, any>;
71
+ } | {
72
+ provider: QuoteProvider.OKX_DEX;
73
+ quote: OkxDexQuote;
74
+ });
75
+ export declare const fetchAggQuotes: (sdkMap: {
76
+ [QuoteProvider.AFTERMATH]: AftermathSdk;
77
+ [QuoteProvider.CETUS]: CetusSdk;
78
+ [QuoteProvider.FLOWX]: FlowXAggregatorQuoter;
79
+ }, activeProviders: QuoteProvider[], setQuotesForTimestamp: (timestamp: number, quotes: StandardizedQuote[]) => void, _tokenIn: Token, _tokenOut: Token, _value: string, _timestamp?: number) => Promise<void>;
package/swap/quote.js ADDED
@@ -0,0 +1,330 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.fetchAggQuotes = exports.QUOTE_PROVIDER_NAME_MAP = exports.QuoteProvider = exports.getPoolProviders = void 0;
16
+ const cjs_1 = require("@7kprotocol/sdk-ts/cjs");
17
+ const utils_1 = require("@mysten/sui/utils");
18
+ const bignumber_js_1 = __importDefault(require("bignumber.js"));
19
+ const bn_js_1 = __importDefault(require("bn.js"));
20
+ const uuid_1 = require("uuid");
21
+ const lib_1 = require("../lib");
22
+ const okxDex_1 = require("./okxDex");
23
+ const getPoolProviders = (standardizedQuote) => {
24
+ return Array.from(new Set(standardizedQuote.routes.reduce((acc, route) => [
25
+ ...acc,
26
+ ...route.path.reduce((acc2, p) => [...acc2, p.provider], []),
27
+ ], [])));
28
+ };
29
+ exports.getPoolProviders = getPoolProviders;
30
+ var QuoteProvider;
31
+ (function (QuoteProvider) {
32
+ QuoteProvider["AFTERMATH"] = "aftermath";
33
+ QuoteProvider["CETUS"] = "cetus";
34
+ QuoteProvider["_7K"] = "7k";
35
+ QuoteProvider["FLOWX"] = "flowx";
36
+ QuoteProvider["OKX_DEX"] = "okxDex";
37
+ })(QuoteProvider || (exports.QuoteProvider = QuoteProvider = {}));
38
+ exports.QUOTE_PROVIDER_NAME_MAP = {
39
+ [QuoteProvider.AFTERMATH]: "Aftermath",
40
+ [QuoteProvider.CETUS]: "Cetus",
41
+ [QuoteProvider._7K]: "7K",
42
+ [QuoteProvider.FLOWX]: "FlowX",
43
+ [QuoteProvider.OKX_DEX]: "OKX DEX",
44
+ };
45
+ const fetchAggQuotes = (sdkMap_1, activeProviders_1, setQuotesForTimestamp_1, _tokenIn_1, _tokenOut_1, _value_1, ...args_1) => __awaiter(void 0, [sdkMap_1, activeProviders_1, setQuotesForTimestamp_1, _tokenIn_1, _tokenOut_1, _value_1, ...args_1], void 0, function* (sdkMap, activeProviders, setQuotesForTimestamp, _tokenIn, _tokenOut, _value, _timestamp = new Date().getTime()) {
46
+ const quotesForTimestamp = [];
47
+ setQuotesForTimestamp(_timestamp, quotesForTimestamp);
48
+ const amountIn = new bignumber_js_1.default(_value)
49
+ .times(10 ** _tokenIn.decimals)
50
+ .integerValue(bignumber_js_1.default.ROUND_DOWN)
51
+ .toString();
52
+ // Fetch quotes in parallel
53
+ // Aftermath
54
+ if (activeProviders.includes(QuoteProvider.AFTERMATH)) {
55
+ (() => __awaiter(void 0, void 0, void 0, function* () {
56
+ console.log("[fetchAggQuotes] fetching Aftermath quote");
57
+ try {
58
+ const quote = yield sdkMap[QuoteProvider.AFTERMATH]
59
+ .Router()
60
+ .getCompleteTradeRouteGivenAmountIn({
61
+ coinInType: _tokenIn.coinType,
62
+ coinOutType: _tokenOut.coinType,
63
+ coinInAmount: BigInt(amountIn),
64
+ });
65
+ const standardizedQuote = {
66
+ id: (0, uuid_1.v4)(),
67
+ provider: QuoteProvider.AFTERMATH,
68
+ in: {
69
+ coinType: _tokenIn.coinType,
70
+ amount: new bignumber_js_1.default(quote.coinIn.amount.toString()).div(10 ** _tokenIn.decimals),
71
+ },
72
+ out: {
73
+ coinType: _tokenOut.coinType,
74
+ amount: new bignumber_js_1.default(quote.coinOut.amount.toString()).div(10 ** _tokenOut.decimals),
75
+ },
76
+ routes: quote.routes.map((route, routeIndex) => ({
77
+ percent: new bignumber_js_1.default(route.portion.toString())
78
+ .div(lib_1.WAD)
79
+ .times(100),
80
+ path: route.paths.map((path) => ({
81
+ id: (0, uuid_1.v4)(),
82
+ poolId: path.poolId,
83
+ routeIndex,
84
+ provider: path.protocolName,
85
+ in: {
86
+ coinType: (0, utils_1.normalizeStructTag)(path.coinIn.type),
87
+ amount: new bignumber_js_1.default(path.coinIn.amount.toString()).div(10 ** _tokenIn.decimals),
88
+ },
89
+ out: {
90
+ coinType: (0, utils_1.normalizeStructTag)(path.coinOut.type),
91
+ amount: new bignumber_js_1.default(path.coinOut.amount.toString()).div(10 ** _tokenOut.decimals),
92
+ },
93
+ })),
94
+ })),
95
+ quote,
96
+ };
97
+ quotesForTimestamp.push(standardizedQuote);
98
+ setQuotesForTimestamp(_timestamp, quotesForTimestamp);
99
+ console.log("[fetchAggQuotes] set Aftermath quote", +standardizedQuote.out.amount, "pool providers:", (0, exports.getPoolProviders)(standardizedQuote), "quote:", quote);
100
+ }
101
+ catch (err) {
102
+ console.error(err);
103
+ }
104
+ }))();
105
+ }
106
+ // Cetus
107
+ if (activeProviders.includes(QuoteProvider.CETUS)) {
108
+ (() => __awaiter(void 0, void 0, void 0, function* () {
109
+ console.log("[fetchAggQuotes] fetching Cetus quote");
110
+ try {
111
+ const quote = yield sdkMap[QuoteProvider.CETUS].findRouters({
112
+ from: _tokenIn.coinType,
113
+ target: _tokenOut.coinType,
114
+ amount: new bn_js_1.default(amountIn),
115
+ byAmountIn: true,
116
+ });
117
+ if (!quote)
118
+ return;
119
+ const standardizedQuote = {
120
+ id: (0, uuid_1.v4)(),
121
+ provider: QuoteProvider.CETUS,
122
+ in: {
123
+ coinType: _tokenIn.coinType,
124
+ amount: new bignumber_js_1.default(quote.amountIn.toString()).div(10 ** _tokenIn.decimals),
125
+ },
126
+ out: {
127
+ coinType: _tokenOut.coinType,
128
+ amount: new bignumber_js_1.default(quote.amountOut.toString()).div(10 ** _tokenOut.decimals),
129
+ },
130
+ routes: quote.routes.map((route, routeIndex) => ({
131
+ percent: new bignumber_js_1.default(route.amountIn.toString())
132
+ .div(quote.amountIn.toString())
133
+ .times(100),
134
+ path: route.path.map((path) => ({
135
+ id: (0, uuid_1.v4)(),
136
+ poolId: path.id,
137
+ routeIndex,
138
+ provider: path.provider,
139
+ in: {
140
+ coinType: (0, utils_1.normalizeStructTag)(path.from),
141
+ amount: new bignumber_js_1.default(path.amountIn.toString()).div(10 ** _tokenIn.decimals),
142
+ },
143
+ out: {
144
+ coinType: (0, utils_1.normalizeStructTag)(path.target),
145
+ amount: new bignumber_js_1.default(path.amountOut.toString()).div(10 ** _tokenOut.decimals),
146
+ },
147
+ })),
148
+ })),
149
+ quote,
150
+ };
151
+ quotesForTimestamp.push(standardizedQuote);
152
+ setQuotesForTimestamp(_timestamp, quotesForTimestamp);
153
+ console.log("[fetchAggQuotes] set Cetus quote", +standardizedQuote.out.amount, "pool providers:", (0, exports.getPoolProviders)(standardizedQuote), "quote:", quote);
154
+ }
155
+ catch (err) {
156
+ console.error(err);
157
+ }
158
+ }))();
159
+ }
160
+ // 7K
161
+ if (activeProviders.includes(QuoteProvider._7K)) {
162
+ (() => __awaiter(void 0, void 0, void 0, function* () {
163
+ var _a;
164
+ console.log("[fetchAggQuotes] fetching 7K quote");
165
+ try {
166
+ const quote = yield (0, cjs_1.getQuote)({
167
+ tokenIn: _tokenIn.coinType,
168
+ tokenOut: _tokenOut.coinType,
169
+ amountIn,
170
+ });
171
+ const standardizedQuote = {
172
+ id: (0, uuid_1.v4)(),
173
+ provider: QuoteProvider._7K,
174
+ in: {
175
+ coinType: _tokenIn.coinType,
176
+ amount: new bignumber_js_1.default(quote.swapAmount),
177
+ },
178
+ out: {
179
+ coinType: _tokenOut.coinType,
180
+ amount: new bignumber_js_1.default(quote.returnAmount),
181
+ },
182
+ routes: ((_a = quote.routes) !== null && _a !== void 0 ? _a : []).map((route, routeIndex) => ({
183
+ percent: new bignumber_js_1.default(route.tokenInAmount)
184
+ .div(quote.swapAmount)
185
+ .times(100),
186
+ path: route.hops.map((hop) => ({
187
+ id: (0, uuid_1.v4)(),
188
+ poolId: hop.poolId,
189
+ routeIndex,
190
+ provider: hop.pool.type,
191
+ in: {
192
+ coinType: (0, utils_1.normalizeStructTag)(hop.tokenIn),
193
+ amount: new bignumber_js_1.default(hop.tokenInAmount),
194
+ },
195
+ out: {
196
+ coinType: (0, utils_1.normalizeStructTag)(hop.tokenOut),
197
+ amount: new bignumber_js_1.default(hop.tokenOutAmount),
198
+ },
199
+ })),
200
+ })),
201
+ quote,
202
+ };
203
+ quotesForTimestamp.push(standardizedQuote);
204
+ setQuotesForTimestamp(_timestamp, quotesForTimestamp);
205
+ console.log("[fetchAggQuotes] set 7K quote", +standardizedQuote.out.amount, "pool providers:", (0, exports.getPoolProviders)(standardizedQuote), "quote:", quote);
206
+ }
207
+ catch (err) {
208
+ console.error(err);
209
+ }
210
+ }))();
211
+ }
212
+ // FlowX
213
+ if (activeProviders.includes(QuoteProvider.FLOWX)) {
214
+ (() => __awaiter(void 0, void 0, void 0, function* () {
215
+ var _a;
216
+ console.log("[fetchAggQuotes] fetching FlowX quote");
217
+ try {
218
+ const quote = yield sdkMap[QuoteProvider.FLOWX].getRoutes({
219
+ tokenIn: _tokenIn.coinType,
220
+ tokenOut: _tokenOut.coinType,
221
+ amountIn: amountIn,
222
+ });
223
+ const standardizedQuote = {
224
+ id: (0, uuid_1.v4)(),
225
+ provider: QuoteProvider.FLOWX,
226
+ in: {
227
+ coinType: _tokenIn.coinType,
228
+ amount: new bignumber_js_1.default(quote.amountIn.toString()).div(10 ** _tokenIn.decimals),
229
+ },
230
+ out: {
231
+ coinType: _tokenOut.coinType,
232
+ amount: new bignumber_js_1.default(quote.amountOut.toString()).div(10 ** _tokenOut.decimals),
233
+ },
234
+ routes: ((_a = quote.routes) !== null && _a !== void 0 ? _a : []).map((route, routeIndex) => ({
235
+ percent: new bignumber_js_1.default(route.amountIn.toString())
236
+ .div(quote.amountIn.toString())
237
+ .times(100),
238
+ path: route.paths.map((hop) => ({
239
+ id: (0, uuid_1.v4)(),
240
+ poolId: hop.pool.id,
241
+ routeIndex,
242
+ provider: hop.protocol(),
243
+ in: {
244
+ coinType: (0, utils_1.normalizeStructTag)(hop.input.coinType),
245
+ amount: new bignumber_js_1.default(hop.amountIn.toString()).div(10 ** _tokenIn.decimals),
246
+ },
247
+ out: {
248
+ coinType: (0, utils_1.normalizeStructTag)(hop.output.coinType),
249
+ amount: new bignumber_js_1.default(hop.amountOut.toString()).div(10 ** _tokenOut.decimals),
250
+ },
251
+ })),
252
+ })),
253
+ quote,
254
+ };
255
+ quotesForTimestamp.push(standardizedQuote);
256
+ setQuotesForTimestamp(_timestamp, quotesForTimestamp);
257
+ console.log("[fetchAggQuotes] set FlowX quote", +standardizedQuote.out.amount, "pool providers:", (0, exports.getPoolProviders)(standardizedQuote), "quote:", quote);
258
+ }
259
+ catch (err) {
260
+ console.error(err);
261
+ }
262
+ }))();
263
+ }
264
+ // OKX DEX
265
+ if (activeProviders.includes(QuoteProvider.OKX_DEX)) {
266
+ (() => __awaiter(void 0, void 0, void 0, function* () {
267
+ console.log("[fetchAggQuotes] fetching OKX DEX quote");
268
+ try {
269
+ const quote = yield (0, okxDex_1.getOkxDexQuote)(amountIn, _tokenIn.coinType, _tokenOut.coinType);
270
+ const flattenedDexRouterList = [];
271
+ for (const dexRouter of quote.dexRouterList) {
272
+ const indexes = [];
273
+ for (const subRouter of dexRouter.subRouterList) {
274
+ indexes.push(Array.from({ length: subRouter.dexProtocol.length }, (_, j) => j));
275
+ }
276
+ const combinations = (0, okxDex_1.cartesianProduct)(indexes);
277
+ for (const combination of combinations) {
278
+ const flattenedRouter = Object.assign(Object.assign({}, dexRouter), { routerPercent: "", subRouterList: dexRouter.subRouterList.map((subRouter, index) => (Object.assign(Object.assign({}, subRouter), { dexProtocol: [subRouter.dexProtocol[combination[index]]] }))) });
279
+ let routerPercent = new bignumber_js_1.default(dexRouter.routerPercent);
280
+ for (const subRouter of flattenedRouter.subRouterList) {
281
+ const dexProtocol = subRouter.dexProtocol[0];
282
+ routerPercent = routerPercent.times(new bignumber_js_1.default(dexProtocol.percent).div(100));
283
+ }
284
+ flattenedRouter.routerPercent = routerPercent.toString();
285
+ flattenedDexRouterList.push(flattenedRouter);
286
+ }
287
+ }
288
+ const standardizedQuote = {
289
+ id: (0, uuid_1.v4)(),
290
+ provider: QuoteProvider.OKX_DEX,
291
+ in: {
292
+ coinType: _tokenIn.coinType,
293
+ amount: new bignumber_js_1.default(quote.fromTokenAmount).div(10 ** _tokenIn.decimals),
294
+ },
295
+ out: {
296
+ coinType: _tokenOut.coinType,
297
+ amount: new bignumber_js_1.default(quote.toTokenAmount).div(10 ** _tokenOut.decimals),
298
+ },
299
+ routes: flattenedDexRouterList.map((dexRouter, routeIndex) => {
300
+ return {
301
+ percent: new bignumber_js_1.default(dexRouter.routerPercent),
302
+ path: dexRouter.subRouterList.map((subRouter) => ({
303
+ id: (0, uuid_1.v4)(),
304
+ poolId: undefined, // Missing data
305
+ routeIndex,
306
+ provider: subRouter.dexProtocol[0].dexName,
307
+ in: {
308
+ coinType: (0, utils_1.normalizeStructTag)(subRouter.fromToken.tokenContractAddress),
309
+ amount: new bignumber_js_1.default(0).div(10 ** _tokenIn.decimals), // Missing data
310
+ },
311
+ out: {
312
+ coinType: (0, utils_1.normalizeStructTag)(subRouter.toToken.tokenContractAddress),
313
+ amount: new bignumber_js_1.default(0).div(10 ** _tokenIn.decimals), // Missing data
314
+ },
315
+ })),
316
+ };
317
+ }),
318
+ quote,
319
+ };
320
+ quotesForTimestamp.push(standardizedQuote);
321
+ setQuotesForTimestamp(_timestamp, quotesForTimestamp);
322
+ console.log("Swap - set OKX DEX quote", +standardizedQuote.out.amount, "pool providers:", (0, exports.getPoolProviders)(standardizedQuote), "quote:", quote);
323
+ }
324
+ catch (err) {
325
+ console.error(err);
326
+ }
327
+ }))();
328
+ }
329
+ });
330
+ exports.fetchAggQuotes = fetchAggQuotes;
@@ -0,0 +1,18 @@
1
+ import { AggregatorClient as CetusSdk } from "@cetusprotocol/aggregator-sdk";
2
+ import { AggregatorQuoter as FlowXAggregatorQuoter } from "@flowx-finance/sdk";
3
+ import { SuiClient } from "@mysten/sui/client";
4
+ import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
5
+ import { Aftermath as AftermathSdk } from "aftermath-ts-sdk";
6
+ import { QuoteProvider, StandardizedQuote } from "./quote";
7
+ export declare const getSwapTransaction: (suiClient: SuiClient, address: string, quote: StandardizedQuote, slippagePercent: number, sdkMap: {
8
+ [QuoteProvider.AFTERMATH]: AftermathSdk;
9
+ [QuoteProvider.CETUS]: CetusSdk;
10
+ [QuoteProvider.FLOWX]: FlowXAggregatorQuoter;
11
+ }, partnerIdMap: {
12
+ [QuoteProvider.CETUS]: string;
13
+ [QuoteProvider._7K]: string;
14
+ [QuoteProvider.FLOWX]: string;
15
+ }, transaction: Transaction, coinIn: TransactionObjectArgument | undefined) => Promise<{
16
+ transaction: any;
17
+ coinOut: any;
18
+ }>;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getSwapTransaction = void 0;
13
+ const cjs_1 = require("@7kprotocol/sdk-ts/cjs");
14
+ const sdk_1 = require("@flowx-finance/sdk");
15
+ const transactions_1 = require("@mysten/sui/transactions");
16
+ const sui_fe_1 = require("@suilend/sui-fe");
17
+ const okxDex_1 = require("./okxDex");
18
+ const quote_1 = require("./quote");
19
+ const getSwapTransaction = (suiClient, address, quote, slippagePercent, sdkMap, partnerIdMap, transaction, coinIn) => __awaiter(void 0, void 0, void 0, function* () {
20
+ if (!address)
21
+ throw new Error("Wallet not connected");
22
+ if (!quote)
23
+ throw new Error("Quote not found");
24
+ if (quote.provider === quote_1.QuoteProvider.AFTERMATH) {
25
+ console.log("[getSwapTransaction] fetching transaction for Aftermath quote");
26
+ const { tx: transaction2, coinOutId: coinOut } = yield sdkMap[quote_1.QuoteProvider.AFTERMATH]
27
+ .Router()
28
+ .addTransactionForCompleteTradeRoute({
29
+ tx: transaction,
30
+ walletAddress: address,
31
+ completeRoute: quote.quote,
32
+ slippage: slippagePercent / 100,
33
+ coinInId: coinIn,
34
+ });
35
+ return { transaction: transaction2, coinOut };
36
+ }
37
+ else if (quote.provider === quote_1.QuoteProvider.CETUS) {
38
+ console.log("[getSwapTransaction] fetching transaction for Cetus quote");
39
+ if (!coinIn)
40
+ coinIn = (0, transactions_1.coinWithBalance)({
41
+ balance: BigInt(quote.quote.amountIn.toString()),
42
+ type: quote.in.coinType,
43
+ useGasCoin: (0, sui_fe_1.isSui)(quote.in.coinType),
44
+ })(transaction);
45
+ const coinOut = yield sdkMap[quote_1.QuoteProvider.CETUS].routerSwap({
46
+ routers: quote.quote,
47
+ inputCoin: coinIn,
48
+ slippage: slippagePercent / 100,
49
+ txb: transaction,
50
+ partner: partnerIdMap[quote_1.QuoteProvider.CETUS],
51
+ });
52
+ return { transaction, coinOut };
53
+ }
54
+ else if (quote.provider === quote_1.QuoteProvider._7K) {
55
+ const { tx: transaction2, coinOut } = yield (0, cjs_1.buildTx)({
56
+ quoteResponse: quote.quote,
57
+ accountAddress: address,
58
+ slippage: slippagePercent / 100,
59
+ commission: {
60
+ partner: partnerIdMap[quote_1.QuoteProvider._7K],
61
+ commissionBps: 0,
62
+ },
63
+ extendTx: {
64
+ tx: transaction,
65
+ coinIn,
66
+ },
67
+ });
68
+ if (transaction2 instanceof cjs_1.BluefinXTx) {
69
+ // BluefinXTx
70
+ throw new Error("BluefinXTx not supported");
71
+ }
72
+ else {
73
+ return { transaction: transaction2, coinOut };
74
+ }
75
+ }
76
+ else if (quote.provider === quote_1.QuoteProvider.FLOWX) {
77
+ console.log("[getSwapTransaction] fetching transaction for FlowX quote");
78
+ if (!coinIn)
79
+ coinIn = (0, transactions_1.coinWithBalance)({
80
+ balance: BigInt(quote.quote.amountIn.toString()),
81
+ type: quote.in.coinType,
82
+ useGasCoin: (0, sui_fe_1.isSui)(quote.in.coinType),
83
+ })(transaction);
84
+ const trade = new sdk_1.TradeBuilder("mainnet", quote.quote.routes)
85
+ .slippage((slippagePercent / 100) * 1e6)
86
+ .commission(new sdk_1.Commission(partnerIdMap[quote_1.QuoteProvider.FLOWX], new sdk_1.Coin(quote.out.coinType), sdk_1.CommissionType.PERCENTAGE, 0, true))
87
+ .build();
88
+ const coinOut = yield trade.swap({
89
+ coinIn: coinIn,
90
+ client: suiClient,
91
+ tx: transaction,
92
+ });
93
+ return { transaction, coinOut: coinOut };
94
+ }
95
+ else if (quote.provider === quote_1.QuoteProvider.OKX_DEX) {
96
+ console.log("[getSwapTransaction] fetching transaction for OKX DEX quote");
97
+ const transaction2 = yield (0, okxDex_1.getOkxDexSwapTransaction)(quote.quote.fromTokenAmount, quote.in.coinType, quote.out.coinType, slippagePercent, address); // Does not use `transaction` or `coinIn`
98
+ return { transaction: transaction2, coinOut: undefined };
99
+ }
100
+ else
101
+ throw new Error("Unknown quote type");
102
+ });
103
+ exports.getSwapTransaction = getSwapTransaction;