@scallop-io/sui-scallop-sdk 0.47.0-alpha.2 → 0.47.0-alpha.4

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.
@@ -7,10 +7,10 @@ export declare const PROTOCOL_OBJECT_ID: "0xc9f859f98ca352a11b97a038c4b4162bee43
7
7
  export declare const BORROW_FEE_PROTOCOL_ID: "0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778" | "0xc38f849e81cfe46d4e4320f508ea7dda42934a329d5a6571bb4c3cb6ea63f5da";
8
8
  export declare const SCA_COIN_TYPE: "0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524::sca::SCA" | "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA";
9
9
  export declare const OLD_BORROW_INCENTIVE_PROTOCOL_ID: "0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410";
10
- export declare const SUPPORT_POOLS: readonly ["weth", "wbtc", "wusdc", "wusdt", "sui", "wapt", "wsol", "cetus", "afsui", "hasui", "vsui", "sca"];
11
- export declare const SUPPORT_COLLATERALS: readonly ["weth", "wbtc", "wusdc", "wusdt", "sui", "wapt", "wsol", "cetus", "afsui", "hasui", "vsui", "sca"];
12
- export declare const SUPPORT_SPOOLS: readonly ["sweth", "ssui", "swusdc", "swusdt", "scetus", "safsui", "shasui", "svsui"];
13
- export declare const SUPPORT_SCOIN: readonly ["ssui", "swusdc", "swusdt", "safsui", "shasui", "svsui", "sweth", "ssca", "scetus", "swsol", "swbtc"];
10
+ export declare const SUPPORT_POOLS: readonly ["usdc", "weth", "wbtc", "wusdc", "wusdt", "sui", "wapt", "wsol", "cetus", "afsui", "hasui", "vsui", "sca"];
11
+ export declare const SUPPORT_COLLATERALS: readonly ["usdc", "weth", "wbtc", "wusdc", "wusdt", "sui", "wapt", "wsol", "cetus", "afsui", "hasui", "vsui", "sca"];
12
+ export declare const SUPPORT_SPOOLS: readonly ["susdc", "sweth", "ssui", "swusdc", "swusdt", "scetus", "safsui", "shasui", "svsui"];
13
+ export declare const SUPPORT_SCOIN: readonly ["susdc", "ssui", "swusdc", "swusdt", "safsui", "shasui", "svsui", "sweth", "ssca", "scetus", "swsol", "swbtc"];
14
14
  export declare const SUPPORT_SPOOLS_REWARDS: readonly ["sui"];
15
15
  export declare const SUPPORT_BORROW_INCENTIVE_POOLS: readonly ["sui", "wusdc", "wusdt", "afsui", "hasui", "vsui", "weth", "sca"];
16
16
  export declare const SUPPORT_BORROW_INCENTIVE_REWARDS: readonly ["sui", "sca"];
package/dist/index.js CHANGED
@@ -87,6 +87,8 @@ var BORROW_FEE_PROTOCOL_ID = IS_VE_SCA_TEST ? "0xc9f859f98ca352a11b97a038c4b4162
87
87
  var SCA_COIN_TYPE = IS_VE_SCA_TEST ? `0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524::sca::SCA` : "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA";
88
88
  var OLD_BORROW_INCENTIVE_PROTOCOL_ID = "0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410";
