@scallop-io/sui-scallop-sdk 1.3.3-alpha.2 → 1.3.4-alpha.1

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.
Files changed (38) hide show
  1. package/dist/constants/coinGecko.d.ts +2 -0
  2. package/dist/constants/index.d.ts +6 -0
  3. package/dist/constants/poolAddress.d.ts +5 -0
  4. package/dist/constants/pyth.d.ts +2 -0
  5. package/dist/index.js +189 -40
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +182 -40
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/models/scallopIndexer.d.ts +6 -0
  10. package/dist/models/scallopQuery.d.ts +10 -4
  11. package/dist/models/scallopUtils.d.ts +6 -1
  12. package/dist/queries/sCoinQuery.d.ts +1 -1
  13. package/dist/queries/spoolQuery.d.ts +1 -1
  14. package/dist/queries/vescaQuery.d.ts +2 -2
  15. package/dist/types/query/portfolio.d.ts +1 -1
  16. package/dist/types/query/spool.d.ts +1 -0
  17. package/dist/types/query/vesca.d.ts +1 -1
  18. package/dist/types/utils.d.ts +12 -0
  19. package/dist/utils/util.d.ts +2 -2
  20. package/package.json +1 -1
  21. package/src/builders/borrowIncentiveBuilder.ts +3 -2
  22. package/src/constants/coinGecko.ts +18 -0
  23. package/src/constants/index.ts +6 -0
  24. package/src/constants/poolAddress.ts +94 -0
  25. package/src/constants/pyth.ts +19 -0
  26. package/src/models/scallopClient.ts +3 -3
  27. package/src/models/scallopIndexer.ts +9 -0
  28. package/src/models/scallopQuery.ts +9 -0
  29. package/src/models/scallopUtils.ts +25 -1
  30. package/src/queries/coreQuery.ts +9 -8
  31. package/src/queries/portfolioQuery.ts +1 -0
  32. package/src/queries/spoolQuery.ts +1 -0
  33. package/src/queries/vescaQuery.ts +4 -6
  34. package/src/types/query/portfolio.ts +1 -0
  35. package/src/types/query/spool.ts +1 -0
  36. package/src/types/query/vesca.ts +1 -1
  37. package/src/types/utils.ts +13 -0
  38. package/src/utils/util.ts +2 -1
package/dist/index.mjs CHANGED
@@ -1,3 +1,31 @@
1
+ // src/constants/cache.ts
2
+ var DEFAULT_CACHE_OPTIONS = {
3
+ defaultOptions: {
4
+ queries: {
5
+ staleTime: 5e3,
6
+ gcTime: 5e3
7
+ }
8
+ }
9
+ };
10
+
11
+ // src/constants/coinGecko.ts
12
+ var COIN_GECKGO_IDS = {
13
+ usdc: "usdc-coin",
14
+ sbeth: "ethereum",
15
+ weth: "ethereum",
16
+ wbtc: "bitcoin",
17
+ wusdc: "usdc-coin",
18
+ wusdt: "tether",
19
+ sui: "sui",
20
+ wapt: "aptos",
21
+ wsol: "solana",
22
+ cetus: "cetus-protocol",
23
+ afsui: "sui",
24
+ hasui: "sui",
25
+ vsui: "sui",
26
+ sca: "scallop-2"
27
+ };
28
+
1
29
  // src/constants/common.ts
2
30
  var API_BASE_URL = "https://sui.apis.scallop.io";
3
31
  var SDK_API_BASE_URL = "https://sdk.api.scallop.io";
@@ -292,6 +320,88 @@ var FlashLoanFeeObjectMap = {
292
320
  wsol: "0xe84bdb35b790fc7bdd1645122ac6ac0fc904531d6772c9e25904fece322c5f34"
293
321
  };
294
322
 
