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

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 (103) hide show
  1. package/dist/index.js +1258 -1092
  2. package/dist/index.js.map +1 -1
  3. package/dist/index.mjs +1249 -1092
  4. package/dist/index.mjs.map +1 -1
  5. package/package.json +2 -2
  6. package/src/builders/loyaltyProgramBuilder.ts +1 -1
  7. package/src/constants/coinGecko.ts +18 -0
  8. package/src/constants/common.ts +0 -1
  9. package/src/constants/enum.ts +8 -0
  10. package/src/constants/index.ts +6 -0
  11. package/src/constants/poolAddress.ts +94 -0
  12. package/src/constants/pyth.ts +19 -0
  13. package/src/constants/queryKeys.ts +1 -5
  14. package/src/constants/rpc.ts +16 -0
  15. package/src/constants/tokenBucket.ts +1 -1
  16. package/src/models/scallop.ts +3 -2
  17. package/src/models/scallopAddress.ts +2 -2
  18. package/src/models/scallopBuilder.ts +4 -3
  19. package/src/models/scallopCache.ts +1 -1
  20. package/src/models/scallopClient.ts +27 -26
  21. package/src/models/scallopQuery.ts +58 -15
  22. package/src/models/scallopUtils.ts +96 -96
  23. package/src/models/suiKit.ts +11 -0
  24. package/src/queries/borrowIncentiveQuery.ts +6 -13
  25. package/src/queries/coreQuery.ts +37 -22
  26. package/src/queries/loyaltyProgramQuery.ts +1 -1
  27. package/src/queries/portfolioQuery.ts +55 -34
  28. package/src/queries/spoolQuery.ts +17 -17
  29. package/src/types/utils.ts +13 -0
  30. package/src/utils/tokenBucket.ts +2 -1
  31. package/src/utils/util.ts +2 -1
  32. package/dist/builders/borrowIncentiveBuilder.d.ts +0 -12
  33. package/dist/builders/coreBuilder.d.ts +0 -12
  34. package/dist/builders/index.d.ts +0 -12
  35. package/dist/builders/loyaltyProgramBuilder.d.ts +0 -12
  36. package/dist/builders/oracle.d.ts +0 -14
  37. package/dist/builders/referralBuilder.d.ts +0 -12
  38. package/dist/builders/sCoinBuilder.d.ts +0 -4
  39. package/dist/builders/spoolBuilder.d.ts +0 -12
  40. package/dist/builders/vescaBuilder.d.ts +0 -25
  41. package/dist/constants/cache.d.ts +0 -14
  42. package/dist/constants/common.d.ts +0 -20
  43. package/dist/constants/enum.d.ts +0 -13
  44. package/dist/constants/flashloan.d.ts +0 -2
  45. package/dist/constants/index.d.ts +0 -5
  46. package/dist/constants/pyth.d.ts +0 -3
  47. package/dist/constants/queryKeys.d.ts +0 -58
  48. package/dist/constants/testAddress.d.ts +0 -2
  49. package/dist/constants/tokenBucket.d.ts +0 -2
  50. package/dist/constants/vesca.d.ts +0 -5
  51. package/dist/index.d.ts +0 -3
  52. package/dist/models/index.d.ts +0 -8
  53. package/dist/models/scallop.d.ts +0 -74
  54. package/dist/models/scallopAddress.d.ts +0 -150
  55. package/dist/models/scallopBuilder.d.ts +0 -89
  56. package/dist/models/scallopCache.d.ts +0 -74
  57. package/dist/models/scallopClient.d.ts +0 -321
  58. package/dist/models/scallopIndexer.d.ts +0 -89
  59. package/dist/models/scallopPrice.d.ts +0 -0
  60. package/dist/models/scallopQuery.d.ts +0 -474
  61. package/dist/models/scallopUtils.d.ts +0 -217
  62. package/dist/queries/borrowIncentiveQuery.d.ts +0 -61
  63. package/dist/queries/coreQuery.d.ts +0 -167
  64. package/dist/queries/index.d.ts +0 -8
  65. package/dist/queries/isolatedAsset.d.ts +0 -14
  66. package/dist/queries/loyaltyProgramQuery.d.ts +0 -10
  67. package/dist/queries/portfolioQuery.d.ts +0 -73
  68. package/dist/queries/priceQuery.d.ts +0 -16
  69. package/dist/queries/referralQuery.d.ts +0 -7
  70. package/dist/queries/sCoinQuery.d.ts +0 -41
  71. package/dist/queries/spoolQuery.d.ts +0 -70
  72. package/dist/queries/supplyLimit.d.ts +0 -9
  73. package/dist/queries/vescaQuery.d.ts +0 -36
  74. package/dist/types/address.d.ts +0 -107
  75. package/dist/types/builder/borrowIncentive.d.ts +0 -35
  76. package/dist/types/builder/core.d.ts +0 -56
  77. package/dist/types/builder/index.d.ts +0 -24
  78. package/dist/types/builder/loyaltyProgram.d.ts +0 -23
  79. package/dist/types/builder/referral.d.ts +0 -30
  80. package/dist/types/builder/sCoin.d.ts +0 -37
  81. package/dist/types/builder/spool.d.ts +0 -29
  82. package/dist/types/builder/vesca.d.ts +0 -51
  83. package/dist/types/constant/common.d.ts +0 -24
  84. package/dist/types/constant/enum.d.ts +0 -48
  85. package/dist/types/constant/index.d.ts +0 -2
  86. package/dist/types/index.d.ts +0 -6
  87. package/dist/types/model.d.ts +0 -54
  88. package/dist/types/query/borrowIncentive.d.ts +0 -124
  89. package/dist/types/query/core.d.ts +0 -361
  90. package/dist/types/query/index.d.ts +0 -7
  91. package/dist/types/query/loyaltyProgram.d.ts +0 -5
  92. package/dist/types/query/portfolio.d.ts +0 -115
  93. package/dist/types/query/sCoin.d.ts +0 -1
  94. package/dist/types/query/spool.d.ts +0 -122
  95. package/dist/types/query/vesca.d.ts +0 -26
  96. package/dist/types/utils.d.ts +0 -9
  97. package/dist/utils/builder.d.ts +0 -15
  98. package/dist/utils/index.d.ts +0 -5
  99. package/dist/utils/indexer.d.ts +0 -17
  100. package/dist/utils/query.d.ts +0 -62
  101. package/dist/utils/tokenBucket.d.ts +0 -11
  102. package/dist/utils/util.d.ts +0 -26
  103. package/src/models/scallopPrice.ts +0 -0
