@scallop-io/sui-scallop-sdk 1.3.4-alpha.1 → 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 (102) hide show
  1. package/dist/index.js +550 -544
  2. package/dist/index.js.map +1 -1
  3. package/dist/index.mjs +549 -544
  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/common.ts +0 -1
  8. package/src/constants/enum.ts +12 -11
  9. package/src/constants/index.ts +0 -1
  10. package/src/constants/queryKeys.ts +1 -5
  11. package/src/constants/rpc.ts +16 -0
  12. package/src/constants/testAddress.ts +35 -76
  13. package/src/constants/tokenBucket.ts +1 -1
  14. package/src/models/scallop.ts +3 -2
  15. package/src/models/scallopAddress.ts +2 -2
  16. package/src/models/scallopBuilder.ts +7 -5
  17. package/src/models/scallopCache.ts +1 -1
  18. package/src/models/scallopClient.ts +27 -26
  19. package/src/models/scallopQuery.ts +61 -19
  20. package/src/models/scallopUtils.ts +74 -109
  21. package/src/models/suiKit.ts +11 -0
  22. package/src/queries/borrowIncentiveQuery.ts +6 -13
  23. package/src/queries/coreQuery.ts +245 -236
  24. package/src/queries/isolatedAsset.ts +4 -4
  25. package/src/queries/loyaltyProgramQuery.ts +1 -1
  26. package/src/queries/portfolioQuery.ts +58 -34
  27. package/src/queries/referralQuery.ts +1 -0
  28. package/src/queries/spoolQuery.ts +17 -17
  29. package/src/types/query/core.ts +0 -1
  30. package/src/utils/tokenBucket.ts +2 -1
  31. package/dist/builders/borrowIncentiveBuilder.d.ts +0 -12
  32. package/dist/builders/coreBuilder.d.ts +0 -12
  33. package/dist/builders/index.d.ts +0 -12
  34. package/dist/builders/loyaltyProgramBuilder.d.ts +0 -12
  35. package/dist/builders/oracle.d.ts +0 -14
  36. package/dist/builders/referralBuilder.d.ts +0 -12
  37. package/dist/builders/sCoinBuilder.d.ts +0 -4
  38. package/dist/builders/spoolBuilder.d.ts +0 -12
  39. package/dist/builders/vescaBuilder.d.ts +0 -25
  40. package/dist/constants/cache.d.ts +0 -14
  41. package/dist/constants/coinGecko.d.ts +0 -2
  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 -12
  46. package/dist/constants/poolAddress.d.ts +0 -5
  47. package/dist/constants/pyth.d.ts +0 -5
  48. package/dist/constants/queryKeys.d.ts +0 -59
  49. package/dist/constants/testAddress.d.ts +0 -2
  50. package/dist/constants/tokenBucket.d.ts +0 -2
  51. package/dist/constants/vesca.d.ts +0 -5
  52. package/dist/index.d.ts +0 -3
  53. package/dist/models/index.d.ts +0 -8
  54. package/dist/models/scallop.d.ts +0 -74
  55. package/dist/models/scallopAddress.d.ts +0 -150
  56. package/dist/models/scallopBuilder.d.ts +0 -89
  57. package/dist/models/scallopCache.d.ts +0 -74
  58. package/dist/models/scallopClient.d.ts +0 -321
  59. package/dist/models/scallopIndexer.d.ts +0 -89
  60. package/dist/models/scallopQuery.d.ts +0 -474
  61. package/dist/models/scallopUtils.d.ts +0 -222
  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 -362
  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 -21
  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