323
+ // src/constants/poolAddress.ts
324
+ var POOL_ADDRESSES = {
325
+ usdc: {
326
+ lendingPoolAddress: "0xd3be98bf540f7603eeb550c0c0a19dbfc78822f25158b5fa84ebd9609def415f",
327
+ collateralPoolAddress: "0x8f0d529ba179c5b3d508213003eab813aaae31f78226099639b9a69d1aec17af"
328
+ },
329
+ sbeth: {
330
+ lendingPoolAddress: "0x5f08c4f71d56dd3342c452cc70ffc47f2f4180146d821941b0b9c04761bb42e7",
331
+ collateralPoolAddress: "0xce0549a1cbe952e734f56646988e6b02bbae14667889a60e24d0d03540a6119f"
332
+ },
333
+ weth: {
334
+ lendingPoolAddress: "0xc8fcdff48efc265740ae0b74aae3faccae9ec00034039a113f3339798035108c",
335
+ collateralPoolAddress: "0xad7ced91ed6e7f2b81805561eee27fa6f3e72fdae561077334c7248583db4dbf"
336
+ },
337
+ wbtc: {
338
+ lendingPoolAddress: "0x65cc08a5aca0a0b8d72e1993ded8d145f06dd102fd0d8f285b92934faed564ab",
339
+ collateralPoolAddress: "0x1aa4e5cf743cd797b4eb8bf1e614f80ae2cf556ced426cddaaf190ffcd0e59c3"
340
+ },
341
+ wusdc: {
342
+ lendingPoolAddress: "0x9c9077abf7a29eebce41e33addbcd6f5246a5221dd733e56ea0f00ae1b25c9e8",
343
+ collateralPoolAddress: "0x75aacfb7dcbf92ee0111fc1bf975b12569e4ba632e81ed7ae5ac090d40cd3acb"
344
+ },
345
+ wusdt: {
346
+ lendingPoolAddress: "0xfbc056f126dd35adc1f8fe985e2cedc8010e687e8e851e1c5b99fdf63cd1c879",
347
+ collateralPoolAddress: "0x2260cb5b24929dd20a1742f37a61ff3ce4fde5cdb023e2d3ce2e0ce2d90719e3"
348
+ },
349
+ sui: {
350
+ lendingPoolAddress: "0x9c9077abf7a29eebce41e33addbcd6f5246a5221dd733e56ea0f00ae1b25c9e8",
351
+ collateralPoolAddress: "0x75aacfb7dcbf92ee0111fc1bf975b12569e4ba632e81ed7ae5ac090d40cd3acb"
352
+ },
353
+ wapt: {
354
+ lendingPoolAddress: "0xca8c14a24e0c32b198eaf479a3317461e3cc339097ce88eaf296a15df8dcfdf5",
355
+ collateralPoolAddress: "0xde33f9ac5bb0ed34598da4e64b4983832716ced65f172fbf267bcfe859c4ad9c"
356
+ },
357
+ wsol: {
358
+ lendingPoolAddress: "0x985682c42984cdfb03f9ff7d8923344c2fe096b1ae4b82ea17721af19d22a21f",
359
+ collateralPoolAddress: "0xdc1cc2c371a043ae8e3c3fe2d013c35f1346960b7dbb4c072982c5b794ed144f"
360
+ },
361
+ cetus: {
362
+ lendingPoolAddress: "0xc09858f60e74a1b671635bec4e8a2c84a0ff313eb87f525fba3258e88c6b6282",
363
+ collateralPoolAddress: "0xe363967e29b7b9c1245d6d46d63e719de8f90b37e3358c545b55d945ea0b676a"
364
+ },
365
+ afsui: {
366
+ lendingPoolAddress: "0x9b942a24ce390b7f5016d34a0217057bf9487b92aa6d7cc9894271dbbe62471a",
367
+ collateralPoolAddress: "0xe5e56f5c0e3072760b21f9d49a5cc793f37d736c412a9065c16e1265c74e6341"
368
+ },
369
+ hasui: {
370
+ lendingPoolAddress: "0x7ebc607f6bdeb659fb6506cb91c5cc1d47bb365cfd5d2e637ea765346ec84ed4",
371
+ collateralPoolAddress: "0xad9ed40d6486e4c26cec7370dffce8dc4821eb79178250b5938a34ccafd61e6d"
372
+ },
373
+ vsui: {
374
+ lendingPoolAddress: "0xda9257c0731d8822e8a438ebced13415850d705b779c79958dcf2aeb21fcb43d",
375
+ collateralPoolAddress: "0x4435e8b8ec2a04094d863aa52deb6ab6f8f47ed8778f4d9f1b27afc4a6e85f1e"
376
+ },
377
+ sca: {
378
+ lendingPoolAddress: "0x6fc7d4211fc7018b6c75e7b908b88f2e0536443239804a3d32af547637bd28d7",
379
+ collateralPoolAddress: "0xff677a5d9e9dc8f08f0a8681ebfc7481d1c7d57bc441f2881974adcdd7b13c31"
380
+ }
381
+ };
382
+
383
+ // src/constants/pyth.ts
384
+ var PYTH_ENDPOINTS = {
385
+ testnet: ["https://hermes-beta.pyth.network"],
386
+ mainnet: ["https://hermes.pyth.network", "https://scallop.rpc.p2p.world"]
387
+ };
388
+ var PYTH_FEED_IDS = {
389
+ usdc: "eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
390
+ sbeth: "ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",
391
+ weth: "ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",
392
+ wbtc: "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43",
393
+ wusdc: "eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
394
+ wusdt: "2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b",
395
+ sui: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
396
+ wapt: "03ae4db29ed4ae33d323568895aa00337e658e348b37509f5372ae51f0af00d5",
397
+ wsol: "ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d",
398
+ cetus: "e5b274b2611143df055d6e7cd8d93fe1961716bcd4dca1cad87a83bc1e78c1ef",
399
+ afsui: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
400
+ hasui: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
401
+ vsui: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
402
+ sca: "7e17f0ac105abe9214deb9944c30264f5986bf292869c6bd8e8da3ccd92d79bc"
403
+ };
404
+
295
405
  // src/constants/queryKeys.ts
