@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.
package/dist/index.mjs CHANGED
@@ -9,6 +9,8 @@ var BORROW_FEE_PROTOCOL_ID = IS_VE_SCA_TEST ? "0xc9f859f98ca352a11b97a038c4b4162
9
9
  var SCA_COIN_TYPE = IS_VE_SCA_TEST ? `0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524::sca::SCA` : "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA";
10
10
  var OLD_BORROW_INCENTIVE_PROTOCOL_ID = "0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410";
11
11
  var SUPPORT_POOLS = [
12
+ "usdc",
13
+ // native USDC
12
14
  "weth",
13
15
  "wbtc",
14
16
  "wusdc",
@@ -23,6 +25,7 @@ var SUPPORT_POOLS = [
23
25
  "sca"
24
26
  ];
25
27
  var SUPPORT_COLLATERALS = [
28
+ "usdc",
26
29
  "weth",
27
30
  "wbtc",
28
31
  "wusdc",
@@ -37,6 +40,7 @@ var SUPPORT_COLLATERALS = [
37
40
  "sca"
38
41
  ];
39
42
  var SUPPORT_SPOOLS = [
43
+ "susdc",
40
44
  "sweth",
41
45
  "ssui",
42
46
  "swusdc",
@@ -47,6 +51,7 @@ var SUPPORT_SPOOLS = [
47
51
  "svsui"
48
52
  ];
49
53
  var SUPPORT_SCOIN = [
54
+ "susdc",
50
55
  "ssui",
51
56
  "swusdc",
52
57
  "swusdt",
@@ -89,6 +94,7 @@ var SUPPORT_PACKAGES = [
89
94
 
90
95
  // src/constants/enum.ts
91
96
  var coinDecimals = {
97
+ usdc: 6,
92
98
  weth: 8,
93
99
  wbtc: 8,
94
100
  wusdc: 6,
@@ -101,6 +107,7 @@ var coinDecimals = {
101
107
  hasui: 9,
102
108
  vsui: 9,
103
109
  sca: 9,
110
+ susdc: 6,
104
111
  sweth: 8,
105
112
  swbtc: 8,
106
113
  swusdc: 6,
@@ -115,6 +122,7 @@ var coinDecimals = {
115
122
  ssca: 9
116
123
  };
117
124
  var assetCoins = {
125
+ usdc: "usdc",
118
126
  weth: "weth",
119
127
  wbtc: "wbtc",
120
128
  wusdc: "wusdc",
@@ -129,6 +137,7 @@ var assetCoins = {
129
137
  sca: "sca"
130
138
  };
131
139
  var marketCoins = {
140
+ susdc: "susdc",
132
141
  sweth: "sweth",
133
142
  swbtc: "swbtc",
134
143
  swusdc: "swusdc",
@@ -143,6 +152,7 @@ var marketCoins = {
143
152
  ssca: "ssca"
144
153
  };
145
154
  var sCoins = {
155
+ susdc: "susdc",
146
156
  sweth: "sweth",
147
157
  swusdc: "swusdc",
148
158
  swusdt: "swusdt",
@@ -156,6 +166,7 @@ var sCoins = {
156
166
  swbtc: "swbtc"
157
167
  };
158
168
  var stakeMarketCoins = {
169
+ susdc: "susdc",
159
170
  sweth: "sweth",
160
171
  ssui: "ssui",
161
172
  swusdc: "swusdc",
@@ -173,7 +184,8 @@ var spoolRewardCoins = {
173
184
  scetus: "sui",
174
185
  safsui: "sui",
175
186
  shasui: "sui",
176
- svsui: "sui"
187
+ svsui: "sui",
188
+ susdc: "sui"
177
189
  };
178
190
  var borrowIncentiveRewardCoins = {
179
191
  sui: ["sui", "sca"],
@@ -186,6 +198,7 @@ var borrowIncentiveRewardCoins = {
186
198
  weth: ["sui"]
187
199
  };
188
200
  var coinIds = {
201
+ usdc: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7",
189
202
  sui: "0x0000000000000000000000000000000000000000000000000000000000000002",
190
203
  weth: "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",
191
204
  wbtc: "0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881",
@@ -211,6 +224,8 @@ var voloCoinIds = {
211
224
  vsui: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55"
212
225
  };
213
226
  var sCoinIds = {
227
+ susdc: "",
228
+ // TODO: sCoin contract
214
229
  ssui: "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI",
215
230
  scetus: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
216
231
  ssca: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
@@ -2239,19 +2254,21 @@ var queryMarket = async (query, indexer = false) => {
2239
2254
  const collaterals = {};
2240
2255
  if (indexer) {
2241
2256
  const marketIndexer = await query.indexer.getMarket();
2242
- for (const pool of Object.values(marketIndexer.pools)) {
2243
- pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
2244
- pool.coinWrappedType = query.utils.getCoinWrappedType(pool.coinName);
2245
- }
2246
- for (const collateral of Object.values(marketIndexer.collaterals)) {
2247
- collateral.coinPrice = coinPrices[collateral.coinName] || collateral.coinPrice;
2248
- collateral.coinWrappedType = query.utils.getCoinWrappedType(
2249
- collateral.coinName
2250
- );
2251
- }
2257
+ const updatePools = (item) => {
2258
+ item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
2259
+ item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
2260
+ pools[item.coinName] = item;
2261
+ };
2262
+ const updateCollaterals = (item) => {
2263
+ item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
2264
+ item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
2265
+ collaterals[item.coinName] = item;
2266
+ };
2267
+ Object.values(marketIndexer.pools).forEach(updatePools);
2268
+ Object.values(marketIndexer.collaterals).forEach(updateCollaterals);
2252
2269
  return {
2253
- pools: marketIndexer.pools,
2254
- collaterals: marketIndexer.collaterals
2270
+ pools,
2271
+ collaterals
2255
2272
  };
2256
2273
  }
2257
2274
  const packageId = query.address.get("core.packages.query.id");
@@ -2361,8 +2378,7 @@ var queryMarket = async (query, indexer = false) => {
2361
2378
  data: marketData
2362
2379
  };
2363
2380
  };
2364
- var getMarketPools = async (query, poolCoinNames, indexer = false) => {
2365
- poolCoinNames = poolCoinNames || [...SUPPORT_POOLS];
2381
+ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer = false) => {
2366
2382
  const marketId = query.address.get("core.market");
2367
2383
  const marketObjectResponse = await query.cache.queryGetObject(marketId, {
2368
2384
  showContent: true
@@ -2371,15 +2387,16 @@ var getMarketPools = async (query, poolCoinNames, indexer = false) => {
2371
2387
  const marketPools = {};
2372
2388
  if (indexer) {
2373
2389
  const marketPoolsIndexer = await query.indexer.getMarketPools();
2374
- for (const marketPool of Object.values(marketPoolsIndexer)) {
2390
+ const updateMarketPool = (marketPool) => {
2375
2391
  if (!poolCoinNames.includes(marketPool.coinName))
2376
- continue;
2392
+ return;
2377
2393
  marketPool.coinPrice = coinPrices[marketPool.coinName] || marketPool.coinPrice;
2378
2394
  marketPool.coinWrappedType = query.utils.getCoinWrappedType(
2379
2395
  marketPool.coinName
2380
2396
  );
2381
2397
  marketPools[marketPool.coinName] = marketPool;
2382
- }
2398
+ };
2399
+ Object.values(marketPoolsIndexer).forEach(updateMarketPool);
2383
2400
  return marketPools;
2384
2401
  }
2385
2402
  await Promise.allSettled(
@@ -2404,6 +2421,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2404
2421
  let borrowIndex;
2405
2422
  let interestModel;
2406
2423
  let borrowFeeRate;
2424
+ coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2407
2425
  if (indexer) {
2408
2426
  const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
2409
2427
  marketPoolIndexer.coinPrice = coinPrice || marketPoolIndexer.coinPrice;
@@ -2416,7 +2434,6 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2416
2434
  marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2417
2435
  showContent: true
2418
2436
  }))?.data;
2419
- coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2420
2437
  if (marketObject) {
2421
2438
  if (marketObject.content && "fields" in marketObject.content) {
2422
2439
  const fields = marketObject.content.fields;
@@ -2546,29 +2563,27 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2546
2563
  }
2547
2564
  return marketPool;
2548
2565
  };
2549
- var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) => {
2550
- collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
2566
+ var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLATERALS], indexer = false) => {
2551
2567
  const marketId = query.address.get("core.market");
2552
- const [marketObjectResponse, coinPrices] = await Promise.all([
2553
- await query.cache.queryGetObject(marketId, {
2554
- showContent: true
2555
- }),
2556
- await query.utils.getCoinPrices(collateralCoinNames ?? [])
2557
- ]);
2568
+ const coinPrices = await query.utils.getCoinPrices(collateralCoinNames ?? []);
2558
2569
  const marketCollaterals = {};
2559
2570
  if (indexer) {
2560
2571
  const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
2561
- for (const marketCollateral of Object.values(marketCollateralsIndexer)) {
2572
+ const updateMarketCollateral = (marketCollateral) => {
2562
2573
  if (!collateralCoinNames.includes(marketCollateral.coinName))
2563
- continue;
2574
+ return;
2564
2575
  marketCollateral.coinPrice = coinPrices[marketCollateral.coinName] || marketCollateral.coinPrice;
2565
2576
  marketCollateral.coinWrappedType = query.utils.getCoinWrappedType(
2566
2577
  marketCollateral.coinName
2567
2578
  );
2568
2579
  marketCollaterals[marketCollateral.coinName] = marketCollateral;
2569
- }
2580
+ };
2581
+ Object.values(marketCollateralsIndexer).forEach(updateMarketCollateral);
2570
2582
  return marketCollaterals;
2571
2583
  }
2584
+ const marketObjectResponse = await query.cache.queryGetObject(marketId, {
2585
+ showContent: true
2586
+ });
2572
2587
  await Promise.allSettled(
2573
2588
  collateralCoinNames.map(async (collateralCoinName) => {
2574
2589
  const marketCollateral = await getMarketCollateral(
@@ -2586,6 +2601,7 @@ var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) =
2586
2601
  return marketCollaterals;
2587
2602
  };
2588
2603
  var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
2604
+ coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
2589
2605
  if (indexer) {
2590
2606
  const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
2591
2607
  marketCollateralIndexer.coinPrice = coinPrice || marketCollateralIndexer.coinPrice;
@@ -2601,7 +2617,6 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
2601
2617
  marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2602
2618
  showContent: true
2603
2619
  }))?.data;
2604
- coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
2605
2620
  if (marketObject) {
2606
2621
  if (marketObject.content && "fields" in marketObject.content) {
2607
2622
  const fields = marketObject.content.fields;
@@ -2851,8 +2866,7 @@ var getFlashLoanFees = async (query, assetNames) => {
2851
2866
 
2852
2867
  // src/queries/spoolQuery.ts
2853
2868
  import { normalizeStructTag as normalizeStructTag4 } from "@mysten/sui.js/utils";
2854
- var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2855
- stakeMarketCoinNames = stakeMarketCoinNames || [...SUPPORT_SPOOLS];
2869
+ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexer = false) => {
2856
2870
  const stakeCoinNames = stakeMarketCoinNames.map(
2857
2871
  (stakeMarketCoinName) => query.utils.parseCoinName(stakeMarketCoinName)
2858
2872
  );
@@ -2867,9 +2881,9 @@ var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2867
2881
  const spools = {};
2868
2882
  if (indexer) {
2869
2883
  const spoolsIndexer = await query.indexer.getSpools();
2870
- for (const spool of Object.values(spoolsIndexer)) {
2884
+ const updateSpools = (spool) => {
2871
2885
  if (!stakeMarketCoinNames.includes(spool.marketCoinName))
2872
- continue;
2886
+ return;
2873
2887
  const coinName = query.utils.parseCoinName(
2874
2888
  spool.marketCoinName
2875
2889
  );
@@ -2881,7 +2895,8 @@ var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
2881
2895
  spool.marketCoinPrice = (coinPrices[coinName] ?? 0) * (marketPool ? marketPool.conversionRate : 0) || spool.marketCoinPrice;
2882
2896
  spool.rewardCoinPrice = coinPrices[rewardCoinName] || spool.rewardCoinPrice;
2883
2897
  spools[spool.marketCoinName] = spool;
2884
- }
2898
+ };
2899
+ Object.values(spoolsIndexer).forEach(updateSpools);
2885
2900
  return spools;
2886
2901
  }
2887
2902
  for (const stakeMarketCoinName of stakeMarketCoinNames) {
@@ -2907,6 +2922,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
2907
2922
  `spool.pools.${marketCoinName}.rewardPoolId`
2908
2923
  );
2909
2924
  let spool = void 0;
2925
+ coinPrices = coinPrices || await query.utils.getCoinPrices([coinName]);
2910
2926
  if (indexer) {
2911
2927
  const spoolIndexer = await query.indexer.getSpool(marketCoinName);
2912
2928
  const coinName2 = query.utils.parseCoinName(marketCoinName);
@@ -3020,6 +3036,7 @@ var getStakeAccounts = async ({
3020
3036
  }
3021
3037
  } while (hasNextPage);
3022
3038
  const stakeAccounts = {
3039
+ susdc: [],
3023
3040
  sweth: [],
3024
3041
  ssui: [],
3025
3042
  swusdc: [],
@@ -3235,10 +3252,9 @@ var getStakeRewardPool = async ({
3235
3252
  // src/queries/borrowIncentiveQuery.ts
3236
3253
  import { normalizeStructTag as normalizeStructTag5 } from "@mysten/sui.js/utils";
3237
3254
  import BigNumber3 from "bignumber.js";
3238
- var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer = false) => {
3239
- borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
3240
- ...SUPPORT_BORROW_INCENTIVE_POOLS
3241
- ];
3255
+ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
3256
+ ...SUPPORT_BORROW_INCENTIVE_POOLS
3257
+ ], indexer = false) => {
3242
3258
  const borrowIncentivePools = {};
3243
3259
  const coinPrices = await query.utils.getCoinPrices(
3244
3260
  [
@@ -3250,14 +3266,15 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer
3250
3266
  );
3251
3267
  if (indexer) {
3252
3268
  const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
3253
- for (const borrowIncentivePool of Object.values(
3254
- borrowIncentivePoolsIndexer
3255
- )) {
3256
- if (!borrowIncentiveCoinNames.includes(borrowIncentivePool.coinName))
3257
- continue;
3258
- borrowIncentivePool.coinPrice = coinPrices[borrowIncentivePool.coinName] || borrowIncentivePool.coinPrice;
3259
- borrowIncentivePools[borrowIncentivePool.coinName] = borrowIncentivePool;
3260
- }
3269
+ const updateBorrowIncentivePool = (pool) => {
3270
+ if (!borrowIncentiveCoinNames.includes(pool.coinName))
3271
+ return;
3272
+ pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
3273
+ borrowIncentivePools[pool.coinName] = pool;
3274
+ };
3275
+ Object.values(borrowIncentivePoolsIndexer).forEach(
3276
+ updateBorrowIncentivePool
3277
+ );
3261
3278
  return borrowIncentivePools;
3262
3279
  }
3263
3280
  const queryPkgId = query.address.get("borrowIncentive.query");