@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.
@@ -14,7 +14,7 @@ export declare const SUPPORT_SCOIN: readonly ["susdc", "ssbeth", "ssui", "swusdc
14
14
  export declare const SUPPORT_SUI_BRIDGE: readonly ["sbeth"];
15
15
  export declare const SUPPORT_WORMHOLE: readonly ["wusdc", "wusdt", "weth", "wbtc", "wapt", "wsol"];
16
16
  export declare const SUPPORT_SPOOLS_REWARDS: readonly ["sui"];
17
- export declare const SUPPORT_BORROW_INCENTIVE_POOLS: readonly ["sui", "wusdc", "wusdt", "afsui", "hasui", "vsui", "weth", "sbeth", "sca", "usdc"];
17
+ export declare const SUPPORT_BORROW_INCENTIVE_POOLS: readonly ["usdc", "sbeth", "weth", "wbtc", "wusdc", "wusdt", "sui", "wapt", "wsol", "cetus", "afsui", "hasui", "vsui", "sca", "fud", "deep"];
18
18
  export declare const SUPPORT_BORROW_INCENTIVE_REWARDS: readonly ["usdc", "sbeth", "weth", "wbtc", "wusdc", "wusdt", "sui", "wapt", "wsol", "cetus", "afsui", "hasui", "vsui", "sca", "fud", "deep", "susdc", "ssbeth", "ssui", "swusdc", "swusdt", "safsui", "shasui", "svsui", "sweth", "ssca", "scetus", "swsol", "swbtc", "sdeep", "sfud"];
19
19
  export declare const SUPPORT_ORACLES: readonly ["supra", "switchboard", "pyth"];
20
20
  export declare const SUPPORT_PACKAGES: readonly ["coinDecimalsRegistry", "math", "whitelist", "x", "protocol", "protocolWhitelist", "query", "supra", "pyth", "switchboard", "xOracle", "testCoin"];
@@ -1,2 +1,2 @@
1
1
  export declare const DEFAULT_TOKENS_PER_INTERVAL = 10;
2
- export declare const DEFAULT_INTERVAL_IN_MS = 50;
2
+ export declare const DEFAULT_INTERVAL_IN_MS = 250;
package/dist/index.js CHANGED
@@ -206,18 +206,7 @@ var SUPPORT_WORMHOLE = [
206
206
  "wsol"
207
207
  ];
208
208
  var SUPPORT_SPOOLS_REWARDS = ["sui"];
209
- var SUPPORT_BORROW_INCENTIVE_POOLS = [
210
- "sui",
211
- "wusdc",
212
- "wusdt",
213
- "afsui",
214
- "hasui",
215
- "vsui",
216
- "weth",
217
- "sbeth",
218
- "sca",
219
- "usdc"
220
- ];
209
+ var SUPPORT_BORROW_INCENTIVE_POOLS = [...SUPPORT_POOLS];
221
210
  var SUPPORT_BORROW_INCENTIVE_REWARDS = [
222
211
  ...SUPPORT_POOLS,
223
212
  ...SUPPORT_SCOIN
@@ -382,12 +371,19 @@ var voloCoinIds = {
382
371
  vsui: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55"
383
372
  };
384
373
  var sCoinIds = {
374
+ // prod values
375
+ // ssui: '0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI',
376
+ // swusdc:
377
+ // '0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC',
378
+ // swusdt:
379
+ // '0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT',
380
+ // ssca: '0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA',
381
+ ssui: "0xf569919046f19a0c40b519ecfbb6ca0319698cd5908716c29b62ef56541f298b::scallop_sui::SCALLOP_SUI",
382
+ swusdt: "0xac781d9f73058ff5e69f9bf8dde32f2e8c71c66d7fe8497fc83b2d9182254b22::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
383
+ swusdc: "0xf5447c4305a486d8c8557559887c2c39449ddb5e748f15d33946d02a1663c158::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
384
+ ssca: "0x958428555e778e55918a59eb1c92c77f32b5c554fa3a5e56cd0815086b5072e7::scallop_sca::SCALLOP_SCA",
385
385
  susdc: "0x854950aa624b1df59fe64e630b2ba7c550642e9342267a33061d59fb31582da5::scallop_usdc::SCALLOP_USDC",
386
386
  ssbeth: "0xb14f82d8506d139eacef109688d1b71e7236bcce9b2c0ad526abcd6aa5be7de0::scallop_sb_eth::SCALLOP_SB_ETH",
387
- ssui: "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI",
388
- swusdc: "0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
389
- swusdt: "0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
390
- ssca: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
391
387
  scetus: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
392
388
  sweth: "0x67540ceb850d418679e69f1fb6b2093d6df78a2a699ffc733f7646096d552e9b::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
393
389
  safsui: "0x00671b1fa2a124f5be8bdae8b91ee711462c5d9e31bda232e70fd9607b523c88::scallop_af_sui::SCALLOP_AF_SUI",
@@ -1076,7 +1072,7 @@ var TEST_ADDRESSES = {
1076
1072
 
1077
1073
  // src/constants/tokenBucket.ts
1078
1074
  var DEFAULT_TOKENS_PER_INTERVAL = 10;
1079
- var DEFAULT_INTERVAL_IN_MS = 50;
1075
+ var DEFAULT_INTERVAL_IN_MS = 250;
1080
1076
 
1081
1077
  // src/constants/vesca.ts
1082
1078
  var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
@@ -1452,7 +1448,7 @@ var parseOriginBorrowIncentivesPoolPointData = (originBorrowIncentivePoolPointDa
1452
1448
  createdAt: Number(originBorrowIncentivePoolPointData.created_at)
1453
1449
  };
1454
1450
  };
1455
- var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
1451
+ var parseOriginBorrowIncentivePoolData = (utils, originBorrowIncentivePoolData) => {
1456
1452
  return {
1457
1453
  poolType: (0, import_utils.normalizeStructTag)(originBorrowIncentivePoolData.pool_type.name),
1458
1454
  minStakes: Number(originBorrowIncentivePoolData.min_stakes),
@@ -1461,12 +1457,9 @@ var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
1461
1457
  poolPoints: originBorrowIncentivePoolData.points.reduce(
1462
1458
  (acc, point) => {
1463
1459
  const parsed = parseOriginBorrowIncentivesPoolPointData(point);
1464
- let name = (0, import_utils.parseStructTag)(
1465
- parsed.pointType
1466
- ).name.toLowerCase();
1467
- if (sCoinRawNameToName[name]) {
1468
- name = sCoinRawNameToName[name];
1469
- }
1460
+ const name = utils.parseSCoinTypeNameToMarketCoinName(
1461
+ (0, import_utils.parseStructTag)(parsed.pointType).name.toLowerCase()
1462
+ );
1470
1463
  acc[name] = parsed;
1471
1464
  return acc;
1472
1465
  },
@@ -1680,7 +1673,7 @@ var TokenBucket = class {
1680
1673
  return false;
1681
1674
  }
1682
1675
  };
1683
- var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 15, backoffFactor = 2) => {
1676
+ var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 15, backoffFactor = 1.25) => {
1684
1677
  let retries = 0;
1685
1678
  const tryRequest = async () => {
1686
1679
  if (tokenBucket.removeTokens(1)) {
@@ -1759,6 +1752,13 @@ var ScallopCache = class {
1759
1752
  })
1760
1753
  );
1761
1754
  }
1755
+ retryFn(errCount, err) {
1756
+ if (err.status === 429)
1757
+ return true;
1758
+ if (errCount >= 5)
1759
+ return false;
1760
+ return false;
1761
+ }
1762
1762
  /**
1763
1763
  * @description Provides cache for inspectTxn of the SuiKit.
1764
1764
  * @param QueryInspectTxnParams
@@ -1773,7 +1773,7 @@ var ScallopCache = class {
1773
1773
  const txBlock = new import_sui_kit.SuiTxBlock();
1774
1774
  txBlock.moveCall(queryTarget, args, typeArgs);
1775
1775
  const query = await this.queryClient.fetchQuery({
1776
- retry: 5,
1776
+ retry: this.retryFn,
1777
1777
  retryDelay: 1e3,
1778
1778
  queryKey: queryKeys.rpc.getInspectTxn(queryTarget, args, typeArgs),
1779
1779
  queryFn: async () => {
@@ -1793,7 +1793,7 @@ var ScallopCache = class {
1793
1793
  */
1794
1794
  async queryGetObject(objectId, options) {
1795
1795
  return this.queryClient.fetchQuery({
1796
- retry: 5,
1796
+ retry: this.retryFn,
1797
1797
  retryDelay: 1e3,
1798
1798
  queryKey: queryKeys.rpc.getObject(objectId, this.walletAddress, options),
1799
1799
  queryFn: async () => {
@@ -1818,7 +1818,7 @@ var ScallopCache = class {
1818
1818
  if (objectIds.length === 0)
1819
1819
  return [];
1820
1820
  return this.queryClient.fetchQuery({
1821
- retry: 5,
1821
+ retry: this.retryFn,
1822
1822
  retryDelay: 1e3,
1823
1823
  queryKey: queryKeys.rpc.getObjects(
1824
1824
  objectIds,
@@ -1840,7 +1840,7 @@ var ScallopCache = class {
1840
1840
  */
1841
1841
  async queryGetOwnedObjects(input) {
1842
1842
  return this.queryClient.fetchQuery({
1843
- retry: 5,
1843
+ retry: this.retryFn,
1844
1844
  retryDelay: 1e3,
1845
1845
  queryKey: queryKeys.rpc.getOwnedObjects(input),
1846
1846
  queryFn: async () => {
@@ -1853,7 +1853,7 @@ var ScallopCache = class {
1853
1853
  }
1854
1854
  async queryGetDynamicFields(input) {
1855
1855
  return this.queryClient.fetchQuery({
1856
- retry: 5,
1856
+ retry: this.retryFn,
1857
1857
  retryDelay: 1e3,
1858
1858
  queryKey: queryKeys.rpc.getDynamicFields(input),
1859
1859
  queryFn: async () => {
@@ -1866,7 +1866,7 @@ var ScallopCache = class {
1866
1866
  }
1867
1867
  async queryGetDynamicFieldObject(input) {
1868
1868
  return this.queryClient.fetchQuery({
1869
- retry: 5,
1869
+ retry: this.retryFn,
1870
1870
  retryDelay: (attemptIndex) => Math.min(1e3 * attemptIndex, 8e3),
1871
1871
  queryKey: queryKeys.rpc.getDynamicFieldObject(input),
1872
1872
  queryFn: async () => {
@@ -1879,7 +1879,7 @@ var ScallopCache = class {
1879
1879
  }
1880
1880
  async queryGetAllCoinBalances(owner) {
1881
1881
  return this.queryClient.fetchQuery({
1882
- retry: 5,
1882
+ retry: this.retryFn,
1883
1883
  retryDelay: 1e3,
1884
1884
  queryKey: queryKeys.rpc.getAllCoinBalances(owner),
1885
1885
  queryFn: async () => {
@@ -2623,7 +2623,10 @@ var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
2623
2623
  );
2624
2624
  for (const pool of borrowIncentivePoolsQueryData?.incentive_pools ?? []) {
2625
2625
  const borrowIncentivePoolPoints = {};
2626
- const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(pool);
2626
+ const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(
2627
+ query.utils,
2628
+ pool
2629
+ );
2627
2630
  const poolCoinType = (0, import_utils3.normalizeStructTag)(pool.pool_type.name);
2628
2631
  const poolCoinName = query.utils.parseCoinNameFromType(
2629
2632
  poolCoinType
@@ -2637,12 +2640,9 @@ var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
2637
2640
  parsedBorrowIncentivePoolData.poolPoints
2638
2641
  )) {
2639
2642
  const rewardCoinType = poolPoint.pointType;
2640
- let rewardCoinName = query.utils.parseCoinNameFromType(
2643
+ const rewardCoinName = query.utils.parseCoinNameFromType(
2641
2644
  rewardCoinType
2642
2645
  );
2643
- if (sCoinRawNameToName[rewardCoinName]) {
2644
- rewardCoinName = sCoinRawNameToName[rewardCoinName];
2645
- }
2646
2646
  const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
2647
2647
  const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
2648
2648
  const symbol = query.utils.parseSymbol(rewardCoinName);
@@ -2790,7 +2790,7 @@ var supplyLimitZod = import_zod.z.object({
2790
2790
  value: import_zod.z.string()
2791
2791
  })
2792
2792
  });
2793
- var supplyLimitKeyType = `0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::SupplyLimitKey`;
2793
+ var supplyLimitKeyType = `0x6c23585e940a989588432509107e98bae06dbca4e333f26d0635d401b3c7c76d::market_dynamic_keys::SupplyLimitKey`;
2794
2794
  var getSupplyLimit = async (utils, poolName) => {
2795
2795
  try {
2796
2796
  const poolCoinType = utils.parseCoinType(poolName).slice(2);
@@ -2830,7 +2830,7 @@ var isolatedAssetZod = import_zod2.z.object({
2830
2830
  value: import_zod2.z.boolean()
2831
2831
  })
2832
2832
  });
2833
- var isolatedAssetKeyType = `0xe7dbb371a9595631f7964b7ece42255ad0e738cc85fe6da26c7221b220f01af6::market_dynamic_keys::IsolatedAssetKey`;
2833
+ var isolatedAssetKeyType = `0x6c23585e940a989588432509107e98bae06dbca4e333f26d0635d401b3c7c76d::market_dynamic_keys::IsolatedAssetKey`;
2834
2834
  var getIsolatedAssets = async (address) => {
2835
2835
  try {
2836
2836
  const marketObject = address.get("core.market");
@@ -2910,7 +2910,7 @@ var borrowLimitZod = import_zod3.z.object({
2910
2910
  value: import_zod3.z.string()
2911
2911
  })
2912
2912
  });
2913
- var borrowLimitKeyType = `0xe7dbb371a9595631f7964b7ece42255ad0e738cc85fe6da26c7221b220f01af6::market_dynamic_keys::BorrowLimitKey`;
2913
+ var borrowLimitKeyType = `0xb784ea287d944e478a3ceaa071f8885072cce6b7224cf245914dc2f9963f460e::market_dynamic_keys::BorrowLimitKey`;
2914
2914
  var getBorrowLimit = async (utils, poolName) => {
2915
2915
  try {
2916
2916
  const poolCoinType = utils.parseCoinType(poolName).slice(2);
@@ -3952,7 +3952,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
3952
3952
  const rewards = [];
3953
3953
  Object.entries(borrowIncentiveAccount.pointList).forEach(
3954
3954
  ([key, accountPoint]) => {
3955
- const poolPoint = borrowIncentivePool.points[key];
3955
+ const poolPoint = borrowIncentivePool.points[query.utils.parseSCoinTypeNameToMarketCoinName(key)];
3956
3956
  if (accountPoint && poolPoint) {
3957
3957
  let availableClaimAmount = (0, import_bignumber5.default)(0);
3958
3958
  let availableClaimCoin = (0, import_bignumber5.default)(0);
@@ -4984,13 +4984,14 @@ var ScallopUtils = class {
4984
4984
  }
4985
4985
  }
4986
4986
  /**
4987
- * Convert sCoin name to coin name.
4987
+ * Convert sCoin name to market coin name.
4988
4988
  * This function will parse new sCoin name `scallop_...` to its old market coin name which is shorter
4989
4989
  * e.g: `scallop_sui -> ssui
4990
+ * if no `scallop_...` is encountered, return coinName
4990
4991
  * @return sCoin name
4991
4992
  */
4992
- parseCoinNameFromSCoinName(coinName) {
4993
- return sCoinRawNameToName[coinName];
4993
+ parseSCoinTypeNameToMarketCoinName(coinName) {
4994
+ return sCoinRawNameToName[coinName] ?? coinName;
4994
4995
  }
4995
4996
  /**
4996
4997
  * Convert sCoin name into sCoin type
@@ -5039,6 +5040,9 @@ var ScallopUtils = class {
5039
5040
  }
5040
5041
  parseCoinNameFromType(coinType) {
5041
5042
  coinType = (0, import_utils10.normalizeStructTag)(coinType);
5043
+ if (sCoinTypeToName[coinType]) {
5044
+ return sCoinTypeToName[coinType];
5045
+ }
5042
5046
  const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
5043
5047
  const coinTypeMatch = coinType.match(coinTypeRegex);
5044
5048
  const isMarketCoinType = coinType.includes("reserve::MarketCoin");