@scallop-io/sui-scallop-sdk 1.4.12 → 1.4.14-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.
package/dist/index.mjs CHANGED
@@ -114,18 +114,7 @@ var SUPPORT_WORMHOLE = [
114
114
  "wsol"
115
115
  ];
116
116
  var SUPPORT_SPOOLS_REWARDS = ["sui"];
117
- var SUPPORT_BORROW_INCENTIVE_POOLS = [
118
- "sui",
119
- "wusdc",
120
- "wusdt",
121
- "afsui",
122
- "hasui",
123
- "vsui",
124
- "weth",
125
- "sbeth",
126
- "sca",
127
- "usdc"
128
- ];
117
+ var SUPPORT_BORROW_INCENTIVE_POOLS = [...SUPPORT_POOLS];
129
118
  var SUPPORT_BORROW_INCENTIVE_REWARDS = [
130
119
  ...SUPPORT_POOLS,
131
120
  ...SUPPORT_SCOIN
@@ -290,12 +279,19 @@ var voloCoinIds = {
290
279
  vsui: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55"
291
280
  };
292
281
  var sCoinIds = {
282
+ // prod values
283
+ // ssui: '0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI',
284
+ // swusdc:
285
+ // '0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC',
286
+ // swusdt:
287
+ // '0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT',
288
+ // ssca: '0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA',
289
+ ssui: "0xf569919046f19a0c40b519ecfbb6ca0319698cd5908716c29b62ef56541f298b::scallop_sui::SCALLOP_SUI",
290
+ swusdt: "0xac781d9f73058ff5e69f9bf8dde32f2e8c71c66d7fe8497fc83b2d9182254b22::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
291
+ swusdc: "0xf5447c4305a486d8c8557559887c2c39449ddb5e748f15d33946d02a1663c158::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
292
+ ssca: "0x958428555e778e55918a59eb1c92c77f32b5c554fa3a5e56cd0815086b5072e7::scallop_sca::SCALLOP_SCA",
293
293
  susdc: "0x854950aa624b1df59fe64e630b2ba7c550642e9342267a33061d59fb31582da5::scallop_usdc::SCALLOP_USDC",
294
294
  ssbeth: "0xb14f82d8506d139eacef109688d1b71e7236bcce9b2c0ad526abcd6aa5be7de0::scallop_sb_eth::SCALLOP_SB_ETH",
295
- ssui: "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI",
296
- swusdc: "0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
297
- swusdt: "0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
298
- ssca: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
299
295
  scetus: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
300
296
  sweth: "0x67540ceb850d418679e69f1fb6b2093d6df78a2a699ffc733f7646096d552e9b::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
301
297
  safsui: "0x00671b1fa2a124f5be8bdae8b91ee711462c5d9e31bda232e70fd9607b523c88::scallop_af_sui::SCALLOP_AF_SUI",
@@ -984,7 +980,7 @@ var TEST_ADDRESSES = {
984
980
 
985
981
  // src/constants/tokenBucket.ts
986
982
  var DEFAULT_TOKENS_PER_INTERVAL = 10;
987
- var DEFAULT_INTERVAL_IN_MS = 50;
983
+ var DEFAULT_INTERVAL_IN_MS = 250;
988
984
 
989
985
  // src/constants/vesca.ts
990
986
  var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
@@ -1363,7 +1359,7 @@ var parseOriginBorrowIncentivesPoolPointData = (originBorrowIncentivePoolPointDa
1363
1359
  createdAt: Number(originBorrowIncentivePoolPointData.created_at)
1364
1360
  };
1365
1361
  };
1366
- var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
1362
+ var parseOriginBorrowIncentivePoolData = (utils, originBorrowIncentivePoolData) => {
1367
1363
  return {
1368
1364
  poolType: normalizeStructTag(originBorrowIncentivePoolData.pool_type.name),
1369
1365
  minStakes: Number(originBorrowIncentivePoolData.min_stakes),
@@ -1372,12 +1368,9 @@ var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
1372
1368
  poolPoints: originBorrowIncentivePoolData.points.reduce(
1373
1369
  (acc, point) => {
1374
1370
  const parsed = parseOriginBorrowIncentivesPoolPointData(point);
1375
- let name = parseStructTag(
1376
- parsed.pointType
1377
- ).name.toLowerCase();
1378
- if (sCoinRawNameToName[name]) {
1379
- name = sCoinRawNameToName[name];
1380
- }
1371
+ const name = utils.parseSCoinTypeNameToMarketCoinName(
1372
+ parseStructTag(parsed.pointType).name.toLowerCase()
1373
+ );
1381
1374
  acc[name] = parsed;
1382
1375
  return acc;
1383
1376
  },
@@ -1591,7 +1584,7 @@ var TokenBucket = class {
1591
1584
  return false;
1592
1585
  }
1593
1586
  };
1594
- var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 15, backoffFactor = 2) => {
1587
+ var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 15, backoffFactor = 1.25) => {
1595
1588
  let retries = 0;
1596
1589
  const tryRequest = async () => {
1597
1590
  if (tokenBucket.removeTokens(1)) {
@@ -1670,6 +1663,13 @@ var ScallopCache = class {
1670
1663
  })
1671
1664
  );
1672
1665
  }
1666
+ retryFn(errCount, err) {
1667
+ if (err.status === 429)
1668
+ return true;
1669
+ if (errCount >= 5)
1670
+ return false;
1671
+ return false;
1672
+ }
1673
1673
  /**
1674
1674
  * @description Provides cache for inspectTxn of the SuiKit.
1675
1675
  * @param QueryInspectTxnParams
@@ -1684,7 +1684,7 @@ var ScallopCache = class {
1684
1684
  const txBlock = new SuiTxBlock();
1685
1685
  txBlock.moveCall(queryTarget, args, typeArgs);
1686
1686
  const query = await this.queryClient.fetchQuery({
1687
- retry: 5,
1687
+ retry: this.retryFn,
1688
1688
  retryDelay: 1e3,
1689
1689
  queryKey: queryKeys.rpc.getInspectTxn(queryTarget, args, typeArgs),
1690
1690
  queryFn: async () => {
@@ -1704,7 +1704,7 @@ var ScallopCache = class {
1704
1704
  */
1705
1705
  async queryGetObject(objectId, options) {
1706
1706
  return this.queryClient.fetchQuery({
1707
- retry: 5,
1707
+ retry: this.retryFn,
1708
1708
  retryDelay: 1e3,
1709
1709
  queryKey: queryKeys.rpc.getObject(objectId, this.walletAddress, options),
1710
1710
  queryFn: async () => {
@@ -1729,7 +1729,7 @@ var ScallopCache = class {
1729
1729
  if (objectIds.length === 0)
1730
1730
  return [];
1731
1731
  return this.queryClient.fetchQuery({
1732
- retry: 5,
1732
+ retry: this.retryFn,
1733
1733
  retryDelay: 1e3,
1734
1734
  queryKey: queryKeys.rpc.getObjects(
1735
1735
  objectIds,
@@ -1751,7 +1751,7 @@ var ScallopCache = class {
1751
1751
  */
1752
1752
  async queryGetOwnedObjects(input) {
1753
1753
  return this.queryClient.fetchQuery({
1754
- retry: 5,
1754
+ retry: this.retryFn,
1755
1755
  retryDelay: 1e3,
1756
1756
  queryKey: queryKeys.rpc.getOwnedObjects(input),
1757
1757
  queryFn: async () => {
@@ -1764,7 +1764,7 @@ var ScallopCache = class {
1764
1764
  }
1765
1765
  async queryGetDynamicFields(input) {
1766
1766
  return this.queryClient.fetchQuery({
1767
- retry: 5,
1767
+ retry: this.retryFn,
1768
1768
  retryDelay: 1e3,
1769
1769
  queryKey: queryKeys.rpc.getDynamicFields(input),
1770
1770
  queryFn: async () => {
@@ -1777,7 +1777,7 @@ var ScallopCache = class {
1777
1777
  }
1778
1778
  async queryGetDynamicFieldObject(input) {
1779
1779
  return this.queryClient.fetchQuery({
1780
- retry: 5,
1780
+ retry: this.retryFn,
1781
1781
  retryDelay: (attemptIndex) => Math.min(1e3 * attemptIndex, 8e3),
1782
1782
  queryKey: queryKeys.rpc.getDynamicFieldObject(input),
1783
1783
  queryFn: async () => {
@@ -1790,7 +1790,7 @@ var ScallopCache = class {
1790
1790
  }
1791
1791
  async queryGetAllCoinBalances(owner) {
1792
1792
  return this.queryClient.fetchQuery({
1793
- retry: 5,
1793
+ retry: this.retryFn,
1794
1794
  retryDelay: 1e3,
1795
1795
  queryKey: queryKeys.rpc.getAllCoinBalances(owner),
1796
1796
  queryFn: async () => {
@@ -2534,7 +2534,10 @@ var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
2534
2534
  );
2535
2535
  for (const pool of borrowIncentivePoolsQueryData?.incentive_pools ?? []) {
2536
2536
  const borrowIncentivePoolPoints = {};
2537
- const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(pool);
2537
+ const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(
2538
+ query.utils,
2539
+ pool
2540
+ );
2538
2541
  const poolCoinType = normalizeStructTag3(pool.pool_type.name);
2539
2542
  const poolCoinName = query.utils.parseCoinNameFromType(
2540
2543
  poolCoinType
@@ -2548,12 +2551,9 @@ var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
2548
2551
  parsedBorrowIncentivePoolData.poolPoints
2549
2552
  )) {
2550
2553
  const rewardCoinType = poolPoint.pointType;
2551
- let rewardCoinName = query.utils.parseCoinNameFromType(
2554
+ const rewardCoinName = query.utils.parseCoinNameFromType(
2552
2555
  rewardCoinType
2553
2556
  );
2554
- if (sCoinRawNameToName[rewardCoinName]) {
2555
- rewardCoinName = sCoinRawNameToName[rewardCoinName];
2556
- }
2557
2557
  const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
2558
2558
  const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
2559
2559
  const symbol = query.utils.parseSymbol(rewardCoinName);
@@ -2701,7 +2701,7 @@ var supplyLimitZod = zod.object({
2701
2701
  value: zod.string()
2702
2702
  })
2703
2703
  });
2704
- var supplyLimitKeyType = `0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::SupplyLimitKey`;
2704
+ var supplyLimitKeyType = `0x6c23585e940a989588432509107e98bae06dbca4e333f26d0635d401b3c7c76d::market_dynamic_keys::SupplyLimitKey`;
2705
2705
  var getSupplyLimit = async (utils, poolName) => {
2706
2706
  try {
2707
2707
  const poolCoinType = utils.parseCoinType(poolName).slice(2);
@@ -2741,7 +2741,7 @@ var isolatedAssetZod = zod2.object({
2741
2741
  value: zod2.boolean()
2742
2742
  })
2743
2743
  });
2744
- var isolatedAssetKeyType = `0xe7dbb371a9595631f7964b7ece42255ad0e738cc85fe6da26c7221b220f01af6::market_dynamic_keys::IsolatedAssetKey`;
2744
+ var isolatedAssetKeyType = `0x6c23585e940a989588432509107e98bae06dbca4e333f26d0635d401b3c7c76d::market_dynamic_keys::IsolatedAssetKey`;
2745
2745
  var getIsolatedAssets = async (address) => {
2746
2746
  try {
2747
2747
  const marketObject = address.get("core.market");
@@ -2821,7 +2821,7 @@ var borrowLimitZod = zod3.object({
2821
2821
  value: zod3.string()
2822
2822
  })
2823
2823
  });
2824
- var borrowLimitKeyType = `0xe7dbb371a9595631f7964b7ece42255ad0e738cc85fe6da26c7221b220f01af6::market_dynamic_keys::BorrowLimitKey`;
2824
+ var borrowLimitKeyType = `0xb784ea287d944e478a3ceaa071f8885072cce6b7224cf245914dc2f9963f460e::market_dynamic_keys::BorrowLimitKey`;
2825
2825
  var getBorrowLimit = async (utils, poolName) => {
2826
2826
  try {
2827
2827
  const poolCoinType = utils.parseCoinType(poolName).slice(2);
@@ -3863,7 +3863,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
3863
3863
  const rewards = [];
3864
3864
  Object.entries(borrowIncentiveAccount.pointList).forEach(
3865
3865
  ([key, accountPoint]) => {
3866
- const poolPoint = borrowIncentivePool.points[key];
3866
+ const poolPoint = borrowIncentivePool.points[query.utils.parseSCoinTypeNameToMarketCoinName(key)];
3867
3867
  if (accountPoint && poolPoint) {
3868
3868
  let availableClaimAmount = BigNumber5(0);
3869
3869
  let availableClaimCoin = BigNumber5(0);
@@ -4895,13 +4895,14 @@ var ScallopUtils = class {
4895
4895
  }
4896
4896
  }
4897
4897
  /**
4898
- * Convert sCoin name to coin name.
4898
+ * Convert sCoin name to market coin name.
4899
4899
  * This function will parse new sCoin name `scallop_...` to its old market coin name which is shorter
4900
4900
  * e.g: `scallop_sui -> ssui
4901
+ * if no `scallop_...` is encountered, return coinName
4901
4902
  * @return sCoin name
4902
4903
  */
4903
- parseCoinNameFromSCoinName(coinName) {
4904
- return sCoinRawNameToName[coinName];
4904
+ parseSCoinTypeNameToMarketCoinName(coinName) {
4905
+ return sCoinRawNameToName[coinName] ?? coinName;
4905
4906
  }
4906
4907
  /**
4907
4908
  * Convert sCoin name into sCoin type
@@ -4950,6 +4951,9 @@ var ScallopUtils = class {
4950
4951
  }
4951
4952
  parseCoinNameFromType(coinType) {
4952
4953
  coinType = normalizeStructTag6(coinType);
4954
+ if (sCoinTypeToName[coinType]) {
4955
+ return sCoinTypeToName[coinType];
4956
+ }
4953
4957
  const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
4954
4958
  const coinTypeMatch = coinType.match(coinTypeRegex);
4955
4959
  const isMarketCoinType = coinType.includes("reserve::MarketCoin");