package/dist/index.mjs CHANGED
@@ -282,20 +282,11 @@ var voloCoinIds = {
282
282
  var sCoinIds = {
283
283
  susdc: "0x854950aa624b1df59fe64e630b2ba7c550642e9342267a33061d59fb31582da5::scallop_usdc::SCALLOP_USDC",
284
284
  ssbeth: "0xb14f82d8506d139eacef109688d1b71e7236bcce9b2c0ad526abcd6aa5be7de0::scallop_sb_eth::SCALLOP_SB_ETH",
285
- // TODO: Change this to the correct value on production release
286
- ssui: "0xf569919046f19a0c40b519ecfbb6ca0319698cd5908716c29b62ef56541f298b::scallop_sui::SCALLOP_SUI",
287
- // ssui: '0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI',
285
+ ssui: "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI",
288
286
  scetus: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
289
- // TODO: Change this to the correct value on production release
290
- ssca: "0x958428555e778e55918a59eb1c92c77f32b5c554fa3a5e56cd0815086b5072e7::scallop_sca::SCALLOP_SCA",
291
- // '0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA',
292
- // TODO: Change this to the correct value on production release
293
- swusdc: "0xf5447c4305a486d8c8557559887c2c39449ddb5e748f15d33946d02a1663c158::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
294
- // '0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC',
295
- swusdt: (
296
- // '0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT',
297
- "0xac781d9f73058ff5e69f9bf8dde32f2e8c71c66d7fe8497fc83b2d9182254b22::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT"
298
- ),
287
+ ssca: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
288
+ swusdc: "0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
289
+ swusdt: "0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
299
290
  sweth: "0x67540ceb850d418679e69f1fb6b2093d6df78a2a699ffc733f7646096d552e9b::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
300
291
  safsui: "0x00671b1fa2a124f5be8bdae8b91ee711462c5d9e31bda232e70fd9607b523c88::scallop_af_sui::SCALLOP_AF_SUI",
301
292
  shasui: "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI",
@@ -303,6 +294,13 @@ var sCoinIds = {
303
294
  swsol: "0x1392650f2eca9e3f6ffae3ff89e42a3590d7102b80e2b430f674730bc30d3259::scallop_wormhole_sol::SCALLOP_WORMHOLE_SOL",
304
295
  swbtc: "0x2cf76a9cf5d3337961d1154283234f94da2dcff18544dfe5cbdef65f319591b5::scallop_wormhole_btc::SCALLOP_WORMHOLE_BTC"
305
296
  };
297
+ var sCoinTypeToName = Object.entries(sCoinIds).reduce(
298
+ (acc, [coinName, coinType]) => {
299
+ acc[coinType] = coinName;
300
+ return acc;
301
+ },
302
+ {}
303
+ );
306
304
 
307
305
  // src/constants/flashloan.ts
308
306
  var FlashLoanFeeObjectMap = {
@@ -478,11 +476,7 @@ var queryKeys = {
478
476
  ]
479
477
  },
480
478
  oracle: {
481
- getPythLatestPriceFeed: (pythPriceId, endpoint) => [
482
- "oracle",
483
- "getPythPriceId",
484
- { pythPriceId, endpoint }
485
- ]
479
+ getPythLatestPriceFeeds: () => ["oracle", "getPythPriceIds"]
486
480
  }
487
481
  };
488
482
 
@@ -491,33 +485,20 @@ var TEST_ADDRESSES = {
491
485
  core: {
492
486
  // version:
493
487
  // '0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7',
494
- version: "0xd318de9b0f6873879a82cbfcc2daa1d1591a8b54e7cea9f4b567da63c692a52b",
488
+ version: "0x6156d5cd1538bec8a167a40fe1209a4ec9cf8137921fe0a697f191ac561f0b09",
495
489
  versionCap: "0x590a4011cb649b3878f3ea14b3a78674642a9548d79b7e091ef679574b158a07",
496
490
  // object:
497
491
  // '0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf',
498
- object: "0x6c23585e940a989588432509107e98bae06dbca4e333f26d0635d401b3c7c76d",
492
+ object: "0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1",
499
493
  // market:
500
494
  // '0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9',
501
- market: "0x9d6434e97f3f98fd9b0c0e1dca22632073985abcd22541feae7ee1e34cbe3af2",
495
+ market: "0x8606ed145cc887985b8ed793f7753ff5dc762a42c379dac035f568e1bac58490",
502
496
  adminCap: "0x09689d018e71c337d9db6d67cbca06b74ed92196103624028ccc3ecea411777c",
503
497
  coinDecimalsRegistry: "0x200abe9bf19751cc566ae35aa58e2b7e4ff688fc1130f8d8909ea09bc137d668",
504
498
  // obligationAccessStore:
505
499
  // '0x733e30b7c94d619d78cb8f5bc4bfbb759ced9a531239028caabb2474e5be59c9',
506
- obligationAccessStore: "0x46e9b44a77ee9c9d33cc2689ecdfbb8f681935cbc6bdf6ac3df048e396c36c82",
500
+ obligationAccessStore: "0x48b472d68ca910c45f7f3b6c26836b6aa6d2569810d94b1b939023da05ae0a23",
507
501
  coins: {
508
- usdc: {
509
- id: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7",
510
- metaData: "0x69b7a7c3c200439c1b5f3b19d7d495d5966d5f08de66c69276152f8db3992ec6",
511
- treasury: "",
512
- oracle: {
513
- supra: "",
514
- switchboard: "",
515
- pyth: {
516
- feed: "eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
517
- feedObject: "0x5dec622733a204ca27f5a90d8c2fad453cc6665186fd5dff13a83d0b6c9027ab"
518
- }
519
- }
520
- },
521
502
  cetus: {
522
503
  id: "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b",
523
504
  metaData: "0x4c0dce55eff2db5419bbd2d239d1aa22b4a400c01bbb648b058a9883989025da",
@@ -673,19 +654,6 @@ var TEST_ADDRESSES = {
673
654
  feedObject: "0xf6de1d3279a269a597d813cbaca59aa906543ab9a8c64e84a4722f1a20863985"
674
655
  }
675
656
  }
676
- },
677
- sbeth: {
678
- id: "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29",
679
- metaData: "0x89b04ba87f8832d4d76e17a1c9dce72eb3e64d372cf02012b8d2de5384faeef0",
680
- treasury: "",
681
- oracle: {
682
- supra: "",
683
- switchboard: "",
684
- pyth: {
685
- feed: "ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",
686
- feedObject: "0x9193fd47f9a0ab99b6e365a464c8a9ae30e6150fc37ed2a89c1586631f6fc4ab"
687
- }
688
- }
689
657
  }
690
658
  },
691
659
  oracles: {
@@ -719,7 +687,7 @@ var TEST_ADDRESSES = {
719
687
  upgradeCap: "0x3f203f6fff6a69d151e4f1cd931f22b68c489ef2759765662fc7baf673943c9e"
720
688
  },
721
689
  protocol: {
722
- id: "0x6c23585e940a989588432509107e98bae06dbca4e333f26d0635d401b3c7c76d",
690
+ id: "0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1",
723
691
  upgradeCap: "0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a"
724
692
  },
725
693
  // protocol: {
@@ -737,7 +705,7 @@ var TEST_ADDRESSES = {
737
705
  // '0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f',
738
706
  // },
739
707
  query: {
740
- id: "0x89706958f43fb170de134579e3fbc53972b946ee78bd2442d8e1adc36074fbdc",
708
+ id: "0xe4f9d62d17746d5b9dbf0d5557747430021a71575780b515161210cdba0a4c1c",
741
709
  upgradeCap: "0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f"
742
710
  },
743
711
  supra: { id: "", upgradeCap: "" },
@@ -773,10 +741,6 @@ var TEST_ADDRESSES = {
773
741
  "0xc3206071a8d43212efb6e3b5504f2321f8df97ab122b466c0bc7cfdf398dc13a"
774
742
  )
775
743
  },
776
- susdc: {
777
- id: "0x0b5f5f413bd3799e4052c37311966c77f3a4545eb125d2e93e67a68478021918",
778
- rewardPoolId: "0x85ed6ed72ea97c35dbf0cdc7ed6fbc48d8ec15de9b17c74bf4512df8a6d7f166"
779
- },
780
744
  swusdc: {
781
745
  // id: '0x4ace6648ddc64e646ba47a957c562c32c9599b3bba8f5ac1aadb2ae23a2f8ca0',
782
746
  id: "0xf1b383b9cf2e9f515fc69567df1053098f273849d09cd84b0278a773429bd2b2",
@@ -825,37 +789,37 @@ var TEST_ADDRESSES = {
825
789
  config: ""
826
790
  },
827
791
  borrowIncentive: {
828
- id: "0x85769d63565ce99c7622f8e336ca1460926ddf29738ad2a39407b5cac29f61fe",
829
- adminCap: "0x56ac8e6f2b360b2b35c0168d72cc6cd17d9592afb83709865cb87af24bb2025b",
830
- object: "0x85769d63565ce99c7622f8e336ca1460926ddf29738ad2a39407b5cac29f61fe",
831
- query: "0x8e0d00f8ff1199d7c5fe56cea0e901a525daeefff0445a1635ace8282ae3302c",
832
- incentivePools: "0x9d564c93128c6ab0c0d3e050a47f11df0b91494f3bb779bdc1301c1c637f15eb",
833
- incentiveAccounts: "0x09e6040e798246de04941bc79a3ba62d3eca6d7a218cc30f21fb07f478fa2926",
834
- config: "0x43d4ca1dfc90b161c4240facd119e74e4b850cca2957f88c2ec289c9380da064"
792
+ id: "0x6152f696fc3a658f33c4b891764731a59153125ffedfa8bff7167c42823f58a9",
793
+ adminCap: "0xc486afa253646f4d381e81d7f1df8aa4723b845a6bb356f69bad635ffefffe2c",
794
+ object: "0x002875153e09f8145ab63527bc85c00f2bd102e12f9573c47f8cdf1a1cb62934",
795
+ query: "0x529edc54a3dce2207703ceebbccb0ac14133f7825c1f528775ba0d85a4063489",
796
+ incentivePools: "0x6547e143d406b5ccd5f46aae482497de279cc1a68c406f701df70a05f9212ab4",
797
+ incentiveAccounts: "0xc4701fdbc1c92f9a636d334d66012b3027659e9fb8aff27279a82edfb6b77d02",
798
+ config: "0xdf5d04b4691cc67e82fd4db8394d89ff44823a9de29716c924f74bb4f11cc1f7"
835
799
  },
836
800
  referral: {
837
- id: "0x1bf5a8ce77050d8052549d743e16b469f15aa6b81b752b78b6ebb65179665f5a",
801
+ id: "0xa3654ebb63eb06c0f4ff52f8aa6512df9f164f7772bdf15dac3709bd3798dda9",
838
802
  object: "0x5658d4bf5ddcba27e4337b4262108b3ad1716643cac8c2054ac341538adc72ec",
839
803
  adminCap: "0xc5dc06b9074291259f2cac460c940012c781c4430e42125c541cc43101c3bcbd",
840
- referralBindings: "0xcf184487782bed962bf678001efe775d31fb94b9992333a57594cf15d79d5ced",
841
- bindingTableId: "0x41a50e258c0a266ce84e0e1a618dbf70b878cc943909e613089a50afcceb2bc0",
842
- referralRevenuePool: "0xc24e3e5e37032f29a3dd91a9a1f057af8821b7e6c148e9683900ac8b6d30f0c6",
804
+ referralBindings: "0xf63299d58789d99de94092b9011323466e55ca0c1ea1a7a3786a589af46e1c09",
805
+ bindingTableId: "0x1c8202b17267ec8d6cf97ca013615354181a04f179570e42601ff2dae19294b1",
806
+ referralRevenuePool: "0x6abd852caf90769c1b185cdf636d841673fa95528f0550f018b8a138bd283c07",
843
807
  revenueTableId: "0x595baa3654c297bff84ab7786a2d250f019cefc66e8df8e89fd9d41e02bd30dd",
844
- referralTiers: "0x144350f3db9b46d11b140084cd54e6de0b9c3b8d265ce8059b51d0ef58ea464b",
808
+ referralTiers: "0x962cb903d8d7346190c5204785ccbb91b61086aa764f674c8145df82335cf83e",
845
809
  tiersTableId: "0xeac755a7a8b7798530905ac79e8c114f19d0f130f6eab012954f08faac29c75d",
846
810
  // authorizedWitnessList:
847
811
  // '0xf21b0ed043c9bb70842c0129159f4943dbcc3c9ef2f2f808af65f8be25cfd20e',
848
812
  authorizedWitnessList: "0x9d6223dc52015b8a3986a573590ef2af8f1b8f3e4685513888c052f001b87e7f",
849
- version: "0x3545849eb97723e676a476ec9d4fe5f2eb0eb2c6b78972851114fd4c7ed4639f"
813
+ version: "0x1bd4b7285f72e11c316b828c7c47b3f4da18dcec9f9b3dba6d8629cbb6f93e5e"
850
814
  },
851
815
  vesca: {
852
- id: "0x1158813b32962c2d22888fae257d5f2365b03631f0cd5d5b912ccdf51ff4e2f2",
853
- object: "0x1158813b32962c2d22888fae257d5f2365b03631f0cd5d5b912ccdf51ff4e2f2",
816
+ id: "0xb15b6e0cdd85afb5028bea851dd249405e734d800a259147bbc24980629723a4",
817
+ object: "0xb15b6e0cdd85afb5028bea851dd249405e734d800a259147bbc24980629723a4",
854
818
  adminCap: "0x8ffa76135c5b85c5fbd73a6448a4a733d826cb63a267ab817656acb77c72d4a5",
855
- tableId: "0x0a0b7f749baeb61e3dfee2b42245e32d0e6b484063f0a536b33e771d573d7246",
856
- table: "0xd3a4632b1080f7d96e1c2487d4dabf2c1196916937c505a69954ac9f393be8d0",
857
- treasury: "0xafa4b6231e49c15a22d641ce33fda761baaf650fa21899dfa2eb1716146e7306",
858
- config: "0x7cbcb0a342179577a117dfdff974cf1ab765d3b571067bf22ddf5f9e3a667922"
819
+ tableId: "0xe3153b2bf124be0b86cb8bd468346a861efd0da52fc42197b54d2f616488a311",
820
+ table: "0x611cb8d9d4d90867467b5ebdf4cc447a0047ed5b01334a28a29fcfe733e3d609",
821
+ treasury: "0xe8c112c09b88158dc6c8e23d1fbae5b3c7136cdee54b7dafc08e65db28c4a5bc",
822
+ config: "0xe0a2ff281e73c1d53cfa85807080f87e833e4f1a7f93dcf8800b3865269a76b9"
859
823
  },
860
824
  loyaltyProgram: {
861
825
  id: "0xd17bcf8b5a59652c36225d478564a8593ae0ed7d650bcacdda1d6fe179127907",
@@ -864,27 +828,27 @@ var TEST_ADDRESSES = {
864
828
  userRewardTableId: "0x748a80395849ed37db1b0e14f2ab5d1d96458d2359ab3a84eb079d0f4ac7cf2e"
865
829
  },
866
830
  scoin: {
867
- id: "0x773dab39c90fe05439b06a2d061795e52a974ff92c2aef90b2ee467acf7f33c8",
831
+ id: "0xad2ca2aa5089df94bb2d444d5eb3520378c2f2dfb3a0bd2a2c994145ac4b0a53",
868
832
  coins: {
869
833
  ssui: {
870
- coinType: "0xf569919046f19a0c40b519ecfbb6ca0319698cd5908716c29b62ef56541f298b::scallop_sui::SCALLOP_SUI",
871
- treasury: "0x0e499640a12c38dd9cc44532f5bc5fd1b6da86d2f9a8810357250f4b26e9e5c7"
834
+ coinType: "0xfac769100bccc0caebcf4f4e2d00ac2f8883f07f724be28940df90605f5e7e9a::scallop_sui::SCALLOP_SUI",
835
+ treasury: "0x9cb4551b36c17d37e19d700147fa819ea1c487ff8bcf18374de2cceb2e9d4845"
872
836
  },
873
837
  scetus: {
874
838
  coinType: "0x8b71e6d323ed78515af2bead13bf3d0da1562ba4a99234eb7c4f14fd39ef0427::scallop_cetus::SCALLOP_CETUS",
875
839
  treasury: "0xd786f4b2d26278cc7911a3445b1b085eab60f269ef9dbb6b87e803d52f155003"
876
840
  },
877
841
  ssca: {
878
- coinType: "0x958428555e778e55918a59eb1c92c77f32b5c554fa3a5e56cd0815086b5072e7::scallop_sca::SCALLOP_SCA",
879
- treasury: "0x5f1c5de1df7341075d119570269b7b452af50afe8363080638f1ae29a554c038"
842
+ coinType: "0x0a9d3c6c9af9f6e8def82921541bcbd17f73ed31bed3adcb684f2a4c267e42f0::scallop_sca::SCALLOP_SCA",
843
+ treasury: "0xe818636d1d6c46d6ea1a2dce9d94696d7cbc18ce27451b603eeaa47aba8d75e0"
880
844
  },
881
845
  swusdc: {
882
- coinType: "0xf5447c4305a486d8c8557559887c2c39449ddb5e748f15d33946d02a1663c158::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
883
- treasury: "0x471fbab72578bab577263006fe32543b6e76153fffa2bef69affe4bc4934258f"
846
+ coinType: "0xaedc3ab75db8680b81a755015fa90124d217be93457b893c05bac033817defaf::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
847
+ treasury: "0xfc6971648f867f7fd6928d1b873af71577e2eaf2c7543ef8bc82c431d833ae78"
884
848
  },
885
849
  swusdt: {
886
- coinType: "0xac781d9f73058ff5e69f9bf8dde32f2e8c71c66d7fe8497fc83b2d9182254b22::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
887
- treasury: "0x921a4ed4bb4b4f11f51a462c83f4c0f6b60a90e441d1bc0d26d6fd893146bf4d"
850
+ coinType: "0xbf02fc87ddc104b342ad8414c85ceadf5b0c823c055a06fb0ed776272c01a52a::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
851
+ treasury: "0xb9593e2c3a0ba796ee815012b75ae46468ea78cda0188b9ac6816efe65503521"
888
852
  },
889
853
  sweth: {
890
854
  coinType: "0x27d54f43e3eda701be56b82e5756e41c84467cd202f5cf713d5f9e45a9f1b6bc::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
@@ -900,18 +864,14 @@ var TEST_ADDRESSES = {
900
864
  },
901
865
  svsui: {
902
866
  coinType: "0x97023a317320c4498cc4cd239dd02fd30c28246e5e8f81325d63f2bd8d70f6b3::scallop_v_sui::SCALLOP_V_SUI",
903
- treasury: "0x327114f0bf3559d7e2de10282147ed76a236c7c6775029165c4db09a6062ead6"
904
- },
905
- ssbeth: {
906
- coinType: "0xb14f82d8506d139eacef109688d1b71e7236bcce9b2c0ad526abcd6aa5be7de0::scallop_sb_eth::SCALLOP_SB_ETH",
907
- treasury: "0xfd0f02def6358a1f266acfa1493d4707ee8387460d434fb667d63d755ff907ed"
867
+ treasury: "0x327114f0bf3559d7e2de10282147ed76a236c7c6775029165c4db09a6062ead6\u0192"
908
868
  }
909
869
  }
910
870
  }
911
871
  };
912
872
 
913
873
  // src/constants/tokenBucket.ts
914
- var DEFAULT_TOKENS_PER_INTERVAL = 50;
874
+ var DEFAULT_TOKENS_PER_INTERVAL = 10;
915
875
  var DEFAULT_INTERVAL_IN_MS = 300;
916
876
 
917
877
  // src/constants/vesca.ts
@@ -921,9 +881,6 @@ var MAX_LOCK_DURATION = MAX_LOCK_ROUNDS * UNLOCK_ROUND_DURATION;
921
881
  var MIN_INITIAL_LOCK_AMOUNT = 1e10;
922
882
  var MIN_TOP_UP_AMOUNT = 1e9;
923
883
 
924
- // src/models/scallop.ts
925
- import { SuiKit as SuiKit7 } from "@scallop-io/sui-kit";
926
-
927
884
  // src/models/scallopAddress.ts
928
885
  import { SuiKit } from "@scallop-io/sui-kit";
929
886
 
@@ -1519,7 +1476,7 @@ var TokenBucket = class {
1519
1476
  return false;
1520
1477
  }
1521
1478
  };
1522
- var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 15, backoffFactor = 1.25) => {
1479
+ var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 30, backoffFactor = 1.25) => {
1523
1480
  let retries = 0;
1524
1481
  const tryRequest = async () => {
1525
1482
  if (tokenBucket.removeTokens(1)) {
@@ -1738,7 +1695,7 @@ var ScallopCache = class {
1738
1695
  async queryGetCoinBalance(input) {
1739
1696
  if (!input.coinType)
1740
1697
  return "0";
1741
- return (await this.queryGetAllCoinBalances(input.owner) || {})[normalizeStructTag2(input.coinType)] ?? "0";
1698
+ return (await this.queryGetAllCoinBalances(input.owner) ?? {})[normalizeStructTag2(input.coinType)] ?? "0";
1742
1699
  }
1743
1700
  };
1744
1701
 
@@ -2099,12 +2056,12 @@ var ScallopAddress = class {
2099
2056
  "Content-Type": "application/json",
2100
2057
  Accept: "application/json"
2101
2058
  },
2102
- timeout: 3e4
2059
+ timeout: 8e3
2103
2060
  });
2104
2061
  if (auth)
2105
2062
  this._auth = auth;
2106
2063
  this._id = id;
2107
- this._network = network || "mainnet";
2064
+ this._network = network ?? "mainnet";
2108
2065
  this._addressesMap = USE_TEST_ADDRESS ? /* @__PURE__ */ new Map([["mainnet", TEST_ADDRESSES]]) : /* @__PURE__ */ new Map();
2109
2066
  if (USE_TEST_ADDRESS)
2110
2067
  this._currentAddresses = TEST_ADDRESSES;
@@ -2407,11 +2364,9 @@ var ScallopAddress = class {
2407
2364
 
2408
2365
  // src/models/scallopClient.ts
2409
2366
  import { normalizeSuiAddress as normalizeSuiAddress3 } from "@mysten/sui/utils";
2410
- import { SuiKit as SuiKit6 } from "@scallop-io/sui-kit";
2411
2367
 
2412
2368
  // src/models/scallopUtils.ts
2413
2369
  import { SUI_TYPE_ARG, normalizeStructTag as normalizeStructTag6 } from "@mysten/sui/utils";
2414
- import { SuiKit as SuiKit2 } from "@scallop-io/sui-kit";
2415
2370
  import { SuiPriceServiceConnection } from "@pythnetwork/pyth-sui-js";
2416
2371
 
2417
2372
  // src/queries/coreQuery.ts
@@ -2453,103 +2408,20 @@ var getSupplyLimit = async (utils, poolName) => {
2453
2408
  return parsedData.data.fields.value;
2454
2409
  };
2455
2410
 
2456
- // src/queries/isolatedAsset.ts
2457
- import { z as zod2 } from "zod";
2458
- var isolatedAssetZod = zod2.object({
2459
- dataType: zod2.string(),
2460
- type: zod2.string(),
2461
- hasPublicTransfer: zod2.boolean(),
2462
- fields: zod2.object({
2463
- id: zod2.object({
2464
- id: zod2.string()
2465
- }),
2466
- name: zod2.object({
2467
- type: zod2.string()
2468
- }),
2469
- value: zod2.boolean()
2470
- })
2471
- });
2472
- var getIsolatedAssets = async (address) => {
2473
- try {
2474
- const marketObject = address.get("core.market");
2475
- const protocolObject = address.get("core.packages.protocol.id");
2476
- const ISOLATED_ASSET_KEY = `${protocolObject}::market_dynamic_keys::IsolatedAssetKey`;
2477
- const isolatedAssets = [];
2478
- if (!marketObject)
2479
- return isolatedAssets;
2480
- let hasNextPage = false;
2481
- let nextCursor = null;
2482
- const isIsolatedDynamicField = (dynamicField) => {
2483
- return dynamicField.name.type === ISOLATED_ASSET_KEY;
2484
- };
2485
- do {
2486
- const response = await address.cache.queryGetDynamicFields({
2487
- parentId: marketObject,
2488
- cursor: nextCursor,
2489
- limit: 10
2490
- });
2491
- if (!response)
2492
- break;
2493
- const isolatedAssetCoinTypes = response.data.filter(isIsolatedDynamicField).map(({ name }) => `0x${name.value.type.name}`);
2494
- isolatedAssets.push(...isolatedAssetCoinTypes);
2495
- if (response && response.hasNextPage && response.nextCursor) {
2496
- hasNextPage = true;
2497
- nextCursor = response.nextCursor;
2498
- } else {
2499
- hasNextPage = false;
2500
- }
2501
- } while (hasNextPage);
2502
- return isolatedAssets;
2503
- } catch (e) {
2504
- console.error(e);
2505
- return [];
2506
- }
2507
- };
2508
- var isIsolatedAsset = async (utils, coinName) => {
2509
- try {
2510
- const marketObject = utils.address.get("core.market");
2511
- const protocolObject = utils.address.get("core.packages.protocol.id");
2512
- const ISOLATED_ASSET_KEY = `${protocolObject}::market_dynamic_keys::IsolatedAssetKey`;
2513
- const cachedData = utils.address.cache.queryClient.getQueryData([
2514
- "getDynamicFields",
2515
- marketObject
2516
- ]);
2517
- if (cachedData) {
2518
- const coinType2 = utils.parseCoinType(coinName);
2519
- return cachedData.includes(coinType2);
2520
- }
2521
- const coinType = utils.parseCoinType(coinName).slice(2);
2522
- const object = await utils.cache.queryGetDynamicFieldObject({
2523
- parentId: marketObject,
2524
- name: {
2525
- type: ISOLATED_ASSET_KEY,
2526
- value: coinType
2527
- }
2528
- });
2529
- const parsedData = isolatedAssetZod.safeParse(object?.data?.content);
2530
- if (!parsedData.success)
2531
- return false;
2532
- return parsedData.data.fields.value;
2533
- } catch (e) {
2534
- console.error(e);
2535
- return false;
2536
- }
2537
- };
2538
-
2539
2411
  // src/queries/coreQuery.ts
2540
- var queryMarket = async (query, indexer = false) => {
2541
- const coinPrices = await query.utils.getCoinPrices();
2412
+ var queryMarket = async (query, indexer = false, coinPrices) => {
2413
+ coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
2542
2414
  const pools = {};
2543
2415
  const collaterals = {};
2544
2416
  if (indexer) {
2545
2417
  const marketIndexer = await query.indexer.getMarket();
2546
2418
  const updatePools = (item) => {
2547
- item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
2419
+ item.coinPrice = coinPrices[item.coinName] ?? item.coinPrice;
2548
2420
  item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
2549
2421
  pools[item.coinName] = item;
2550
2422
  };
2551
2423
  const updateCollaterals = (item) => {
2552
- item.coinPrice = coinPrices[item.coinName] || item.coinPrice;
2424
+ item.coinPrice = coinPrices[item.coinName] ?? item.coinPrice;
2553
2425
  item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
2554
2426
  collaterals[item.coinName] = item;
2555
2427
  };
@@ -2620,8 +2492,8 @@ var queryMarket = async (query, indexer = false) => {
2620
2492
  borrowFee: parsedMarketPoolData.borrowFee,
2621
2493
  marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
2622
2494
  minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
2623
- isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
2624
- // isIsolated: false,
2495
+ // isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
2496
+ isIsolated: false,
2625
2497
  maxSupplyCoin,
2626
2498
  ...calculatedMarketPoolData
2627
2499
  };
@@ -2660,7 +2532,6 @@ var queryMarket = async (query, indexer = false) => {
2660
2532
  liquidationDiscount: parsedMarketCollateralData.liquidationDiscount,
2661
2533
  liquidationPanelty: parsedMarketCollateralData.liquidationPanelty,
2662
2534
  liquidationReserveFactor: parsedMarketCollateralData.liquidationReserveFactor,
2663
- isIsolated: await isIsolatedAsset(query.utils, collateralCoinName),
2664
2535
  ...calculatedMarketCollateralData
2665
2536
  };
2666
2537
  }
@@ -2670,19 +2541,19 @@ var queryMarket = async (query, indexer = false) => {
2670
2541
  // data: marketData,
2671
2542
  };
2672
2543
  };
2673
- var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer = false) => {
2544
+ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer = false, coinPrices) => {
2674
2545
  const marketId = query.address.get("core.market");
2675
2546
  const marketObjectResponse = await query.cache.queryGetObject(marketId, {
2676
2547
  showContent: true
2677
2548
  });
2678
- const coinPrices = await query.utils.getCoinPrices(poolCoinNames) ?? {};
2549
+ coinPrices = await query.utils.getCoinPrices(poolCoinNames) ?? {};
2679
2550
  const marketPools = {};
2680
2551
  if (indexer) {
2681
2552
  const marketPoolsIndexer = await query.indexer.getMarketPools();
2682
2553
  const updateMarketPool = (marketPool) => {
2683
2554
  if (!poolCoinNames.includes(marketPool.coinName))
2684
2555
  return;
2685
- marketPool.coinPrice = coinPrices[marketPool.coinName] || marketPool.coinPrice;
2556
+ marketPool.coinPrice = coinPrices[marketPool.coinName] ?? marketPool.coinPrice;
2686
2557
  marketPool.coinWrappedType = query.utils.getCoinWrappedType(
2687
2558
  marketPool.coinName
2688
2559
  );
@@ -2708,73 +2579,85 @@ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer =
2708
2579
  return marketPools;
2709
2580
  };
2710
2581
  var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, coinPrice) => {
2711
- try {
2712
- coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2713
- if (indexer) {
2714
- const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
2715
- marketPoolIndexer.coinPrice = coinPrice || marketPoolIndexer.coinPrice;
2716
- marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
2717
- marketPoolIndexer.coinName
2718
- );
2719
- return marketPoolIndexer;
2720
- }
2721
- const marketId = query.address.get("core.market");
2722
- marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2723
- showContent: true
2724
- }))?.data;
2725
- if (!(marketObject && marketObject.content?.dataType === "moveObject"))
2726
- throw new Error(`Failed to fetch marketObject`);
2727
- const fields = marketObject.content.fields;
2728
- const coinType = query.utils.parseCoinType(poolCoinName);
2729
- const balanceSheetParentId = fields.vault.fields.balance_sheets.fields.table.fields.id.id;
2730
- const balanceSheetDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
2731
- parentId: balanceSheetParentId,
2732
- name: {
2733
- type: "0x1::type_name::TypeName",
2734
- value: {
2735
- name: coinType.substring(2)
2582
+ let marketPool;
2583
+ let balanceSheet;
2584
+ let borrowIndex;
2585
+ let interestModel;
2586
+ let borrowFeeRate;
2587
+ coinPrice = coinPrice ?? (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
2588
+ if (indexer) {
2589
+ const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
2590
+ marketPoolIndexer.coinPrice = coinPrice ?? marketPoolIndexer.coinPrice;
2591
+ marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
2592
+ marketPoolIndexer.coinName
2593
+ );
2594
+ return marketPoolIndexer;
2595
+ }
2596
+ const marketId = query.address.get("core.market");
2597
+ marketObject = marketObject ?? (await query.cache.queryGetObject(marketId, {
2598
+ showContent: true
2599
+ }))?.data;
2600
+ if (marketObject) {
2601
+ if (marketObject.content && "fields" in marketObject.content) {
2602
+ const fields = marketObject.content.fields;
2603
+ const coinType = query.utils.parseCoinType(poolCoinName);
2604
+ const balanceSheetParentId = fields.vault.fields.balance_sheets.fields.table.fields.id.id;
2605
+ const balanceSheetDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
2606
+ parentId: balanceSheetParentId,
2607
+ name: {
2608
+ type: "0x1::type_name::TypeName",
2609
+ value: {
2610
+ name: coinType.substring(2)
2611
+ }
2736
2612
  }
2613
+ });
2614
+ if (!balanceSheetDynamicFieldObjectResponse)
2615
+ throw new Error(
2616
+ `Failed to fetch balanceSheetDynamicFieldObjectResponse for ${poolCoinName}`
2617
+ );
2618
+ const balanceSheetDynamicFieldObject = balanceSheetDynamicFieldObjectResponse.data;
2619
+ if (balanceSheetDynamicFieldObject && balanceSheetDynamicFieldObject.content && "fields" in balanceSheetDynamicFieldObject.content) {
2620
+ const dynamicFields = balanceSheetDynamicFieldObject.content.fields;
2621
+ balanceSheet = dynamicFields.value.fields;
2737
2622
  }
2738
- });
2739
- const balanceSheetDynamicFieldObject = balanceSheetDynamicFieldObjectResponse?.data;
2740
- if (!(balanceSheetDynamicFieldObject && balanceSheetDynamicFieldObject.content && "fields" in balanceSheetDynamicFieldObject.content))
2741
- throw new Error(
2742
- `Failed to fetch balanceSheetDynamicFieldObject for ${poolCoinName}: ${balanceSheetDynamicFieldObjectResponse?.error?.code.toString()}`
2743
- );
2744
- const balanceSheet = balanceSheetDynamicFieldObject.content.fields.value.fields;
2745
- const borrowIndexParentId = fields.borrow_dynamics.fields.table.fields.id.id;
2746
- const borrowIndexDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
2747
- parentId: borrowIndexParentId,
2748
- name: {
2749
- type: "0x1::type_name::TypeName",
2750
- value: {
2751
- name: coinType.substring(2)
2623
+ const borrowIndexParentId = fields.borrow_dynamics.fields.table.fields.id.id;
2624
+ const borrowIndexDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
2625
+ parentId: borrowIndexParentId,
2626
+ name: {
2627
+ type: "0x1::type_name::TypeName",
2628
+ value: {
2629
+ name: coinType.substring(2)
2630
+ }
2752
2631
  }
2632
+ });
2633
+ if (!borrowIndexDynamicFieldObjectResponse)
2634
+ throw new Error(
2635
+ `Failed to fetch borrowIndexDynamicFieldObjectResponse for ${poolCoinName}`
2636
+ );
2637
+ const borrowIndexDynamicFieldObject = borrowIndexDynamicFieldObjectResponse.data;
2638
+ if (borrowIndexDynamicFieldObject && borrowIndexDynamicFieldObject.content && "fields" in borrowIndexDynamicFieldObject.content) {
2639
+ const dynamicFields = borrowIndexDynamicFieldObject.content.fields;
2640
+ borrowIndex = dynamicFields.value.fields;
2753
2641
  }
2754
- });
2755
- const borrowIndexDynamicFieldObject = borrowIndexDynamicFieldObjectResponse?.data;
2756
- if (!(borrowIndexDynamicFieldObject && borrowIndexDynamicFieldObject.content && "fields" in borrowIndexDynamicFieldObject.content))
2757
- throw new Error(
2758
- `Failed to fetch borrowIndexDynamicFieldObject for ${poolCoinName}`
2759
- );
2760
- const borrowIndex = borrowIndexDynamicFieldObject.content.fields.value.fields;
2761
- const interestModelParentId = fields.interest_models.fields.table.fields.id.id;
2762
- const interestModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
2763
- parentId: interestModelParentId,
2764
- name: {
2765
- type: "0x1::type_name::TypeName",
2766
- value: {
2767
- name: coinType.substring(2)
2642
+ const interestModelParentId = fields.interest_models.fields.table.fields.id.id;
2643
+ const interestModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
2644
+ parentId: interestModelParentId,
2645
+ name: {
2646
+ type: "0x1::type_name::TypeName",
2647
+ value: {
2648
+ name: coinType.substring(2)
2649
+ }
2768
2650
  }
2651
+ });
2652
+ if (!interestModelDynamicFieldObjectResponse)
2653
+ throw new Error(
2654
+ `Failed to fetch interestModelDynamicFieldObjectResponse for ${poolCoinName}`
2655
+ );
2656
+ const interestModelDynamicFieldObject = interestModelDynamicFieldObjectResponse.data;
2657
+ if (interestModelDynamicFieldObject && interestModelDynamicFieldObject.content && "fields" in interestModelDynamicFieldObject.content) {
2658
+ const dynamicFields = interestModelDynamicFieldObject.content.fields;
2659
+ interestModel = dynamicFields.value.fields;
2769
2660
  }
2770
- });
2771
- const interestModelDynamicFieldObject = interestModelDynamicFieldObjectResponse?.data;
2772
- if (!(interestModelDynamicFieldObject && interestModelDynamicFieldObject.content && "fields" in interestModelDynamicFieldObject.content))
2773
- throw new Error(
2774
- `Failed to fetch interestModelDynamicFieldObject for ${poolCoinName}: ${interestModelDynamicFieldObject}`
2775
- );
2776
- const interestModel = interestModelDynamicFieldObject.content.fields.value.fields;
2777
- const getBorrowFee = async () => {
2778
2661
  const borrowFeeDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
2779
2662
  parentId: marketId,
2780
2663
  name: {
@@ -2786,11 +2669,18 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2786
2669
  }
2787
2670
  }
