@scallop-io/sui-scallop-sdk 1.4.5 → 1.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/index.d.ts +0 -1
- package/dist/constants/poolAddress.d.ts +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1644 -1478
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1848 -1678
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallop.d.ts +1 -2
- package/dist/models/scallopCache.d.ts +16 -11
- package/dist/models/scallopQuery.d.ts +67 -3
- package/dist/queries/poolAddressesQuery.d.ts +2 -0
- package/dist/queries/portfolioQuery.d.ts +60 -3
- package/dist/types/model.d.ts +8 -2
- package/dist/utils/index.d.ts +0 -2
- package/package.json +1 -1
- package/src/constants/index.ts +0 -1
- package/src/constants/poolAddress.ts +93 -25
- package/src/constants/queryKeys.ts +1 -1
- package/src/index.ts +0 -1
- package/src/models/scallop.ts +8 -13
- package/src/models/scallopAddress.ts +2 -9
- package/src/models/scallopBuilder.ts +3 -6
- package/src/models/scallopCache.ts +96 -55
- package/src/models/scallopClient.ts +3 -6
- package/src/models/scallopIndexer.ts +1 -5
- package/src/models/scallopQuery.ts +42 -16
- package/src/models/scallopUtils.ts +7 -11
- package/src/queries/coreQuery.ts +4 -4
- package/src/queries/poolAddressesQuery.ts +6 -0
- package/src/queries/portfolioQuery.ts +209 -8
- package/src/queries/sCoinQuery.ts +2 -2
- package/src/types/model.ts +13 -2
- package/src/utils/index.ts +0 -2
- package/src/utils/indexer.ts +3 -1
- package/dist/constants/tokenBucket.d.ts +0 -2
- package/dist/utils/tokenBucket.d.ts +0 -11
- package/src/constants/tokenBucket.ts +0 -2
- package/src/utils/tokenBucket.ts +0 -68
package/dist/index.js
CHANGED
|
@@ -35,8 +35,6 @@ __export(src_exports, {
|
|
|
35
35
|
BORROW_FEE_PROTOCOL_ID: () => BORROW_FEE_PROTOCOL_ID,
|
|
36
36
|
COIN_GECKGO_IDS: () => COIN_GECKGO_IDS,
|
|
37
37
|
DEFAULT_CACHE_OPTIONS: () => DEFAULT_CACHE_OPTIONS,
|
|
38
|
-
DEFAULT_INTERVAL_IN_MS: () => DEFAULT_INTERVAL_IN_MS,
|
|
39
|
-
DEFAULT_TOKENS_PER_INTERVAL: () => DEFAULT_TOKENS_PER_INTERVAL,
|
|
40
38
|
FlashLoanFeeObjectMap: () => FlashLoanFeeObjectMap,
|
|
41
39
|
IS_VE_SCA_TEST: () => IS_VE_SCA_TEST,
|
|
42
40
|
MAX_LOCK_DURATION: () => MAX_LOCK_DURATION,
|
|
@@ -71,11 +69,9 @@ __export(src_exports, {
|
|
|
71
69
|
ScallopQuery: () => ScallopQuery,
|
|
72
70
|
ScallopUtils: () => ScallopUtils,
|
|
73
71
|
TEST_ADDRESSES: () => TEST_ADDRESSES,
|
|
74
|
-
TokenBucket: () => TokenBucket,
|
|
75
72
|
UNLOCK_ROUND_DURATION: () => UNLOCK_ROUND_DURATION,
|
|
76
73
|
USE_TEST_ADDRESS: () => USE_TEST_ADDRESS,
|
|
77
74
|
assetCoins: () => assetCoins,
|
|
78
|
-
callWithRateLimit: () => callWithRateLimit,
|
|
79
75
|
coinDecimals: () => coinDecimals,
|
|
80
76
|
coinIds: () => coinIds,
|
|
81
77
|
marketCoins: () => marketCoins,
|
|
@@ -446,7 +442,9 @@ var POOL_ADDRESSES = {
|
|
|
446
442
|
spool: "0x0b5f5f413bd3799e4052c37311966c77f3a4545eb125d2e93e67a68478021918",
|
|
447
443
|
spoolReward: "0x85ed6ed72ea97c35dbf0cdc7ed6fbc48d8ec15de9b17c74bf4512df8a6d7f166",
|
|
448
444
|
sCoinTreasury: "0xbe6b63021f3d82e0e7e977cdd718ed7c019cf2eba374b7b546220402452f938e",
|
|
449
|
-
|
|
445
|
+
sCoinType: "0x854950aa624b1df59fe64e630b2ba7c550642e9342267a33061d59fb31582da5::scallop_usdc::SCALLOP_USDC",
|
|
446
|
+
coinDecimalId: "0x69b7a7c3c200439c1b5f3b19d7d495d5966d5f08de66c69276152f8db3992ec6",
|
|
447
|
+
coinType: "dba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
|
|
450
448
|
},
|
|
451
449
|
sbeth: {
|
|
452
450
|
lendingPoolAddress: "0xaa34c938e0394e5186c7dc626ad69be96af2194b23fdc6ac1c63090e399f5ba4",
|
|
@@ -461,7 +459,9 @@ var POOL_ADDRESSES = {
|
|
|
461
459
|
spool: void 0,
|
|
462
460
|
spoolReward: void 0,
|
|
463
461
|
sCoinTreasury: "0xfd0f02def6358a1f266acfa1493d4707ee8387460d434fb667d63d755ff907ed",
|
|
464
|
-
|
|
462
|
+
sCoinType: "0xb14f82d8506d139eacef109688d1b71e7236bcce9b2c0ad526abcd6aa5be7de0::scallop_sb_eth::SCALLOP_SB_ETH",
|
|
463
|
+
coinDecimalId: "0x89b04ba87f8832d4d76e17a1c9dce72eb3e64d372cf02012b8d2de5384faeef0",
|
|
464
|
+
coinType: "d0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH"
|
|
465
465
|
},
|
|
466
466
|
weth: {
|
|
467
467
|
lendingPoolAddress: "0xc8fcdff48efc265740ae0b74aae3faccae9ec00034039a113f3339798035108c",
|
|
@@ -476,7 +476,9 @@ var POOL_ADDRESSES = {
|
|
|
476
476
|
spool: "0xeec40beccb07c575bebd842eeaabb835f77cd3dab73add433477e57f583a6787",
|
|
477
477
|
spoolReward: "0x957de68a18d87817de8309b30c1ec269a4d87ae513abbeed86b5619cb9ce1077",
|
|
478
478
|
sCoinTreasury: "0x4b7f5da0e306c9d52490a0c1d4091e653d6b89778b9b4f23c877e534e4d9cd21",
|
|
479
|
-
|
|
479
|
+
sCoinType: "0x67540ceb850d418679e69f1fb6b2093d6df78a2a699ffc733f7646096d552e9b::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
|
|
480
|
+
coinDecimalId: "0x8900e4ceede3363bef086d6b50ca89d816d0e90bf6bc46efefe1f8455e08f50f",
|
|
481
|
+
coinType: "af8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN"
|
|
480
482
|
},
|
|
481
483
|
wbtc: {
|
|
482
484
|
lendingPoolAddress: "0x65cc08a5aca0a0b8d72e1993ded8d145f06dd102fd0d8f285b92934faed564ab",
|
|
@@ -491,7 +493,9 @@ var POOL_ADDRESSES = {
|
|
|
491
493
|
spool: void 0,
|
|
492
494
|
spoolReward: void 0,
|
|
493
495
|
sCoinTreasury: "0xe2883934ea42c99bc998bbe0f01dd6d27aa0e27a56455707b1b34e6a41c20baa",
|
|
494
|
-
|
|
496
|
+
sCoinType: "0x2cf76a9cf5d3337961d1154283234f94da2dcff18544dfe5cbdef65f319591b5::scallop_wormhole_btc::SCALLOP_WORMHOLE_BTC",
|
|
497
|
+
coinDecimalId: "0x5d3c6e60eeff8a05b693b481539e7847dfe33013e7070cdcb387f5c0cac05dfd",
|
|
498
|
+
coinType: "027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881::coin::COIN"
|
|
495
499
|
},
|
|
496
500
|
wusdc: {
|
|
497
501
|
lendingPoolAddress: "0x2f4df5e1368fbbdaa5c712d28b837b3d41c2d3872979ccededcdfdac55ff8a93",
|
|
@@ -506,7 +510,9 @@ var POOL_ADDRESSES = {
|
|
|
506
510
|
spool: "0x4ace6648ddc64e646ba47a957c562c32c9599b3bba8f5ac1aadb2ae23a2f8ca0",
|
|
507
511
|
spoolReward: "0xf4268cc9b9413b9bfe09e8966b8de650494c9e5784bf0930759cfef4904daff8",
|
|
508
512
|
sCoinTreasury: "0x50c5cfcbcca3aaacab0984e4d7ad9a6ad034265bebb440f0d1cd688ec20b2548",
|
|
509
|
-
|
|
513
|
+
sCoinType: "0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
514
|
+
coinDecimalId: "0x4fbf84f3029bd0c0b77164b587963be957f853eccf834a67bb9ecba6ec80f189",
|
|
515
|
+
coinType: "5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN"
|
|
510
516
|
},
|
|
511
517
|
wusdt: {
|
|
512
518
|
lendingPoolAddress: "0xfbc056f126dd35adc1f8fe985e2cedc8010e687e8e851e1c5b99fdf63cd1c879",
|
|
@@ -521,7 +527,9 @@ var POOL_ADDRESSES = {
|
|
|
521
527
|
spool: "0xcb328f7ffa7f9342ed85af3fdb2f22919e1a06dfb2f713c04c73543870d7548f",
|
|
522
528
|
spoolReward: "0x2c9f934d67a5baa586ceec2cc24163a2f049a6af3d5ba36b84d8ac40f25c4080",
|
|
523
529
|
sCoinTreasury: "0x1f02e2fed702b477732d4ad6044aaed04f2e8e586a169153694861a901379df0",
|
|
524
|
-
|
|
530
|
+
sCoinType: "0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
|
|
531
|
+
coinDecimalId: "0xfb0e3eb97dd158a5ae979dddfa24348063843c5b20eb8381dd5fa7c93699e45c",
|
|
532
|
+
coinType: "c060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN"
|
|
525
533
|
},
|
|
526
534
|
sui: {
|
|
527
535
|
lendingPoolAddress: "0x9c9077abf7a29eebce41e33addbcd6f5246a5221dd733e56ea0f00ae1b25c9e8",
|
|
@@ -536,7 +544,9 @@ var POOL_ADDRESSES = {
|
|
|
536
544
|
spool: "0x4f0ba970d3c11db05c8f40c64a15b6a33322db3702d634ced6536960ab6f3ee4",
|
|
537
545
|
spoolReward: "0x162250ef72393a4ad3d46294c4e1bdfcb03f04c869d390e7efbfc995353a7ee9",
|
|
538
546
|
sCoinTreasury: "0x5c1678c8261ac9eec024d4d630006a9f55c80dc0b1aa38a003fcb1d425818c6b",
|
|
539
|
-
|
|
547
|
+
sCoinType: "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI",
|
|
548
|
+
coinDecimalId: "0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3",
|
|
549
|
+
coinType: "0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"
|
|
540
550
|
},
|
|
541
551
|
wapt: {
|
|
542
552
|
lendingPoolAddress: "0xca8c14a24e0c32b198eaf479a3317461e3cc339097ce88eaf296a15df8dcfdf5",
|
|
@@ -551,22 +561,9 @@ var POOL_ADDRESSES = {
|
|
|
551
561
|
spool: void 0,
|
|
552
562
|
spoolReward: void 0,
|
|
553
563
|
sCoinTreasury: void 0,
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
lendingPoolAddress: "0x985682c42984cdfb03f9ff7d8923344c2fe096b1ae4b82ea17721af19d22a21f",
|
|
558
|
-
collateralPoolAddress: "0xdc1cc2c371a043ae8e3c3fe2d013c35f1346960b7dbb4c072982c5b794ed144f",
|
|
559
|
-
borrowDynamic: "0xe3f301e16d4f1273ea659dd82c5c3f124ca5a5883a5726c7ec0f77bf43b70895",
|
|
560
|
-
interestModel: "0xd95affaee077006b8dbb4b108c1b087e95fc6e5143ef0682da345d5b35bc6356",
|
|
561
|
-
riskModel: "0x8e0da6358073144ec3557400c87f04991ba3a13ca7e0d0a19daed45260b32f16",
|
|
562
|
-
borrowFeeKey: "0x604bffbc817e8e12db15f2373a9e15b2c7adbc510649cdf2cc62a594af90671c",
|
|
563
|
-
supplyLimitKey: "0xbd419b536b3f9c9d4adfc20372ca6feedc53cc31798ac860dbfc847bcf05f54b",
|
|
564
|
-
borrowLimitKey: "0x77d453c51948f32564c810bc73f9ba7abde880657b7f89e1c8a3bc28fa36ee87",
|
|
565
|
-
isolatedAssetKey: void 0,
|
|
566
|
-
spool: void 0,
|
|
567
|
-
spoolReward: void 0,
|
|
568
|
-
sCoinTreasury: "0x760fd66f5be869af4382fa32b812b3c67f0eca1bb1ed7a5578b21d56e1848819",
|
|
569
|
-
coinDecimalId: "0x4d2c39082b4477e3e79dc4562d939147ab90c42fc5f3e4acf03b94383cd69b6e"
|
|
564
|
+
sCoinType: void 0,
|
|
565
|
+
coinDecimalId: "0xc969c5251f372c0f34c32759f1d315cf1ea0ee5e4454b52aea08778eacfdd0a8",
|
|
566
|
+
coinType: "3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37::coin::COIN"
|
|
570
567
|
},
|
|
571
568
|
cetus: {
|
|
572
569
|
lendingPoolAddress: "0xc09858f60e74a1b671635bec4e8a2c84a0ff313eb87f525fba3258e88c6b6282",
|
|
@@ -581,7 +578,26 @@ var POOL_ADDRESSES = {
|
|
|
581
578
|
spool: "0xac1bb13bf4472a637c18c2415fb0e3c1227ea2bcf35242e50563c98215bd298e",
|
|
582
579
|
spoolReward: "0x6835c1224126a45086fc6406adc249e3f30df18d779ca4f4e570e38716a17f3f",
|
|
583
580
|
sCoinTreasury: "0xa283c63488773c916cb3d6c64109536160d5eb496caddc721eb39aad2977d735",
|
|
584
|
-
|
|
581
|
+
sCoinType: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
|
|
582
|
+
coinDecimalId: "0x4c0dce55eff2db5419bbd2d239d1aa22b4a400c01bbb648b058a9883989025da",
|
|
583
|
+
coinType: "06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"
|
|
584
|
+
},
|
|
585
|
+
wsol: {
|
|
586
|
+
lendingPoolAddress: "0x985682c42984cdfb03f9ff7d8923344c2fe096b1ae4b82ea17721af19d22a21f",
|
|
587
|
+
collateralPoolAddress: "0xdc1cc2c371a043ae8e3c3fe2d013c35f1346960b7dbb4c072982c5b794ed144f",
|
|
588
|
+
borrowDynamic: "0xe3f301e16d4f1273ea659dd82c5c3f124ca5a5883a5726c7ec0f77bf43b70895",
|
|
589
|
+
interestModel: "0xd95affaee077006b8dbb4b108c1b087e95fc6e5143ef0682da345d5b35bc6356",
|
|
590
|
+
riskModel: "0x8e0da6358073144ec3557400c87f04991ba3a13ca7e0d0a19daed45260b32f16",
|
|
591
|
+
borrowFeeKey: "0x604bffbc817e8e12db15f2373a9e15b2c7adbc510649cdf2cc62a594af90671c",
|
|
592
|
+
supplyLimitKey: "0xbd419b536b3f9c9d4adfc20372ca6feedc53cc31798ac860dbfc847bcf05f54b",
|
|
593
|
+
borrowLimitKey: "0x77d453c51948f32564c810bc73f9ba7abde880657b7f89e1c8a3bc28fa36ee87",
|
|
594
|
+
isolatedAssetKey: void 0,
|
|
595
|
+
spool: void 0,
|
|
596
|
+
spoolReward: void 0,
|
|
597
|
+
sCoinTreasury: "0x760fd66f5be869af4382fa32b812b3c67f0eca1bb1ed7a5578b21d56e1848819",
|
|
598
|
+
sCoinType: "0x1392650f2eca9e3f6ffae3ff89e42a3590d7102b80e2b430f674730bc30d3259::scallop_wormhole_sol::SCALLOP_WORMHOLE_SOL",
|
|
599
|
+
coinDecimalId: "0x4d2c39082b4477e3e79dc4562d939147ab90c42fc5f3e4acf03b94383cd69b6e",
|
|
600
|
+
coinType: "b7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8::coin::COIN"
|
|
585
601
|
},
|
|
586
602
|
afsui: {
|
|
587
603
|
lendingPoolAddress: "0x9b942a24ce390b7f5016d34a0217057bf9487b92aa6d7cc9894271dbbe62471a",
|
|
@@ -596,7 +612,9 @@ var POOL_ADDRESSES = {
|
|
|
596
612
|
spool: "0xeedf438abcaa6ce4d9625ffca110920592d5867e4c5637d84ad9f466c4feb800",
|
|
597
613
|
spoolReward: "0x89255a2f86ed7fbfef35ab8b7be48cc7667015975be2685dd9a55a9a64baf76e",
|
|
598
614
|
sCoinTreasury: "0x55f4dfe9e40bc4cc11c70fcb1f3daefa2bdc330567c58d4f0792fbd9f9175a62",
|
|
599
|
-
|
|
615
|
+
sCoinType: "0x00671b1fa2a124f5be8bdae8b91ee711462c5d9e31bda232e70fd9607b523c88::scallop_af_sui::SCALLOP_AF_SUI",
|
|
616
|
+
coinDecimalId: "0x2f9217f533e51334873a39b8026a4aa6919497b47f49d0986a4f1aec66f8a34d",
|
|
617
|
+
coinType: "f325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"
|
|
600
618
|
},
|
|
601
619
|
hasui: {
|
|
602
620
|
lendingPoolAddress: "0x7ebc607f6bdeb659fb6506cb91c5cc1d47bb365cfd5d2e637ea765346ec84ed4",
|
|
@@ -611,7 +629,9 @@ var POOL_ADDRESSES = {
|
|
|
611
629
|
spool: "0xa6148bc1b623e936d39a952ceb5bea79e8b37228a8f595067bf1852efd3c34aa",
|
|
612
630
|
spoolReward: "0x6f3563644d3e2ef13176dbf9d865bd93479df60ccbe07b7e66db57f6309f5a66",
|
|
613
631
|
sCoinTreasury: "0x404ccc1404d74a90eb6f9c9d4b6cda6d417fb03189f80d9070a35e5dab1df0f5",
|
|
614
|
-
|
|
632
|
+
sCoinType: "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI",
|
|
633
|
+
coinDecimalId: "0x2c5f33af93f6511df699aaaa5822d823aac6ed99d4a0de2a4a50b3afa0172e24",
|
|
634
|
+
coinType: "bde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
615
635
|
},
|
|
616
636
|
vsui: {
|
|
617
637
|
lendingPoolAddress: "0xda9257c0731d8822e8a438ebced13415850d705b779c79958dcf2aeb21fcb43d",
|
|
@@ -626,7 +646,9 @@ var POOL_ADDRESSES = {
|
|
|
626
646
|
spool: "0x69ce8e537e750a95381e6040794afa5ab1758353a1a2e1de7760391b01f91670",
|
|
627
647
|
spoolReward: "0xbca914adce058ad0902c7f3cfcd698392a475f00dcfdc3f76001d0370b98777a",
|
|
628
648
|
sCoinTreasury: "0xc06688ee1af25abc286ffb1d18ce273d1d5907cd1064c25f4e8ca61ea989c1d1",
|
|
629
|
-
|
|
649
|
+
sCoinType: "0xe1a1cc6bcf0001a015eab84bcc6713393ce20535f55b8b6f35c142e057a25fbe::scallop_v_sui::SCALLOP_V_SUI",
|
|
650
|
+
coinDecimalId: "0xabd84a23467b33854ab25cf862006fd97479f8f6f53e50fe732c43a274d939bd",
|
|
651
|
+
coinType: "549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
|
|
630
652
|
},
|
|
631
653
|
sca: {
|
|
632
654
|
lendingPoolAddress: "0x6fc7d4211fc7018b6c75e7b908b88f2e0536443239804a3d32af547637bd28d7",
|
|
@@ -641,7 +663,9 @@ var POOL_ADDRESSES = {
|
|
|
641
663
|
spool: void 0,
|
|
642
664
|
spoolReward: void 0,
|
|
643
665
|
sCoinTreasury: "0xe04bfc95e00252bd654ee13c08edef9ac5e4b6ae4074e8390db39e9a0109c529",
|
|
644
|
-
|
|
666
|
+
sCoinType: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
|
|
667
|
+
coinDecimalId: "0x5d26a1e9a55c88147ac870bfa31b729d7f49f8804b8b3adfdf3582d301cca844",
|
|
668
|
+
coinType: "7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA"
|
|
645
669
|
},
|
|
646
670
|
fud: {
|
|
647
671
|
lendingPoolAddress: "0xefed2cbe76b344792ac724523c8b2236740d1cea2100d46a0ed0dc760c7f4231",
|
|
@@ -656,7 +680,9 @@ var POOL_ADDRESSES = {
|
|
|
656
680
|
spool: void 0,
|
|
657
681
|
spoolReward: void 0,
|
|
658
682
|
sCoinTreasury: "0xf25212f11d182decff7a86165699a73e3d5787aced203ca539f43cfbc10db867",
|
|
659
|
-
|
|
683
|
+
sCoinType: "0xe56d5167f427cbe597da9e8150ef5c337839aaf46891d62468dcf80bdd8e10d1::scallop_fud::SCALLOP_FUD",
|
|
684
|
+
coinDecimalId: "0x01087411ef48aaac1eb6e24803213e3a60a03b147dac930e5e341f17a85e524e",
|
|
685
|
+
coinType: "76cb819b01abed502bee8a702b4c2d547532c12f25001c9dea795a5e631c26f1::fud::FUD"
|
|
660
686
|
},
|
|
661
687
|
deep: {
|
|
662
688
|
lendingPoolAddress: "0xf4a67ffb43da1e1c61c049f188f19463ea8dbbf2d5ef4722d6df854ff1b1cc03",
|
|
@@ -671,7 +697,9 @@ var POOL_ADDRESSES = {
|
|
|
671
697
|
spool: void 0,
|
|
672
698
|
spoolReward: void 0,
|
|
673
699
|
sCoinTreasury: "0xc63838fabe37b25ad897392d89876d920f5e0c6a406bf3abcb84753d2829bc88",
|
|
674
|
-
|
|
700
|
+
sCoinType: "0xeb7a05a3224837c5e5503575aed0be73c091d1ce5e43aa3c3e716e0ae614608f::scallop_deep::SCALLOP_DEEP",
|
|
701
|
+
coinDecimalId: "0x6e60b051a08fa836f5a7acd7c464c8d9825bc29c44657fe170fe9b8e1e4770c0",
|
|
702
|
+
coinType: "deeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP"
|
|
675
703
|
},
|
|
676
704
|
fdusd: {
|
|
677
705
|
lendingPoolAddress: "0x4f46051a01f05c3ad9aecf29a771aad5c884e1a1888e08d7709085e3a095bc9c",
|
|
@@ -686,7 +714,9 @@ var POOL_ADDRESSES = {
|
|
|
686
714
|
spool: void 0,
|
|
687
715
|
spoolReward: void 0,
|
|
688
716
|
sCoinTreasury: "0xdad9bc6293e694f67a5274ea51b596e0bdabfafc585ae6d7e82888e65f1a03e0",
|
|
689
|
-
|
|
717
|
+
sCoinType: "0x6711551c1e7652a270d9fbf0eee25d99594c157cde3cb5fbb49035eb59b1b001::scallop_fdusd::SCALLOP_FDUSD",
|
|
718
|
+
coinDecimalId: "0xdebee5265a67c186ed87fe93303d33dfe1de53e3b4fd7d9329c2852860acd3e7",
|
|
719
|
+
coinType: "f16e6b723f242ec745dfd7634ad072c42d5c1d9ac9d62a39c381303eaa57693a::fdusd::FDUSD"
|
|
690
720
|
}
|
|
691
721
|
};
|
|
692
722
|
|
|
@@ -749,7 +779,7 @@ var queryKeys = {
|
|
|
749
779
|
{
|
|
750
780
|
walletAddress,
|
|
751
781
|
options,
|
|
752
|
-
objectIds: JSON.stringify(objectIds ??
|
|
782
|
+
objectIds: JSON.stringify(objectIds ?? void 0)
|
|
753
783
|
}
|
|
754
784
|
],
|
|
755
785
|
getOwnedObjects: (input) => [
|
|
@@ -1294,10 +1324,6 @@ var TEST_ADDRESSES = {
|
|
|
1294
1324
|
}
|
|
1295
1325
|
};
|
|
1296
1326
|
|
|
1297
|
-
// src/constants/tokenBucket.ts
|
|
1298
|
-
var DEFAULT_TOKENS_PER_INTERVAL = 10;
|
|
1299
|
-
var DEFAULT_INTERVAL_IN_MS = 250;
|
|
1300
|
-
|
|
1301
1327
|
// src/constants/vesca.ts
|
|
1302
1328
|
var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
|
|
1303
1329
|
var MAX_LOCK_ROUNDS = 1460;
|
|
@@ -1305,988 +1331,400 @@ var MAX_LOCK_DURATION = MAX_LOCK_ROUNDS * UNLOCK_ROUND_DURATION;
|
|
|
1305
1331
|
var MIN_INITIAL_LOCK_AMOUNT = 1e10;
|
|
1306
1332
|
var MIN_TOP_UP_AMOUNT = 1e9;
|
|
1307
1333
|
|
|
1308
|
-
// src/models/scallopAddress.ts
|
|
1309
|
-
var import_sui_kit2 = require("@scallop-io/sui-kit");
|
|
1310
|
-
|
|
1311
1334
|
// src/models/scallopCache.ts
|
|
1312
1335
|
var import_query_core = require("@tanstack/query-core");
|
|
1313
|
-
var
|
|
1336
|
+
var import_sui_kit2 = require("@scallop-io/sui-kit");
|
|
1314
1337
|
|
|
1315
|
-
// src/
|
|
1316
|
-
var
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1338
|
+
// src/models/suiKit.ts
|
|
1339
|
+
var import_sui_kit = require("@scallop-io/sui-kit");
|
|
1340
|
+
var newSuiKit = (params) => {
|
|
1341
|
+
return new import_sui_kit.SuiKit({
|
|
1342
|
+
...params,
|
|
1343
|
+
fullnodeUrls: Array.from(
|
|
1344
|
+
/* @__PURE__ */ new Set([...params.fullnodeUrls ?? [], ...RPC_PROVIDERS])
|
|
1345
|
+
)
|
|
1346
|
+
});
|
|
1322
1347
|
};
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1348
|
+
|
|
1349
|
+
// src/models/scallopCache.ts
|
|
1350
|
+
var DEFAULT_TOKENS_PER_INTERVAL = 10;
|
|
1351
|
+
var DEFAULT_INTERVAL_IN_MS = 250;
|
|
1352
|
+
var ScallopCache = class {
|
|
1353
|
+
constructor(params, instance) {
|
|
1354
|
+
this.tokensPerInterval = DEFAULT_TOKENS_PER_INTERVAL;
|
|
1355
|
+
this.interval = DEFAULT_INTERVAL_IN_MS;
|
|
1356
|
+
this.params = params;
|
|
1357
|
+
this.suiKit = instance?.suiKit ?? newSuiKit(params);
|
|
1358
|
+
this.queryClient = instance?.queryClient ?? new import_query_core.QueryClient(params?.cacheOptions ?? DEFAULT_CACHE_OPTIONS);
|
|
1359
|
+
this.tokens = this.tokensPerInterval;
|
|
1360
|
+
this.lastRefill = Date.now();
|
|
1361
|
+
this.walletAddress = params.walletAddress ?? this.suiKit.currentAddress();
|
|
1326
1362
|
}
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
if (prevUnlockAtInMillisTimestamp <= (/* @__PURE__ */ new Date()).getTime()) {
|
|
1330
|
-
throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
|
|
1363
|
+
get client() {
|
|
1364
|
+
return this.suiKit.client();
|
|
1331
1365
|
}
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
throw new Error("Minimum lock period is 1 day");
|
|
1366
|
+
refill() {
|
|
1367
|
+
const now = Date.now();
|
|
1368
|
+
const elapsed = now - this.lastRefill;
|
|
1369
|
+
if (elapsed >= this.interval) {
|
|
1370
|
+
const tokensToAdd = Math.floor(elapsed / this.interval) * this.tokensPerInterval;
|
|
1371
|
+
this.tokens = Math.min(this.tokens + tokensToAdd, this.tokensPerInterval);
|
|
1372
|
+
this.lastRefill += Math.floor(elapsed / this.interval) * this.interval;
|
|
1373
|
+
}
|
|
1341
1374
|
}
|
|
1342
|
-
|
|
1343
|
-
(
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1375
|
+
removeTokens(count) {
|
|
1376
|
+
this.refill();
|
|
1377
|
+
if (this.tokens >= count) {
|
|
1378
|
+
this.tokens -= count;
|
|
1379
|
+
return true;
|
|
1380
|
+
}
|
|
1381
|
+
return false;
|
|
1349
1382
|
}
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1383
|
+
async callWithRateLimit(fn, maxRetries = 15, backoffFactor = 1.25) {
|
|
1384
|
+
let retries = 0;
|
|
1385
|
+
const tryRequest = async () => {
|
|
1386
|
+
if (this.removeTokens(1)) {
|
|
1387
|
+
const result = await fn();
|
|
1388
|
+
return result;
|
|
1389
|
+
} else if (retries < maxRetries) {
|
|
1390
|
+
retries++;
|
|
1391
|
+
const delay = this.interval * Math.pow(backoffFactor, retries);
|
|
1392
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1393
|
+
return tryRequest();
|
|
1394
|
+
} else {
|
|
1395
|
+
console.error("Maximum retries reached");
|
|
1396
|
+
return null;
|
|
1359
1397
|
}
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1398
|
+
};
|
|
1399
|
+
return tryRequest();
|
|
1400
|
+
}
|
|
1401
|
+
/**
|
|
1402
|
+
* @description Invalidate cache based on the refetchType parameter
|
|
1403
|
+
* @param refetchType Determines the type of queries to be refetched. Defaults to `active`.
|
|
1404
|
+
*
|
|
1405
|
+
* - `active`: Only queries that match the refetch predicate and are actively being rendered via useQuery and related functions will be refetched in the background.
|
|
1406
|
+
* - `inactive`: Only queries that match the refetch predicate and are NOT actively being rendered via useQuery and related functions will be refetched in the background.
|
|
1407
|
+
* - `all`: All queries that match the refetch predicate will be refetched in the background.
|
|
1408
|
+
* - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
|
|
1409
|
+
*/
|
|
1410
|
+
// public async invalidateAllCache() {
|
|
1411
|
+
// return Object.values(queryKeys.rpc).map((t) =>
|
|
1412
|
+
// this.queryClient.invalidateQueries({
|
|
1413
|
+
// queryKey: t(),
|
|
1414
|
+
// type: 'all',
|
|
1415
|
+
// })
|
|
1416
|
+
// );
|
|
1417
|
+
// }
|
|
1418
|
+
retryFn(errCount, e) {
|
|
1419
|
+
if (errCount === 5)
|
|
1420
|
+
return false;
|
|
1421
|
+
if (e.status === 429)
|
|
1422
|
+
return true;
|
|
1423
|
+
return false;
|
|
1424
|
+
}
|
|
1425
|
+
/**
|
|
1426
|
+
* @description Provides cache for inspectTxn of the SuiKit.
|
|
1427
|
+
* @param QueryInspectTxnParams
|
|
1428
|
+
* @param txBlock
|
|
1429
|
+
* @returns Promise<DevInspectResults>
|
|
1430
|
+
*/
|
|
1431
|
+
async queryInspectTxn({
|
|
1432
|
+
queryTarget,
|
|
1433
|
+
args,
|
|
1434
|
+
typeArgs
|
|
1435
|
+
}) {
|
|
1436
|
+
const txBlock = new import_sui_kit2.SuiTxBlock();
|
|
1437
|
+
const resolvedQueryTarget = await this.queryGetNormalizedMoveFunction(queryTarget);
|
|
1438
|
+
if (!resolvedQueryTarget)
|
|
1439
|
+
throw new Error("Invalid query target");
|
|
1440
|
+
const { parameters } = resolvedQueryTarget;
|
|
1441
|
+
const resolvedArgs = await Promise.all(
|
|
1442
|
+
(args ?? []).map(async (arg, idx) => {
|
|
1443
|
+
if (typeof arg !== "string")
|
|
1444
|
+
return arg;
|
|
1445
|
+
const cachedData = (await this.queryGetObject(arg))?.data;
|
|
1446
|
+
if (!cachedData)
|
|
1447
|
+
return arg;
|
|
1448
|
+
const owner = cachedData.owner;
|
|
1449
|
+
if (!owner || typeof owner !== "object" || !("Shared" in owner))
|
|
1450
|
+
return {
|
|
1451
|
+
objectId: cachedData.objectId,
|
|
1452
|
+
version: cachedData.version,
|
|
1453
|
+
digest: cachedData.digest
|
|
1454
|
+
};
|
|
1455
|
+
const parameter = parameters[idx];
|
|
1456
|
+
if (typeof parameter !== "object" || !("MutableReference" in parameter || "Reference" in parameter))
|
|
1457
|
+
return arg;
|
|
1458
|
+
return {
|
|
1459
|
+
objectId: cachedData.objectId,
|
|
1460
|
+
initialSharedVersion: owner.Shared.initial_shared_version,
|
|
1461
|
+
mutable: "MutableReference" in parameter
|
|
1462
|
+
};
|
|
1463
|
+
})
|
|
1464
|
+
);
|
|
1465
|
+
txBlock.moveCall(queryTarget, resolvedArgs, typeArgs);
|
|
1466
|
+
const query = await this.queryClient.fetchQuery({
|
|
1467
|
+
retry: this.retryFn,
|
|
1468
|
+
retryDelay: 1e3,
|
|
1469
|
+
queryKey: queryKeys.rpc.getInspectTxn(queryTarget, args, typeArgs),
|
|
1470
|
+
queryFn: async () => {
|
|
1471
|
+
return await this.callWithRateLimit(
|
|
1472
|
+
async () => await this.suiKit.inspectTxn(txBlock)
|
|
1363
1473
|
);
|
|
1364
1474
|
}
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1475
|
+
});
|
|
1476
|
+
return query;
|
|
1477
|
+
}
|
|
1478
|
+
async queryGetNormalizedMoveFunction(target) {
|
|
1479
|
+
const { address, module: module2, name } = (0, import_sui_kit2.parseStructTag)(target);
|
|
1480
|
+
return this.queryClient.fetchQuery({
|
|
1481
|
+
queryKey: queryKeys.rpc.getNormalizedMoveFunction(target),
|
|
1482
|
+
queryFn: async () => {
|
|
1483
|
+
return await this.callWithRateLimit(
|
|
1484
|
+
async () => await this.suiKit.client().getNormalizedMoveFunction({
|
|
1485
|
+
package: address,
|
|
1486
|
+
module: module2,
|
|
1487
|
+
function: name
|
|
1488
|
+
})
|
|
1369
1489
|
);
|
|
1370
1490
|
}
|
|
1371
|
-
}
|
|
1372
|
-
throw new Error(
|
|
1373
|
-
`SCA amount and lock period is required for ${isLockExpired ? "renewing expired veSca" : "initial lock"}`
|
|
1374
|
-
);
|
|
1375
|
-
}
|
|
1376
|
-
} else {
|
|
1377
|
-
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
1378
|
-
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
1379
|
-
if (typeof scaAmountOrCoin === "number" && scaAmountOrCoin < MIN_TOP_UP_AMOUNT) {
|
|
1380
|
-
throw new Error("Minimum top up amount is 1 SCA");
|
|
1381
|
-
}
|
|
1382
|
-
if (newUnlockAtInSecondTimestamp && lockPeriodInDays) {
|
|
1383
|
-
checkExtendLockPeriod(
|
|
1384
|
-
lockPeriodInDays,
|
|
1385
|
-
newUnlockAtInSecondTimestamp,
|
|
1386
|
-
prevUnlockAtInMillisTimestamp
|
|
1387
|
-
);
|
|
1388
|
-
}
|
|
1389
|
-
}
|
|
1390
|
-
};
|
|
1391
|
-
var checkExtendLockAmount = (scaAmount, prevUnlockAtInMillisTimestamp) => {
|
|
1392
|
-
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
1393
|
-
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
1394
|
-
if (scaAmount < MIN_TOP_UP_AMOUNT) {
|
|
1395
|
-
throw new Error("Minimum top up amount is 1 SCA");
|
|
1396
|
-
}
|
|
1397
|
-
const isInitialLock = !prevUnlockAtInMillisTimestamp;
|
|
1398
|
-
const isLockExpired = !isInitialLock && prevUnlockAtInMillisTimestamp <= (/* @__PURE__ */ new Date()).getTime();
|
|
1399
|
-
if (isLockExpired) {
|
|
1400
|
-
throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
|
|
1491
|
+
});
|
|
1401
1492
|
}
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1493
|
+
/**
|
|
1494
|
+
* @description Provides cache for getObject of the SuiKit.
|
|
1495
|
+
* @param objectId
|
|
1496
|
+
* @param QueryObjectParams
|
|
1497
|
+
* @returns Promise<SuiObjectResponse>
|
|
1498
|
+
*/
|
|
1499
|
+
async queryGetObject(objectId, options) {
|
|
1500
|
+
options = {
|
|
1501
|
+
...options,
|
|
1502
|
+
showOwner: true,
|
|
1503
|
+
showContent: true
|
|
1504
|
+
};
|
|
1505
|
+
return this.queryClient.fetchQuery({
|
|
1506
|
+
retry: this.retryFn,
|
|
1507
|
+
retryDelay: 1e3,
|
|
1508
|
+
queryKey: queryKeys.rpc.getObject(objectId, options),
|
|
1509
|
+
queryFn: async () => {
|
|
1510
|
+
return await this.callWithRateLimit(
|
|
1511
|
+
async () => await this.client.getObject({
|
|
1512
|
+
id: objectId,
|
|
1513
|
+
options
|
|
1514
|
+
})
|
|
1515
|
+
);
|
|
1516
|
+
}
|
|
1517
|
+
});
|
|
1406
1518
|
}
|
|
1407
|
-
|
|
1408
|
-
|
|
1519
|
+
/**
|
|
1520
|
+
* @description Provides cache for getObjects of the SuiKit.
|
|
1521
|
+
* @param objectIds
|
|
1522
|
+
* @returns Promise<SuiObjectData[]>
|
|
1523
|
+
*/
|
|
1524
|
+
async queryGetObjects(objectIds, options = {
|
|
1525
|
+
showContent: true
|
|
1526
|
+
}) {
|
|
1527
|
+
if (objectIds.length === 0)
|
|
1528
|
+
return [];
|
|
1529
|
+
return this.queryClient.fetchQuery({
|
|
1530
|
+
retry: this.retryFn,
|
|
1531
|
+
retryDelay: 1e3,
|
|
1532
|
+
queryKey: queryKeys.rpc.getObjects(
|
|
1533
|
+
objectIds,
|
|
1534
|
+
this.walletAddress,
|
|
1535
|
+
options
|
|
1536
|
+
),
|
|
1537
|
+
queryFn: async () => {
|
|
1538
|
+
const results = await this.callWithRateLimit(
|
|
1539
|
+
async () => await this.suiKit.getObjects(objectIds, options)
|
|
1540
|
+
);
|
|
1541
|
+
if (results) {
|
|
1542
|
+
results.forEach((result) => {
|
|
1543
|
+
this.queryClient.setQueriesData(
|
|
1544
|
+
{
|
|
1545
|
+
exact: false,
|
|
1546
|
+
queryKey: queryKeys.rpc.getObject(result.objectId, options)
|
|
1547
|
+
},
|
|
1548
|
+
{
|
|
1549
|
+
data: result,
|
|
1550
|
+
error: null
|
|
1551
|
+
},
|
|
1552
|
+
{
|
|
1553
|
+
updatedAt: Date.now()
|
|
1554
|
+
}
|
|
1555
|
+
);
|
|
1556
|
+
});
|
|
1557
|
+
}
|
|
1558
|
+
return results;
|
|
1559
|
+
}
|
|
1560
|
+
});
|
|
1409
1561
|
}
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1562
|
+
/**
|
|
1563
|
+
* @description Provides cache for getOwnedObjects of the SuiKit.
|
|
1564
|
+
* @param input
|
|
1565
|
+
* @returns Promise<PaginatedObjectsResponse>
|
|
1566
|
+
*/
|
|
1567
|
+
async queryGetOwnedObjects(input) {
|
|
1568
|
+
return this.queryClient.fetchQuery({
|
|
1569
|
+
retry: this.retryFn,
|
|
1570
|
+
retryDelay: 1e3,
|
|
1571
|
+
queryKey: queryKeys.rpc.getOwnedObjects(input),
|
|
1572
|
+
queryFn: async () => {
|
|
1573
|
+
const results = await this.callWithRateLimit(
|
|
1574
|
+
async () => await this.client.getOwnedObjects(input)
|
|
1575
|
+
);
|
|
1576
|
+
if (results && results.data.length > 0) {
|
|
1577
|
+
results.data.filter(
|
|
1578
|
+
(result) => !!result.data
|
|
1579
|
+
).forEach((result) => {
|
|
1580
|
+
this.queryClient.setQueriesData(
|
|
1581
|
+
{
|
|
1582
|
+
exact: false,
|
|
1583
|
+
queryKey: queryKeys.rpc.getObject(
|
|
1584
|
+
result.data.objectId,
|
|
1585
|
+
input.options ?? {}
|
|
1586
|
+
)
|
|
1587
|
+
},
|
|
1588
|
+
{
|
|
1589
|
+
data: result.data,
|
|
1590
|
+
error: null
|
|
1591
|
+
},
|
|
1592
|
+
{
|
|
1593
|
+
updatedAt: Date.now()
|
|
1594
|
+
}
|
|
1595
|
+
);
|
|
1596
|
+
});
|
|
1597
|
+
}
|
|
1598
|
+
return results;
|
|
1599
|
+
}
|
|
1600
|
+
});
|
|
1601
|
+
}
|
|
1602
|
+
async queryGetDynamicFields(input) {
|
|
1603
|
+
return this.queryClient.fetchQuery({
|
|
1604
|
+
retry: this.retryFn,
|
|
1605
|
+
retryDelay: 1e3,
|
|
1606
|
+
queryKey: queryKeys.rpc.getDynamicFields(input),
|
|
1607
|
+
queryFn: async () => {
|
|
1608
|
+
return await this.callWithRateLimit(
|
|
1609
|
+
async () => await this.client.getDynamicFields(input)
|
|
1610
|
+
);
|
|
1611
|
+
}
|
|
1612
|
+
});
|
|
1613
|
+
}
|
|
1614
|
+
async queryGetDynamicFieldObject(input) {
|
|
1615
|
+
return this.queryClient.fetchQuery({
|
|
1616
|
+
retry: this.retryFn,
|
|
1617
|
+
retryDelay: (attemptIndex) => Math.min(1e3 * attemptIndex, 8e3),
|
|
1618
|
+
queryKey: queryKeys.rpc.getDynamicFieldObject(input),
|
|
1619
|
+
queryFn: async () => {
|
|
1620
|
+
const result = await this.callWithRateLimit(
|
|
1621
|
+
() => this.client.getDynamicFieldObject(input)
|
|
1622
|
+
);
|
|
1623
|
+
if (result?.data) {
|
|
1624
|
+
this.queryClient.setQueriesData(
|
|
1625
|
+
{
|
|
1626
|
+
exact: false,
|
|
1627
|
+
queryKey: queryKeys.rpc.getObject(result?.data.objectId, {
|
|
1628
|
+
showContent: true,
|
|
1629
|
+
showOwner: true
|
|
1630
|
+
})
|
|
1631
|
+
},
|
|
1632
|
+
{
|
|
1633
|
+
data: result.data,
|
|
1634
|
+
error: null
|
|
1635
|
+
},
|
|
1636
|
+
{
|
|
1637
|
+
updatedAt: Date.now()
|
|
1638
|
+
}
|
|
1639
|
+
);
|
|
1640
|
+
}
|
|
1641
|
+
return result;
|
|
1642
|
+
}
|
|
1643
|
+
});
|
|
1644
|
+
}
|
|
1645
|
+
async queryGetAllCoinBalances(owner) {
|
|
1646
|
+
return this.queryClient.fetchQuery({
|
|
1647
|
+
retry: this.retryFn,
|
|
1648
|
+
retryDelay: 1e3,
|
|
1649
|
+
queryKey: queryKeys.rpc.getAllCoinBalances(owner),
|
|
1650
|
+
queryFn: async () => {
|
|
1651
|
+
const allBalances = await this.callWithRateLimit(
|
|
1652
|
+
async () => await this.client.getAllBalances({ owner })
|
|
1653
|
+
);
|
|
1654
|
+
if (!allBalances)
|
|
1655
|
+
return {};
|
|
1656
|
+
const balances = allBalances.reduce(
|
|
1657
|
+
(acc, coinBalance) => {
|
|
1658
|
+
if (coinBalance.totalBalance !== "0") {
|
|
1659
|
+
acc[(0, import_sui_kit2.normalizeStructTag)(coinBalance.coinType)] = coinBalance;
|
|
1660
|
+
}
|
|
1661
|
+
return acc;
|
|
1662
|
+
},
|
|
1663
|
+
{}
|
|
1664
|
+
);
|
|
1665
|
+
return balances;
|
|
1666
|
+
}
|
|
1667
|
+
});
|
|
1668
|
+
}
|
|
1669
|
+
async queryGetCoinBalance(input) {
|
|
1670
|
+
if (!input.coinType)
|
|
1671
|
+
return null;
|
|
1672
|
+
return (await this.queryGetAllCoinBalances(input.owner) ?? {})[(0, import_sui_kit2.normalizeStructTag)(input.coinType)] ?? "0";
|
|
1415
1673
|
}
|
|
1416
1674
|
};
|
|
1417
1675
|
|
|
1418
|
-
// src/
|
|
1419
|
-
var
|
|
1420
|
-
var
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
midKink: Number(originMarketPoolData.midKink.value) / 2 ** 32,
|
|
1443
|
-
minBorrowAmount: Number(originMarketPoolData.minBorrowAmount),
|
|
1444
|
-
isIsolated: originMarketPoolData.isIsolated,
|
|
1445
|
-
supplyLimit: Number(originMarketPoolData.supplyLimit),
|
|
1446
|
-
borrowLimit: Number(originMarketPoolData.borrowLimit)
|
|
1447
|
-
};
|
|
1448
|
-
};
|
|
1449
|
-
var calculateMarketPoolData = (utils, parsedMarketPoolData) => {
|
|
1450
|
-
const poolCoinName = utils.parseCoinNameFromType(
|
|
1451
|
-
parsedMarketPoolData.coinType
|
|
1452
|
-
);
|
|
1453
|
-
const coinDecimal = utils.getCoinDecimal(poolCoinName);
|
|
1454
|
-
const borrowYearFactor = 24 * 365 * 3600;
|
|
1455
|
-
const baseBorrowApr = parsedMarketPoolData.baseBorrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
1456
|
-
const borrowAprOnHighKink = parsedMarketPoolData.borrowRateOnHighKink * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
1457
|
-
const borrowAprOnMidKink = parsedMarketPoolData.borrowRateOnMidKink * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
1458
|
-
const maxBorrowApr = parsedMarketPoolData.maxBorrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
1459
|
-
const borrowApr = parsedMarketPoolData.borrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
1460
|
-
const timeDelta = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedMarketPoolData.lastUpdated;
|
|
1461
|
-
const borrowIndexDelta = (0, import_bignumber.default)(parsedMarketPoolData.borrowIndex).multipliedBy(
|
|
1462
|
-
(0, import_bignumber.default)(timeDelta).multipliedBy(parsedMarketPoolData.borrowRate)
|
|
1463
|
-
).dividedBy(parsedMarketPoolData.borrowRateScale);
|
|
1464
|
-
const currentBorrowIndex = (0, import_bignumber.default)(parsedMarketPoolData.borrowIndex).plus(
|
|
1465
|
-
borrowIndexDelta
|
|
1466
|
-
);
|
|
1467
|
-
const growthInterest = (0, import_bignumber.default)(currentBorrowIndex).dividedBy(parsedMarketPoolData.borrowIndex).minus(1);
|
|
1468
|
-
const increasedDebtAmount = (0, import_bignumber.default)(
|
|
1469
|
-
parsedMarketPoolData.debtAmount
|
|
1470
|
-
).multipliedBy(growthInterest);
|
|
1471
|
-
const borrowAmount = increasedDebtAmount.plus(
|
|
1472
|
-
parsedMarketPoolData.debtAmount
|
|
1473
|
-
);
|
|
1474
|
-
const borrowCoin = borrowAmount.shiftedBy(-1 * coinDecimal);
|
|
1475
|
-
const reserveAmount = (0, import_bignumber.default)(parsedMarketPoolData.reserveAmount).plus(
|
|
1476
|
-
increasedDebtAmount.multipliedBy(parsedMarketPoolData.reserveFactor)
|
|
1477
|
-
);
|
|
1478
|
-
const reserveCoin = reserveAmount.shiftedBy(-1 * coinDecimal);
|
|
1479
|
-
const supplyAmount = (0, import_bignumber.default)(borrowAmount).plus(
|
|
1480
|
-
Math.max(parsedMarketPoolData.cashAmount - reserveAmount.toNumber(), 0)
|
|
1481
|
-
);
|
|
1482
|
-
const supplyCoin = supplyAmount.shiftedBy(-1 * coinDecimal);
|
|
1483
|
-
let utilizationRate = (0, import_bignumber.default)(borrowAmount).dividedBy(supplyAmount);
|
|
1484
|
-
utilizationRate = utilizationRate.isFinite() ? utilizationRate : (0, import_bignumber.default)(0);
|
|
1485
|
-
let supplyApr = (0, import_bignumber.default)(borrowApr).multipliedBy(utilizationRate).multipliedBy(1 - parsedMarketPoolData.reserveFactor);
|
|
1486
|
-
supplyApr = supplyApr.isFinite() ? supplyApr : (0, import_bignumber.default)(0);
|
|
1487
|
-
let conversionRate = supplyAmount.dividedBy(
|
|
1488
|
-
parsedMarketPoolData.marketCoinSupplyAmount
|
|
1489
|
-
);
|
|
1490
|
-
conversionRate = conversionRate.isFinite() && !conversionRate.isNaN() ? conversionRate : (0, import_bignumber.default)(1);
|
|
1491
|
-
return {
|
|
1492
|
-
baseBorrowApr,
|
|
1493
|
-
baseBorrowApy: utils.parseAprToApy(baseBorrowApr),
|
|
1494
|
-
borrowAprOnHighKink,
|
|
1495
|
-
borrowApyOnHighKink: utils.parseAprToApy(borrowAprOnHighKink),
|
|
1496
|
-
borrowAprOnMidKink,
|
|
1497
|
-
borrowApyOnMidKink: utils.parseAprToApy(borrowAprOnMidKink),
|
|
1498
|
-
coinDecimal,
|
|
1499
|
-
maxBorrowApr,
|
|
1500
|
-
maxBorrowApy: utils.parseAprToApy(maxBorrowApr),
|
|
1501
|
-
borrowApr: Math.min(borrowApr, maxBorrowApr),
|
|
1502
|
-
borrowApy: Math.min(
|
|
1503
|
-
utils.parseAprToApy(borrowApr),
|
|
1504
|
-
utils.parseAprToApy(maxBorrowApr)
|
|
1505
|
-
),
|
|
1506
|
-
borrowIndex: currentBorrowIndex.toNumber(),
|
|
1507
|
-
growthInterest: growthInterest.toNumber(),
|
|
1508
|
-
supplyAmount: supplyAmount.toNumber(),
|
|
1509
|
-
supplyCoin: supplyCoin.toNumber(),
|
|
1510
|
-
borrowAmount: borrowAmount.toNumber(),
|
|
1511
|
-
borrowCoin: borrowCoin.toNumber(),
|
|
1512
|
-
reserveAmount: reserveAmount.toNumber(),
|
|
1513
|
-
reserveCoin: reserveCoin.toNumber(),
|
|
1514
|
-
utilizationRate: utilizationRate.toNumber(),
|
|
1515
|
-
supplyApr: supplyApr.toNumber(),
|
|
1516
|
-
supplyApy: utils.parseAprToApy(supplyApr.toNumber()),
|
|
1517
|
-
conversionRate: conversionRate.toNumber(),
|
|
1518
|
-
isIsolated: parsedMarketPoolData.isIsolated,
|
|
1519
|
-
maxSupplyCoin: (0, import_bignumber.default)(parsedMarketPoolData.supplyLimit).shiftedBy(-coinDecimal).toNumber(),
|
|
1520
|
-
maxBorrowCoin: (0, import_bignumber.default)(parsedMarketPoolData.borrowLimit).shiftedBy(-coinDecimal).toNumber()
|
|
1521
|
-
};
|
|
1522
|
-
};
|
|
1523
|
-
var parseOriginMarketCollateralData = (originMarketCollateralData) => {
|
|
1524
|
-
const divisor = 2 ** 32;
|
|
1525
|
-
return {
|
|
1526
|
-
coinType: (0, import_utils.normalizeStructTag)(originMarketCollateralData.type.name),
|
|
1527
|
-
isIsolated: originMarketCollateralData.isIsolated,
|
|
1528
|
-
collateralFactor: Number(originMarketCollateralData.collateralFactor.value) / divisor,
|
|
1529
|
-
liquidationFactor: Number(originMarketCollateralData.liquidationFactor.value) / divisor,
|
|
1530
|
-
liquidationDiscount: Number(originMarketCollateralData.liquidationDiscount.value) / divisor,
|
|
1531
|
-
liquidationPenalty: Number(originMarketCollateralData.liquidationPenalty.value) / divisor,
|
|
1532
|
-
liquidationReserveFactor: Number(originMarketCollateralData.liquidationReserveFactor.value) / divisor,
|
|
1533
|
-
maxCollateralAmount: Number(originMarketCollateralData.maxCollateralAmount),
|
|
1534
|
-
totalCollateralAmount: Number(
|
|
1535
|
-
originMarketCollateralData.totalCollateralAmount
|
|
1536
|
-
)
|
|
1537
|
-
};
|
|
1538
|
-
};
|
|
1539
|
-
var calculateMarketCollateralData = (utils, parsedMarketCollateralData) => {
|
|
1540
|
-
const collateralCoinName = utils.parseCoinNameFromType(
|
|
1541
|
-
parsedMarketCollateralData.coinType
|
|
1542
|
-
);
|
|
1543
|
-
const coinDecimal = utils.getCoinDecimal(collateralCoinName);
|
|
1544
|
-
const maxCollateralCoin = (0, import_bignumber.default)(
|
|
1545
|
-
parsedMarketCollateralData.maxCollateralAmount
|
|
1546
|
-
).shiftedBy(-1 * coinDecimal);
|
|
1547
|
-
const depositCoin = (0, import_bignumber.default)(
|
|
1548
|
-
parsedMarketCollateralData.totalCollateralAmount
|
|
1549
|
-
).shiftedBy(-1 * coinDecimal);
|
|
1550
|
-
return {
|
|
1551
|
-
coinDecimal,
|
|
1552
|
-
isIsolated: parsedMarketCollateralData.isIsolated,
|
|
1553
|
-
maxDepositAmount: parsedMarketCollateralData.maxCollateralAmount,
|
|
1554
|
-
maxDepositCoin: maxCollateralCoin.toNumber(),
|
|
1555
|
-
depositAmount: parsedMarketCollateralData.totalCollateralAmount,
|
|
1556
|
-
depositCoin: depositCoin.toNumber()
|
|
1557
|
-
};
|
|
1558
|
-
};
|
|
1559
|
-
var parseOriginSpoolData = (originSpoolData) => {
|
|
1560
|
-
return {
|
|
1561
|
-
stakeType: (0, import_utils.normalizeStructTag)(originSpoolData.stakeType.fields.name),
|
|
1562
|
-
maxPoint: Number(originSpoolData.maxDistributedPoint),
|
|
1563
|
-
distributedPoint: Number(originSpoolData.distributedPoint),
|
|
1564
|
-
pointPerPeriod: Number(originSpoolData.distributedPointPerPeriod),
|
|
1565
|
-
period: Number(originSpoolData.pointDistributionTime),
|
|
1566
|
-
maxStake: Number(originSpoolData.maxStake),
|
|
1567
|
-
staked: Number(originSpoolData.stakes),
|
|
1568
|
-
index: Number(originSpoolData.index),
|
|
1569
|
-
createdAt: Number(originSpoolData.createdAt),
|
|
1570
|
-
lastUpdate: Number(originSpoolData.lastUpdate)
|
|
1571
|
-
};
|
|
1572
|
-
};
|
|
1573
|
-
var calculateSpoolData = (parsedSpoolData, stakeMarketCoinPrice, stakeMarketCoinDecimal) => {
|
|
1574
|
-
const baseIndexRate = 1e9;
|
|
1575
|
-
const distributedPointPerSec = (0, import_bignumber.default)(
|
|
1576
|
-
parsedSpoolData.pointPerPeriod
|
|
1577
|
-
).dividedBy(parsedSpoolData.period);
|
|
1578
|
-
const pointPerSec = (0, import_bignumber.default)(parsedSpoolData.pointPerPeriod).dividedBy(
|
|
1579
|
-
parsedSpoolData.period
|
|
1580
|
-
);
|
|
1581
|
-
const remainingPeriod = pointPerSec.gt(0) ? (0, import_bignumber.default)(parsedSpoolData.maxPoint).minus(parsedSpoolData.distributedPoint).dividedBy(pointPerSec) : (0, import_bignumber.default)(0);
|
|
1582
|
-
const startDate = parsedSpoolData.createdAt;
|
|
1583
|
-
const endDate = remainingPeriod.plus(parsedSpoolData.lastUpdate).integerValue().toNumber();
|
|
1584
|
-
const timeDelta = (0, import_bignumber.default)(
|
|
1585
|
-
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedSpoolData.lastUpdate
|
|
1586
|
-
).dividedBy(parsedSpoolData.period).toFixed(0);
|
|
1587
|
-
const remainingPoints = (0, import_bignumber.default)(parsedSpoolData.maxPoint).minus(
|
|
1588
|
-
parsedSpoolData.distributedPoint
|
|
1589
|
-
);
|
|
1590
|
-
const accumulatedPoints = import_bignumber.default.minimum(
|
|
1591
|
-
(0, import_bignumber.default)(timeDelta).multipliedBy(parsedSpoolData.pointPerPeriod),
|
|
1592
|
-
remainingPoints
|
|
1593
|
-
);
|
|
1594
|
-
const currentPointIndex = (0, import_bignumber.default)(parsedSpoolData.index).plus(
|
|
1595
|
-
accumulatedPoints.dividedBy(parsedSpoolData.staked).isFinite() ? (0, import_bignumber.default)(baseIndexRate).multipliedBy(accumulatedPoints).dividedBy(parsedSpoolData.staked) : 0
|
|
1596
|
-
);
|
|
1597
|
-
const currentTotalDistributedPoint = (0, import_bignumber.default)(
|
|
1598
|
-
parsedSpoolData.distributedPoint
|
|
1599
|
-
).plus(accumulatedPoints);
|
|
1600
|
-
const stakedAmount = (0, import_bignumber.default)(parsedSpoolData.staked);
|
|
1601
|
-
const stakedCoin = stakedAmount.shiftedBy(-1 * stakeMarketCoinDecimal);
|
|
1602
|
-
const stakedValue = stakedCoin.multipliedBy(stakeMarketCoinPrice);
|
|
1603
|
-
return {
|
|
1604
|
-
distributedPointPerSec: distributedPointPerSec.toNumber(),
|
|
1605
|
-
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
1606
|
-
currentPointIndex: currentPointIndex.toNumber(),
|
|
1607
|
-
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
1608
|
-
startDate: new Date(startDate * 1e3),
|
|
1609
|
-
endDate: new Date(endDate * 1e3),
|
|
1610
|
-
stakedAmount: stakedAmount.toNumber(),
|
|
1611
|
-
stakedCoin: stakedCoin.toNumber(),
|
|
1612
|
-
stakedValue: stakedValue.toNumber()
|
|
1613
|
-
};
|
|
1614
|
-
};
|
|
1615
|
-
var parseOriginSpoolRewardPoolData = (originSpoolRewardPoolData) => {
|
|
1616
|
-
return {
|
|
1617
|
-
claimedRewards: Number(originSpoolRewardPoolData.claimed_rewards),
|
|
1618
|
-
exchangeRateDenominator: Number(
|
|
1619
|
-
originSpoolRewardPoolData.exchange_rate_denominator
|
|
1620
|
-
),
|
|
1621
|
-
exchangeRateNumerator: Number(
|
|
1622
|
-
originSpoolRewardPoolData.exchange_rate_numerator
|
|
1623
|
-
),
|
|
1624
|
-
rewards: Number(originSpoolRewardPoolData.rewards),
|
|
1625
|
-
spoolId: String(originSpoolRewardPoolData.spool_id)
|
|
1626
|
-
};
|
|
1627
|
-
};
|
|
1628
|
-
var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData, calculatedSpoolData, rewardCoinPrice, rewardCoinDecimal) => {
|
|
1629
|
-
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
1630
|
-
const rewardPerSec = (0, import_bignumber.default)(calculatedSpoolData.distributedPointPerSec).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
1631
|
-
const totalRewardAmount = (0, import_bignumber.default)(parsedSpoolData.maxPoint).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
1632
|
-
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
1633
|
-
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1634
|
-
const remaindRewardAmount = (0, import_bignumber.default)(parsedSpoolRewardPoolData.rewards);
|
|
1635
|
-
const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
1636
|
-
-1 * rewardCoinDecimal
|
|
1637
|
-
);
|
|
1638
|
-
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1639
|
-
const claimedRewardAmount = (0, import_bignumber.default)(
|
|
1640
|
-
parsedSpoolRewardPoolData.claimedRewards
|
|
1641
|
-
);
|
|
1642
|
-
const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
1643
|
-
-1 * rewardCoinDecimal
|
|
1644
|
-
);
|
|
1645
|
-
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1646
|
-
const rewardValueForYear = (0, import_bignumber.default)(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
1647
|
-
let rewardRate = rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).toNumber() : Infinity;
|
|
1648
|
-
if (parsedSpoolData.maxPoint <= parsedSpoolData.distributedPoint || parsedSpoolData.pointPerPeriod === 0) {
|
|
1649
|
-
rewardRate = Infinity;
|
|
1650
|
-
}
|
|
1651
|
-
return {
|
|
1652
|
-
rewardApr: rewardRate,
|
|
1653
|
-
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
1654
|
-
totalRewardCoin: totalRewardCoin.toNumber(),
|
|
1655
|
-
totalRewardValue: totalRewardValue.toNumber(),
|
|
1656
|
-
remaindRewardAmount: remaindRewardAmount.toNumber(),
|
|
1657
|
-
remaindRewardCoin: remaindRewardCoin.toNumber(),
|
|
1658
|
-
remaindRewardValue: remaindRewardValue.toNumber(),
|
|
1659
|
-
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
1660
|
-
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
1661
|
-
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
1662
|
-
rewardPerSec: rewardPerSec.toNumber()
|
|
1663
|
-
};
|
|
1664
|
-
};
|
|
1665
|
-
var parseOriginBorrowIncentivesPoolPointData = (originBorrowIncentivePoolPointData) => {
|
|
1666
|
-
return {
|
|
1667
|
-
pointType: (0, import_utils.normalizeStructTag)(
|
|
1668
|
-
originBorrowIncentivePoolPointData.point_type.name
|
|
1669
|
-
),
|
|
1670
|
-
distributedPointPerPeriod: Number(
|
|
1671
|
-
originBorrowIncentivePoolPointData.distributed_point_per_period
|
|
1672
|
-
),
|
|
1673
|
-
period: Number(originBorrowIncentivePoolPointData.point_distribution_time),
|
|
1674
|
-
distributedPoint: Number(
|
|
1675
|
-
originBorrowIncentivePoolPointData.distributed_point
|
|
1676
|
-
),
|
|
1677
|
-
points: Number(originBorrowIncentivePoolPointData.points),
|
|
1678
|
-
index: Number(originBorrowIncentivePoolPointData.index),
|
|
1679
|
-
baseWeight: Number(originBorrowIncentivePoolPointData.base_weight),
|
|
1680
|
-
weightedAmount: Number(originBorrowIncentivePoolPointData.weighted_amount),
|
|
1681
|
-
lastUpdate: Number(originBorrowIncentivePoolPointData.last_update),
|
|
1682
|
-
createdAt: Number(originBorrowIncentivePoolPointData.created_at)
|
|
1683
|
-
};
|
|
1684
|
-
};
|
|
1685
|
-
var parseOriginBorrowIncentivePoolData = (utils, originBorrowIncentivePoolData) => {
|
|
1686
|
-
return {
|
|
1687
|
-
poolType: (0, import_utils.normalizeStructTag)(originBorrowIncentivePoolData.pool_type.name),
|
|
1688
|
-
minStakes: Number(originBorrowIncentivePoolData.min_stakes),
|
|
1689
|
-
maxStakes: Number(originBorrowIncentivePoolData.max_stakes),
|
|
1690
|
-
staked: Number(originBorrowIncentivePoolData.stakes),
|
|
1691
|
-
poolPoints: originBorrowIncentivePoolData.points.reduce(
|
|
1692
|
-
(acc, point) => {
|
|
1693
|
-
const parsed = parseOriginBorrowIncentivesPoolPointData(point);
|
|
1694
|
-
const name = utils.parseSCoinTypeNameToMarketCoinName(
|
|
1695
|
-
(0, import_utils.parseStructTag)(parsed.pointType).name.toLowerCase()
|
|
1696
|
-
);
|
|
1697
|
-
acc[name] = parsed;
|
|
1698
|
-
return acc;
|
|
1676
|
+
// src/models/scallopAddress.ts
|
|
1677
|
+
var import_axios = __toESM(require("axios"));
|
|
1678
|
+
var EMPTY_ADDRESSES = {
|
|
1679
|
+
core: {
|
|
1680
|
+
version: "",
|
|
1681
|
+
versionCap: "",
|
|
1682
|
+
object: "",
|
|
1683
|
+
market: "",
|
|
1684
|
+
adminCap: "",
|
|
1685
|
+
coinDecimalsRegistry: "",
|
|
1686
|
+
obligationAccessStore: "",
|
|
1687
|
+
coins: {
|
|
1688
|
+
cetus: {
|
|
1689
|
+
id: "",
|
|
1690
|
+
metaData: "",
|
|
1691
|
+
treasury: "",
|
|
1692
|
+
oracle: {
|
|
1693
|
+
supra: "",
|
|
1694
|
+
switchboard: "",
|
|
1695
|
+
pyth: {
|
|
1696
|
+
feed: "",
|
|
1697
|
+
feedObject: ""
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1699
1700
|
},
|
|
1700
|
-
{
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
const accumulatedPoints = import_bignumber.default.minimum(
|
|
1713
|
-
(0, import_bignumber.default)(timeDelta).multipliedBy(
|
|
1714
|
-
parsedBorrowIncentivePoolPointData.distributedPointPerPeriod
|
|
1715
|
-
),
|
|
1716
|
-
(0, import_bignumber.default)(parsedBorrowIncentivePoolPointData.points)
|
|
1717
|
-
);
|
|
1718
|
-
const currentPointIndex = (0, import_bignumber.default)(
|
|
1719
|
-
parsedBorrowIncentivePoolPointData.index
|
|
1720
|
-
).plus(
|
|
1721
|
-
accumulatedPoints.dividedBy(parsedBorrowIncentivePoolPointData.weightedAmount).isFinite() ? (0, import_bignumber.default)(baseIndexRate).multipliedBy(accumulatedPoints).dividedBy(parsedBorrowIncentivePoolPointData.weightedAmount) : 0
|
|
1722
|
-
);
|
|
1723
|
-
const currentTotalDistributedPoint = (0, import_bignumber.default)(
|
|
1724
|
-
parsedBorrowIncentivePoolPointData.distributedPoint
|
|
1725
|
-
).plus(accumulatedPoints);
|
|
1726
|
-
const baseWeight = (0, import_bignumber.default)(parsedBorrowIncentivePoolPointData.baseWeight);
|
|
1727
|
-
const weightedStakedAmount = (0, import_bignumber.default)(
|
|
1728
|
-
parsedBorrowIncentivePoolPointData.weightedAmount
|
|
1729
|
-
);
|
|
1730
|
-
const weightedStakedCoin = weightedStakedAmount.shiftedBy(
|
|
1731
|
-
-1 * poolCoinDecimal
|
|
1732
|
-
);
|
|
1733
|
-
const weightedStakedValue = weightedStakedCoin.multipliedBy(poolCoinPrice);
|
|
1734
|
-
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
1735
|
-
const rewardPerSec = (0, import_bignumber.default)(distributedPointPerSec).shiftedBy(
|
|
1736
|
-
-1 * rewardCoinDecimal
|
|
1737
|
-
);
|
|
1738
|
-
const rewardValueForYear = (0, import_bignumber.default)(rewardPerSec).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
1739
|
-
const weightScale = (0, import_bignumber.default)(1e12);
|
|
1740
|
-
const rewardRate = rewardValueForYear.multipliedBy(
|
|
1741
|
-
(0, import_bignumber.default)(parsedBorrowIncentivePoolPointData.baseWeight).dividedBy(
|
|
1742
|
-
weightScale
|
|
1743
|
-
)
|
|
1744
|
-
).dividedBy(weightedStakedValue).isFinite() && parsedBorrowIncentivePoolPointData.points > 0 ? rewardValueForYear.multipliedBy(
|
|
1745
|
-
(0, import_bignumber.default)(parsedBorrowIncentivePoolPointData.baseWeight).dividedBy(
|
|
1746
|
-
weightScale
|
|
1747
|
-
)
|
|
1748
|
-
).dividedBy(weightedStakedValue).toNumber() : Infinity;
|
|
1749
|
-
return {
|
|
1750
|
-
distributedPointPerSec: distributedPointPerSec.toNumber(),
|
|
1751
|
-
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
1752
|
-
currentPointIndex: currentPointIndex.toNumber(),
|
|
1753
|
-
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
1754
|
-
baseWeight: baseWeight.toNumber(),
|
|
1755
|
-
weightedStakedAmount: weightedStakedAmount.toNumber(),
|
|
1756
|
-
weightedStakedCoin: weightedStakedCoin.toNumber(),
|
|
1757
|
-
weightedStakedValue: weightedStakedValue.toNumber(),
|
|
1758
|
-
rewardApr: rewardRate,
|
|
1759
|
-
rewardPerSec: rewardPerSec.toNumber()
|
|
1760
|
-
};
|
|
1761
|
-
};
|
|
1762
|
-
var parseOriginBorrowIncentiveAccountPoolPointData = (originBorrowIncentiveAccountPoolPointData) => {
|
|
1763
|
-
return {
|
|
1764
|
-
pointType: (0, import_utils.normalizeStructTag)(
|
|
1765
|
-
originBorrowIncentiveAccountPoolPointData.point_type.name
|
|
1766
|
-
),
|
|
1767
|
-
weightedAmount: Number(
|
|
1768
|
-
originBorrowIncentiveAccountPoolPointData.weighted_amount
|
|
1769
|
-
),
|
|
1770
|
-
points: Number(originBorrowIncentiveAccountPoolPointData.points),
|
|
1771
|
-
totalPoints: Number(originBorrowIncentiveAccountPoolPointData.total_points),
|
|
1772
|
-
index: Number(originBorrowIncentiveAccountPoolPointData.index)
|
|
1773
|
-
};
|
|
1774
|
-
};
|
|
1775
|
-
var parseOriginBorrowIncentiveAccountData = (originBorrowIncentiveAccountData) => {
|
|
1776
|
-
return {
|
|
1777
|
-
poolType: (0, import_utils.normalizeStructTag)(
|
|
1778
|
-
originBorrowIncentiveAccountData.pool_type.name
|
|
1779
|
-
),
|
|
1780
|
-
debtAmount: Number(originBorrowIncentiveAccountData.debt_amount),
|
|
1781
|
-
pointList: originBorrowIncentiveAccountData.points_list.reduce(
|
|
1782
|
-
(acc, point) => {
|
|
1783
|
-
const parsed = parseOriginBorrowIncentiveAccountPoolPointData(point);
|
|
1784
|
-
const name = (0, import_utils.parseStructTag)(
|
|
1785
|
-
parsed.pointType
|
|
1786
|
-
).name.toLowerCase();
|
|
1787
|
-
acc[name] = parsed;
|
|
1788
|
-
return acc;
|
|
1701
|
+
wapt: {
|
|
1702
|
+
id: "",
|
|
1703
|
+
metaData: "",
|
|
1704
|
+
treasury: "",
|
|
1705
|
+
oracle: {
|
|
1706
|
+
supra: "",
|
|
1707
|
+
switchboard: "",
|
|
1708
|
+
pyth: {
|
|
1709
|
+
feed: "",
|
|
1710
|
+
feedObject: ""
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1789
1713
|
},
|
|
1790
|
-
{
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
}
|
|
1801
|
-
var estimatedFactor = (amount, scaleStep, type) => {
|
|
1802
|
-
const amountOfDigits = Math.max(
|
|
1803
|
-
1,
|
|
1804
|
-
Math.floor(Math.log10(Math.abs(amount)) + 1)
|
|
1805
|
-
);
|
|
1806
|
-
const adjustScale = Math.max(Math.floor((amountOfDigits - 1) / scaleStep), 1) + 1;
|
|
1807
|
-
let adjustFactor = Math.pow(10, -adjustScale);
|
|
1808
|
-
adjustFactor = type === "increase" ? 1 - adjustFactor : 1 + adjustFactor;
|
|
1809
|
-
return adjustFactor;
|
|
1810
|
-
};
|
|
1811
|
-
|
|
1812
|
-
// src/utils/util.ts
|
|
1813
|
-
var COIN_SET = Array.from(
|
|
1814
|
-
/* @__PURE__ */ new Set([
|
|
1815
|
-
...SUPPORT_POOLS,
|
|
1816
|
-
...SUPPORT_COLLATERALS,
|
|
1817
|
-
...SUPPORT_SPOOLS_REWARDS,
|
|
1818
|
-
...SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
1819
|
-
...SUPPORT_SCOIN
|
|
1820
|
-
])
|
|
1821
|
-
);
|
|
1822
|
-
var isMarketCoin = (coinName) => {
|
|
1823
|
-
const assetCoinName = coinName.slice(1).toLowerCase();
|
|
1824
|
-
return coinName.charAt(0).toLowerCase() === "s" && COIN_SET.includes(assetCoinName);
|
|
1825
|
-
};
|
|
1826
|
-
var isSuiBridgeAsset = (coinName) => {
|
|
1827
|
-
return SUPPORT_SUI_BRIDGE.includes(coinName);
|
|
1828
|
-
};
|
|
1829
|
-
var isWormholeAsset = (coinName) => {
|
|
1830
|
-
return SUPPORT_WORMHOLE.includes(coinName);
|
|
1831
|
-
};
|
|
1832
|
-
var parseAssetSymbol = (coinName) => {
|
|
1833
|
-
if (isWormholeAsset(coinName)) {
|
|
1834
|
-
return `w${coinName.slice(1).toUpperCase()}`;
|
|
1835
|
-
}
|
|
1836
|
-
if (isSuiBridgeAsset(coinName)) {
|
|
1837
|
-
return `sb${coinName.slice(2).toUpperCase()}`;
|
|
1838
|
-
}
|
|
1839
|
-
if (isMarketCoin(coinName)) {
|
|
1840
|
-
const assetCoinName = coinName.slice(1).toLowerCase();
|
|
1841
|
-
return coinName.slice(0, 1).toLowerCase() + parseAssetSymbol(assetCoinName);
|
|
1842
|
-
}
|
|
1843
|
-
switch (coinName) {
|
|
1844
|
-
case "afsui":
|
|
1845
|
-
return "afSUI";
|
|
1846
|
-
case "hasui":
|
|
1847
|
-
return "haSUI";
|
|
1848
|
-
case "vsui":
|
|
1849
|
-
return "vSUI";
|
|
1850
|
-
default:
|
|
1851
|
-
return coinName.toUpperCase();
|
|
1852
|
-
}
|
|
1853
|
-
};
|
|
1854
|
-
var parseDataFromPythPriceFeed = (feed, address) => {
|
|
1855
|
-
const assetCoinNames = COIN_SET;
|
|
1856
|
-
const assetCoinName = assetCoinNames.find((assetCoinName2) => {
|
|
1857
|
-
return address.get(`core.coins.${assetCoinName2}.oracle.pyth.feed`) === feed.id;
|
|
1858
|
-
});
|
|
1859
|
-
if (assetCoinName) {
|
|
1860
|
-
const price = feed.price.price * 10 ** feed.price.expo;
|
|
1861
|
-
return {
|
|
1862
|
-
coinName: assetCoinName,
|
|
1863
|
-
price,
|
|
1864
|
-
publishTime: Number(feed.price.publishTime) * 10 ** 3
|
|
1865
|
-
};
|
|
1866
|
-
} else {
|
|
1867
|
-
throw new Error("Invalid feed id");
|
|
1868
|
-
}
|
|
1869
|
-
};
|
|
1870
|
-
var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
|
|
1871
|
-
const unlockDate = new Date(unlockAtInSecondTimestamp * 1e3);
|
|
1872
|
-
const closestTwelveAM = new Date(unlockAtInSecondTimestamp * 1e3);
|
|
1873
|
-
closestTwelveAM.setUTCHours(0, 0, 0, 0);
|
|
1874
|
-
if (unlockDate.getUTCHours() >= 0) {
|
|
1875
|
-
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() + 1);
|
|
1876
|
-
}
|
|
1877
|
-
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
1878
|
-
if (closestTwelveAM.getTime() - now > MAX_LOCK_DURATION * 1e3) {
|
|
1879
|
-
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() - 1);
|
|
1880
|
-
}
|
|
1881
|
-
return Math.floor(closestTwelveAM.getTime() / 1e3);
|
|
1882
|
-
};
|
|
1883
|
-
var partitionArray = (array, chunkSize) => {
|
|
1884
|
-
const result = [];
|
|
1885
|
-
for (let i = 0; i < array.length; i += chunkSize) {
|
|
1886
|
-
result.push(array.slice(i, i + chunkSize));
|
|
1887
|
-
}
|
|
1888
|
-
return result;
|
|
1889
|
-
};
|
|
1890
|
-
|
|
1891
|
-
// src/utils/tokenBucket.ts
|
|
1892
|
-
var TokenBucket = class {
|
|
1893
|
-
constructor(tokensPerInterval, intervalInMs) {
|
|
1894
|
-
this.tokensPerInterval = tokensPerInterval;
|
|
1895
|
-
this.interval = intervalInMs;
|
|
1896
|
-
this.tokens = tokensPerInterval;
|
|
1897
|
-
this.lastRefill = Date.now();
|
|
1898
|
-
}
|
|
1899
|
-
refill() {
|
|
1900
|
-
const now = Date.now();
|
|
1901
|
-
const elapsed = now - this.lastRefill;
|
|
1902
|
-
if (elapsed >= this.interval) {
|
|
1903
|
-
const tokensToAdd = Math.floor(elapsed / this.interval) * this.tokensPerInterval;
|
|
1904
|
-
this.tokens = Math.min(this.tokens + tokensToAdd, this.tokensPerInterval);
|
|
1905
|
-
this.lastRefill += Math.floor(elapsed / this.interval) * this.interval;
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
removeTokens(count) {
|
|
1909
|
-
this.refill();
|
|
1910
|
-
if (this.tokens >= count) {
|
|
1911
|
-
this.tokens -= count;
|
|
1912
|
-
return true;
|
|
1913
|
-
}
|
|
1914
|
-
return false;
|
|
1915
|
-
}
|
|
1916
|
-
};
|
|
1917
|
-
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 15, backoffFactor = 1.25) => {
|
|
1918
|
-
let retries = 0;
|
|
1919
|
-
const tryRequest = async () => {
|
|
1920
|
-
if (tokenBucket.removeTokens(1)) {
|
|
1921
|
-
const result = await fn();
|
|
1922
|
-
return result;
|
|
1923
|
-
} else if (retries < maxRetries) {
|
|
1924
|
-
retries++;
|
|
1925
|
-
const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
|
|
1926
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1927
|
-
return tryRequest();
|
|
1928
|
-
} else {
|
|
1929
|
-
console.error("Maximum retries reached");
|
|
1930
|
-
return null;
|
|
1931
|
-
}
|
|
1932
|
-
};
|
|
1933
|
-
return tryRequest();
|
|
1934
|
-
};
|
|
1935
|
-
|
|
1936
|
-
// src/utils/indexer.ts
|
|
1937
|
-
async function callMethodWithIndexerFallback(method, context, ...args) {
|
|
1938
|
-
const lastArgs = args[args.length - 1];
|
|
1939
|
-
if (typeof lastArgs === "object" && lastArgs.indexer) {
|
|
1940
|
-
try {
|
|
1941
|
-
return await method.apply(context, args);
|
|
1942
|
-
} catch (e) {
|
|
1943
|
-
console.warn(`Indexer requests failed: ${e}. Retrying without indexer..`);
|
|
1944
|
-
return await method.apply(context, [
|
|
1945
|
-
...args.slice(0, -1),
|
|
1946
|
-
{
|
|
1947
|
-
...lastArgs,
|
|
1948
|
-
indexer: false
|
|
1714
|
+
wsol: {
|
|
1715
|
+
id: "",
|
|
1716
|
+
metaData: "",
|
|
1717
|
+
treasury: "",
|
|
1718
|
+
oracle: {
|
|
1719
|
+
supra: "",
|
|
1720
|
+
switchboard: "",
|
|
1721
|
+
pyth: {
|
|
1722
|
+
feed: "",
|
|
1723
|
+
feedObject: ""
|
|
1724
|
+
}
|
|
1949
1725
|
}
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
}
|
|
1953
|
-
return await method.apply(context, args);
|
|
1954
|
-
}
|
|
1955
|
-
function withIndexerFallback(method) {
|
|
1956
|
-
return (...args) => {
|
|
1957
|
-
return callMethodWithIndexerFallback(method, this, ...args);
|
|
1958
|
-
};
|
|
1959
|
-
}
|
|
1960
|
-
|
|
1961
|
-
// src/utils/core.ts
|
|
1962
|
-
var parseObjectAs = (object) => {
|
|
1963
|
-
if (!(object && object.content && "fields" in object.content))
|
|
1964
|
-
throw new Error(`Failed to parse object`);
|
|
1965
|
-
const fields = object.content.fields;
|
|
1966
|
-
if (typeof fields === "object" && "value" in fields) {
|
|
1967
|
-
const value = fields.value;
|
|
1968
|
-
if (typeof value === "object" && "fields" in value)
|
|
1969
|
-
return value.fields;
|
|
1970
|
-
return value;
|
|
1971
|
-
} else if (typeof fields === "object") {
|
|
1972
|
-
return fields;
|
|
1973
|
-
}
|
|
1974
|
-
return fields;
|
|
1975
|
-
};
|
|
1976
|
-
|
|
1977
|
-
// src/models/scallopCache.ts
|
|
1978
|
-
var ScallopCache = class {
|
|
1979
|
-
constructor(suiKit, walletAddress, cacheOptions, tokenBucket, queryClient) {
|
|
1980
|
-
this.queryClient = queryClient ?? new import_query_core.QueryClient(cacheOptions ?? DEFAULT_CACHE_OPTIONS);
|
|
1981
|
-
this._suiKit = suiKit;
|
|
1982
|
-
this.tokenBucket = tokenBucket ?? new TokenBucket(DEFAULT_TOKENS_PER_INTERVAL, DEFAULT_INTERVAL_IN_MS);
|
|
1983
|
-
this.walletAddress = walletAddress ?? suiKit.currentAddress();
|
|
1984
|
-
}
|
|
1985
|
-
get suiKit() {
|
|
1986
|
-
if (!this._suiKit) {
|
|
1987
|
-
throw new Error("SuiKit instance is not initialized");
|
|
1988
|
-
}
|
|
1989
|
-
return this._suiKit;
|
|
1990
|
-
}
|
|
1991
|
-
get client() {
|
|
1992
|
-
return this.suiKit.client();
|
|
1993
|
-
}
|
|
1994
|
-
/**
|
|
1995
|
-
* @description Invalidate cache based on the refetchType parameter
|
|
1996
|
-
* @param refetchType Determines the type of queries to be refetched. Defaults to `active`.
|
|
1997
|
-
*
|
|
1998
|
-
* - `active`: Only queries that match the refetch predicate and are actively being rendered via useQuery and related functions will be refetched in the background.
|
|
1999
|
-
* - `inactive`: Only queries that match the refetch predicate and are NOT actively being rendered via useQuery and related functions will be refetched in the background.
|
|
2000
|
-
* - `all`: All queries that match the refetch predicate will be refetched in the background.
|
|
2001
|
-
* - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
|
|
2002
|
-
*/
|
|
2003
|
-
async invalidateAllCache() {
|
|
2004
|
-
return Object.values(queryKeys.rpc).map(
|
|
2005
|
-
(t) => this.queryClient.invalidateQueries({
|
|
2006
|
-
queryKey: t(),
|
|
2007
|
-
type: "all"
|
|
2008
|
-
})
|
|
2009
|
-
);
|
|
2010
|
-
}
|
|
2011
|
-
retryFn(errCount, e) {
|
|
2012
|
-
if (errCount === 5)
|
|
2013
|
-
return false;
|
|
2014
|
-
if (e.status === 429)
|
|
2015
|
-
return true;
|
|
2016
|
-
return false;
|
|
2017
|
-
}
|
|
2018
|
-
/**
|
|
2019
|
-
* @description Provides cache for inspectTxn of the SuiKit.
|
|
2020
|
-
* @param QueryInspectTxnParams
|
|
2021
|
-
* @param txBlock
|
|
2022
|
-
* @returns Promise<DevInspectResults>
|
|
2023
|
-
*/
|
|
2024
|
-
async queryInspectTxn({
|
|
2025
|
-
queryTarget,
|
|
2026
|
-
args,
|
|
2027
|
-
typeArgs
|
|
2028
|
-
}) {
|
|
2029
|
-
const txBlock = new import_sui_kit.SuiTxBlock();
|
|
2030
|
-
const resolvedQueryTarget = await this.queryGetNormalizedMoveFunction(queryTarget);
|
|
2031
|
-
if (!resolvedQueryTarget)
|
|
2032
|
-
throw new Error("Invalid query target");
|
|
2033
|
-
const { parameters } = resolvedQueryTarget;
|
|
2034
|
-
const resolvedArgs = await Promise.all(
|
|
2035
|
-
(args ?? []).map(async (arg, idx) => {
|
|
2036
|
-
if (typeof arg !== "string")
|
|
2037
|
-
return arg;
|
|
2038
|
-
const cachedData = (await this.queryGetObject(arg))?.data;
|
|
2039
|
-
if (!cachedData)
|
|
2040
|
-
return arg;
|
|
2041
|
-
const owner = cachedData.owner;
|
|
2042
|
-
if (!owner || typeof owner !== "object" || !("Shared" in owner))
|
|
2043
|
-
return {
|
|
2044
|
-
objectId: cachedData.objectId,
|
|
2045
|
-
version: cachedData.version,
|
|
2046
|
-
digest: cachedData.digest
|
|
2047
|
-
};
|
|
2048
|
-
const parameter = parameters[idx];
|
|
2049
|
-
if (typeof parameter !== "object" || !("MutableReference" in parameter || "Reference" in parameter))
|
|
2050
|
-
return arg;
|
|
2051
|
-
return {
|
|
2052
|
-
objectId: cachedData.objectId,
|
|
2053
|
-
initialSharedVersion: owner.Shared.initial_shared_version,
|
|
2054
|
-
mutable: "MutableReference" in parameter
|
|
2055
|
-
};
|
|
2056
|
-
})
|
|
2057
|
-
);
|
|
2058
|
-
txBlock.moveCall(queryTarget, resolvedArgs, typeArgs);
|
|
2059
|
-
const query = await this.queryClient.fetchQuery({
|
|
2060
|
-
retry: this.retryFn,
|
|
2061
|
-
retryDelay: 1e3,
|
|
2062
|
-
queryKey: queryKeys.rpc.getInspectTxn(queryTarget, args, typeArgs),
|
|
2063
|
-
queryFn: async () => {
|
|
2064
|
-
return await callWithRateLimit(
|
|
2065
|
-
this.tokenBucket,
|
|
2066
|
-
async () => await this.suiKit.inspectTxn(txBlock)
|
|
2067
|
-
);
|
|
2068
|
-
}
|
|
2069
|
-
});
|
|
2070
|
-
return query;
|
|
2071
|
-
}
|
|
2072
|
-
async queryGetNormalizedMoveFunction(target) {
|
|
2073
|
-
const { address, module: module2, name } = (0, import_sui_kit.parseStructTag)(target);
|
|
2074
|
-
return this.queryClient.fetchQuery({
|
|
2075
|
-
queryKey: queryKeys.rpc.getNormalizedMoveFunction(target),
|
|
2076
|
-
queryFn: async () => {
|
|
2077
|
-
return await callWithRateLimit(
|
|
2078
|
-
this.tokenBucket,
|
|
2079
|
-
async () => await this.suiKit.client().getNormalizedMoveFunction({
|
|
2080
|
-
package: address,
|
|
2081
|
-
module: module2,
|
|
2082
|
-
function: name
|
|
2083
|
-
})
|
|
2084
|
-
);
|
|
2085
|
-
}
|
|
2086
|
-
});
|
|
2087
|
-
}
|
|
2088
|
-
/**
|
|
2089
|
-
* @description Provides cache for getObject of the SuiKit.
|
|
2090
|
-
* @param objectId
|
|
2091
|
-
* @param QueryObjectParams
|
|
2092
|
-
* @returns Promise<SuiObjectResponse>
|
|
2093
|
-
*/
|
|
2094
|
-
async queryGetObject(objectId, options) {
|
|
2095
|
-
options = {
|
|
2096
|
-
...options,
|
|
2097
|
-
showOwner: true,
|
|
2098
|
-
showContent: true
|
|
2099
|
-
};
|
|
2100
|
-
return this.queryClient.fetchQuery({
|
|
2101
|
-
retry: this.retryFn,
|
|
2102
|
-
retryDelay: 1e3,
|
|
2103
|
-
queryKey: queryKeys.rpc.getObject(objectId, options),
|
|
2104
|
-
queryFn: async () => {
|
|
2105
|
-
return await callWithRateLimit(
|
|
2106
|
-
this.tokenBucket,
|
|
2107
|
-
async () => await this.client.getObject({
|
|
2108
|
-
id: objectId,
|
|
2109
|
-
options
|
|
2110
|
-
})
|
|
2111
|
-
);
|
|
2112
|
-
}
|
|
2113
|
-
});
|
|
2114
|
-
}
|
|
2115
|
-
/**
|
|
2116
|
-
* @description Provides cache for getObjects of the SuiKit.
|
|
2117
|
-
* @param objectIds
|
|
2118
|
-
* @returns Promise<SuiObjectData[]>
|
|
2119
|
-
*/
|
|
2120
|
-
async queryGetObjects(objectIds, options = {
|
|
2121
|
-
showContent: true
|
|
2122
|
-
}) {
|
|
2123
|
-
if (objectIds.length === 0)
|
|
2124
|
-
return [];
|
|
2125
|
-
return this.queryClient.fetchQuery({
|
|
2126
|
-
retry: this.retryFn,
|
|
2127
|
-
retryDelay: 1e3,
|
|
2128
|
-
queryKey: queryKeys.rpc.getObjects(
|
|
2129
|
-
objectIds,
|
|
2130
|
-
this.walletAddress,
|
|
2131
|
-
options
|
|
2132
|
-
),
|
|
2133
|
-
queryFn: async () => {
|
|
2134
|
-
const results = await callWithRateLimit(
|
|
2135
|
-
this.tokenBucket,
|
|
2136
|
-
async () => await this.suiKit.getObjects(objectIds, options)
|
|
2137
|
-
);
|
|
2138
|
-
if (results) {
|
|
2139
|
-
results.forEach((result) => {
|
|
2140
|
-
this.queryClient.setQueriesData(
|
|
2141
|
-
{
|
|
2142
|
-
exact: false,
|
|
2143
|
-
queryKey: queryKeys.rpc.getObject(result.objectId, options)
|
|
2144
|
-
},
|
|
2145
|
-
{
|
|
2146
|
-
data: result,
|
|
2147
|
-
error: null
|
|
2148
|
-
},
|
|
2149
|
-
{
|
|
2150
|
-
updatedAt: Date.now()
|
|
2151
|
-
}
|
|
2152
|
-
);
|
|
2153
|
-
});
|
|
2154
|
-
}
|
|
2155
|
-
return results;
|
|
2156
|
-
}
|
|
2157
|
-
});
|
|
2158
|
-
}
|
|
2159
|
-
/**
|
|
2160
|
-
* @description Provides cache for getOwnedObjects of the SuiKit.
|
|
2161
|
-
* @param input
|
|
2162
|
-
* @returns Promise<PaginatedObjectsResponse>
|
|
2163
|
-
*/
|
|
2164
|
-
async queryGetOwnedObjects(input) {
|
|
2165
|
-
return this.queryClient.fetchQuery({
|
|
2166
|
-
retry: this.retryFn,
|
|
2167
|
-
retryDelay: 1e3,
|
|
2168
|
-
queryKey: queryKeys.rpc.getOwnedObjects(input),
|
|
2169
|
-
queryFn: async () => {
|
|
2170
|
-
const results = await callWithRateLimit(
|
|
2171
|
-
this.tokenBucket,
|
|
2172
|
-
async () => await this.client.getOwnedObjects(input)
|
|
2173
|
-
);
|
|
2174
|
-
if (results && results.data.length > 0) {
|
|
2175
|
-
results.data.filter(
|
|
2176
|
-
(result) => !!result.data
|
|
2177
|
-
).forEach((result) => {
|
|
2178
|
-
this.queryClient.setQueriesData(
|
|
2179
|
-
{
|
|
2180
|
-
exact: false,
|
|
2181
|
-
queryKey: queryKeys.rpc.getObject(
|
|
2182
|
-
result.data.objectId,
|
|
2183
|
-
input.options ?? {}
|
|
2184
|
-
)
|
|
2185
|
-
},
|
|
2186
|
-
{
|
|
2187
|
-
data: result.data,
|
|
2188
|
-
error: null
|
|
2189
|
-
},
|
|
2190
|
-
{
|
|
2191
|
-
updatedAt: Date.now()
|
|
2192
|
-
}
|
|
2193
|
-
);
|
|
2194
|
-
});
|
|
2195
|
-
}
|
|
2196
|
-
return results;
|
|
2197
|
-
}
|
|
2198
|
-
});
|
|
2199
|
-
}
|
|
2200
|
-
async queryGetDynamicFields(input) {
|
|
2201
|
-
return this.queryClient.fetchQuery({
|
|
2202
|
-
retry: this.retryFn,
|
|
2203
|
-
retryDelay: 1e3,
|
|
2204
|
-
queryKey: queryKeys.rpc.getDynamicFields(input),
|
|
2205
|
-
queryFn: async () => {
|
|
2206
|
-
return await callWithRateLimit(
|
|
2207
|
-
this.tokenBucket,
|
|
2208
|
-
async () => await this.client.getDynamicFields(input)
|
|
2209
|
-
);
|
|
2210
|
-
}
|
|
2211
|
-
});
|
|
2212
|
-
}
|
|
2213
|
-
async queryGetDynamicFieldObject(input) {
|
|
2214
|
-
return this.queryClient.fetchQuery({
|
|
2215
|
-
retry: this.retryFn,
|
|
2216
|
-
retryDelay: (attemptIndex) => Math.min(1e3 * attemptIndex, 8e3),
|
|
2217
|
-
queryKey: queryKeys.rpc.getDynamicFieldObject(input),
|
|
2218
|
-
queryFn: async () => {
|
|
2219
|
-
const result = await callWithRateLimit(
|
|
2220
|
-
this.tokenBucket,
|
|
2221
|
-
() => this.client.getDynamicFieldObject(input)
|
|
2222
|
-
);
|
|
2223
|
-
if (result?.data) {
|
|
2224
|
-
this.queryClient.setQueriesData(
|
|
2225
|
-
{
|
|
2226
|
-
exact: false,
|
|
2227
|
-
queryKey: queryKeys.rpc.getObject(result?.data.objectId, {
|
|
2228
|
-
showContent: true,
|
|
2229
|
-
showOwner: true
|
|
2230
|
-
})
|
|
2231
|
-
},
|
|
2232
|
-
{
|
|
2233
|
-
data: result.data,
|
|
2234
|
-
error: null
|
|
2235
|
-
},
|
|
2236
|
-
{
|
|
2237
|
-
updatedAt: Date.now()
|
|
2238
|
-
}
|
|
2239
|
-
);
|
|
2240
|
-
}
|
|
2241
|
-
return result;
|
|
2242
|
-
}
|
|
2243
|
-
});
|
|
2244
|
-
}
|
|
2245
|
-
async queryGetAllCoinBalances(owner) {
|
|
2246
|
-
return this.queryClient.fetchQuery({
|
|
2247
|
-
retry: this.retryFn,
|
|
2248
|
-
retryDelay: 1e3,
|
|
2249
|
-
queryKey: queryKeys.rpc.getAllCoinBalances(owner),
|
|
2250
|
-
queryFn: async () => {
|
|
2251
|
-
const allBalances = await callWithRateLimit(
|
|
2252
|
-
this.tokenBucket,
|
|
2253
|
-
async () => await this.client.getAllBalances({ owner })
|
|
2254
|
-
);
|
|
2255
|
-
if (!allBalances)
|
|
2256
|
-
return {};
|
|
2257
|
-
const balances = allBalances.reduce(
|
|
2258
|
-
(acc, coinBalance) => {
|
|
2259
|
-
if (coinBalance.totalBalance !== "0") {
|
|
2260
|
-
acc[(0, import_sui_kit.normalizeStructTag)(coinBalance.coinType)] = coinBalance.totalBalance;
|
|
2261
|
-
}
|
|
2262
|
-
return acc;
|
|
2263
|
-
},
|
|
2264
|
-
{}
|
|
2265
|
-
);
|
|
2266
|
-
return balances;
|
|
2267
|
-
}
|
|
2268
|
-
});
|
|
2269
|
-
}
|
|
2270
|
-
async queryGetCoinBalance(input) {
|
|
2271
|
-
if (!input.coinType)
|
|
2272
|
-
return "0";
|
|
2273
|
-
return (await this.queryGetAllCoinBalances(input.owner) ?? {})[(0, import_sui_kit.normalizeStructTag)(input.coinType)] ?? "0";
|
|
2274
|
-
}
|
|
2275
|
-
};
|
|
2276
|
-
|
|
2277
|
-
// src/models/scallopAddress.ts
|
|
2278
|
-
var import_axios = __toESM(require("axios"));
|
|
2279
|
-
var EMPTY_ADDRESSES = {
|
|
2280
|
-
core: {
|
|
2281
|
-
version: "",
|
|
2282
|
-
versionCap: "",
|
|
2283
|
-
object: "",
|
|
2284
|
-
market: "",
|
|
2285
|
-
adminCap: "",
|
|
2286
|
-
coinDecimalsRegistry: "",
|
|
2287
|
-
obligationAccessStore: "",
|
|
2288
|
-
coins: {
|
|
2289
|
-
cetus: {
|
|
1726
|
+
},
|
|
1727
|
+
wbtc: {
|
|
2290
1728
|
id: "",
|
|
2291
1729
|
metaData: "",
|
|
2292
1730
|
treasury: "",
|
|
@@ -2299,7 +1737,7 @@ var EMPTY_ADDRESSES = {
|
|
|
2299
1737
|
}
|
|
2300
1738
|
}
|
|
2301
1739
|
},
|
|
2302
|
-
|
|
1740
|
+
weth: {
|
|
2303
1741
|
id: "",
|
|
2304
1742
|
metaData: "",
|
|
2305
1743
|
treasury: "",
|
|
@@ -2312,7 +1750,7 @@ var EMPTY_ADDRESSES = {
|
|
|
2312
1750
|
}
|
|
2313
1751
|
}
|
|
2314
1752
|
},
|
|
2315
|
-
|
|
1753
|
+
wusdc: {
|
|
2316
1754
|
id: "",
|
|
2317
1755
|
metaData: "",
|
|
2318
1756
|
treasury: "",
|
|
@@ -2325,7 +1763,7 @@ var EMPTY_ADDRESSES = {
|
|
|
2325
1763
|
}
|
|
2326
1764
|
}
|
|
2327
1765
|
},
|
|
2328
|
-
|
|
1766
|
+
wusdt: {
|
|
2329
1767
|
id: "",
|
|
2330
1768
|
metaData: "",
|
|
2331
1769
|
treasury: "",
|
|
@@ -2338,7 +1776,7 @@ var EMPTY_ADDRESSES = {
|
|
|
2338
1776
|
}
|
|
2339
1777
|
}
|
|
2340
1778
|
},
|
|
2341
|
-
|
|
1779
|
+
sui: {
|
|
2342
1780
|
id: "",
|
|
2343
1781
|
metaData: "",
|
|
2344
1782
|
treasury: "",
|
|
@@ -2351,46 +1789,7 @@ var EMPTY_ADDRESSES = {
|
|
|
2351
1789
|
}
|
|
2352
1790
|
}
|
|
2353
1791
|
},
|
|
2354
|
-
|
|
2355
|
-
id: "",
|
|
2356
|
-
metaData: "",
|
|
2357
|
-
treasury: "",
|
|
2358
|
-
oracle: {
|
|
2359
|
-
supra: "",
|
|
2360
|
-
switchboard: "",
|
|
2361
|
-
pyth: {
|
|
2362
|
-
feed: "",
|
|
2363
|
-
feedObject: ""
|
|
2364
|
-
}
|
|
2365
|
-
}
|
|
2366
|
-
},
|
|
2367
|
-
wusdt: {
|
|
2368
|
-
id: "",
|
|
2369
|
-
metaData: "",
|
|
2370
|
-
treasury: "",
|
|
2371
|
-
oracle: {
|
|
2372
|
-
supra: "",
|
|
2373
|
-
switchboard: "",
|
|
2374
|
-
pyth: {
|
|
2375
|
-
feed: "",
|
|
2376
|
-
feedObject: ""
|
|
2377
|
-
}
|
|
2378
|
-
}
|
|
2379
|
-
},
|
|
2380
|
-
sui: {
|
|
2381
|
-
id: "",
|
|
2382
|
-
metaData: "",
|
|
2383
|
-
treasury: "",
|
|
2384
|
-
oracle: {
|
|
2385
|
-
supra: "",
|
|
2386
|
-
switchboard: "",
|
|
2387
|
-
pyth: {
|
|
2388
|
-
feed: "",
|
|
2389
|
-
feedObject: ""
|
|
2390
|
-
}
|
|
2391
|
-
}
|
|
2392
|
-
},
|
|
2393
|
-
afsui: {
|
|
1792
|
+
afsui: {
|
|
2394
1793
|
id: "",
|
|
2395
1794
|
metaData: "",
|
|
2396
1795
|
treasury: "",
|
|
@@ -2606,346 +2005,963 @@ var EMPTY_ADDRESSES = {
|
|
|
2606
2005
|
coinType: "",
|
|
2607
2006
|
treasury: ""
|
|
2608
2007
|
},
|
|
2609
|
-
shasui: {
|
|
2610
|
-
coinType: "",
|
|
2611
|
-
treasury: ""
|
|
2008
|
+
shasui: {
|
|
2009
|
+
coinType: "",
|
|
2010
|
+
treasury: ""
|
|
2011
|
+
},
|
|
2012
|
+
svsui: {
|
|
2013
|
+
coinType: "",
|
|
2014
|
+
treasury: ""
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
};
|
|
2019
|
+
var ScallopAddress = class {
|
|
2020
|
+
constructor(params, instance) {
|
|
2021
|
+
const { id, auth, network, forceInterface } = params;
|
|
2022
|
+
this.cache = instance?.cache ?? new ScallopCache({});
|
|
2023
|
+
this._requestClient = import_axios.default.create({
|
|
2024
|
+
baseURL: API_BASE_URL,
|
|
2025
|
+
headers: {
|
|
2026
|
+
"Content-Type": "application/json",
|
|
2027
|
+
Accept: "application/json"
|
|
2028
|
+
},
|
|
2029
|
+
timeout: 8e3
|
|
2030
|
+
});
|
|
2031
|
+
if (auth)
|
|
2032
|
+
this._auth = auth;
|
|
2033
|
+
this._id = id;
|
|
2034
|
+
this._network = network ?? "mainnet";
|
|
2035
|
+
this._addressesMap = USE_TEST_ADDRESS ? /* @__PURE__ */ new Map([["mainnet", TEST_ADDRESSES]]) : /* @__PURE__ */ new Map();
|
|
2036
|
+
if (USE_TEST_ADDRESS)
|
|
2037
|
+
this._currentAddresses = TEST_ADDRESSES;
|
|
2038
|
+
if (forceInterface) {
|
|
2039
|
+
for (const [network2, addresses] of Object.entries(
|
|
2040
|
+
forceInterface
|
|
2041
|
+
)) {
|
|
2042
|
+
if (["localnet", "devnet", "testnet", "mainnet"].includes(network2)) {
|
|
2043
|
+
if (network2 === this._network)
|
|
2044
|
+
this._currentAddresses = addresses;
|
|
2045
|
+
this._addressesMap.set(network2, addresses);
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
2050
|
+
/**
|
|
2051
|
+
* Get addresses API id.
|
|
2052
|
+
*
|
|
2053
|
+
* @return The addresses API id.
|
|
2054
|
+
*/
|
|
2055
|
+
getId() {
|
|
2056
|
+
return this._id || void 0;
|
|
2057
|
+
}
|
|
2058
|
+
/**
|
|
2059
|
+
* Get the address at the provided path.
|
|
2060
|
+
*
|
|
2061
|
+
* @param path - The path of the address to get.
|
|
2062
|
+
* @return The address at the provided path.
|
|
2063
|
+
*/
|
|
2064
|
+
get(path) {
|
|
2065
|
+
if (this._currentAddresses) {
|
|
2066
|
+
const value = path.split(".").reduce(
|
|
2067
|
+
(nestedAddressObj, key) => typeof nestedAddressObj === "object" ? nestedAddressObj[key] : nestedAddressObj,
|
|
2068
|
+
this._currentAddresses
|
|
2069
|
+
);
|
|
2070
|
+
return value || void 0;
|
|
2071
|
+
} else {
|
|
2072
|
+
return void 0;
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
/**
|
|
2076
|
+
* Sets the address for the specified path, it does not interact with the API.
|
|
2077
|
+
*
|
|
2078
|
+
* @param path - The path of the address to set.
|
|
2079
|
+
* @param address - The address be setted to the tartget path.
|
|
2080
|
+
* @return The addresses.
|
|
2081
|
+
*/
|
|
2082
|
+
set(path, address) {
|
|
2083
|
+
if (this._currentAddresses) {
|
|
2084
|
+
const keys = path.split(".");
|
|
2085
|
+
keys.reduce((nestedAddressObj, key, index) => {
|
|
2086
|
+
if (index === keys.length - 1) {
|
|
2087
|
+
nestedAddressObj[key] = address;
|
|
2088
|
+
} else {
|
|
2089
|
+
return nestedAddressObj[key];
|
|
2090
|
+
}
|
|
2091
|
+
}, this._currentAddresses);
|
|
2092
|
+
}
|
|
2093
|
+
return this._currentAddresses;
|
|
2094
|
+
}
|
|
2095
|
+
/**
|
|
2096
|
+
* Synchronize the specified network addresses from the addresses map to the
|
|
2097
|
+
* current addresses and change the default network to specified network.
|
|
2098
|
+
*
|
|
2099
|
+
* @param network - Specifies which network's addresses you want to get.
|
|
2100
|
+
* @return Current addresses.
|
|
2101
|
+
*/
|
|
2102
|
+
switchCurrentAddresses(network) {
|
|
2103
|
+
if (this._addressesMap.has(network)) {
|
|
2104
|
+
this._currentAddresses = this._addressesMap.get(network);
|
|
2105
|
+
this._network = network;
|
|
2106
|
+
}
|
|
2107
|
+
return this._currentAddresses;
|
|
2108
|
+
}
|
|
2109
|
+
/**
|
|
2110
|
+
* Get the addresses, If `network` is not provided, returns the current
|
|
2111
|
+
* addresses or the default network addresses in the addresses map.
|
|
2112
|
+
*
|
|
2113
|
+
* @param network - Specifies which network's addresses you want to get.
|
|
2114
|
+
*/
|
|
2115
|
+
getAddresses(network) {
|
|
2116
|
+
if (network) {
|
|
2117
|
+
return this._addressesMap.get(network);
|
|
2118
|
+
} else {
|
|
2119
|
+
return this._currentAddresses ?? this._addressesMap.get(this._network);
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
/**
|
|
2123
|
+
* Set the addresses into addresses map. If the specified network is the same
|
|
2124
|
+
* as the current network, the current addresses will be updated at the same time.
|
|
2125
|
+
*
|
|
2126
|
+
* @param addresses - The addresses be setted to the tartget network.
|
|
2127
|
+
* @param network - Specifies which network's addresses you want to set.
|
|
2128
|
+
* @return The addresses.
|
|
2129
|
+
*/
|
|
2130
|
+
setAddresses(addresses, network) {
|
|
2131
|
+
const targetNetwork = network || this._network;
|
|
2132
|
+
if (targetNetwork === this._network)
|
|
2133
|
+
this._currentAddresses = addresses;
|
|
2134
|
+
this._addressesMap.set(targetNetwork, addresses);
|
|
2135
|
+
}
|
|
2136
|
+
/**
|
|
2137
|
+
* Get all addresses.
|
|
2138
|
+
*
|
|
2139
|
+
* @return All addresses.
|
|
2140
|
+
*/
|
|
2141
|
+
getAllAddresses() {
|
|
2142
|
+
return Object.fromEntries(this._addressesMap);
|
|
2143
|
+
}
|
|
2144
|
+
/**
|
|
2145
|
+
* Create a new addresses through the API and synchronize it back to the
|
|
2146
|
+
* instance.
|
|
2147
|
+
*
|
|
2148
|
+
* @description
|
|
2149
|
+
* If the `network` is not specified, the mainnet is used by default.
|
|
2150
|
+
* If no `addresses` from instance or parameter is provided, an addresses with
|
|
2151
|
+
* all empty strings is created by default.
|
|
2152
|
+
*
|
|
2153
|
+
* This function only allows for one addresses to be input into a specific network
|
|
2154
|
+
* at a time, and does not provide an addresses map for setting addresses
|
|
2155
|
+
* across all networks at once.
|
|
2156
|
+
*
|
|
2157
|
+
* @param params.addresses - The addresses be setted to the tartget network.
|
|
2158
|
+
* @param params.network - Specifies which network's addresses you want to set.
|
|
2159
|
+
* @param params.auth - The authentication API key.
|
|
2160
|
+
* @param params.memo - Add memo to the addresses created in the API.
|
|
2161
|
+
* @return All addresses.
|
|
2162
|
+
*/
|
|
2163
|
+
async create(params) {
|
|
2164
|
+
const { addresses, network, auth, memo } = params ?? {};
|
|
2165
|
+
const apiKey = auth || this._auth || void 0;
|
|
2166
|
+
const targetNetwork = network || this._network;
|
|
2167
|
+
const targetAddresses = addresses || this._currentAddresses || this._addressesMap.get(targetNetwork) || EMPTY_ADDRESSES;
|
|
2168
|
+
if (apiKey !== void 0) {
|
|
2169
|
+
this._addressesMap.clear();
|
|
2170
|
+
this.setAddresses(targetAddresses, targetNetwork);
|
|
2171
|
+
const response = await this._requestClient.post(
|
|
2172
|
+
`/addresses`,
|
|
2173
|
+
JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
|
|
2174
|
+
{
|
|
2175
|
+
headers: {
|
|
2176
|
+
"Content-Type": "application/json",
|
|
2177
|
+
"api-key": auth || this._auth
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
);
|
|
2181
|
+
if (response.status === 201) {
|
|
2182
|
+
for (const [network2, addresses2] of Object.entries(
|
|
2183
|
+
response.data
|
|
2184
|
+
)) {
|
|
2185
|
+
if (["localnet", "devnet", "testnet", "mainnet"].includes(network2)) {
|
|
2186
|
+
if (network2 === this._network)
|
|
2187
|
+
this._currentAddresses = addresses2;
|
|
2188
|
+
this._addressesMap.set(network2, addresses2);
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
this._id = response.data.id;
|
|
2192
|
+
return this.getAllAddresses();
|
|
2193
|
+
} else {
|
|
2194
|
+
throw Error("Failed to create addresses.");
|
|
2195
|
+
}
|
|
2196
|
+
} else {
|
|
2197
|
+
throw Error("You don't have permission to access this request.");
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
/**
|
|
2201
|
+
* Read and synchronizes all addresses from the API into instance.
|
|
2202
|
+
*
|
|
2203
|
+
* @param id - The id of the addresses to get.
|
|
2204
|
+
* @return All addresses.
|
|
2205
|
+
*/
|
|
2206
|
+
async read(id) {
|
|
2207
|
+
const addressesId = id || this._id || void 0;
|
|
2208
|
+
if (addressesId !== void 0) {
|
|
2209
|
+
const response = await this.cache.queryClient.fetchQuery({
|
|
2210
|
+
queryKey: queryKeys.api.getAddresses(addressesId),
|
|
2211
|
+
queryFn: async () => {
|
|
2212
|
+
return await this._requestClient.get(`/addresses/${addressesId}`, {
|
|
2213
|
+
headers: {
|
|
2214
|
+
"Content-Type": "application/json"
|
|
2215
|
+
}
|
|
2216
|
+
});
|
|
2217
|
+
}
|
|
2218
|
+
});
|
|
2219
|
+
if (response.status === 200) {
|
|
2220
|
+
for (const [network, addresses] of Object.entries(
|
|
2221
|
+
response.data
|
|
2222
|
+
)) {
|
|
2223
|
+
if (["localnet", "devnet", "testnet", "mainnet"].includes(network)) {
|
|
2224
|
+
if (network === this._network)
|
|
2225
|
+
this._currentAddresses = addresses;
|
|
2226
|
+
this._addressesMap.set(network, addresses);
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
this._id = response.data.id;
|
|
2230
|
+
return this.getAllAddresses();
|
|
2231
|
+
} else {
|
|
2232
|
+
throw Error("Failed to create addresses.");
|
|
2233
|
+
}
|
|
2234
|
+
} else {
|
|
2235
|
+
throw Error("Please provide API addresses id.");
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
/**
|
|
2239
|
+
* Update the addresses through the API and synchronize it back to the
|
|
2240
|
+
* instance.
|
|
2241
|
+
*
|
|
2242
|
+
* @description
|
|
2243
|
+
* If the `network` is not specified, the mainnet is used by default.
|
|
2244
|
+
* If no `addresses` from instance or parameter is provided, an addresses with
|
|
2245
|
+
* all empty strings is created by default.
|
|
2246
|
+
*
|
|
2247
|
+
* This function only allows for one addresses to be input into a specific network
|
|
2248
|
+
* at a time, and does not provide an addresses map for setting addresses
|
|
2249
|
+
* across all networks at once.
|
|
2250
|
+
*
|
|
2251
|
+
* @param params.id - The id of the addresses to update.
|
|
2252
|
+
* @param params.addresses - The addresses be setted to the tartget network.
|
|
2253
|
+
* @param params.network - Specifies which network's addresses you want to set.
|
|
2254
|
+
* @param params.auth - The authentication api key.
|
|
2255
|
+
* @param params.memo - Add memo to the addresses created in the API.
|
|
2256
|
+
* @return All addresses.
|
|
2257
|
+
*/
|
|
2258
|
+
async update(params) {
|
|
2259
|
+
const { id, addresses, network, auth, memo } = params ?? {};
|
|
2260
|
+
const apiKey = auth || this._auth || void 0;
|
|
2261
|
+
const targetId = id || this._id || void 0;
|
|
2262
|
+
const targetNetwork = network || this._network;
|
|
2263
|
+
const targetAddresses = addresses || this._currentAddresses || this._addressesMap.get(targetNetwork) || EMPTY_ADDRESSES;
|
|
2264
|
+
if (targetId === void 0)
|
|
2265
|
+
throw Error("Require specific addresses id to be updated.");
|
|
2266
|
+
if (apiKey !== void 0) {
|
|
2267
|
+
if (id !== this._id) {
|
|
2268
|
+
this._addressesMap.clear();
|
|
2269
|
+
}
|
|
2270
|
+
this.setAddresses(targetAddresses, targetNetwork);
|
|
2271
|
+
const response = await this._requestClient.put(
|
|
2272
|
+
`/addresses/${targetId}`,
|
|
2273
|
+
JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
|
|
2274
|
+
{
|
|
2275
|
+
headers: {
|
|
2276
|
+
"Content-Type": "application/json",
|
|
2277
|
+
"api-key": auth || this._auth
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
);
|
|
2281
|
+
if (response.status === 200) {
|
|
2282
|
+
for (const [network2, addresses2] of Object.entries(
|
|
2283
|
+
response.data
|
|
2284
|
+
)) {
|
|
2285
|
+
if (["localnet", "devnet", "testnet", "mainnet"].includes(network2)) {
|
|
2286
|
+
if (network2 === this._network)
|
|
2287
|
+
this._currentAddresses = addresses2;
|
|
2288
|
+
this._addressesMap.set(network2, addresses2);
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
this._id = response.data.id;
|
|
2292
|
+
return this.getAllAddresses();
|
|
2293
|
+
} else {
|
|
2294
|
+
throw Error("Failed to update addresses.");
|
|
2295
|
+
}
|
|
2296
|
+
} else {
|
|
2297
|
+
throw Error("You don't have permission to access this request.");
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
/**
|
|
2301
|
+
* Deletes all addresses of a specified id through the API and clear all
|
|
2302
|
+
* addresses in the instance.
|
|
2303
|
+
*
|
|
2304
|
+
* @param id - The id of the addresses to delete.
|
|
2305
|
+
* @param auth - The authentication API key.
|
|
2306
|
+
*/
|
|
2307
|
+
async delete(id, auth) {
|
|
2308
|
+
const apiKey = auth || this._auth || void 0;
|
|
2309
|
+
const targetId = id || this._id || void 0;
|
|
2310
|
+
if (targetId === void 0)
|
|
2311
|
+
throw Error("Require specific addresses id to be deleted.");
|
|
2312
|
+
if (apiKey !== void 0) {
|
|
2313
|
+
const response = await this._requestClient.delete(
|
|
2314
|
+
`/addresses/${targetId}`,
|
|
2315
|
+
{
|
|
2316
|
+
headers: {
|
|
2317
|
+
"Content-Type": "application/json",
|
|
2318
|
+
"api-key": auth || this._auth
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
);
|
|
2322
|
+
if (response.status === 200) {
|
|
2323
|
+
this._id = void 0;
|
|
2324
|
+
this._currentAddresses = void 0;
|
|
2325
|
+
this._addressesMap.clear();
|
|
2326
|
+
} else {
|
|
2327
|
+
throw Error("Failed to delete addresses.");
|
|
2328
|
+
}
|
|
2329
|
+
} else {
|
|
2330
|
+
throw Error("You don't have permission to access this request.");
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
};
|
|
2334
|
+
|
|
2335
|
+
// src/models/scallopClient.ts
|
|
2336
|
+
var import_utils25 = require("@mysten/sui/utils");
|
|
2337
|
+
|
|
2338
|
+
// src/models/scallopUtils.ts
|
|
2339
|
+
var import_utils10 = require("@mysten/sui/utils");
|
|
2340
|
+
var import_pyth_sui_js = require("@pythnetwork/pyth-sui-js");
|
|
2341
|
+
|
|
2342
|
+
// src/queries/borrowIncentiveQuery.ts
|
|
2343
|
+
var import_utils2 = require("@mysten/sui/utils");
|
|
2344
|
+
|
|
2345
|
+
// src/utils/builder.ts
|
|
2346
|
+
var requireSender = (txBlock) => {
|
|
2347
|
+
const sender = txBlock.blockData.sender;
|
|
2348
|
+
if (!sender) {
|
|
2349
|
+
throw new Error("Sender is required");
|
|
2350
|
+
}
|
|
2351
|
+
return sender;
|
|
2352
|
+
};
|
|
2353
|
+
var checkVesca = (prevUnlockAtInMillisTimestamp) => {
|
|
2354
|
+
if (prevUnlockAtInMillisTimestamp === void 0) {
|
|
2355
|
+
throw new Error("veSca not found");
|
|
2356
|
+
}
|
|
2357
|
+
};
|
|
2358
|
+
var checkVescaExpired = (prevUnlockAtInMillisTimestamp) => {
|
|
2359
|
+
if (prevUnlockAtInMillisTimestamp <= (/* @__PURE__ */ new Date()).getTime()) {
|
|
2360
|
+
throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
|
|
2361
|
+
}
|
|
2362
|
+
};
|
|
2363
|
+
var checkExtendLockPeriod = (lockPeriodInDays, newUnlockAtInSecondTimestamp, prevUnlockAtInMillisTimestamp) => {
|
|
2364
|
+
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
2365
|
+
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
2366
|
+
const prevUnlockAtInSecondTimestamp = Math.floor(
|
|
2367
|
+
prevUnlockAtInMillisTimestamp / 1e3
|
|
2368
|
+
);
|
|
2369
|
+
if (lockPeriodInDays < 1) {
|
|
2370
|
+
throw new Error("Minimum lock period is 1 day");
|
|
2371
|
+
}
|
|
2372
|
+
const availableLockPeriodInDays = Math.floor(
|
|
2373
|
+
(newUnlockAtInSecondTimestamp - prevUnlockAtInSecondTimestamp) / UNLOCK_ROUND_DURATION
|
|
2374
|
+
);
|
|
2375
|
+
if (lockPeriodInDays > availableLockPeriodInDays) {
|
|
2376
|
+
throw new Error(
|
|
2377
|
+
`Cannot extend lock period by ${lockPeriodInDays} days, maximum lock period is ~4 years (${MAX_LOCK_ROUNDS} days), remaining lock period is ${MAX_LOCK_ROUNDS - availableLockPeriodInDays}`
|
|
2378
|
+
);
|
|
2379
|
+
}
|
|
2380
|
+
};
|
|
2381
|
+
var checkLockSca = (scaAmountOrCoin, lockPeriodInDays, newUnlockAtInSecondTimestamp, prevUnlockAtInMillisTimestamp) => {
|
|
2382
|
+
const prevUnlockAtInSecondTimestamp = prevUnlockAtInMillisTimestamp ? Math.floor(prevUnlockAtInMillisTimestamp / 1e3) : void 0;
|
|
2383
|
+
const isInitialLock = !prevUnlockAtInSecondTimestamp;
|
|
2384
|
+
const isLockExpired = !isInitialLock && prevUnlockAtInSecondTimestamp * 1e3 <= (/* @__PURE__ */ new Date()).getTime();
|
|
2385
|
+
if (isInitialLock || isLockExpired) {
|
|
2386
|
+
if (scaAmountOrCoin !== void 0 && lockPeriodInDays !== void 0) {
|
|
2387
|
+
if (lockPeriodInDays <= 0) {
|
|
2388
|
+
throw new Error("Lock period must be greater than 0");
|
|
2389
|
+
}
|
|
2390
|
+
if (typeof scaAmountOrCoin === "number" && scaAmountOrCoin < MIN_INITIAL_LOCK_AMOUNT) {
|
|
2391
|
+
throw new Error(
|
|
2392
|
+
`Minimum lock amount for ${isLockExpired ? "renewing expired veSca" : "initial lock"} is 10 SCA`
|
|
2393
|
+
);
|
|
2394
|
+
}
|
|
2395
|
+
const extendLockPeriodInSecond = lockPeriodInDays * UNLOCK_ROUND_DURATION;
|
|
2396
|
+
if (extendLockPeriodInSecond > MAX_LOCK_DURATION) {
|
|
2397
|
+
throw new Error(
|
|
2398
|
+
`Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS} days)`
|
|
2399
|
+
);
|
|
2400
|
+
}
|
|
2401
|
+
} else {
|
|
2402
|
+
throw new Error(
|
|
2403
|
+
`SCA amount and lock period is required for ${isLockExpired ? "renewing expired veSca" : "initial lock"}`
|
|
2404
|
+
);
|
|
2405
|
+
}
|
|
2406
|
+
} else {
|
|
2407
|
+
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
2408
|
+
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
2409
|
+
if (typeof scaAmountOrCoin === "number" && scaAmountOrCoin < MIN_TOP_UP_AMOUNT) {
|
|
2410
|
+
throw new Error("Minimum top up amount is 1 SCA");
|
|
2411
|
+
}
|
|
2412
|
+
if (newUnlockAtInSecondTimestamp && lockPeriodInDays) {
|
|
2413
|
+
checkExtendLockPeriod(
|
|
2414
|
+
lockPeriodInDays,
|
|
2415
|
+
newUnlockAtInSecondTimestamp,
|
|
2416
|
+
prevUnlockAtInMillisTimestamp
|
|
2417
|
+
);
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
};
|
|
2421
|
+
var checkExtendLockAmount = (scaAmount, prevUnlockAtInMillisTimestamp) => {
|
|
2422
|
+
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
2423
|
+
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
2424
|
+
if (scaAmount < MIN_TOP_UP_AMOUNT) {
|
|
2425
|
+
throw new Error("Minimum top up amount is 1 SCA");
|
|
2426
|
+
}
|
|
2427
|
+
const isInitialLock = !prevUnlockAtInMillisTimestamp;
|
|
2428
|
+
const isLockExpired = !isInitialLock && prevUnlockAtInMillisTimestamp <= (/* @__PURE__ */ new Date()).getTime();
|
|
2429
|
+
if (isLockExpired) {
|
|
2430
|
+
throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
|
|
2431
|
+
}
|
|
2432
|
+
};
|
|
2433
|
+
var checkRenewExpiredVeSca = (scaAmount, lockPeriodInDays, prevUnlockAtInMillisTimestamp) => {
|
|
2434
|
+
if (!prevUnlockAtInMillisTimestamp || prevUnlockAtInMillisTimestamp > (/* @__PURE__ */ new Date()).getTime()) {
|
|
2435
|
+
throw new Error("Renew method can only be used for expired veSca");
|
|
2436
|
+
}
|
|
2437
|
+
if (scaAmount < MIN_INITIAL_LOCK_AMOUNT) {
|
|
2438
|
+
throw new Error("Minimum lock amount for renewing expired vesca 10 SCA");
|
|
2439
|
+
}
|
|
2440
|
+
const extendLockPeriodInSecond = lockPeriodInDays * UNLOCK_ROUND_DURATION;
|
|
2441
|
+
if (extendLockPeriodInSecond >= MAX_LOCK_DURATION - UNLOCK_ROUND_DURATION) {
|
|
2442
|
+
throw new Error(
|
|
2443
|
+
`Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS - 1} days)`
|
|
2444
|
+
);
|
|
2445
|
+
}
|
|
2446
|
+
};
|
|
2447
|
+
|
|
2448
|
+
// src/utils/query.ts
|
|
2449
|
+
var import_bignumber = __toESM(require("bignumber.js"));
|
|
2450
|
+
var import_utils = require("@mysten/sui/utils");
|
|
2451
|
+
var parseOriginMarketPoolData = (originMarketPoolData) => {
|
|
2452
|
+
return {
|
|
2453
|
+
coinType: (0, import_utils.normalizeStructTag)(originMarketPoolData.type.name),
|
|
2454
|
+
// Parse origin data required for basic calculations.
|
|
2455
|
+
maxBorrowRate: Number(originMarketPoolData.maxBorrowRate.value) / 2 ** 32,
|
|
2456
|
+
borrowRate: Number(originMarketPoolData.interestRate.value) / 2 ** 32,
|
|
2457
|
+
borrowRateScale: Number(originMarketPoolData.interestRateScale),
|
|
2458
|
+
borrowIndex: Number(originMarketPoolData.borrowIndex),
|
|
2459
|
+
lastUpdated: Number(originMarketPoolData.lastUpdated),
|
|
2460
|
+
cashAmount: Number(originMarketPoolData.cash),
|
|
2461
|
+
debtAmount: Number(originMarketPoolData.debt),
|
|
2462
|
+
marketCoinSupplyAmount: Number(originMarketPoolData.marketCoinSupply),
|
|
2463
|
+
reserveAmount: Number(originMarketPoolData.reserve),
|
|
2464
|
+
reserveFactor: Number(originMarketPoolData.reserveFactor.value) / 2 ** 32,
|
|
2465
|
+
borrowWeight: Number(originMarketPoolData.borrowWeight.value) / 2 ** 32,
|
|
2466
|
+
borrowFee: Number(originMarketPoolData.borrowFeeRate.value) / 2 ** 32,
|
|
2467
|
+
// Parse origin data required for additional display.
|
|
2468
|
+
baseBorrowRate: Number(originMarketPoolData.baseBorrowRatePerSec.value) / 2 ** 32,
|
|
2469
|
+
borrowRateOnHighKink: Number(originMarketPoolData.borrowRateOnHighKink.value) / 2 ** 32,
|
|
2470
|
+
borrowRateOnMidKink: Number(originMarketPoolData.borrowRateOnMidKink.value) / 2 ** 32,
|
|
2471
|
+
highKink: Number(originMarketPoolData.highKink.value) / 2 ** 32,
|
|
2472
|
+
midKink: Number(originMarketPoolData.midKink.value) / 2 ** 32,
|
|
2473
|
+
minBorrowAmount: Number(originMarketPoolData.minBorrowAmount),
|
|
2474
|
+
isIsolated: originMarketPoolData.isIsolated,
|
|
2475
|
+
supplyLimit: Number(originMarketPoolData.supplyLimit),
|
|
2476
|
+
borrowLimit: Number(originMarketPoolData.borrowLimit)
|
|
2477
|
+
};
|
|
2478
|
+
};
|
|
2479
|
+
var calculateMarketPoolData = (utils, parsedMarketPoolData) => {
|
|
2480
|
+
const poolCoinName = utils.parseCoinNameFromType(
|
|
2481
|
+
parsedMarketPoolData.coinType
|
|
2482
|
+
);
|
|
2483
|
+
const coinDecimal = utils.getCoinDecimal(poolCoinName);
|
|
2484
|
+
const borrowYearFactor = 24 * 365 * 3600;
|
|
2485
|
+
const baseBorrowApr = parsedMarketPoolData.baseBorrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
2486
|
+
const borrowAprOnHighKink = parsedMarketPoolData.borrowRateOnHighKink * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
2487
|
+
const borrowAprOnMidKink = parsedMarketPoolData.borrowRateOnMidKink * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
2488
|
+
const maxBorrowApr = parsedMarketPoolData.maxBorrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
2489
|
+
const borrowApr = parsedMarketPoolData.borrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
2490
|
+
const timeDelta = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedMarketPoolData.lastUpdated;
|
|
2491
|
+
const borrowIndexDelta = (0, import_bignumber.default)(parsedMarketPoolData.borrowIndex).multipliedBy(
|
|
2492
|
+
(0, import_bignumber.default)(timeDelta).multipliedBy(parsedMarketPoolData.borrowRate)
|
|
2493
|
+
).dividedBy(parsedMarketPoolData.borrowRateScale);
|
|
2494
|
+
const currentBorrowIndex = (0, import_bignumber.default)(parsedMarketPoolData.borrowIndex).plus(
|
|
2495
|
+
borrowIndexDelta
|
|
2496
|
+
);
|
|
2497
|
+
const growthInterest = (0, import_bignumber.default)(currentBorrowIndex).dividedBy(parsedMarketPoolData.borrowIndex).minus(1);
|
|
2498
|
+
const increasedDebtAmount = (0, import_bignumber.default)(
|
|
2499
|
+
parsedMarketPoolData.debtAmount
|
|
2500
|
+
).multipliedBy(growthInterest);
|
|
2501
|
+
const borrowAmount = increasedDebtAmount.plus(
|
|
2502
|
+
parsedMarketPoolData.debtAmount
|
|
2503
|
+
);
|
|
2504
|
+
const borrowCoin = borrowAmount.shiftedBy(-1 * coinDecimal);
|
|
2505
|
+
const reserveAmount = (0, import_bignumber.default)(parsedMarketPoolData.reserveAmount).plus(
|
|
2506
|
+
increasedDebtAmount.multipliedBy(parsedMarketPoolData.reserveFactor)
|
|
2507
|
+
);
|
|
2508
|
+
const reserveCoin = reserveAmount.shiftedBy(-1 * coinDecimal);
|
|
2509
|
+
const supplyAmount = (0, import_bignumber.default)(borrowAmount).plus(
|
|
2510
|
+
Math.max(parsedMarketPoolData.cashAmount - reserveAmount.toNumber(), 0)
|
|
2511
|
+
);
|
|
2512
|
+
const supplyCoin = supplyAmount.shiftedBy(-1 * coinDecimal);
|
|
2513
|
+
let utilizationRate = (0, import_bignumber.default)(borrowAmount).dividedBy(supplyAmount);
|
|
2514
|
+
utilizationRate = utilizationRate.isFinite() ? utilizationRate : (0, import_bignumber.default)(0);
|
|
2515
|
+
let supplyApr = (0, import_bignumber.default)(borrowApr).multipliedBy(utilizationRate).multipliedBy(1 - parsedMarketPoolData.reserveFactor);
|
|
2516
|
+
supplyApr = supplyApr.isFinite() ? supplyApr : (0, import_bignumber.default)(0);
|
|
2517
|
+
let conversionRate = supplyAmount.dividedBy(
|
|
2518
|
+
parsedMarketPoolData.marketCoinSupplyAmount
|
|
2519
|
+
);
|
|
2520
|
+
conversionRate = conversionRate.isFinite() && !conversionRate.isNaN() ? conversionRate : (0, import_bignumber.default)(1);
|
|
2521
|
+
return {
|
|
2522
|
+
baseBorrowApr,
|
|
2523
|
+
baseBorrowApy: utils.parseAprToApy(baseBorrowApr),
|
|
2524
|
+
borrowAprOnHighKink,
|
|
2525
|
+
borrowApyOnHighKink: utils.parseAprToApy(borrowAprOnHighKink),
|
|
2526
|
+
borrowAprOnMidKink,
|
|
2527
|
+
borrowApyOnMidKink: utils.parseAprToApy(borrowAprOnMidKink),
|
|
2528
|
+
coinDecimal,
|
|
2529
|
+
maxBorrowApr,
|
|
2530
|
+
maxBorrowApy: utils.parseAprToApy(maxBorrowApr),
|
|
2531
|
+
borrowApr: Math.min(borrowApr, maxBorrowApr),
|
|
2532
|
+
borrowApy: Math.min(
|
|
2533
|
+
utils.parseAprToApy(borrowApr),
|
|
2534
|
+
utils.parseAprToApy(maxBorrowApr)
|
|
2535
|
+
),
|
|
2536
|
+
borrowIndex: currentBorrowIndex.toNumber(),
|
|
2537
|
+
growthInterest: growthInterest.toNumber(),
|
|
2538
|
+
supplyAmount: supplyAmount.toNumber(),
|
|
2539
|
+
supplyCoin: supplyCoin.toNumber(),
|
|
2540
|
+
borrowAmount: borrowAmount.toNumber(),
|
|
2541
|
+
borrowCoin: borrowCoin.toNumber(),
|
|
2542
|
+
reserveAmount: reserveAmount.toNumber(),
|
|
2543
|
+
reserveCoin: reserveCoin.toNumber(),
|
|
2544
|
+
utilizationRate: utilizationRate.toNumber(),
|
|
2545
|
+
supplyApr: supplyApr.toNumber(),
|
|
2546
|
+
supplyApy: utils.parseAprToApy(supplyApr.toNumber()),
|
|
2547
|
+
conversionRate: conversionRate.toNumber(),
|
|
2548
|
+
isIsolated: parsedMarketPoolData.isIsolated,
|
|
2549
|
+
maxSupplyCoin: (0, import_bignumber.default)(parsedMarketPoolData.supplyLimit).shiftedBy(-coinDecimal).toNumber(),
|
|
2550
|
+
maxBorrowCoin: (0, import_bignumber.default)(parsedMarketPoolData.borrowLimit).shiftedBy(-coinDecimal).toNumber()
|
|
2551
|
+
};
|
|
2552
|
+
};
|
|
2553
|
+
var parseOriginMarketCollateralData = (originMarketCollateralData) => {
|
|
2554
|
+
const divisor = 2 ** 32;
|
|
2555
|
+
return {
|
|
2556
|
+
coinType: (0, import_utils.normalizeStructTag)(originMarketCollateralData.type.name),
|
|
2557
|
+
isIsolated: originMarketCollateralData.isIsolated,
|
|
2558
|
+
collateralFactor: Number(originMarketCollateralData.collateralFactor.value) / divisor,
|
|
2559
|
+
liquidationFactor: Number(originMarketCollateralData.liquidationFactor.value) / divisor,
|
|
2560
|
+
liquidationDiscount: Number(originMarketCollateralData.liquidationDiscount.value) / divisor,
|
|
2561
|
+
liquidationPenalty: Number(originMarketCollateralData.liquidationPenalty.value) / divisor,
|
|
2562
|
+
liquidationReserveFactor: Number(originMarketCollateralData.liquidationReserveFactor.value) / divisor,
|
|
2563
|
+
maxCollateralAmount: Number(originMarketCollateralData.maxCollateralAmount),
|
|
2564
|
+
totalCollateralAmount: Number(
|
|
2565
|
+
originMarketCollateralData.totalCollateralAmount
|
|
2566
|
+
)
|
|
2567
|
+
};
|
|
2568
|
+
};
|
|
2569
|
+
var calculateMarketCollateralData = (utils, parsedMarketCollateralData) => {
|
|
2570
|
+
const collateralCoinName = utils.parseCoinNameFromType(
|
|
2571
|
+
parsedMarketCollateralData.coinType
|
|
2572
|
+
);
|
|
2573
|
+
const coinDecimal = utils.getCoinDecimal(collateralCoinName);
|
|
2574
|
+
const maxCollateralCoin = (0, import_bignumber.default)(
|
|
2575
|
+
parsedMarketCollateralData.maxCollateralAmount
|
|
2576
|
+
).shiftedBy(-1 * coinDecimal);
|
|
2577
|
+
const depositCoin = (0, import_bignumber.default)(
|
|
2578
|
+
parsedMarketCollateralData.totalCollateralAmount
|
|
2579
|
+
).shiftedBy(-1 * coinDecimal);
|
|
2580
|
+
return {
|
|
2581
|
+
coinDecimal,
|
|
2582
|
+
isIsolated: parsedMarketCollateralData.isIsolated,
|
|
2583
|
+
maxDepositAmount: parsedMarketCollateralData.maxCollateralAmount,
|
|
2584
|
+
maxDepositCoin: maxCollateralCoin.toNumber(),
|
|
2585
|
+
depositAmount: parsedMarketCollateralData.totalCollateralAmount,
|
|
2586
|
+
depositCoin: depositCoin.toNumber()
|
|
2587
|
+
};
|
|
2588
|
+
};
|
|
2589
|
+
var parseOriginSpoolData = (originSpoolData) => {
|
|
2590
|
+
return {
|
|
2591
|
+
stakeType: (0, import_utils.normalizeStructTag)(originSpoolData.stakeType.fields.name),
|
|
2592
|
+
maxPoint: Number(originSpoolData.maxDistributedPoint),
|
|
2593
|
+
distributedPoint: Number(originSpoolData.distributedPoint),
|
|
2594
|
+
pointPerPeriod: Number(originSpoolData.distributedPointPerPeriod),
|
|
2595
|
+
period: Number(originSpoolData.pointDistributionTime),
|
|
2596
|
+
maxStake: Number(originSpoolData.maxStake),
|
|
2597
|
+
staked: Number(originSpoolData.stakes),
|
|
2598
|
+
index: Number(originSpoolData.index),
|
|
2599
|
+
createdAt: Number(originSpoolData.createdAt),
|
|
2600
|
+
lastUpdate: Number(originSpoolData.lastUpdate)
|
|
2601
|
+
};
|
|
2602
|
+
};
|
|
2603
|
+
var calculateSpoolData = (parsedSpoolData, stakeMarketCoinPrice, stakeMarketCoinDecimal) => {
|
|
2604
|
+
const baseIndexRate = 1e9;
|
|
2605
|
+
const distributedPointPerSec = (0, import_bignumber.default)(
|
|
2606
|
+
parsedSpoolData.pointPerPeriod
|
|
2607
|
+
).dividedBy(parsedSpoolData.period);
|
|
2608
|
+
const pointPerSec = (0, import_bignumber.default)(parsedSpoolData.pointPerPeriod).dividedBy(
|
|
2609
|
+
parsedSpoolData.period
|
|
2610
|
+
);
|
|
2611
|
+
const remainingPeriod = pointPerSec.gt(0) ? (0, import_bignumber.default)(parsedSpoolData.maxPoint).minus(parsedSpoolData.distributedPoint).dividedBy(pointPerSec) : (0, import_bignumber.default)(0);
|
|
2612
|
+
const startDate = parsedSpoolData.createdAt;
|
|
2613
|
+
const endDate = remainingPeriod.plus(parsedSpoolData.lastUpdate).integerValue().toNumber();
|
|
2614
|
+
const timeDelta = (0, import_bignumber.default)(
|
|
2615
|
+
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedSpoolData.lastUpdate
|
|
2616
|
+
).dividedBy(parsedSpoolData.period).toFixed(0);
|
|
2617
|
+
const remainingPoints = (0, import_bignumber.default)(parsedSpoolData.maxPoint).minus(
|
|
2618
|
+
parsedSpoolData.distributedPoint
|
|
2619
|
+
);
|
|
2620
|
+
const accumulatedPoints = import_bignumber.default.minimum(
|
|
2621
|
+
(0, import_bignumber.default)(timeDelta).multipliedBy(parsedSpoolData.pointPerPeriod),
|
|
2622
|
+
remainingPoints
|
|
2623
|
+
);
|
|
2624
|
+
const currentPointIndex = (0, import_bignumber.default)(parsedSpoolData.index).plus(
|
|
2625
|
+
accumulatedPoints.dividedBy(parsedSpoolData.staked).isFinite() ? (0, import_bignumber.default)(baseIndexRate).multipliedBy(accumulatedPoints).dividedBy(parsedSpoolData.staked) : 0
|
|
2626
|
+
);
|
|
2627
|
+
const currentTotalDistributedPoint = (0, import_bignumber.default)(
|
|
2628
|
+
parsedSpoolData.distributedPoint
|
|
2629
|
+
).plus(accumulatedPoints);
|
|
2630
|
+
const stakedAmount = (0, import_bignumber.default)(parsedSpoolData.staked);
|
|
2631
|
+
const stakedCoin = stakedAmount.shiftedBy(-1 * stakeMarketCoinDecimal);
|
|
2632
|
+
const stakedValue = stakedCoin.multipliedBy(stakeMarketCoinPrice);
|
|
2633
|
+
return {
|
|
2634
|
+
distributedPointPerSec: distributedPointPerSec.toNumber(),
|
|
2635
|
+
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
2636
|
+
currentPointIndex: currentPointIndex.toNumber(),
|
|
2637
|
+
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
2638
|
+
startDate: new Date(startDate * 1e3),
|
|
2639
|
+
endDate: new Date(endDate * 1e3),
|
|
2640
|
+
stakedAmount: stakedAmount.toNumber(),
|
|
2641
|
+
stakedCoin: stakedCoin.toNumber(),
|
|
2642
|
+
stakedValue: stakedValue.toNumber()
|
|
2643
|
+
};
|
|
2644
|
+
};
|
|
2645
|
+
var parseOriginSpoolRewardPoolData = (originSpoolRewardPoolData) => {
|
|
2646
|
+
return {
|
|
2647
|
+
claimedRewards: Number(originSpoolRewardPoolData.claimed_rewards),
|
|
2648
|
+
exchangeRateDenominator: Number(
|
|
2649
|
+
originSpoolRewardPoolData.exchange_rate_denominator
|
|
2650
|
+
),
|
|
2651
|
+
exchangeRateNumerator: Number(
|
|
2652
|
+
originSpoolRewardPoolData.exchange_rate_numerator
|
|
2653
|
+
),
|
|
2654
|
+
rewards: Number(originSpoolRewardPoolData.rewards),
|
|
2655
|
+
spoolId: String(originSpoolRewardPoolData.spool_id)
|
|
2656
|
+
};
|
|
2657
|
+
};
|
|
2658
|
+
var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData, calculatedSpoolData, rewardCoinPrice, rewardCoinDecimal) => {
|
|
2659
|
+
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
2660
|
+
const rewardPerSec = (0, import_bignumber.default)(calculatedSpoolData.distributedPointPerSec).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
2661
|
+
const totalRewardAmount = (0, import_bignumber.default)(parsedSpoolData.maxPoint).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
2662
|
+
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
2663
|
+
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
2664
|
+
const remaindRewardAmount = (0, import_bignumber.default)(parsedSpoolRewardPoolData.rewards);
|
|
2665
|
+
const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
2666
|
+
-1 * rewardCoinDecimal
|
|
2667
|
+
);
|
|
2668
|
+
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
2669
|
+
const claimedRewardAmount = (0, import_bignumber.default)(
|
|
2670
|
+
parsedSpoolRewardPoolData.claimedRewards
|
|
2671
|
+
);
|
|
2672
|
+
const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
2673
|
+
-1 * rewardCoinDecimal
|
|
2674
|
+
);
|
|
2675
|
+
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
2676
|
+
const rewardValueForYear = (0, import_bignumber.default)(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
2677
|
+
let rewardRate = rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).toNumber() : Infinity;
|
|
2678
|
+
if (parsedSpoolData.maxPoint <= parsedSpoolData.distributedPoint || parsedSpoolData.pointPerPeriod === 0) {
|
|
2679
|
+
rewardRate = Infinity;
|
|
2680
|
+
}
|
|
2681
|
+
return {
|
|
2682
|
+
rewardApr: rewardRate,
|
|
2683
|
+
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
2684
|
+
totalRewardCoin: totalRewardCoin.toNumber(),
|
|
2685
|
+
totalRewardValue: totalRewardValue.toNumber(),
|
|
2686
|
+
remaindRewardAmount: remaindRewardAmount.toNumber(),
|
|
2687
|
+
remaindRewardCoin: remaindRewardCoin.toNumber(),
|
|
2688
|
+
remaindRewardValue: remaindRewardValue.toNumber(),
|
|
2689
|
+
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
2690
|
+
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
2691
|
+
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
2692
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
2693
|
+
};
|
|
2694
|
+
};
|
|
2695
|
+
var parseOriginBorrowIncentivesPoolPointData = (originBorrowIncentivePoolPointData) => {
|
|
2696
|
+
return {
|
|
2697
|
+
pointType: (0, import_utils.normalizeStructTag)(
|
|
2698
|
+
originBorrowIncentivePoolPointData.point_type.name
|
|
2699
|
+
),
|
|
2700
|
+
distributedPointPerPeriod: Number(
|
|
2701
|
+
originBorrowIncentivePoolPointData.distributed_point_per_period
|
|
2702
|
+
),
|
|
2703
|
+
period: Number(originBorrowIncentivePoolPointData.point_distribution_time),
|
|
2704
|
+
distributedPoint: Number(
|
|
2705
|
+
originBorrowIncentivePoolPointData.distributed_point
|
|
2706
|
+
),
|
|
2707
|
+
points: Number(originBorrowIncentivePoolPointData.points),
|
|
2708
|
+
index: Number(originBorrowIncentivePoolPointData.index),
|
|
2709
|
+
baseWeight: Number(originBorrowIncentivePoolPointData.base_weight),
|
|
2710
|
+
weightedAmount: Number(originBorrowIncentivePoolPointData.weighted_amount),
|
|
2711
|
+
lastUpdate: Number(originBorrowIncentivePoolPointData.last_update),
|
|
2712
|
+
createdAt: Number(originBorrowIncentivePoolPointData.created_at)
|
|
2713
|
+
};
|
|
2714
|
+
};
|
|
2715
|
+
var parseOriginBorrowIncentivePoolData = (utils, originBorrowIncentivePoolData) => {
|
|
2716
|
+
return {
|
|
2717
|
+
poolType: (0, import_utils.normalizeStructTag)(originBorrowIncentivePoolData.pool_type.name),
|
|
2718
|
+
minStakes: Number(originBorrowIncentivePoolData.min_stakes),
|
|
2719
|
+
maxStakes: Number(originBorrowIncentivePoolData.max_stakes),
|
|
2720
|
+
staked: Number(originBorrowIncentivePoolData.stakes),
|
|
2721
|
+
poolPoints: originBorrowIncentivePoolData.points.reduce(
|
|
2722
|
+
(acc, point) => {
|
|
2723
|
+
const parsed = parseOriginBorrowIncentivesPoolPointData(point);
|
|
2724
|
+
const name = utils.parseSCoinTypeNameToMarketCoinName(
|
|
2725
|
+
(0, import_utils.parseStructTag)(parsed.pointType).name.toLowerCase()
|
|
2726
|
+
);
|
|
2727
|
+
acc[name] = parsed;
|
|
2728
|
+
return acc;
|
|
2729
|
+
},
|
|
2730
|
+
{}
|
|
2731
|
+
)
|
|
2732
|
+
};
|
|
2733
|
+
};
|
|
2734
|
+
var calculateBorrowIncentivePoolPointData = (parsedBorrowIncentivePoolPointData, rewardCoinPrice, rewardCoinDecimal, poolCoinPrice, poolCoinDecimal) => {
|
|
2735
|
+
const baseIndexRate = 1e9;
|
|
2736
|
+
const distributedPointPerSec = (0, import_bignumber.default)(
|
|
2737
|
+
parsedBorrowIncentivePoolPointData.distributedPointPerPeriod
|
|
2738
|
+
).dividedBy(parsedBorrowIncentivePoolPointData.period);
|
|
2739
|
+
const timeDelta = (0, import_bignumber.default)(
|
|
2740
|
+
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedBorrowIncentivePoolPointData.lastUpdate
|
|
2741
|
+
).dividedBy(parsedBorrowIncentivePoolPointData.period).toFixed(0);
|
|
2742
|
+
const accumulatedPoints = import_bignumber.default.minimum(
|
|
2743
|
+
(0, import_bignumber.default)(timeDelta).multipliedBy(
|
|
2744
|
+
parsedBorrowIncentivePoolPointData.distributedPointPerPeriod
|
|
2745
|
+
),
|
|
2746
|
+
(0, import_bignumber.default)(parsedBorrowIncentivePoolPointData.points)
|
|
2747
|
+
);
|
|
2748
|
+
const currentPointIndex = (0, import_bignumber.default)(
|
|
2749
|
+
parsedBorrowIncentivePoolPointData.index
|
|
2750
|
+
).plus(
|
|
2751
|
+
accumulatedPoints.dividedBy(parsedBorrowIncentivePoolPointData.weightedAmount).isFinite() ? (0, import_bignumber.default)(baseIndexRate).multipliedBy(accumulatedPoints).dividedBy(parsedBorrowIncentivePoolPointData.weightedAmount) : 0
|
|
2752
|
+
);
|
|
2753
|
+
const currentTotalDistributedPoint = (0, import_bignumber.default)(
|
|
2754
|
+
parsedBorrowIncentivePoolPointData.distributedPoint
|
|
2755
|
+
).plus(accumulatedPoints);
|
|
2756
|
+
const baseWeight = (0, import_bignumber.default)(parsedBorrowIncentivePoolPointData.baseWeight);
|
|
2757
|
+
const weightedStakedAmount = (0, import_bignumber.default)(
|
|
2758
|
+
parsedBorrowIncentivePoolPointData.weightedAmount
|
|
2759
|
+
);
|
|
2760
|
+
const weightedStakedCoin = weightedStakedAmount.shiftedBy(
|
|
2761
|
+
-1 * poolCoinDecimal
|
|
2762
|
+
);
|
|
2763
|
+
const weightedStakedValue = weightedStakedCoin.multipliedBy(poolCoinPrice);
|
|
2764
|
+
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
2765
|
+
const rewardPerSec = (0, import_bignumber.default)(distributedPointPerSec).shiftedBy(
|
|
2766
|
+
-1 * rewardCoinDecimal
|
|
2767
|
+
);
|
|
2768
|
+
const rewardValueForYear = (0, import_bignumber.default)(rewardPerSec).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
2769
|
+
const weightScale = (0, import_bignumber.default)(1e12);
|
|
2770
|
+
const rewardRate = rewardValueForYear.multipliedBy(
|
|
2771
|
+
(0, import_bignumber.default)(parsedBorrowIncentivePoolPointData.baseWeight).dividedBy(
|
|
2772
|
+
weightScale
|
|
2773
|
+
)
|
|
2774
|
+
).dividedBy(weightedStakedValue).isFinite() && parsedBorrowIncentivePoolPointData.points > 0 ? rewardValueForYear.multipliedBy(
|
|
2775
|
+
(0, import_bignumber.default)(parsedBorrowIncentivePoolPointData.baseWeight).dividedBy(
|
|
2776
|
+
weightScale
|
|
2777
|
+
)
|
|
2778
|
+
).dividedBy(weightedStakedValue).toNumber() : Infinity;
|
|
2779
|
+
return {
|
|
2780
|
+
distributedPointPerSec: distributedPointPerSec.toNumber(),
|
|
2781
|
+
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
2782
|
+
currentPointIndex: currentPointIndex.toNumber(),
|
|
2783
|
+
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
2784
|
+
baseWeight: baseWeight.toNumber(),
|
|
2785
|
+
weightedStakedAmount: weightedStakedAmount.toNumber(),
|
|
2786
|
+
weightedStakedCoin: weightedStakedCoin.toNumber(),
|
|
2787
|
+
weightedStakedValue: weightedStakedValue.toNumber(),
|
|
2788
|
+
rewardApr: rewardRate,
|
|
2789
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
2790
|
+
};
|
|
2791
|
+
};
|
|
2792
|
+
var parseOriginBorrowIncentiveAccountPoolPointData = (originBorrowIncentiveAccountPoolPointData) => {
|
|
2793
|
+
return {
|
|
2794
|
+
pointType: (0, import_utils.normalizeStructTag)(
|
|
2795
|
+
originBorrowIncentiveAccountPoolPointData.point_type.name
|
|
2796
|
+
),
|
|
2797
|
+
weightedAmount: Number(
|
|
2798
|
+
originBorrowIncentiveAccountPoolPointData.weighted_amount
|
|
2799
|
+
),
|
|
2800
|
+
points: Number(originBorrowIncentiveAccountPoolPointData.points),
|
|
2801
|
+
totalPoints: Number(originBorrowIncentiveAccountPoolPointData.total_points),
|
|
2802
|
+
index: Number(originBorrowIncentiveAccountPoolPointData.index)
|
|
2803
|
+
};
|
|
2804
|
+
};
|
|
2805
|
+
var parseOriginBorrowIncentiveAccountData = (originBorrowIncentiveAccountData) => {
|
|
2806
|
+
return {
|
|
2807
|
+
poolType: (0, import_utils.normalizeStructTag)(
|
|
2808
|
+
originBorrowIncentiveAccountData.pool_type.name
|
|
2809
|
+
),
|
|
2810
|
+
debtAmount: Number(originBorrowIncentiveAccountData.debt_amount),
|
|
2811
|
+
pointList: originBorrowIncentiveAccountData.points_list.reduce(
|
|
2812
|
+
(acc, point) => {
|
|
2813
|
+
const parsed = parseOriginBorrowIncentiveAccountPoolPointData(point);
|
|
2814
|
+
const name = (0, import_utils.parseStructTag)(
|
|
2815
|
+
parsed.pointType
|
|
2816
|
+
).name.toLowerCase();
|
|
2817
|
+
acc[name] = parsed;
|
|
2818
|
+
return acc;
|
|
2612
2819
|
},
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2820
|
+
{}
|
|
2821
|
+
)
|
|
2822
|
+
};
|
|
2823
|
+
};
|
|
2824
|
+
var minBigNumber = (...args) => {
|
|
2825
|
+
return (0, import_bignumber.default)(
|
|
2826
|
+
args.reduce(
|
|
2827
|
+
(min, current) => new import_bignumber.default(current).lt(min) ? current : min
|
|
2828
|
+
)
|
|
2829
|
+
);
|
|
2830
|
+
};
|
|
2831
|
+
var estimatedFactor = (amount, scaleStep, type) => {
|
|
2832
|
+
const amountOfDigits = Math.max(
|
|
2833
|
+
1,
|
|
2834
|
+
Math.floor(Math.log10(Math.abs(amount)) + 1)
|
|
2835
|
+
);
|
|
2836
|
+
const adjustScale = Math.max(Math.floor((amountOfDigits - 1) / scaleStep), 1) + 1;
|
|
2837
|
+
let adjustFactor = Math.pow(10, -adjustScale);
|
|
2838
|
+
adjustFactor = type === "increase" ? 1 - adjustFactor : 1 + adjustFactor;
|
|
2839
|
+
return adjustFactor;
|
|
2840
|
+
};
|
|
2841
|
+
|
|
2842
|
+
// src/utils/util.ts
|
|
2843
|
+
var COIN_SET = Array.from(
|
|
2844
|
+
/* @__PURE__ */ new Set([
|
|
2845
|
+
...SUPPORT_POOLS,
|
|
2846
|
+
...SUPPORT_COLLATERALS,
|
|
2847
|
+
...SUPPORT_SPOOLS_REWARDS,
|
|
2848
|
+
...SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
2849
|
+
...SUPPORT_SCOIN
|
|
2850
|
+
])
|
|
2851
|
+
);
|
|
2852
|
+
var isMarketCoin = (coinName) => {
|
|
2853
|
+
const assetCoinName = coinName.slice(1).toLowerCase();
|
|
2854
|
+
return coinName.charAt(0).toLowerCase() === "s" && COIN_SET.includes(assetCoinName);
|
|
2619
2855
|
};
|
|
2620
|
-
var
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
baseURL: API_BASE_URL,
|
|
2630
|
-
headers: {
|
|
2631
|
-
"Content-Type": "application/json",
|
|
2632
|
-
Accept: "application/json"
|
|
2633
|
-
},
|
|
2634
|
-
timeout: 8e3
|
|
2635
|
-
});
|
|
2636
|
-
if (auth)
|
|
2637
|
-
this._auth = auth;
|
|
2638
|
-
this._id = id;
|
|
2639
|
-
this._network = network ?? "mainnet";
|
|
2640
|
-
this._addressesMap = USE_TEST_ADDRESS ? /* @__PURE__ */ new Map([["mainnet", TEST_ADDRESSES]]) : /* @__PURE__ */ new Map();
|
|
2641
|
-
if (USE_TEST_ADDRESS)
|
|
2642
|
-
this._currentAddresses = TEST_ADDRESSES;
|
|
2643
|
-
if (forceInterface) {
|
|
2644
|
-
for (const [network2, addresses] of Object.entries(
|
|
2645
|
-
forceInterface
|
|
2646
|
-
)) {
|
|
2647
|
-
if (["localnet", "devnet", "testnet", "mainnet"].includes(network2)) {
|
|
2648
|
-
if (network2 === this._network)
|
|
2649
|
-
this._currentAddresses = addresses;
|
|
2650
|
-
this._addressesMap.set(network2, addresses);
|
|
2651
|
-
}
|
|
2652
|
-
}
|
|
2653
|
-
}
|
|
2654
|
-
}
|
|
2655
|
-
/**
|
|
2656
|
-
* Get addresses API id.
|
|
2657
|
-
*
|
|
2658
|
-
* @return The addresses API id.
|
|
2659
|
-
*/
|
|
2660
|
-
getId() {
|
|
2661
|
-
return this._id || void 0;
|
|
2662
|
-
}
|
|
2663
|
-
/**
|
|
2664
|
-
* Get the address at the provided path.
|
|
2665
|
-
*
|
|
2666
|
-
* @param path - The path of the address to get.
|
|
2667
|
-
* @return The address at the provided path.
|
|
2668
|
-
*/
|
|
2669
|
-
get(path) {
|
|
2670
|
-
if (this._currentAddresses) {
|
|
2671
|
-
const value = path.split(".").reduce(
|
|
2672
|
-
(nestedAddressObj, key) => typeof nestedAddressObj === "object" ? nestedAddressObj[key] : nestedAddressObj,
|
|
2673
|
-
this._currentAddresses
|
|
2674
|
-
);
|
|
2675
|
-
return value || void 0;
|
|
2676
|
-
} else {
|
|
2677
|
-
return void 0;
|
|
2678
|
-
}
|
|
2679
|
-
}
|
|
2680
|
-
/**
|
|
2681
|
-
* Sets the address for the specified path, it does not interact with the API.
|
|
2682
|
-
*
|
|
2683
|
-
* @param path - The path of the address to set.
|
|
2684
|
-
* @param address - The address be setted to the tartget path.
|
|
2685
|
-
* @return The addresses.
|
|
2686
|
-
*/
|
|
2687
|
-
set(path, address) {
|
|
2688
|
-
if (this._currentAddresses) {
|
|
2689
|
-
const keys = path.split(".");
|
|
2690
|
-
keys.reduce((nestedAddressObj, key, index) => {
|
|
2691
|
-
if (index === keys.length - 1) {
|
|
2692
|
-
nestedAddressObj[key] = address;
|
|
2693
|
-
} else {
|
|
2694
|
-
return nestedAddressObj[key];
|
|
2695
|
-
}
|
|
2696
|
-
}, this._currentAddresses);
|
|
2697
|
-
}
|
|
2698
|
-
return this._currentAddresses;
|
|
2699
|
-
}
|
|
2700
|
-
/**
|
|
2701
|
-
* Synchronize the specified network addresses from the addresses map to the
|
|
2702
|
-
* current addresses and change the default network to specified network.
|
|
2703
|
-
*
|
|
2704
|
-
* @param network - Specifies which network's addresses you want to get.
|
|
2705
|
-
* @return Current addresses.
|
|
2706
|
-
*/
|
|
2707
|
-
switchCurrentAddresses(network) {
|
|
2708
|
-
if (this._addressesMap.has(network)) {
|
|
2709
|
-
this._currentAddresses = this._addressesMap.get(network);
|
|
2710
|
-
this._network = network;
|
|
2711
|
-
}
|
|
2712
|
-
return this._currentAddresses;
|
|
2856
|
+
var isSuiBridgeAsset = (coinName) => {
|
|
2857
|
+
return SUPPORT_SUI_BRIDGE.includes(coinName);
|
|
2858
|
+
};
|
|
2859
|
+
var isWormholeAsset = (coinName) => {
|
|
2860
|
+
return SUPPORT_WORMHOLE.includes(coinName);
|
|
2861
|
+
};
|
|
2862
|
+
var parseAssetSymbol = (coinName) => {
|
|
2863
|
+
if (isWormholeAsset(coinName)) {
|
|
2864
|
+
return `w${coinName.slice(1).toUpperCase()}`;
|
|
2713
2865
|
}
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
* addresses or the default network addresses in the addresses map.
|
|
2717
|
-
*
|
|
2718
|
-
* @param network - Specifies which network's addresses you want to get.
|
|
2719
|
-
*/
|
|
2720
|
-
getAddresses(network) {
|
|
2721
|
-
if (network) {
|
|
2722
|
-
return this._addressesMap.get(network);
|
|
2723
|
-
} else {
|
|
2724
|
-
return this._currentAddresses ?? this._addressesMap.get(this._network);
|
|
2725
|
-
}
|
|
2866
|
+
if (isSuiBridgeAsset(coinName)) {
|
|
2867
|
+
return `sb${coinName.slice(2).toUpperCase()}`;
|
|
2726
2868
|
}
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
*
|
|
2731
|
-
* @param addresses - The addresses be setted to the tartget network.
|
|
2732
|
-
* @param network - Specifies which network's addresses you want to set.
|
|
2733
|
-
* @return The addresses.
|
|
2734
|
-
*/
|
|
2735
|
-
setAddresses(addresses, network) {
|
|
2736
|
-
const targetNetwork = network || this._network;
|
|
2737
|
-
if (targetNetwork === this._network)
|
|
2738
|
-
this._currentAddresses = addresses;
|
|
2739
|
-
this._addressesMap.set(targetNetwork, addresses);
|
|
2869
|
+
if (isMarketCoin(coinName)) {
|
|
2870
|
+
const assetCoinName = coinName.slice(1).toLowerCase();
|
|
2871
|
+
return coinName.slice(0, 1).toLowerCase() + parseAssetSymbol(assetCoinName);
|
|
2740
2872
|
}
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2873
|
+
switch (coinName) {
|
|
2874
|
+
case "afsui":
|
|
2875
|
+
return "afSUI";
|
|
2876
|
+
case "hasui":
|
|
2877
|
+
return "haSUI";
|
|
2878
|
+
case "vsui":
|
|
2879
|
+
return "vSUI";
|
|
2880
|
+
default:
|
|
2881
|
+
return coinName.toUpperCase();
|
|
2748
2882
|
}
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
* @param params.auth - The authentication API key.
|
|
2765
|
-
* @param params.memo - Add memo to the addresses created in the API.
|
|
2766
|
-
* @return All addresses.
|
|
2767
|
-
*/
|
|
2768
|
-
async create(params) {
|
|
2769
|
-
const { addresses, network, auth, memo } = params ?? {};
|
|
2770
|
-
const apiKey = auth || this._auth || void 0;
|
|
2771
|
-
const targetNetwork = network || this._network;
|
|
2772
|
-
const targetAddresses = addresses || this._currentAddresses || this._addressesMap.get(targetNetwork) || EMPTY_ADDRESSES;
|
|
2773
|
-
if (apiKey !== void 0) {
|
|
2774
|
-
this._addressesMap.clear();
|
|
2775
|
-
this.setAddresses(targetAddresses, targetNetwork);
|
|
2776
|
-
const response = await this._requestClient.post(
|
|
2777
|
-
`/addresses`,
|
|
2778
|
-
JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
|
|
2779
|
-
{
|
|
2780
|
-
headers: {
|
|
2781
|
-
"Content-Type": "application/json",
|
|
2782
|
-
"api-key": auth || this._auth
|
|
2783
|
-
}
|
|
2784
|
-
}
|
|
2785
|
-
);
|
|
2786
|
-
if (response.status === 201) {
|
|
2787
|
-
for (const [network2, addresses2] of Object.entries(
|
|
2788
|
-
response.data
|
|
2789
|
-
)) {
|
|
2790
|
-
if (["localnet", "devnet", "testnet", "mainnet"].includes(network2)) {
|
|
2791
|
-
if (network2 === this._network)
|
|
2792
|
-
this._currentAddresses = addresses2;
|
|
2793
|
-
this._addressesMap.set(network2, addresses2);
|
|
2794
|
-
}
|
|
2795
|
-
}
|
|
2796
|
-
this._id = response.data.id;
|
|
2797
|
-
return this.getAllAddresses();
|
|
2798
|
-
} else {
|
|
2799
|
-
throw Error("Failed to create addresses.");
|
|
2800
|
-
}
|
|
2801
|
-
} else {
|
|
2802
|
-
throw Error("You don't have permission to access this request.");
|
|
2803
|
-
}
|
|
2883
|
+
};
|
|
2884
|
+
var parseDataFromPythPriceFeed = (feed, address) => {
|
|
2885
|
+
const assetCoinNames = COIN_SET;
|
|
2886
|
+
const assetCoinName = assetCoinNames.find((assetCoinName2) => {
|
|
2887
|
+
return address.get(`core.coins.${assetCoinName2}.oracle.pyth.feed`) === feed.id;
|
|
2888
|
+
});
|
|
2889
|
+
if (assetCoinName) {
|
|
2890
|
+
const price = feed.price.price * 10 ** feed.price.expo;
|
|
2891
|
+
return {
|
|
2892
|
+
coinName: assetCoinName,
|
|
2893
|
+
price,
|
|
2894
|
+
publishTime: Number(feed.price.publishTime) * 10 ** 3
|
|
2895
|
+
};
|
|
2896
|
+
} else {
|
|
2897
|
+
throw new Error("Invalid feed id");
|
|
2804
2898
|
}
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
const addressesId = id || this._id || void 0;
|
|
2813
|
-
if (addressesId !== void 0) {
|
|
2814
|
-
const response = await this.cache.queryClient.fetchQuery({
|
|
2815
|
-
queryKey: queryKeys.api.getAddresses(addressesId),
|
|
2816
|
-
queryFn: async () => {
|
|
2817
|
-
return await this._requestClient.get(`/addresses/${addressesId}`, {
|
|
2818
|
-
headers: {
|
|
2819
|
-
"Content-Type": "application/json"
|
|
2820
|
-
}
|
|
2821
|
-
});
|
|
2822
|
-
}
|
|
2823
|
-
});
|
|
2824
|
-
if (response.status === 200) {
|
|
2825
|
-
for (const [network, addresses] of Object.entries(
|
|
2826
|
-
response.data
|
|
2827
|
-
)) {
|
|
2828
|
-
if (["localnet", "devnet", "testnet", "mainnet"].includes(network)) {
|
|
2829
|
-
if (network === this._network)
|
|
2830
|
-
this._currentAddresses = addresses;
|
|
2831
|
-
this._addressesMap.set(network, addresses);
|
|
2832
|
-
}
|
|
2833
|
-
}
|
|
2834
|
-
this._id = response.data.id;
|
|
2835
|
-
return this.getAllAddresses();
|
|
2836
|
-
} else {
|
|
2837
|
-
throw Error("Failed to create addresses.");
|
|
2838
|
-
}
|
|
2839
|
-
} else {
|
|
2840
|
-
throw Error("Please provide API addresses id.");
|
|
2841
|
-
}
|
|
2899
|
+
};
|
|
2900
|
+
var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
|
|
2901
|
+
const unlockDate = new Date(unlockAtInSecondTimestamp * 1e3);
|
|
2902
|
+
const closestTwelveAM = new Date(unlockAtInSecondTimestamp * 1e3);
|
|
2903
|
+
closestTwelveAM.setUTCHours(0, 0, 0, 0);
|
|
2904
|
+
if (unlockDate.getUTCHours() >= 0) {
|
|
2905
|
+
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() + 1);
|
|
2842
2906
|
}
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
*
|
|
2847
|
-
* @description
|
|
2848
|
-
* If the `network` is not specified, the mainnet is used by default.
|
|
2849
|
-
* If no `addresses` from instance or parameter is provided, an addresses with
|
|
2850
|
-
* all empty strings is created by default.
|
|
2851
|
-
*
|
|
2852
|
-
* This function only allows for one addresses to be input into a specific network
|
|
2853
|
-
* at a time, and does not provide an addresses map for setting addresses
|
|
2854
|
-
* across all networks at once.
|
|
2855
|
-
*
|
|
2856
|
-
* @param params.id - The id of the addresses to update.
|
|
2857
|
-
* @param params.addresses - The addresses be setted to the tartget network.
|
|
2858
|
-
* @param params.network - Specifies which network's addresses you want to set.
|
|
2859
|
-
* @param params.auth - The authentication api key.
|
|
2860
|
-
* @param params.memo - Add memo to the addresses created in the API.
|
|
2861
|
-
* @return All addresses.
|
|
2862
|
-
*/
|
|
2863
|
-
async update(params) {
|
|
2864
|
-
const { id, addresses, network, auth, memo } = params ?? {};
|
|
2865
|
-
const apiKey = auth || this._auth || void 0;
|
|
2866
|
-
const targetId = id || this._id || void 0;
|
|
2867
|
-
const targetNetwork = network || this._network;
|
|
2868
|
-
const targetAddresses = addresses || this._currentAddresses || this._addressesMap.get(targetNetwork) || EMPTY_ADDRESSES;
|
|
2869
|
-
if (targetId === void 0)
|
|
2870
|
-
throw Error("Require specific addresses id to be updated.");
|
|
2871
|
-
if (apiKey !== void 0) {
|
|
2872
|
-
if (id !== this._id) {
|
|
2873
|
-
this._addressesMap.clear();
|
|
2874
|
-
}
|
|
2875
|
-
this.setAddresses(targetAddresses, targetNetwork);
|
|
2876
|
-
const response = await this._requestClient.put(
|
|
2877
|
-
`/addresses/${targetId}`,
|
|
2878
|
-
JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
|
|
2879
|
-
{
|
|
2880
|
-
headers: {
|
|
2881
|
-
"Content-Type": "application/json",
|
|
2882
|
-
"api-key": auth || this._auth
|
|
2883
|
-
}
|
|
2884
|
-
}
|
|
2885
|
-
);
|
|
2886
|
-
if (response.status === 200) {
|
|
2887
|
-
for (const [network2, addresses2] of Object.entries(
|
|
2888
|
-
response.data
|
|
2889
|
-
)) {
|
|
2890
|
-
if (["localnet", "devnet", "testnet", "mainnet"].includes(network2)) {
|
|
2891
|
-
if (network2 === this._network)
|
|
2892
|
-
this._currentAddresses = addresses2;
|
|
2893
|
-
this._addressesMap.set(network2, addresses2);
|
|
2894
|
-
}
|
|
2895
|
-
}
|
|
2896
|
-
this._id = response.data.id;
|
|
2897
|
-
return this.getAllAddresses();
|
|
2898
|
-
} else {
|
|
2899
|
-
throw Error("Failed to update addresses.");
|
|
2900
|
-
}
|
|
2901
|
-
} else {
|
|
2902
|
-
throw Error("You don't have permission to access this request.");
|
|
2903
|
-
}
|
|
2907
|
+
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
2908
|
+
if (closestTwelveAM.getTime() - now > MAX_LOCK_DURATION * 1e3) {
|
|
2909
|
+
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() - 1);
|
|
2904
2910
|
}
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2911
|
+
return Math.floor(closestTwelveAM.getTime() / 1e3);
|
|
2912
|
+
};
|
|
2913
|
+
var partitionArray = (array, chunkSize) => {
|
|
2914
|
+
const result = [];
|
|
2915
|
+
for (let i = 0; i < array.length; i += chunkSize) {
|
|
2916
|
+
result.push(array.slice(i, i + chunkSize));
|
|
2917
|
+
}
|
|
2918
|
+
return result;
|
|
2919
|
+
};
|
|
2920
|
+
|
|
2921
|
+
// src/utils/indexer.ts
|
|
2922
|
+
async function callMethodWithIndexerFallback(method, context, ...args) {
|
|
2923
|
+
const lastArgs = args[args.length - 1];
|
|
2924
|
+
if (typeof lastArgs === "object" && lastArgs.indexer) {
|
|
2925
|
+
try {
|
|
2926
|
+
return await method.apply(context, args);
|
|
2927
|
+
} catch (e) {
|
|
2928
|
+
console.warn(
|
|
2929
|
+
`Indexer requests failed: ${e.message}. Retrying without indexer..`
|
|
2930
|
+
);
|
|
2931
|
+
return await method.apply(context, [
|
|
2932
|
+
...args.slice(0, -1),
|
|
2920
2933
|
{
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
"api-key": auth || this._auth
|
|
2924
|
-
}
|
|
2934
|
+
...lastArgs,
|
|
2935
|
+
indexer: false
|
|
2925
2936
|
}
|
|
2926
|
-
);
|
|
2927
|
-
if (response.status === 200) {
|
|
2928
|
-
this._id = void 0;
|
|
2929
|
-
this._currentAddresses = void 0;
|
|
2930
|
-
this._addressesMap.clear();
|
|
2931
|
-
} else {
|
|
2932
|
-
throw Error("Failed to delete addresses.");
|
|
2933
|
-
}
|
|
2934
|
-
} else {
|
|
2935
|
-
throw Error("You don't have permission to access this request.");
|
|
2937
|
+
]);
|
|
2936
2938
|
}
|
|
2937
2939
|
}
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2940
|
+
return await method.apply(context, args);
|
|
2941
|
+
}
|
|
2942
|
+
function withIndexerFallback(method) {
|
|
2943
|
+
return (...args) => {
|
|
2944
|
+
return callMethodWithIndexerFallback(method, this, ...args);
|
|
2945
|
+
};
|
|
2946
|
+
}
|
|
2942
2947
|
|
|
2943
|
-
// src/
|
|
2944
|
-
var
|
|
2945
|
-
|
|
2948
|
+
// src/utils/core.ts
|
|
2949
|
+
var parseObjectAs = (object) => {
|
|
2950
|
+
if (!(object && object.content && "fields" in object.content))
|
|
2951
|
+
throw new Error(`Failed to parse object`);
|
|
2952
|
+
const fields = object.content.fields;
|
|
2953
|
+
if (typeof fields === "object" && "value" in fields) {
|
|
2954
|
+
const value = fields.value;
|
|
2955
|
+
if (typeof value === "object" && "fields" in value)
|
|
2956
|
+
return value.fields;
|
|
2957
|
+
return value;
|
|
2958
|
+
} else if (typeof fields === "object") {
|
|
2959
|
+
return fields;
|
|
2960
|
+
}
|
|
2961
|
+
return fields;
|
|
2962
|
+
};
|
|
2946
2963
|
|
|
2947
2964
|
// src/queries/borrowIncentiveQuery.ts
|
|
2948
|
-
var import_utils3 = require("@mysten/sui/utils");
|
|
2949
2965
|
var import_bignumber2 = __toESM(require("bignumber.js"));
|
|
2950
2966
|
var queryBorrowIncentivePools = async (address) => {
|
|
2951
2967
|
const queryPkgId = address.get("borrowIncentive.query");
|
|
@@ -2992,7 +3008,7 @@ var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
|
|
|
2992
3008
|
query.utils,
|
|
2993
3009
|
pool
|
|
2994
3010
|
);
|
|
2995
|
-
const poolCoinType = (0,
|
|
3011
|
+
const poolCoinType = (0, import_utils2.normalizeStructTag)(pool.pool_type.name);
|
|
2996
3012
|
const poolCoinName = query.utils.parseCoinNameFromType(
|
|
2997
3013
|
poolCoinType
|
|
2998
3014
|
);
|
|
@@ -3136,7 +3152,7 @@ var getBindedVeScaKey = async ({
|
|
|
3136
3152
|
};
|
|
3137
3153
|
|
|
3138
3154
|
// src/queries/coreQuery.ts
|
|
3139
|
-
var
|
|
3155
|
+
var import_utils5 = require("@mysten/sui/utils");
|
|
3140
3156
|
var import_bignumber3 = __toESM(require("bignumber.js"));
|
|
3141
3157
|
|
|
3142
3158
|
// src/queries/supplyLimitQuery.ts
|
|
@@ -3344,7 +3360,7 @@ var queryMarket = async (query, indexer = false, coinPrices) => {
|
|
|
3344
3360
|
const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
|
|
3345
3361
|
const marketData = queryResult?.events[0]?.parsedJson;
|
|
3346
3362
|
for (const pool of marketData?.pools ?? []) {
|
|
3347
|
-
const coinType = (0,
|
|
3363
|
+
const coinType = (0, import_utils5.normalizeStructTag)(pool.type.name);
|
|
3348
3364
|
const poolCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
3349
3365
|
const coinPrice = coinPrices[poolCoinName] ?? 0;
|
|
3350
3366
|
if (!SUPPORT_POOLS.includes(poolCoinName)) {
|
|
@@ -3399,7 +3415,7 @@ var queryMarket = async (query, indexer = false, coinPrices) => {
|
|
|
3399
3415
|
};
|
|
3400
3416
|
}
|
|
3401
3417
|
for (const collateral of marketData?.collaterals ?? []) {
|
|
3402
|
-
const coinType = (0,
|
|
3418
|
+
const coinType = (0, import_utils5.normalizeStructTag)(collateral.type.name);
|
|
3403
3419
|
const collateralCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
3404
3420
|
const coinPrice = coinPrices[collateralCoinName] ?? 0;
|
|
3405
3421
|
if (!SUPPORT_COLLATERALS.includes(collateralCoinName)) {
|
|
@@ -3971,11 +3987,11 @@ var getCoinAmounts = async (query, assetCoinNames = [...SUPPORT_POOLS], ownerAdd
|
|
|
3971
3987
|
var getCoinAmount = async (query, assetCoinName, ownerAddress) => {
|
|
3972
3988
|
const owner = ownerAddress ?? query.suiKit.currentAddress();
|
|
3973
3989
|
const coinType = query.utils.parseCoinType(assetCoinName);
|
|
3974
|
-
const
|
|
3990
|
+
const coinBalance = await query.cache.queryGetCoinBalance({
|
|
3975
3991
|
owner,
|
|
3976
3992
|
coinType
|
|
3977
3993
|
});
|
|
3978
|
-
return (0, import_bignumber3.default)(
|
|
3994
|
+
return (0, import_bignumber3.default)(coinBalance?.totalBalance ?? "0").toNumber();
|
|
3979
3995
|
};
|
|
3980
3996
|
var getMarketCoinAmounts = async (query, marketCoinNames, ownerAddress) => {
|
|
3981
3997
|
marketCoinNames = marketCoinNames || [...SUPPORT_POOLS].map(
|
|
@@ -3998,11 +4014,11 @@ var getMarketCoinAmounts = async (query, marketCoinNames, ownerAddress) => {
|
|
|
3998
4014
|
var getMarketCoinAmount = async (query, marketCoinName, ownerAddress) => {
|
|
3999
4015
|
const owner = ownerAddress ?? query.suiKit.currentAddress();
|
|
4000
4016
|
const marketCoinType = query.utils.parseMarketCoinType(marketCoinName);
|
|
4001
|
-
const
|
|
4017
|
+
const coinBalance = await query.cache.queryGetCoinBalance({
|
|
4002
4018
|
owner,
|
|
4003
4019
|
coinType: marketCoinType
|
|
4004
4020
|
});
|
|
4005
|
-
return (0, import_bignumber3.default)(
|
|
4021
|
+
return (0, import_bignumber3.default)(coinBalance?.totalBalance ?? "0").toNumber();
|
|
4006
4022
|
};
|
|
4007
4023
|
var getFlashLoanFees = async (query, assetNames) => {
|
|
4008
4024
|
const FEE_RATE = 1e4;
|
|
@@ -4116,7 +4132,8 @@ var getLoyaltyProgramInformations = async (query, veScaKey) => {
|
|
|
4116
4132
|
|
|
4117
4133
|
// src/queries/portfolioQuery.ts
|
|
4118
4134
|
var import_bignumber5 = __toESM(require("bignumber.js"));
|
|
4119
|
-
var
|
|
4135
|
+
var import_sui_kit3 = require("@scallop-io/sui-kit");
|
|
4136
|
+
var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress, marketPools, indexer = false) => {
|
|
4120
4137
|
const marketCoinNames = poolCoinNames.map(
|
|
4121
4138
|
(poolCoinName) => query.utils.parseMarketCoinName(poolCoinName)
|
|
4122
4139
|
);
|
|
@@ -4124,7 +4141,7 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
|
|
|
4124
4141
|
(marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
|
|
4125
4142
|
);
|
|
4126
4143
|
const coinPrices = await query.utils.getCoinPrices();
|
|
4127
|
-
|
|
4144
|
+
marketPools = marketPools ?? (await query.getMarketPools(poolCoinNames, {
|
|
4128
4145
|
indexer,
|
|
4129
4146
|
coinPrices
|
|
4130
4147
|
})).pools;
|
|
@@ -4294,8 +4311,8 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
4294
4311
|
};
|
|
4295
4312
|
return lending;
|
|
4296
4313
|
};
|
|
4297
|
-
var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
|
|
4298
|
-
|
|
4314
|
+
var getObligationAccounts = async (query, ownerAddress, market, indexer = false) => {
|
|
4315
|
+
market = market ?? await query.getMarketPools(void 0, { indexer });
|
|
4299
4316
|
const coinPrices = await query.getAllCoinPrices({
|
|
4300
4317
|
marketPools: market.pools
|
|
4301
4318
|
});
|
|
@@ -4337,7 +4354,6 @@ var getObligationAccount = async (query, obligation, ownerAddress, indexer = fal
|
|
|
4337
4354
|
query.queryObligation(obligation),
|
|
4338
4355
|
query.getBorrowIncentivePools(void 0, {
|
|
4339
4356
|
coinPrices,
|
|
4340
|
-
indexer,
|
|
4341
4357
|
marketPools: market.pools
|
|
4342
4358
|
}),
|
|
4343
4359
|
query.getBorrowIncentiveAccounts(obligation)
|
|
@@ -4656,6 +4672,154 @@ var getTotalValueLocked = async (query, indexer = false) => {
|
|
|
4656
4672
|
};
|
|
4657
4673
|
return tvl;
|
|
4658
4674
|
};
|
|
4675
|
+
var getUserPortfolio = async (query, walletAddress, indexer = false) => {
|
|
4676
|
+
const market = await query.getMarketPools();
|
|
4677
|
+
const [lendings, obligationAccounts, borrowIncentivePools] = await Promise.all([
|
|
4678
|
+
query.getLendings(void 0, walletAddress, {
|
|
4679
|
+
indexer,
|
|
4680
|
+
marketPools: market.pools
|
|
4681
|
+
}),
|
|
4682
|
+
query.getObligationAccounts(walletAddress, {
|
|
4683
|
+
indexer,
|
|
4684
|
+
market
|
|
4685
|
+
}),
|
|
4686
|
+
query.getBorrowIncentivePools(void 0, {
|
|
4687
|
+
marketPools: market.pools
|
|
4688
|
+
})
|
|
4689
|
+
]);
|
|
4690
|
+
const parsedLendings = Object.values(lendings).filter((t) => t.availableWithdrawCoin > 0).map((lending) => ({
|
|
4691
|
+
suppliedCoin: lending.availableWithdrawCoin,
|
|
4692
|
+
suppliedValue: lending.suppliedValue,
|
|
4693
|
+
stakedCoin: lending.availableUnstakeCoin,
|
|
4694
|
+
coinName: lending.coinName,
|
|
4695
|
+
symbol: lending.symbol,
|
|
4696
|
+
coinType: lending.coinType,
|
|
4697
|
+
coinPrice: lending.coinPrice,
|
|
4698
|
+
coinDecimals: lending.coinDecimal,
|
|
4699
|
+
supplyApr: lending.supplyApr,
|
|
4700
|
+
supplyApy: lending.supplyApy,
|
|
4701
|
+
incentiveApr: isFinite(lending.rewardApr) ? lending.rewardApr : 0
|
|
4702
|
+
}));
|
|
4703
|
+
const parsedObligationAccounts = Object.values(obligationAccounts).filter(
|
|
4704
|
+
(t) => !!t && t.totalBorrowedValueWithWeight > 0
|
|
4705
|
+
).map((obligationAccount) => {
|
|
4706
|
+
return {
|
|
4707
|
+
obligationId: obligationAccount.obligationId,
|
|
4708
|
+
totalDebtsInUsd: obligationAccount.totalBorrowedValueWithWeight,
|
|
4709
|
+
totalCollateralInUsd: obligationAccount.totalDepositedValue,
|
|
4710
|
+
riskLevel: obligationAccount.totalRiskLevel,
|
|
4711
|
+
availableCollateralInUsd: obligationAccount.totalAvailableCollateralValue,
|
|
4712
|
+
totalUnhealthyCollateralInUsd: obligationAccount.totalUnhealthyCollateralValue,
|
|
4713
|
+
borrowedPools: Object.values(obligationAccount.debts).filter((debt) => debt.borrowedCoin > 0).map((debt) => ({
|
|
4714
|
+
coinName: debt.coinName,
|
|
4715
|
+
symbol: debt.symbol,
|
|
4716
|
+
coinDecimals: debt.coinDecimal,
|
|
4717
|
+
coinType: debt.coinType,
|
|
4718
|
+
coinPrice: debt.coinPrice,
|
|
4719
|
+
borrowedCoin: debt.borrowedCoin,
|
|
4720
|
+
borrowedValueInUsd: debt.borrowedValueWithWeight,
|
|
4721
|
+
borrowApr: market.pools[debt.coinName]?.borrowApr,
|
|
4722
|
+
borrowApy: market.pools[debt.coinName]?.borrowApy,
|
|
4723
|
+
incentiveInfos: Object.values(
|
|
4724
|
+
borrowIncentivePools[debt.coinName]?.points ?? {}
|
|
4725
|
+
).filter((t) => isFinite(t.rewardApr)).map((t) => ({
|
|
4726
|
+
coinName: t.coinName,
|
|
4727
|
+
symbol: t.symbol,
|
|
4728
|
+
coinType: t.coinType,
|
|
4729
|
+
incentiveApr: t.rewardApr
|
|
4730
|
+
}))
|
|
4731
|
+
}))
|
|
4732
|
+
};
|
|
4733
|
+
});
|
|
4734
|
+
const pendingLendingRewards = Object.values(lendings).reduce(
|
|
4735
|
+
(acc, reward) => {
|
|
4736
|
+
if (reward.availableClaimCoin === 0)
|
|
4737
|
+
return acc;
|
|
4738
|
+
if (!acc[reward.symbol]) {
|
|
4739
|
+
acc[reward.symbol] = {
|
|
4740
|
+
symbol: reward.symbol,
|
|
4741
|
+
coinType: (0, import_sui_kit3.normalizeStructTag)(import_sui_kit3.SUI_TYPE_ARG),
|
|
4742
|
+
// @TODO: for now lending reward is all in SUI
|
|
4743
|
+
coinPrice: reward.coinPrice,
|
|
4744
|
+
pendingRewardInCoin: reward.availableClaimCoin
|
|
4745
|
+
};
|
|
4746
|
+
} else {
|
|
4747
|
+
acc[reward.symbol].pendingRewardInCoin += reward.availableClaimCoin;
|
|
4748
|
+
}
|
|
4749
|
+
return acc;
|
|
4750
|
+
},
|
|
4751
|
+
{}
|
|
4752
|
+
);
|
|
4753
|
+
const pendingBorrowIncentiveRewards = Object.values(obligationAccounts).filter((t) => !!t).reduce(
|
|
4754
|
+
(acc, curr) => {
|
|
4755
|
+
Object.values(curr.borrowIncentives).forEach((incentive) => {
|
|
4756
|
+
incentive.rewards.forEach((reward) => {
|
|
4757
|
+
if (reward.availableClaimCoin === 0)
|
|
4758
|
+
return acc;
|
|
4759
|
+
if (!acc[reward.coinName]) {
|
|
4760
|
+
acc[reward.coinName] = {
|
|
4761
|
+
symbol: reward.symbol,
|
|
4762
|
+
coinType: reward.coinType,
|
|
4763
|
+
coinPrice: reward.coinPrice,
|
|
4764
|
+
pendingRewardInCoin: reward.availableClaimCoin
|
|
4765
|
+
};
|
|
4766
|
+
} else {
|
|
4767
|
+
acc[reward.coinName].pendingRewardInCoin += reward.availableClaimCoin;
|
|
4768
|
+
}
|
|
4769
|
+
});
|
|
4770
|
+
});
|
|
4771
|
+
return acc;
|
|
4772
|
+
},
|
|
4773
|
+
{}
|
|
4774
|
+
);
|
|
4775
|
+
return {
|
|
4776
|
+
lendings: {
|
|
4777
|
+
totalSupplyValue: parsedLendings.reduce((acc, curr) => {
|
|
4778
|
+
acc += curr.suppliedValue;
|
|
4779
|
+
return acc;
|
|
4780
|
+
}, 0),
|
|
4781
|
+
suppliedPools: parsedLendings
|
|
4782
|
+
},
|
|
4783
|
+
borrowings: {
|
|
4784
|
+
...parsedObligationAccounts.reduce(
|
|
4785
|
+
(acc, curr) => {
|
|
4786
|
+
acc.totalDebtValue += curr.totalDebtsInUsd;
|
|
4787
|
+
acc.totalCollateralValue += curr.totalCollateralInUsd;
|
|
4788
|
+
return acc;
|
|
4789
|
+
},
|
|
4790
|
+
{
|
|
4791
|
+
totalDebtValue: 0,
|
|
4792
|
+
totalCollateralValue: 0
|
|
4793
|
+
}
|
|
4794
|
+
),
|
|
4795
|
+
obligations: parsedObligationAccounts
|
|
4796
|
+
},
|
|
4797
|
+
pendingRewards: {
|
|
4798
|
+
lendings: Object.entries(pendingLendingRewards).reduce(
|
|
4799
|
+
(acc, [key, value]) => {
|
|
4800
|
+
acc.push({
|
|
4801
|
+
...value,
|
|
4802
|
+
coinName: key,
|
|
4803
|
+
pendingRewardInUsd: value.coinPrice * value.pendingRewardInCoin
|
|
4804
|
+
});
|
|
4805
|
+
return acc;
|
|
4806
|
+
},
|
|
4807
|
+
[]
|
|
4808
|
+
),
|
|
4809
|
+
borrowIncentives: Object.entries(pendingBorrowIncentiveRewards).reduce(
|
|
4810
|
+
(acc, [key, value]) => {
|
|
4811
|
+
acc.push({
|
|
4812
|
+
coinName: key,
|
|
4813
|
+
...value,
|
|
4814
|
+
pendingRewardInUsd: value.coinPrice * value.pendingRewardInCoin
|
|
4815
|
+
});
|
|
4816
|
+
return acc;
|
|
4817
|
+
},
|
|
4818
|
+
[]
|
|
4819
|
+
)
|
|
4820
|
+
}
|
|
4821
|
+
};
|
|
4822
|
+
};
|
|
4659
4823
|
|
|
4660
4824
|
// src/queries/priceQuery.ts
|
|
4661
4825
|
var import_bignumber6 = __toESM(require("bignumber.js"));
|
|
@@ -4819,11 +4983,11 @@ var getSCoinAmount = async ({
|
|
|
4819
4983
|
}, sCoinName, ownerAddress) => {
|
|
4820
4984
|
const owner = ownerAddress || utils.suiKit.currentAddress();
|
|
4821
4985
|
const sCoinType = utils.parseSCoinType(sCoinName);
|
|
4822
|
-
const
|
|
4986
|
+
const coinBalance = await utils.cache.queryGetCoinBalance({
|
|
4823
4987
|
owner,
|
|
4824
4988
|
coinType: sCoinType
|
|
4825
4989
|
});
|
|
4826
|
-
return (0, import_bignumber7.default)(
|
|
4990
|
+
return (0, import_bignumber7.default)(coinBalance?.totalBalance ?? "0").toNumber();
|
|
4827
4991
|
};
|
|
4828
4992
|
var isSupportStakeCoins = (value) => {
|
|
4829
4993
|
return SUPPORT_SCOIN.includes(value);
|
|
@@ -4867,7 +5031,7 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
|
|
|
4867
5031
|
};
|
|
4868
5032
|
|
|
4869
5033
|
// src/queries/spoolQuery.ts
|
|
4870
|
-
var
|
|
5034
|
+
var import_utils8 = require("@mysten/sui/utils");
|
|
4871
5035
|
var queryRequiredSpoolObjects = async (query, stakePoolCoinNames) => {
|
|
4872
5036
|
const tasks = stakePoolCoinNames.map((t, idx) => ({
|
|
4873
5037
|
poolCoinName: stakePoolCoinNames[idx],
|
|
@@ -5127,14 +5291,14 @@ var getStakeAccounts = async ({
|
|
|
5127
5291
|
svsui: stakeAccounts.svsui,
|
|
5128
5292
|
susdc: stakeAccounts.susdc
|
|
5129
5293
|
};
|
|
5130
|
-
const normalizedType = (0,
|
|
5294
|
+
const normalizedType = (0, import_utils8.normalizeStructTag)(type);
|
|
5131
5295
|
const stakeAccountArray = stakeMarketCoinTypeMap[reversedStakeMarketCoinTypes[normalizedType]];
|
|
5132
5296
|
if (stakeAccountArray) {
|
|
5133
5297
|
stakeAccountArray.push({
|
|
5134
5298
|
id,
|
|
5135
5299
|
type: normalizedType,
|
|
5136
5300
|
stakePoolId,
|
|
5137
|
-
stakeType: (0,
|
|
5301
|
+
stakeType: (0, import_utils8.normalizeStructTag)(stakeType),
|
|
5138
5302
|
staked,
|
|
5139
5303
|
index,
|
|
5140
5304
|
points,
|
|
@@ -5172,13 +5336,13 @@ var getStakePool = async ({
|
|
|
5172
5336
|
const lastUpdate = Number(fields.last_update);
|
|
5173
5337
|
stakePool = {
|
|
5174
5338
|
id,
|
|
5175
|
-
type: (0,
|
|
5339
|
+
type: (0, import_utils8.normalizeStructTag)(type),
|
|
5176
5340
|
maxPoint,
|
|
5177
5341
|
distributedPoint,
|
|
5178
5342
|
pointPerPeriod,
|
|
5179
5343
|
period,
|
|
5180
5344
|
maxStake,
|
|
5181
|
-
stakeType: (0,
|
|
5345
|
+
stakeType: (0, import_utils8.normalizeStructTag)(stakeType),
|
|
5182
5346
|
totalStaked,
|
|
5183
5347
|
index,
|
|
5184
5348
|
createdAt,
|
|
@@ -5217,7 +5381,7 @@ var getStakeRewardPool = async ({
|
|
|
5217
5381
|
const claimedRewards = Number(rewardPoolFields.claimed_rewards);
|
|
5218
5382
|
stakeRewardPool = {
|
|
5219
5383
|
id,
|
|
5220
|
-
type: (0,
|
|
5384
|
+
type: (0, import_utils8.normalizeStructTag)(type),
|
|
5221
5385
|
stakePoolId,
|
|
5222
5386
|
ratioNumerator,
|
|
5223
5387
|
ratioDenominator,
|
|
@@ -5231,7 +5395,7 @@ var getStakeRewardPool = async ({
|
|
|
5231
5395
|
|
|
5232
5396
|
// src/queries/vescaQuery.ts
|
|
5233
5397
|
var import_bignumber8 = __toESM(require("bignumber.js"));
|
|
5234
|
-
var
|
|
5398
|
+
var import_sui_kit4 = require("@scallop-io/sui-kit");
|
|
5235
5399
|
var import_bcs2 = require("@mysten/sui/bcs");
|
|
5236
5400
|
var import_zod5 = require("zod");
|
|
5237
5401
|
var import_assert2 = __toESM(require("assert"));
|
|
@@ -5332,9 +5496,9 @@ var getTotalVeScaTreasuryAmount = async (utils, veScaTreasury) => {
|
|
|
5332
5496
|
const veScaConfig = utils.address.get("vesca.config");
|
|
5333
5497
|
veScaTreasury = veScaTreasury ?? utils.address.get("vesca.treasury");
|
|
5334
5498
|
const refreshQueryTarget = `${veScaPkgId}::treasury::refresh`;
|
|
5335
|
-
const refreshArgs = [veScaConfig, veScaTreasury,
|
|
5499
|
+
const refreshArgs = [veScaConfig, veScaTreasury, import_sui_kit4.SUI_CLOCK_OBJECT_ID];
|
|
5336
5500
|
const veScaAmountQueryTarget = `${veScaPkgId}::treasury::total_ve_sca_amount`;
|
|
5337
|
-
const veScaAmountArgs = [veScaTreasury,
|
|
5501
|
+
const veScaAmountArgs = [veScaTreasury, import_sui_kit4.SUI_CLOCK_OBJECT_ID];
|
|
5338
5502
|
const resolvedRefreshArgs = await Promise.all(
|
|
5339
5503
|
refreshArgs.map(async (arg) => {
|
|
5340
5504
|
if (typeof arg === "string") {
|
|
@@ -5351,7 +5515,7 @@ var getTotalVeScaTreasuryAmount = async (utils, veScaTreasury) => {
|
|
|
5351
5515
|
return arg;
|
|
5352
5516
|
})
|
|
5353
5517
|
);
|
|
5354
|
-
const txb = new
|
|
5518
|
+
const txb = new import_sui_kit4.SuiTxBlock();
|
|
5355
5519
|
txb.moveCall(refreshQueryTarget, resolvedRefreshArgs);
|
|
5356
5520
|
txb.moveCall(veScaAmountQueryTarget, resolvedVeScaAmountArgs);
|
|
5357
5521
|
const txBytes = await txb.txBlock.build({
|
|
@@ -5471,6 +5635,7 @@ var getAllAddresses = async (query) => {
|
|
|
5471
5635
|
// @ts-ignore
|
|
5472
5636
|
`spool.pools.s${coinName}.rewardPoolId`
|
|
5473
5637
|
);
|
|
5638
|
+
const sCoinType = query.address.get(`scoin.coins.s${coinName}.coinType`);
|
|
5474
5639
|
const sCoinTreasury = query.address.get(
|
|
5475
5640
|
// @ts-ignore
|
|
5476
5641
|
`scoin.coins.s${coinName}.treasury`
|
|
@@ -5491,7 +5656,9 @@ var getAllAddresses = async (query) => {
|
|
|
5491
5656
|
spool,
|
|
5492
5657
|
spoolReward: rewardPool,
|
|
5493
5658
|
sCoinTreasury,
|
|
5494
|
-
|
|
5659
|
+
sCoinType,
|
|
5660
|
+
coinDecimalId,
|
|
5661
|
+
coinType
|
|
5495
5662
|
};
|
|
5496
5663
|
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
5497
5664
|
})
|
|
@@ -5499,17 +5666,6 @@ var getAllAddresses = async (query) => {
|
|
|
5499
5666
|
return results;
|
|
5500
5667
|
};
|
|
5501
5668
|
|
|
5502
|
-
// src/models/suiKit.ts
|
|
5503
|
-
var import_sui_kit4 = require("@scallop-io/sui-kit");
|
|
5504
|
-
var newSuiKit = (params) => {
|
|
5505
|
-
return new import_sui_kit4.SuiKit({
|
|
5506
|
-
...params,
|
|
5507
|
-
fullnodeUrls: Array.from(
|
|
5508
|
-
/* @__PURE__ */ new Set([...params.fullnodeUrls ?? [], ...RPC_PROVIDERS])
|
|
5509
|
-
)
|
|
5510
|
-
});
|
|
5511
|
-
};
|
|
5512
|
-
|
|
5513
5669
|
// src/models/scallopUtils.ts
|
|
5514
5670
|
var ScallopUtils = class {
|
|
5515
5671
|
constructor(params, instance) {
|
|
@@ -5526,18 +5682,15 @@ var ScallopUtils = class {
|
|
|
5526
5682
|
pythEndpoints: params.pythEndpoints ?? PYTH_ENDPOINTS["mainnet"],
|
|
5527
5683
|
...params
|
|
5528
5684
|
};
|
|
5529
|
-
this.
|
|
5530
|
-
this.
|
|
5685
|
+
this.walletAddress = params.walletAddress ?? instance?.suiKit?.currentAddress() ?? "";
|
|
5686
|
+
this.suiKit = instance?.suiKit ?? instance?.address?.cache.suiKit ?? newSuiKit(params);
|
|
5531
5687
|
if (instance?.address) {
|
|
5532
5688
|
this.address = instance.address;
|
|
5533
5689
|
this.cache = this.address.cache;
|
|
5534
|
-
this.suiKit = this.address.cache._suiKit;
|
|
5535
5690
|
} else {
|
|
5536
|
-
this.cache = new ScallopCache(
|
|
5537
|
-
this.suiKit
|
|
5538
|
-
|
|
5539
|
-
DEFAULT_CACHE_OPTIONS
|
|
5540
|
-
);
|
|
5691
|
+
this.cache = new ScallopCache(this.params, {
|
|
5692
|
+
suiKit: this.suiKit
|
|
5693
|
+
});
|
|
5541
5694
|
this.address = instance?.address ?? new ScallopAddress(
|
|
5542
5695
|
{
|
|
5543
5696
|
id: params?.addressesId ?? ADDRESSES_ID,
|
|
@@ -5601,7 +5754,7 @@ var ScallopUtils = class {
|
|
|
5601
5754
|
throw Error(`Coin ${coinName} is not supported`);
|
|
5602
5755
|
}
|
|
5603
5756
|
if (coinName === "sui")
|
|
5604
|
-
return (0,
|
|
5757
|
+
return (0, import_utils10.normalizeStructTag)(`${coinPackageId}::sui::SUI`);
|
|
5605
5758
|
const wormHolePackageIds = [
|
|
5606
5759
|
this.address.get("core.coins.wusdc.id") ?? wormholeCoinIds.wusdc,
|
|
5607
5760
|
this.address.get("core.coins.wusdt.id") ?? wormholeCoinIds.wusdt,
|
|
@@ -5705,7 +5858,7 @@ var ScallopUtils = class {
|
|
|
5705
5858
|
return `${protocolObjectId}::reserve::MarketCoin<${coinType}>`;
|
|
5706
5859
|
}
|
|
5707
5860
|
parseCoinNameFromType(coinType) {
|
|
5708
|
-
coinType = (0,
|
|
5861
|
+
coinType = (0, import_utils10.normalizeStructTag)(coinType);
|
|
5709
5862
|
if (sCoinTypeToName[coinType]) {
|
|
5710
5863
|
return sCoinTypeToName[coinType];
|
|
5711
5864
|
}
|
|
@@ -5789,8 +5942,8 @@ var ScallopUtils = class {
|
|
|
5789
5942
|
* @param coinType - The coin type, default is 0x2::SUI::SUI.
|
|
5790
5943
|
* @return The selected transaction coin arguments.
|
|
5791
5944
|
*/
|
|
5792
|
-
async selectCoins(amount, coinType =
|
|
5793
|
-
ownerAddress = ownerAddress ?? this.
|
|
5945
|
+
async selectCoins(amount, coinType = import_utils10.SUI_TYPE_ARG, ownerAddress) {
|
|
5946
|
+
ownerAddress = ownerAddress ?? this.walletAddress;
|
|
5794
5947
|
const coins = await this.suiKit.suiInteractor.selectCoins(
|
|
5795
5948
|
ownerAddress,
|
|
5796
5949
|
amount,
|
|
@@ -5987,15 +6140,15 @@ var ScallopUtils = class {
|
|
|
5987
6140
|
};
|
|
5988
6141
|
|
|
5989
6142
|
// src/models/scallopBuilder.ts
|
|
5990
|
-
var
|
|
6143
|
+
var import_utils24 = require("@mysten/sui/utils");
|
|
5991
6144
|
|
|
5992
6145
|
// src/builders/coreBuilder.ts
|
|
5993
6146
|
var import_transactions = require("@mysten/sui/transactions");
|
|
5994
|
-
var
|
|
6147
|
+
var import_utils13 = require("@mysten/sui/utils");
|
|
5995
6148
|
var import_sui_kit5 = require("@scallop-io/sui-kit");
|
|
5996
6149
|
|
|
5997
6150
|
// src/builders/oracle.ts
|
|
5998
|
-
var
|
|
6151
|
+
var import_utils12 = require("@mysten/sui/utils");
|
|
5999
6152
|
var import_pyth_sui_js2 = require("@pythnetwork/pyth-sui-js");
|
|
6000
6153
|
var updateOracles = async (builder, txBlock, assetCoinNames, options = { usePythPullModel: true }) => {
|
|
6001
6154
|
const usePythPullModel = builder.params.usePythPullModel ?? options.usePythPullModel;
|
|
@@ -6111,27 +6264,27 @@ var priceUpdateRequest = (txBlock, packageId, xOracleId, coinType) => {
|
|
|
6111
6264
|
var confirmPriceUpdateRequest = (txBlock, packageId, xOracleId, request, coinType) => {
|
|
6112
6265
|
const target = `${packageId}::x_oracle::confirm_price_update_request`;
|
|
6113
6266
|
const typeArgs = [coinType];
|
|
6114
|
-
txBlock.moveCall(target, [xOracleId, request,
|
|
6267
|
+
txBlock.moveCall(target, [xOracleId, request, import_utils12.SUI_CLOCK_OBJECT_ID], typeArgs);
|
|
6115
6268
|
return txBlock;
|
|
6116
6269
|
};
|
|
6117
6270
|
var updateSupraPrice = (txBlock, packageId, request, holderId, registryId, coinType) => {
|
|
6118
6271
|
txBlock.moveCall(
|
|
6119
6272
|
`${packageId}::rule::set_price`,
|
|
6120
|
-
[request, holderId, registryId,
|
|
6273
|
+
[request, holderId, registryId, import_utils12.SUI_CLOCK_OBJECT_ID],
|
|
6121
6274
|
[coinType]
|
|
6122
6275
|
);
|
|
6123
6276
|
};
|
|
6124
6277
|
var updateSwitchboardPrice = (txBlock, packageId, request, aggregatorId, registryId, coinType) => {
|
|
6125
6278
|
txBlock.moveCall(
|
|
6126
6279
|
`${packageId}::rule::set_price`,
|
|
6127
|
-
[request, aggregatorId, registryId,
|
|
6280
|
+
[request, aggregatorId, registryId, import_utils12.SUI_CLOCK_OBJECT_ID],
|
|
6128
6281
|
[coinType]
|
|
6129
6282
|
);
|
|
6130
6283
|
};
|
|
6131
6284
|
var updatePythPrice = (txBlock, packageId, request, stateId, feedObjectId, registryId, coinType) => {
|
|
6132
6285
|
txBlock.moveCall(
|
|
6133
6286
|
`${packageId}::rule::set_price`,
|
|
6134
|
-
[request, stateId, feedObjectId, registryId,
|
|
6287
|
+
[request, stateId, feedObjectId, registryId, import_utils12.SUI_CLOCK_OBJECT_ID],
|
|
6135
6288
|
[coinType]
|
|
6136
6289
|
);
|
|
6137
6290
|
};
|
|
@@ -6211,7 +6364,7 @@ var generateCoreNormalMethod = ({
|
|
|
6211
6364
|
coreIds.coinDecimalsRegistry,
|
|
6212
6365
|
txBlock.pure.u64(amount),
|
|
6213
6366
|
coreIds.xOracle,
|
|
6214
|
-
|
|
6367
|
+
import_utils13.SUI_CLOCK_OBJECT_ID
|
|
6215
6368
|
],
|
|
6216
6369
|
[coinType]
|
|
6217
6370
|
);
|
|
@@ -6221,7 +6374,7 @@ var generateCoreNormalMethod = ({
|
|
|
6221
6374
|
return builder.moveCall(
|
|
6222
6375
|
txBlock,
|
|
6223
6376
|
`${coreIds.protocolPkg}::mint::mint`,
|
|
6224
|
-
[coreIds.version, coreIds.market, coin,
|
|
6377
|
+
[coreIds.version, coreIds.market, coin, import_utils13.SUI_CLOCK_OBJECT_ID],
|
|
6225
6378
|
[coinType]
|
|
6226
6379
|
);
|
|
6227
6380
|
},
|
|
@@ -6230,7 +6383,7 @@ var generateCoreNormalMethod = ({
|
|
|
6230
6383
|
return builder.moveCall(
|
|
6231
6384
|
txBlock,
|
|
6232
6385
|
`${coreIds.protocolPkg}::mint::mint_entry`,
|
|
6233
|
-
[coreIds.version, coreIds.market, coin,
|
|
6386
|
+
[coreIds.version, coreIds.market, coin, import_utils13.SUI_CLOCK_OBJECT_ID],
|
|
6234
6387
|
[coinType]
|
|
6235
6388
|
);
|
|
6236
6389
|
},
|
|
@@ -6239,7 +6392,7 @@ var generateCoreNormalMethod = ({
|
|
|
6239
6392
|
return builder.moveCall(
|
|
6240
6393
|
txBlock,
|
|
6241
6394
|
`${coreIds.protocolPkg}::redeem::redeem`,
|
|
6242
|
-
[coreIds.version, coreIds.market, marketCoin,
|
|
6395
|
+
[coreIds.version, coreIds.market, marketCoin, import_utils13.SUI_CLOCK_OBJECT_ID],
|
|
6243
6396
|
[coinType]
|
|
6244
6397
|
);
|
|
6245
6398
|
},
|
|
@@ -6248,7 +6401,7 @@ var generateCoreNormalMethod = ({
|
|
|
6248
6401
|
return builder.moveCall(
|
|
6249
6402
|
txBlock,
|
|
6250
6403
|
`${coreIds.protocolPkg}::redeem::redeem_entry`,
|
|
6251
|
-
[coreIds.version, coreIds.market, marketCoin,
|
|
6404
|
+
[coreIds.version, coreIds.market, marketCoin, import_utils13.SUI_CLOCK_OBJECT_ID],
|
|
6252
6405
|
[coinType]
|
|
6253
6406
|
);
|
|
6254
6407
|
},
|
|
@@ -6265,7 +6418,7 @@ var generateCoreNormalMethod = ({
|
|
|
6265
6418
|
coreIds.coinDecimalsRegistry,
|
|
6266
6419
|
amount,
|
|
6267
6420
|
coreIds.xOracle,
|
|
6268
|
-
|
|
6421
|
+
import_utils13.SUI_CLOCK_OBJECT_ID
|
|
6269
6422
|
],
|
|
6270
6423
|
[coinType]
|
|
6271
6424
|
);
|
|
@@ -6284,7 +6437,7 @@ var generateCoreNormalMethod = ({
|
|
|
6284
6437
|
borrowReferral,
|
|
6285
6438
|
typeof amount === "number" ? txBlock.pure.u64(amount) : amount,
|
|
6286
6439
|
coreIds.xOracle,
|
|
6287
|
-
|
|
6440
|
+
import_utils13.SUI_CLOCK_OBJECT_ID
|
|
6288
6441
|
],
|
|
6289
6442
|
[coinType, referralWitnessType]
|
|
6290
6443
|
);
|
|
@@ -6302,7 +6455,7 @@ var generateCoreNormalMethod = ({
|
|
|
6302
6455
|
coreIds.coinDecimalsRegistry,
|
|
6303
6456
|
txBlock.pure.u64(amount),
|
|
6304
6457
|
coreIds.xOracle,
|
|
6305
|
-
|
|
6458
|
+
import_utils13.SUI_CLOCK_OBJECT_ID
|
|
6306
6459
|
],
|
|
6307
6460
|
[coinType]
|
|
6308
6461
|
);
|
|
@@ -6317,7 +6470,7 @@ var generateCoreNormalMethod = ({
|
|
|
6317
6470
|
obligation,
|
|
6318
6471
|
coreIds.market,
|
|
6319
6472
|
coin,
|
|
6320
|
-
|
|
6473
|
+
import_utils13.SUI_CLOCK_OBJECT_ID
|
|
6321
6474
|
],
|
|
6322
6475
|
[coinType]
|
|
6323
6476
|
);
|
|
@@ -6554,7 +6707,7 @@ var newCoreTxBlock = (builder, initTxBlock) => {
|
|
|
6554
6707
|
|
|
6555
6708
|
// src/builders/spoolBuilder.ts
|
|
6556
6709
|
var import_transactions2 = require("@mysten/sui/transactions");
|
|
6557
|
-
var
|
|
6710
|
+
var import_utils15 = require("@mysten/sui/utils");
|
|
6558
6711
|
var import_sui_kit6 = require("@scallop-io/sui-kit");
|
|
6559
6712
|
var requireStakeAccountIds = async (...params) => {
|
|
6560
6713
|
const [builder, txBlock, stakeMarketCoinName, stakeAccountId] = params;
|
|
@@ -6610,7 +6763,7 @@ var generateSpoolNormalMethod = ({
|
|
|
6610
6763
|
return builder.moveCall(
|
|
6611
6764
|
txBlock,
|
|
6612
6765
|
`${spoolIds.spoolPkg}::user::new_spool_account`,
|
|
6613
|
-
[stakePoolId,
|
|
6766
|
+
[stakePoolId, import_utils15.SUI_CLOCK_OBJECT_ID],
|
|
6614
6767
|
[marketCoinType]
|
|
6615
6768
|
);
|
|
6616
6769
|
},
|
|
@@ -6622,7 +6775,7 @@ var generateSpoolNormalMethod = ({
|
|
|
6622
6775
|
builder.moveCall(
|
|
6623
6776
|
txBlock,
|
|
6624
6777
|
`${spoolIds.spoolPkg}::user::stake`,
|
|
6625
|
-
[stakePoolId, stakeAccount, coin,
|
|
6778
|
+
[stakePoolId, stakeAccount, coin, import_utils15.SUI_CLOCK_OBJECT_ID],
|
|
6626
6779
|
[marketCoinType]
|
|
6627
6780
|
);
|
|
6628
6781
|
},
|
|
@@ -6634,7 +6787,7 @@ var generateSpoolNormalMethod = ({
|
|
|
6634
6787
|
return builder.moveCall(
|
|
6635
6788
|
txBlock,
|
|
6636
6789
|
`${spoolIds.spoolPkg}::user::unstake`,
|
|
6637
|
-
[stakePoolId, stakeAccount, amount,
|
|
6790
|
+
[stakePoolId, stakeAccount, amount, import_utils15.SUI_CLOCK_OBJECT_ID],
|
|
6638
6791
|
[marketCoinType]
|
|
6639
6792
|
);
|
|
6640
6793
|
},
|
|
@@ -6651,7 +6804,7 @@ var generateSpoolNormalMethod = ({
|
|
|
6651
6804
|
return builder.moveCall(
|
|
6652
6805
|
txBlock,
|
|
6653
6806
|
`${spoolIds.spoolPkg}::user::redeem_rewards`,
|
|
6654
|
-
[stakePoolId, rewardPoolId, stakeAccount,
|
|
6807
|
+
[stakePoolId, rewardPoolId, stakeAccount, import_utils15.SUI_CLOCK_OBJECT_ID],
|
|
6655
6808
|
[marketCoinType, rewardCoinType]
|
|
6656
6809
|
);
|
|
6657
6810
|
}
|
|
@@ -6786,7 +6939,7 @@ var newSpoolTxBlock = (builder, initTxBlock) => {
|
|
|
6786
6939
|
|
|
6787
6940
|
// src/builders/borrowIncentiveBuilder.ts
|
|
6788
6941
|
var import_transactions3 = require("@mysten/sui/transactions");
|
|
6789
|
-
var
|
|
6942
|
+
var import_utils17 = require("@mysten/sui/utils");
|
|
6790
6943
|
var import_sui_kit7 = require("@scallop-io/sui-kit");
|
|
6791
6944
|
var requireObligationInfo2 = async (...params) => {
|
|
6792
6945
|
const [builder, txBlock, obligationId, obligationKey] = params;
|
|
@@ -6839,7 +6992,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
|
6839
6992
|
obligationKey,
|
|
6840
6993
|
obligationId,
|
|
6841
6994
|
borrowIncentiveIds.obligationAccessStore,
|
|
6842
|
-
|
|
6995
|
+
import_utils17.SUI_CLOCK_OBJECT_ID
|
|
6843
6996
|
]
|
|
6844
6997
|
);
|
|
6845
6998
|
},
|
|
@@ -6858,7 +7011,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
|
6858
7011
|
veScaIds.treasury,
|
|
6859
7012
|
veScaIds.table,
|
|
6860
7013
|
veScaKey,
|
|
6861
|
-
|
|
7014
|
+
import_utils17.SUI_CLOCK_OBJECT_ID
|
|
6862
7015
|
],
|
|
6863
7016
|
[]
|
|
6864
7017
|
);
|
|
@@ -6873,7 +7026,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
|
6873
7026
|
borrowIncentiveIds.incentiveAccounts,
|
|
6874
7027
|
obligationKey,
|
|
6875
7028
|
obligationId,
|
|
6876
|
-
|
|
7029
|
+
import_utils17.SUI_CLOCK_OBJECT_ID
|
|
6877
7030
|
]
|
|
6878
7031
|
);
|
|
6879
7032
|
},
|
|
@@ -6888,7 +7041,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
|
6888
7041
|
borrowIncentiveIds.incentiveAccounts,
|
|
6889
7042
|
obligationKey,
|
|
6890
7043
|
obligationId,
|
|
6891
|
-
|
|
7044
|
+
import_utils17.SUI_CLOCK_OBJECT_ID
|
|
6892
7045
|
],
|
|
6893
7046
|
[rewardType]
|
|
6894
7047
|
);
|
|
@@ -6903,7 +7056,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
|
6903
7056
|
borrowIncentiveIds.incentiveAccounts,
|
|
6904
7057
|
obligation,
|
|
6905
7058
|
veScaKey,
|
|
6906
|
-
|
|
7059
|
+
import_utils17.SUI_CLOCK_OBJECT_ID
|
|
6907
7060
|
]
|
|
6908
7061
|
);
|
|
6909
7062
|
}
|
|
@@ -7636,11 +7789,10 @@ var newScallopTxBlock = (builder, initTxBlock) => {
|
|
|
7636
7789
|
|
|
7637
7790
|
// src/models/scallopIndexer.ts
|
|
7638
7791
|
var import_axios2 = __toESM(require("axios"));
|
|
7639
|
-
var import_sui_kit12 = require("@scallop-io/sui-kit");
|
|
7640
7792
|
var ScallopIndexer = class {
|
|
7641
7793
|
constructor(params, instance) {
|
|
7642
7794
|
this.params = params;
|
|
7643
|
-
this.cache = instance?.cache ?? new ScallopCache(
|
|
7795
|
+
this.cache = instance?.cache ?? new ScallopCache(this.params);
|
|
7644
7796
|
this._requestClient = import_axios2.default.create({
|
|
7645
7797
|
baseURL: SDK_API_BASE_URL,
|
|
7646
7798
|
headers: {
|
|
@@ -7812,12 +7964,12 @@ var ScallopIndexer = class {
|
|
|
7812
7964
|
};
|
|
7813
7965
|
|
|
7814
7966
|
// src/models/scallopQuery.ts
|
|
7815
|
-
var
|
|
7967
|
+
var import_utils23 = require("@mysten/sui/utils");
|
|
7816
7968
|
var ScallopQuery = class {
|
|
7817
7969
|
constructor(params, instance) {
|
|
7818
7970
|
this.params = params;
|
|
7819
7971
|
this.suiKit = instance?.suiKit ?? instance?.utils?.suiKit ?? newSuiKit(params);
|
|
7820
|
-
this.walletAddress = (0,
|
|
7972
|
+
this.walletAddress = (0, import_utils23.normalizeSuiAddress)(
|
|
7821
7973
|
params.walletAddress ?? this.suiKit.currentAddress()
|
|
7822
7974
|
);
|
|
7823
7975
|
if (instance?.utils) {
|
|
@@ -7825,11 +7977,9 @@ var ScallopQuery = class {
|
|
|
7825
7977
|
this.address = instance.utils.address;
|
|
7826
7978
|
this.cache = this.address.cache;
|
|
7827
7979
|
} else {
|
|
7828
|
-
this.cache = new ScallopCache(
|
|
7829
|
-
this.suiKit
|
|
7830
|
-
|
|
7831
|
-
DEFAULT_CACHE_OPTIONS
|
|
7832
|
-
);
|
|
7980
|
+
this.cache = new ScallopCache(this.params, {
|
|
7981
|
+
suiKit: this.suiKit
|
|
7982
|
+
});
|
|
7833
7983
|
this.address = new ScallopAddress(
|
|
7834
7984
|
{
|
|
7835
7985
|
id: params?.addressesId ?? ADDRESSES_ID,
|
|
@@ -8184,7 +8334,13 @@ var ScallopQuery = class {
|
|
|
8184
8334
|
* @return All lending and spool infomation.
|
|
8185
8335
|
*/
|
|
8186
8336
|
async getLendings(poolCoinNames, ownerAddress = this.walletAddress, args) {
|
|
8187
|
-
return await getLendings(
|
|
8337
|
+
return await getLendings(
|
|
8338
|
+
this,
|
|
8339
|
+
poolCoinNames,
|
|
8340
|
+
ownerAddress,
|
|
8341
|
+
args?.marketPools,
|
|
8342
|
+
args?.indexer
|
|
8343
|
+
);
|
|
8188
8344
|
}
|
|
8189
8345
|
/**
|
|
8190
8346
|
* Get user lending and spool information for specific pool.
|
|
@@ -8208,7 +8364,12 @@ var ScallopQuery = class {
|
|
|
8208
8364
|
* @return All obligation accounts information.
|
|
8209
8365
|
*/
|
|
8210
8366
|
async getObligationAccounts(ownerAddress = this.walletAddress, args) {
|
|
8211
|
-
return await getObligationAccounts(
|
|
8367
|
+
return await getObligationAccounts(
|
|
8368
|
+
this,
|
|
8369
|
+
ownerAddress,
|
|
8370
|
+
args?.market,
|
|
8371
|
+
args?.indexer
|
|
8372
|
+
);
|
|
8212
8373
|
}
|
|
8213
8374
|
/**
|
|
8214
8375
|
* Get obligation account information for specific id.
|
|
@@ -8383,12 +8544,22 @@ var ScallopQuery = class {
|
|
|
8383
8544
|
return getAllCoinPrices(this, args?.marketPools, args?.coinPrices);
|
|
8384
8545
|
}
|
|
8385
8546
|
/**
|
|
8386
|
-
* Query all address (lending pool, collateral pool, borrow dynamics, interest models) of all pool
|
|
8547
|
+
* Query all address (lending pool, collateral pool, borrow dynamics, interest models, etc.) of all pool
|
|
8387
8548
|
* @returns
|
|
8388
8549
|
*/
|
|
8389
8550
|
async getPoolAddresses() {
|
|
8390
8551
|
return getAllAddresses(this);
|
|
8391
8552
|
}
|
|
8553
|
+
/**
|
|
8554
|
+
* Get user portfolio
|
|
8555
|
+
*/
|
|
8556
|
+
async getUserPortfolio(args) {
|
|
8557
|
+
return getUserPortfolio(
|
|
8558
|
+
this,
|
|
8559
|
+
args?.walletAddress ?? this.walletAddress,
|
|
8560
|
+
args?.indexer ?? false
|
|
8561
|
+
);
|
|
8562
|
+
}
|
|
8392
8563
|
};
|
|
8393
8564
|
|
|
8394
8565
|
// src/models/scallopBuilder.ts
|
|
@@ -8396,7 +8567,7 @@ var ScallopBuilder = class {
|
|
|
8396
8567
|
constructor(params, instance) {
|
|
8397
8568
|
this.suiKit = instance?.suiKit ?? newSuiKit(params);
|
|
8398
8569
|
this.params = params;
|
|
8399
|
-
this.walletAddress = (0,
|
|
8570
|
+
this.walletAddress = (0, import_utils24.normalizeSuiAddress)(
|
|
8400
8571
|
params?.walletAddress ?? this.suiKit.currentAddress()
|
|
8401
8572
|
);
|
|
8402
8573
|
if (instance?.query) {
|
|
@@ -8405,11 +8576,9 @@ var ScallopBuilder = class {
|
|
|
8405
8576
|
this.address = this.utils.address;
|
|
8406
8577
|
this.cache = this.address.cache;
|
|
8407
8578
|
} else {
|
|
8408
|
-
this.cache = new ScallopCache(
|
|
8409
|
-
this.suiKit
|
|
8410
|
-
|
|
8411
|
-
DEFAULT_CACHE_OPTIONS
|
|
8412
|
-
);
|
|
8579
|
+
this.cache = new ScallopCache(this.params, {
|
|
8580
|
+
suiKit: this.suiKit
|
|
8581
|
+
});
|
|
8413
8582
|
this.address = new ScallopAddress(
|
|
8414
8583
|
{
|
|
8415
8584
|
id: params?.addressesId ?? ADDRESSES_ID,
|
|
@@ -8545,7 +8714,7 @@ var ScallopClient = class {
|
|
|
8545
8714
|
constructor(params, instance) {
|
|
8546
8715
|
this.params = params;
|
|
8547
8716
|
this.suiKit = instance?.suiKit ?? instance?.builder?.suiKit ?? newSuiKit(params);
|
|
8548
|
-
this.walletAddress = (0,
|
|
8717
|
+
this.walletAddress = (0, import_utils25.normalizeSuiAddress)(
|
|
8549
8718
|
params?.walletAddress ?? this.suiKit.currentAddress()
|
|
8550
8719
|
);
|
|
8551
8720
|
if (instance?.builder) {
|
|
@@ -8555,11 +8724,9 @@ var ScallopClient = class {
|
|
|
8555
8724
|
this.address = this.utils.address;
|
|
8556
8725
|
this.cache = this.address.cache;
|
|
8557
8726
|
} else {
|
|
8558
|
-
this.cache = new ScallopCache(
|
|
8559
|
-
this.suiKit
|
|
8560
|
-
|
|
8561
|
-
DEFAULT_CACHE_OPTIONS
|
|
8562
|
-
);
|
|
8727
|
+
this.cache = new ScallopCache(this.params, {
|
|
8728
|
+
suiKit: this.suiKit
|
|
8729
|
+
});
|
|
8563
8730
|
this.address = new ScallopAddress(
|
|
8564
8731
|
{
|
|
8565
8732
|
id: params?.addressesId ?? ADDRESSES_ID,
|
|
@@ -9233,15 +9400,18 @@ var ScallopClient = class {
|
|
|
9233
9400
|
|
|
9234
9401
|
// src/models/scallop.ts
|
|
9235
9402
|
var Scallop = class {
|
|
9236
|
-
constructor(params, cacheOptions,
|
|
9403
|
+
constructor(params, cacheOptions, queryClient) {
|
|
9237
9404
|
this.params = params;
|
|
9238
9405
|
this.suiKit = newSuiKit(params);
|
|
9239
9406
|
this.cache = new ScallopCache(
|
|
9240
|
-
|
|
9241
|
-
|
|
9242
|
-
|
|
9243
|
-
|
|
9244
|
-
|
|
9407
|
+
{
|
|
9408
|
+
...this.params,
|
|
9409
|
+
cacheOptions
|
|
9410
|
+
},
|
|
9411
|
+
{
|
|
9412
|
+
suiKit: this.suiKit,
|
|
9413
|
+
queryClient
|
|
9414
|
+
}
|
|
9245
9415
|
);
|
|
9246
9416
|
this.address = new ScallopAddress(
|
|
9247
9417
|
{
|
|
@@ -9352,8 +9522,6 @@ var Scallop = class {
|
|
|
9352
9522
|
BORROW_FEE_PROTOCOL_ID,
|
|
9353
9523
|
COIN_GECKGO_IDS,
|
|
9354
9524
|
DEFAULT_CACHE_OPTIONS,
|
|
9355
|
-
DEFAULT_INTERVAL_IN_MS,
|
|
9356
|
-
DEFAULT_TOKENS_PER_INTERVAL,
|
|
9357
9525
|
FlashLoanFeeObjectMap,
|
|
9358
9526
|
IS_VE_SCA_TEST,
|
|
9359
9527
|
MAX_LOCK_DURATION,
|
|
@@ -9388,11 +9556,9 @@ var Scallop = class {
|
|
|
9388
9556
|
ScallopQuery,
|
|
9389
9557
|
ScallopUtils,
|
|
9390
9558
|
TEST_ADDRESSES,
|
|
9391
|
-
TokenBucket,
|
|
9392
9559
|
UNLOCK_ROUND_DURATION,
|
|
9393
9560
|
USE_TEST_ADDRESS,
|
|
9394
9561
|
assetCoins,
|
|
9395
|
-
callWithRateLimit,
|
|
9396
9562
|
coinDecimals,
|
|
9397
9563
|
coinIds,
|
|
9398
9564
|
marketCoins,
|