package/dist/index.js CHANGED
@@ -33,6 +33,10 @@ __export(src_exports, {
33
33
  ADDRESSES_ID: () => ADDRESSES_ID,
34
34
  API_BASE_URL: () => API_BASE_URL,
35
35
  BORROW_FEE_PROTOCOL_ID: () => BORROW_FEE_PROTOCOL_ID,
36
+ COIN_GECKGO_IDS: () => COIN_GECKGO_IDS,
37
+ DEFAULT_CACHE_OPTIONS: () => DEFAULT_CACHE_OPTIONS,
38
+ DEFAULT_INTERVAL_IN_MS: () => DEFAULT_INTERVAL_IN_MS,
39
+ DEFAULT_TOKENS_PER_INTERVAL: () => DEFAULT_TOKENS_PER_INTERVAL,
36
40
  FlashLoanFeeObjectMap: () => FlashLoanFeeObjectMap,
37
41
  IS_VE_SCA_TEST: () => IS_VE_SCA_TEST,
38
42
  MAX_LOCK_DURATION: () => MAX_LOCK_DURATION,
@@ -40,7 +44,10 @@ __export(src_exports, {
40
44
  MIN_INITIAL_LOCK_AMOUNT: () => MIN_INITIAL_LOCK_AMOUNT,
41
45
  MIN_TOP_UP_AMOUNT: () => MIN_TOP_UP_AMOUNT,
42
46
  OLD_BORROW_INCENTIVE_PROTOCOL_ID: () => OLD_BORROW_INCENTIVE_PROTOCOL_ID,
47
+ POOL_ADDRESSES: () => POOL_ADDRESSES,
43
48
  PROTOCOL_OBJECT_ID: () => PROTOCOL_OBJECT_ID,
49
+ PYTH_ENDPOINTS: () => PYTH_ENDPOINTS,
50
+ PYTH_FEED_IDS: () => PYTH_FEED_IDS,
44
51
  SCA_COIN_TYPE: () => SCA_COIN_TYPE,
45
52
  SDK_API_BASE_URL: () => SDK_API_BASE_URL,
46
53
  SUPPORT_BORROW_INCENTIVE_POOLS: () => SUPPORT_BORROW_INCENTIVE_POOLS,
@@ -62,6 +69,7 @@ __export(src_exports, {
62
69
  ScallopIndexer: () => ScallopIndexer,
63
70
  ScallopQuery: () => ScallopQuery,
64
71
  ScallopUtils: () => ScallopUtils,
72
+ TEST_ADDRESSES: () => TEST_ADDRESSES,
65
73
  UNLOCK_ROUND_DURATION: () => UNLOCK_ROUND_DURATION,
66
74
  USE_TEST_ADDRESS: () => USE_TEST_ADDRESS,
67
75
  assetCoins: () => assetCoins,
@@ -71,6 +79,7 @@ __export(src_exports, {
71
79
  marketCoins: () => marketCoins,
72
80
  queryKeys: () => queryKeys,
73
81
  sCoinIds: () => sCoinIds,
82
+ sCoinTypeToName: () => sCoinTypeToName,
74
83
  sCoins: () => sCoins,
75
84
  spoolRewardCoins: () => spoolRewardCoins,
76
85
  stakeMarketCoins: () => stakeMarketCoins,
@@ -80,6 +89,34 @@ __export(src_exports, {
80
89
  });
81
90
  module.exports = __toCommonJS(src_exports);
82
91
 
92
+ // src/constants/cache.ts
93
+ var DEFAULT_CACHE_OPTIONS = {
94
+ defaultOptions: {
95
+ queries: {
96
+ staleTime: 5e3,
97
+ gcTime: 5e3
98
+ }
99
+ }
100
+ };
101
+
102
+ // src/constants/coinGecko.ts
103
+ var COIN_GECKGO_IDS = {
104
+ usdc: "usdc-coin",
105
+ sbeth: "ethereum",
106
+ weth: "ethereum",
107
+ wbtc: "bitcoin",
108
+ wusdc: "usdc-coin",
109
+ wusdt: "tether",
110
+ sui: "sui",
111
+ wapt: "aptos",
112
+ wsol: "solana",
113
+ cetus: "cetus-protocol",
114
+ afsui: "sui",
115
+ hasui: "sui",
116
+ vsui: "sui",
117
+ sca: "scallop-2"
118
+ };
119
+
83
120
  // src/constants/common.ts
84
121
  var API_BASE_URL = "https://sui.apis.scallop.io";
85
122
  var SDK_API_BASE_URL = "https://sdk.api.scallop.io";
@@ -348,6 +385,13 @@ var sCoinIds = {
348
385
  swsol: "0x1392650f2eca9e3f6ffae3ff89e42a3590d7102b80e2b430f674730bc30d3259::scallop_wormhole_sol::SCALLOP_WORMHOLE_SOL",
349
386
  swbtc: "0x2cf76a9cf5d3337961d1154283234f94da2dcff18544dfe5cbdef65f319591b5::scallop_wormhole_btc::SCALLOP_WORMHOLE_BTC"
350
387
  };
388
+ var sCoinTypeToName = Object.entries(sCoinIds).reduce(
389
+ (acc, [coinName, coinType]) => {
390
+ acc[coinType] = coinName;
391
+ return acc;
392
+ },
393
+ {}
394
+ );
351
395
 
352
396
  // src/constants/flashloan.ts
353
397
  var FlashLoanFeeObjectMap = {
@@ -365,6 +409,88 @@ var FlashLoanFeeObjectMap = {
365
409
  wsol: "0xe84bdb35b790fc7bdd1645122ac6ac0fc904531d6772c9e25904fece322c5f34"
366
410
  };
367
411
 
412
+ // src/constants/poolAddress.ts
413
+ var POOL_ADDRESSES = {
414
+ usdc: {
415
+ lendingPoolAddress: "0xd3be98bf540f7603eeb550c0c0a19dbfc78822f25158b5fa84ebd9609def415f",
416
+ collateralPoolAddress: "0x8f0d529ba179c5b3d508213003eab813aaae31f78226099639b9a69d1aec17af"
417
+ },
418
+ sbeth: {
419
+ lendingPoolAddress: "0x5f08c4f71d56dd3342c452cc70ffc47f2f4180146d821941b0b9c04761bb42e7",
420
+ collateralPoolAddress: "0xce0549a1cbe952e734f56646988e6b02bbae14667889a60e24d0d03540a6119f"
421
+ },
422
+ weth: {
423
+ lendingPoolAddress: "0xc8fcdff48efc265740ae0b74aae3faccae9ec00034039a113f3339798035108c",
424
+ collateralPoolAddress: "0xad7ced91ed6e7f2b81805561eee27fa6f3e72fdae561077334c7248583db4dbf"
425
+ },
426
+ wbtc: {
427
+ lendingPoolAddress: "0x65cc08a5aca0a0b8d72e1993ded8d145f06dd102fd0d8f285b92934faed564ab",
428
+ collateralPoolAddress: "0x1aa4e5cf743cd797b4eb8bf1e614f80ae2cf556ced426cddaaf190ffcd0e59c3"
429
+ },
430
+ wusdc: {
431
+ lendingPoolAddress: "0x9c9077abf7a29eebce41e33addbcd6f5246a5221dd733e56ea0f00ae1b25c9e8",
432
+ collateralPoolAddress: "0x75aacfb7dcbf92ee0111fc1bf975b12569e4ba632e81ed7ae5ac090d40cd3acb"
433
+ },
434
+ wusdt: {
435
+ lendingPoolAddress: "0xfbc056f126dd35adc1f8fe985e2cedc8010e687e8e851e1c5b99fdf63cd1c879",
436
+ collateralPoolAddress: "0x2260cb5b24929dd20a1742f37a61ff3ce4fde5cdb023e2d3ce2e0ce2d90719e3"
437
+ },
438
+ sui: {
439
+ lendingPoolAddress: "0x9c9077abf7a29eebce41e33addbcd6f5246a5221dd733e56ea0f00ae1b25c9e8",
440
+ collateralPoolAddress: "0x75aacfb7dcbf92ee0111fc1bf975b12569e4ba632e81ed7ae5ac090d40cd3acb"
441
+ },
442
+ wapt: {
443
+ lendingPoolAddress: "0xca8c14a24e0c32b198eaf479a3317461e3cc339097ce88eaf296a15df8dcfdf5",
444
+ collateralPoolAddress: "0xde33f9ac5bb0ed34598da4e64b4983832716ced65f172fbf267bcfe859c4ad9c"
445
+ },
446
+ wsol: {
447
+ lendingPoolAddress: "0x985682c42984cdfb03f9ff7d8923344c2fe096b1ae4b82ea17721af19d22a21f",
448
+ collateralPoolAddress: "0xdc1cc2c371a043ae8e3c3fe2d013c35f1346960b7dbb4c072982c5b794ed144f"
449
+ },
450
+ cetus: {
451
+ lendingPoolAddress: "0xc09858f60e74a1b671635bec4e8a2c84a0ff313eb87f525fba3258e88c6b6282",
452
+ collateralPoolAddress: "0xe363967e29b7b9c1245d6d46d63e719de8f90b37e3358c545b55d945ea0b676a"
453
+ },
454
+ afsui: {
455
+ lendingPoolAddress: "0x9b942a24ce390b7f5016d34a0217057bf9487b92aa6d7cc9894271dbbe62471a",
456
+ collateralPoolAddress: "0xe5e56f5c0e3072760b21f9d49a5cc793f37d736c412a9065c16e1265c74e6341"
457
+ },
458
+ hasui: {
459
+ lendingPoolAddress: "0x7ebc607f6bdeb659fb6506cb91c5cc1d47bb365cfd5d2e637ea765346ec84ed4",
460
+ collateralPoolAddress: "0xad9ed40d6486e4c26cec7370dffce8dc4821eb79178250b5938a34ccafd61e6d"
461
+ },
462
+ vsui: {
463
+ lendingPoolAddress: "0xda9257c0731d8822e8a438ebced13415850d705b779c79958dcf2aeb21fcb43d",
464
+ collateralPoolAddress: "0x4435e8b8ec2a04094d863aa52deb6ab6f8f47ed8778f4d9f1b27afc4a6e85f1e"
465
+ },
466
+ sca: {
467
+ lendingPoolAddress: "0x6fc7d4211fc7018b6c75e7b908b88f2e0536443239804a3d32af547637bd28d7",
468
+ collateralPoolAddress: "0xff677a5d9e9dc8f08f0a8681ebfc7481d1c7d57bc441f2881974adcdd7b13c31"
469
+ }
470
+ };
471
+
472
+ // src/constants/pyth.ts
473
+ var PYTH_ENDPOINTS = {
474
+ testnet: ["https://hermes-beta.pyth.network"],
475
+ mainnet: ["https://hermes.pyth.network", "https://scallop.rpc.p2p.world"]
476
+ };
477
+ var PYTH_FEED_IDS = {
478
+ usdc: "eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
479
+ sbeth: "ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",
480
+ weth: "ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",
481
+ wbtc: "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43",
482
+ wusdc: "eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
483
+ wusdt: "2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b",
484
+ sui: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
485
+ wapt: "03ae4db29ed4ae33d323568895aa00337e658e348b37509f5372ae51f0af00d5",
486
+ wsol: "ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d",
487
+ cetus: "e5b274b2611143df055d6e7cd8d93fe1961716bcd4dca1cad87a83bc1e78c1ef",
488
+ afsui: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
489
+ hasui: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
490
+ vsui: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
491
+ sca: "7e17f0ac105abe9214deb9944c30264f5986bf292869c6bd8e8da3ccd92d79bc"
492
+ };
493
+
368
494
  // src/constants/queryKeys.ts
369
495
  var queryKeys = {
370
496
  api: {
@@ -441,232 +567,609 @@ var queryKeys = {
441
567
  ]
442
568
  },
443
569
  oracle: {
444
- getPythLatestPriceFeed: (pythPriceId) => [
445
- "oracle",
446
- "getPythPriceId",
447
- { pythPriceId }
448
- ]
449
- }
450
- };
451
-
452
- // src/constants/vesca.ts
453
- var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
454
- var MAX_LOCK_ROUNDS = 1460;
455
- var MAX_LOCK_DURATION = MAX_LOCK_ROUNDS * UNLOCK_ROUND_DURATION;
456
- var MIN_INITIAL_LOCK_AMOUNT = 1e10;
457
- var MIN_TOP_UP_AMOUNT = 1e9;
458
-
459
- // src/models/scallop.ts
460
- var import_sui_kit16 = require("@scallop-io/sui-kit");
461
-
462
- // src/models/scallopAddress.ts
463
- var import_sui_kit2 = require("@scallop-io/sui-kit");
464
-
465
- // src/models/scallopCache.ts
466
- var import_query_core = require("@tanstack/query-core");
467
- var import_sui_kit = require("@scallop-io/sui-kit");
468
-
469
- // src/constants/cache.ts
470
- var DEFAULT_CACHE_OPTIONS = {
471
- defaultOptions: {
472
- queries: {
473
- staleTime: 5e3,
474
- gcTime: 5e3
475
- }
476
- }
477
- };
478
-
479
- // src/utils/builder.ts
480
- var requireSender = (txBlock) => {
481
- const sender = txBlock.blockData.sender;
482
- if (!sender) {
483
- throw new Error("Sender is required");
484
- }
485
- return sender;
486
- };
487
- var checkVesca = (prevUnlockAtInMillisTimestamp) => {
488
- if (prevUnlockAtInMillisTimestamp === void 0) {
489
- throw new Error("veSca not found");
490
- }
491
- };
492
- var checkVescaExpired = (prevUnlockAtInMillisTimestamp) => {
493
- if (prevUnlockAtInMillisTimestamp <= (/* @__PURE__ */ new Date()).getTime()) {
494
- throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
495
- }
496
- };
497
- var checkExtendLockPeriod = (lockPeriodInDays, newUnlockAtInSecondTimestamp, prevUnlockAtInMillisTimestamp) => {
498
- checkVesca(prevUnlockAtInMillisTimestamp);
499
- checkVescaExpired(prevUnlockAtInMillisTimestamp);
500
- const prevUnlockAtInSecondTimestamp = Math.floor(
501
- prevUnlockAtInMillisTimestamp / 1e3
502
- );
503
- if (lockPeriodInDays < 1) {
504
- throw new Error("Minimum lock period is 1 day");
505
- }
506
- const availableLockPeriodInDays = Math.floor(
507
- (newUnlockAtInSecondTimestamp - prevUnlockAtInSecondTimestamp) / UNLOCK_ROUND_DURATION
508
- );
509
- if (lockPeriodInDays > availableLockPeriodInDays) {
510
- throw new Error(
511
- `Cannot extend lock period by ${lockPeriodInDays} days, maximum lock period is ~4 years (${MAX_LOCK_ROUNDS} days), remaining lock period is ${MAX_LOCK_ROUNDS - availableLockPeriodInDays}`
512
- );
513
- }
514
- };
515
- var checkLockSca = (scaAmountOrCoin, lockPeriodInDays, newUnlockAtInSecondTimestamp, prevUnlockAtInMillisTimestamp) => {
516
- const prevUnlockAtInSecondTimestamp = prevUnlockAtInMillisTimestamp ? Math.floor(prevUnlockAtInMillisTimestamp / 1e3) : void 0;
517
- const isInitialLock = !prevUnlockAtInSecondTimestamp;
518
- const isLockExpired = !isInitialLock && prevUnlockAtInSecondTimestamp * 1e3 <= (/* @__PURE__ */ new Date()).getTime();
519
- if (isInitialLock || isLockExpired) {
520
- if (scaAmountOrCoin !== void 0 && lockPeriodInDays !== void 0) {
521
- if (lockPeriodInDays <= 0) {
522
- throw new Error("Lock period must be greater than 0");
523
- }
524
- if (typeof scaAmountOrCoin === "number" && scaAmountOrCoin < MIN_INITIAL_LOCK_AMOUNT) {
525
- throw new Error(
526
- `Minimum lock amount for ${isLockExpired ? "renewing expired veSca" : "initial lock"} is 10 SCA`
527
- );
528
- }
529
- const extendLockPeriodInSecond = lockPeriodInDays * UNLOCK_ROUND_DURATION;
530
- if (extendLockPeriodInSecond > MAX_LOCK_DURATION) {
531
- throw new Error(
532
- `Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS} days)`
533
- );
534
- }
535
- } else {
536
- throw new Error(
537
- `SCA amount and lock period is required for ${isLockExpired ? "renewing expired veSca" : "initial lock"}`
538
- );
539
- }
540
- } else {
541
- checkVesca(prevUnlockAtInMillisTimestamp);
542
- checkVescaExpired(prevUnlockAtInMillisTimestamp);
543
- if (typeof scaAmountOrCoin === "number" && scaAmountOrCoin < MIN_TOP_UP_AMOUNT) {
544
- throw new Error("Minimum top up amount is 1 SCA");
545
- }
546
- if (newUnlockAtInSecondTimestamp && lockPeriodInDays) {
547
- checkExtendLockPeriod(
548
- lockPeriodInDays,
549
- newUnlockAtInSecondTimestamp,
550
- prevUnlockAtInMillisTimestamp
551
- );
552
- }
553
- }
554
- };
555
- var checkExtendLockAmount = (scaAmount, prevUnlockAtInMillisTimestamp) => {
556
- checkVesca(prevUnlockAtInMillisTimestamp);
557
- checkVescaExpired(prevUnlockAtInMillisTimestamp);
558
- if (scaAmount < MIN_TOP_UP_AMOUNT) {
559
- throw new Error("Minimum top up amount is 1 SCA");
560
- }
561
- const isInitialLock = !prevUnlockAtInMillisTimestamp;
562
- const isLockExpired = !isInitialLock && prevUnlockAtInMillisTimestamp <= (/* @__PURE__ */ new Date()).getTime();
563
- if (isLockExpired) {
564
- throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
565
- }
566
- };
567
- var checkRenewExpiredVeSca = (scaAmount, lockPeriodInDays, prevUnlockAtInMillisTimestamp) => {
568
- if (!prevUnlockAtInMillisTimestamp || prevUnlockAtInMillisTimestamp > (/* @__PURE__ */ new Date()).getTime()) {
569
- throw new Error("Renew method can only be used for expired veSca");
570
- }
571
- if (scaAmount < MIN_INITIAL_LOCK_AMOUNT) {
572
- throw new Error("Minimum lock amount for renewing expired vesca 10 SCA");
573
- }
574
- const extendLockPeriodInSecond = lockPeriodInDays * UNLOCK_ROUND_DURATION;
575
- if (extendLockPeriodInSecond >= MAX_LOCK_DURATION - UNLOCK_ROUND_DURATION) {
576
- throw new Error(
577
- `Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS - 1} days)`
578
- );
570
+ getPythLatestPriceFeeds: () => ["oracle", "getPythPriceIds"]
579
571
  }
580
572
  };
581
573
 
582
- // src/utils/query.ts
583
- var import_bignumber = __toESM(require("bignumber.js"));
584
- var import_utils = require("@mysten/sui/utils");
585
- var parseOriginMarketPoolData = (originMarketPoolData) => {
586
- return {
587
- coinType: (0, import_utils.normalizeStructTag)(originMarketPoolData.type.name),
588
- // Parse origin data required for basic calculations.
589
- maxBorrowRate: Number(originMarketPoolData.maxBorrowRate.value) / 2 ** 32,
590
- borrowRate: Number(originMarketPoolData.interestRate.value) / 2 ** 32,
591
- borrowRateScale: Number(originMarketPoolData.interestRateScale),
592
- borrowIndex: Number(originMarketPoolData.borrowIndex),
593
- lastUpdated: Number(originMarketPoolData.lastUpdated),
594
- cashAmount: Number(originMarketPoolData.cash),
595
- debtAmount: Number(originMarketPoolData.debt),
596
- marketCoinSupplyAmount: Number(originMarketPoolData.marketCoinSupply),
597
- reserveAmount: Number(originMarketPoolData.reserve),
598
- reserveFactor: Number(originMarketPoolData.reserveFactor.value) / 2 ** 32,
599
- borrowWeight: Number(originMarketPoolData.borrowWeight.value) / 2 ** 32,
600
- borrowFee: Number(originMarketPoolData.borrowFeeRate.value) / 2 ** 32,
601
- // Parse origin data required for additional display.
602
- baseBorrowRate: Number(originMarketPoolData.baseBorrowRatePerSec.value) / 2 ** 32,
603
- borrowRateOnHighKink: Number(originMarketPoolData.borrowRateOnHighKink.value) / 2 ** 32,
604
- borrowRateOnMidKink: Number(originMarketPoolData.borrowRateOnMidKink.value) / 2 ** 32,
605
- highKink: Number(originMarketPoolData.highKink.value) / 2 ** 32,
606
- midKink: Number(originMarketPoolData.midKink.value) / 2 ** 32,
607
- minBorrowAmount: Number(originMarketPoolData.minBorrowAmount)
608
- };
609
- };
610
- var calculateMarketPoolData = (utils, parsedMarketPoolData) => {
611
- const poolCoinName = utils.parseCoinNameFromType(
612
- parsedMarketPoolData.coinType
613
- );
614
- const coinDecimal = utils.getCoinDecimal(poolCoinName);
615
- const borrowYearFactor = 24 * 365 * 3600;
616
- const baseBorrowApr = parsedMarketPoolData.baseBorrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
617
- const borrowAprOnHighKink = parsedMarketPoolData.borrowRateOnHighKink * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
618
- const borrowAprOnMidKink = parsedMarketPoolData.borrowRateOnMidKink * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
619
- const maxBorrowApr = parsedMarketPoolData.maxBorrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
620
- const borrowApr = parsedMarketPoolData.borrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
621
- const timeDelta = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedMarketPoolData.lastUpdated;
622
- const borrowIndexDelta = (0, import_bignumber.default)(parsedMarketPoolData.borrowIndex).multipliedBy(
623
- (0, import_bignumber.default)(timeDelta).multipliedBy(parsedMarketPoolData.borrowRate)
624
- ).dividedBy(parsedMarketPoolData.borrowRateScale);
625
- const currentBorrowIndex = (0, import_bignumber.default)(parsedMarketPoolData.borrowIndex).plus(
626
- borrowIndexDelta
627
- );
628
- const growthInterest = (0, import_bignumber.default)(currentBorrowIndex).dividedBy(parsedMarketPoolData.borrowIndex).minus(1);
629
- const increasedDebtAmount = (0, import_bignumber.default)(
630
- parsedMarketPoolData.debtAmount
631
- ).multipliedBy(growthInterest);
632
- const borrowAmount = increasedDebtAmount.plus(
633
- parsedMarketPoolData.debtAmount
634
- );
635
- const borrowCoin = borrowAmount.shiftedBy(-1 * coinDecimal);
636
- const reserveAmount = (0, import_bignumber.default)(parsedMarketPoolData.reserveAmount).plus(
637
- increasedDebtAmount.multipliedBy(parsedMarketPoolData.reserveFactor)
638
- );
639
- const reserveCoin = reserveAmount.shiftedBy(-1 * coinDecimal);
640
- const supplyAmount = (0, import_bignumber.default)(borrowAmount).plus(
641
- Math.max(parsedMarketPoolData.cashAmount - reserveAmount.toNumber(), 0)
642
- );
643
- const supplyCoin = supplyAmount.shiftedBy(-1 * coinDecimal);
644
- let utilizationRate = (0, import_bignumber.default)(borrowAmount).dividedBy(supplyAmount);
645
- utilizationRate = utilizationRate.isFinite() ? utilizationRate : (0, import_bignumber.default)(0);
646
- let supplyApr = (0, import_bignumber.default)(borrowApr).multipliedBy(utilizationRate).multipliedBy(1 - parsedMarketPoolData.reserveFactor);
647
- supplyApr = supplyApr.isFinite() ? supplyApr : (0, import_bignumber.default)(0);
648
- let conversionRate = supplyAmount.dividedBy(
649
- parsedMarketPoolData.marketCoinSupplyAmount
650
- );
651
- conversionRate = conversionRate.isFinite() && !conversionRate.isNaN() ? conversionRate : (0, import_bignumber.default)(1);
652
- return {
653
- baseBorrowApr,
654
- baseBorrowApy: utils.parseAprToApy(baseBorrowApr),
655
- borrowAprOnHighKink,
656
- borrowApyOnHighKink: utils.parseAprToApy(borrowAprOnHighKink),
657
- borrowAprOnMidKink,
658
- borrowApyOnMidKink: utils.parseAprToApy(borrowAprOnMidKink),
659
- maxBorrowApr,
660
- maxBorrowApy: utils.parseAprToApy(maxBorrowApr),
661
- borrowApr: Math.min(borrowApr, maxBorrowApr),
662
- borrowApy: Math.min(
663
- utils.parseAprToApy(borrowApr),
664
- utils.parseAprToApy(maxBorrowApr)
665
- ),
666
- borrowIndex: currentBorrowIndex.toNumber(),
667
- growthInterest: growthInterest.toNumber(),
668
- supplyAmount: supplyAmount.toNumber(),
669
- supplyCoin: supplyCoin.toNumber(),
574
+ // src/constants/testAddress.ts
575
+ var TEST_ADDRESSES = {
576
+ core: {
577
+ // version:
578
+ // '0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7',
579
+ version: "0x6156d5cd1538bec8a167a40fe1209a4ec9cf8137921fe0a697f191ac561f0b09",
580
+ versionCap: "0x590a4011cb649b3878f3ea14b3a78674642a9548d79b7e091ef679574b158a07",
581
+ // object:
582
+ // '0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf',
583
+ object: "0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1",
584
+ // market:
585
+ // '0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9',
586
+ market: "0x8606ed145cc887985b8ed793f7753ff5dc762a42c379dac035f568e1bac58490",
587
+ adminCap: "0x09689d018e71c337d9db6d67cbca06b74ed92196103624028ccc3ecea411777c",
588
+ coinDecimalsRegistry: "0x200abe9bf19751cc566ae35aa58e2b7e4ff688fc1130f8d8909ea09bc137d668",
589
+ // obligationAccessStore:
590
+ // '0x733e30b7c94d619d78cb8f5bc4bfbb759ced9a531239028caabb2474e5be59c9',
591
+ obligationAccessStore: "0x48b472d68ca910c45f7f3b6c26836b6aa6d2569810d94b1b939023da05ae0a23",
592
+ coins: {
593
+ cetus: {
594
+ id: "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b",
595
+ metaData: "0x4c0dce55eff2db5419bbd2d239d1aa22b4a400c01bbb648b058a9883989025da",
596
+ treasury: "",
597
+ oracle: {
598
+ supra: "",
599
+ switchboard: "",
600
+ pyth: {
601
+ feed: "e5b274b2611143df055d6e7cd8d93fe1961716bcd4dca1cad87a83bc1e78c1ef",
602
+ feedObject: "0x24c0247fb22457a719efac7f670cdc79be321b521460bd6bd2ccfa9f80713b14"
603
+ }
604
+ }
605
+ },
606
+ wapt: {
607
+ id: "0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37",
608
+ metaData: "0xc969c5251f372c0f34c32759f1d315cf1ea0ee5e4454b52aea08778eacfdd0a8",
609
+ treasury: "",
610
+ oracle: {
611
+ supra: "",
612
+ switchboard: "",
613
+ pyth: {
614
+ feed: "03ae4db29ed4ae33d323568895aa00337e658e348b37509f5372ae51f0af00d5",
615
+ feedObject: "0x7c5b7837c44a69b469325463ac0673ac1aa8435ff44ddb4191c9ae380463647f"
616
+ }
617
+ }
618
+ },
619
+ wsol: {
620
+ id: "0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8",
621
+ metaData: "0x4d2c39082b4477e3e79dc4562d939147ab90c42fc5f3e4acf03b94383cd69b6e",
622
+ treasury: "",
623
+ oracle: {
624
+ supra: "",
625
+ switchboard: "",
626
+ pyth: {
627
+ feed: "ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d",
628
+ feedObject: "0x9d0d275efbd37d8a8855f6f2c761fa5983293dd8ce202ee5196626de8fcd4469"
629
+ }
630
+ }
631
+ },
632
+ wbtc: {
633
+ id: "0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881",
634
+ metaData: "0x5d3c6e60eeff8a05b693b481539e7847dfe33013e7070cdcb387f5c0cac05dfd",
635
+ treasury: "",
636
+ oracle: {
637
+ supra: "",
638
+ switchboard: "",
639
+ pyth: {
640
+ feed: "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43",
641
+ feedObject: "0x9a62b4863bdeaabdc9500fce769cf7e72d5585eeb28a6d26e4cafadc13f76ab2"
642
+ }
643
+ }
644
+ },
645
+ weth: {
646
+ id: "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",
647
+ metaData: "0x8900e4ceede3363bef086d6b50ca89d816d0e90bf6bc46efefe1f8455e08f50f",
648
+ treasury: "",
649
+ oracle: {
650
+ supra: "",
651
+ switchboard: "",
652
+ pyth: {
653
+ feed: "ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",
654
+ feedObject: "0x9193fd47f9a0ab99b6e365a464c8a9ae30e6150fc37ed2a89c1586631f6fc4ab"
655
+ }
656
+ }
657
+ },
658
+ wusdc: {
659
+ id: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf",
660
+ metaData: "0x4fbf84f3029bd0c0b77164b587963be957f853eccf834a67bb9ecba6ec80f189",
661
+ treasury: "",
662
+ oracle: {
663
+ supra: "",
664
+ switchboard: "",
665
+ pyth: {
666
+ feed: "eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
667
+ feedObject: "0x5dec622733a204ca27f5a90d8c2fad453cc6665186fd5dff13a83d0b6c9027ab"
668
+ }
669
+ }
670
+ },
671
+ wusdt: {
672
+ id: "0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c",
673
+ metaData: "0xfb0e3eb97dd158a5ae979dddfa24348063843c5b20eb8381dd5fa7c93699e45c",
674
+ treasury: "",
675
+ oracle: {
676
+ supra: "",
677
+ switchboard: "",
678
+ pyth: {
679
+ feed: "2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b",
680
+ feedObject: "0x985e3db9f93f76ee8bace7c3dd5cc676a096accd5d9e09e9ae0fb6e492b14572"
681
+ }
682
+ }
683
+ },
684
+ sui: {
685
+ id: "0x0000000000000000000000000000000000000000000000000000000000000002",
686
+ metaData: "0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3",
687
+ treasury: "",
688
+ oracle: {
689
+ supra: "",
690
+ switchboard: "0xbca474133638352ba83ccf7b5c931d50f764b09550e16612c9f70f1e21f3f594",
691
+ pyth: {
692
+ feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
693
+ feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
694
+ }
695
+ }
696
+ },
697
+ afsui: {
698
+ id: "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc",
699
+ metaData: "0x2f9217f533e51334873a39b8026a4aa6919497b47f49d0986a4f1aec66f8a34d",
700
+ treasury: "",
701
+ oracle: {
702
+ supra: "",
703
+ switchboard: "",
704
+ pyth: {
705
+ feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
706
+ feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
707
+ }
708
+ }
709
+ },
710
+ hasui: {
711
+ id: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",
712
+ metaData: "0x2c5f33af93f6511df699aaaa5822d823aac6ed99d4a0de2a4a50b3afa0172e24",
713
+ treasury: "",
714
+ oracle: {
715
+ supra: "",
716
+ switchboard: "",
717
+ pyth: {
718
+ feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
719
+ feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
720
+ }
721
+ }
722
+ },
723
+ vsui: {
724
+ id: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",
725
+ metaData: "0xabd84a23467b33854ab25cf862006fd97479f8f6f53e50fe732c43a274d939bd",
726
+ treasury: "",
727
+ oracle: {
728
+ supra: "",
729
+ switchboard: "",
730
+ pyth: {
731
+ feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
732
+ feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
733
+ }
734
+ }
735
+ },
736
+ sca: {
737
+ id: "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6",
738
+ metaData: "0x5d26a1e9a55c88147ac870bfa31b729d7f49f8804b8b3adfdf3582d301cca844",
739
+ treasury: "",
740
+ oracle: {
741
+ supra: "",
742
+ switchboard: "",
743
+ pyth: {
744
+ feed: "7e17f0ac105abe9214deb9944c30264f5986bf292869c6bd8e8da3ccd92d79bc",
745
+ feedObject: "0xf6de1d3279a269a597d813cbaca59aa906543ab9a8c64e84a4722f1a20863985"
746
+ }
747
+ }
748
+ }
749
+ },
750
+ oracles: {
751
+ xOracle: "0x93d5bf0936b71eb27255941e532fac33b5a5c7759e377b4923af0a1359ad494f",
752
+ xOracleCap: "0x1edeae568fde99e090dbdec4bcdbd33a15f53a1ce1f87aeef1a560dedf4b4a90",
753
+ supra: { registry: "", registryCap: "", holder: "" },
754
+ switchboard: { registry: "", registryCap: "" },
755
+ pyth: {
756
+ registry: "0xedc293f9413a5a7a5d53bdba1fd889d0a4030894469228f0acdae4aa3c55a213",
757
+ registryCap: "0xbcb07141eb1f7e01fbda4130ecf5f5adaeabb77f5d9c32158b7532bcd2197acd",
758
+ state: "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8",
759
+ wormhole: "0x5306f64e312b581766351c07af79c72fcb1cd25147157fdc2f8ad76de9a3fb6a",
760
+ wormholeState: "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c"
761
+ }
762
+ },
763
+ packages: {
764
+ coinDecimalsRegistry: {
765
+ id: "0xca5a5a62f01c79a104bf4d31669e29daa387f325c241de4edbe30986a9bc8b0d",
766
+ upgradeCap: "0x34e76a945d29f195bc53ca704fa70877d1cf3a5d7bbfdda1b13e633fff13c0f6"
767
+ },
768
+ math: {
769
+ id: "0xad013d5fde39e15eabda32b3dbdafd67dac32b798ce63237c27a8f73339b9b6f",
770
+ upgradeCap: "0x3a329598231de02e6135c62284b66005b41cad1d9ab7ca2dc79c08293aba2ec6"
771
+ },
772
+ whitelist: {
773
+ id: "0x1318fdc90319ec9c24df1456d960a447521b0a658316155895014a6e39b5482f",
774
+ upgradeCap: "0xf5a22aea23db664f7b69855b6a546747f17c1ec4230319cfc17225e462b05761"
775
+ },
776
+ x: {
777
+ id: "0x779b5c547976899f5474f3a5bc0db36ddf4697ad7e5a901db0415c2281d28162",
778
+ upgradeCap: "0x3f203f6fff6a69d151e4f1cd931f22b68c489ef2759765662fc7baf673943c9e"
779
+ },
780
+ protocol: {
781
+ id: "0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1",
782
+ upgradeCap: "0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a"
783
+ },
784
+ // protocol: {
785
+ // id: '0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e',
786
+ // upgradeCap:
787
+ // '0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a',
788
+ // },
789
+ protocolWhitelist: {
790
+ id: "0x4c262d9343dac53ecb28f482a2a3f62c73d0ebac5b5f03d57383d56ff219acdf",
791
+ upgradeCap: "0x4a5e88a75039b00988f633f811f58117f31b8627a46bf822aa114d9010049449"
792
+ },
793
+ // query: {
794
+ // id: '0xb8d603a39114a5efef3dd0bf84df0bed1be1fbd39b78b7dd6e8a61ccc5e6006f',
795
+ // upgradeCap:
796
+ // '0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f',
797
+ // },
798
+ query: {
799
+ id: "0xe4f9d62d17746d5b9dbf0d5557747430021a71575780b515161210cdba0a4c1c",
800
+ upgradeCap: "0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f"
801
+ },
802
+ supra: { id: "", upgradeCap: "" },
803
+ pyth: {
804
+ id: "0x910f30cbc7f601f75a5141a01265cd47c62d468707c5e1aecb32a18f448cb25a",
805
+ upgradeCap: "0xdf0ffbae1ea5bb25fbca5efba433dcf00c7cced65679af2f04728901275c6157"
806
+ },
807
+ switchboard: { id: "", upgradeCap: "" },
808
+ xOracle: {
809
+ id: "0x1478a432123e4b3d61878b629f2c692969fdb375644f1251cd278a4b1e7d7cd6",
810
+ upgradeCap: "0x0f928a6b2e26b73330fecaf9b44acfc9800a4a9794d6415c2a3153bc70e3c1f0"
811
+ },
812
+ testCoin: { id: "", upgradeCap: "" }
813
+ }
814
+ },
815
+ spool: {
816
+ // id: '0x7c4fdabe81c31b19a45d1e572a52a539997a90903fbb5bfab71480abe0fa62c3',
817
+ id: "0x1742655fe5872dfa6456673f9e38612a4965e6979e6cd7696a7f1225f28bae21",
818
+ adminCap: "0xdd8a047cbbf802bfcde5288b8ef1910965d789cc614da11d39af05fca0bd020a",
819
+ // object:
820
+ // '0xe87f1b2d498106a2c61421cec75b7b5c5e348512b0dc263949a0e7a3c256571a',
821
+ object: "0x1742655fe5872dfa6456673f9e38612a4965e6979e6cd7696a7f1225f28bae21",
822
+ pools: {
823
+ sweth: {
824
+ id: "0xeec40beccb07c575bebd842eeaabb835f77cd3dab73add433477e57f583a6787",
825
+ rewardPoolId: "0x957de68a18d87817de8309b30c1ec269a4d87ae513abbeed86b5619cb9ce1077"
826
+ },
827
+ ssui: {
828
+ // id: '0x4f0ba970d3c11db05c8f40c64a15b6a33322db3702d634ced6536960ab6f3ee4',
829
+ id: "0xb9617f83c06ebdeac0a8834782b1015e1cc7ea23739e30c132c4bfb95c37a579",
830
+ rewardPoolId: (
831
+ // '0x162250ef72393a4ad3d46294c4e1bdfcb03f04c869d390e7efbfc995353a7ee9',
832
+ "0xc3206071a8d43212efb6e3b5504f2321f8df97ab122b466c0bc7cfdf398dc13a"
833
+ )
834
+ },
835
+ swusdc: {
836
+ // id: '0x4ace6648ddc64e646ba47a957c562c32c9599b3bba8f5ac1aadb2ae23a2f8ca0',
837
+ id: "0xf1b383b9cf2e9f515fc69567df1053098f273849d09cd84b0278a773429bd2b2",
838
+ rewardPoolId: (
839
+ // '0xf4268cc9b9413b9bfe09e8966b8de650494c9e5784bf0930759cfef4904daff8',
840
+ "0xc71c53ee6505d928ba15bea4fe4f45d98c9c31eced94b72d00a7827d4b7ba3ff"
841
+ )
842
+ },
843
+ swusdt: {
844
+ // id: '0xcb328f7ffa7f9342ed85af3fdb2f22919e1a06dfb2f713c04c73543870d7548f',
845
+ id: "0xb5567dfa5c7fc17a249e959732664c50713dd8c23db1a11376b27df800c17418",
846
+ rewardPoolId: (
847
+ // '0x2c9f934d67a5baa586ceec2cc24163a2f049a6af3d5ba36b84d8ac40f25c4080',
848
+ "0x60768b0687ff0235e376a039709a683e4c436098785e473b67b32dbab47b69ab"
849
+ )
850
+ },
851
+ scetus: {
852
+ id: "0xac1bb13bf4472a637c18c2415fb0e3c1227ea2bcf35242e50563c98215bd298e",
853
+ rewardPoolId: "0x6835c1224126a45086fc6406adc249e3f30df18d779ca4f4e570e38716a17f3f"
854
+ },
855
+ safsui: {
856
+ // id: '0xeedf438abcaa6ce4d9625ffca110920592d5867e4c5637d84ad9f466c4feb800',
857
+ id: "0xc568bb4c991258e839aa54802ecda04fcd9838c826bc3b42b40af81b23c458c8",
858
+ rewardPoolId: (
859
+ // '0x89255a2f86ed7fbfef35ab8b7be48cc7667015975be2685dd9a55a9a64baf76e',
860
+ "0x389a3cbeda742b918941bb24fd00e077bad3367484394d6234f8209b9a6aa03d"
861
+ )
862
+ },
863
+ shasui: {
864
+ // id: '0xa6148bc1b623e936d39a952ceb5bea79e8b37228a8f595067bf1852efd3c34aa',
865
+ id: "0x93f3f4499bf89f2d05ddc1f8b15f51701a7c6c4d0ac0b9c3bc99462cbbd8e321",
866
+ rewardPoolId: (
867
+ // '0x6f3563644d3e2ef13176dbf9d865bd93479df60ccbe07b7e66db57f6309f5a66',
868
+ "0x94cee1be7f5ff34193f3aabef0b14142cb28af4d905fe487a9a7d85a15edb6aa"
869
+ )
870
+ },
871
+ svsui: {
872
+ // id: '0x69ce8e537e750a95381e6040794afa5ab1758353a1a2e1de7760391b01f91670',
873
+ id: "0xa970e9087f80cb59e9299b8e7af7175d977ad6c9af0322aa4440e138fbd7ae00",
874
+ rewardPoolId: (
875
+ // '0xbca914adce058ad0902c7f3cfcd698392a475f00dcfdc3f76001d0370b98777a',
876
+ "0x38eee9699c4fc132a6623e54b865f047df4fc6eb83af807300f44e8f4b235ff0"
877
+ )
878
+ }
879
+ },
880
+ config: ""
881
+ },
882
+ borrowIncentive: {
883
+ id: "0x6152f696fc3a658f33c4b891764731a59153125ffedfa8bff7167c42823f58a9",
884
+ adminCap: "0xc486afa253646f4d381e81d7f1df8aa4723b845a6bb356f69bad635ffefffe2c",
885
+ object: "0x002875153e09f8145ab63527bc85c00f2bd102e12f9573c47f8cdf1a1cb62934",
886
+ query: "0x529edc54a3dce2207703ceebbccb0ac14133f7825c1f528775ba0d85a4063489",
887
+ incentivePools: "0x6547e143d406b5ccd5f46aae482497de279cc1a68c406f701df70a05f9212ab4",
888
+ incentiveAccounts: "0xc4701fdbc1c92f9a636d334d66012b3027659e9fb8aff27279a82edfb6b77d02",
889
+ config: "0xdf5d04b4691cc67e82fd4db8394d89ff44823a9de29716c924f74bb4f11cc1f7"
890
+ },
891
+ referral: {
892
+ id: "0xa3654ebb63eb06c0f4ff52f8aa6512df9f164f7772bdf15dac3709bd3798dda9",
893
+ object: "0x5658d4bf5ddcba27e4337b4262108b3ad1716643cac8c2054ac341538adc72ec",
894
+ adminCap: "0xc5dc06b9074291259f2cac460c940012c781c4430e42125c541cc43101c3bcbd",
895
+ referralBindings: "0xf63299d58789d99de94092b9011323466e55ca0c1ea1a7a3786a589af46e1c09",
896
+ bindingTableId: "0x1c8202b17267ec8d6cf97ca013615354181a04f179570e42601ff2dae19294b1",
897
+ referralRevenuePool: "0x6abd852caf90769c1b185cdf636d841673fa95528f0550f018b8a138bd283c07",
898
+ revenueTableId: "0x595baa3654c297bff84ab7786a2d250f019cefc66e8df8e89fd9d41e02bd30dd",
899
+ referralTiers: "0x962cb903d8d7346190c5204785ccbb91b61086aa764f674c8145df82335cf83e",
900
+ tiersTableId: "0xeac755a7a8b7798530905ac79e8c114f19d0f130f6eab012954f08faac29c75d",
901
+ // authorizedWitnessList:
902
+ // '0xf21b0ed043c9bb70842c0129159f4943dbcc3c9ef2f2f808af65f8be25cfd20e',
903
+ authorizedWitnessList: "0x9d6223dc52015b8a3986a573590ef2af8f1b8f3e4685513888c052f001b87e7f",
904
+ version: "0x1bd4b7285f72e11c316b828c7c47b3f4da18dcec9f9b3dba6d8629cbb6f93e5e"
905
+ },
906
+ vesca: {
907
+ id: "0xb15b6e0cdd85afb5028bea851dd249405e734d800a259147bbc24980629723a4",
908
+ object: "0xb15b6e0cdd85afb5028bea851dd249405e734d800a259147bbc24980629723a4",
909
+ adminCap: "0x8ffa76135c5b85c5fbd73a6448a4a733d826cb63a267ab817656acb77c72d4a5",
910
+ tableId: "0xe3153b2bf124be0b86cb8bd468346a861efd0da52fc42197b54d2f616488a311",
911
+ table: "0x611cb8d9d4d90867467b5ebdf4cc447a0047ed5b01334a28a29fcfe733e3d609",
912
+ treasury: "0xe8c112c09b88158dc6c8e23d1fbae5b3c7136cdee54b7dafc08e65db28c4a5bc",
913
+ config: "0xe0a2ff281e73c1d53cfa85807080f87e833e4f1a7f93dcf8800b3865269a76b9"
914
+ },
915
+ loyaltyProgram: {
916
+ id: "0xd17bcf8b5a59652c36225d478564a8593ae0ed7d650bcacdda1d6fe179127907",
917
+ object: "0xd17bcf8b5a59652c36225d478564a8593ae0ed7d650bcacdda1d6fe179127907",
918
+ rewardPool: "0xf9c090492ef476bd542109d0913ffe871cbfa28578b7114eca2a8c0e5671786f",
919
+ userRewardTableId: "0x748a80395849ed37db1b0e14f2ab5d1d96458d2359ab3a84eb079d0f4ac7cf2e"
920
+ },
921
+ scoin: {
922
+ id: "0xad2ca2aa5089df94bb2d444d5eb3520378c2f2dfb3a0bd2a2c994145ac4b0a53",
923
+ coins: {
924
+ ssui: {
925
+ coinType: "0xfac769100bccc0caebcf4f4e2d00ac2f8883f07f724be28940df90605f5e7e9a::scallop_sui::SCALLOP_SUI",
926
+ treasury: "0x9cb4551b36c17d37e19d700147fa819ea1c487ff8bcf18374de2cceb2e9d4845"
927
+ },
928
+ scetus: {
929
+ coinType: "0x8b71e6d323ed78515af2bead13bf3d0da1562ba4a99234eb7c4f14fd39ef0427::scallop_cetus::SCALLOP_CETUS",
930
+ treasury: "0xd786f4b2d26278cc7911a3445b1b085eab60f269ef9dbb6b87e803d52f155003"
931
+ },
932
+ ssca: {
933
+ coinType: "0x0a9d3c6c9af9f6e8def82921541bcbd17f73ed31bed3adcb684f2a4c267e42f0::scallop_sca::SCALLOP_SCA",
934
+ treasury: "0xe818636d1d6c46d6ea1a2dce9d94696d7cbc18ce27451b603eeaa47aba8d75e0"
935
+ },
936
+ swusdc: {
937
+ coinType: "0xaedc3ab75db8680b81a755015fa90124d217be93457b893c05bac033817defaf::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
938
+ treasury: "0xfc6971648f867f7fd6928d1b873af71577e2eaf2c7543ef8bc82c431d833ae78"
939
+ },
940
+ swusdt: {
941
+ coinType: "0xbf02fc87ddc104b342ad8414c85ceadf5b0c823c055a06fb0ed776272c01a52a::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
942
+ treasury: "0xb9593e2c3a0ba796ee815012b75ae46468ea78cda0188b9ac6816efe65503521"
943
+ },
944
+ sweth: {
945
+ coinType: "0x27d54f43e3eda701be56b82e5756e41c84467cd202f5cf713d5f9e45a9f1b6bc::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
946
+ treasury: "0x032b4c8fac94c038dbe986f7587e9b1e4ef580b5ee06d2ef249d85459b7ef05d"
947
+ },
948
+ safsui: {
949
+ coinType: "0xb75b46d975d8d80670b53a6bee90baaa8ce2e0b7d397f079447d641eef6b44ad::scallop_af_sui::SCALLOP_AF_SUI",
950
+ treasury: "0x21450ef0570ef3d224ffa3b873ab802e439ece7b93cc7efad10ae0c1e3b3fcfe"
951
+ },
952
+ shasui: {
953
+ coinType: "0xd973a723874e2c7cde196602a79155a1343a933f8cf87d9b1bb7408bc1acbc58::scallop_ha_sui::SCALLOP_HA_SUI",
954
+ treasury: "0xf822fc1402207e47d2e3ba8ff6e1e594bf1de777dc5ebd2744619cd2726e3b0d"
955
+ },
956
+ svsui: {
957
+ coinType: "0x97023a317320c4498cc4cd239dd02fd30c28246e5e8f81325d63f2bd8d70f6b3::scallop_v_sui::SCALLOP_V_SUI",
958
+ treasury: "0x327114f0bf3559d7e2de10282147ed76a236c7c6775029165c4db09a6062ead6\u0192"
959
+ }
960
+ }
961
+ }
962
+ };
963
+
964
+ // src/constants/tokenBucket.ts
965
+ var DEFAULT_TOKENS_PER_INTERVAL = 10;
966
+ var DEFAULT_INTERVAL_IN_MS = 300;
967
+
968
+ // src/constants/vesca.ts
969
+ var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
970
+ var MAX_LOCK_ROUNDS = 1460;
971
+ var MAX_LOCK_DURATION = MAX_LOCK_ROUNDS * UNLOCK_ROUND_DURATION;
972
+ var MIN_INITIAL_LOCK_AMOUNT = 1e10;
973
+ var MIN_TOP_UP_AMOUNT = 1e9;
974
+
975
+ // src/models/scallopAddress.ts
976
+ var import_sui_kit2 = require("@scallop-io/sui-kit");
977
+
978
+ // src/models/scallopCache.ts
979
+ var import_query_core = require("@tanstack/query-core");
980
+ var import_sui_kit = require("@scallop-io/sui-kit");
981
+
982
+ // src/utils/builder.ts
983
+ var requireSender = (txBlock) => {
984
+ const sender = txBlock.blockData.sender;
985
+ if (!sender) {
986
+ throw new Error("Sender is required");
987
+ }
988
+ return sender;
989
+ };
990
+ var checkVesca = (prevUnlockAtInMillisTimestamp) => {
991
+ if (prevUnlockAtInMillisTimestamp === void 0) {
992
+ throw new Error("veSca not found");
993
+ }
994
+ };
995
+ var checkVescaExpired = (prevUnlockAtInMillisTimestamp) => {
996
+ if (prevUnlockAtInMillisTimestamp <= (/* @__PURE__ */ new Date()).getTime()) {
997
+ throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
998
+ }
999
+ };
1000
+ var checkExtendLockPeriod = (lockPeriodInDays, newUnlockAtInSecondTimestamp, prevUnlockAtInMillisTimestamp) => {
1001
+ checkVesca(prevUnlockAtInMillisTimestamp);
1002
+ checkVescaExpired(prevUnlockAtInMillisTimestamp);
1003
+ const prevUnlockAtInSecondTimestamp = Math.floor(
1004
+ prevUnlockAtInMillisTimestamp / 1e3
1005
+ );
1006
+ if (lockPeriodInDays < 1) {
1007
+ throw new Error("Minimum lock period is 1 day");
1008
+ }
1009
+ const availableLockPeriodInDays = Math.floor(
1010
+ (newUnlockAtInSecondTimestamp - prevUnlockAtInSecondTimestamp) / UNLOCK_ROUND_DURATION
1011
+ );
1012
+ if (lockPeriodInDays > availableLockPeriodInDays) {
1013
+ throw new Error(
1014
+ `Cannot extend lock period by ${lockPeriodInDays} days, maximum lock period is ~4 years (${MAX_LOCK_ROUNDS} days), remaining lock period is ${MAX_LOCK_ROUNDS - availableLockPeriodInDays}`
1015
+ );
1016
+ }
1017
+ };
1018
+ var checkLockSca = (scaAmountOrCoin, lockPeriodInDays, newUnlockAtInSecondTimestamp, prevUnlockAtInMillisTimestamp) => {
1019
+ const prevUnlockAtInSecondTimestamp = prevUnlockAtInMillisTimestamp ? Math.floor(prevUnlockAtInMillisTimestamp / 1e3) : void 0;
1020
+ const isInitialLock = !prevUnlockAtInSecondTimestamp;
1021
+ const isLockExpired = !isInitialLock && prevUnlockAtInSecondTimestamp * 1e3 <= (/* @__PURE__ */ new Date()).getTime();
1022
+ if (isInitialLock || isLockExpired) {
1023
+ if (scaAmountOrCoin !== void 0 && lockPeriodInDays !== void 0) {
1024
+ if (lockPeriodInDays <= 0) {
1025
+ throw new Error("Lock period must be greater than 0");
1026
+ }
1027
+ if (typeof scaAmountOrCoin === "number" && scaAmountOrCoin < MIN_INITIAL_LOCK_AMOUNT) {
1028
+ throw new Error(
1029
+ `Minimum lock amount for ${isLockExpired ? "renewing expired veSca" : "initial lock"} is 10 SCA`
1030
+ );
1031
+ }
1032
+ const extendLockPeriodInSecond = lockPeriodInDays * UNLOCK_ROUND_DURATION;
1033
+ if (extendLockPeriodInSecond > MAX_LOCK_DURATION) {
1034
+ throw new Error(
1035
+ `Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS} days)`
1036
+ );
1037
+ }
1038
+ } else {
1039
+ throw new Error(
1040
+ `SCA amount and lock period is required for ${isLockExpired ? "renewing expired veSca" : "initial lock"}`
1041
+ );
1042
+ }
1043
+ } else {
1044
+ checkVesca(prevUnlockAtInMillisTimestamp);
1045
+ checkVescaExpired(prevUnlockAtInMillisTimestamp);
1046
+ if (typeof scaAmountOrCoin === "number" && scaAmountOrCoin < MIN_TOP_UP_AMOUNT) {
1047
+ throw new Error("Minimum top up amount is 1 SCA");
1048
+ }
1049
+ if (newUnlockAtInSecondTimestamp && lockPeriodInDays) {
1050
+ checkExtendLockPeriod(
1051
+ lockPeriodInDays,
1052
+ newUnlockAtInSecondTimestamp,
1053
+ prevUnlockAtInMillisTimestamp
1054
+ );
1055
+ }
1056
+ }
1057
+ };
1058
+ var checkExtendLockAmount = (scaAmount, prevUnlockAtInMillisTimestamp) => {
1059
+ checkVesca(prevUnlockAtInMillisTimestamp);
1060
+ checkVescaExpired(prevUnlockAtInMillisTimestamp);
1061
+ if (scaAmount < MIN_TOP_UP_AMOUNT) {
1062
+ throw new Error("Minimum top up amount is 1 SCA");
1063
+ }
1064
+ const isInitialLock = !prevUnlockAtInMillisTimestamp;
1065
+ const isLockExpired = !isInitialLock && prevUnlockAtInMillisTimestamp <= (/* @__PURE__ */ new Date()).getTime();
1066
+ if (isLockExpired) {
1067
+ throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
1068
+ }
1069
+ };
1070
+ var checkRenewExpiredVeSca = (scaAmount, lockPeriodInDays, prevUnlockAtInMillisTimestamp) => {
1071
+ if (!prevUnlockAtInMillisTimestamp || prevUnlockAtInMillisTimestamp > (/* @__PURE__ */ new Date()).getTime()) {
1072
+ throw new Error("Renew method can only be used for expired veSca");
1073
+ }
1074
+ if (scaAmount < MIN_INITIAL_LOCK_AMOUNT) {
1075
+ throw new Error("Minimum lock amount for renewing expired vesca 10 SCA");
1076
+ }
1077
+ const extendLockPeriodInSecond = lockPeriodInDays * UNLOCK_ROUND_DURATION;
1078
+ if (extendLockPeriodInSecond >= MAX_LOCK_DURATION - UNLOCK_ROUND_DURATION) {
1079
+ throw new Error(
1080
+ `Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS - 1} days)`
1081
+ );
1082
+ }
1083
+ };
1084
+
1085
+ // src/utils/query.ts
1086
+ var import_bignumber = __toESM(require("bignumber.js"));
1087
+ var import_utils = require("@mysten/sui/utils");
1088
+ var parseOriginMarketPoolData = (originMarketPoolData) => {
1089
+ return {
1090
+ coinType: (0, import_utils.normalizeStructTag)(originMarketPoolData.type.name),
1091
+ // Parse origin data required for basic calculations.
1092
+ maxBorrowRate: Number(originMarketPoolData.maxBorrowRate.value) / 2 ** 32,
1093
+ borrowRate: Number(originMarketPoolData.interestRate.value) / 2 ** 32,
1094
+ borrowRateScale: Number(originMarketPoolData.interestRateScale),
1095
+ borrowIndex: Number(originMarketPoolData.borrowIndex),
1096
+ lastUpdated: Number(originMarketPoolData.lastUpdated),
1097
+ cashAmount: Number(originMarketPoolData.cash),
1098
+ debtAmount: Number(originMarketPoolData.debt),
1099
+ marketCoinSupplyAmount: Number(originMarketPoolData.marketCoinSupply),
1100
+ reserveAmount: Number(originMarketPoolData.reserve),
1101
+ reserveFactor: Number(originMarketPoolData.reserveFactor.value) / 2 ** 32,
1102
+ borrowWeight: Number(originMarketPoolData.borrowWeight.value) / 2 ** 32,
1103
+ borrowFee: Number(originMarketPoolData.borrowFeeRate.value) / 2 ** 32,
1104
+ // Parse origin data required for additional display.
1105
+ baseBorrowRate: Number(originMarketPoolData.baseBorrowRatePerSec.value) / 2 ** 32,
1106
+ borrowRateOnHighKink: Number(originMarketPoolData.borrowRateOnHighKink.value) / 2 ** 32,
1107
+ borrowRateOnMidKink: Number(originMarketPoolData.borrowRateOnMidKink.value) / 2 ** 32,
1108
+ highKink: Number(originMarketPoolData.highKink.value) / 2 ** 32,
1109
+ midKink: Number(originMarketPoolData.midKink.value) / 2 ** 32,
1110
+ minBorrowAmount: Number(originMarketPoolData.minBorrowAmount)
1111
+ };
1112
+ };
1113
+ var calculateMarketPoolData = (utils, parsedMarketPoolData) => {
1114
+ const poolCoinName = utils.parseCoinNameFromType(
1115
+ parsedMarketPoolData.coinType
1116
+ );
1117
+ const coinDecimal = utils.getCoinDecimal(poolCoinName);
1118
+ const borrowYearFactor = 24 * 365 * 3600;
1119
+ const baseBorrowApr = parsedMarketPoolData.baseBorrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
1120
+ const borrowAprOnHighKink = parsedMarketPoolData.borrowRateOnHighKink * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
1121
+ const borrowAprOnMidKink = parsedMarketPoolData.borrowRateOnMidKink * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
1122
+ const maxBorrowApr = parsedMarketPoolData.maxBorrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
1123
+ const borrowApr = parsedMarketPoolData.borrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
1124
+ const timeDelta = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedMarketPoolData.lastUpdated;
1125
+ const borrowIndexDelta = (0, import_bignumber.default)(parsedMarketPoolData.borrowIndex).multipliedBy(
1126
+ (0, import_bignumber.default)(timeDelta).multipliedBy(parsedMarketPoolData.borrowRate)
1127
+ ).dividedBy(parsedMarketPoolData.borrowRateScale);
1128
+ const currentBorrowIndex = (0, import_bignumber.default)(parsedMarketPoolData.borrowIndex).plus(
1129
+ borrowIndexDelta
1130
+ );
1131
+ const growthInterest = (0, import_bignumber.default)(currentBorrowIndex).dividedBy(parsedMarketPoolData.borrowIndex).minus(1);
1132
+ const increasedDebtAmount = (0, import_bignumber.default)(
1133
+ parsedMarketPoolData.debtAmount
1134
+ ).multipliedBy(growthInterest);
1135
+ const borrowAmount = increasedDebtAmount.plus(
1136
+ parsedMarketPoolData.debtAmount
1137
+ );
1138
+ const borrowCoin = borrowAmount.shiftedBy(-1 * coinDecimal);
1139
+ const reserveAmount = (0, import_bignumber.default)(parsedMarketPoolData.reserveAmount).plus(
1140
+ increasedDebtAmount.multipliedBy(parsedMarketPoolData.reserveFactor)
1141
+ );
1142
+ const reserveCoin = reserveAmount.shiftedBy(-1 * coinDecimal);
1143
+ const supplyAmount = (0, import_bignumber.default)(borrowAmount).plus(
1144
+ Math.max(parsedMarketPoolData.cashAmount - reserveAmount.toNumber(), 0)
1145
+ );
1146
+ const supplyCoin = supplyAmount.shiftedBy(-1 * coinDecimal);
1147
+ let utilizationRate = (0, import_bignumber.default)(borrowAmount).dividedBy(supplyAmount);
1148
+ utilizationRate = utilizationRate.isFinite() ? utilizationRate : (0, import_bignumber.default)(0);
1149
+ let supplyApr = (0, import_bignumber.default)(borrowApr).multipliedBy(utilizationRate).multipliedBy(1 - parsedMarketPoolData.reserveFactor);
1150
+ supplyApr = supplyApr.isFinite() ? supplyApr : (0, import_bignumber.default)(0);
1151
+ let conversionRate = supplyAmount.dividedBy(
1152
+ parsedMarketPoolData.marketCoinSupplyAmount
1153
+ );
1154
+ conversionRate = conversionRate.isFinite() && !conversionRate.isNaN() ? conversionRate : (0, import_bignumber.default)(1);
1155
+ return {
1156
+ baseBorrowApr,
1157
+ baseBorrowApy: utils.parseAprToApy(baseBorrowApr),
1158
+ borrowAprOnHighKink,
1159
+ borrowApyOnHighKink: utils.parseAprToApy(borrowAprOnHighKink),
1160
+ borrowAprOnMidKink,
1161
+ borrowApyOnMidKink: utils.parseAprToApy(borrowAprOnMidKink),
1162
+ maxBorrowApr,
1163
+ maxBorrowApy: utils.parseAprToApy(maxBorrowApr),
1164
+ borrowApr: Math.min(borrowApr, maxBorrowApr),
1165
+ borrowApy: Math.min(
1166
+ utils.parseAprToApy(borrowApr),
1167
+ utils.parseAprToApy(maxBorrowApr)
1168
+ ),
1169
+ borrowIndex: currentBorrowIndex.toNumber(),
1170
+ growthInterest: growthInterest.toNumber(),
1171
+ supplyAmount: supplyAmount.toNumber(),
1172
+ supplyCoin: supplyCoin.toNumber(),
670
1173
  borrowAmount: borrowAmount.toNumber(),
671
1174
  borrowCoin: borrowCoin.toNumber(),
672
1175
  reserveAmount: reserveAmount.toNumber(),
@@ -1012,676 +1515,280 @@ var parseDataFromPythPriceFeed = (feed, address) => {
1012
1515
  });
1013
1516
  if (assetCoinName) {
1014
1517
  const price = feed.price.price * 10 ** feed.price.expo;
1015
- return {
1016
- coinName: assetCoinName,
1017
- price,
1018
- publishTime: Number(feed.price.publishTime) * 10 ** 3
1019
- };
1020
- } else {
1021
- throw new Error("Invalid feed id");
1022
- }
1023
- };
1024
- var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
1025
- const unlockDate = new Date(unlockAtInSecondTimestamp * 1e3);
1026
- const closestTwelveAM = new Date(unlockAtInSecondTimestamp * 1e3);
1027
- closestTwelveAM.setUTCHours(0, 0, 0, 0);
1028
- if (unlockDate.getUTCHours() >= 0) {
1029
- closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() + 1);
1030
- }
1031
- const now = (/* @__PURE__ */ new Date()).getTime();
1032
- if (closestTwelveAM.getTime() - now > MAX_LOCK_DURATION * 1e3) {
1033
- closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() - 1);
1034
- }
1035
- return Math.floor(closestTwelveAM.getTime() / 1e3);
1036
- };
1037
-
1038
- // src/constants/tokenBucket.ts
1039
- var DEFAULT_TOKENS_PER_INTERVAL = 50;
1040
- var DEFAULT_INTERVAL_IN_MS = 300;
1041
-
1042
- // src/utils/tokenBucket.ts
1043
- var TokenBucket = class {
1044
- constructor(tokensPerInterval, intervalInMs) {
1045
- this.tokensPerInterval = tokensPerInterval;
1046
- this.interval = intervalInMs;
1047
- this.tokens = tokensPerInterval;
1048
- this.lastRefill = Date.now();
1049
- }
1050
- refill() {
1051
- const now = Date.now();
1052
- const elapsed = now - this.lastRefill;
1053
- if (elapsed > this.interval) {
1054
- const tokensToAdd = Math.floor(elapsed / this.interval) * this.tokensPerInterval;
1055
- this.tokens = Math.min(this.tokens + tokensToAdd, this.tokensPerInterval);
1056
- this.lastRefill = now;
1057
- }
1058
- }
1059
- removeTokens(count) {
1060
- this.refill();
1061
- if (this.tokens >= count) {
1062
- this.tokens -= count;
1063
- return true;
1064
- }
1065
- return false;
1066
- }
1067
- };
1068
- var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 15, backoffFactor = 1.25) => {
1069
- let retries = 0;
1070
- const tryRequest = async () => {
1071
- if (tokenBucket.removeTokens(1)) {
1072
- try {
1073
- const result = await fn();
1074
- if (result && result.status === 429) {
1075
- throw new Error("Unexpected status code: 429");
1076
- }
1077
- return result;
1078
- } catch (error) {
1079
- if (error.message === "Unexpected status code: 429" && retries < maxRetries) {
1080
- retries++;
1081
- const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
1082
- await new Promise((resolve) => setTimeout(resolve, delay));
1083
- return tryRequest();
1084
- } else {
1085
- console.error("An error occurred:", error.message);
1086
- return null;
1087
- }
1088
- }
1089
- } else if (retries < maxRetries) {
1090
- retries++;
1091
- const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
1092
- await new Promise((resolve) => setTimeout(resolve, delay));
1093
- return tryRequest();
1094
- } else {
1095
- console.error("Maximum retries reached");
1096
- return null;
1097
- }
1098
- };
1099
- return tryRequest();
1100
- };
1101
-
1102
- // src/utils/indexer.ts
1103
- async function callMethodWithIndexerFallback(method, context, ...args) {
1104
- const indexer = args[args.length - 1];
1105
- if (indexer) {
1106
- try {
1107
- return await method.apply(context, args);
1108
- } catch (e) {
1109
- console.warn(`Indexer requests failed: ${e}. Retrying without indexer..`);
1110
- return await method.apply(context, [...args.slice(0, -1), false]);
1111
- }
1112
- }
1113
- return await method.apply(context, args);
1114
- }
1115
- function withIndexerFallback(method) {
1116
- return (...args) => {
1117
- return callMethodWithIndexerFallback(method, this, ...args);
1118
- };
1119
- }
1120
-
1121
- // src/models/scallopCache.ts
1122
- var ScallopCache = class {
1123
- constructor(suiKit, walletAddress, cacheOptions, tokenBucket, queryClient) {
1124
- this.queryClient = queryClient ?? new import_query_core.QueryClient(cacheOptions ?? DEFAULT_CACHE_OPTIONS);
1125
- this._suiKit = suiKit;
1126
- this.tokenBucket = tokenBucket ?? new TokenBucket(DEFAULT_TOKENS_PER_INTERVAL, DEFAULT_INTERVAL_IN_MS);
1127
- this.walletAddress = walletAddress ?? suiKit.currentAddress();
1128
- }
1129
- get suiKit() {
1130
- if (!this._suiKit) {
1131
- throw new Error("SuiKit instance is not initialized");
1132
- }
1133
- return this._suiKit;
1134
- }
1135
- get client() {
1136
- return this.suiKit.client();
1137
- }
1138
- /**
1139
- * @description Invalidate cache based on the refetchType parameter
1140
- * @param refetchType Determines the type of queries to be refetched. Defaults to `active`.
1141
- *
1142
- * - `active`: Only queries that match the refetch predicate and are actively being rendered via useQuery and related functions will be refetched in the background.
1143
- * - `inactive`: Only queries that match the refetch predicate and are NOT actively being rendered via useQuery and related functions will be refetched in the background.
1144
- * - `all`: All queries that match the refetch predicate will be refetched in the background.
1145
- * - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
1146
- */
1147
- async invalidateAllCache() {
1148
- return Object.values(queryKeys.rpc).map(
1149
- (t) => this.queryClient.invalidateQueries({
1150
- queryKey: t(),
1151
- type: "all"
1152
- })
1153
- );
1154
- }
1155
- /**
1156
- * @description Provides cache for inspectTxn of the SuiKit.
1157
- * @param QueryInspectTxnParams
1158
- * @param txBlock
1159
- * @returns Promise<DevInspectResults>
1160
- */
1161
- async queryInspectTxn({
1162
- queryTarget,
1163
- args,
1164
- typeArgs
1165
- }) {
1166
- const txBlock = new import_sui_kit.SuiTxBlock();
1167
- txBlock.moveCall(queryTarget, args, typeArgs);
1168
- const query = await this.queryClient.fetchQuery({
1169
- queryKey: queryKeys.rpc.getInspectTxn(queryTarget, args, typeArgs),
1170
- queryFn: async () => {
1171
- return await callWithRateLimit(
1172
- this.tokenBucket,
1173
- () => this.suiKit.inspectTxn(txBlock)
1174
- );
1175
- }
1176
- });
1177
- return query;
1178
- }
1179
- /**
1180
- * @description Provides cache for getObject of the SuiKit.
1181
- * @param objectId
1182
- * @param QueryObjectParams
1183
- * @returns Promise<SuiObjectResponse>
1184
- */
1185
- async queryGetObject(objectId, options) {
1186
- return this.queryClient.fetchQuery({
1187
- queryKey: queryKeys.rpc.getObject(objectId, this.walletAddress, options),
1188
- queryFn: async () => {
1189
- return await callWithRateLimit(
1190
- this.tokenBucket,
1191
- () => this.client.getObject({
1192
- id: objectId,
1193
- options
1194
- })
1195
- );
1196
- }
1197
- });
1198
- }
1199
- /**
1200
- * @description Provides cache for getObjects of the SuiKit.
1201
- * @param objectIds
1202
- * @returns Promise<SuiObjectData[]>
1203
- */
1204
- async queryGetObjects(objectIds, options = {
1205
- showContent: true
1206
- }) {
1207
- if (objectIds.length === 0)
1208
- return [];
1209
- return this.queryClient.fetchQuery({
1210
- queryKey: queryKeys.rpc.getObjects(
1211
- objectIds,
1212
- this.walletAddress,
1213
- options
1214
- ),
1215
- queryFn: async () => {
1216
- return await callWithRateLimit(
1217
- this.tokenBucket,
1218
- () => this.suiKit.getObjects(objectIds, options)
1219
- );
1220
- }
1221
- });
1222
- }
1223
- /**
1224
- * @description Provides cache for getOwnedObjects of the SuiKit.
1225
- * @param input
1226
- * @returns Promise<PaginatedObjectsResponse>
1227
- */
1228
- async queryGetOwnedObjects(input) {
1229
- return this.queryClient.fetchQuery({
1230
- queryKey: queryKeys.rpc.getOwnedObjects(input),
1231
- queryFn: async () => {
1232
- return await callWithRateLimit(
1233
- this.tokenBucket,
1234
- () => this.client.getOwnedObjects(input)
1235
- );
1236
- }
1237
- });
1238
- }
1239
- async queryGetDynamicFields(input) {
1240
- return this.queryClient.fetchQuery({
1241
- queryKey: queryKeys.rpc.getDynamicFields(input),
1242
- queryFn: async () => {
1243
- return await callWithRateLimit(
1244
- this.tokenBucket,
1245
- () => this.client.getDynamicFields(input)
1246
- );
1247
- }
1248
- });
1249
- }
1250
- async queryGetDynamicFieldObject(input) {
1251
- return this.queryClient.fetchQuery({
1252
- queryKey: queryKeys.rpc.getDynamicFieldObject(input),
1253
- queryFn: async () => {
1254
- return await callWithRateLimit(
1255
- this.tokenBucket,
1256
- () => this.client.getDynamicFieldObject(input)
1257
- );
1258
- }
1259
- });
1518
+ return {
1519
+ coinName: assetCoinName,
1520
+ price,
1521
+ publishTime: Number(feed.price.publishTime) * 10 ** 3
1522
+ };
1523
+ } else {
1524
+ throw new Error("Invalid feed id");
1260
1525
  }
1261
- async queryGetAllCoinBalances(owner) {
1262
- return this.queryClient.fetchQuery({
1263
- queryKey: queryKeys.rpc.getAllCoinBalances(owner),
1264
- queryFn: async () => {
1265
- const allBalances = await callWithRateLimit(
1266
- this.tokenBucket,
1267
- () => this.client.getAllBalances({ owner })
1268
- );
1269
- if (!allBalances)
1270
- return {};
1271
- const balances = allBalances.reduce(
1272
- (acc, coinBalance) => {
1273
- if (coinBalance.totalBalance !== "0") {
1274
- acc[(0, import_sui_kit.normalizeStructTag)(coinBalance.coinType)] = coinBalance.totalBalance;
1275
- }
1276
- return acc;
1277
- },
1278
- {}
1279
- );
1280
- return balances;
1281
- }
1282
- });
1526
+ };
1527
+ var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
1528
+ const unlockDate = new Date(unlockAtInSecondTimestamp * 1e3);
1529
+ const closestTwelveAM = new Date(unlockAtInSecondTimestamp * 1e3);
1530
+ closestTwelveAM.setUTCHours(0, 0, 0, 0);
1531
+ if (unlockDate.getUTCHours() >= 0) {
1532
+ closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() + 1);
1283
1533
  }
1284
- async queryGetCoinBalance(input) {
1285
- if (!input.coinType)
1286
- return "0";
1287
- return (await this.queryGetAllCoinBalances(input.owner) || {})[(0, import_sui_kit.normalizeStructTag)(input.coinType)] ?? "0";
1534
+ const now = (/* @__PURE__ */ new Date()).getTime();
1535
+ if (closestTwelveAM.getTime() - now > MAX_LOCK_DURATION * 1e3) {
1536
+ closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() - 1);
1288
1537
  }
1538
+ return Math.floor(closestTwelveAM.getTime() / 1e3);
1289
1539
  };
1290
1540
 
1291
- // src/models/scallopAddress.ts
1292
- var import_axios = __toESM(require("axios"));
1293
-
1294
- // src/constants/testAddress.ts
1295
- var TEST_ADDRESSES = {
1296
- core: {
1297
- // version:
1298
- // '0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7',
1299
- version: "0x6156d5cd1538bec8a167a40fe1209a4ec9cf8137921fe0a697f191ac561f0b09",
1300
- versionCap: "0x590a4011cb649b3878f3ea14b3a78674642a9548d79b7e091ef679574b158a07",
1301
- // object:
1302
- // '0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf',
1303
- object: "0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1",
1304
- // market:
1305
- // '0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9',
1306
- market: "0x8606ed145cc887985b8ed793f7753ff5dc762a42c379dac035f568e1bac58490",
1307
- adminCap: "0x09689d018e71c337d9db6d67cbca06b74ed92196103624028ccc3ecea411777c",
1308
- coinDecimalsRegistry: "0x200abe9bf19751cc566ae35aa58e2b7e4ff688fc1130f8d8909ea09bc137d668",
1309
- // obligationAccessStore:
1310
- // '0x733e30b7c94d619d78cb8f5bc4bfbb759ced9a531239028caabb2474e5be59c9',
1311
- obligationAccessStore: "0x48b472d68ca910c45f7f3b6c26836b6aa6d2569810d94b1b939023da05ae0a23",
1312
- coins: {
1313
- cetus: {
1314
- id: "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b",
1315
- metaData: "0x4c0dce55eff2db5419bbd2d239d1aa22b4a400c01bbb648b058a9883989025da",
1316
- treasury: "",
1317
- oracle: {
1318
- supra: "",
1319
- switchboard: "",
1320
- pyth: {
1321
- feed: "e5b274b2611143df055d6e7cd8d93fe1961716bcd4dca1cad87a83bc1e78c1ef",
1322
- feedObject: "0x24c0247fb22457a719efac7f670cdc79be321b521460bd6bd2ccfa9f80713b14"
1323
- }
1324
- }
1325
- },
1326
- wapt: {
1327
- id: "0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37",
1328
- metaData: "0xc969c5251f372c0f34c32759f1d315cf1ea0ee5e4454b52aea08778eacfdd0a8",
1329
- treasury: "",
1330
- oracle: {
1331
- supra: "",
1332
- switchboard: "",
1333
- pyth: {
1334
- feed: "03ae4db29ed4ae33d323568895aa00337e658e348b37509f5372ae51f0af00d5",
1335
- feedObject: "0x7c5b7837c44a69b469325463ac0673ac1aa8435ff44ddb4191c9ae380463647f"
1336
- }
1337
- }
1338
- },
1339
- wsol: {
1340
- id: "0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8",
1341
- metaData: "0x4d2c39082b4477e3e79dc4562d939147ab90c42fc5f3e4acf03b94383cd69b6e",
1342
- treasury: "",
1343
- oracle: {
1344
- supra: "",
1345
- switchboard: "",
1346
- pyth: {
1347
- feed: "ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d",
1348
- feedObject: "0x9d0d275efbd37d8a8855f6f2c761fa5983293dd8ce202ee5196626de8fcd4469"
1349
- }
1350
- }
1351
- },
1352
- wbtc: {
1353
- id: "0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881",
1354
- metaData: "0x5d3c6e60eeff8a05b693b481539e7847dfe33013e7070cdcb387f5c0cac05dfd",
1355
- treasury: "",
1356
- oracle: {
1357
- supra: "",
1358
- switchboard: "",
1359
- pyth: {
1360
- feed: "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43",
1361
- feedObject: "0x9a62b4863bdeaabdc9500fce769cf7e72d5585eeb28a6d26e4cafadc13f76ab2"
1362
- }
1363
- }
1364
- },
1365
- weth: {
1366
- id: "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",
1367
- metaData: "0x8900e4ceede3363bef086d6b50ca89d816d0e90bf6bc46efefe1f8455e08f50f",
1368
- treasury: "",
1369
- oracle: {
1370
- supra: "",
1371
- switchboard: "",
1372
- pyth: {
1373
- feed: "ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",
1374
- feedObject: "0x9193fd47f9a0ab99b6e365a464c8a9ae30e6150fc37ed2a89c1586631f6fc4ab"
1375
- }
1376
- }
1377
- },
1378
- wusdc: {
1379
- id: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf",
1380
- metaData: "0x4fbf84f3029bd0c0b77164b587963be957f853eccf834a67bb9ecba6ec80f189",
1381
- treasury: "",
1382
- oracle: {
1383
- supra: "",
1384
- switchboard: "",
1385
- pyth: {
1386
- feed: "eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
1387
- feedObject: "0x5dec622733a204ca27f5a90d8c2fad453cc6665186fd5dff13a83d0b6c9027ab"
1388
- }
1389
- }
1390
- },
1391
- wusdt: {
1392
- id: "0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c",
1393
- metaData: "0xfb0e3eb97dd158a5ae979dddfa24348063843c5b20eb8381dd5fa7c93699e45c",
1394
- treasury: "",
1395
- oracle: {
1396
- supra: "",
1397
- switchboard: "",
1398
- pyth: {
1399
- feed: "2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b",
1400
- feedObject: "0x985e3db9f93f76ee8bace7c3dd5cc676a096accd5d9e09e9ae0fb6e492b14572"
1401
- }
1402
- }
1403
- },
1404
- sui: {
1405
- id: "0x0000000000000000000000000000000000000000000000000000000000000002",
1406
- metaData: "0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3",
1407
- treasury: "",
1408
- oracle: {
1409
- supra: "",
1410
- switchboard: "0xbca474133638352ba83ccf7b5c931d50f764b09550e16612c9f70f1e21f3f594",
1411
- pyth: {
1412
- feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
1413
- feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
1414
- }
1415
- }
1416
- },
1417
- afsui: {
1418
- id: "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc",
1419
- metaData: "0x2f9217f533e51334873a39b8026a4aa6919497b47f49d0986a4f1aec66f8a34d",
1420
- treasury: "",
1421
- oracle: {
1422
- supra: "",
1423
- switchboard: "",
1424
- pyth: {
1425
- feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
1426
- feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
1427
- }
1428
- }
1429
- },
1430
- hasui: {
1431
- id: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",
1432
- metaData: "0x2c5f33af93f6511df699aaaa5822d823aac6ed99d4a0de2a4a50b3afa0172e24",
1433
- treasury: "",
1434
- oracle: {
1435
- supra: "",
1436
- switchboard: "",
1437
- pyth: {
1438
- feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
1439
- feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
1440
- }
1441
- }
1442
- },
1443
- vsui: {
1444
- id: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",
1445
- metaData: "0xabd84a23467b33854ab25cf862006fd97479f8f6f53e50fe732c43a274d939bd",
1446
- treasury: "",
1447
- oracle: {
1448
- supra: "",
1449
- switchboard: "",
1450
- pyth: {
1451
- feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
1452
- feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
1453
- }
1541
+ // src/utils/tokenBucket.ts
1542
+ var TokenBucket = class {
1543
+ constructor(tokensPerInterval, intervalInMs) {
1544
+ this.tokensPerInterval = tokensPerInterval;
1545
+ this.interval = intervalInMs;
1546
+ this.tokens = tokensPerInterval;
1547
+ this.lastRefill = Date.now();
1548
+ }
1549
+ refill() {
1550
+ const now = Date.now();
1551
+ const elapsed = now - this.lastRefill;
1552
+ if (elapsed > this.interval) {
1553
+ const tokensToAdd = Math.floor(elapsed / this.interval) * this.tokensPerInterval;
1554
+ this.tokens = Math.min(this.tokens + tokensToAdd, this.tokensPerInterval);
1555
+ this.lastRefill = now;
1556
+ }
1557
+ }
1558
+ removeTokens(count) {
1559
+ this.refill();
1560
+ if (this.tokens >= count) {
1561
+ this.tokens -= count;
1562
+ return true;
1563
+ }
1564
+ return false;
1565
+ }
1566
+ };
1567
+ var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 30, backoffFactor = 1.25) => {
1568
+ let retries = 0;
1569
+ const tryRequest = async () => {
1570
+ if (tokenBucket.removeTokens(1)) {
1571
+ try {
1572
+ const result = await fn();
1573
+ if (result && result.status === 429) {
1574
+ throw new Error("Unexpected status code: 429");
1454
1575
  }
1455
- },
1456
- sca: {
1457
- id: "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6",
1458
- metaData: "0x5d26a1e9a55c88147ac870bfa31b729d7f49f8804b8b3adfdf3582d301cca844",
1459
- treasury: "",
1460
- oracle: {
1461
- supra: "",
1462
- switchboard: "",
1463
- pyth: {
1464
- feed: "7e17f0ac105abe9214deb9944c30264f5986bf292869c6bd8e8da3ccd92d79bc",
1465
- feedObject: "0xf6de1d3279a269a597d813cbaca59aa906543ab9a8c64e84a4722f1a20863985"
1466
- }
1576
+ return result;
1577
+ } catch (error) {
1578
+ if (error.message === "Unexpected status code: 429" && retries < maxRetries) {
1579
+ retries++;
1580
+ const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
1581
+ await new Promise((resolve) => setTimeout(resolve, delay));
1582
+ return tryRequest();
1583
+ } else {
1584
+ console.error("An error occurred:", error.message);
1585
+ return null;
1467
1586
  }
1468
1587
  }
1469
- },
1470
- oracles: {
1471
- xOracle: "0x93d5bf0936b71eb27255941e532fac33b5a5c7759e377b4923af0a1359ad494f",
1472
- xOracleCap: "0x1edeae568fde99e090dbdec4bcdbd33a15f53a1ce1f87aeef1a560dedf4b4a90",
1473
- supra: { registry: "", registryCap: "", holder: "" },
1474
- switchboard: { registry: "", registryCap: "" },
1475
- pyth: {
1476
- registry: "0xedc293f9413a5a7a5d53bdba1fd889d0a4030894469228f0acdae4aa3c55a213",
1477
- registryCap: "0xbcb07141eb1f7e01fbda4130ecf5f5adaeabb77f5d9c32158b7532bcd2197acd",
1478
- state: "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8",
1479
- wormhole: "0x5306f64e312b581766351c07af79c72fcb1cd25147157fdc2f8ad76de9a3fb6a",
1480
- wormholeState: "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c"
1481
- }
1482
- },
1483
- packages: {
1484
- coinDecimalsRegistry: {
1485
- id: "0xca5a5a62f01c79a104bf4d31669e29daa387f325c241de4edbe30986a9bc8b0d",
1486
- upgradeCap: "0x34e76a945d29f195bc53ca704fa70877d1cf3a5d7bbfdda1b13e633fff13c0f6"
1487
- },
1488
- math: {
1489
- id: "0xad013d5fde39e15eabda32b3dbdafd67dac32b798ce63237c27a8f73339b9b6f",
1490
- upgradeCap: "0x3a329598231de02e6135c62284b66005b41cad1d9ab7ca2dc79c08293aba2ec6"
1491
- },
1492
- whitelist: {
1493
- id: "0x1318fdc90319ec9c24df1456d960a447521b0a658316155895014a6e39b5482f",
1494
- upgradeCap: "0xf5a22aea23db664f7b69855b6a546747f17c1ec4230319cfc17225e462b05761"
1495
- },
1496
- x: {
1497
- id: "0x779b5c547976899f5474f3a5bc0db36ddf4697ad7e5a901db0415c2281d28162",
1498
- upgradeCap: "0x3f203f6fff6a69d151e4f1cd931f22b68c489ef2759765662fc7baf673943c9e"
1499
- },
1500
- protocol: {
1501
- id: "0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1",
1502
- upgradeCap: "0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a"
1503
- },
1504
- // protocol: {
1505
- // id: '0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e',
1506
- // upgradeCap:
1507
- // '0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a',
1508
- // },
1509
- protocolWhitelist: {
1510
- id: "0x4c262d9343dac53ecb28f482a2a3f62c73d0ebac5b5f03d57383d56ff219acdf",
1511
- upgradeCap: "0x4a5e88a75039b00988f633f811f58117f31b8627a46bf822aa114d9010049449"
1512
- },
1513
- // query: {
1514
- // id: '0xb8d603a39114a5efef3dd0bf84df0bed1be1fbd39b78b7dd6e8a61ccc5e6006f',
1515
- // upgradeCap:
1516
- // '0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f',
1517
- // },
1518
- query: {
1519
- id: "0xe4f9d62d17746d5b9dbf0d5557747430021a71575780b515161210cdba0a4c1c",
1520
- upgradeCap: "0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f"
1521
- },
1522
- supra: { id: "", upgradeCap: "" },
1523
- pyth: {
1524
- id: "0x910f30cbc7f601f75a5141a01265cd47c62d468707c5e1aecb32a18f448cb25a",
1525
- upgradeCap: "0xdf0ffbae1ea5bb25fbca5efba433dcf00c7cced65679af2f04728901275c6157"
1526
- },
1527
- switchboard: { id: "", upgradeCap: "" },
1528
- xOracle: {
1529
- id: "0x1478a432123e4b3d61878b629f2c692969fdb375644f1251cd278a4b1e7d7cd6",
1530
- upgradeCap: "0x0f928a6b2e26b73330fecaf9b44acfc9800a4a9794d6415c2a3153bc70e3c1f0"
1531
- },
1532
- testCoin: { id: "", upgradeCap: "" }
1588
+ } else if (retries < maxRetries) {
1589
+ retries++;
1590
+ const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
1591
+ await new Promise((resolve) => setTimeout(resolve, delay));
1592
+ return tryRequest();
1593
+ } else {
1594
+ console.error("Maximum retries reached");
1595
+ return null;
1533
1596
  }
1534
- },
1535
- spool: {
1536
- // id: '0x7c4fdabe81c31b19a45d1e572a52a539997a90903fbb5bfab71480abe0fa62c3',
1537
- id: "0x1742655fe5872dfa6456673f9e38612a4965e6979e6cd7696a7f1225f28bae21",
1538
- adminCap: "0xdd8a047cbbf802bfcde5288b8ef1910965d789cc614da11d39af05fca0bd020a",
1539
- // object:
1540
- // '0xe87f1b2d498106a2c61421cec75b7b5c5e348512b0dc263949a0e7a3c256571a',
1541
- object: "0x1742655fe5872dfa6456673f9e38612a4965e6979e6cd7696a7f1225f28bae21",
1542
- pools: {
1543
- sweth: {
1544
- id: "0xeec40beccb07c575bebd842eeaabb835f77cd3dab73add433477e57f583a6787",
1545
- rewardPoolId: "0x957de68a18d87817de8309b30c1ec269a4d87ae513abbeed86b5619cb9ce1077"
1546
- },
1547
- ssui: {
1548
- // id: '0x4f0ba970d3c11db05c8f40c64a15b6a33322db3702d634ced6536960ab6f3ee4',
1549
- id: "0xb9617f83c06ebdeac0a8834782b1015e1cc7ea23739e30c132c4bfb95c37a579",
1550
- rewardPoolId: (
1551
- // '0x162250ef72393a4ad3d46294c4e1bdfcb03f04c869d390e7efbfc995353a7ee9',
1552
- "0xc3206071a8d43212efb6e3b5504f2321f8df97ab122b466c0bc7cfdf398dc13a"
1553
- )
1554
- },
1555
- swusdc: {
1556
- // id: '0x4ace6648ddc64e646ba47a957c562c32c9599b3bba8f5ac1aadb2ae23a2f8ca0',
1557
- id: "0xf1b383b9cf2e9f515fc69567df1053098f273849d09cd84b0278a773429bd2b2",
1558
- rewardPoolId: (
1559
- // '0xf4268cc9b9413b9bfe09e8966b8de650494c9e5784bf0930759cfef4904daff8',
1560
- "0xc71c53ee6505d928ba15bea4fe4f45d98c9c31eced94b72d00a7827d4b7ba3ff"
1561
- )
1562
- },
1563
- swusdt: {
1564
- // id: '0xcb328f7ffa7f9342ed85af3fdb2f22919e1a06dfb2f713c04c73543870d7548f',
1565
- id: "0xb5567dfa5c7fc17a249e959732664c50713dd8c23db1a11376b27df800c17418",
1566
- rewardPoolId: (
1567
- // '0x2c9f934d67a5baa586ceec2cc24163a2f049a6af3d5ba36b84d8ac40f25c4080',
1568
- "0x60768b0687ff0235e376a039709a683e4c436098785e473b67b32dbab47b69ab"
1569
- )
1570
- },
1571
- scetus: {
1572
- id: "0xac1bb13bf4472a637c18c2415fb0e3c1227ea2bcf35242e50563c98215bd298e",
1573
- rewardPoolId: "0x6835c1224126a45086fc6406adc249e3f30df18d779ca4f4e570e38716a17f3f"
1574
- },
1575
- safsui: {
1576
- // id: '0xeedf438abcaa6ce4d9625ffca110920592d5867e4c5637d84ad9f466c4feb800',
1577
- id: "0xc568bb4c991258e839aa54802ecda04fcd9838c826bc3b42b40af81b23c458c8",
1578
- rewardPoolId: (
1579
- // '0x89255a2f86ed7fbfef35ab8b7be48cc7667015975be2685dd9a55a9a64baf76e',
1580
- "0x389a3cbeda742b918941bb24fd00e077bad3367484394d6234f8209b9a6aa03d"
1581
- )
1582
- },
1583
- shasui: {
1584
- // id: '0xa6148bc1b623e936d39a952ceb5bea79e8b37228a8f595067bf1852efd3c34aa',
1585
- id: "0x93f3f4499bf89f2d05ddc1f8b15f51701a7c6c4d0ac0b9c3bc99462cbbd8e321",
1586
- rewardPoolId: (
1587
- // '0x6f3563644d3e2ef13176dbf9d865bd93479df60ccbe07b7e66db57f6309f5a66',
1588
- "0x94cee1be7f5ff34193f3aabef0b14142cb28af4d905fe487a9a7d85a15edb6aa"
1589
- )
1590
- },
1591
- svsui: {
1592
- // id: '0x69ce8e537e750a95381e6040794afa5ab1758353a1a2e1de7760391b01f91670',
1593
- id: "0xa970e9087f80cb59e9299b8e7af7175d977ad6c9af0322aa4440e138fbd7ae00",
1594
- rewardPoolId: (
1595
- // '0xbca914adce058ad0902c7f3cfcd698392a475f00dcfdc3f76001d0370b98777a',
1596
- "0x38eee9699c4fc132a6623e54b865f047df4fc6eb83af807300f44e8f4b235ff0"
1597
- )
1597
+ };
1598
+ return tryRequest();
1599
+ };
1600
+
1601
+ // src/utils/indexer.ts
1602
+ async function callMethodWithIndexerFallback(method, context, ...args) {
1603
+ const indexer = args[args.length - 1];
1604
+ if (indexer) {
1605
+ try {
1606
+ return await method.apply(context, args);
1607
+ } catch (e) {
1608
+ console.warn(`Indexer requests failed: ${e}. Retrying without indexer..`);
1609
+ return await method.apply(context, [...args.slice(0, -1), false]);
1610
+ }
1611
+ }
1612
+ return await method.apply(context, args);
1613
+ }
1614
+ function withIndexerFallback(method) {
1615
+ return (...args) => {
1616
+ return callMethodWithIndexerFallback(method, this, ...args);
1617
+ };
1618
+ }
1619
+
1620
+ // src/models/scallopCache.ts
1621
+ var ScallopCache = class {
1622
+ constructor(suiKit, walletAddress, cacheOptions, tokenBucket, queryClient) {
1623
+ this.queryClient = queryClient ?? new import_query_core.QueryClient(cacheOptions ?? DEFAULT_CACHE_OPTIONS);
1624
+ this._suiKit = suiKit;
1625
+ this.tokenBucket = tokenBucket ?? new TokenBucket(DEFAULT_TOKENS_PER_INTERVAL, DEFAULT_INTERVAL_IN_MS);
1626
+ this.walletAddress = walletAddress ?? suiKit.currentAddress();
1627
+ }
1628
+ get suiKit() {
1629
+ if (!this._suiKit) {
1630
+ throw new Error("SuiKit instance is not initialized");
1631
+ }
1632
+ return this._suiKit;
1633
+ }
1634
+ get client() {
1635
+ return this.suiKit.client();
1636
+ }
1637
+ /**
1638
+ * @description Invalidate cache based on the refetchType parameter
1639
+ * @param refetchType Determines the type of queries to be refetched. Defaults to `active`.
1640
+ *
1641
+ * - `active`: Only queries that match the refetch predicate and are actively being rendered via useQuery and related functions will be refetched in the background.
1642
+ * - `inactive`: Only queries that match the refetch predicate and are NOT actively being rendered via useQuery and related functions will be refetched in the background.
1643
+ * - `all`: All queries that match the refetch predicate will be refetched in the background.
1644
+ * - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
1645
+ */
1646
+ async invalidateAllCache() {
1647
+ return Object.values(queryKeys.rpc).map(
1648
+ (t) => this.queryClient.invalidateQueries({
1649
+ queryKey: t(),
1650
+ type: "all"
1651
+ })
1652
+ );
1653
+ }
1654
+ /**
1655
+ * @description Provides cache for inspectTxn of the SuiKit.
1656
+ * @param QueryInspectTxnParams
1657
+ * @param txBlock
1658
+ * @returns Promise<DevInspectResults>
1659
+ */
1660
+ async queryInspectTxn({
1661
+ queryTarget,
1662
+ args,
1663
+ typeArgs
1664
+ }) {
1665
+ const txBlock = new import_sui_kit.SuiTxBlock();
1666
+ txBlock.moveCall(queryTarget, args, typeArgs);
1667
+ const query = await this.queryClient.fetchQuery({
1668
+ queryKey: queryKeys.rpc.getInspectTxn(queryTarget, args, typeArgs),
1669
+ queryFn: async () => {
1670
+ return await callWithRateLimit(
1671
+ this.tokenBucket,
1672
+ () => this.suiKit.inspectTxn(txBlock)
1673
+ );
1674
+ }
1675
+ });
1676
+ return query;
1677
+ }
1678
+ /**
1679
+ * @description Provides cache for getObject of the SuiKit.
1680
+ * @param objectId
1681
+ * @param QueryObjectParams
1682
+ * @returns Promise<SuiObjectResponse>
1683
+ */
1684
+ async queryGetObject(objectId, options) {
1685
+ return this.queryClient.fetchQuery({
1686
+ queryKey: queryKeys.rpc.getObject(objectId, this.walletAddress, options),
1687
+ queryFn: async () => {
1688
+ return await callWithRateLimit(
1689
+ this.tokenBucket,
1690
+ () => this.client.getObject({
1691
+ id: objectId,
1692
+ options
1693
+ })
1694
+ );
1695
+ }
1696
+ });
1697
+ }
1698
+ /**
1699
+ * @description Provides cache for getObjects of the SuiKit.
1700
+ * @param objectIds
1701
+ * @returns Promise<SuiObjectData[]>
1702
+ */
1703
+ async queryGetObjects(objectIds, options = {
1704
+ showContent: true
1705
+ }) {
1706
+ if (objectIds.length === 0)
1707
+ return [];
1708
+ return this.queryClient.fetchQuery({
1709
+ queryKey: queryKeys.rpc.getObjects(
1710
+ objectIds,
1711
+ this.walletAddress,
1712
+ options
1713
+ ),
1714
+ queryFn: async () => {
1715
+ return await callWithRateLimit(
1716
+ this.tokenBucket,
1717
+ () => this.suiKit.getObjects(objectIds, options)
1718
+ );
1598
1719
  }
1599
- },
1600
- config: ""
1601
- },
1602
- borrowIncentive: {
1603
- id: "0x6152f696fc3a658f33c4b891764731a59153125ffedfa8bff7167c42823f58a9",
1604
- adminCap: "0xc486afa253646f4d381e81d7f1df8aa4723b845a6bb356f69bad635ffefffe2c",
1605
- object: "0x002875153e09f8145ab63527bc85c00f2bd102e12f9573c47f8cdf1a1cb62934",
1606
- query: "0x529edc54a3dce2207703ceebbccb0ac14133f7825c1f528775ba0d85a4063489",
1607
- incentivePools: "0x6547e143d406b5ccd5f46aae482497de279cc1a68c406f701df70a05f9212ab4",
1608
- incentiveAccounts: "0xc4701fdbc1c92f9a636d334d66012b3027659e9fb8aff27279a82edfb6b77d02",
1609
- config: "0xdf5d04b4691cc67e82fd4db8394d89ff44823a9de29716c924f74bb4f11cc1f7"
1610
- },
1611
- referral: {
1612
- id: "0xa3654ebb63eb06c0f4ff52f8aa6512df9f164f7772bdf15dac3709bd3798dda9",
1613
- object: "0x5658d4bf5ddcba27e4337b4262108b3ad1716643cac8c2054ac341538adc72ec",
1614
- adminCap: "0xc5dc06b9074291259f2cac460c940012c781c4430e42125c541cc43101c3bcbd",
1615
- referralBindings: "0xf63299d58789d99de94092b9011323466e55ca0c1ea1a7a3786a589af46e1c09",
1616
- bindingTableId: "0x1c8202b17267ec8d6cf97ca013615354181a04f179570e42601ff2dae19294b1",
1617
- referralRevenuePool: "0x6abd852caf90769c1b185cdf636d841673fa95528f0550f018b8a138bd283c07",
1618
- revenueTableId: "0x595baa3654c297bff84ab7786a2d250f019cefc66e8df8e89fd9d41e02bd30dd",
1619
- referralTiers: "0x962cb903d8d7346190c5204785ccbb91b61086aa764f674c8145df82335cf83e",
1620
- tiersTableId: "0xeac755a7a8b7798530905ac79e8c114f19d0f130f6eab012954f08faac29c75d",
1621
- // authorizedWitnessList:
1622
- // '0xf21b0ed043c9bb70842c0129159f4943dbcc3c9ef2f2f808af65f8be25cfd20e',
1623
- authorizedWitnessList: "0x9d6223dc52015b8a3986a573590ef2af8f1b8f3e4685513888c052f001b87e7f",
1624
- version: "0x1bd4b7285f72e11c316b828c7c47b3f4da18dcec9f9b3dba6d8629cbb6f93e5e"
1625
- },
1626
- vesca: {
1627
- id: "0xb15b6e0cdd85afb5028bea851dd249405e734d800a259147bbc24980629723a4",
1628
- object: "0xb15b6e0cdd85afb5028bea851dd249405e734d800a259147bbc24980629723a4",
1629
- adminCap: "0x8ffa76135c5b85c5fbd73a6448a4a733d826cb63a267ab817656acb77c72d4a5",
1630
- tableId: "0xe3153b2bf124be0b86cb8bd468346a861efd0da52fc42197b54d2f616488a311",
1631
- table: "0x611cb8d9d4d90867467b5ebdf4cc447a0047ed5b01334a28a29fcfe733e3d609",
1632
- treasury: "0xe8c112c09b88158dc6c8e23d1fbae5b3c7136cdee54b7dafc08e65db28c4a5bc",
1633
- config: "0xe0a2ff281e73c1d53cfa85807080f87e833e4f1a7f93dcf8800b3865269a76b9"
1634
- },
1635
- loyaltyProgram: {
1636
- id: "0xd17bcf8b5a59652c36225d478564a8593ae0ed7d650bcacdda1d6fe179127907",
1637
- object: "0xd17bcf8b5a59652c36225d478564a8593ae0ed7d650bcacdda1d6fe179127907",
1638
- rewardPool: "0xf9c090492ef476bd542109d0913ffe871cbfa28578b7114eca2a8c0e5671786f",
1639
- userRewardTableId: "0x748a80395849ed37db1b0e14f2ab5d1d96458d2359ab3a84eb079d0f4ac7cf2e"
1640
- },
1641
- scoin: {
1642
- id: "0xad2ca2aa5089df94bb2d444d5eb3520378c2f2dfb3a0bd2a2c994145ac4b0a53",
1643
- coins: {
1644
- ssui: {
1645
- coinType: "0xfac769100bccc0caebcf4f4e2d00ac2f8883f07f724be28940df90605f5e7e9a::scallop_sui::SCALLOP_SUI",
1646
- treasury: "0x9cb4551b36c17d37e19d700147fa819ea1c487ff8bcf18374de2cceb2e9d4845"
1647
- },
1648
- scetus: {
1649
- coinType: "0x8b71e6d323ed78515af2bead13bf3d0da1562ba4a99234eb7c4f14fd39ef0427::scallop_cetus::SCALLOP_CETUS",
1650
- treasury: "0xd786f4b2d26278cc7911a3445b1b085eab60f269ef9dbb6b87e803d52f155003"
1651
- },
1652
- ssca: {
1653
- coinType: "0x0a9d3c6c9af9f6e8def82921541bcbd17f73ed31bed3adcb684f2a4c267e42f0::scallop_sca::SCALLOP_SCA",
1654
- treasury: "0xe818636d1d6c46d6ea1a2dce9d94696d7cbc18ce27451b603eeaa47aba8d75e0"
1655
- },
1656
- swusdc: {
1657
- coinType: "0xaedc3ab75db8680b81a755015fa90124d217be93457b893c05bac033817defaf::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
1658
- treasury: "0xfc6971648f867f7fd6928d1b873af71577e2eaf2c7543ef8bc82c431d833ae78"
1659
- },
1660
- swusdt: {
1661
- coinType: "0xbf02fc87ddc104b342ad8414c85ceadf5b0c823c055a06fb0ed776272c01a52a::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
1662
- treasury: "0xb9593e2c3a0ba796ee815012b75ae46468ea78cda0188b9ac6816efe65503521"
1663
- },
1664
- sweth: {
1665
- coinType: "0x27d54f43e3eda701be56b82e5756e41c84467cd202f5cf713d5f9e45a9f1b6bc::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
1666
- treasury: "0x032b4c8fac94c038dbe986f7587e9b1e4ef580b5ee06d2ef249d85459b7ef05d"
1667
- },
1668
- safsui: {
1669
- coinType: "0xb75b46d975d8d80670b53a6bee90baaa8ce2e0b7d397f079447d641eef6b44ad::scallop_af_sui::SCALLOP_AF_SUI",
1670
- treasury: "0x21450ef0570ef3d224ffa3b873ab802e439ece7b93cc7efad10ae0c1e3b3fcfe"
1671
- },
1672
- shasui: {
1673
- coinType: "0xd973a723874e2c7cde196602a79155a1343a933f8cf87d9b1bb7408bc1acbc58::scallop_ha_sui::SCALLOP_HA_SUI",
1674
- treasury: "0xf822fc1402207e47d2e3ba8ff6e1e594bf1de777dc5ebd2744619cd2726e3b0d"
1675
- },
1676
- svsui: {
1677
- coinType: "0x97023a317320c4498cc4cd239dd02fd30c28246e5e8f81325d63f2bd8d70f6b3::scallop_v_sui::SCALLOP_V_SUI",
1678
- treasury: "0x327114f0bf3559d7e2de10282147ed76a236c7c6775029165c4db09a6062ead6\u0192"
1720
+ });
1721
+ }
1722
+ /**
1723
+ * @description Provides cache for getOwnedObjects of the SuiKit.
1724
+ * @param input
1725
+ * @returns Promise<PaginatedObjectsResponse>
1726
+ */
1727
+ async queryGetOwnedObjects(input) {
1728
+ return this.queryClient.fetchQuery({
1729
+ queryKey: queryKeys.rpc.getOwnedObjects(input),
1730
+ queryFn: async () => {
1731
+ return await callWithRateLimit(
1732
+ this.tokenBucket,
1733
+ () => this.client.getOwnedObjects(input)
1734
+ );
1679
1735
  }
1680
- }
1736
+ });
1737
+ }
1738
+ async queryGetDynamicFields(input) {
1739
+ return this.queryClient.fetchQuery({
1740
+ queryKey: queryKeys.rpc.getDynamicFields(input),
1741
+ queryFn: async () => {
1742
+ return await callWithRateLimit(
1743
+ this.tokenBucket,
1744
+ () => this.client.getDynamicFields(input)
1745
+ );
1746
+ }
1747
+ });
1748
+ }
1749
+ async queryGetDynamicFieldObject(input) {
1750
+ return this.queryClient.fetchQuery({
1751
+ queryKey: queryKeys.rpc.getDynamicFieldObject(input),
1752
+ queryFn: async () => {
1753
+ return await callWithRateLimit(
1754
+ this.tokenBucket,
1755
+ () => this.client.getDynamicFieldObject(input)
1756
+ );
1757
+ }
1758
+ });
1759
+ }
1760
+ async queryGetAllCoinBalances(owner) {
1761
+ return this.queryClient.fetchQuery({
1762
+ queryKey: queryKeys.rpc.getAllCoinBalances(owner),
1763
+ queryFn: async () => {
1764
+ const allBalances = await callWithRateLimit(
1765
+ this.tokenBucket,
1766
+ () => this.client.getAllBalances({ owner })
1767
+ );
1768
+ if (!allBalances)
1769
+ return {};
1770
+ const balances = allBalances.reduce(
1771
+ (acc, coinBalance) => {
1772
+ if (coinBalance.totalBalance !== "0") {
1773
+ acc[(0, import_sui_kit.normalizeStructTag)(coinBalance.coinType)] = coinBalance.totalBalance;
1774
+ }
1775
+ return acc;
1776
+ },
1777
+ {}
1778
+ );
1779
+ return balances;
1780
+ }
1781
+ });
1782
+ }
1783
+ async queryGetCoinBalance(input) {
1784
+ if (!input.coinType)
1785
+ return "0";
1786
+ return (await this.queryGetAllCoinBalances(input.owner) ?? {})[(0, import_sui_kit.normalizeStructTag)(input.coinType)] ?? "0";
1681
1787
  }
1682
1788
  };
1683
1789
 
1684
1790
  // src/models/scallopAddress.ts
1791
+ var import_axios = __toESM(require("axios"));
1685
1792
  var EMPTY_ADDRESSES = {
1686
1793
  core: {
1687
1794
  version: "",
@@ -2037,12 +2144,12 @@ var ScallopAddress = class {
2037
2144
  "Content-Type": "application/json",
2038
2145
  Accept: "application/json"
2039
2146
  },
2040
- timeout: 3e4
2147
+ timeout: 8e3
2041
2148
  });
2042
2149
  if (auth)
2043
2150
  this._auth = auth;
2044
2151
  this._id = id;
2045
- this._network = network || "mainnet";
2152
+ this._network = network ?? "mainnet";
2046
2153
  this._addressesMap = USE_TEST_ADDRESS ? /* @__PURE__ */ new Map([["mainnet", TEST_ADDRESSES]]) : /* @__PURE__ */ new Map();
2047
2154
  if (USE_TEST_ADDRESS)
2048
2155
  this._currentAddresses = TEST_ADDRESSES;
@@ -2345,11 +2452,9 @@ var ScallopAddress = class {
2345
2452
 
2346
2453
  // src/models/scallopClient.ts
2347
2454
  var import_utils25 = require("@mysten/sui/utils");
2348
- var import_sui_kit15 = require("@scallop-io/sui-kit");
2349
2455
 
2350
2456
  // src/models/scallopUtils.ts
2351
2457
  var import_utils10 = require("@mysten/sui/utils");
2352
- var import_sui_kit4 = require("@scallop-io/sui-kit");
2353
2458
  var import_pyth_sui_js = require("@pythnetwork/pyth-sui-js");
2354
2459
 
2355
2460
  // src/queries/coreQuery.ts
@@ -2392,19 +2497,19 @@ var getSupplyLimit = async (utils, poolName) => {
2392
2497
  };
2393
2498
 
2394
2499
  // src/queries/coreQuery.ts
2395
- var queryMarket = async (query, indexer = false) => {
2396
- const coinPrices = await query.utils.getCoinPrices();
2500
+ var queryMarket = async (query, indexer = false, coinPrices) => {
2501
+ coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
2397
2502
  const pools = {};
2398
2503
  const collaterals = {};
2399
2504
  if (indexer) {
2400
2505
  const marketIndexer = await query.indexer.getMarket();
2401
2506
  const updatePools = (item) => {
2402
- item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
2507
+ item.coinPrice = coinPrices[item.coinName] ?? item.coinPrice;
2403
2508
  item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
2404
2509
  pools[item.coinName] = item;
2405
2510
  };
2406
2511
  const updateCollaterals = (item) => {
2407
- item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
2512
+ item.coinPrice = coinPrices[item.coinName] ?? item.coinPrice;
2408
2513
  item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
2409
2514
  collaterals[item.coinName] = item;
2410
2515
  };
@@ -2524,19 +2629,19 @@ var queryMarket = async (query, indexer = false) => {
2524
2629
  // data: marketData,
2525
2630
  };
2526
2631
  };
2527
- var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer = false) => {
2632
+ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer = false, coinPrices) => {
2528
2633
  const marketId = query.address.get("core.market");
2529
2634
  const marketObjectResponse = await query.cache.queryGetObject(marketId, {
2530
2635
  showContent: true
2531
2636
  });
2532
- const coinPrices = await query.utils.getCoinPrices(poolCoinNames) ?? {};
2637
+ coinPrices = await query.utils.getCoinPrices(poolCoinNames) ?? {};
2533
2638
  const marketPools = {};
2534
2639
  if (indexer) {
2535
2640
  const marketPoolsIndexer = await query.indexer.getMarketPools();
2536
2641
  const updateMarketPool = (marketPool) => {
2537
2642
  if (!poolCoinNames.includes(marketPool.coinName))
2538
2643
  return;
2539
- marketPool.coinPrice = coinPrices[marketPool.coinName] || marketPool.coinPrice;
2644
+ marketPool.coinPrice = coinPrices[marketPool.coinName] ?? marketPool.coinPrice;
2540
2645
  marketPool.coinWrappedType = query.utils.getCoinWrappedType(
2541
2646
  marketPool.coinName
2542
2647
  );
@@ -2567,17 +2672,17 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2567
2672
  let borrowIndex;
2568
2673
  let interestModel;
2569
2674
  let borrowFeeRate;
2570
- coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2675
+ coinPrice = coinPrice ?? (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2571
2676
  if (indexer) {
2572
2677
  const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
2573
- marketPoolIndexer.coinPrice = coinPrice || marketPoolIndexer.coinPrice;
2678
+ marketPoolIndexer.coinPrice = coinPrice ?? marketPoolIndexer.coinPrice;
2574
2679
  marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
2575
2680
  marketPoolIndexer.coinName
2576
2681
  );
2577
2682
  return marketPoolIndexer;
2578
2683
  }
2579
2684
  const marketId = query.address.get("core.market");
2580
- marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2685
+ marketObject = marketObject ?? (await query.cache.queryGetObject(marketId, {
2581
2686
  showContent: true
2582
2687
  }))?.data;
2583
2688
  if (marketObject) {
@@ -2595,7 +2700,9 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2595
2700
  }
2596
2701
  });
2597
2702
  if (!balanceSheetDynamicFieldObjectResponse)
2598
- return void 0;
2703
+ throw new Error(
2704
+ `Failed to fetch balanceSheetDynamicFieldObjectResponse for ${poolCoinName}`
2705
+ );
2599
2706
  const balanceSheetDynamicFieldObject = balanceSheetDynamicFieldObjectResponse.data;
2600
2707
  if (balanceSheetDynamicFieldObject && balanceSheetDynamicFieldObject.content && "fields" in balanceSheetDynamicFieldObject.content) {
2601
2708
  const dynamicFields = balanceSheetDynamicFieldObject.content.fields;
@@ -2612,7 +2719,9 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2612
2719
  }
2613
2720
  });
2614
2721
  if (!borrowIndexDynamicFieldObjectResponse)
2615
- return void 0;
2722
+ throw new Error(
2723
+ `Failed to fetch borrowIndexDynamicFieldObjectResponse for ${poolCoinName}`
2724
+ );
2616
2725
  const borrowIndexDynamicFieldObject = borrowIndexDynamicFieldObjectResponse.data;
2617
2726
  if (borrowIndexDynamicFieldObject && borrowIndexDynamicFieldObject.content && "fields" in borrowIndexDynamicFieldObject.content) {
2618
2727
  const dynamicFields = borrowIndexDynamicFieldObject.content.fields;
@@ -2629,7 +2738,9 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2629
2738
  }
2630
2739
  });
2631
2740
  if (!interestModelDynamicFieldObjectResponse)
2632
- return void 0;
2741
+ throw new Error(
2742
+ `Failed to fetch interestModelDynamicFieldObjectResponse for ${poolCoinName}`
2743
+ );
2633
2744
  const interestModelDynamicFieldObject = interestModelDynamicFieldObjectResponse.data;
2634
2745
  if (interestModelDynamicFieldObject && interestModelDynamicFieldObject.content && "fields" in interestModelDynamicFieldObject.content) {
2635
2746
  const dynamicFields = interestModelDynamicFieldObject.content.fields;
@@ -2647,7 +2758,9 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2647
2758
  }
2648
2759
  });
2649
2760
  if (!borrowFeeDynamicFieldObjectResponse)
2650
- return void 0;
2761
+ throw new Error(
2762
+ `Failed to fetch borrowFeeDynamicFieldObjectResponse for ${poolCoinName}`
2763
+ );
2651
2764
  const borrowFeeDynamicFieldObject = borrowFeeDynamicFieldObjectResponse.data;
2652
2765
  if (borrowFeeDynamicFieldObject && borrowFeeDynamicFieldObject.content && "fields" in borrowFeeDynamicFieldObject.content) {
2653
2766
  const dynamicFields = borrowFeeDynamicFieldObject.content.fields;
@@ -2669,7 +2782,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2669
2782
  reserve: balanceSheet.revenue,
2670
2783
  reserveFactor: interestModel.revenue_factor.fields,
2671
2784
  borrowWeight: interestModel.borrow_weight.fields,
2672
- borrowFeeRate: borrowFeeRate || { value: "0" },
2785
+ borrowFeeRate: borrowFeeRate ?? { value: "0" },
2673
2786
  baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
2674
2787
  borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
2675
2788
  borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
@@ -2720,7 +2833,7 @@ var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLA
2720
2833
  const updateMarketCollateral = (marketCollateral) => {
2721
2834
  if (!collateralCoinNames.includes(marketCollateral.coinName))
2722
2835
  return;
2723
- marketCollateral.coinPrice = coinPrices[marketCollateral.coinName] || marketCollateral.coinPrice;
2836
+ marketCollateral.coinPrice = coinPrices[marketCollateral.coinName] ?? marketCollateral.coinPrice;
2724
2837
  marketCollateral.coinWrappedType = query.utils.getCoinWrappedType(
2725
2838
  marketCollateral.coinName
2726
2839
  );
@@ -2752,7 +2865,7 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
2752
2865
  coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
2753
2866
  if (indexer) {
2754
2867
  const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
2755
- marketCollateralIndexer.coinPrice = coinPrice || marketCollateralIndexer.coinPrice;
2868
+ marketCollateralIndexer.coinPrice = coinPrice ?? marketCollateralIndexer.coinPrice;
2756
2869
  marketCollateralIndexer.coinWrappedType = query.utils.getCoinWrappedType(
2757
2870
  marketCollateralIndexer.coinName
2758
2871
  );
@@ -2842,7 +2955,7 @@ var getObligations = async ({
2842
2955
  address
2843
2956
  }, ownerAddress) => {
2844
2957
  const owner = ownerAddress;
2845
- const protocolObjectId = address.get("core.object") || PROTOCOL_OBJECT_ID;
2958
+ const protocolObjectId = address.get("core.object") ?? PROTOCOL_OBJECT_ID;
2846
2959
  const keyObjectsResponse = [];
2847
2960
  let hasNextPage = false;
2848
2961
  let nextCursor = null;
@@ -2909,7 +3022,7 @@ var queryObligation = async ({
2909
3022
  return queryResult?.events[0]?.parsedJson;
2910
3023
  };
2911
3024
  var getCoinAmounts = async (query, assetCoinNames = [...SUPPORT_POOLS], ownerAddress) => {
2912
- const owner = ownerAddress || query.suiKit.currentAddress();
3025
+ const owner = ownerAddress ?? query.suiKit.currentAddress();
2913
3026
  const assetCoins2 = {};
2914
3027
  await Promise.allSettled(
2915
3028
  assetCoinNames.map(async (assetCoinName) => {
@@ -2920,7 +3033,7 @@ var getCoinAmounts = async (query, assetCoinNames = [...SUPPORT_POOLS], ownerAdd
2920
3033
  return assetCoins2;
2921
3034
  };
2922
3035
  var getCoinAmount = async (query, assetCoinName, ownerAddress) => {
2923
- const owner = ownerAddress || query.suiKit.currentAddress();
3036
+ const owner = ownerAddress ?? query.suiKit.currentAddress();
2924
3037
  const coinType = query.utils.parseCoinType(assetCoinName);
2925
3038
  const amount = await query.cache.queryGetCoinBalance({
2926
3039
  owner,
@@ -2932,7 +3045,7 @@ var getMarketCoinAmounts = async (query, marketCoinNames, ownerAddress) => {
2932
3045
  marketCoinNames = marketCoinNames || [...SUPPORT_POOLS].map(
2933
3046
  (poolCoinName) => query.utils.parseMarketCoinName(poolCoinName)
2934
3047
  );
2935
- const owner = ownerAddress || query.suiKit.currentAddress();
3048
+ const owner = ownerAddress ?? query.suiKit.currentAddress();
2936
3049
  const marketCoins2 = {};
2937
3050
  await Promise.allSettled(
2938
3051
  marketCoinNames.map(async (marketCoinName) => {
@@ -2947,7 +3060,7 @@ var getMarketCoinAmounts = async (query, marketCoinNames, ownerAddress) => {
2947
3060
  return marketCoins2;
2948
3061
  };
2949
3062
  var getMarketCoinAmount = async (query, marketCoinName, ownerAddress) => {
2950
- const owner = ownerAddress || query.suiKit.currentAddress();
3063
+ const owner = ownerAddress ?? query.suiKit.currentAddress();
2951
3064
  const marketCoinType = query.utils.parseMarketCoinType(marketCoinName);
2952
3065
  const amount = await query.cache.queryGetCoinBalance({
2953
3066
  owner,
@@ -3016,18 +3129,14 @@ var getFlashLoanFees = async (query, assetNames) => {
3016
3129
 
3017
3130
  // src/queries/spoolQuery.ts
3018
3131
  var import_utils5 = require("@mysten/sui/utils");
3019
- var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexer = false) => {
3132
+ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexer = false, marketPools, coinPrices) => {
3020
3133
  const stakeCoinNames = stakeMarketCoinNames.map(
3021
3134
  (stakeMarketCoinName) => query.utils.parseCoinName(stakeMarketCoinName)
3022
3135
  );
3023
- const rewardCoinNames = stakeMarketCoinNames.map((stakeMarketCoinName) => {
3024
- const rewardCoinName = query.utils.getSpoolRewardCoinName(stakeMarketCoinName);
3025
- return rewardCoinName;
3026
- });
3027
- const coinPrices = await query.utils.getCoinPrices([
3028
- .../* @__PURE__ */ new Set([...stakeCoinNames, ...rewardCoinNames])
3029
- ]) ?? {};
3030
- const marketPools = await query.getMarketPools(stakeCoinNames, indexer);
3136
+ coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
3137
+ marketPools = marketPools ?? await query.getMarketPools(stakeCoinNames, indexer);
3138
+ if (!marketPools)
3139
+ throw new Error(`Fail to fetch marketPools for ${stakeCoinNames}`);
3031
3140
  const spools = {};
3032
3141
  if (indexer) {
3033
3142
  const spoolsIndexer = await query.indexer.getSpools();
@@ -3041,9 +3150,9 @@ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexe
3041
3150
  spool.marketCoinName
3042
3151
  );
3043
3152
  const marketPool = marketPools[coinName];
3044
- spool.coinPrice = coinPrices[coinName] || spool.coinPrice;
3045
- spool.marketCoinPrice = (coinPrices[coinName] ?? 0) * (marketPool ? marketPool.conversionRate : 0) || spool.marketCoinPrice;
3046
- spool.rewardCoinPrice = coinPrices[rewardCoinName] || spool.rewardCoinPrice;
3153
+ spool.coinPrice = coinPrices[coinName] ?? spool.coinPrice;
3154
+ spool.marketCoinPrice = coinPrices[coinName] ? (coinPrices[coinName] ?? 0) * (marketPool ? marketPool.conversionRate : 0) : spool.marketCoinPrice;
3155
+ spool.rewardCoinPrice = coinPrices[rewardCoinName] ?? spool.rewardCoinPrice;
3047
3156
  spools[spool.marketCoinName] = spool;
3048
3157
  };
3049
3158
  Object.values(spoolsIndexer).forEach(updateSpools);
@@ -3068,7 +3177,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
3068
3177
  const coinName = query.utils.parseCoinName(marketCoinName);
3069
3178
  marketPool = marketPool || await query.getMarketPool(coinName, indexer);
3070
3179
  if (!marketPool) {
3071
- throw new Error("Fail to fetch marketPool");
3180
+ throw new Error(`Fail to fetch marketPool for ${coinName}`);
3072
3181
  }
3073
3182
  const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
3074
3183
  const rewardPoolId = query.address.get(
@@ -3355,20 +3464,15 @@ var queryBorrowIncentivePools = async (address) => {
3355
3464
  };
3356
3465
  var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
3357
3466
  ...SUPPORT_BORROW_INCENTIVE_POOLS
3358
- ], indexer = false) => {
3467
+ ], indexer = false, coinPrices) => {
3359
3468
  const borrowIncentivePools = {};
3360
- const coinPrices = await query.utils.getCoinPrices([
3361
- .../* @__PURE__ */ new Set([
3362
- ...borrowIncentiveCoinNames,
3363
- ...SUPPORT_BORROW_INCENTIVE_REWARDS
3364
- ])
3365
- ]) ?? {};
3469
+ coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
3366
3470
  if (indexer) {
3367
3471
  const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
3368
3472
  const updateBorrowIncentivePool = (pool) => {
3369
3473
  if (!borrowIncentiveCoinNames.includes(pool.coinName))
3370
3474
  return;
3371
- pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
3475
+ pool.coinPrice = coinPrices[pool.coinName] ?? pool.coinPrice;
3372
3476
  borrowIncentivePools[pool.coinName] = pool;
3373
3477
  };
3374
3478
  Object.values(borrowIncentivePoolsIndexer).forEach(
@@ -3615,20 +3719,18 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
3615
3719
  const stakeMarketCoinNames = marketCoinNames.filter(
3616
3720
  (marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
3617
3721
  );
3618
- const [
3722
+ const coinPrices = await query.utils.getCoinPrices(poolCoinNames);
3723
+ const marketPools = await query.getMarketPools(poolCoinNames, indexer, {
3724
+ coinPrices
3725
+ });
3726
+ const spools = await query.getSpools(stakeMarketCoinNames, indexer, {
3619
3727
  marketPools,
3620
- spools,
3621
- coinAmounts,
3622
- marketCoinAmounts,
3623
- allStakeAccounts,
3624
3728
  coinPrices
3625
- ] = await Promise.all([
3626
- query.getMarketPools(poolCoinNames, indexer),
3627
- query.getSpools(stakeMarketCoinNames, indexer),
3729
+ });
3730
+ const [coinAmounts, marketCoinAmounts, allStakeAccounts] = await Promise.all([
3628
3731
  query.getCoinAmounts(poolCoinNames, ownerAddress),
3629
3732
  query.getMarketCoinAmounts(marketCoinNames, ownerAddress),
3630
- query.getAllStakeAccounts(ownerAddress),
3631
- query.utils.getCoinPrices(poolCoinNames)
3733
+ query.getAllStakeAccounts(ownerAddress)
3632
3734
  ]);
3633
3735
  const lendings = {};
3634
3736
  await Promise.allSettled(
@@ -3644,7 +3746,7 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
3644
3746
  indexer,
3645
3747
  marketPools?.[poolCoinName],
3646
3748
  stakeMarketCoinName ? spools[stakeMarketCoinName] : void 0,
3647
- stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : void 0,
3749
+ stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : [],
3648
3750
  coinAmounts?.[poolCoinName],
3649
3751
  marketCoinAmounts?.[marketCoinName],
3650
3752
  coinPrices?.[poolCoinName] ?? 0
@@ -3655,8 +3757,22 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
3655
3757
  };
3656
3758
  var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice, sCoinAmount) => {
3657
3759
  const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
3658
- marketPool = marketPool || await query.getMarketPool(poolCoinName, indexer);
3659
- spool = spool || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(marketCoinName, indexer) : void 0;
3760
+ coinPrice = coinPrice ?? (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
3761
+ marketPool = marketPool ?? await query.getMarketPool(poolCoinName, indexer, {
3762
+ coinPrice
3763
+ });
3764
+ if (!marketPool)
3765
+ throw new Error(`Failed to fetch marketPool for ${poolCoinName}`);
3766
+ spool = spool ?? SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(
3767
+ marketCoinName,
3768
+ indexer,
3769
+ {
3770
+ marketPool,
3771
+ coinPrices: {
3772
+ [poolCoinName]: coinPrice
3773
+ }
3774
+ }
3775
+ ) : void 0;
3660
3776
  stakeAccounts = stakeAccounts || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getStakeAccounts(
3661
3777
  marketCoinName,
3662
3778
  ownerAddress
@@ -3664,7 +3780,6 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
3664
3780
  coinAmount = coinAmount || await query.getCoinAmount(poolCoinName, ownerAddress);
3665
3781
  marketCoinAmount = marketCoinAmount || await query.getMarketCoinAmount(marketCoinName, ownerAddress);
3666
3782
  sCoinAmount = sCoinAmount || await query.getSCoinAmount(marketCoinName, ownerAddress);
3667
- coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
3668
3783
  const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
3669
3784
  let stakedMarketAmount = (0, import_bignumber4.default)(0);
3670
3785
  let stakedMarketCoin = (0, import_bignumber4.default)(0);
@@ -3776,10 +3891,12 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
3776
3891
  return lending;
3777
3892
  };
3778
3893
  var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
3779
- const market = await query.queryMarket(indexer);
3780
3894
  const coinPrices = await query.utils.getCoinPrices();
3781
- const coinAmounts = await query.getCoinAmounts(void 0, ownerAddress);
3782
- const obligations = await query.getObligations(ownerAddress);
3895
+ const market = await query.queryMarket(indexer, { coinPrices });
3896
+ const [coinAmounts, obligations] = await Promise.all([
3897
+ query.getCoinAmounts(void 0, ownerAddress),
3898
+ query.getObligations(ownerAddress)
3899
+ ]);
3783
3900
  const obligationAccounts = {};
3784
3901
  await Promise.allSettled(
3785
3902
  obligations.map(async (obligation) => {
@@ -3797,22 +3914,19 @@ var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
3797
3914
  return obligationAccounts;
3798
3915
  };
3799
3916
  var getObligationAccount = async (query, obligationId, ownerAddress, indexer = false, market, coinPrices, coinAmounts) => {
3800
- market = market || await query.queryMarket(indexer);
3801
3917
  const collateralAssetCoinNames = [
3802
- .../* @__PURE__ */ new Set([
3803
- ...Object.values(market.collaterals).map(
3804
- (collateral) => collateral.coinName
3805
- )
3806
- ])
3918
+ ...SUPPORT_COLLATERALS
3807
3919
  ];
3808
- const obligationQuery = await query.queryObligation(obligationId);
3809
- const borrowIncentivePools = await query.getBorrowIncentivePools(
3810
- void 0,
3811
- indexer
3812
- );
3813
- const borrowIncentiveAccounts = await query.getBorrowIncentiveAccounts(obligationId);
3814
- coinPrices = coinPrices || await query.utils.getCoinPrices(collateralAssetCoinNames);
3920
+ coinPrices = coinPrices ?? await query.utils.getCoinPrices(collateralAssetCoinNames);
3921
+ market = market ?? await query.queryMarket(indexer, { coinPrices });
3815
3922
  coinAmounts = coinAmounts || await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress);
3923
+ const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] = await Promise.all([
3924
+ query.queryObligation(obligationId),
3925
+ query.getBorrowIncentivePools(void 0, indexer, {
3926
+ coinPrices
3927
+ }),
3928
+ query.getBorrowIncentiveAccounts(obligationId)
3929
+ ]);
3816
3930
  const collaterals = {};
3817
3931
  const debts = {};
3818
3932
  const borrowIncentives = {};
@@ -4341,7 +4455,7 @@ var getLoyaltyProgramInformations = async (query, veScaKey) => {
4341
4455
  totalPoolReward,
4342
4456
  isClaimEnabled
4343
4457
  };
4344
- veScaKey = veScaKey || (await query.getVeScas())[0]?.keyObject;
4458
+ veScaKey = veScaKey ?? (await query.getVeScas())[0]?.keyObject;
4345
4459
  if (!veScaKey)
4346
4460
  return result;
4347
4461
  const userRewardTableId = query.address.get(
@@ -4363,16 +4477,39 @@ var getLoyaltyProgramInformations = async (query, veScaKey) => {
4363
4477
  return result;
4364
4478
  };
4365
4479
 
4366
- // src/constants/pyth.ts
4367
- var PYTH_ENDPOINTS = {
4368
- testnet: ["https://hermes-beta.pyth.network"],
4369
- mainnet: ["https://hermes.pyth.network", "https://scallop.rpc.p2p.world"]
4480
+ // src/models/suiKit.ts
4481
+ var import_sui_kit4 = require("@scallop-io/sui-kit");
4482
+
4483
+ // src/constants/rpc.ts
4484
+ var import_client = require("@mysten/sui/client");
4485
+ var RPC_PROVIDERS = [
4486
+ (0, import_client.getFullnodeUrl)("mainnet"),
4487
+ "https://sui-mainnet.public.blastapi.io",
4488
+ "https://sui-mainnet-ca-2.cosmostation.io",
4489
+ "https://sui-mainnet-eu-4.cosmostation.io",
4490
+ "https://sui-mainnet-endpoint.blockvision.org",
4491
+ "https://sui-rpc.publicnode.com",
4492
+ "https://sui-mainnet-rpc.allthatnode.com",
4493
+ "https://mainnet.suiet.app",
4494
+ "https://mainnet.sui.rpcpool.com",
4495
+ "https://sui1mainnet-rpc.chainode.tech",
4496
+ "https://fullnode.mainnet.apis.scallop.io",
4497
+ "https://sui-mainnet-us-2.cosmostation.io"
4498
+ ];
4499
+
4500
+ // src/models/suiKit.ts
4501
+ var newSuiKit = (params) => {
4502
+ return new import_sui_kit4.SuiKit({
4503
+ ...params,
4504
+ fullnodeUrls: Array.from(
4505
+ /* @__PURE__ */ new Set([...params.fullnodeUrls ?? [], ...RPC_PROVIDERS])
4506
+ )
4507
+ });
4370
4508
  };
4371
4509
 
4372
4510
  // src/models/scallopUtils.ts
4373
4511
  var ScallopUtils = class {
4374
4512
  constructor(params, instance) {
4375
- this._priceMap = /* @__PURE__ */ new Map();
4376
4513
  /**
4377
4514
  * Get reward type of spool.
4378
4515
  *
@@ -4395,7 +4532,7 @@ var ScallopUtils = class {
4395
4532
  pythEndpoints: params.pythEndpoints ?? PYTH_ENDPOINTS["mainnet"],
4396
4533
  ...params
4397
4534
  };
4398
- this.suiKit = instance?.suiKit ?? instance?.address?.cache._suiKit ?? new import_sui_kit4.SuiKit(params);
4535
+ this.suiKit = instance?.suiKit ?? instance?.address?.cache._suiKit ?? newSuiKit(params);
4399
4536
  this.walletAddress = params.walletAddress ?? this.suiKit.currentAddress();
4400
4537
  if (instance?.address) {
4401
4538
  this.address = instance.address;
@@ -4409,7 +4546,7 @@ var ScallopUtils = class {
4409
4546
  );
4410
4547
  this.address = instance?.address ?? new ScallopAddress(
4411
4548
  {
4412
- id: params?.addressesId || ADDRESSES_ID,
4549
+ id: params?.addressesId ?? ADDRESSES_ID,
4413
4550
  network: params?.networkType,
4414
4551
  forceInterface: params?.forceAddressesInterface
4415
4552
  },
@@ -4523,6 +4660,14 @@ var ScallopUtils = class {
4523
4660
  parseSCoinType(sCoinName) {
4524
4661
  return sCoinIds[sCoinName];
4525
4662
  }
4663
+ /**
4664
+ * Convert sCoinType into sCoin name
4665
+ * @param sCoinType
4666
+ * @returns sCoin name
4667
+ */
4668
+ parseSCoinNameFromType(sCoinType) {
4669
+ return sCoinTypeToName[sCoinType];
4670
+ }
4526
4671
  /**
4527
4672
  * Convert sCoin name into its underlying coin type
4528
4673
  * @param sCoinName
@@ -4548,7 +4693,7 @@ var ScallopUtils = class {
4548
4693
  * @return Market coin type.
4549
4694
  */
4550
4695
  parseMarketCoinType(coinName) {
4551
- const protocolObjectId = this.address.get("core.object") || PROTOCOL_OBJECT_ID;
4696
+ const protocolObjectId = this.address.get("core.object") ?? PROTOCOL_OBJECT_ID;
4552
4697
  const coinType = this.parseCoinType(coinName);
4553
4698
  return `${protocolObjectId}::reserve::MarketCoin<${coinType}>`;
4554
4699
  }
@@ -4557,7 +4702,7 @@ var ScallopUtils = class {
4557
4702
  const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
4558
4703
  const coinTypeMatch = coinType.match(coinTypeRegex);
4559
4704
  const isMarketCoinType = coinType.includes("reserve::MarketCoin");
4560
- coinType = coinTypeMatch?.[1] || coinType;
4705
+ coinType = coinTypeMatch?.[1] ?? coinType;
4561
4706
  const wormHoleCoinTypeMap = {
4562
4707
  [`${this.address.get("core.coins.wusdc.id") ?? wormholeCoinIds.wusdc}::coin::COIN`]: "wusdc",
4563
4708
  [`${this.address.get("core.coins.wusdt.id") ?? wormholeCoinIds.wusdt}::coin::COIN`]: "wusdt",
@@ -4635,7 +4780,7 @@ var ScallopUtils = class {
4635
4780
  * @return The selected transaction coin arguments.
4636
4781
  */
4637
4782
  async selectCoins(amount, coinType = import_utils10.SUI_TYPE_ARG, ownerAddress) {
4638
- ownerAddress = ownerAddress || this.suiKit.currentAddress();
4783
+ ownerAddress = ownerAddress ?? this.suiKit.currentAddress();
4639
4784
  const coins = await this.suiKit.suiInteractor.selectCoins(
4640
4785
  ownerAddress,
4641
4786
  amount,
@@ -4703,86 +4848,59 @@ var ScallopUtils = class {
4703
4848
  * @param assetCoinNames - Specific an array of support asset coin name.
4704
4849
  * @return Asset coin price.
4705
4850
  */
4706
- async getCoinPrices(assetCoinNames = [
4851
+ async getCoinPrices(_ = [
4707
4852
  .../* @__PURE__ */ new Set([...SUPPORT_POOLS, ...SUPPORT_COLLATERALS])
4708
4853
  ]) {
4709
- const coinPrices = {};
4710
- const existPricesCoinNames = [];
4711
- const lackPricesCoinNames = [];
4712
- assetCoinNames.forEach((assetCoinName) => {
4713
- if (this._priceMap.has(assetCoinName) && Date.now() - this._priceMap.get(assetCoinName).publishTime < 1e3 * 60) {
4714
- existPricesCoinNames.push(assetCoinName);
4715
- } else {
4716
- lackPricesCoinNames.push(assetCoinName);
4717
- this.cache.queryClient.invalidateQueries({
4718
- queryKey: queryKeys.oracle.getPythLatestPriceFeed(
4719
- this.address.get(`core.coins.${assetCoinName}.oracle.pyth.feed`)
4720
- )
4721
- });
4722
- }
4723
- });
4724
- if (existPricesCoinNames.length > 0) {
4725
- for (const coinName of existPricesCoinNames) {
4726
- coinPrices[coinName] = this._priceMap.get(coinName).price;
4727
- }
4728
- }
4729
- if (lackPricesCoinNames.length > 0) {
4730
- const endpoints = this.params.pythEndpoints ?? PYTH_ENDPOINTS[this.isTestnet ? "testnet" : "mainnet"];
4731
- const failedRequests = new Set(
4732
- lackPricesCoinNames
4854
+ let coinPrices = {};
4855
+ const endpoints = this.params.pythEndpoints ?? PYTH_ENDPOINTS[this.isTestnet ? "testnet" : "mainnet"];
4856
+ const failedRequests = /* @__PURE__ */ new Set([
4857
+ ...SUPPORT_POOLS,
4858
+ ...SUPPORT_COLLATERALS
4859
+ ]);
4860
+ for (const endpoint of endpoints) {
4861
+ const priceIdPairs = Array.from(failedRequests.values()).reduce(
4862
+ (acc, coinName) => {
4863
+ const priceId = this.address.get(
4864
+ `core.coins.${coinName}.oracle.pyth.feed`
4865
+ );
4866
+ acc.push([coinName, priceId]);
4867
+ return acc;
4868
+ },
4869
+ []
4733
4870
  );
4734
- for (const endpoint of endpoints) {
4735
- const priceIds = Array.from(failedRequests.values()).reduce(
4736
- (acc, coinName) => {
4737
- const priceId = this.address.get(
4738
- `core.coins.${coinName}.oracle.pyth.feed`
4739
- );
4740
- acc[coinName] = priceId;
4741
- return acc;
4871
+ const priceIds = priceIdPairs.map(([_2, priceId]) => priceId);
4872
+ const pythConnection = new import_pyth_sui_js.SuiPriceServiceConnection(endpoint, {
4873
+ timeout: 2e3
4874
+ });
4875
+ try {
4876
+ const feeds = await this.cache.queryClient.fetchQuery({
4877
+ queryKey: queryKeys.oracle.getPythLatestPriceFeeds(),
4878
+ queryFn: async () => {
4879
+ return await pythConnection.getLatestPriceFeeds(priceIds);
4742
4880
  },
4743
- {}
4744
- );
4745
- await Promise.allSettled(
4746
- Object.entries(priceIds).map(async ([coinName, priceId]) => {
4747
- const pythConnection = new import_pyth_sui_js.SuiPriceServiceConnection(endpoint);
4748
- try {
4749
- const feed = await this.cache.queryClient.fetchQuery({
4750
- queryKey: queryKeys.oracle.getPythLatestPriceFeed(priceId),
4751
- queryFn: async () => {
4752
- return await pythConnection.getLatestPriceFeeds([priceId]) ?? [];
4753
- }
4754
- });
4755
- if (feed[0]) {
4756
- const data = parseDataFromPythPriceFeed(feed[0], this.address);
4757
- this._priceMap.set(coinName, {
4758
- price: data.price,
4759
- publishTime: data.publishTime
4760
- });
4761
- coinPrices[coinName] = data.price;
4762
- }
4763
- failedRequests.delete(coinName);
4764
- } catch (e) {
4765
- console.warn(
4766
- `Failed to get price ${coinName} feeds with endpoint ${endpoint}: ${e}`
4767
- );
4768
- }
4769
- })
4770
- );
4771
- if (failedRequests.size === 0)
4772
- break;
4773
- }
4774
- if (failedRequests.size > 0) {
4775
- await Promise.allSettled(
4776
- Array.from(failedRequests.values()).map(async (coinName) => {
4777
- const price = await getPythPrice(this, coinName);
4778
- this._priceMap.set(coinName, {
4779
- price,
4780
- publishTime: Date.now()
4781
- });
4782
- coinPrices[coinName] = price;
4783
- })
4784
- );
4881
+ staleTime: 3e4,
4882
+ gcTime: 3e4
4883
+ });
4884
+ if (feeds) {
4885
+ feeds.forEach((feed, idx) => {
4886
+ const coinName = priceIdPairs[idx][0];
4887
+ const data = parseDataFromPythPriceFeed(feed, this.address);
4888
+ coinPrices[coinName] = data.price;
4889
+ failedRequests.delete(coinName);
4890
+ });
4891
+ }
4892
+ } catch (e) {
4893
+ console.error(e.message);
4785
4894
  }
4895
+ if (failedRequests.size === 0)
4896
+ break;
4897
+ }
4898
+ if (failedRequests.size > 0) {
4899
+ coinPrices = {
4900
+ ...coinPrices,
4901
+ ...await getPythPrices(this, Array.from(failedRequests.values()))
4902
+ };
4903
+ failedRequests.clear();
4786
4904
  }
4787
4905
  return coinPrices;
4788
4906
  }
@@ -4838,11 +4956,30 @@ var ScallopUtils = class {
4838
4956
  }
4839
4957
  return findClosestUnlockRound(newUnlockAtInSecondTimestamp);
4840
4958
  }
4959
+ /**
4960
+ * Get detailed contract address and price id information for supported pool in Scallop
4961
+ * @returns Supported pool informations
4962
+ */
4963
+ getSupportedPoolAddresses() {
4964
+ return SUPPORT_POOLS.map((poolName) => {
4965
+ const sCoinName = this.parseSCoinName(poolName);
4966
+ return {
4967
+ name: this.parseSymbol(poolName),
4968
+ coingeckoId: COIN_GECKGO_IDS[poolName],
4969
+ decimal: coinDecimals[poolName],
4970
+ pythFeedId: PYTH_FEED_IDS[poolName],
4971
+ ...POOL_ADDRESSES[poolName],
4972
+ sCoinAddress: sCoinIds[sCoinName],
4973
+ marketCoinAddress: this.parseMarketCoinType(poolName),
4974
+ coinAddress: this.parseCoinType(poolName),
4975
+ sCoinName: sCoinName ? this.parseSymbol(sCoinName) : void 0
4976
+ };
4977
+ });
4978
+ }
4841
4979
  };
4842
4980
 
4843
4981
  // src/models/scallopBuilder.ts
4844
4982
  var import_utils24 = require("@mysten/sui/utils");
4845
- var import_sui_kit14 = require("@scallop-io/sui-kit");
4846
4983
 
4847
4984
  // src/builders/coreBuilder.ts
4848
4985
  var import_transactions = require("@mysten/sui/transactions");
@@ -6276,7 +6413,7 @@ var generateLoyaltyProgramQuickMethod = ({
6276
6413
  }) => {
6277
6414
  return {
6278
6415
  claimLoyaltyRevenueQuick: async (veScaKey) => {
6279
- veScaKey = veScaKey || (await builder.query.getVeScas())[0]?.keyObject;
6416
+ veScaKey = veScaKey ?? (await builder.query.getVeScas())[0]?.keyObject;
6280
6417
  const sender = requireSender(txBlock);
6281
6418
  if (!veScaKey)
6282
6419
  throw new Error(`No veScaKey found for user ${sender}`);
@@ -6440,9 +6577,6 @@ var newScallopTxBlock = (builder, initTxBlock) => {
6440
6577
  });
6441
6578
  };
6442
6579
 
6443
- // src/models/scallopQuery.ts
6444
- var import_sui_kit13 = require("@scallop-io/sui-kit");
6445
-
6446
6580
  // src/models/scallopIndexer.ts
6447
6581
  var import_axios2 = __toESM(require("axios"));
6448
6582
  var import_sui_kit12 = require("@scallop-io/sui-kit");
@@ -6800,9 +6934,9 @@ var isIsolatedAsset = async (utils, coinName) => {
6800
6934
  var ScallopQuery = class {
6801
6935
  constructor(params, instance) {
6802
6936
  this.params = params;
6803
- this.suiKit = instance?.suiKit ?? instance?.utils?.suiKit ?? new import_sui_kit13.SuiKit(params);
6937
+ this.suiKit = instance?.suiKit ?? instance?.utils?.suiKit ?? newSuiKit(params);
6804
6938
  this.walletAddress = (0, import_utils23.normalizeSuiAddress)(
6805
- params.walletAddress || this.suiKit.currentAddress()
6939
+ params.walletAddress ?? this.suiKit.currentAddress()
6806
6940
  );
6807
6941
  if (instance?.utils) {
6808
6942
  this.utils = instance.utils;
@@ -6816,7 +6950,7 @@ var ScallopQuery = class {
6816
6950
  );
6817
6951
  this.address = new ScallopAddress(
6818
6952
  {
6819
- id: params?.addressesId || ADDRESSES_ID,
6953
+ id: params?.addressesId ?? ADDRESSES_ID,
6820
6954
  network: params?.networkType,
6821
6955
  forceInterface: params?.forceAddressesInterface
6822
6956
  },
@@ -6879,8 +7013,8 @@ var ScallopQuery = class {
6879
7013
  * @param indexer - Whether to use indexer.
6880
7014
  * @return Market data.
6881
7015
  */
6882
- async queryMarket(indexer = false) {
6883
- return await queryMarket(this, indexer);
7016
+ async queryMarket(indexer = false, args) {
7017
+ return await queryMarket(this, indexer, args?.coinPrices);
6884
7018
  }
6885
7019
  /**
6886
7020
  * Get market pools.
@@ -6893,8 +7027,8 @@ var ScallopQuery = class {
6893
7027
  * @param indexer - Whether to use indexer.
6894
7028
  * @return Market pools data.
6895
7029
  */
6896
- async getMarketPools(poolCoinNames, indexer = false) {
6897
- return await getMarketPools(this, poolCoinNames, indexer);
7030
+ async getMarketPools(poolCoinNames, indexer = false, args) {
7031
+ return await getMarketPools(this, poolCoinNames, indexer, args?.coinPrices);
6898
7032
  }
6899
7033
  /**
6900
7034
  * Get market pool
@@ -6903,8 +7037,14 @@ var ScallopQuery = class {
6903
7037
  * @param indexer - Whether to use indexer.
6904
7038
  * @return Market pool data.
6905
7039
  */
6906
- async getMarketPool(poolCoinName, indexer = false) {
6907
- return await getMarketPool(this, poolCoinName, indexer);
7040
+ async getMarketPool(poolCoinName, indexer = false, args) {
7041
+ return await getMarketPool(
7042
+ this,
7043
+ poolCoinName,
7044
+ indexer,
7045
+ args?.marketObject,
7046
+ args?.coinPrice
7047
+ );
6908
7048
  }
6909
7049
  /**
6910
7050
  * Get market collaterals.
@@ -7014,8 +7154,14 @@ var ScallopQuery = class {
7014
7154
  * @param indexer - Whether to use indexer.
7015
7155
  * @return Spools data.
7016
7156
  */
7017
- async getSpools(stakeMarketCoinNames, indexer = false) {
7018
- return await getSpools(this, stakeMarketCoinNames, indexer);
7157
+ async getSpools(stakeMarketCoinNames, indexer = false, args) {
7158
+ return await getSpools(
7159
+ this,
7160
+ stakeMarketCoinNames,
7161
+ indexer,
7162
+ args?.marketPools,
7163
+ args?.coinPrices
7164
+ );
7019
7165
  }
7020
7166
  /**
7021
7167
  * Get spool data.
@@ -7024,8 +7170,14 @@ var ScallopQuery = class {
7024
7170
  * @param indexer - Whether to use indexer.
7025
7171
  * @return Spool data.
7026
7172
  */
7027
- async getSpool(stakeMarketCoinName, indexer = false) {
7028
- return await getSpool(this, stakeMarketCoinName, indexer);
7173
+ async getSpool(stakeMarketCoinName, indexer = false, args) {
7174
+ return await getSpool(
7175
+ this,
7176
+ stakeMarketCoinName,
7177
+ indexer,
7178
+ args?.marketPool,
7179
+ args?.coinPrices
7180
+ );
7029
7181
  }
7030
7182
  /**
7031
7183
  * Get stake accounts data for all stake pools (spools).
@@ -7125,8 +7277,13 @@ var ScallopQuery = class {
7125
7277
  * @param indexer - Whether to use indexer.
7126
7278
  * @return Borrow incentive pools data.
7127
7279
  */
7128
- async getBorrowIncentivePools(coinNames, indexer = false) {
7129
- return await getBorrowIncentivePools(this, coinNames, indexer);
7280
+ async getBorrowIncentivePools(coinNames, indexer = false, args) {
7281
+ return await getBorrowIncentivePools(
7282
+ this,
7283
+ coinNames,
7284
+ indexer,
7285
+ args?.coinPrices
7286
+ );
7130
7287
  }
7131
7288
  /**
7132
7289
  * Get borrow incentive accounts data.
@@ -7339,10 +7496,10 @@ var ScallopQuery = class {
7339
7496
  // src/models/scallopBuilder.ts
7340
7497
  var ScallopBuilder = class {
7341
7498
  constructor(params, instance) {
7342
- this.suiKit = instance?.suiKit ?? new import_sui_kit14.SuiKit(params);
7499
+ this.suiKit = instance?.suiKit ?? newSuiKit(params);
7343
7500
  this.params = params;
7344
7501
  this.walletAddress = (0, import_utils24.normalizeSuiAddress)(
7345
- params?.walletAddress || this.suiKit.currentAddress()
7502
+ params?.walletAddress ?? this.suiKit.currentAddress()
7346
7503
  );
7347
7504
  if (instance?.query) {
7348
7505
  this.query = instance.query;
@@ -7357,7 +7514,7 @@ var ScallopBuilder = class {
7357
7514
  );
7358
7515
  this.address = new ScallopAddress(
7359
7516
  {
7360
- id: params?.addressesId || ADDRESSES_ID,
7517
+ id: params?.addressesId ?? ADDRESSES_ID,
7361
7518
  network: params?.networkType,
7362
7519
  forceInterface: params?.forceAddressesInterface
7363
7520
  },
@@ -7487,9 +7644,9 @@ var ScallopBuilder = class {
7487
7644
  var ScallopClient = class {
7488
7645
  constructor(params, instance) {
7489
7646
  this.params = params;
7490
- this.suiKit = instance?.suiKit ?? instance?.builder?.suiKit ?? new import_sui_kit15.SuiKit(params);
7647
+ this.suiKit = instance?.suiKit ?? instance?.builder?.suiKit ?? newSuiKit(params);
7491
7648
  this.walletAddress = (0, import_utils25.normalizeSuiAddress)(
7492
- params?.walletAddress || this.suiKit.currentAddress()
7649
+ params?.walletAddress ?? this.suiKit.currentAddress()
7493
7650
  );
7494
7651
  if (instance?.builder) {
7495
7652
  this.builder = instance.builder;
@@ -7505,7 +7662,7 @@ var ScallopClient = class {
7505
7662
  );
7506
7663
  this.address = new ScallopAddress(
7507
7664
  {
7508
- id: params?.addressesId || ADDRESSES_ID,
7665
+ id: params?.addressesId ?? ADDRESSES_ID,
7509
7666
  network: params?.networkType,
7510
7667
  forceInterface: params?.forceAddressesInterface
7511
7668
  },
@@ -7559,7 +7716,7 @@ var ScallopClient = class {
7559
7716
  * @return Obligations data.
7560
7717
  */
7561
7718
  async getObligations(ownerAddress) {
7562
- const owner = ownerAddress || this.walletAddress;
7719
+ const owner = ownerAddress ?? this.walletAddress;
7563
7720
  return await this.query.getObligations(owner);
7564
7721
  }
7565
7722
  /**
@@ -7584,7 +7741,7 @@ var ScallopClient = class {
7584
7741
  * @return All stake accounts data.
7585
7742
  */
7586
7743
  async getAllStakeAccounts(ownerAddress) {
7587
- const owner = ownerAddress || this.walletAddress;
7744
+ const owner = ownerAddress ?? this.walletAddress;
7588
7745
  return await this.query.getAllStakeAccounts(owner);
7589
7746
  }
7590
7747
  /**
@@ -7598,7 +7755,7 @@ var ScallopClient = class {
7598
7755
  * @return Stake accounts data.
7599
7756
  */
7600
7757
  async getStakeAccounts(stakeMarketCoinName, ownerAddress) {
7601
- const owner = ownerAddress || this.walletAddress;
7758
+ const owner = ownerAddress ?? this.walletAddress;
7602
7759
  return await this.query.getStakeAccounts(stakeMarketCoinName, owner);
7603
7760
  }
7604
7761
  /**
@@ -7638,10 +7795,10 @@ var ScallopClient = class {
7638
7795
  }
7639
7796
  async depositCollateral(collateralCoinName, amount, sign = true, obligationId, walletAddress) {
7640
7797
  const txBlock = this.builder.createTxBlock();
7641
- const sender = walletAddress || this.walletAddress;
7798
+ const sender = walletAddress ?? this.walletAddress;
7642
7799
  txBlock.setSender(sender);
7643
7800
  const obligations = await this.query.getObligations(sender);
7644
- const specificObligationId = obligationId || obligations[0]?.id;
7801
+ const specificObligationId = obligationId ?? obligations[0]?.id;
7645
7802
  if (specificObligationId) {
7646
7803
  await txBlock.addCollateralQuick(
7647
7804
  amount,
@@ -7675,7 +7832,7 @@ var ScallopClient = class {
7675
7832
  */
7676
7833
  async withdrawCollateral(collateralCoinName, amount, sign = true, obligationId, obligationKey, walletAddress) {
7677
7834
  const txBlock = this.builder.createTxBlock();
7678
- const sender = walletAddress || this.walletAddress;
7835
+ const sender = walletAddress ?? this.walletAddress;
7679
7836
  txBlock.setSender(sender);
7680
7837
  const collateralCoin = await txBlock.takeCollateralQuick(
7681
7838
  amount,
@@ -7694,7 +7851,7 @@ var ScallopClient = class {
7694
7851
  }
7695
7852
  async deposit(poolCoinName, amount, sign = true, walletAddress) {
7696
7853
  const txBlock = this.builder.createTxBlock();
7697
- const sender = walletAddress || this.walletAddress;
7854
+ const sender = walletAddress ?? this.walletAddress;
7698
7855
  txBlock.setSender(sender);
7699
7856
  const sCoin = await txBlock.depositQuick(amount, poolCoinName);
7700
7857
  txBlock.transferObjects([sCoin], sender);
@@ -7708,11 +7865,11 @@ var ScallopClient = class {
7708
7865
  }
7709
7866
  async depositAndStake(stakeCoinName, amount, sign = true, stakeAccountId, walletAddress) {
7710
7867
  const txBlock = this.builder.createTxBlock();
7711
- const sender = walletAddress || this.walletAddress;
7868
+ const sender = walletAddress ?? this.walletAddress;
7712
7869
  txBlock.setSender(sender);
7713
7870
  const stakeMarketCoinName = this.utils.parseMarketCoinName(stakeCoinName);
7714
7871
  const stakeAccounts = await this.query.getStakeAccounts(stakeMarketCoinName);
7715
- const targetStakeAccount = stakeAccountId || stakeAccounts[0]?.id;
7872
+ const targetStakeAccount = stakeAccountId ?? stakeAccounts[0]?.id;
7716
7873
  const marketCoin = await txBlock.depositQuick(amount, stakeCoinName, false);
7717
7874
  if (targetStakeAccount) {
7718
7875
  await txBlock.stakeQuick(
@@ -7735,7 +7892,7 @@ var ScallopClient = class {
7735
7892
  }
7736
7893
  async withdraw(poolCoinName, amount, sign = true, walletAddress) {
7737
7894
  const txBlock = this.builder.createTxBlock();
7738
- const sender = walletAddress || this.walletAddress;
7895
+ const sender = walletAddress ?? this.walletAddress;
7739
7896
  txBlock.setSender(sender);
7740
7897
  const coin = await txBlock.withdrawQuick(amount, poolCoinName);
7741
7898
  txBlock.transferObjects([coin], sender);
@@ -7760,7 +7917,7 @@ var ScallopClient = class {
7760
7917
  */
7761
7918
  async borrow(poolCoinName, amount, sign = true, obligationId, obligationKey, walletAddress) {
7762
7919
  const txBlock = this.builder.createTxBlock();
7763
- const sender = walletAddress || this.walletAddress;
7920
+ const sender = walletAddress ?? this.walletAddress;
7764
7921
  txBlock.setSender(sender);
7765
7922
  const availableStake = SUPPORT_BORROW_INCENTIVE_POOLS.includes(poolCoinName);
7766
7923
  if (sign && availableStake) {
@@ -7796,7 +7953,7 @@ var ScallopClient = class {
7796
7953
  */
7797
7954
  async repay(poolCoinName, amount, sign = true, obligationId, obligationKey, walletAddress) {
7798
7955
  const txBlock = this.builder.createTxBlock();
7799
- const sender = walletAddress || this.walletAddress;
7956
+ const sender = walletAddress ?? this.walletAddress;
7800
7957
  txBlock.setSender(sender);
7801
7958
  const availableStake = SUPPORT_BORROW_INCENTIVE_POOLS.includes(poolCoinName);
7802
7959
  if (sign && availableStake) {
@@ -7816,7 +7973,7 @@ var ScallopClient = class {
7816
7973
  }
7817
7974
  async flashLoan(poolCoinName, amount, callback, sign = true, walletAddress) {
7818
7975
  const txBlock = this.builder.createTxBlock();
7819
- const sender = walletAddress || this.walletAddress;
7976
+ const sender = walletAddress ?? this.walletAddress;
7820
7977
  txBlock.setSender(sender);
7821
7978
  const [coin, loan] = txBlock.borrowFlashLoan(amount, poolCoinName);
7822
7979
  txBlock.repayFlashLoan(await callback(txBlock, coin), loan, poolCoinName);
@@ -7830,7 +7987,7 @@ var ScallopClient = class {
7830
7987
  }
7831
7988
  async createStakeAccount(marketCoinName, sign = true, walletAddress) {
7832
7989
  const txBlock = this.builder.createTxBlock();
7833
- const sender = walletAddress || this.walletAddress;
7990
+ const sender = walletAddress ?? this.walletAddress;
7834
7991
  txBlock.setSender(sender);
7835
7992
  const stakeAccount = txBlock.createStakeAccount(marketCoinName);
7836
7993
  txBlock.transferObjects([stakeAccount], sender);
@@ -7844,10 +8001,10 @@ var ScallopClient = class {
7844
8001
  }
7845
8002
  async stake(stakeMarketCoinName, amount, sign = true, stakeAccountId, walletAddress) {
7846
8003
  const txBlock = this.builder.createTxBlock();
7847
- const sender = walletAddress || this.walletAddress;
8004
+ const sender = walletAddress ?? this.walletAddress;
7848
8005
  txBlock.setSender(sender);
7849
8006
  const stakeAccounts = await this.query.getStakeAccounts(stakeMarketCoinName);
7850
- const targetStakeAccount = stakeAccountId || stakeAccounts[0]?.id;
8007
+ const targetStakeAccount = stakeAccountId ?? stakeAccounts[0]?.id;
7851
8008
  if (targetStakeAccount) {
7852
8009
  await txBlock.stakeQuick(amount, stakeMarketCoinName, targetStakeAccount);
7853
8010
  } else {
@@ -7865,7 +8022,7 @@ var ScallopClient = class {
7865
8022
  }
7866
8023
  async unstake(stakeMarketCoinName, amount, sign = true, stakeAccountId, walletAddress) {
7867
8024
  const txBlock = this.builder.createTxBlock();
7868
- const sender = walletAddress || this.walletAddress;
8025
+ const sender = walletAddress ?? this.walletAddress;
7869
8026
  txBlock.setSender(sender);
7870
8027
  const sCoin = await txBlock.unstakeQuick(
7871
8028
  amount,
@@ -7891,7 +8048,7 @@ var ScallopClient = class {
7891
8048
  }
7892
8049
  async unstakeAndWithdraw(stakeMarketCoinName, amount, sign = true, stakeAccountId, walletAddress) {
7893
8050
  const txBlock = this.builder.createTxBlock();
7894
- const sender = walletAddress || this.walletAddress;
8051
+ const sender = walletAddress ?? this.walletAddress;
7895
8052
  txBlock.setSender(sender);
7896
8053
  const stakeMarketCoin = await txBlock.unstakeQuick(
7897
8054
  amount,
@@ -7922,7 +8079,7 @@ var ScallopClient = class {
7922
8079
  }
7923
8080
  async claim(stakeMarketCoinName, sign = true, stakeAccountId, walletAddress) {
7924
8081
  const txBlock = this.builder.createTxBlock();
7925
- const sender = walletAddress || this.walletAddress;
8082
+ const sender = walletAddress ?? this.walletAddress;
7926
8083
  txBlock.setSender(sender);
7927
8084
  const rewardCoins = await txBlock.claimQuick(
7928
8085
  stakeMarketCoinName,
@@ -7949,7 +8106,7 @@ var ScallopClient = class {
7949
8106
  */
7950
8107
  async stakeObligation(obligationId, obligationKeyId, sign = true, walletAddress) {
7951
8108
  const txBlock = this.builder.createTxBlock();
7952
- const sender = walletAddress || this.walletAddress;
8109
+ const sender = walletAddress ?? this.walletAddress;
7953
8110
  txBlock.setSender(sender);
7954
8111
  await txBlock.stakeObligationWithVeScaQuick(obligationId, obligationKeyId);
7955
8112
  if (sign) {
@@ -7971,7 +8128,7 @@ var ScallopClient = class {
7971
8128
  */
7972
8129
  async unstakeObligation(obligationId, obligationKeyId, sign = true, walletAddress) {
7973
8130
  const txBlock = this.builder.createTxBlock();
7974
- const sender = walletAddress || this.walletAddress;
8131
+ const sender = walletAddress ?? this.walletAddress;
7975
8132
  txBlock.setSender(sender);
7976
8133
  await txBlock.unstakeObligationQuick(obligationId, obligationKeyId);
7977
8134
  if (sign) {
@@ -7994,7 +8151,7 @@ var ScallopClient = class {
7994
8151
  */
7995
8152
  async claimBorrowIncentive(coinName, obligationId, obligationKeyId, sign = true, walletAddress) {
7996
8153
  const txBlock = this.builder.createTxBlock();
7997
- const sender = walletAddress || this.walletAddress;
8154
+ const sender = walletAddress ?? this.walletAddress;
7998
8155
  txBlock.setSender(sender);
7999
8156
  const rewardCoins = [];
8000
8157
  for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
@@ -8140,7 +8297,7 @@ var ScallopClient = class {
8140
8297
  throw new Error("Only be used on the test network.");
8141
8298
  }
8142
8299
  const txBlock = this.builder.createTxBlock();
8143
- const recipient = receiveAddress || this.walletAddress;
8300
+ const recipient = receiveAddress ?? this.walletAddress;
8144
8301
  const packageId = this.address.get("core.packages.testCoin.id");
8145
8302
  const treasuryId = this.address.get(`core.coins.${assetCoinName}.treasury`);
8146
8303
  const target = `${packageId}::${assetCoinName}::mint`;
@@ -8160,7 +8317,7 @@ var ScallopClient = class {
8160
8317
  var Scallop = class {
8161
8318
  constructor(params, cacheOptions, tokenBucket, queryClient) {
8162
8319
  this.params = params;
8163
- this.suiKit = new import_sui_kit16.SuiKit(params);
8320
+ this.suiKit = newSuiKit(params);
8164
8321
  this.cache = new ScallopCache(
8165
8322
  this.suiKit,
8166
8323
  params.walletAddress,
@@ -8170,7 +8327,7 @@ var Scallop = class {
8170
8327
  );
8171
8328
  this.address = new ScallopAddress(
8172
8329
  {
8173
- id: params?.addressesId || ADDRESSES_ID,
8330
+ id: params?.addressesId ?? ADDRESSES_ID,
8174
8331
  network: params?.networkType,
8175
8332
  forceInterface: params?.forceAddressesInterface
8176
8333
  },
@@ -8275,6 +8432,10 @@ var Scallop = class {
8275
8432
  ADDRESSES_ID,
8276
8433
  API_BASE_URL,
8277
8434
  BORROW_FEE_PROTOCOL_ID,
8435
+ COIN_GECKGO_IDS,
8436
+ DEFAULT_CACHE_OPTIONS,
8437
+ DEFAULT_INTERVAL_IN_MS,
8438
+ DEFAULT_TOKENS_PER_INTERVAL,
8278
8439
  FlashLoanFeeObjectMap,
8279
8440
  IS_VE_SCA_TEST,
8280
8441
  MAX_LOCK_DURATION,
@@ -8282,7 +8443,10 @@ var Scallop = class {
8282
8443
  MIN_INITIAL_LOCK_AMOUNT,
8283
8444
  MIN_TOP_UP_AMOUNT,
8284
8445
  OLD_BORROW_INCENTIVE_PROTOCOL_ID,
8446
+ POOL_ADDRESSES,
8285
8447
  PROTOCOL_OBJECT_ID,
8448
+ PYTH_ENDPOINTS,
8449
+ PYTH_FEED_IDS,
8286
8450
  SCA_COIN_TYPE,
8287
8451
  SDK_API_BASE_URL,
8288
8452
  SUPPORT_BORROW_INCENTIVE_POOLS,
@@ -8304,6 +8468,7 @@ var Scallop = class {
8304
8468
  ScallopIndexer,
8305
8469
  ScallopQuery,
8306
8470
  ScallopUtils,
8471
+ TEST_ADDRESSES,
8307
8472
  UNLOCK_ROUND_DURATION,
8308
8473
  USE_TEST_ADDRESS,
8309
8474
  assetCoins,
@@ -8313,6 +8478,7 @@ var Scallop = class {
8313
8478
  marketCoins,
8314
8479
  queryKeys,
8315
8480
  sCoinIds,
8481
+ sCoinTypeToName,
8316
8482
  sCoins,
8317
8483
  spoolRewardCoins,
8318
8484
  stakeMarketCoins,