89
89
  var SUPPORT_POOLS = [
90
+ "usdc",
91
+ // native USDC
90
92
  "weth",
91
93
  "wbtc",
92
94
  "wusdc",
@@ -101,6 +103,7 @@ var SUPPORT_POOLS = [
101
103
  "sca"
102
104
  ];
103
105
  var SUPPORT_COLLATERALS = [
106
+ "usdc",
104
107
  "weth",
105
108
  "wbtc",
106
109
  "wusdc",
@@ -115,6 +118,7 @@ var SUPPORT_COLLATERALS = [
115
118
  "sca"
116
119
  ];
117
120
  var SUPPORT_SPOOLS = [
121
+ "susdc",
118
122
  "sweth",
119
123
  "ssui",
120
124
  "swusdc",
@@ -125,6 +129,7 @@ var SUPPORT_SPOOLS = [
125
129
  "svsui"
126
130
  ];
127
131
  var SUPPORT_SCOIN = [
132
+ "susdc",
128
133
  "ssui",
129
134
  "swusdc",
130
135
  "swusdt",
@@ -167,6 +172,7 @@ var SUPPORT_PACKAGES = [
167
172
 
168
173
  // src/constants/enum.ts
169
174
  var coinDecimals = {
175
+ usdc: 6,
170
176
  weth: 8,
171
177
  wbtc: 8,
172
178
  wusdc: 6,
@@ -179,6 +185,7 @@ var coinDecimals = {
179
185
  hasui: 9,
180
186
  vsui: 9,
181
187
  sca: 9,
188
+ susdc: 6,
182
189
  sweth: 8,
183
190
  swbtc: 8,
184
191
  swusdc: 6,
@@ -193,6 +200,7 @@ var coinDecimals = {
193
200
  ssca: 9
194
201
  };
195
202
  var assetCoins = {
203
+ usdc: "usdc",
196
204
  weth: "weth",
197
205
  wbtc: "wbtc",
198
206
  wusdc: "wusdc",
@@ -207,6 +215,7 @@ var assetCoins = {
207
215
  sca: "sca"
208
216
  };
209
217
  var marketCoins = {
218
+ susdc: "susdc",
210
219
  sweth: "sweth",
211
220
  swbtc: "swbtc",
212
221
  swusdc: "swusdc",
@@ -221,6 +230,7 @@ var marketCoins = {
221
230
  ssca: "ssca"
222
231
  };
223
232
  var sCoins = {
233
+ susdc: "susdc",
224
234
  sweth: "sweth",
225
235
  swusdc: "swusdc",
226
236
  swusdt: "swusdt",
@@ -234,6 +244,7 @@ var sCoins = {
234
244
  swbtc: "swbtc"
235
245
  };
236
246
  var stakeMarketCoins = {
247
+ susdc: "susdc",
237
248
  sweth: "sweth",
238
249
  ssui: "ssui",
239
250
  swusdc: "swusdc",
@@ -251,7 +262,8 @@ var spoolRewardCoins = {
251
262
  scetus: "sui",
252
263
  safsui: "sui",
253
264
  shasui: "sui",
254
- svsui: "sui"
265
+ svsui: "sui",
266
+ susdc: "sui"
255
267
  };
256
268
  var borrowIncentiveRewardCoins = {
257
269
  sui: ["sui", "sca"],
@@ -264,6 +276,7 @@ var borrowIncentiveRewardCoins = {
264
276
  weth: ["sui"]
265
277
  };
266
278
  var coinIds = {
279
+ usdc: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7",
267
280
  sui: "0x0000000000000000000000000000000000000000000000000000000000000002",
268
281
  weth: "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",
269
282
  wbtc: "0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881",
@@ -289,6 +302,8 @@ var voloCoinIds = {
289
302
  vsui: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55"
290
303
  };
291
304
  var sCoinIds = {
305
+ susdc: "",
306
+ // TODO: sCoin contract
292
307
  ssui: "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI",
293
308
  scetus: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
294
309
  ssca: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
@@ -2313,19 +2328,21 @@ var queryMarket = async (query, indexer = false) => {
2313
2328
  const collaterals = {};
2314
2329
  if (indexer) {
2315
2330
  const marketIndexer = await query.indexer.getMarket();
2316
- for (const pool of Object.values(marketIndexer.pools)) {
2317
- pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
2318
- pool.coinWrappedType = query.utils.getCoinWrappedType(pool.coinName);
2319
- }
2320
- for (const collateral of Object.values(marketIndexer.collaterals)) {
2321
- collateral.coinPrice = coinPrices[collateral.coinName] || collateral.coinPrice;
2322
- collateral.coinWrappedType = query.utils.getCoinWrappedType(
2323
- collateral.coinName
2324
- );
2325
- }
2331
+ const updatePools = (item) => {
2332
+ item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
2333
+ item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
2334
+ pools[item.coinName] = item;
2335
+ };
2336
+ const updateCollaterals = (item) => {
2337
+ item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
2338
+ item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
2339
+ collaterals[item.coinName] = item;
2340
+ };
2341
+ Object.values(marketIndexer.pools).forEach(updatePools);
2342
+ Object.values(marketIndexer.collaterals).forEach(updateCollaterals);
2326
2343
  return {
2327
- pools: marketIndexer.pools,
2328
- collaterals: marketIndexer.collaterals
2344
+ pools,
2345
+ collaterals
2329
2346
  };
2330
2347
  }
2331
2348
  const packageId = query.address.get("core.packages.query.id");
@@ -2435,8 +2452,7 @@ var queryMarket = async (query, indexer = false) => {
2435
2452
  data: marketData
2436
2453
  };
2437
2454
  };
2438
- var getMarketPools = async (query, poolCoinNames, indexer = false) => {
2439
- poolCoinNames = poolCoinNames || [...SUPPORT_POOLS];
2455
+ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer = false) => {
2440
2456
  const marketId = query.address.get("core.market");
2441
2457
  const marketObjectResponse = await query.cache.queryGetObject(marketId, {
2442
2458
  showContent: true
@@ -2445,15 +2461,16 @@ var getMarketPools = async (query, poolCoinNames, indexer = false) => {
2445
2461
  const marketPools = {};
2446
2462
  if (indexer) {
2447
2463
  const marketPoolsIndexer = await query.indexer.getMarketPools();
2448
- for (const marketPool of Object.values(marketPoolsIndexer)) {
2464
+ const updateMarketPool = (marketPool) => {
2449
2465
  if (!poolCoinNames.includes(marketPool.coinName))
2450
- continue;
2466
+ return;
2451
2467
  marketPool.coinPrice = coinPrices[marketPool.coinName] || marketPool.coinPrice;
2452
2468
  marketPool.coinWrappedType = query.utils.getCoinWrappedType(
2453
2469
  marketPool.coinName
2454
2470
  );
2455
2471
  marketPools[marketPool.coinName] = marketPool;
2456
- }
2472
+ };
2473
+ Object.values(marketPoolsIndexer).forEach(updateMarketPool);
2457
2474
  return marketPools;
2458
2475
  }
2459
2476
  await Promise.allSettled(
@@ -2478,6 +2495,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2478
2495
  let borrowIndex;
2479
2496
  let interestModel;
2480
2497
  let borrowFeeRate;
2498
+ coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2481
2499
  if (indexer) {
2482
2500
  const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
2483
2501
  marketPoolIndexer.coinPrice = coinPrice || marketPoolIndexer.coinPrice;
@@ -2490,7 +2508,6 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2490
2508
  marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2491
2509
  showContent: true
2492
2510
  }))?.data;
2493
- coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2494
2511
  if (marketObject) {
2495
2512
  if (marketObject.content && "fields" in marketObject.content) {
2496
2513
  const fields = marketObject.content.fields;
@@ -2620,29 +2637,27 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2620
2637
  }
2621
2638
  return marketPool;
2622
2639
  };
2623
- var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) => {
2624
- collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
2640
+ var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLATERALS], indexer = false) => {
2625
2641
  const marketId = query.address.get("core.market");
2626
- const [marketObjectResponse, coinPrices] = await Promise.all([
2627
- await query.cache.queryGetObject(marketId, {
2628
- showContent: true
2629
- }),
2630
- await query.utils.getCoinPrices(collateralCoinNames ?? [])
2631
- ]);
2642
+ const coinPrices = await query.utils.getCoinPrices(collateralCoinNames ?? []);
2632
2643
  const marketCollaterals = {};
2633
2644
  if (indexer) {
2634
2645
  const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
2635
- for (const marketCollateral of Object.values(marketCollateralsIndexer)) {
2646
+ const updateMarketCollateral = (marketCollateral) => {
2636
2647
  if (!collateralCoinNames.includes(marketCollateral.coinName))
2637
- continue;
2648
+ return;
2638
2649
  marketCollateral.coinPrice = coinPrices[marketCollateral.coinName] || marketCollateral.coinPrice;
2639
2650
  marketCollateral.coinWrappedType = query.utils.getCoinWrappedType(
2640
2651
  marketCollateral.coinName
2641
2652
  );
2642
2653
  marketCollaterals[marketCollateral.coinName] = marketCollateral;
2643
- }
2654
+ };
2655
+ Object.values(marketCollateralsIndexer).forEach(updateMarketCollateral);
2644
2656
  return marketCollaterals;
2645
2657
  }
2658
+ const marketObjectResponse = await query.cache.queryGetObject(marketId, {
2659
+ showContent: true
2660
+ });
2646
2661
  await Promise.allSettled(
2647
2662
  collateralCoinNames.map(async (collateralCoinName) => {
2648
2663
  const marketCollateral = await getMarketCollateral(
@@ -2660,6 +2675,7 @@ var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) =
2660
2675
  return marketCollaterals;
2661
2676
  };
2662
2677
  var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
2678
+ coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
2663
2679
  if (indexer) {
2664
2680
  const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
2665
2681
  marketCollateralIndexer.coinPrice = coinPrice || marketCollateralIndexer.coinPrice;
@@ -2675,7 +2691,6 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
2675
2691
  marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2676
2692
  showContent: true
2677
2693
  }))?.data;
2678
- coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
2679
2694
  if (marketObject) {
2680
2695
  if (marketObject.content && "fields" in marketObject.content) {
2681
2696
  const fields = marketObject.content.fields;
@@ -2925,8 +2940,7 @@ var getFlashLoanFees = async (query, assetNames) => {
2925
2940
 
2926
2941
  // src/queries/spoolQuery.ts
2927
2942
  var import_utils5 = require("@mysten/sui.js/utils");
2928
- var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2929
- stakeMarketCoinNames = stakeMarketCoinNames || [...SUPPORT_SPOOLS];
2943
+ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexer = false) => {
2930
2944
  const stakeCoinNames = stakeMarketCoinNames.map(
2931
2945
  (stakeMarketCoinName) => query.utils.parseCoinName(stakeMarketCoinName)
2932
2946
  );
@@ -2941,9 +2955,9 @@ var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2941
2955
  const spools = {};
2942
2956
  if (indexer) {
2943
2957
  const spoolsIndexer = await query.indexer.getSpools();
2944
- for (const spool of Object.values(spoolsIndexer)) {
2958
+ const updateSpools = (spool) => {
2945
2959
  if (!stakeMarketCoinNames.includes(spool.marketCoinName))
2946
- continue;
2960
+ return;
2947
2961
  const coinName = query.utils.parseCoinName(
2948
2962
  spool.marketCoinName
2949
2963
  );
@@ -2955,7 +2969,8 @@ var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2955
2969
  spool.marketCoinPrice = (coinPrices[coinName] ?? 0) * (marketPool ? marketPool.conversionRate : 0) || spool.marketCoinPrice;
2956
2970
  spool.rewardCoinPrice = coinPrices[rewardCoinName] || spool.rewardCoinPrice;
2957
2971
  spools[spool.marketCoinName] = spool;
2958
- }
2972
+ };
2973
+ Object.values(spoolsIndexer).forEach(updateSpools);
2959
2974
  return spools;
2960
2975
  }
2961
2976
  for (const stakeMarketCoinName of stakeMarketCoinNames) {
@@ -2981,6 +2996,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
2981
2996
  `spool.pools.${marketCoinName}.rewardPoolId`
2982
2997
  );
2983
2998
  let spool = void 0;
2999
+ coinPrices = coinPrices || await query.utils.getCoinPrices([coinName]);
2984
3000
  if (indexer) {
2985
3001
  const spoolIndexer = await query.indexer.getSpool(marketCoinName);
2986
3002
  const coinName2 = query.utils.parseCoinName(marketCoinName);
@@ -3094,6 +3110,7 @@ var getStakeAccounts = async ({
3094
3110
  }
3095
3111
  } while (hasNextPage);
3096
3112
  const stakeAccounts = {
3113
+ susdc: [],
3097
3114
  sweth: [],
3098
3115
  ssui: [],
3099
3116
  swusdc: [],
@@ -3309,10 +3326,9 @@ var getStakeRewardPool = async ({
3309
3326
  // src/queries/borrowIncentiveQuery.ts
3310
3327
  var import_utils7 = require("@mysten/sui.js/utils");
3311
3328
  var import_bignumber3 = __toESM(require("bignumber.js"));
3312
- var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer = false) => {
3313
- borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
3314
- ...SUPPORT_BORROW_INCENTIVE_POOLS
3315
- ];
3329
+ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
3330
+ ...SUPPORT_BORROW_INCENTIVE_POOLS
3331
+ ], indexer = false) => {
3316
3332
  const borrowIncentivePools = {};
3317
3333
  const coinPrices = await query.utils.getCoinPrices(
3318
3334
  [
@@ -3324,14 +3340,15 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer
3324
3340
  );
3325
3341
  if (indexer) {
3326
3342
  const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
3327
- for (const borrowIncentivePool of Object.values(
3328
- borrowIncentivePoolsIndexer
3329
- )) {
3330
- if (!borrowIncentiveCoinNames.includes(borrowIncentivePool.coinName))
3331
- continue;
3332
- borrowIncentivePool.coinPrice = coinPrices[borrowIncentivePool.coinName] || borrowIncentivePool.coinPrice;
3333
- borrowIncentivePools[borrowIncentivePool.coinName] = borrowIncentivePool;
3334
- }
3343
+ const updateBorrowIncentivePool = (pool) => {
3344
+ if (!borrowIncentiveCoinNames.includes(pool.coinName))
3345
+ return;
3346
+ pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
3347
+ borrowIncentivePools[pool.coinName] = pool;
3348
+ };
3349
+ Object.values(borrowIncentivePoolsIndexer).forEach(
3350
+ updateBorrowIncentivePool
3351
+ );
3335
3352
  return borrowIncentivePools;
3336
3353
  }
3337
3354
  const queryPkgId = query.address.get("borrowIncentive.query");