2788
2671
  });
2789
- const borrowFeeDynamicFieldObject = borrowFeeDynamicFieldObjectResponse?.data;
2790
- if (!(borrowFeeDynamicFieldObject && borrowFeeDynamicFieldObject.content && "fields" in borrowFeeDynamicFieldObject.content))
2791
- return { value: "0" };
2792
- return borrowFeeDynamicFieldObject.content.fields.value.fields;
2793
- };
2672
+ if (!borrowFeeDynamicFieldObjectResponse)
2673
+ throw new Error(
2674
+ `Failed to fetch borrowFeeDynamicFieldObjectResponse for ${poolCoinName}`
2675
+ );
2676
+ const borrowFeeDynamicFieldObject = borrowFeeDynamicFieldObjectResponse.data;
2677
+ if (borrowFeeDynamicFieldObject && borrowFeeDynamicFieldObject.content && "fields" in borrowFeeDynamicFieldObject.content) {
2678
+ const dynamicFields = borrowFeeDynamicFieldObject.content.fields;
2679
+ borrowFeeRate = dynamicFields.value.fields;
2680
+ }
2681
+ }
2682
+ }
2683
+ if (balanceSheet && borrowIndex && interestModel && (USE_TEST_ADDRESS || borrowFeeRate)) {
2794
2684
  const parsedMarketPoolData = parseOriginMarketPoolData({
2795
2685
  type: interestModel.type.fields,
2796
2686
  maxBorrowRate: interestModel.max_borrow_rate.fields,
@@ -2804,7 +2694,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2804
2694
  reserve: balanceSheet.revenue,
2805
2695
  reserveFactor: interestModel.revenue_factor.fields,
2806
2696
  borrowWeight: interestModel.borrow_weight.fields,
2807
- borrowFeeRate: await getBorrowFee(),
2697
+ borrowFeeRate: borrowFeeRate ?? { value: "0" },
2808
2698
  baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
2809
2699
  borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
2810
2700
  borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
@@ -2820,7 +2710,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2820
2710
  const maxSupplyCoin = BigNumber2(
2821
2711
  await getSupplyLimit(query.utils, poolCoinName) ?? "0"
2822
2712
  ).shiftedBy(-coinDecimal).toNumber();
2823
- return {
2713
+ marketPool = {
2824
2714
  coinName: poolCoinName,
2825
2715
  symbol: query.utils.parseSymbol(poolCoinName),
2826
2716
  coinType: query.utils.parseCoinType(poolCoinName),
@@ -2839,13 +2729,12 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2839
2729
  marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
2840
2730
  minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
2841
2731
  maxSupplyCoin,
2842
- isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
2843
- // isIsolated: false,
2732
+ // isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
2733
+ isIsolated: false,
2844
2734
  ...calculatedMarketPoolData
2845
2735
  };
2846
- } catch (e) {
2847
- console.error(e);
2848
2736
  }
2737
+ return marketPool;
2849
2738
  };
2850
2739
  var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLATERALS], indexer = false) => {
2851
2740
  const marketId = query.address.get("core.market");
@@ -2856,7 +2745,7 @@ var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLA
2856
2745
  const updateMarketCollateral = (marketCollateral) => {
2857
2746
  if (!collateralCoinNames.includes(marketCollateral.coinName))
2858
2747
  return;
2859
- marketCollateral.coinPrice = coinPrices[marketCollateral.coinName] || marketCollateral.coinPrice;
2748
+ marketCollateral.coinPrice = coinPrices[marketCollateral.coinName] ?? marketCollateral.coinPrice;
2860
2749
  marketCollateral.coinWrappedType = query.utils.getCoinWrappedType(
2861
2750
  marketCollateral.coinName
2862
2751
  );
@@ -2888,88 +2777,97 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
2888
2777
  coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
2889
2778
  if (indexer) {
2890
2779
  const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
2891
- marketCollateralIndexer.coinPrice = coinPrice || marketCollateralIndexer.coinPrice;
2780
+ marketCollateralIndexer.coinPrice = coinPrice ?? marketCollateralIndexer.coinPrice;
2892
2781
  marketCollateralIndexer.coinWrappedType = query.utils.getCoinWrappedType(
2893
2782
  marketCollateralIndexer.coinName
2894
2783
  );
2895
2784
  return marketCollateralIndexer;
2896
2785
  }
2786
+ let marketCollateral;
2787
+ let riskModel;
2788
+ let collateralStat;
2897
2789
  const marketId = query.address.get("core.market");
2898
2790
  marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
2899
2791
  showContent: true
2900
2792
  }))?.data;