296
406
  var queryKeys = {
297
407
  api: {
@@ -376,13 +486,6 @@ var queryKeys = {
376
486
  }
377
487
  };
378
488
 
379
- // src/constants/vesca.ts
380
- var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
381
- var MAX_LOCK_ROUNDS = 1460;
382
- var MAX_LOCK_DURATION = MAX_LOCK_ROUNDS * UNLOCK_ROUND_DURATION;
383
- var MIN_INITIAL_LOCK_AMOUNT = 1e10;
384
- var MIN_TOP_UP_AMOUNT = 1e9;
385
-
386
489
  // src/constants/testAddress.ts
387
490
  var TEST_ADDRESSES = {
388
491
  core: {
@@ -807,6 +910,17 @@ var TEST_ADDRESSES = {
807
910
  }
808
911
  };
809
912
 
913
+ // src/constants/tokenBucket.ts
914
+ var DEFAULT_TOKENS_PER_INTERVAL = 50;
915
+ var DEFAULT_INTERVAL_IN_MS = 300;
916
+
917
+ // src/constants/vesca.ts
918
+ var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
919
+ var MAX_LOCK_ROUNDS = 1460;
920
+ var MAX_LOCK_DURATION = MAX_LOCK_ROUNDS * UNLOCK_ROUND_DURATION;
921
+ var MIN_INITIAL_LOCK_AMOUNT = 1e10;
922
+ var MIN_TOP_UP_AMOUNT = 1e9;
923
+
810
924
  // src/models/scallop.ts
811
925
  import { SuiKit as SuiKit7 } from "@scallop-io/sui-kit";
812
926
 
@@ -820,16 +934,6 @@ import {
820
934
  normalizeStructTag as normalizeStructTag2
821
935
  } from "@scallop-io/sui-kit";
822
936
 
823
- // src/constants/cache.ts
824
- var DEFAULT_CACHE_OPTIONS = {
825
- defaultOptions: {
826
- queries: {
827
- staleTime: 5e3,
828
- gcTime: 5e3
829
- }
830
- }
831
- };
832
-
833
937
  // src/utils/builder.ts
834
938
  var requireSender = (txBlock) => {
835
939
  const sender = txBlock.blockData.sender;
@@ -1389,10 +1493,6 @@ var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
1389
1493
  return Math.floor(closestTwelveAM.getTime() / 1e3);
1390
1494
  };
1391
1495
 
1392
- // src/constants/tokenBucket.ts
1393
- var DEFAULT_TOKENS_PER_INTERVAL = 50;
1394
- var DEFAULT_INTERVAL_IN_MS = 300;
1395
-
1396
1496
  // src/utils/tokenBucket.ts
1397
1497
  var TokenBucket = class {
1398
1498
  constructor(tokensPerInterval, intervalInMs) {
@@ -2879,6 +2979,9 @@ var getObligations = async ({
2879
2979
  filter: {
2880
2980
  StructType: `${protocolObjectId}::obligation::ObligationKey`
2881
2981
  },
2982
+ options: {
2983
+ showContent: true
2984
+ },
2882
2985
  cursor: nextCursor,
2883
2986
  limit: 10
2884
2987
  });
@@ -2892,14 +2995,14 @@ var getObligations = async ({
2892
2995
  hasNextPage = false;
2893
2996
  }
2894
2997
  } while (hasNextPage);
2895
- const keyObjectIds = keyObjectsResponse.map((ref) => ref?.data?.objectId).filter((id) => id !== void 0);
2896
- const keyObjects = await address.cache.queryGetObjects(keyObjectIds);
2998
+ const keyObjects = keyObjectsResponse.filter((ref) => !!ref.data);
2897
2999
  const obligations = [];
2898
3000
  await Promise.allSettled(
2899
- keyObjects.map(async (keyObject) => {
2900
- const keyId = keyObject.objectId;
2901
- if (keyObject.content && "fields" in keyObject.content) {
2902
- const fields = keyObject.content.fields;
3001
+ keyObjects.map(async ({ data }) => {
3002
+ const keyId = data?.objectId;
3003
+ const content = data?.content;
3004
+ if (keyId && content && "fields" in content) {
3005
+ const fields = content.fields;
2903
3006
  const obligationId = String(fields.ownership.fields.of);
2904
3007
  const locked = await getObligationLocked(address.cache, obligationId);
2905
3008
  obligations.push({ id: obligationId, keyId, locked });
@@ -3167,6 +3270,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
3167
3270
  coinType: query.utils.parseCoinType(coinName),
3168
3271
  marketCoinType: query.utils.parseMarketCoinType(coinName),
3169
3272
  rewardCoinType: isMarketCoin(rewardCoinName) ? query.utils.parseMarketCoinType(rewardCoinName) : query.utils.parseCoinType(rewardCoinName),
3273
+ sCoinType: marketPool.sCoinType,
3170
3274
  coinDecimal: query.utils.getCoinDecimal(coinName),
3171
3275
  rewardCoinDecimal: query.utils.getCoinDecimal(rewardCoinName),
3172
3276
  coinPrice: coinPrices?.[coinName] ?? 0,
@@ -3763,6 +3867,7 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
3763
3867
  symbol: query.utils.parseSymbol(poolCoinName),
3764
3868
  coinType: query.utils.parseCoinType(poolCoinName),
3765
3869
  marketCoinType: query.utils.parseMarketCoinType(poolCoinName),
3870
+ sCoinType: marketPool?.sCoinType ?? "",
3766
3871
  coinDecimal,
3767
3872
  coinPrice: coinPrice ?? 0,
3768
3873
  conversionRate: marketPool?.conversionRate ?? 1,
@@ -4202,9 +4307,8 @@ var SuiObjectRefZod = zod3.object({
4202
4307
  digest: zod3.string(),
4203
4308
  version: zod3.string()
4204
4309
  });
4205
- var getVeSca = async (utils, veScaKey, ownerAddress) => {
4310
+ var getVeSca = async (utils, veScaKey) => {
4206
4311
  const tableId = utils.address.get(`vesca.tableId`);
4207
- veScaKey = veScaKey || (await getVescaKeys(utils, ownerAddress))[0];
4208
4312
  if (!veScaKey)
4209
4313
  return void 0;
4210
4314
  if (typeof veScaKey === "object") {
@@ -4383,12 +4487,6 @@ var getLoyaltyProgramInformations = async (query, veScaKey) => {
4383
4487
  return result;
4384
4488
  };
4385
4489
 
4386
- // src/constants/pyth.ts
4387
- var PYTH_ENDPOINTS = {
4388
- testnet: ["https://hermes-beta.pyth.network"],
4389
- mainnet: ["https://hermes.pyth.network", "https://scallop.rpc.p2p.world"]
4390
- };
4391
-
4392
4490
  // src/models/scallopUtils.ts
4393
4491
  var ScallopUtils = class {
4394
4492
  constructor(params, instance) {
@@ -4866,6 +4964,26 @@ var ScallopUtils = class {
4866
4964
  }
4867
4965
  return findClosestUnlockRound(newUnlockAtInSecondTimestamp);
4868
4966
  }
4967
+ /**
4968
+ * Get detailed contract address and price id information for supported pool in Scallop
4969
+ * @returns Supported pool informations
4970
+ */
4971
+ getSupportedPoolAddresses() {
4972
+ return SUPPORT_POOLS.map((poolName) => {
4973
+ const sCoinName = this.parseSCoinName(poolName);
4974
+ return {
4975
+ name: this.parseSymbol(poolName),
4976
+ coingeckoId: COIN_GECKGO_IDS[poolName],
4977
+ decimal: coinDecimals[poolName],
4978
+ pythFeedId: PYTH_FEED_IDS[poolName],
4979
+ ...POOL_ADDRESSES[poolName],
4980
+ sCoinAddress: sCoinIds[sCoinName],
4981
+ marketCoinAddress: this.parseMarketCoinType(poolName),
4982
+ coinAddress: this.parseCoinType(poolName),
4983
+ sCoinName: sCoinName ? this.parseSymbol(sCoinName) : void 0
4984
+ };
4985
+ });
4986
+ }
4869
4987
  };
4870
4988
 
4871
4989
  // src/models/scallopBuilder.ts
@@ -5800,13 +5918,14 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
5800
5918
  );
5801
5919
  if (!obligationLocked || unstakeObligationBeforeStake) {
5802
5920
  const bindedVeScaKey = await builder.query.getBindedVeScaKey(obligationArg);
5803
- if (veScaKey && veScaKey !== bindedVeScaKey || !bindedVeScaKey) {
5921
+ const _veScaKey = bindedVeScaKey ?? veScaKey;
5922
+ if (!_veScaKey) {
5804
5923
  txBlock.stakeObligation(obligationArg, obligationKeyArg);
5805
5924
  } else {
5806
5925
  txBlock.stakeObligationWithVesca(
5807
5926
  obligationArg,
5808
5927
  obligationKeyArg,
5809
- bindedVeScaKey
5928
+ _veScaKey
5810
5929
  );
5811
5930
  }
5812
5931
  }
@@ -6648,6 +6767,14 @@ var ScallopIndexer = class {
6648
6767
  throw Error("Failed to getTotalValueLocked.");
6649
6768
  }
6650
6769
  }
6770
+ /**
6771
+ * Get coin price index data.
6772
+ *
6773
+ * @return price data.
6774
+ */
6775
+ async getCoinPrice(poolCoinName) {
6776
+ return (await this.getMarketPool(poolCoinName))?.coinPrice ?? 0;
6777
+ }
6651
6778
  };
6652
6779
 
6653
6780
  // src/queries/sCoinQuery.ts
@@ -7275,6 +7402,14 @@ var ScallopQuery = class {
7275
7402
  async isIsolatedAsset(assetCoinName) {
7276
7403
  return isIsolatedAsset(this.utils, assetCoinName);
7277
7404
  }
7405
+ /**
7406
+ * Get pool coin price from indexer
7407
+ * @param coinName
7408
+ * @returns price data
7409
+ */
7410
+ async getCoinPriceByIndexer(poolName) {
7411
+ return this.indexer.getCoinPrice(poolName);
7412
+ }
7278
7413
  };
7279
7414
 
7280
7415
  // src/models/scallopBuilder.ts
@@ -7715,7 +7850,7 @@ var ScallopClient = class {
7715
7850
  );
7716
7851
  txBlock.transferObjects([coin], sender);
7717
7852
  if (sign && availableStake) {
7718
- await txBlock.stakeObligationQuick(obligationId, obligationKey);
7853
+ await txBlock.stakeObligationWithVeScaQuick(obligationId, obligationKey);
7719
7854
  }
7720
7855
  if (sign) {
7721
7856
  return await this.suiKit.signAndSendTxn(
@@ -7745,7 +7880,7 @@ var ScallopClient = class {
7745
7880
  }
7746
7881
  await txBlock.repayQuick(amount, poolCoinName, obligationId);
7747
7882
  if (sign && availableStake) {
7748
- await txBlock.stakeObligationQuick(obligationId, obligationKey);
7883
+ await txBlock.stakeObligationWithVeScaQuick(obligationId, obligationKey);
7749
7884
  }
7750
7885
  if (sign) {
7751
7886
  return await this.suiKit.signAndSendTxn(
@@ -7892,7 +8027,7 @@ var ScallopClient = class {
7892
8027
  const txBlock = this.builder.createTxBlock();
7893
8028
  const sender = walletAddress || this.walletAddress;
7894
8029
  txBlock.setSender(sender);
7895
- await txBlock.stakeObligationQuick(obligationId, obligationKeyId);
8030
+ await txBlock.stakeObligationWithVeScaQuick(obligationId, obligationKeyId);
7896
8031
  if (sign) {
7897
8032
  return await this.suiKit.signAndSendTxn(
7898
8033
  txBlock
@@ -8215,6 +8350,10 @@ export {
8215
8350
  ADDRESSES_ID,
8216
8351
  API_BASE_URL,
8217
8352
  BORROW_FEE_PROTOCOL_ID,
8353
+ COIN_GECKGO_IDS,
8354
+ DEFAULT_CACHE_OPTIONS,
8355
+ DEFAULT_INTERVAL_IN_MS,
8356
+ DEFAULT_TOKENS_PER_INTERVAL,
8218
8357
  FlashLoanFeeObjectMap,
8219
8358
  IS_VE_SCA_TEST,
8220
8359
  MAX_LOCK_DURATION,
@@ -8222,7 +8361,10 @@ export {
8222
8361
  MIN_INITIAL_LOCK_AMOUNT,
8223
8362
  MIN_TOP_UP_AMOUNT,
8224
8363
  OLD_BORROW_INCENTIVE_PROTOCOL_ID,
8364
+ POOL_ADDRESSES,
8225
8365
  PROTOCOL_OBJECT_ID,
8366
+ PYTH_ENDPOINTS,
8367
+ PYTH_FEED_IDS,
8226
8368
  SCA_COIN_TYPE,
8227
8369
  SDK_API_BASE_URL,
8228
8370
  SUPPORT_BORROW_INCENTIVE_POOLS,