2901
- if (!(marketObject && marketObject.content?.dataType === "moveObject"))
2902
- throw new Error(`Failed to fetch marketObject`);
2903
- const fields = marketObject.content.fields;
2904
- const coinType = query.utils.parseCoinType(collateralCoinName);
2905
- const riskModelParentId = fields.risk_models.fields.table.fields.id.id;
2906
- const riskModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
2907
- parentId: riskModelParentId,
2908
- name: {
2909
- type: "0x1::type_name::TypeName",
2910
- value: {
2911
- name: coinType.substring(2)
2793
+ if (marketObject) {
2794
+ if (marketObject.content && "fields" in marketObject.content) {
2795
+ const fields = marketObject.content.fields;
2796
+ const coinType = query.utils.parseCoinType(collateralCoinName);
2797
+ const riskModelParentId = fields.risk_models.fields.table.fields.id.id;
2798
+ const riskModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
2799
+ parentId: riskModelParentId,
2800
+ name: {
2801
+ type: "0x1::type_name::TypeName",
2802
+ value: {
2803
+ name: coinType.substring(2)
2804
+ }
2805
+ }
2806
+ });
2807
+ if (!riskModelDynamicFieldObjectResponse)
2808
+ return void 0;
2809
+ const riskModelDynamicFieldObject = riskModelDynamicFieldObjectResponse.data;
2810
+ if (riskModelDynamicFieldObject && riskModelDynamicFieldObject.content && "fields" in riskModelDynamicFieldObject.content) {
2811
+ const dynamicFields = riskModelDynamicFieldObject.content.fields;
2812
+ riskModel = dynamicFields.value.fields;
2912
2813
  }
2913
- }
2914
- });
2915
- const riskModelDynamicFieldObject = riskModelDynamicFieldObjectResponse?.data;
2916
- if (!(riskModelDynamicFieldObject && riskModelDynamicFieldObject.content && "fields" in riskModelDynamicFieldObject.content))
2917
- throw new Error(
2918
- `Failed to fetch riskModelDynamicFieldObject for ${riskModelDynamicFieldObjectResponse?.error?.code.toString()}: `
2919
- );
2920
- const riskModel = riskModelDynamicFieldObject.content.fields.value.fields;
2921
- const collateralStatParentId = fields.collateral_stats.fields.table.fields.id.id;
2922
- const collateralStatDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
2923
- parentId: collateralStatParentId,
2924
- name: {
2925
- type: "0x1::type_name::TypeName",
2926
- value: {
2927
- name: coinType.substring(2)
2814
+ const collateralStatParentId = fields.collateral_stats.fields.table.fields.id.id;
2815
+ const collateralStatDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
2816
+ parentId: collateralStatParentId,
2817
+ name: {
2818
+ type: "0x1::type_name::TypeName",
2819
+ value: {
2820
+ name: coinType.substring(2)
2821
+ }
2822
+ }
2823
+ });
2824
+ if (!collateralStatDynamicFieldObjectResponse)
2825
+ return void 0;
2826
+ const collateralStatDynamicFieldObject = collateralStatDynamicFieldObjectResponse.data;
2827
+ if (collateralStatDynamicFieldObject && collateralStatDynamicFieldObject.content && "fields" in collateralStatDynamicFieldObject.content) {
2828
+ const dynamicFields = collateralStatDynamicFieldObject.content.fields;
2829
+ collateralStat = dynamicFields.value.fields;
2928
2830
  }
2929
2831
  }
2930
- });
2931
- const collateralStatDynamicFieldObject = collateralStatDynamicFieldObjectResponse?.data;
2932
- if (!(collateralStatDynamicFieldObject && collateralStatDynamicFieldObject.content && "fields" in collateralStatDynamicFieldObject.content))
2933
- throw new Error(
2934
- `Failed to fetch collateralStatDynamicFieldObject for ${collateralCoinName}: ${collateralStatDynamicFieldObjectResponse?.error?.code.toString()}`
2832
+ }
2833
+ if (riskModel && collateralStat) {
2834
+ const parsedMarketCollateralData = parseOriginMarketCollateralData({
2835
+ type: riskModel.type.fields,
2836
+ collateralFactor: riskModel.collateral_factor.fields,
2837
+ liquidationFactor: riskModel.liquidation_factor.fields,
2838
+ liquidationDiscount: riskModel.liquidation_discount.fields,
2839
+ liquidationPanelty: riskModel.liquidation_penalty.fields,
2840
+ liquidationReserveFactor: riskModel.liquidation_revenue_factor.fields,
2841
+ maxCollateralAmount: riskModel.max_collateral_amount,
2842
+ totalCollateralAmount: collateralStat.amount
2843
+ });
2844
+ const calculatedMarketCollateralData = calculateMarketCollateralData(
2845
+ query.utils,
2846
+ parsedMarketCollateralData
2935
2847
  );
2936
- const collateralStat = collateralStatDynamicFieldObject.content.fields.value.fields;
2937
- const parsedMarketCollateralData = parseOriginMarketCollateralData({
2938
- type: riskModel.type.fields,
2939
- collateralFactor: riskModel.collateral_factor.fields,
2940
- liquidationFactor: riskModel.liquidation_factor.fields,
2941
- liquidationDiscount: riskModel.liquidation_discount.fields,
2942
- liquidationPanelty: riskModel.liquidation_penalty.fields,
2943
- liquidationReserveFactor: riskModel.liquidation_revenue_factor.fields,
2944
- maxCollateralAmount: riskModel.max_collateral_amount,
2945
- totalCollateralAmount: collateralStat.amount
2946
- });
2947
- const calculatedMarketCollateralData = calculateMarketCollateralData(
2948
- query.utils,
2949
- parsedMarketCollateralData
2950
- );
2951
- return {
2952
- coinName: collateralCoinName,
2953
- symbol: query.utils.parseSymbol(collateralCoinName),
2954
- coinType: query.utils.parseCoinType(collateralCoinName),
2955
- marketCoinType: query.utils.parseMarketCoinType(collateralCoinName),
2956
- coinWrappedType: query.utils.getCoinWrappedType(collateralCoinName),
2957
- coinDecimal: query.utils.getCoinDecimal(collateralCoinName),
2958
- coinPrice: coinPrice ?? 0,
2959
- collateralFactor: parsedMarketCollateralData.collateralFactor,
2960
- liquidationFactor: parsedMarketCollateralData.liquidationFactor,
2961
- liquidationDiscount: parsedMarketCollateralData.liquidationDiscount,
2962
- liquidationPanelty: parsedMarketCollateralData.liquidationPanelty,
2963
- liquidationReserveFactor: parsedMarketCollateralData.liquidationReserveFactor,
2964
- isIsolated: await isIsolatedAsset(query.utils, collateralCoinName),
2965
- ...calculatedMarketCollateralData
2966
- };
2848
+ marketCollateral = {
2849
+ coinName: collateralCoinName,
2850
+ symbol: query.utils.parseSymbol(collateralCoinName),
2851
+ coinType: query.utils.parseCoinType(collateralCoinName),
2852
+ marketCoinType: query.utils.parseMarketCoinType(collateralCoinName),
2853
+ coinWrappedType: query.utils.getCoinWrappedType(collateralCoinName),
2854
+ coinDecimal: query.utils.getCoinDecimal(collateralCoinName),
2855
+ coinPrice: coinPrice ?? 0,
2856
+ collateralFactor: parsedMarketCollateralData.collateralFactor,
2857
+ liquidationFactor: parsedMarketCollateralData.liquidationFactor,
2858
+ liquidationDiscount: parsedMarketCollateralData.liquidationDiscount,
2859
+ liquidationPanelty: parsedMarketCollateralData.liquidationPanelty,
2860
+ liquidationReserveFactor: parsedMarketCollateralData.liquidationReserveFactor,
2861
+ ...calculatedMarketCollateralData
2862
+ };
2863
+ }
2864
+ return marketCollateral;
2967
2865
  };
2968
2866
  var getObligations = async ({
2969
2867
  address
2970
2868
  }, ownerAddress) => {
2971
2869
  const owner = ownerAddress;
2972
- const protocolObjectId = address.get("core.object") || PROTOCOL_OBJECT_ID;
2870
+ const protocolObjectId = address.get("core.object") ?? PROTOCOL_OBJECT_ID;
2973
2871
  const keyObjectsResponse = [];
2974
2872
  let hasNextPage = false;
2975
2873
  let nextCursor = null;
@@ -3036,7 +2934,7 @@ var queryObligation = async ({
3036
2934
  return queryResult?.events[0]?.parsedJson;
3037
2935
  };
3038
2936
  var getCoinAmounts = async (query, assetCoinNames = [...SUPPORT_POOLS], ownerAddress) => {
3039
- const owner = ownerAddress || query.suiKit.currentAddress();
2937
+ const owner = ownerAddress ?? query.suiKit.currentAddress();
3040
2938
  const assetCoins2 = {};
3041
2939
  await Promise.allSettled(
3042
2940
  assetCoinNames.map(async (assetCoinName) => {
@@ -3047,7 +2945,7 @@ var getCoinAmounts = async (query, assetCoinNames = [...SUPPORT_POOLS], ownerAdd
3047
2945
  return assetCoins2;
3048
2946
  };
3049
2947
  var getCoinAmount = async (query, assetCoinName, ownerAddress) => {
3050
- const owner = ownerAddress || query.suiKit.currentAddress();
2948
+ const owner = ownerAddress ?? query.suiKit.currentAddress();
3051
2949
  const coinType = query.utils.parseCoinType(assetCoinName);
3052
2950
  const amount = await query.cache.queryGetCoinBalance({
3053
2951
  owner,
@@ -3059,7 +2957,7 @@ var getMarketCoinAmounts = async (query, marketCoinNames, ownerAddress) => {
3059
2957
  marketCoinNames = marketCoinNames || [...SUPPORT_POOLS].map(
3060
2958
  (poolCoinName) => query.utils.parseMarketCoinName(poolCoinName)
3061
2959
  );
3062
- const owner = ownerAddress || query.suiKit.currentAddress();
2960
+ const owner = ownerAddress ?? query.suiKit.currentAddress();
3063
2961
  const marketCoins2 = {};
3064
2962
  await Promise.allSettled(
3065
2963
  marketCoinNames.map(async (marketCoinName) => {
@@ -3074,7 +2972,7 @@ var getMarketCoinAmounts = async (query, marketCoinNames, ownerAddress) => {
3074
2972
  return marketCoins2;
3075
2973
  };
3076
2974
  var getMarketCoinAmount = async (query, marketCoinName, ownerAddress) => {
3077
- const owner = ownerAddress || query.suiKit.currentAddress();
2975
+ const owner = ownerAddress ?? query.suiKit.currentAddress();
3078
2976
  const marketCoinType = query.utils.parseMarketCoinType(marketCoinName);
3079
2977
  const amount = await query.cache.queryGetCoinBalance({
3080
2978
  owner,
@@ -3143,18 +3041,14 @@ var getFlashLoanFees = async (query, assetNames) => {
3143
3041
 
3144
3042
  // src/queries/spoolQuery.ts
3145
3043
  import { normalizeStructTag as normalizeStructTag4 } from "@mysten/sui/utils";
3146
- var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexer = false) => {
3044
+ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexer = false, marketPools, coinPrices) => {
3147
3045
  const stakeCoinNames = stakeMarketCoinNames.map(
3148
3046
  (stakeMarketCoinName) => query.utils.parseCoinName(stakeMarketCoinName)
3149
3047
  );
3150
- const rewardCoinNames = stakeMarketCoinNames.map((stakeMarketCoinName) => {
3151
- const rewardCoinName = query.utils.getSpoolRewardCoinName(stakeMarketCoinName);
3152
- return rewardCoinName;
3153
- });
3154
- const coinPrices = await query.utils.getCoinPrices([
3155
- .../* @__PURE__ */ new Set([...stakeCoinNames, ...rewardCoinNames])
3156
- ]) ?? {};
3157
- const marketPools = await query.getMarketPools(stakeCoinNames, indexer);
3048
+ coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
3049
+ marketPools = marketPools ?? await query.getMarketPools(stakeCoinNames, indexer);
3050
+ if (!marketPools)
3051
+ throw new Error(`Fail to fetch marketPools for ${stakeCoinNames}`);
3158
3052
  const spools = {};
3159
3053
  if (indexer) {
3160
3054
  const spoolsIndexer = await query.indexer.getSpools();
@@ -3168,9 +3062,9 @@ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexe
3168
3062
  spool.marketCoinName
3169
3063
  );
3170
3064
  const marketPool = marketPools[coinName];
3171
- spool.coinPrice = coinPrices[coinName] || spool.coinPrice;
3172
- spool.marketCoinPrice = (coinPrices[coinName] ?? 0) * (marketPool ? marketPool.conversionRate : 0) || spool.marketCoinPrice;
3173
- spool.rewardCoinPrice = coinPrices[rewardCoinName] || spool.rewardCoinPrice;
3065
+ spool.coinPrice = coinPrices[coinName] ?? spool.coinPrice;
3066
+ spool.marketCoinPrice = coinPrices[coinName] ? (coinPrices[coinName] ?? 0) * (marketPool ? marketPool.conversionRate : 0) : spool.marketCoinPrice;
3067
+ spool.rewardCoinPrice = coinPrices[rewardCoinName] ?? spool.rewardCoinPrice;
3174
3068
  spools[spool.marketCoinName] = spool;
3175
3069
  };
3176
3070
  Object.values(spoolsIndexer).forEach(updateSpools);
@@ -3195,7 +3089,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
3195
3089
  const coinName = query.utils.parseCoinName(marketCoinName);
3196
3090
  marketPool = marketPool || await query.getMarketPool(coinName, indexer);
3197
3091
  if (!marketPool) {
3198
- throw new Error(`Failed to fetch marketPool for ${marketCoinName}`);
3092
+ throw new Error(`Fail to fetch marketPool for ${coinName}`);
3199
3093
  }
3200
3094
  const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
3201
3095
  const rewardPoolId = query.address.get(
@@ -3482,20 +3376,15 @@ var queryBorrowIncentivePools = async (address) => {
3482
3376
  };
3483
3377
  var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
3484
3378
  ...SUPPORT_BORROW_INCENTIVE_POOLS
3485
- ], indexer = false) => {
3379
+ ], indexer = false, coinPrices) => {
3486
3380
  const borrowIncentivePools = {};
3487
- const coinPrices = await query.utils.getCoinPrices([
3488
- .../* @__PURE__ */ new Set([
3489
- ...borrowIncentiveCoinNames,
3490
- ...SUPPORT_BORROW_INCENTIVE_REWARDS
3491
- ])
3492
- ]) ?? {};
3381
+ coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
3493
3382
  if (indexer) {
3494
3383
  const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
3495
3384
  const updateBorrowIncentivePool = (pool) => {
3496
3385
  if (!borrowIncentiveCoinNames.includes(pool.coinName))
3497
3386
  return;
3498
- pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
3387
+ pool.coinPrice = coinPrices[pool.coinName] ?? pool.coinPrice;
3499
3388
  borrowIncentivePools[pool.coinName] = pool;
3500
3389
  };
3501
3390
  Object.values(borrowIncentivePoolsIndexer).forEach(
@@ -3742,20 +3631,18 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
3742
3631
  const stakeMarketCoinNames = marketCoinNames.filter(
3743
3632
  (marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
3744
3633
  );
3745
- const [
3634
+ const coinPrices = await query.utils.getCoinPrices(poolCoinNames);
3635
+ const marketPools = await query.getMarketPools(poolCoinNames, indexer, {
3636
+ coinPrices
3637
+ });
3638
+ const spools = await query.getSpools(stakeMarketCoinNames, indexer, {
3746
3639
  marketPools,
3747
- spools,
3748
- coinAmounts,
3749
- marketCoinAmounts,
3750
- allStakeAccounts,
3751
3640
  coinPrices
3752
- ] = await Promise.all([
3753
- query.getMarketPools(poolCoinNames, indexer),
3754
- query.getSpools(stakeMarketCoinNames, indexer),
3641
+ });
3642
+ const [coinAmounts, marketCoinAmounts, allStakeAccounts] = await Promise.all([
3755
3643
  query.getCoinAmounts(poolCoinNames, ownerAddress),
3756
3644
  query.getMarketCoinAmounts(marketCoinNames, ownerAddress),
3757
- query.getAllStakeAccounts(ownerAddress),
3758
- query.utils.getCoinPrices(poolCoinNames)
3645
+ query.getAllStakeAccounts(ownerAddress)
3759
3646
  ]);
3760
3647
  const lendings = {};
3761
3648
  await Promise.allSettled(
@@ -3771,7 +3658,7 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
3771
3658
  indexer,
3772
3659
  marketPools?.[poolCoinName],
3773
3660
  stakeMarketCoinName ? spools[stakeMarketCoinName] : void 0,
3774
- stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : void 0,
3661
+ stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : [],
3775
3662
  coinAmounts?.[poolCoinName],
3776
3663
  marketCoinAmounts?.[marketCoinName],
3777
3664
  coinPrices?.[poolCoinName] ?? 0
@@ -3782,8 +3669,22 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
3782
3669
  };
3783
3670
  var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice, sCoinAmount) => {
3784
3671
  const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
3785
- marketPool = marketPool || await query.getMarketPool(poolCoinName, indexer);
3786
- spool = spool || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(marketCoinName, indexer) : void 0;
3672
+ coinPrice = coinPrice ?? (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
3673
+ marketPool = marketPool ?? await query.getMarketPool(poolCoinName, indexer, {
3674
+ coinPrice
3675
+ });
3676
+ if (!marketPool)
3677
+ throw new Error(`Failed to fetch marketPool for ${poolCoinName}`);
3678
+ spool = spool ?? SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(
3679
+ marketCoinName,
3680
+ indexer,
3681
+ {
3682
+ marketPool,
3683
+ coinPrices: {
3684
+ [poolCoinName]: coinPrice
3685
+ }
3686
+ }
3687
+ ) : void 0;
3787
3688
  stakeAccounts = stakeAccounts || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getStakeAccounts(
3788
3689
  marketCoinName,
3789
3690
  ownerAddress
@@ -3791,7 +3692,6 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
3791
3692
  coinAmount = coinAmount || await query.getCoinAmount(poolCoinName, ownerAddress);
3792
3693
  marketCoinAmount = marketCoinAmount || await query.getMarketCoinAmount(marketCoinName, ownerAddress);
3793
3694
  sCoinAmount = sCoinAmount || await query.getSCoinAmount(marketCoinName, ownerAddress);
3794
- coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
3795
3695
  const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
3796
3696
  let stakedMarketAmount = BigNumber4(0);
3797
3697
  let stakedMarketCoin = BigNumber4(0);
@@ -3903,10 +3803,12 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
3903
3803
  return lending;
3904
3804
  };
3905
3805
  var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
3906
- const market = await query.queryMarket(indexer);
3907
3806
  const coinPrices = await query.utils.getCoinPrices();
3908
- const coinAmounts = await query.getCoinAmounts(void 0, ownerAddress);
3909
- const obligations = await query.getObligations(ownerAddress);
3807
+ const market = await query.queryMarket(indexer, { coinPrices });
3808
+ const [coinAmounts, obligations] = await Promise.all([
3809
+ query.getCoinAmounts(void 0, ownerAddress),
3810
+ query.getObligations(ownerAddress)
3811
+ ]);
3910
3812
  const obligationAccounts = {};
3911
3813
  await Promise.allSettled(
3912
3814
  obligations.map(async (obligation) => {
@@ -3924,19 +3826,19 @@ var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
3924
3826
  return obligationAccounts;
3925
3827
  };
3926
3828
  var getObligationAccount = async (query, obligationId, ownerAddress, indexer = false, market, coinPrices, coinAmounts) => {
3927
- market = market || await query.queryMarket(indexer);
3928
- const poolAssetCoinNames = [
3929
- .../* @__PURE__ */ new Set([...Object.values(market.pools).map((pool) => pool.coinName)])
3829
+ const collateralAssetCoinNames = [
3830
+ ...SUPPORT_COLLATERALS
3930
3831
  ];
3931
- const obligationQuery = await query.queryObligation(obligationId);
3932
- const borrowIncentivePools = await query.getBorrowIncentivePools(
3933
- void 0,
3934
- indexer
3935
- );
3936
- const borrowIncentiveAccounts = await query.getBorrowIncentiveAccounts(obligationId);
3937
- coinPrices = coinPrices || await query.utils.getCoinPrices(poolAssetCoinNames);
3938
- coinAmounts = coinAmounts || await query.getCoinAmounts(poolAssetCoinNames, ownerAddress);
3939
- console.log(coinPrices);
3832
+ coinPrices = coinPrices ?? await query.utils.getCoinPrices(collateralAssetCoinNames);
3833
+ market = market ?? await query.queryMarket(indexer, { coinPrices });
3834
+ coinAmounts = coinAmounts || await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress);
3835
+ const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] = await Promise.all([
3836
+ query.queryObligation(obligationId),
3837
+ query.getBorrowIncentivePools(void 0, indexer, {
3838
+ coinPrices
3839
+ }),
3840
+ query.getBorrowIncentiveAccounts(obligationId)
3841
+ ]);
3940
3842
  const collaterals = {};
3941
3843
  const debts = {};
3942
3844
  const borrowIncentives = {};
@@ -3948,7 +3850,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
3948
3850
  let totalRewardedPools = 0;
3949
3851
  let totalBorrowedValue = BigNumber4(0);
3950
3852
  let totalBorrowedValueWithWeight = BigNumber4(0);
3951
- for (const assetCoinName of poolAssetCoinNames) {
3853
+ for (const assetCoinName of collateralAssetCoinNames) {
3952
3854
  const collateral = obligationQuery?.collaterals.find((collateral2) => {
3953
3855
  const collateralCoinName = query.utils.parseCoinNameFromType(
3954
3856
  collateral2.type.name
@@ -4253,7 +4155,7 @@ var getTotalValueLocked = async (query, indexer = false) => {
4253
4155
  import BigNumber5 from "bignumber.js";
4254
4156
  import { SUI_CLOCK_OBJECT_ID, SuiTxBlock as SuiTxBlock2 } from "@scallop-io/sui-kit";
4255
4157
  import { bcs } from "@mysten/sui/bcs";
4256
- import { z as zod3 } from "zod";
4158
+ import { z as zod2 } from "zod";
4257
4159
  import assert from "assert";
4258
4160
  var getVescaKeys = async (utils, ownerAddress) => {
4259
4161
  const owner = ownerAddress || utils.suiKit.currentAddress();
@@ -4302,10 +4204,10 @@ var getVeScas = async ({
4302
4204
  }
4303
4205
  return result;
4304
4206
  };
4305
- var SuiObjectRefZod = zod3.object({
4306
- objectId: zod3.string(),
4307
- digest: zod3.string(),
4308
- version: zod3.string()
4207
+ var SuiObjectRefZod = zod2.object({
4208
+ objectId: zod2.string(),
4209
+ digest: zod2.string(),
4210
+ version: zod2.string()
4309
4211
  });
4310
4212
  var getVeSca = async (utils, veScaKey) => {
4311
4213
  const tableId = utils.address.get(`vesca.tableId`);
@@ -4438,16 +4340,16 @@ var queryVeScaKeyIdFromReferralBindings = async (address, refereeAddress) => {
4438
4340
 
4439
4341
  // src/queries/loyaltyProgramQuery.ts
4440
4342
  import BigNumber6 from "bignumber.js";
4441
- import { z as zod4 } from "zod";
4442
- var rewardPoolFieldsZod = zod4.object({
4443
- balance: zod4.string(),
4444
- enable_claim: zod4.boolean()
4343
+ import { z as zod3 } from "zod";
4344
+ var rewardPoolFieldsZod = zod3.object({
4345
+ balance: zod3.string(),
4346
+ enable_claim: zod3.boolean()
4445
4347
  }).transform((value) => ({
4446
4348
  totalPoolReward: BigNumber6(value.balance).shiftedBy(-9).toNumber(),
4447
4349
  isClaimEnabled: value.enable_claim
4448
4350
  }));
4449
- var userRewardFieldsZod = zod4.object({
4450
- value: zod4.string()
4351
+ var userRewardFieldsZod = zod3.object({
4352
+ value: zod3.string()
4451
4353
  }).transform((value) => BigNumber6(value.value).shiftedBy(-9).toNumber());
4452
4354
  var getLoyaltyProgramInformations = async (query, veScaKey) => {
4453
4355
  const rewardPool = query.address.get("loyaltyProgram.rewardPool");
@@ -4465,7 +4367,7 @@ var getLoyaltyProgramInformations = async (query, veScaKey) => {
4465
4367
  totalPoolReward,
4466
4368
  isClaimEnabled
4467
4369
  };
4468
- veScaKey = veScaKey || (await query.getVeScas())[0]?.keyObject;
4370
+ veScaKey = veScaKey ?? (await query.getVeScas())[0]?.keyObject;
4469
4371
  if (!veScaKey)
4470
4372
  return result;
4471
4373
  const userRewardTableId = query.address.get(
@@ -4487,10 +4389,39 @@ var getLoyaltyProgramInformations = async (query, veScaKey) => {
4487
4389
  return result;
4488
4390
  };
4489
4391
 
4392
+ // src/models/suiKit.ts
4393
+ import { SuiKit as SuiKit2 } from "@scallop-io/sui-kit";
4394
+
4395
+ // src/constants/rpc.ts
4396
+ import { getFullnodeUrl } from "@mysten/sui/client";
4397
+ var RPC_PROVIDERS = [
4398
+ getFullnodeUrl("mainnet"),
4399
+ "https://sui-mainnet.public.blastapi.io",
4400
+ "https://sui-mainnet-ca-2.cosmostation.io",
4401
+ "https://sui-mainnet-eu-4.cosmostation.io",
4402
+ "https://sui-mainnet-endpoint.blockvision.org",
4403
+ "https://sui-rpc.publicnode.com",
4404
+ "https://sui-mainnet-rpc.allthatnode.com",
4405
+ "https://mainnet.suiet.app",
4406
+ "https://mainnet.sui.rpcpool.com",
4407
+ "https://sui1mainnet-rpc.chainode.tech",
4408
+ "https://fullnode.mainnet.apis.scallop.io",
4409
+ "https://sui-mainnet-us-2.cosmostation.io"
4410
+ ];
4411
+
4412
+ // src/models/suiKit.ts
4413
+ var newSuiKit = (params) => {
4414
+ return new SuiKit2({
4415
+ ...params,
4416
+ fullnodeUrls: Array.from(
4417
+ /* @__PURE__ */ new Set([...params.fullnodeUrls ?? [], ...RPC_PROVIDERS])
4418
+ )
4419
+ });
4420
+ };
4421
+
4490
4422
  // src/models/scallopUtils.ts
4491
4423
  var ScallopUtils = class {
4492
4424
  constructor(params, instance) {
4493
- this._priceMap = /* @__PURE__ */ new Map();
4494
4425
  /**
4495
4426
  * Get reward type of spool.
4496
4427
  *
@@ -4513,7 +4444,7 @@ var ScallopUtils = class {
4513
4444
  pythEndpoints: params.pythEndpoints ?? PYTH_ENDPOINTS["mainnet"],
4514
4445
  ...params
4515
4446
  };
4516
- this.suiKit = instance?.suiKit ?? instance?.address?.cache._suiKit ?? new SuiKit2(params);
4447
+ this.suiKit = instance?.suiKit ?? instance?.address?.cache._suiKit ?? newSuiKit(params);
4517
4448
  this.walletAddress = params.walletAddress ?? this.suiKit.currentAddress();
4518
4449
  if (instance?.address) {
4519
4450
  this.address = instance.address;
@@ -4527,7 +4458,7 @@ var ScallopUtils = class {
4527
4458
  );
4528
4459
  this.address = instance?.address ?? new ScallopAddress(
4529
4460
  {
4530
- id: params?.addressesId || ADDRESSES_ID,
4461
+ id: params?.addressesId ?? ADDRESSES_ID,
4531
4462
  network: params?.networkType,
4532
4463
  forceInterface: params?.forceAddressesInterface
4533
4464
  },
@@ -4552,10 +4483,10 @@ var ScallopUtils = class {
4552
4483
  * @param address - ScallopAddress instance.
4553
4484
  */
4554
4485
  async init(force = false, address) {
4555
- if (address && !this.address)
4556
- this.address = address;
4557
- if (force || !this.address.getAddresses()) {
4486
+ if (force || !this.address.getAddresses() || !address?.getAddresses()) {
4558
4487
  await this.address.read();
4488
+ } else {
4489
+ this.address = address;
4559
4490
  }
4560
4491
  }
4561
4492
  /**
@@ -4641,6 +4572,14 @@ var ScallopUtils = class {
4641
4572
  parseSCoinType(sCoinName) {
4642
4573
  return sCoinIds[sCoinName];
4643
4574
  }
4575
+ /**
4576
+ * Convert sCoinType into sCoin name
4577
+ * @param sCoinType
4578
+ * @returns sCoin name
4579
+ */
4580
+ parseSCoinNameFromType(sCoinType) {
4581
+ return sCoinTypeToName[sCoinType];
4582
+ }
4644
4583
  /**
4645
4584
  * Convert sCoin name into its underlying coin type
4646
4585
  * @param sCoinName
@@ -4666,7 +4605,7 @@ var ScallopUtils = class {
4666
4605
  * @return Market coin type.
4667
4606
  */
4668
4607
  parseMarketCoinType(coinName) {
4669
- const protocolObjectId = this.address.get("core.object") || PROTOCOL_OBJECT_ID;
4608
+ const protocolObjectId = this.address.get("core.object") ?? PROTOCOL_OBJECT_ID;
4670
4609
  const coinType = this.parseCoinType(coinName);
4671
4610
  return `${protocolObjectId}::reserve::MarketCoin<${coinType}>`;
4672
4611
  }
@@ -4675,7 +4614,7 @@ var ScallopUtils = class {
4675
4614
  const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
4676
4615
  const coinTypeMatch = coinType.match(coinTypeRegex);
4677
4616
  const isMarketCoinType = coinType.includes("reserve::MarketCoin");
4678
- coinType = coinTypeMatch?.[1] || coinType;
4617
+ coinType = coinTypeMatch?.[1] ?? coinType;
4679
4618
  const wormHoleCoinTypeMap = {
4680
4619
  [`${this.address.get("core.coins.wusdc.id") ?? wormholeCoinIds.wusdc}::coin::COIN`]: "wusdc",
4681
4620
  [`${this.address.get("core.coins.wusdt.id") ?? wormholeCoinIds.wusdt}::coin::COIN`]: "wusdt",
@@ -4753,7 +4692,7 @@ var ScallopUtils = class {
4753
4692
  * @return The selected transaction coin arguments.
4754
4693
  */
4755
4694
  async selectCoins(amount, coinType = SUI_TYPE_ARG, ownerAddress) {
4756
- ownerAddress = ownerAddress || this.suiKit.currentAddress();
4695
+ ownerAddress = ownerAddress ?? this.suiKit.currentAddress();
4757
4696
  const coins = await this.suiKit.suiInteractor.selectCoins(
4758
4697
  ownerAddress,
4759
4698
  amount,
@@ -4821,94 +4760,59 @@ var ScallopUtils = class {
4821
4760
  * @param assetCoinNames - Specific an array of support asset coin name.
4822
4761
  * @return Asset coin price.
4823
4762
  */
4824
- async getCoinPrices(assetCoinNames = [
4763
+ async getCoinPrices(_ = [
4825
4764
  .../* @__PURE__ */ new Set([...SUPPORT_POOLS, ...SUPPORT_COLLATERALS])
4826
4765
  ]) {
4827
- const coinPrices = {};
4828
- const existPricesCoinNames = [];
4829
- const lackPricesCoinNames = [];
4830
- assetCoinNames.forEach((assetCoinName) => {
4831
- if (this._priceMap.has(assetCoinName) && Date.now() - this._priceMap.get(assetCoinName).publishTime < 1e3 * 60) {
4832
- existPricesCoinNames.push(assetCoinName);
4833
- } else {
4834
- lackPricesCoinNames.push(assetCoinName);
4835
- this.cache.queryClient.invalidateQueries({
4836
- queryKey: queryKeys.oracle.getPythLatestPriceFeed(
4837
- this.address.get(`core.coins.${assetCoinName}.oracle.pyth.feed`)
4838
- )
4839
- });
4840
- }
4841
- });
4842
- if (existPricesCoinNames.length > 0) {
4843
- for (const coinName of existPricesCoinNames) {
4844
- coinPrices[coinName] = this._priceMap.get(coinName).price;
4845
- }
4846
- }
4847
- if (lackPricesCoinNames.length > 0) {
4848
- const endpoints = this.params.pythEndpoints ?? PYTH_ENDPOINTS[this.isTestnet ? "testnet" : "mainnet"];
4849
- const failedRequests = new Set(
4850
- lackPricesCoinNames
4766
+ let coinPrices = {};
4767
+ const endpoints = this.params.pythEndpoints ?? PYTH_ENDPOINTS[this.isTestnet ? "testnet" : "mainnet"];
4768
+ const failedRequests = /* @__PURE__ */ new Set([
4769
+ ...SUPPORT_POOLS,
4770
+ ...SUPPORT_COLLATERALS
4771
+ ]);
4772
+ for (const endpoint of endpoints) {
4773
+ const priceIdPairs = Array.from(failedRequests.values()).reduce(
4774
+ (acc, coinName) => {
4775
+ const priceId = this.address.get(
4776
+ `core.coins.${coinName}.oracle.pyth.feed`
4777
+ );
4778
+ acc.push([coinName, priceId]);
4779
+ return acc;
4780
+ },
4781
+ []
4851
4782
  );
4852
- for (const endpoint of endpoints) {
4853
- const priceIds = Array.from(failedRequests.values()).reduce(
4854
- (acc, coinName) => {
4855
- const priceId = this.address.get(
4856
- `core.coins.${coinName}.oracle.pyth.feed`
4857
- );
4858
- if (priceId) {
4859
- acc[coinName] = priceId;
4860
- }
4861
- return acc;
4783
+ const priceIds = priceIdPairs.map(([_2, priceId]) => priceId);
4784
+ const pythConnection = new SuiPriceServiceConnection(endpoint, {
4785
+ timeout: 2e3
4786
+ });
4787
+ try {
4788
+ const feeds = await this.cache.queryClient.fetchQuery({
4789
+ queryKey: queryKeys.oracle.getPythLatestPriceFeeds(),
4790
+ queryFn: async () => {
4791
+ return await pythConnection.getLatestPriceFeeds(priceIds);
4862
4792
  },
4863
- {}
4864
- );
4865
- await Promise.allSettled(
4866
- Object.entries(priceIds).filter(([_, priceId]) => !!priceId).map(async ([coinName, priceId]) => {
4867
- const pythConnection = new SuiPriceServiceConnection(endpoint);
4868
- try {
4869
- const feed = await this.cache.queryClient.fetchQuery({
4870
- queryKey: queryKeys.oracle.getPythLatestPriceFeed(
4871
- priceId,
4872
- endpoint
4873
- ),
4874
- queryFn: async () => {
4875
- return await pythConnection.getLatestPriceFeeds([priceId]) ?? [];
4876
- }
4877
- });
4878
- if (feed[0]) {
4879
- const data = parseDataFromPythPriceFeed(
4880
- feed[0],
4881
- this.address
4882
- );
4883
- this._priceMap.set(coinName, {
4884
- price: data.price,
4885
- publishTime: data.publishTime
4886
- });
4887
- coinPrices[coinName] = data.price;
4888
- failedRequests.delete(coinName);
4889
- }
4890
- } catch (e) {
4891
- console.warn(
4892
- `Failed to get price ${coinName} feeds with endpoint ${endpoint}: ${e}`
4893
- );
4894
- }
4895
- })
4896
- );
4897
- if (failedRequests.size === 0)
4898
- break;
4899
- }
4900
- if (failedRequests.size > 0) {
4901
- await Promise.allSettled(
4902
- Array.from(failedRequests.values()).map(async (coinName) => {
4903
- const price = await getPythPrice(this, coinName);
4904
- this._priceMap.set(coinName, {
4905
- price,
4906
- publishTime: Date.now()
4907
- });
4908
- coinPrices[coinName] = price;
4909
- })
4910
- );
4793
+ staleTime: 3e4,
4794
+ gcTime: 3e4
4795
+ });
4796
+ if (feeds) {
4797
+ feeds.forEach((feed, idx) => {
4798
+ const coinName = priceIdPairs[idx][0];
4799
+ const data = parseDataFromPythPriceFeed(feed, this.address);
4800
+ coinPrices[coinName] = data.price;
4801
+ failedRequests.delete(coinName);
4802
+ });
4803
+ }
4804
+ } catch (e) {
4805
+ console.error(e.message);
4911
4806
  }
4807
+ if (failedRequests.size === 0)
4808
+ break;
4809
+ }
4810
+ if (failedRequests.size > 0) {
4811
+ coinPrices = {
4812
+ ...coinPrices,
4813
+ ...await getPythPrices(this, Array.from(failedRequests.values()))
4814
+ };
4815
+ failedRequests.clear();
4912
4816
  }
4913
4817
  return coinPrices;
4914
4818
  }
@@ -4988,7 +4892,6 @@ var ScallopUtils = class {
4988
4892
 
4989
4893
  // src/models/scallopBuilder.ts
4990
4894
  import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui/utils";
4991
- import { SuiKit as SuiKit5 } from "@scallop-io/sui-kit";
4992
4895
 
4993
4896
  // src/builders/coreBuilder.ts
4994
4897
  import { Transaction } from "@mysten/sui/transactions";
@@ -6433,7 +6336,7 @@ var generateLoyaltyProgramQuickMethod = ({
6433
6336
  }) => {
6434
6337
  return {
6435
6338
  claimLoyaltyRevenueQuick: async (veScaKey) => {
6436
- veScaKey = veScaKey || (await builder.query.getVeScas())[0]?.keyObject;
6339
+ veScaKey = veScaKey ?? (await builder.query.getVeScas())[0]?.keyObject;
6437
6340
  const sender = requireSender(txBlock);
6438
6341
  if (!veScaKey)
6439
6342
  throw new Error(`No veScaKey found for user ${sender}`);
@@ -6597,9 +6500,6 @@ var newScallopTxBlock = (builder, initTxBlock) => {
6597
6500
  });
6598
6501
  };
6599
6502
 
6600
- // src/models/scallopQuery.ts
6601
- import { SuiKit as SuiKit4 } from "@scallop-io/sui-kit";
6602
-
6603
6503
  // src/models/scallopIndexer.ts
6604
6504
  import axios2 from "axios";
6605
6505
  import { SuiKit as SuiKit3 } from "@scallop-io/sui-kit";
@@ -6872,12 +6772,94 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
6872
6772
 
6873
6773
  // src/models/scallopQuery.ts
6874
6774
  import { normalizeSuiAddress } from "@mysten/sui/utils";
6775
+
6776
+ // src/queries/isolatedAsset.ts
6777
+ import { z as zod4 } from "zod";
6778
+ var isolatedAssetZod = zod4.object({
6779
+ dataType: zod4.string(),
6780
+ type: zod4.string(),
6781
+ hasPublicTransfer: zod4.boolean(),
6782
+ fields: zod4.object({
6783
+ id: zod4.object({
6784
+ id: zod4.string()
6785
+ }),
6786
+ name: zod4.object({
6787
+ type: zod4.string()
6788
+ }),
6789
+ value: zod4.boolean()
6790
+ })
6791
+ });
6792
+ var ISOLATED_ASSET_KEY = "0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::IsolatedAssetKey";
6793
+ var getIsolatedAssets = async (address) => {
6794
+ try {
6795
+ const marketObject = address.get("core.market");
6796
+ const isolatedAssets = [];
6797
+ if (!marketObject)
6798
+ return isolatedAssets;
6799
+ let hasNextPage = false;
6800
+ let nextCursor = null;
6801
+ const isIsolatedDynamicField = (dynamicField) => {
6802
+ return dynamicField.name.type === ISOLATED_ASSET_KEY;
6803
+ };
6804
+ do {
6805
+ const response = await address.cache.queryGetDynamicFields({
6806
+ parentId: marketObject,
6807
+ cursor: nextCursor,
6808
+ limit: 10
6809
+ });
6810
+ if (!response)
6811
+ break;
6812
+ const isolatedAssetCoinTypes = response.data.filter(isIsolatedDynamicField).map(({ name }) => `0x${name.value.type.name}`);
6813
+ isolatedAssets.push(...isolatedAssetCoinTypes);
6814
+ if (response && response.hasNextPage && response.nextCursor) {
6815
+ hasNextPage = true;
6816
+ nextCursor = response.nextCursor;
6817
+ } else {
6818
+ hasNextPage = false;
6819
+ }
6820
+ } while (hasNextPage);
6821
+ return isolatedAssets;
6822
+ } catch (e) {
6823
+ console.error(e);
6824
+ return [];
6825
+ }
6826
+ };
6827
+ var isIsolatedAsset = async (utils, coinName) => {
6828
+ try {
6829
+ const marketObject = utils.address.get("core.market");
6830
+ const cachedData = utils.address.cache.queryClient.getQueryData([
6831
+ "getDynamicFields",
6832
+ marketObject
6833
+ ]);
6834
+ if (cachedData) {
6835
+ const coinType2 = utils.parseCoinType(coinName);
6836
+ return cachedData.includes(coinType2);
6837
+ }
6838
+ const coinType = utils.parseCoinType(coinName).slice(2);
6839
+ const object = await utils.cache.queryGetDynamicFieldObject({
6840
+ parentId: marketObject,
6841
+ name: {
6842
+ type: ISOLATED_ASSET_KEY,
6843
+ value: coinType
6844
+ }
6845
+ });
6846
+ const parsedData = isolatedAssetZod.safeParse(object?.data?.content);
6847
+ if (!parsedData.success)
6848
+ return false;
6849
+ return parsedData.data.fields.value;
6850
+ } catch (e) {
6851
+ console.error(e);
6852
+ return false;
6853
+ }
6854
+ };
6855
+
6856
+ // src/models/scallopQuery.ts
6875
6857
  var ScallopQuery = class {
6876
6858
  constructor(params, instance) {
6877
6859
  this.params = params;
6878
- this.suiKit = instance?.suiKit ?? instance?.utils?.suiKit ?? new SuiKit4(params);
6860
+ this.suiKit = instance?.suiKit ?? instance?.utils?.suiKit ?? newSuiKit(params);
6879
6861
  this.walletAddress = normalizeSuiAddress(
6880
- params.walletAddress || this.suiKit.currentAddress()
6862
+ params.walletAddress ?? this.suiKit.currentAddress()
6881
6863
  );
6882
6864
  if (instance?.utils) {
6883
6865
  this.utils = instance.utils;
@@ -6891,7 +6873,7 @@ var ScallopQuery = class {
6891
6873
  );
6892
6874
  this.address = new ScallopAddress(
6893
6875
  {
6894
- id: params?.addressesId || ADDRESSES_ID,
6876
+ id: params?.addressesId ?? ADDRESSES_ID,
6895
6877
  network: params?.networkType,
6896
6878
  forceInterface: params?.forceAddressesInterface
6897
6879
  },
@@ -6941,11 +6923,10 @@ var ScallopQuery = class {
6941
6923
  * @param address - ScallopAddress instance.
6942
6924
  */
6943
6925
  async init(force = false, address) {
6944
- if (address && !this.address) {
6945
- this.address = address;
6946
- }
6947
- if (force || !this.address.getAddresses()) {
6926
+ if (force || !this.address.getAddresses() || !address?.getAddresses()) {
6948
6927
  await this.address.read();
6928
+ } else {
6929
+ this.address = address;
6949
6930
  }
6950
6931
  await this.utils.init(force, this.address);
6951
6932
  }
@@ -6955,8 +6936,8 @@ var ScallopQuery = class {
6955
6936
  * @param indexer - Whether to use indexer.
6956
6937
  * @return Market data.
6957
6938
  */
6958
- async queryMarket(indexer = false) {
6959
- return await queryMarket(this, indexer);
6939
+ async queryMarket(indexer = false, args) {
6940
+ return await queryMarket(this, indexer, args?.coinPrices);
6960
6941
  }
6961
6942
  /**
6962
6943
  * Get market pools.
@@ -6969,8 +6950,8 @@ var ScallopQuery = class {
6969
6950
  * @param indexer - Whether to use indexer.
6970
6951
  * @return Market pools data.
6971
6952
  */
6972
- async getMarketPools(poolCoinNames, indexer = false) {
6973
- return await getMarketPools(this, poolCoinNames, indexer);
6953
+ async getMarketPools(poolCoinNames, indexer = false, args) {
6954
+ return await getMarketPools(this, poolCoinNames, indexer, args?.coinPrices);
6974
6955
  }
6975
6956
  /**
6976
6957
  * Get market pool
@@ -6979,8 +6960,14 @@ var ScallopQuery = class {
6979
6960
  * @param indexer - Whether to use indexer.
6980
6961
  * @return Market pool data.
6981
6962
  */
6982
- async getMarketPool(poolCoinName, indexer = false) {
6983
- return await getMarketPool(this, poolCoinName, indexer);
6963
+ async getMarketPool(poolCoinName, indexer = false, args) {
6964
+ return await getMarketPool(
6965
+ this,
6966
+ poolCoinName,
6967
+ indexer,
6968
+ args?.marketObject,
6969
+ args?.coinPrice
6970
+ );
6984
6971
  }
6985
6972
  /**
6986
6973
  * Get market collaterals.
@@ -7090,8 +7077,14 @@ var ScallopQuery = class {
7090
7077
  * @param indexer - Whether to use indexer.
7091
7078
  * @return Spools data.
7092
7079
  */
7093
- async getSpools(stakeMarketCoinNames, indexer = false) {
7094
- return await getSpools(this, stakeMarketCoinNames, indexer);
7080
+ async getSpools(stakeMarketCoinNames, indexer = false, args) {
7081
+ return await getSpools(
7082
+ this,
7083
+ stakeMarketCoinNames,
7084
+ indexer,
7085
+ args?.marketPools,
7086
+ args?.coinPrices
7087
+ );
7095
7088
  }
7096
7089
  /**
7097
7090
  * Get spool data.
@@ -7100,8 +7093,14 @@ var ScallopQuery = class {
7100
7093
  * @param indexer - Whether to use indexer.
7101
7094
  * @return Spool data.
7102
7095
  */
7103
- async getSpool(stakeMarketCoinName, indexer = false) {
7104
- return await getSpool(this, stakeMarketCoinName, indexer);
7096
+ async getSpool(stakeMarketCoinName, indexer = false, args) {
7097
+ return await getSpool(
7098
+ this,
7099
+ stakeMarketCoinName,
7100
+ indexer,
7101
+ args?.marketPool,
7102
+ args?.coinPrices
7103
+ );
7105
7104
  }
7106
7105
  /**
7107
7106
  * Get stake accounts data for all stake pools (spools).
@@ -7201,8 +7200,13 @@ var ScallopQuery = class {
7201
7200
  * @param indexer - Whether to use indexer.
7202
7201
  * @return Borrow incentive pools data.
7203
7202
  */
7204
- async getBorrowIncentivePools(coinNames, indexer = false) {
7205
- return await getBorrowIncentivePools(this, coinNames, indexer);
7203
+ async getBorrowIncentivePools(coinNames, indexer = false, args) {
7204
+ return await getBorrowIncentivePools(
7205
+ this,
7206
+ coinNames,
7207
+ indexer,
7208
+ args?.coinPrices
7209
+ );
7206
7210
  }
7207
7211
  /**
7208
7212
  * Get borrow incentive accounts data.
@@ -7415,10 +7419,10 @@ var ScallopQuery = class {
7415
7419
  // src/models/scallopBuilder.ts
7416
7420
  var ScallopBuilder = class {
7417
7421
  constructor(params, instance) {
7418
- this.suiKit = instance?.suiKit ?? new SuiKit5(params);
7422
+ this.suiKit = instance?.suiKit ?? newSuiKit(params);
7419
7423
  this.params = params;
7420
7424
  this.walletAddress = normalizeSuiAddress2(
7421
- params?.walletAddress || this.suiKit.currentAddress()
7425
+ params?.walletAddress ?? this.suiKit.currentAddress()
7422
7426
  );
7423
7427
  if (instance?.query) {
7424
7428
  this.query = instance.query;
@@ -7433,7 +7437,7 @@ var ScallopBuilder = class {
7433
7437
  );
7434
7438
  this.address = new ScallopAddress(
7435
7439
  {
7436
- id: params?.addressesId || ADDRESSES_ID,
7440
+ id: params?.addressesId ?? ADDRESSES_ID,
7437
7441
  network: params?.networkType,
7438
7442
  forceInterface: params?.forceAddressesInterface
7439
7443
  },
@@ -7462,10 +7466,10 @@ var ScallopBuilder = class {
7462
7466
  * @param address - ScallopAddress instance.
7463
7467
  */
7464
7468
  async init(force = false, address) {
7465
- if (address && !this.address)
7466
- this.address = address;
7467
- if (force || !this.address.getAddresses()) {
7469
+ if (force || !this.address.getAddresses() || !address?.getAddresses()) {
7468
7470
  await this.address.read();
7471
+ } else {
7472
+ this.address = address;
7469
7473
  }
7470
7474
  await this.query.init(force, this.address);
7471
7475
  await this.utils.init(force, this.address);
@@ -7563,9 +7567,9 @@ var ScallopBuilder = class {
7563
7567
  var ScallopClient = class {
7564
7568
  constructor(params, instance) {
7565
7569
  this.params = params;
7566
- this.suiKit = instance?.suiKit ?? instance?.builder?.suiKit ?? new SuiKit6(params);
7570
+ this.suiKit = instance?.suiKit ?? instance?.builder?.suiKit ?? newSuiKit(params);
7567
7571
  this.walletAddress = normalizeSuiAddress3(
7568
- params?.walletAddress || this.suiKit.currentAddress()
7572
+ params?.walletAddress ?? this.suiKit.currentAddress()
7569
7573
  );
7570
7574
  if (instance?.builder) {
7571
7575
  this.builder = instance.builder;
@@ -7581,7 +7585,7 @@ var ScallopClient = class {
7581
7585
  );
7582
7586
  this.address = new ScallopAddress(
7583
7587
  {
7584
- id: params?.addressesId || ADDRESSES_ID,
7588
+ id: params?.addressesId ?? ADDRESSES_ID,
7585
7589
  network: params?.networkType,
7586
7590
  forceInterface: params?.forceAddressesInterface
7587
7591
  },
@@ -7635,7 +7639,7 @@ var ScallopClient = class {
7635
7639
  * @return Obligations data.
7636
7640
  */
7637
7641
  async getObligations(ownerAddress) {
7638
- const owner = ownerAddress || this.walletAddress;
7642
+ const owner = ownerAddress ?? this.walletAddress;
7639
7643
  return await this.query.getObligations(owner);
7640
7644
  }
7641
7645
  /**
@@ -7660,7 +7664,7 @@ var ScallopClient = class {
7660
7664
  * @return All stake accounts data.
7661
7665
  */
7662
7666
  async getAllStakeAccounts(ownerAddress) {
7663
- const owner = ownerAddress || this.walletAddress;
7667
+ const owner = ownerAddress ?? this.walletAddress;
7664
7668
  return await this.query.getAllStakeAccounts(owner);
7665
7669
  }
7666
7670
  /**
@@ -7674,7 +7678,7 @@ var ScallopClient = class {
7674
7678
  * @return Stake accounts data.
7675
7679
  */
7676
7680
  async getStakeAccounts(stakeMarketCoinName, ownerAddress) {
7677
- const owner = ownerAddress || this.walletAddress;
7681
+ const owner = ownerAddress ?? this.walletAddress;
7678
7682
  return await this.query.getStakeAccounts(stakeMarketCoinName, owner);
7679
7683
  }
7680
7684
  /**
@@ -7714,10 +7718,10 @@ var ScallopClient = class {
7714
7718
  }
7715
7719
  async depositCollateral(collateralCoinName, amount, sign = true, obligationId, walletAddress) {
7716
7720
  const txBlock = this.builder.createTxBlock();
7717
- const sender = walletAddress || this.walletAddress;
7721
+ const sender = walletAddress ?? this.walletAddress;
7718
7722
  txBlock.setSender(sender);
7719
7723
  const obligations = await this.query.getObligations(sender);
7720
- const specificObligationId = obligationId || obligations[0]?.id;
7724
+ const specificObligationId = obligationId ?? obligations[0]?.id;
7721
7725
  if (specificObligationId) {
7722
7726
  await txBlock.addCollateralQuick(
7723
7727
  amount,
@@ -7751,7 +7755,7 @@ var ScallopClient = class {
7751
7755
  */
7752
7756
  async withdrawCollateral(collateralCoinName, amount, sign = true, obligationId, obligationKey, walletAddress) {
7753
7757
  const txBlock = this.builder.createTxBlock();
7754
- const sender = walletAddress || this.walletAddress;
7758
+ const sender = walletAddress ?? this.walletAddress;
7755
7759
  txBlock.setSender(sender);
7756
7760
  const collateralCoin = await txBlock.takeCollateralQuick(
7757
7761
  amount,
@@ -7770,7 +7774,7 @@ var ScallopClient = class {
7770
7774
  }
7771
7775
  async deposit(poolCoinName, amount, sign = true, walletAddress) {
7772
7776
  const txBlock = this.builder.createTxBlock();
7773
- const sender = walletAddress || this.walletAddress;
7777
+ const sender = walletAddress ?? this.walletAddress;
7774
7778
  txBlock.setSender(sender);
7775
7779
  const sCoin = await txBlock.depositQuick(amount, poolCoinName);
7776
7780
  txBlock.transferObjects([sCoin], sender);
@@ -7784,11 +7788,11 @@ var ScallopClient = class {
7784
7788
  }
7785
7789
  async depositAndStake(stakeCoinName, amount, sign = true, stakeAccountId, walletAddress) {
7786
7790
  const txBlock = this.builder.createTxBlock();
7787
- const sender = walletAddress || this.walletAddress;
7791
+ const sender = walletAddress ?? this.walletAddress;
7788
7792
  txBlock.setSender(sender);
7789
7793
  const stakeMarketCoinName = this.utils.parseMarketCoinName(stakeCoinName);
7790
7794
  const stakeAccounts = await this.query.getStakeAccounts(stakeMarketCoinName);
7791
- const targetStakeAccount = stakeAccountId || stakeAccounts[0]?.id;
7795
+ const targetStakeAccount = stakeAccountId ?? stakeAccounts[0]?.id;
7792
7796
  const marketCoin = await txBlock.depositQuick(amount, stakeCoinName, false);
7793
7797
  if (targetStakeAccount) {
7794
7798
  await txBlock.stakeQuick(
@@ -7811,7 +7815,7 @@ var ScallopClient = class {
7811
7815
  }
7812
7816
  async withdraw(poolCoinName, amount, sign = true, walletAddress) {
7813
7817
  const txBlock = this.builder.createTxBlock();
7814
- const sender = walletAddress || this.walletAddress;
7818
+ const sender = walletAddress ?? this.walletAddress;
7815
7819
  txBlock.setSender(sender);
7816
7820
  const coin = await txBlock.withdrawQuick(amount, poolCoinName);
7817
7821
  txBlock.transferObjects([coin], sender);
@@ -7836,7 +7840,7 @@ var ScallopClient = class {
7836
7840
  */
7837
7841
  async borrow(poolCoinName, amount, sign = true, obligationId, obligationKey, walletAddress) {
7838
7842
  const txBlock = this.builder.createTxBlock();
7839
- const sender = walletAddress || this.walletAddress;
7843
+ const sender = walletAddress ?? this.walletAddress;
7840
7844
  txBlock.setSender(sender);
7841
7845
  const availableStake = SUPPORT_BORROW_INCENTIVE_POOLS.includes(poolCoinName);
7842
7846
  if (sign && availableStake) {
@@ -7872,7 +7876,7 @@ var ScallopClient = class {
7872
7876
  */
7873
7877
  async repay(poolCoinName, amount, sign = true, obligationId, obligationKey, walletAddress) {
7874
7878
  const txBlock = this.builder.createTxBlock();
7875
- const sender = walletAddress || this.walletAddress;
7879
+ const sender = walletAddress ?? this.walletAddress;
7876
7880
  txBlock.setSender(sender);
7877
7881
  const availableStake = SUPPORT_BORROW_INCENTIVE_POOLS.includes(poolCoinName);
7878
7882
  if (sign && availableStake) {
@@ -7892,7 +7896,7 @@ var ScallopClient = class {
7892
7896
  }
7893
7897
  async flashLoan(poolCoinName, amount, callback, sign = true, walletAddress) {
7894
7898
  const txBlock = this.builder.createTxBlock();
7895
- const sender = walletAddress || this.walletAddress;
7899
+ const sender = walletAddress ?? this.walletAddress;
7896
7900
  txBlock.setSender(sender);
7897
7901
  const [coin, loan] = txBlock.borrowFlashLoan(amount, poolCoinName);
7898
7902
  txBlock.repayFlashLoan(await callback(txBlock, coin), loan, poolCoinName);
@@ -7906,7 +7910,7 @@ var ScallopClient = class {
7906
7910
  }
7907
7911
  async createStakeAccount(marketCoinName, sign = true, walletAddress) {
7908
7912
  const txBlock = this.builder.createTxBlock();
7909
- const sender = walletAddress || this.walletAddress;
7913
+ const sender = walletAddress ?? this.walletAddress;
7910
7914
  txBlock.setSender(sender);
7911
7915
  const stakeAccount = txBlock.createStakeAccount(marketCoinName);
7912
7916
  txBlock.transferObjects([stakeAccount], sender);
@@ -7920,10 +7924,10 @@ var ScallopClient = class {
7920
7924
  }
7921
7925
  async stake(stakeMarketCoinName, amount, sign = true, stakeAccountId, walletAddress) {
7922
7926
  const txBlock = this.builder.createTxBlock();
7923
- const sender = walletAddress || this.walletAddress;
7927
+ const sender = walletAddress ?? this.walletAddress;
7924
7928
  txBlock.setSender(sender);
7925
7929
  const stakeAccounts = await this.query.getStakeAccounts(stakeMarketCoinName);
7926
- const targetStakeAccount = stakeAccountId || stakeAccounts[0]?.id;
7930
+ const targetStakeAccount = stakeAccountId ?? stakeAccounts[0]?.id;
7927
7931
  if (targetStakeAccount) {
7928
7932
  await txBlock.stakeQuick(amount, stakeMarketCoinName, targetStakeAccount);
7929
7933
  } else {
@@ -7941,7 +7945,7 @@ var ScallopClient = class {
7941
7945
  }
7942
7946
  async unstake(stakeMarketCoinName, amount, sign = true, stakeAccountId, walletAddress) {
7943
7947
  const txBlock = this.builder.createTxBlock();
7944
- const sender = walletAddress || this.walletAddress;
7948
+ const sender = walletAddress ?? this.walletAddress;
7945
7949
  txBlock.setSender(sender);
7946
7950
  const sCoin = await txBlock.unstakeQuick(
7947
7951
  amount,
@@ -7967,7 +7971,7 @@ var ScallopClient = class {
7967
7971
  }
7968
7972
  async unstakeAndWithdraw(stakeMarketCoinName, amount, sign = true, stakeAccountId, walletAddress) {
7969
7973
  const txBlock = this.builder.createTxBlock();
7970
- const sender = walletAddress || this.walletAddress;
7974
+ const sender = walletAddress ?? this.walletAddress;
7971
7975
  txBlock.setSender(sender);
7972
7976
  const stakeMarketCoin = await txBlock.unstakeQuick(
7973
7977
  amount,
@@ -7998,7 +8002,7 @@ var ScallopClient = class {
7998
8002
  }
7999
8003
  async claim(stakeMarketCoinName, sign = true, stakeAccountId, walletAddress) {
8000
8004
  const txBlock = this.builder.createTxBlock();
8001
- const sender = walletAddress || this.walletAddress;
8005
+ const sender = walletAddress ?? this.walletAddress;
8002
8006
  txBlock.setSender(sender);
8003
8007
  const rewardCoins = await txBlock.claimQuick(
8004
8008
  stakeMarketCoinName,
@@ -8025,7 +8029,7 @@ var ScallopClient = class {
8025
8029
  */
8026
8030
  async stakeObligation(obligationId, obligationKeyId, sign = true, walletAddress) {
8027
8031
  const txBlock = this.builder.createTxBlock();
8028
- const sender = walletAddress || this.walletAddress;
8032
+ const sender = walletAddress ?? this.walletAddress;
8029
8033
  txBlock.setSender(sender);
8030
8034
  await txBlock.stakeObligationWithVeScaQuick(obligationId, obligationKeyId);
8031
8035
  if (sign) {
@@ -8047,7 +8051,7 @@ var ScallopClient = class {
8047
8051
  */
8048
8052
  async unstakeObligation(obligationId, obligationKeyId, sign = true, walletAddress) {
8049
8053
  const txBlock = this.builder.createTxBlock();
8050
- const sender = walletAddress || this.walletAddress;
8054
+ const sender = walletAddress ?? this.walletAddress;
8051
8055
  txBlock.setSender(sender);
8052
8056
  await txBlock.unstakeObligationQuick(obligationId, obligationKeyId);
8053
8057
  if (sign) {
@@ -8070,7 +8074,7 @@ var ScallopClient = class {
8070
8074
  */
8071
8075
  async claimBorrowIncentive(coinName, obligationId, obligationKeyId, sign = true, walletAddress) {
8072
8076
  const txBlock = this.builder.createTxBlock();
8073
- const sender = walletAddress || this.walletAddress;
8077
+ const sender = walletAddress ?? this.walletAddress;
8074
8078
  txBlock.setSender(sender);
8075
8079
  const rewardCoins = [];
8076
8080
  for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
@@ -8216,7 +8220,7 @@ var ScallopClient = class {
8216
8220
  throw new Error("Only be used on the test network.");
8217
8221
  }
8218
8222
  const txBlock = this.builder.createTxBlock();
8219
- const recipient = receiveAddress || this.walletAddress;
8223
+ const recipient = receiveAddress ?? this.walletAddress;
8220
8224
  const packageId = this.address.get("core.packages.testCoin.id");
8221
8225
  const treasuryId = this.address.get(`core.coins.${assetCoinName}.treasury`);
8222
8226
  const target = `${packageId}::${assetCoinName}::mint`;
@@ -8236,7 +8240,7 @@ var ScallopClient = class {
8236
8240
  var Scallop = class {
8237
8241
  constructor(params, cacheOptions, tokenBucket, queryClient) {
8238
8242
  this.params = params;
8239
- this.suiKit = new SuiKit7(params);
8243
+ this.suiKit = newSuiKit(params);
8240
8244
  this.cache = new ScallopCache(
8241
8245
  this.suiKit,
8242
8246
  params.walletAddress,
@@ -8246,7 +8250,7 @@ var Scallop = class {
8246
8250
  );
8247
8251
  this.address = new ScallopAddress(
8248
8252
  {
8249
- id: params?.addressesId || ADDRESSES_ID,
8253
+ id: params?.addressesId ?? ADDRESSES_ID,
8250
8254
  network: params?.networkType,
8251
8255
  forceInterface: params?.forceAddressesInterface
8252
8256
  },
@@ -8396,6 +8400,7 @@ export {
8396
8400
  marketCoins,
8397
8401
  queryKeys,
8398
8402
  sCoinIds,
8403
+ sCoinTypeToName,
8399
8404
  sCoins,
8400
8405
  spoolRewardCoins,
8401
8406
  stakeMarketCoins,