@scallop-io/sui-scallop-sdk 1.3.4-alpha.1 → 1.3.4-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +550 -544
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +549 -544
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/builders/loyaltyProgramBuilder.ts +1 -1
- package/src/constants/common.ts +0 -1
- package/src/constants/enum.ts +12 -11
- package/src/constants/index.ts +0 -1
- package/src/constants/queryKeys.ts +1 -5
- package/src/constants/rpc.ts +16 -0
- package/src/constants/testAddress.ts +35 -76
- package/src/constants/tokenBucket.ts +1 -1
- package/src/models/scallop.ts +3 -2
- package/src/models/scallopAddress.ts +2 -2
- package/src/models/scallopBuilder.ts +7 -5
- package/src/models/scallopCache.ts +1 -1
- package/src/models/scallopClient.ts +27 -26
- package/src/models/scallopQuery.ts +61 -19
- package/src/models/scallopUtils.ts +74 -109
- package/src/models/suiKit.ts +11 -0
- package/src/queries/borrowIncentiveQuery.ts +6 -13
- package/src/queries/coreQuery.ts +245 -236
- package/src/queries/isolatedAsset.ts +4 -4
- package/src/queries/loyaltyProgramQuery.ts +1 -1
- package/src/queries/portfolioQuery.ts +58 -34
- package/src/queries/referralQuery.ts +1 -0
- package/src/queries/spoolQuery.ts +17 -17
- package/src/types/query/core.ts +0 -1
- package/src/utils/tokenBucket.ts +2 -1
- package/dist/builders/borrowIncentiveBuilder.d.ts +0 -12
- package/dist/builders/coreBuilder.d.ts +0 -12
- package/dist/builders/index.d.ts +0 -12
- package/dist/builders/loyaltyProgramBuilder.d.ts +0 -12
- package/dist/builders/oracle.d.ts +0 -14
- package/dist/builders/referralBuilder.d.ts +0 -12
- package/dist/builders/sCoinBuilder.d.ts +0 -4
- package/dist/builders/spoolBuilder.d.ts +0 -12
- package/dist/builders/vescaBuilder.d.ts +0 -25
- package/dist/constants/cache.d.ts +0 -14
- package/dist/constants/coinGecko.d.ts +0 -2
- package/dist/constants/common.d.ts +0 -20
- package/dist/constants/enum.d.ts +0 -13
- package/dist/constants/flashloan.d.ts +0 -2
- package/dist/constants/index.d.ts +0 -12
- package/dist/constants/poolAddress.d.ts +0 -5
- package/dist/constants/pyth.d.ts +0 -5
- package/dist/constants/queryKeys.d.ts +0 -59
- package/dist/constants/testAddress.d.ts +0 -2
- package/dist/constants/tokenBucket.d.ts +0 -2
- package/dist/constants/vesca.d.ts +0 -5
- package/dist/index.d.ts +0 -3
- package/dist/models/index.d.ts +0 -8
- package/dist/models/scallop.d.ts +0 -74
- package/dist/models/scallopAddress.d.ts +0 -150
- package/dist/models/scallopBuilder.d.ts +0 -89
- package/dist/models/scallopCache.d.ts +0 -74
- package/dist/models/scallopClient.d.ts +0 -321
- package/dist/models/scallopIndexer.d.ts +0 -89
- package/dist/models/scallopQuery.d.ts +0 -474
- package/dist/models/scallopUtils.d.ts +0 -222
- package/dist/queries/borrowIncentiveQuery.d.ts +0 -61
- package/dist/queries/coreQuery.d.ts +0 -167
- package/dist/queries/index.d.ts +0 -8
- package/dist/queries/isolatedAsset.d.ts +0 -14
- package/dist/queries/loyaltyProgramQuery.d.ts +0 -10
- package/dist/queries/portfolioQuery.d.ts +0 -73
- package/dist/queries/priceQuery.d.ts +0 -16
- package/dist/queries/referralQuery.d.ts +0 -7
- package/dist/queries/sCoinQuery.d.ts +0 -41
- package/dist/queries/spoolQuery.d.ts +0 -70
- package/dist/queries/supplyLimit.d.ts +0 -9
- package/dist/queries/vescaQuery.d.ts +0 -36
- package/dist/types/address.d.ts +0 -107
- package/dist/types/builder/borrowIncentive.d.ts +0 -35
- package/dist/types/builder/core.d.ts +0 -56
- package/dist/types/builder/index.d.ts +0 -24
- package/dist/types/builder/loyaltyProgram.d.ts +0 -23
- package/dist/types/builder/referral.d.ts +0 -30
- package/dist/types/builder/sCoin.d.ts +0 -37
- package/dist/types/builder/spool.d.ts +0 -29
- package/dist/types/builder/vesca.d.ts +0 -51
- package/dist/types/constant/common.d.ts +0 -24
- package/dist/types/constant/enum.d.ts +0 -48
- package/dist/types/constant/index.d.ts +0 -2
- package/dist/types/index.d.ts +0 -6
- package/dist/types/model.d.ts +0 -54
- package/dist/types/query/borrowIncentive.d.ts +0 -124
- package/dist/types/query/core.d.ts +0 -362
- package/dist/types/query/index.d.ts +0 -7
- package/dist/types/query/loyaltyProgram.d.ts +0 -5
- package/dist/types/query/portfolio.d.ts +0 -115
- package/dist/types/query/sCoin.d.ts +0 -1
- package/dist/types/query/spool.d.ts +0 -122
- package/dist/types/query/vesca.d.ts +0 -26
- package/dist/types/utils.d.ts +0 -21
- package/dist/utils/builder.d.ts +0 -15
- package/dist/utils/index.d.ts +0 -5
- package/dist/utils/indexer.d.ts +0 -17
- package/dist/utils/query.d.ts +0 -62
- package/dist/utils/tokenBucket.d.ts +0 -11
- package/dist/utils/util.d.ts +0 -26
package/dist/index.js
CHANGED
|
@@ -79,6 +79,7 @@ __export(src_exports, {
|
|
|
79
79
|
marketCoins: () => marketCoins,
|
|
80
80
|
queryKeys: () => queryKeys,
|
|
81
81
|
sCoinIds: () => sCoinIds,
|
|
82
|
+
sCoinTypeToName: () => sCoinTypeToName,
|
|
82
83
|
sCoins: () => sCoins,
|
|
83
84
|
spoolRewardCoins: () => spoolRewardCoins,
|
|
84
85
|
stakeMarketCoins: () => stakeMarketCoins,
|
|
@@ -372,20 +373,11 @@ var voloCoinIds = {
|
|
|
372
373
|
var sCoinIds = {
|
|
373
374
|
susdc: "0x854950aa624b1df59fe64e630b2ba7c550642e9342267a33061d59fb31582da5::scallop_usdc::SCALLOP_USDC",
|
|
374
375
|
ssbeth: "0xb14f82d8506d139eacef109688d1b71e7236bcce9b2c0ad526abcd6aa5be7de0::scallop_sb_eth::SCALLOP_SB_ETH",
|
|
375
|
-
|
|
376
|
-
ssui: "0xf569919046f19a0c40b519ecfbb6ca0319698cd5908716c29b62ef56541f298b::scallop_sui::SCALLOP_SUI",
|
|
377
|
-
// ssui: '0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI',
|
|
376
|
+
ssui: "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI",
|
|
378
377
|
scetus: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
// TODO: Change this to the correct value on production release
|
|
383
|
-
swusdc: "0xf5447c4305a486d8c8557559887c2c39449ddb5e748f15d33946d02a1663c158::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
384
|
-
// '0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC',
|
|
385
|
-
swusdt: (
|
|
386
|
-
// '0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT',
|
|
387
|
-
"0xac781d9f73058ff5e69f9bf8dde32f2e8c71c66d7fe8497fc83b2d9182254b22::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT"
|
|
388
|
-
),
|
|
378
|
+
ssca: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
|
|
379
|
+
swusdc: "0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
380
|
+
swusdt: "0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
|
|
389
381
|
sweth: "0x67540ceb850d418679e69f1fb6b2093d6df78a2a699ffc733f7646096d552e9b::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
|
|
390
382
|
safsui: "0x00671b1fa2a124f5be8bdae8b91ee711462c5d9e31bda232e70fd9607b523c88::scallop_af_sui::SCALLOP_AF_SUI",
|
|
391
383
|
shasui: "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI",
|
|
@@ -393,6 +385,13 @@ var sCoinIds = {
|
|
|
393
385
|
swsol: "0x1392650f2eca9e3f6ffae3ff89e42a3590d7102b80e2b430f674730bc30d3259::scallop_wormhole_sol::SCALLOP_WORMHOLE_SOL",
|
|
394
386
|
swbtc: "0x2cf76a9cf5d3337961d1154283234f94da2dcff18544dfe5cbdef65f319591b5::scallop_wormhole_btc::SCALLOP_WORMHOLE_BTC"
|
|
395
387
|
};
|
|
388
|
+
var sCoinTypeToName = Object.entries(sCoinIds).reduce(
|
|
389
|
+
(acc, [coinName, coinType]) => {
|
|
390
|
+
acc[coinType] = coinName;
|
|
391
|
+
return acc;
|
|
392
|
+
},
|
|
393
|
+
{}
|
|
394
|
+
);
|
|
396
395
|
|
|
397
396
|
// src/constants/flashloan.ts
|
|
398
397
|
var FlashLoanFeeObjectMap = {
|
|
@@ -568,11 +567,7 @@ var queryKeys = {
|
|
|
568
567
|
]
|
|
569
568
|
},
|
|
570
569
|
oracle: {
|
|
571
|
-
|
|
572
|
-
"oracle",
|
|
573
|
-
"getPythPriceId",
|
|
574
|
-
{ pythPriceId, endpoint }
|
|
575
|
-
]
|
|
570
|
+
getPythLatestPriceFeeds: () => ["oracle", "getPythPriceIds"]
|
|
576
571
|
}
|
|
577
572
|
};
|
|
578
573
|
|
|
@@ -581,33 +576,20 @@ var TEST_ADDRESSES = {
|
|
|
581
576
|
core: {
|
|
582
577
|
// version:
|
|
583
578
|
// '0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7',
|
|
584
|
-
version: "
|
|
579
|
+
version: "0x6156d5cd1538bec8a167a40fe1209a4ec9cf8137921fe0a697f191ac561f0b09",
|
|
585
580
|
versionCap: "0x590a4011cb649b3878f3ea14b3a78674642a9548d79b7e091ef679574b158a07",
|
|
586
581
|
// object:
|
|
587
582
|
// '0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf',
|
|
588
|
-
object: "
|
|
583
|
+
object: "0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1",
|
|
589
584
|
// market:
|
|
590
585
|
// '0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9',
|
|
591
|
-
market: "
|
|
586
|
+
market: "0x8606ed145cc887985b8ed793f7753ff5dc762a42c379dac035f568e1bac58490",
|
|
592
587
|
adminCap: "0x09689d018e71c337d9db6d67cbca06b74ed92196103624028ccc3ecea411777c",
|
|
593
588
|
coinDecimalsRegistry: "0x200abe9bf19751cc566ae35aa58e2b7e4ff688fc1130f8d8909ea09bc137d668",
|
|
594
589
|
// obligationAccessStore:
|
|
595
590
|
// '0x733e30b7c94d619d78cb8f5bc4bfbb759ced9a531239028caabb2474e5be59c9',
|
|
596
|
-
obligationAccessStore: "
|
|
591
|
+
obligationAccessStore: "0x48b472d68ca910c45f7f3b6c26836b6aa6d2569810d94b1b939023da05ae0a23",
|
|
597
592
|
coins: {
|
|
598
|
-
usdc: {
|
|
599
|
-
id: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7",
|
|
600
|
-
metaData: "0x69b7a7c3c200439c1b5f3b19d7d495d5966d5f08de66c69276152f8db3992ec6",
|
|
601
|
-
treasury: "",
|
|
602
|
-
oracle: {
|
|
603
|
-
supra: "",
|
|
604
|
-
switchboard: "",
|
|
605
|
-
pyth: {
|
|
606
|
-
feed: "eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
|
|
607
|
-
feedObject: "0x5dec622733a204ca27f5a90d8c2fad453cc6665186fd5dff13a83d0b6c9027ab"
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
},
|
|
611
593
|
cetus: {
|
|
612
594
|
id: "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b",
|
|
613
595
|
metaData: "0x4c0dce55eff2db5419bbd2d239d1aa22b4a400c01bbb648b058a9883989025da",
|
|
@@ -763,19 +745,6 @@ var TEST_ADDRESSES = {
|
|
|
763
745
|
feedObject: "0xf6de1d3279a269a597d813cbaca59aa906543ab9a8c64e84a4722f1a20863985"
|
|
764
746
|
}
|
|
765
747
|
}
|
|
766
|
-
},
|
|
767
|
-
sbeth: {
|
|
768
|
-
id: "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29",
|
|
769
|
-
metaData: "0x89b04ba87f8832d4d76e17a1c9dce72eb3e64d372cf02012b8d2de5384faeef0",
|
|
770
|
-
treasury: "",
|
|
771
|
-
oracle: {
|
|
772
|
-
supra: "",
|
|
773
|
-
switchboard: "",
|
|
774
|
-
pyth: {
|
|
775
|
-
feed: "ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",
|
|
776
|
-
feedObject: "0x9193fd47f9a0ab99b6e365a464c8a9ae30e6150fc37ed2a89c1586631f6fc4ab"
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
748
|
}
|
|
780
749
|
},
|
|
781
750
|
oracles: {
|
|
@@ -809,7 +778,7 @@ var TEST_ADDRESSES = {
|
|
|
809
778
|
upgradeCap: "0x3f203f6fff6a69d151e4f1cd931f22b68c489ef2759765662fc7baf673943c9e"
|
|
810
779
|
},
|
|
811
780
|
protocol: {
|
|
812
|
-
id: "
|
|
781
|
+
id: "0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1",
|
|
813
782
|
upgradeCap: "0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a"
|
|
814
783
|
},
|
|
815
784
|
// protocol: {
|
|
@@ -827,7 +796,7 @@ var TEST_ADDRESSES = {
|
|
|
827
796
|
// '0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f',
|
|
828
797
|
// },
|
|
829
798
|
query: {
|
|
830
|
-
id: "
|
|
799
|
+
id: "0xe4f9d62d17746d5b9dbf0d5557747430021a71575780b515161210cdba0a4c1c",
|
|
831
800
|
upgradeCap: "0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f"
|
|
832
801
|
},
|
|
833
802
|
supra: { id: "", upgradeCap: "" },
|
|
@@ -863,10 +832,6 @@ var TEST_ADDRESSES = {
|
|
|
863
832
|
"0xc3206071a8d43212efb6e3b5504f2321f8df97ab122b466c0bc7cfdf398dc13a"
|
|
864
833
|
)
|
|
865
834
|
},
|
|
866
|
-
susdc: {
|
|
867
|
-
id: "0x0b5f5f413bd3799e4052c37311966c77f3a4545eb125d2e93e67a68478021918",
|
|
868
|
-
rewardPoolId: "0x85ed6ed72ea97c35dbf0cdc7ed6fbc48d8ec15de9b17c74bf4512df8a6d7f166"
|
|
869
|
-
},
|
|
870
835
|
swusdc: {
|
|
871
836
|
// id: '0x4ace6648ddc64e646ba47a957c562c32c9599b3bba8f5ac1aadb2ae23a2f8ca0',
|
|
872
837
|
id: "0xf1b383b9cf2e9f515fc69567df1053098f273849d09cd84b0278a773429bd2b2",
|
|
@@ -915,37 +880,37 @@ var TEST_ADDRESSES = {
|
|
|
915
880
|
config: ""
|
|
916
881
|
},
|
|
917
882
|
borrowIncentive: {
|
|
918
|
-
id: "
|
|
919
|
-
adminCap: "
|
|
920
|
-
object: "
|
|
921
|
-
query: "
|
|
922
|
-
incentivePools: "
|
|
923
|
-
incentiveAccounts: "
|
|
924
|
-
config: "
|
|
883
|
+
id: "0x6152f696fc3a658f33c4b891764731a59153125ffedfa8bff7167c42823f58a9",
|
|
884
|
+
adminCap: "0xc486afa253646f4d381e81d7f1df8aa4723b845a6bb356f69bad635ffefffe2c",
|
|
885
|
+
object: "0x002875153e09f8145ab63527bc85c00f2bd102e12f9573c47f8cdf1a1cb62934",
|
|
886
|
+
query: "0x529edc54a3dce2207703ceebbccb0ac14133f7825c1f528775ba0d85a4063489",
|
|
887
|
+
incentivePools: "0x6547e143d406b5ccd5f46aae482497de279cc1a68c406f701df70a05f9212ab4",
|
|
888
|
+
incentiveAccounts: "0xc4701fdbc1c92f9a636d334d66012b3027659e9fb8aff27279a82edfb6b77d02",
|
|
889
|
+
config: "0xdf5d04b4691cc67e82fd4db8394d89ff44823a9de29716c924f74bb4f11cc1f7"
|
|
925
890
|
},
|
|
926
891
|
referral: {
|
|
927
|
-
id: "
|
|
892
|
+
id: "0xa3654ebb63eb06c0f4ff52f8aa6512df9f164f7772bdf15dac3709bd3798dda9",
|
|
928
893
|
object: "0x5658d4bf5ddcba27e4337b4262108b3ad1716643cac8c2054ac341538adc72ec",
|
|
929
894
|
adminCap: "0xc5dc06b9074291259f2cac460c940012c781c4430e42125c541cc43101c3bcbd",
|
|
930
|
-
referralBindings: "
|
|
931
|
-
bindingTableId: "
|
|
932
|
-
referralRevenuePool: "
|
|
895
|
+
referralBindings: "0xf63299d58789d99de94092b9011323466e55ca0c1ea1a7a3786a589af46e1c09",
|
|
896
|
+
bindingTableId: "0x1c8202b17267ec8d6cf97ca013615354181a04f179570e42601ff2dae19294b1",
|
|
897
|
+
referralRevenuePool: "0x6abd852caf90769c1b185cdf636d841673fa95528f0550f018b8a138bd283c07",
|
|
933
898
|
revenueTableId: "0x595baa3654c297bff84ab7786a2d250f019cefc66e8df8e89fd9d41e02bd30dd",
|
|
934
|
-
referralTiers: "
|
|
899
|
+
referralTiers: "0x962cb903d8d7346190c5204785ccbb91b61086aa764f674c8145df82335cf83e",
|
|
935
900
|
tiersTableId: "0xeac755a7a8b7798530905ac79e8c114f19d0f130f6eab012954f08faac29c75d",
|
|
936
901
|
// authorizedWitnessList:
|
|
937
902
|
// '0xf21b0ed043c9bb70842c0129159f4943dbcc3c9ef2f2f808af65f8be25cfd20e',
|
|
938
903
|
authorizedWitnessList: "0x9d6223dc52015b8a3986a573590ef2af8f1b8f3e4685513888c052f001b87e7f",
|
|
939
|
-
version: "
|
|
904
|
+
version: "0x1bd4b7285f72e11c316b828c7c47b3f4da18dcec9f9b3dba6d8629cbb6f93e5e"
|
|
940
905
|
},
|
|
941
906
|
vesca: {
|
|
942
|
-
id: "
|
|
943
|
-
object: "
|
|
907
|
+
id: "0xb15b6e0cdd85afb5028bea851dd249405e734d800a259147bbc24980629723a4",
|
|
908
|
+
object: "0xb15b6e0cdd85afb5028bea851dd249405e734d800a259147bbc24980629723a4",
|
|
944
909
|
adminCap: "0x8ffa76135c5b85c5fbd73a6448a4a733d826cb63a267ab817656acb77c72d4a5",
|
|
945
|
-
tableId: "
|
|
946
|
-
table: "
|
|
947
|
-
treasury: "
|
|
948
|
-
config: "
|
|
910
|
+
tableId: "0xe3153b2bf124be0b86cb8bd468346a861efd0da52fc42197b54d2f616488a311",
|
|
911
|
+
table: "0x611cb8d9d4d90867467b5ebdf4cc447a0047ed5b01334a28a29fcfe733e3d609",
|
|
912
|
+
treasury: "0xe8c112c09b88158dc6c8e23d1fbae5b3c7136cdee54b7dafc08e65db28c4a5bc",
|
|
913
|
+
config: "0xe0a2ff281e73c1d53cfa85807080f87e833e4f1a7f93dcf8800b3865269a76b9"
|
|
949
914
|
},
|
|
950
915
|
loyaltyProgram: {
|
|
951
916
|
id: "0xd17bcf8b5a59652c36225d478564a8593ae0ed7d650bcacdda1d6fe179127907",
|
|
@@ -954,27 +919,27 @@ var TEST_ADDRESSES = {
|
|
|
954
919
|
userRewardTableId: "0x748a80395849ed37db1b0e14f2ab5d1d96458d2359ab3a84eb079d0f4ac7cf2e"
|
|
955
920
|
},
|
|
956
921
|
scoin: {
|
|
957
|
-
id: "
|
|
922
|
+
id: "0xad2ca2aa5089df94bb2d444d5eb3520378c2f2dfb3a0bd2a2c994145ac4b0a53",
|
|
958
923
|
coins: {
|
|
959
924
|
ssui: {
|
|
960
|
-
coinType: "
|
|
961
|
-
treasury: "
|
|
925
|
+
coinType: "0xfac769100bccc0caebcf4f4e2d00ac2f8883f07f724be28940df90605f5e7e9a::scallop_sui::SCALLOP_SUI",
|
|
926
|
+
treasury: "0x9cb4551b36c17d37e19d700147fa819ea1c487ff8bcf18374de2cceb2e9d4845"
|
|
962
927
|
},
|
|
963
928
|
scetus: {
|
|
964
929
|
coinType: "0x8b71e6d323ed78515af2bead13bf3d0da1562ba4a99234eb7c4f14fd39ef0427::scallop_cetus::SCALLOP_CETUS",
|
|
965
930
|
treasury: "0xd786f4b2d26278cc7911a3445b1b085eab60f269ef9dbb6b87e803d52f155003"
|
|
966
931
|
},
|
|
967
932
|
ssca: {
|
|
968
|
-
coinType: "
|
|
969
|
-
treasury: "
|
|
933
|
+
coinType: "0x0a9d3c6c9af9f6e8def82921541bcbd17f73ed31bed3adcb684f2a4c267e42f0::scallop_sca::SCALLOP_SCA",
|
|
934
|
+
treasury: "0xe818636d1d6c46d6ea1a2dce9d94696d7cbc18ce27451b603eeaa47aba8d75e0"
|
|
970
935
|
},
|
|
971
936
|
swusdc: {
|
|
972
|
-
coinType: "
|
|
973
|
-
treasury: "
|
|
937
|
+
coinType: "0xaedc3ab75db8680b81a755015fa90124d217be93457b893c05bac033817defaf::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
938
|
+
treasury: "0xfc6971648f867f7fd6928d1b873af71577e2eaf2c7543ef8bc82c431d833ae78"
|
|
974
939
|
},
|
|
975
940
|
swusdt: {
|
|
976
|
-
coinType: "
|
|
977
|
-
treasury: "
|
|
941
|
+
coinType: "0xbf02fc87ddc104b342ad8414c85ceadf5b0c823c055a06fb0ed776272c01a52a::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
|
|
942
|
+
treasury: "0xb9593e2c3a0ba796ee815012b75ae46468ea78cda0188b9ac6816efe65503521"
|
|
978
943
|
},
|
|
979
944
|
sweth: {
|
|
980
945
|
coinType: "0x27d54f43e3eda701be56b82e5756e41c84467cd202f5cf713d5f9e45a9f1b6bc::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
|
|
@@ -990,18 +955,14 @@ var TEST_ADDRESSES = {
|
|
|
990
955
|
},
|
|
991
956
|
svsui: {
|
|
992
957
|
coinType: "0x97023a317320c4498cc4cd239dd02fd30c28246e5e8f81325d63f2bd8d70f6b3::scallop_v_sui::SCALLOP_V_SUI",
|
|
993
|
-
treasury: "0x327114f0bf3559d7e2de10282147ed76a236c7c6775029165c4db09a6062ead6"
|
|
994
|
-
},
|
|
995
|
-
ssbeth: {
|
|
996
|
-
coinType: "0xb14f82d8506d139eacef109688d1b71e7236bcce9b2c0ad526abcd6aa5be7de0::scallop_sb_eth::SCALLOP_SB_ETH",
|
|
997
|
-
treasury: "0xfd0f02def6358a1f266acfa1493d4707ee8387460d434fb667d63d755ff907ed"
|
|
958
|
+
treasury: "0x327114f0bf3559d7e2de10282147ed76a236c7c6775029165c4db09a6062ead6\u0192"
|
|
998
959
|
}
|
|
999
960
|
}
|
|
1000
961
|
}
|
|
1001
962
|
};
|
|
1002
963
|
|
|
1003
964
|
// src/constants/tokenBucket.ts
|
|
1004
|
-
var DEFAULT_TOKENS_PER_INTERVAL =
|
|
965
|
+
var DEFAULT_TOKENS_PER_INTERVAL = 10;
|
|
1005
966
|
var DEFAULT_INTERVAL_IN_MS = 300;
|
|
1006
967
|
|
|
1007
968
|
// src/constants/vesca.ts
|
|
@@ -1011,9 +972,6 @@ var MAX_LOCK_DURATION = MAX_LOCK_ROUNDS * UNLOCK_ROUND_DURATION;
|
|
|
1011
972
|
var MIN_INITIAL_LOCK_AMOUNT = 1e10;
|
|
1012
973
|
var MIN_TOP_UP_AMOUNT = 1e9;
|
|
1013
974
|
|
|
1014
|
-
// src/models/scallop.ts
|
|
1015
|
-
var import_sui_kit16 = require("@scallop-io/sui-kit");
|
|
1016
|
-
|
|
1017
975
|
// src/models/scallopAddress.ts
|
|
1018
976
|
var import_sui_kit2 = require("@scallop-io/sui-kit");
|
|
1019
977
|
|
|
@@ -1606,7 +1564,7 @@ var TokenBucket = class {
|
|
|
1606
1564
|
return false;
|
|
1607
1565
|
}
|
|
1608
1566
|
};
|
|
1609
|
-
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries =
|
|
1567
|
+
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 30, backoffFactor = 1.25) => {
|
|
1610
1568
|
let retries = 0;
|
|
1611
1569
|
const tryRequest = async () => {
|
|
1612
1570
|
if (tokenBucket.removeTokens(1)) {
|
|
@@ -1825,7 +1783,7 @@ var ScallopCache = class {
|
|
|
1825
1783
|
async queryGetCoinBalance(input) {
|
|
1826
1784
|
if (!input.coinType)
|
|
1827
1785
|
return "0";
|
|
1828
|
-
return (await this.queryGetAllCoinBalances(input.owner)
|
|
1786
|
+
return (await this.queryGetAllCoinBalances(input.owner) ?? {})[(0, import_sui_kit.normalizeStructTag)(input.coinType)] ?? "0";
|
|
1829
1787
|
}
|
|
1830
1788
|
};
|
|
1831
1789
|
|
|
@@ -2186,12 +2144,12 @@ var ScallopAddress = class {
|
|
|
2186
2144
|
"Content-Type": "application/json",
|
|
2187
2145
|
Accept: "application/json"
|
|
2188
2146
|
},
|
|
2189
|
-
timeout:
|
|
2147
|
+
timeout: 8e3
|
|
2190
2148
|
});
|
|
2191
2149
|
if (auth)
|
|
2192
2150
|
this._auth = auth;
|
|
2193
2151
|
this._id = id;
|
|
2194
|
-
this._network = network
|
|
2152
|
+
this._network = network ?? "mainnet";
|
|
2195
2153
|
this._addressesMap = USE_TEST_ADDRESS ? /* @__PURE__ */ new Map([["mainnet", TEST_ADDRESSES]]) : /* @__PURE__ */ new Map();
|
|
2196
2154
|
if (USE_TEST_ADDRESS)
|
|
2197
2155
|
this._currentAddresses = TEST_ADDRESSES;
|
|
@@ -2494,11 +2452,9 @@ var ScallopAddress = class {
|
|
|
2494
2452
|
|
|
2495
2453
|
// src/models/scallopClient.ts
|
|
2496
2454
|
var import_utils25 = require("@mysten/sui/utils");
|
|
2497
|
-
var import_sui_kit15 = require("@scallop-io/sui-kit");
|
|
2498
2455
|
|
|
2499
2456
|
// src/models/scallopUtils.ts
|
|
2500
2457
|
var import_utils10 = require("@mysten/sui/utils");
|
|
2501
|
-
var import_sui_kit4 = require("@scallop-io/sui-kit");
|
|
2502
2458
|
var import_pyth_sui_js = require("@pythnetwork/pyth-sui-js");
|
|
2503
2459
|
|
|
2504
2460
|
// src/queries/coreQuery.ts
|
|
@@ -2540,103 +2496,20 @@ var getSupplyLimit = async (utils, poolName) => {
|
|
|
2540
2496
|
return parsedData.data.fields.value;
|
|
2541
2497
|
};
|
|
2542
2498
|
|
|
2543
|
-
// src/queries/isolatedAsset.ts
|
|
2544
|
-
var import_zod2 = require("zod");
|
|
2545
|
-
var isolatedAssetZod = import_zod2.z.object({
|
|
2546
|
-
dataType: import_zod2.z.string(),
|
|
2547
|
-
type: import_zod2.z.string(),
|
|
2548
|
-
hasPublicTransfer: import_zod2.z.boolean(),
|
|
2549
|
-
fields: import_zod2.z.object({
|
|
2550
|
-
id: import_zod2.z.object({
|
|
2551
|
-
id: import_zod2.z.string()
|
|
2552
|
-
}),
|
|
2553
|
-
name: import_zod2.z.object({
|
|
2554
|
-
type: import_zod2.z.string()
|
|
2555
|
-
}),
|
|
2556
|
-
value: import_zod2.z.boolean()
|
|
2557
|
-
})
|
|
2558
|
-
});
|
|
2559
|
-
var getIsolatedAssets = async (address) => {
|
|
2560
|
-
try {
|
|
2561
|
-
const marketObject = address.get("core.market");
|
|
2562
|
-
const protocolObject = address.get("core.packages.protocol.id");
|
|
2563
|
-
const ISOLATED_ASSET_KEY = `${protocolObject}::market_dynamic_keys::IsolatedAssetKey`;
|
|
2564
|
-
const isolatedAssets = [];
|
|
2565
|
-
if (!marketObject)
|
|
2566
|
-
return isolatedAssets;
|
|
2567
|
-
let hasNextPage = false;
|
|
2568
|
-
let nextCursor = null;
|
|
2569
|
-
const isIsolatedDynamicField = (dynamicField) => {
|
|
2570
|
-
return dynamicField.name.type === ISOLATED_ASSET_KEY;
|
|
2571
|
-
};
|
|
2572
|
-
do {
|
|
2573
|
-
const response = await address.cache.queryGetDynamicFields({
|
|
2574
|
-
parentId: marketObject,
|
|
2575
|
-
cursor: nextCursor,
|
|
2576
|
-
limit: 10
|
|
2577
|
-
});
|
|
2578
|
-
if (!response)
|
|
2579
|
-
break;
|
|
2580
|
-
const isolatedAssetCoinTypes = response.data.filter(isIsolatedDynamicField).map(({ name }) => `0x${name.value.type.name}`);
|
|
2581
|
-
isolatedAssets.push(...isolatedAssetCoinTypes);
|
|
2582
|
-
if (response && response.hasNextPage && response.nextCursor) {
|
|
2583
|
-
hasNextPage = true;
|
|
2584
|
-
nextCursor = response.nextCursor;
|
|
2585
|
-
} else {
|
|
2586
|
-
hasNextPage = false;
|
|
2587
|
-
}
|
|
2588
|
-
} while (hasNextPage);
|
|
2589
|
-
return isolatedAssets;
|
|
2590
|
-
} catch (e) {
|
|
2591
|
-
console.error(e);
|
|
2592
|
-
return [];
|
|
2593
|
-
}
|
|
2594
|
-
};
|
|
2595
|
-
var isIsolatedAsset = async (utils, coinName) => {
|
|
2596
|
-
try {
|
|
2597
|
-
const marketObject = utils.address.get("core.market");
|
|
2598
|
-
const protocolObject = utils.address.get("core.packages.protocol.id");
|
|
2599
|
-
const ISOLATED_ASSET_KEY = `${protocolObject}::market_dynamic_keys::IsolatedAssetKey`;
|
|
2600
|
-
const cachedData = utils.address.cache.queryClient.getQueryData([
|
|
2601
|
-
"getDynamicFields",
|
|
2602
|
-
marketObject
|
|
2603
|
-
]);
|
|
2604
|
-
if (cachedData) {
|
|
2605
|
-
const coinType2 = utils.parseCoinType(coinName);
|
|
2606
|
-
return cachedData.includes(coinType2);
|
|
2607
|
-
}
|
|
2608
|
-
const coinType = utils.parseCoinType(coinName).slice(2);
|
|
2609
|
-
const object = await utils.cache.queryGetDynamicFieldObject({
|
|
2610
|
-
parentId: marketObject,
|
|
2611
|
-
name: {
|
|
2612
|
-
type: ISOLATED_ASSET_KEY,
|
|
2613
|
-
value: coinType
|
|
2614
|
-
}
|
|
2615
|
-
});
|
|
2616
|
-
const parsedData = isolatedAssetZod.safeParse(object?.data?.content);
|
|
2617
|
-
if (!parsedData.success)
|
|
2618
|
-
return false;
|
|
2619
|
-
return parsedData.data.fields.value;
|
|
2620
|
-
} catch (e) {
|
|
2621
|
-
console.error(e);
|
|
2622
|
-
return false;
|
|
2623
|
-
}
|
|
2624
|
-
};
|
|
2625
|
-
|
|
2626
2499
|
// src/queries/coreQuery.ts
|
|
2627
|
-
var queryMarket = async (query, indexer = false) => {
|
|
2628
|
-
|
|
2500
|
+
var queryMarket = async (query, indexer = false, coinPrices) => {
|
|
2501
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
|
|
2629
2502
|
const pools = {};
|
|
2630
2503
|
const collaterals = {};
|
|
2631
2504
|
if (indexer) {
|
|
2632
2505
|
const marketIndexer = await query.indexer.getMarket();
|
|
2633
2506
|
const updatePools = (item) => {
|
|
2634
|
-
item.coinPrice = coinPrices[item.coinName]
|
|
2507
|
+
item.coinPrice = coinPrices[item.coinName] ?? item.coinPrice;
|
|
2635
2508
|
item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
|
|
2636
2509
|
pools[item.coinName] = item;
|
|
2637
2510
|
};
|
|
2638
2511
|
const updateCollaterals = (item) => {
|
|
2639
|
-
item.coinPrice = coinPrices[item.coinName]
|
|
2512
|
+
item.coinPrice = coinPrices[item.coinName] ?? item.coinPrice;
|
|
2640
2513
|
item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
|
|
2641
2514
|
collaterals[item.coinName] = item;
|
|
2642
2515
|
};
|
|
@@ -2707,8 +2580,8 @@ var queryMarket = async (query, indexer = false) => {
|
|
|
2707
2580
|
borrowFee: parsedMarketPoolData.borrowFee,
|
|
2708
2581
|
marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
|
|
2709
2582
|
minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
|
|
2710
|
-
isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
|
|
2711
|
-
|
|
2583
|
+
// isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
|
|
2584
|
+
isIsolated: false,
|
|
2712
2585
|
maxSupplyCoin,
|
|
2713
2586
|
...calculatedMarketPoolData
|
|
2714
2587
|
};
|
|
@@ -2747,7 +2620,6 @@ var queryMarket = async (query, indexer = false) => {
|
|
|
2747
2620
|
liquidationDiscount: parsedMarketCollateralData.liquidationDiscount,
|
|
2748
2621
|
liquidationPanelty: parsedMarketCollateralData.liquidationPanelty,
|
|
2749
2622
|
liquidationReserveFactor: parsedMarketCollateralData.liquidationReserveFactor,
|
|
2750
|
-
isIsolated: await isIsolatedAsset(query.utils, collateralCoinName),
|
|
2751
2623
|
...calculatedMarketCollateralData
|
|
2752
2624
|
};
|
|
2753
2625
|
}
|
|
@@ -2757,19 +2629,19 @@ var queryMarket = async (query, indexer = false) => {
|
|
|
2757
2629
|
// data: marketData,
|
|
2758
2630
|
};
|
|
2759
2631
|
};
|
|
2760
|
-
var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer = false) => {
|
|
2632
|
+
var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer = false, coinPrices) => {
|
|
2761
2633
|
const marketId = query.address.get("core.market");
|
|
2762
2634
|
const marketObjectResponse = await query.cache.queryGetObject(marketId, {
|
|
2763
2635
|
showContent: true
|
|
2764
2636
|
});
|
|
2765
|
-
|
|
2637
|
+
coinPrices = await query.utils.getCoinPrices(poolCoinNames) ?? {};
|
|
2766
2638
|
const marketPools = {};
|
|
2767
2639
|
if (indexer) {
|
|
2768
2640
|
const marketPoolsIndexer = await query.indexer.getMarketPools();
|
|
2769
2641
|
const updateMarketPool = (marketPool) => {
|
|
2770
2642
|
if (!poolCoinNames.includes(marketPool.coinName))
|
|
2771
2643
|
return;
|
|
2772
|
-
marketPool.coinPrice = coinPrices[marketPool.coinName]
|
|
2644
|
+
marketPool.coinPrice = coinPrices[marketPool.coinName] ?? marketPool.coinPrice;
|
|
2773
2645
|
marketPool.coinWrappedType = query.utils.getCoinWrappedType(
|
|
2774
2646
|
marketPool.coinName
|
|
2775
2647
|
);
|
|
@@ -2795,73 +2667,85 @@ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer =
|
|
|
2795
2667
|
return marketPools;
|
|
2796
2668
|
};
|
|
2797
2669
|
var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, coinPrice) => {
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2670
|
+
let marketPool;
|
|
2671
|
+
let balanceSheet;
|
|
2672
|
+
let borrowIndex;
|
|
2673
|
+
let interestModel;
|
|
2674
|
+
let borrowFeeRate;
|
|
2675
|
+
coinPrice = coinPrice ?? (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
2676
|
+
if (indexer) {
|
|
2677
|
+
const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
|
|
2678
|
+
marketPoolIndexer.coinPrice = coinPrice ?? marketPoolIndexer.coinPrice;
|
|
2679
|
+
marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
2680
|
+
marketPoolIndexer.coinName
|
|
2681
|
+
);
|
|
2682
|
+
return marketPoolIndexer;
|
|
2683
|
+
}
|
|
2684
|
+
const marketId = query.address.get("core.market");
|
|
2685
|
+
marketObject = marketObject ?? (await query.cache.queryGetObject(marketId, {
|
|
2686
|
+
showContent: true
|
|
2687
|
+
}))?.data;
|
|
2688
|
+
if (marketObject) {
|
|
2689
|
+
if (marketObject.content && "fields" in marketObject.content) {
|
|
2690
|
+
const fields = marketObject.content.fields;
|
|
2691
|
+
const coinType = query.utils.parseCoinType(poolCoinName);
|
|
2692
|
+
const balanceSheetParentId = fields.vault.fields.balance_sheets.fields.table.fields.id.id;
|
|
2693
|
+
const balanceSheetDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
2694
|
+
parentId: balanceSheetParentId,
|
|
2695
|
+
name: {
|
|
2696
|
+
type: "0x1::type_name::TypeName",
|
|
2697
|
+
value: {
|
|
2698
|
+
name: coinType.substring(2)
|
|
2699
|
+
}
|
|
2823
2700
|
}
|
|
2701
|
+
});
|
|
2702
|
+
if (!balanceSheetDynamicFieldObjectResponse)
|
|
2703
|
+
throw new Error(
|
|
2704
|
+
`Failed to fetch balanceSheetDynamicFieldObjectResponse for ${poolCoinName}`
|
|
2705
|
+
);
|
|
2706
|
+
const balanceSheetDynamicFieldObject = balanceSheetDynamicFieldObjectResponse.data;
|
|
2707
|
+
if (balanceSheetDynamicFieldObject && balanceSheetDynamicFieldObject.content && "fields" in balanceSheetDynamicFieldObject.content) {
|
|
2708
|
+
const dynamicFields = balanceSheetDynamicFieldObject.content.fields;
|
|
2709
|
+
balanceSheet = dynamicFields.value.fields;
|
|
2824
2710
|
}
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
const borrowIndexDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
2834
|
-
parentId: borrowIndexParentId,
|
|
2835
|
-
name: {
|
|
2836
|
-
type: "0x1::type_name::TypeName",
|
|
2837
|
-
value: {
|
|
2838
|
-
name: coinType.substring(2)
|
|
2711
|
+
const borrowIndexParentId = fields.borrow_dynamics.fields.table.fields.id.id;
|
|
2712
|
+
const borrowIndexDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
2713
|
+
parentId: borrowIndexParentId,
|
|
2714
|
+
name: {
|
|
2715
|
+
type: "0x1::type_name::TypeName",
|
|
2716
|
+
value: {
|
|
2717
|
+
name: coinType.substring(2)
|
|
2718
|
+
}
|
|
2839
2719
|
}
|
|
2720
|
+
});
|
|
2721
|
+
if (!borrowIndexDynamicFieldObjectResponse)
|
|
2722
|
+
throw new Error(
|
|
2723
|
+
`Failed to fetch borrowIndexDynamicFieldObjectResponse for ${poolCoinName}`
|
|
2724
|
+
);
|
|
2725
|
+
const borrowIndexDynamicFieldObject = borrowIndexDynamicFieldObjectResponse.data;
|
|
2726
|
+
if (borrowIndexDynamicFieldObject && borrowIndexDynamicFieldObject.content && "fields" in borrowIndexDynamicFieldObject.content) {
|
|
2727
|
+
const dynamicFields = borrowIndexDynamicFieldObject.content.fields;
|
|
2728
|
+
borrowIndex = dynamicFields.value.fields;
|
|
2840
2729
|
}
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
const interestModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
2850
|
-
parentId: interestModelParentId,
|
|
2851
|
-
name: {
|
|
2852
|
-
type: "0x1::type_name::TypeName",
|
|
2853
|
-
value: {
|
|
2854
|
-
name: coinType.substring(2)
|
|
2730
|
+
const interestModelParentId = fields.interest_models.fields.table.fields.id.id;
|
|
2731
|
+
const interestModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
2732
|
+
parentId: interestModelParentId,
|
|
2733
|
+
name: {
|
|
2734
|
+
type: "0x1::type_name::TypeName",
|
|
2735
|
+
value: {
|
|
2736
|
+
name: coinType.substring(2)
|
|
2737
|
+
}
|
|
2855
2738
|
}
|
|
2739
|
+
});
|
|
2740
|
+
if (!interestModelDynamicFieldObjectResponse)
|
|
2741
|
+
throw new Error(
|
|
2742
|
+
`Failed to fetch interestModelDynamicFieldObjectResponse for ${poolCoinName}`
|
|
2743
|
+
);
|
|
2744
|
+
const interestModelDynamicFieldObject = interestModelDynamicFieldObjectResponse.data;
|
|
2745
|
+
if (interestModelDynamicFieldObject && interestModelDynamicFieldObject.content && "fields" in interestModelDynamicFieldObject.content) {
|
|
2746
|
+
const dynamicFields = interestModelDynamicFieldObject.content.fields;
|
|
2747
|
+
interestModel = dynamicFields.value.fields;
|
|
2856
2748
|
}
|
|
2857
|
-
});
|
|
2858
|
-
const interestModelDynamicFieldObject = interestModelDynamicFieldObjectResponse?.data;
|
|
2859
|
-
if (!(interestModelDynamicFieldObject && interestModelDynamicFieldObject.content && "fields" in interestModelDynamicFieldObject.content))
|
|
2860
|
-
throw new Error(
|
|
2861
|
-
`Failed to fetch interestModelDynamicFieldObject for ${poolCoinName}: ${interestModelDynamicFieldObject}`
|
|
2862
|
-
);
|
|
2863
|
-
const interestModel = interestModelDynamicFieldObject.content.fields.value.fields;
|
|
2864
|
-
const getBorrowFee = async () => {
|
|
2865
2749
|
const borrowFeeDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
2866
2750
|
parentId: marketId,
|
|
2867
2751
|
name: {
|
|
@@ -2873,11 +2757,18 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2873
2757
|
}
|
|
2874
2758
|
}
|
|
2875
2759
|
});
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2760
|
+
if (!borrowFeeDynamicFieldObjectResponse)
|
|
2761
|
+
throw new Error(
|
|
2762
|
+
`Failed to fetch borrowFeeDynamicFieldObjectResponse for ${poolCoinName}`
|
|
2763
|
+
);
|
|
2764
|
+
const borrowFeeDynamicFieldObject = borrowFeeDynamicFieldObjectResponse.data;
|
|
2765
|
+
if (borrowFeeDynamicFieldObject && borrowFeeDynamicFieldObject.content && "fields" in borrowFeeDynamicFieldObject.content) {
|
|
2766
|
+
const dynamicFields = borrowFeeDynamicFieldObject.content.fields;
|
|
2767
|
+
borrowFeeRate = dynamicFields.value.fields;
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
if (balanceSheet && borrowIndex && interestModel && (USE_TEST_ADDRESS || borrowFeeRate)) {
|
|
2881
2772
|
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
2882
2773
|
type: interestModel.type.fields,
|
|
2883
2774
|
maxBorrowRate: interestModel.max_borrow_rate.fields,
|
|
@@ -2891,7 +2782,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2891
2782
|
reserve: balanceSheet.revenue,
|
|
2892
2783
|
reserveFactor: interestModel.revenue_factor.fields,
|
|
2893
2784
|
borrowWeight: interestModel.borrow_weight.fields,
|
|
2894
|
-
borrowFeeRate:
|
|
2785
|
+
borrowFeeRate: borrowFeeRate ?? { value: "0" },
|
|
2895
2786
|
baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
|
|
2896
2787
|
borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
|
|
2897
2788
|
borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
|
|
@@ -2907,7 +2798,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2907
2798
|
const maxSupplyCoin = (0, import_bignumber2.default)(
|
|
2908
2799
|
await getSupplyLimit(query.utils, poolCoinName) ?? "0"
|
|
2909
2800
|
).shiftedBy(-coinDecimal).toNumber();
|
|
2910
|
-
|
|
2801
|
+
marketPool = {
|
|
2911
2802
|
coinName: poolCoinName,
|
|
2912
2803
|
symbol: query.utils.parseSymbol(poolCoinName),
|
|
2913
2804
|
coinType: query.utils.parseCoinType(poolCoinName),
|
|
@@ -2926,13 +2817,12 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2926
2817
|
marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
|
|
2927
2818
|
minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
|
|
2928
2819
|
maxSupplyCoin,
|
|
2929
|
-
isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
|
|
2930
|
-
|
|
2820
|
+
// isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
|
|
2821
|
+
isIsolated: false,
|
|
2931
2822
|
...calculatedMarketPoolData
|
|
2932
2823
|
};
|
|
2933
|
-
} catch (e) {
|
|
2934
|
-
console.error(e);
|
|
2935
2824
|
}
|
|
2825
|
+
return marketPool;
|
|
2936
2826
|
};
|
|
2937
2827
|
var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLATERALS], indexer = false) => {
|
|
2938
2828
|
const marketId = query.address.get("core.market");
|
|
@@ -2943,7 +2833,7 @@ var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLA
|
|
|
2943
2833
|
const updateMarketCollateral = (marketCollateral) => {
|
|
2944
2834
|
if (!collateralCoinNames.includes(marketCollateral.coinName))
|
|
2945
2835
|
return;
|
|
2946
|
-
marketCollateral.coinPrice = coinPrices[marketCollateral.coinName]
|
|
2836
|
+
marketCollateral.coinPrice = coinPrices[marketCollateral.coinName] ?? marketCollateral.coinPrice;
|
|
2947
2837
|
marketCollateral.coinWrappedType = query.utils.getCoinWrappedType(
|
|
2948
2838
|
marketCollateral.coinName
|
|
2949
2839
|
);
|
|
@@ -2975,88 +2865,97 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
|
|
|
2975
2865
|
coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
|
|
2976
2866
|
if (indexer) {
|
|
2977
2867
|
const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
|
|
2978
|
-
marketCollateralIndexer.coinPrice = coinPrice
|
|
2868
|
+
marketCollateralIndexer.coinPrice = coinPrice ?? marketCollateralIndexer.coinPrice;
|
|
2979
2869
|
marketCollateralIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
2980
2870
|
marketCollateralIndexer.coinName
|
|
2981
2871
|
);
|
|
2982
2872
|
return marketCollateralIndexer;
|
|
2983
2873
|
}
|
|
2874
|
+
let marketCollateral;
|
|
2875
|
+
let riskModel;
|
|
2876
|
+
let collateralStat;
|
|
2984
2877
|
const marketId = query.address.get("core.market");
|
|
2985
2878
|
marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
|
|
2986
2879
|
showContent: true
|
|
2987
2880
|
}))?.data;
|
|
2988
|
-
if (
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2881
|
+
if (marketObject) {
|
|
2882
|
+
if (marketObject.content && "fields" in marketObject.content) {
|
|
2883
|
+
const fields = marketObject.content.fields;
|
|
2884
|
+
const coinType = query.utils.parseCoinType(collateralCoinName);
|
|
2885
|
+
const riskModelParentId = fields.risk_models.fields.table.fields.id.id;
|
|
2886
|
+
const riskModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
2887
|
+
parentId: riskModelParentId,
|
|
2888
|
+
name: {
|
|
2889
|
+
type: "0x1::type_name::TypeName",
|
|
2890
|
+
value: {
|
|
2891
|
+
name: coinType.substring(2)
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
});
|
|
2895
|
+
if (!riskModelDynamicFieldObjectResponse)
|
|
2896
|
+
return void 0;
|
|
2897
|
+
const riskModelDynamicFieldObject = riskModelDynamicFieldObjectResponse.data;
|
|
2898
|
+
if (riskModelDynamicFieldObject && riskModelDynamicFieldObject.content && "fields" in riskModelDynamicFieldObject.content) {
|
|
2899
|
+
const dynamicFields = riskModelDynamicFieldObject.content.fields;
|
|
2900
|
+
riskModel = dynamicFields.value.fields;
|
|
2999
2901
|
}
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
2902
|
+
const collateralStatParentId = fields.collateral_stats.fields.table.fields.id.id;
|
|
2903
|
+
const collateralStatDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
2904
|
+
parentId: collateralStatParentId,
|
|
2905
|
+
name: {
|
|
2906
|
+
type: "0x1::type_name::TypeName",
|
|
2907
|
+
value: {
|
|
2908
|
+
name: coinType.substring(2)
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
});
|
|
2912
|
+
if (!collateralStatDynamicFieldObjectResponse)
|
|
2913
|
+
return void 0;
|
|
2914
|
+
const collateralStatDynamicFieldObject = collateralStatDynamicFieldObjectResponse.data;
|
|
2915
|
+
if (collateralStatDynamicFieldObject && collateralStatDynamicFieldObject.content && "fields" in collateralStatDynamicFieldObject.content) {
|
|
2916
|
+
const dynamicFields = collateralStatDynamicFieldObject.content.fields;
|
|
2917
|
+
collateralStat = dynamicFields.value.fields;
|
|
3015
2918
|
}
|
|
3016
2919
|
}
|
|
3017
|
-
}
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
2920
|
+
}
|
|
2921
|
+
if (riskModel && collateralStat) {
|
|
2922
|
+
const parsedMarketCollateralData = parseOriginMarketCollateralData({
|
|
2923
|
+
type: riskModel.type.fields,
|
|
2924
|
+
collateralFactor: riskModel.collateral_factor.fields,
|
|
2925
|
+
liquidationFactor: riskModel.liquidation_factor.fields,
|
|
2926
|
+
liquidationDiscount: riskModel.liquidation_discount.fields,
|
|
2927
|
+
liquidationPanelty: riskModel.liquidation_penalty.fields,
|
|
2928
|
+
liquidationReserveFactor: riskModel.liquidation_revenue_factor.fields,
|
|
2929
|
+
maxCollateralAmount: riskModel.max_collateral_amount,
|
|
2930
|
+
totalCollateralAmount: collateralStat.amount
|
|
2931
|
+
});
|
|
2932
|
+
const calculatedMarketCollateralData = calculateMarketCollateralData(
|
|
2933
|
+
query.utils,
|
|
2934
|
+
parsedMarketCollateralData
|
|
3022
2935
|
);
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
symbol: query.utils.parseSymbol(collateralCoinName),
|
|
3041
|
-
coinType: query.utils.parseCoinType(collateralCoinName),
|
|
3042
|
-
marketCoinType: query.utils.parseMarketCoinType(collateralCoinName),
|
|
3043
|
-
coinWrappedType: query.utils.getCoinWrappedType(collateralCoinName),
|
|
3044
|
-
coinDecimal: query.utils.getCoinDecimal(collateralCoinName),
|
|
3045
|
-
coinPrice: coinPrice ?? 0,
|
|
3046
|
-
collateralFactor: parsedMarketCollateralData.collateralFactor,
|
|
3047
|
-
liquidationFactor: parsedMarketCollateralData.liquidationFactor,
|
|
3048
|
-
liquidationDiscount: parsedMarketCollateralData.liquidationDiscount,
|
|
3049
|
-
liquidationPanelty: parsedMarketCollateralData.liquidationPanelty,
|
|
3050
|
-
liquidationReserveFactor: parsedMarketCollateralData.liquidationReserveFactor,
|
|
3051
|
-
isIsolated: await isIsolatedAsset(query.utils, collateralCoinName),
|
|
3052
|
-
...calculatedMarketCollateralData
|
|
3053
|
-
};
|
|
2936
|
+
marketCollateral = {
|
|
2937
|
+
coinName: collateralCoinName,
|
|
2938
|
+
symbol: query.utils.parseSymbol(collateralCoinName),
|
|
2939
|
+
coinType: query.utils.parseCoinType(collateralCoinName),
|
|
2940
|
+
marketCoinType: query.utils.parseMarketCoinType(collateralCoinName),
|
|
2941
|
+
coinWrappedType: query.utils.getCoinWrappedType(collateralCoinName),
|
|
2942
|
+
coinDecimal: query.utils.getCoinDecimal(collateralCoinName),
|
|
2943
|
+
coinPrice: coinPrice ?? 0,
|
|
2944
|
+
collateralFactor: parsedMarketCollateralData.collateralFactor,
|
|
2945
|
+
liquidationFactor: parsedMarketCollateralData.liquidationFactor,
|
|
2946
|
+
liquidationDiscount: parsedMarketCollateralData.liquidationDiscount,
|
|
2947
|
+
liquidationPanelty: parsedMarketCollateralData.liquidationPanelty,
|
|
2948
|
+
liquidationReserveFactor: parsedMarketCollateralData.liquidationReserveFactor,
|
|
2949
|
+
...calculatedMarketCollateralData
|
|
2950
|
+
};
|
|
2951
|
+
}
|
|
2952
|
+
return marketCollateral;
|
|
3054
2953
|
};
|
|
3055
2954
|
var getObligations = async ({
|
|
3056
2955
|
address
|
|
3057
2956
|
}, ownerAddress) => {
|
|
3058
2957
|
const owner = ownerAddress;
|
|
3059
|
-
const protocolObjectId = address.get("core.object")
|
|
2958
|
+
const protocolObjectId = address.get("core.object") ?? PROTOCOL_OBJECT_ID;
|
|
3060
2959
|
const keyObjectsResponse = [];
|
|
3061
2960
|
let hasNextPage = false;
|
|
3062
2961
|
let nextCursor = null;
|
|
@@ -3123,7 +3022,7 @@ var queryObligation = async ({
|
|
|
3123
3022
|
return queryResult?.events[0]?.parsedJson;
|
|
3124
3023
|
};
|
|
3125
3024
|
var getCoinAmounts = async (query, assetCoinNames = [...SUPPORT_POOLS], ownerAddress) => {
|
|
3126
|
-
const owner = ownerAddress
|
|
3025
|
+
const owner = ownerAddress ?? query.suiKit.currentAddress();
|
|
3127
3026
|
const assetCoins2 = {};
|
|
3128
3027
|
await Promise.allSettled(
|
|
3129
3028
|
assetCoinNames.map(async (assetCoinName) => {
|
|
@@ -3134,7 +3033,7 @@ var getCoinAmounts = async (query, assetCoinNames = [...SUPPORT_POOLS], ownerAdd
|
|
|
3134
3033
|
return assetCoins2;
|
|
3135
3034
|
};
|
|
3136
3035
|
var getCoinAmount = async (query, assetCoinName, ownerAddress) => {
|
|
3137
|
-
const owner = ownerAddress
|
|
3036
|
+
const owner = ownerAddress ?? query.suiKit.currentAddress();
|
|
3138
3037
|
const coinType = query.utils.parseCoinType(assetCoinName);
|
|
3139
3038
|
const amount = await query.cache.queryGetCoinBalance({
|
|
3140
3039
|
owner,
|
|
@@ -3146,7 +3045,7 @@ var getMarketCoinAmounts = async (query, marketCoinNames, ownerAddress) => {
|
|
|
3146
3045
|
marketCoinNames = marketCoinNames || [...SUPPORT_POOLS].map(
|
|
3147
3046
|
(poolCoinName) => query.utils.parseMarketCoinName(poolCoinName)
|
|
3148
3047
|
);
|
|
3149
|
-
const owner = ownerAddress
|
|
3048
|
+
const owner = ownerAddress ?? query.suiKit.currentAddress();
|
|
3150
3049
|
const marketCoins2 = {};
|
|
3151
3050
|
await Promise.allSettled(
|
|
3152
3051
|
marketCoinNames.map(async (marketCoinName) => {
|
|
@@ -3161,7 +3060,7 @@ var getMarketCoinAmounts = async (query, marketCoinNames, ownerAddress) => {
|
|
|
3161
3060
|
return marketCoins2;
|
|
3162
3061
|
};
|
|
3163
3062
|
var getMarketCoinAmount = async (query, marketCoinName, ownerAddress) => {
|
|
3164
|
-
const owner = ownerAddress
|
|
3063
|
+
const owner = ownerAddress ?? query.suiKit.currentAddress();
|
|
3165
3064
|
const marketCoinType = query.utils.parseMarketCoinType(marketCoinName);
|
|
3166
3065
|
const amount = await query.cache.queryGetCoinBalance({
|
|
3167
3066
|
owner,
|
|
@@ -3230,18 +3129,14 @@ var getFlashLoanFees = async (query, assetNames) => {
|
|
|
3230
3129
|
|
|
3231
3130
|
// src/queries/spoolQuery.ts
|
|
3232
3131
|
var import_utils5 = require("@mysten/sui/utils");
|
|
3233
|
-
var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexer = false) => {
|
|
3132
|
+
var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexer = false, marketPools, coinPrices) => {
|
|
3234
3133
|
const stakeCoinNames = stakeMarketCoinNames.map(
|
|
3235
3134
|
(stakeMarketCoinName) => query.utils.parseCoinName(stakeMarketCoinName)
|
|
3236
3135
|
);
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
const coinPrices = await query.utils.getCoinPrices([
|
|
3242
|
-
.../* @__PURE__ */ new Set([...stakeCoinNames, ...rewardCoinNames])
|
|
3243
|
-
]) ?? {};
|
|
3244
|
-
const marketPools = await query.getMarketPools(stakeCoinNames, indexer);
|
|
3136
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
|
|
3137
|
+
marketPools = marketPools ?? await query.getMarketPools(stakeCoinNames, indexer);
|
|
3138
|
+
if (!marketPools)
|
|
3139
|
+
throw new Error(`Fail to fetch marketPools for ${stakeCoinNames}`);
|
|
3245
3140
|
const spools = {};
|
|
3246
3141
|
if (indexer) {
|
|
3247
3142
|
const spoolsIndexer = await query.indexer.getSpools();
|
|
@@ -3255,9 +3150,9 @@ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexe
|
|
|
3255
3150
|
spool.marketCoinName
|
|
3256
3151
|
);
|
|
3257
3152
|
const marketPool = marketPools[coinName];
|
|
3258
|
-
spool.coinPrice = coinPrices[coinName]
|
|
3259
|
-
spool.marketCoinPrice = (coinPrices[coinName] ?? 0) * (marketPool ? marketPool.conversionRate : 0)
|
|
3260
|
-
spool.rewardCoinPrice = coinPrices[rewardCoinName]
|
|
3153
|
+
spool.coinPrice = coinPrices[coinName] ?? spool.coinPrice;
|
|
3154
|
+
spool.marketCoinPrice = coinPrices[coinName] ? (coinPrices[coinName] ?? 0) * (marketPool ? marketPool.conversionRate : 0) : spool.marketCoinPrice;
|
|
3155
|
+
spool.rewardCoinPrice = coinPrices[rewardCoinName] ?? spool.rewardCoinPrice;
|
|
3261
3156
|
spools[spool.marketCoinName] = spool;
|
|
3262
3157
|
};
|
|
3263
3158
|
Object.values(spoolsIndexer).forEach(updateSpools);
|
|
@@ -3282,7 +3177,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
|
|
|
3282
3177
|
const coinName = query.utils.parseCoinName(marketCoinName);
|
|
3283
3178
|
marketPool = marketPool || await query.getMarketPool(coinName, indexer);
|
|
3284
3179
|
if (!marketPool) {
|
|
3285
|
-
throw new Error(`
|
|
3180
|
+
throw new Error(`Fail to fetch marketPool for ${coinName}`);
|
|
3286
3181
|
}
|
|
3287
3182
|
const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
|
|
3288
3183
|
const rewardPoolId = query.address.get(
|
|
@@ -3569,20 +3464,15 @@ var queryBorrowIncentivePools = async (address) => {
|
|
|
3569
3464
|
};
|
|
3570
3465
|
var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
|
|
3571
3466
|
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
3572
|
-
], indexer = false) => {
|
|
3467
|
+
], indexer = false, coinPrices) => {
|
|
3573
3468
|
const borrowIncentivePools = {};
|
|
3574
|
-
|
|
3575
|
-
.../* @__PURE__ */ new Set([
|
|
3576
|
-
...borrowIncentiveCoinNames,
|
|
3577
|
-
...SUPPORT_BORROW_INCENTIVE_REWARDS
|
|
3578
|
-
])
|
|
3579
|
-
]) ?? {};
|
|
3469
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
|
|
3580
3470
|
if (indexer) {
|
|
3581
3471
|
const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
|
|
3582
3472
|
const updateBorrowIncentivePool = (pool) => {
|
|
3583
3473
|
if (!borrowIncentiveCoinNames.includes(pool.coinName))
|
|
3584
3474
|
return;
|
|
3585
|
-
pool.coinPrice = coinPrices[pool.coinName]
|
|
3475
|
+
pool.coinPrice = coinPrices[pool.coinName] ?? pool.coinPrice;
|
|
3586
3476
|
borrowIncentivePools[pool.coinName] = pool;
|
|
3587
3477
|
};
|
|
3588
3478
|
Object.values(borrowIncentivePoolsIndexer).forEach(
|
|
@@ -3829,20 +3719,18 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
|
|
|
3829
3719
|
const stakeMarketCoinNames = marketCoinNames.filter(
|
|
3830
3720
|
(marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
|
|
3831
3721
|
);
|
|
3832
|
-
const
|
|
3722
|
+
const coinPrices = await query.utils.getCoinPrices(poolCoinNames);
|
|
3723
|
+
const marketPools = await query.getMarketPools(poolCoinNames, indexer, {
|
|
3724
|
+
coinPrices
|
|
3725
|
+
});
|
|
3726
|
+
const spools = await query.getSpools(stakeMarketCoinNames, indexer, {
|
|
3833
3727
|
marketPools,
|
|
3834
|
-
spools,
|
|
3835
|
-
coinAmounts,
|
|
3836
|
-
marketCoinAmounts,
|
|
3837
|
-
allStakeAccounts,
|
|
3838
3728
|
coinPrices
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
query.getSpools(stakeMarketCoinNames, indexer),
|
|
3729
|
+
});
|
|
3730
|
+
const [coinAmounts, marketCoinAmounts, allStakeAccounts] = await Promise.all([
|
|
3842
3731
|
query.getCoinAmounts(poolCoinNames, ownerAddress),
|
|
3843
3732
|
query.getMarketCoinAmounts(marketCoinNames, ownerAddress),
|
|
3844
|
-
query.getAllStakeAccounts(ownerAddress)
|
|
3845
|
-
query.utils.getCoinPrices(poolCoinNames)
|
|
3733
|
+
query.getAllStakeAccounts(ownerAddress)
|
|
3846
3734
|
]);
|
|
3847
3735
|
const lendings = {};
|
|
3848
3736
|
await Promise.allSettled(
|
|
@@ -3858,7 +3746,7 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
|
|
|
3858
3746
|
indexer,
|
|
3859
3747
|
marketPools?.[poolCoinName],
|
|
3860
3748
|
stakeMarketCoinName ? spools[stakeMarketCoinName] : void 0,
|
|
3861
|
-
stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] :
|
|
3749
|
+
stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : [],
|
|
3862
3750
|
coinAmounts?.[poolCoinName],
|
|
3863
3751
|
marketCoinAmounts?.[marketCoinName],
|
|
3864
3752
|
coinPrices?.[poolCoinName] ?? 0
|
|
@@ -3869,8 +3757,22 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
|
|
|
3869
3757
|
};
|
|
3870
3758
|
var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice, sCoinAmount) => {
|
|
3871
3759
|
const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
|
|
3872
|
-
|
|
3873
|
-
|
|
3760
|
+
coinPrice = coinPrice ?? (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
|
|
3761
|
+
marketPool = marketPool ?? await query.getMarketPool(poolCoinName, indexer, {
|
|
3762
|
+
coinPrice
|
|
3763
|
+
});
|
|
3764
|
+
if (!marketPool)
|
|
3765
|
+
throw new Error(`Failed to fetch marketPool for ${poolCoinName}`);
|
|
3766
|
+
spool = spool ?? SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(
|
|
3767
|
+
marketCoinName,
|
|
3768
|
+
indexer,
|
|
3769
|
+
{
|
|
3770
|
+
marketPool,
|
|
3771
|
+
coinPrices: {
|
|
3772
|
+
[poolCoinName]: coinPrice
|
|
3773
|
+
}
|
|
3774
|
+
}
|
|
3775
|
+
) : void 0;
|
|
3874
3776
|
stakeAccounts = stakeAccounts || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getStakeAccounts(
|
|
3875
3777
|
marketCoinName,
|
|
3876
3778
|
ownerAddress
|
|
@@ -3878,7 +3780,6 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
3878
3780
|
coinAmount = coinAmount || await query.getCoinAmount(poolCoinName, ownerAddress);
|
|
3879
3781
|
marketCoinAmount = marketCoinAmount || await query.getMarketCoinAmount(marketCoinName, ownerAddress);
|
|
3880
3782
|
sCoinAmount = sCoinAmount || await query.getSCoinAmount(marketCoinName, ownerAddress);
|
|
3881
|
-
coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
3882
3783
|
const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
3883
3784
|
let stakedMarketAmount = (0, import_bignumber4.default)(0);
|
|
3884
3785
|
let stakedMarketCoin = (0, import_bignumber4.default)(0);
|
|
@@ -3990,10 +3891,12 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
3990
3891
|
return lending;
|
|
3991
3892
|
};
|
|
3992
3893
|
var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
|
|
3993
|
-
const market = await query.queryMarket(indexer);
|
|
3994
3894
|
const coinPrices = await query.utils.getCoinPrices();
|
|
3995
|
-
const
|
|
3996
|
-
const obligations = await
|
|
3895
|
+
const market = await query.queryMarket(indexer, { coinPrices });
|
|
3896
|
+
const [coinAmounts, obligations] = await Promise.all([
|
|
3897
|
+
query.getCoinAmounts(void 0, ownerAddress),
|
|
3898
|
+
query.getObligations(ownerAddress)
|
|
3899
|
+
]);
|
|
3997
3900
|
const obligationAccounts = {};
|
|
3998
3901
|
await Promise.allSettled(
|
|
3999
3902
|
obligations.map(async (obligation) => {
|
|
@@ -4011,19 +3914,19 @@ var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
|
|
|
4011
3914
|
return obligationAccounts;
|
|
4012
3915
|
};
|
|
4013
3916
|
var getObligationAccount = async (query, obligationId, ownerAddress, indexer = false, market, coinPrices, coinAmounts) => {
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
.../* @__PURE__ */ new Set([...Object.values(market.pools).map((pool) => pool.coinName)])
|
|
3917
|
+
const collateralAssetCoinNames = [
|
|
3918
|
+
...SUPPORT_COLLATERALS
|
|
4017
3919
|
];
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
3920
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices(collateralAssetCoinNames);
|
|
3921
|
+
market = market ?? await query.queryMarket(indexer, { coinPrices });
|
|
3922
|
+
coinAmounts = coinAmounts || await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress);
|
|
3923
|
+
const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] = await Promise.all([
|
|
3924
|
+
query.queryObligation(obligationId),
|
|
3925
|
+
query.getBorrowIncentivePools(void 0, indexer, {
|
|
3926
|
+
coinPrices
|
|
3927
|
+
}),
|
|
3928
|
+
query.getBorrowIncentiveAccounts(obligationId)
|
|
3929
|
+
]);
|
|
4027
3930
|
const collaterals = {};
|
|
4028
3931
|
const debts = {};
|
|
4029
3932
|
const borrowIncentives = {};
|
|
@@ -4035,7 +3938,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
4035
3938
|
let totalRewardedPools = 0;
|
|
4036
3939
|
let totalBorrowedValue = (0, import_bignumber4.default)(0);
|
|
4037
3940
|
let totalBorrowedValueWithWeight = (0, import_bignumber4.default)(0);
|
|
4038
|
-
for (const assetCoinName of
|
|
3941
|
+
for (const assetCoinName of collateralAssetCoinNames) {
|
|
4039
3942
|
const collateral = obligationQuery?.collaterals.find((collateral2) => {
|
|
4040
3943
|
const collateralCoinName = query.utils.parseCoinNameFromType(
|
|
4041
3944
|
collateral2.type.name
|
|
@@ -4340,7 +4243,7 @@ var getTotalValueLocked = async (query, indexer = false) => {
|
|
|
4340
4243
|
var import_bignumber5 = __toESM(require("bignumber.js"));
|
|
4341
4244
|
var import_sui_kit3 = require("@scallop-io/sui-kit");
|
|
4342
4245
|
var import_bcs = require("@mysten/sui/bcs");
|
|
4343
|
-
var
|
|
4246
|
+
var import_zod2 = require("zod");
|
|
4344
4247
|
var import_assert = __toESM(require("assert"));
|
|
4345
4248
|
var getVescaKeys = async (utils, ownerAddress) => {
|
|
4346
4249
|
const owner = ownerAddress || utils.suiKit.currentAddress();
|
|
@@ -4389,10 +4292,10 @@ var getVeScas = async ({
|
|
|
4389
4292
|
}
|
|
4390
4293
|
return result;
|
|
4391
4294
|
};
|
|
4392
|
-
var SuiObjectRefZod =
|
|
4393
|
-
objectId:
|
|
4394
|
-
digest:
|
|
4395
|
-
version:
|
|
4295
|
+
var SuiObjectRefZod = import_zod2.z.object({
|
|
4296
|
+
objectId: import_zod2.z.string(),
|
|
4297
|
+
digest: import_zod2.z.string(),
|
|
4298
|
+
version: import_zod2.z.string()
|
|
4396
4299
|
});
|
|
4397
4300
|
var getVeSca = async (utils, veScaKey) => {
|
|
4398
4301
|
const tableId = utils.address.get(`vesca.tableId`);
|
|
@@ -4525,16 +4428,16 @@ var queryVeScaKeyIdFromReferralBindings = async (address, refereeAddress) => {
|
|
|
4525
4428
|
|
|
4526
4429
|
// src/queries/loyaltyProgramQuery.ts
|
|
4527
4430
|
var import_bignumber6 = __toESM(require("bignumber.js"));
|
|
4528
|
-
var
|
|
4529
|
-
var rewardPoolFieldsZod =
|
|
4530
|
-
balance:
|
|
4531
|
-
enable_claim:
|
|
4431
|
+
var import_zod3 = require("zod");
|
|
4432
|
+
var rewardPoolFieldsZod = import_zod3.z.object({
|
|
4433
|
+
balance: import_zod3.z.string(),
|
|
4434
|
+
enable_claim: import_zod3.z.boolean()
|
|
4532
4435
|
}).transform((value) => ({
|
|
4533
4436
|
totalPoolReward: (0, import_bignumber6.default)(value.balance).shiftedBy(-9).toNumber(),
|
|
4534
4437
|
isClaimEnabled: value.enable_claim
|
|
4535
4438
|
}));
|
|
4536
|
-
var userRewardFieldsZod =
|
|
4537
|
-
value:
|
|
4439
|
+
var userRewardFieldsZod = import_zod3.z.object({
|
|
4440
|
+
value: import_zod3.z.string()
|
|
4538
4441
|
}).transform((value) => (0, import_bignumber6.default)(value.value).shiftedBy(-9).toNumber());
|
|
4539
4442
|
var getLoyaltyProgramInformations = async (query, veScaKey) => {
|
|
4540
4443
|
const rewardPool = query.address.get("loyaltyProgram.rewardPool");
|
|
@@ -4552,7 +4455,7 @@ var getLoyaltyProgramInformations = async (query, veScaKey) => {
|
|
|
4552
4455
|
totalPoolReward,
|
|
4553
4456
|
isClaimEnabled
|
|
4554
4457
|
};
|
|
4555
|
-
veScaKey = veScaKey
|
|
4458
|
+
veScaKey = veScaKey ?? (await query.getVeScas())[0]?.keyObject;
|
|
4556
4459
|
if (!veScaKey)
|
|
4557
4460
|
return result;
|
|
4558
4461
|
const userRewardTableId = query.address.get(
|
|
@@ -4574,10 +4477,39 @@ var getLoyaltyProgramInformations = async (query, veScaKey) => {
|
|
|
4574
4477
|
return result;
|
|
4575
4478
|
};
|
|
4576
4479
|
|
|
4480
|
+
// src/models/suiKit.ts
|
|
4481
|
+
var import_sui_kit4 = require("@scallop-io/sui-kit");
|
|
4482
|
+
|
|
4483
|
+
// src/constants/rpc.ts
|
|
4484
|
+
var import_client = require("@mysten/sui/client");
|
|
4485
|
+
var RPC_PROVIDERS = [
|
|
4486
|
+
(0, import_client.getFullnodeUrl)("mainnet"),
|
|
4487
|
+
"https://sui-mainnet.public.blastapi.io",
|
|
4488
|
+
"https://sui-mainnet-ca-2.cosmostation.io",
|
|
4489
|
+
"https://sui-mainnet-eu-4.cosmostation.io",
|
|
4490
|
+
"https://sui-mainnet-endpoint.blockvision.org",
|
|
4491
|
+
"https://sui-rpc.publicnode.com",
|
|
4492
|
+
"https://sui-mainnet-rpc.allthatnode.com",
|
|
4493
|
+
"https://mainnet.suiet.app",
|
|
4494
|
+
"https://mainnet.sui.rpcpool.com",
|
|
4495
|
+
"https://sui1mainnet-rpc.chainode.tech",
|
|
4496
|
+
"https://fullnode.mainnet.apis.scallop.io",
|
|
4497
|
+
"https://sui-mainnet-us-2.cosmostation.io"
|
|
4498
|
+
];
|
|
4499
|
+
|
|
4500
|
+
// src/models/suiKit.ts
|
|
4501
|
+
var newSuiKit = (params) => {
|
|
4502
|
+
return new import_sui_kit4.SuiKit({
|
|
4503
|
+
...params,
|
|
4504
|
+
fullnodeUrls: Array.from(
|
|
4505
|
+
/* @__PURE__ */ new Set([...params.fullnodeUrls ?? [], ...RPC_PROVIDERS])
|
|
4506
|
+
)
|
|
4507
|
+
});
|
|
4508
|
+
};
|
|
4509
|
+
|
|
4577
4510
|
// src/models/scallopUtils.ts
|
|
4578
4511
|
var ScallopUtils = class {
|
|
4579
4512
|
constructor(params, instance) {
|
|
4580
|
-
this._priceMap = /* @__PURE__ */ new Map();
|
|
4581
4513
|
/**
|
|
4582
4514
|
* Get reward type of spool.
|
|
4583
4515
|
*
|
|
@@ -4600,7 +4532,7 @@ var ScallopUtils = class {
|
|
|
4600
4532
|
pythEndpoints: params.pythEndpoints ?? PYTH_ENDPOINTS["mainnet"],
|
|
4601
4533
|
...params
|
|
4602
4534
|
};
|
|
4603
|
-
this.suiKit = instance?.suiKit ?? instance?.address?.cache._suiKit ??
|
|
4535
|
+
this.suiKit = instance?.suiKit ?? instance?.address?.cache._suiKit ?? newSuiKit(params);
|
|
4604
4536
|
this.walletAddress = params.walletAddress ?? this.suiKit.currentAddress();
|
|
4605
4537
|
if (instance?.address) {
|
|
4606
4538
|
this.address = instance.address;
|
|
@@ -4614,7 +4546,7 @@ var ScallopUtils = class {
|
|
|
4614
4546
|
);
|
|
4615
4547
|
this.address = instance?.address ?? new ScallopAddress(
|
|
4616
4548
|
{
|
|
4617
|
-
id: params?.addressesId
|
|
4549
|
+
id: params?.addressesId ?? ADDRESSES_ID,
|
|
4618
4550
|
network: params?.networkType,
|
|
4619
4551
|
forceInterface: params?.forceAddressesInterface
|
|
4620
4552
|
},
|
|
@@ -4639,10 +4571,10 @@ var ScallopUtils = class {
|
|
|
4639
4571
|
* @param address - ScallopAddress instance.
|
|
4640
4572
|
*/
|
|
4641
4573
|
async init(force = false, address) {
|
|
4642
|
-
if (
|
|
4643
|
-
this.address = address;
|
|
4644
|
-
if (force || !this.address.getAddresses()) {
|
|
4574
|
+
if (force || !this.address.getAddresses() || !address?.getAddresses()) {
|
|
4645
4575
|
await this.address.read();
|
|
4576
|
+
} else {
|
|
4577
|
+
this.address = address;
|
|
4646
4578
|
}
|
|
4647
4579
|
}
|
|
4648
4580
|
/**
|
|
@@ -4728,6 +4660,14 @@ var ScallopUtils = class {
|
|
|
4728
4660
|
parseSCoinType(sCoinName) {
|
|
4729
4661
|
return sCoinIds[sCoinName];
|
|
4730
4662
|
}
|
|
4663
|
+
/**
|
|
4664
|
+
* Convert sCoinType into sCoin name
|
|
4665
|
+
* @param sCoinType
|
|
4666
|
+
* @returns sCoin name
|
|
4667
|
+
*/
|
|
4668
|
+
parseSCoinNameFromType(sCoinType) {
|
|
4669
|
+
return sCoinTypeToName[sCoinType];
|
|
4670
|
+
}
|
|
4731
4671
|
/**
|
|
4732
4672
|
* Convert sCoin name into its underlying coin type
|
|
4733
4673
|
* @param sCoinName
|
|
@@ -4753,7 +4693,7 @@ var ScallopUtils = class {
|
|
|
4753
4693
|
* @return Market coin type.
|
|
4754
4694
|
*/
|
|
4755
4695
|
parseMarketCoinType(coinName) {
|
|
4756
|
-
const protocolObjectId = this.address.get("core.object")
|
|
4696
|
+
const protocolObjectId = this.address.get("core.object") ?? PROTOCOL_OBJECT_ID;
|
|
4757
4697
|
const coinType = this.parseCoinType(coinName);
|
|
4758
4698
|
return `${protocolObjectId}::reserve::MarketCoin<${coinType}>`;
|
|
4759
4699
|
}
|
|
@@ -4762,7 +4702,7 @@ var ScallopUtils = class {
|
|
|
4762
4702
|
const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
|
|
4763
4703
|
const coinTypeMatch = coinType.match(coinTypeRegex);
|
|
4764
4704
|
const isMarketCoinType = coinType.includes("reserve::MarketCoin");
|
|
4765
|
-
coinType = coinTypeMatch?.[1]
|
|
4705
|
+
coinType = coinTypeMatch?.[1] ?? coinType;
|
|
4766
4706
|
const wormHoleCoinTypeMap = {
|
|
4767
4707
|
[`${this.address.get("core.coins.wusdc.id") ?? wormholeCoinIds.wusdc}::coin::COIN`]: "wusdc",
|
|
4768
4708
|
[`${this.address.get("core.coins.wusdt.id") ?? wormholeCoinIds.wusdt}::coin::COIN`]: "wusdt",
|
|
@@ -4840,7 +4780,7 @@ var ScallopUtils = class {
|
|
|
4840
4780
|
* @return The selected transaction coin arguments.
|
|
4841
4781
|
*/
|
|
4842
4782
|
async selectCoins(amount, coinType = import_utils10.SUI_TYPE_ARG, ownerAddress) {
|
|
4843
|
-
ownerAddress = ownerAddress
|
|
4783
|
+
ownerAddress = ownerAddress ?? this.suiKit.currentAddress();
|
|
4844
4784
|
const coins = await this.suiKit.suiInteractor.selectCoins(
|
|
4845
4785
|
ownerAddress,
|
|
4846
4786
|
amount,
|
|
@@ -4908,94 +4848,59 @@ var ScallopUtils = class {
|
|
|
4908
4848
|
* @param assetCoinNames - Specific an array of support asset coin name.
|
|
4909
4849
|
* @return Asset coin price.
|
|
4910
4850
|
*/
|
|
4911
|
-
async getCoinPrices(
|
|
4851
|
+
async getCoinPrices(_ = [
|
|
4912
4852
|
.../* @__PURE__ */ new Set([...SUPPORT_POOLS, ...SUPPORT_COLLATERALS])
|
|
4913
4853
|
]) {
|
|
4914
|
-
|
|
4915
|
-
const
|
|
4916
|
-
const
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
)
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
for (const coinName of existPricesCoinNames) {
|
|
4931
|
-
coinPrices[coinName] = this._priceMap.get(coinName).price;
|
|
4932
|
-
}
|
|
4933
|
-
}
|
|
4934
|
-
if (lackPricesCoinNames.length > 0) {
|
|
4935
|
-
const endpoints = this.params.pythEndpoints ?? PYTH_ENDPOINTS[this.isTestnet ? "testnet" : "mainnet"];
|
|
4936
|
-
const failedRequests = new Set(
|
|
4937
|
-
lackPricesCoinNames
|
|
4854
|
+
let coinPrices = {};
|
|
4855
|
+
const endpoints = this.params.pythEndpoints ?? PYTH_ENDPOINTS[this.isTestnet ? "testnet" : "mainnet"];
|
|
4856
|
+
const failedRequests = /* @__PURE__ */ new Set([
|
|
4857
|
+
...SUPPORT_POOLS,
|
|
4858
|
+
...SUPPORT_COLLATERALS
|
|
4859
|
+
]);
|
|
4860
|
+
for (const endpoint of endpoints) {
|
|
4861
|
+
const priceIdPairs = Array.from(failedRequests.values()).reduce(
|
|
4862
|
+
(acc, coinName) => {
|
|
4863
|
+
const priceId = this.address.get(
|
|
4864
|
+
`core.coins.${coinName}.oracle.pyth.feed`
|
|
4865
|
+
);
|
|
4866
|
+
acc.push([coinName, priceId]);
|
|
4867
|
+
return acc;
|
|
4868
|
+
},
|
|
4869
|
+
[]
|
|
4938
4870
|
);
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
return acc;
|
|
4871
|
+
const priceIds = priceIdPairs.map(([_2, priceId]) => priceId);
|
|
4872
|
+
const pythConnection = new import_pyth_sui_js.SuiPriceServiceConnection(endpoint, {
|
|
4873
|
+
timeout: 2e3
|
|
4874
|
+
});
|
|
4875
|
+
try {
|
|
4876
|
+
const feeds = await this.cache.queryClient.fetchQuery({
|
|
4877
|
+
queryKey: queryKeys.oracle.getPythLatestPriceFeeds(),
|
|
4878
|
+
queryFn: async () => {
|
|
4879
|
+
return await pythConnection.getLatestPriceFeeds(priceIds);
|
|
4949
4880
|
},
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
}
|
|
4964
|
-
});
|
|
4965
|
-
if (feed[0]) {
|
|
4966
|
-
const data = parseDataFromPythPriceFeed(
|
|
4967
|
-
feed[0],
|
|
4968
|
-
this.address
|
|
4969
|
-
);
|
|
4970
|
-
this._priceMap.set(coinName, {
|
|
4971
|
-
price: data.price,
|
|
4972
|
-
publishTime: data.publishTime
|
|
4973
|
-
});
|
|
4974
|
-
coinPrices[coinName] = data.price;
|
|
4975
|
-
failedRequests.delete(coinName);
|
|
4976
|
-
}
|
|
4977
|
-
} catch (e) {
|
|
4978
|
-
console.warn(
|
|
4979
|
-
`Failed to get price ${coinName} feeds with endpoint ${endpoint}: ${e}`
|
|
4980
|
-
);
|
|
4981
|
-
}
|
|
4982
|
-
})
|
|
4983
|
-
);
|
|
4984
|
-
if (failedRequests.size === 0)
|
|
4985
|
-
break;
|
|
4986
|
-
}
|
|
4987
|
-
if (failedRequests.size > 0) {
|
|
4988
|
-
await Promise.allSettled(
|
|
4989
|
-
Array.from(failedRequests.values()).map(async (coinName) => {
|
|
4990
|
-
const price = await getPythPrice(this, coinName);
|
|
4991
|
-
this._priceMap.set(coinName, {
|
|
4992
|
-
price,
|
|
4993
|
-
publishTime: Date.now()
|
|
4994
|
-
});
|
|
4995
|
-
coinPrices[coinName] = price;
|
|
4996
|
-
})
|
|
4997
|
-
);
|
|
4881
|
+
staleTime: 3e4,
|
|
4882
|
+
gcTime: 3e4
|
|
4883
|
+
});
|
|
4884
|
+
if (feeds) {
|
|
4885
|
+
feeds.forEach((feed, idx) => {
|
|
4886
|
+
const coinName = priceIdPairs[idx][0];
|
|
4887
|
+
const data = parseDataFromPythPriceFeed(feed, this.address);
|
|
4888
|
+
coinPrices[coinName] = data.price;
|
|
4889
|
+
failedRequests.delete(coinName);
|
|
4890
|
+
});
|
|
4891
|
+
}
|
|
4892
|
+
} catch (e) {
|
|
4893
|
+
console.error(e.message);
|
|
4998
4894
|
}
|
|
4895
|
+
if (failedRequests.size === 0)
|
|
4896
|
+
break;
|
|
4897
|
+
}
|
|
4898
|
+
if (failedRequests.size > 0) {
|
|
4899
|
+
coinPrices = {
|
|
4900
|
+
...coinPrices,
|
|
4901
|
+
...await getPythPrices(this, Array.from(failedRequests.values()))
|
|
4902
|
+
};
|
|
4903
|
+
failedRequests.clear();
|
|
4999
4904
|
}
|
|
5000
4905
|
return coinPrices;
|
|
5001
4906
|
}
|
|
@@ -5075,7 +4980,6 @@ var ScallopUtils = class {
|
|
|
5075
4980
|
|
|
5076
4981
|
// src/models/scallopBuilder.ts
|
|
5077
4982
|
var import_utils24 = require("@mysten/sui/utils");
|
|
5078
|
-
var import_sui_kit14 = require("@scallop-io/sui-kit");
|
|
5079
4983
|
|
|
5080
4984
|
// src/builders/coreBuilder.ts
|
|
5081
4985
|
var import_transactions = require("@mysten/sui/transactions");
|
|
@@ -6509,7 +6413,7 @@ var generateLoyaltyProgramQuickMethod = ({
|
|
|
6509
6413
|
}) => {
|
|
6510
6414
|
return {
|
|
6511
6415
|
claimLoyaltyRevenueQuick: async (veScaKey) => {
|
|
6512
|
-
veScaKey = veScaKey
|
|
6416
|
+
veScaKey = veScaKey ?? (await builder.query.getVeScas())[0]?.keyObject;
|
|
6513
6417
|
const sender = requireSender(txBlock);
|
|
6514
6418
|
if (!veScaKey)
|
|
6515
6419
|
throw new Error(`No veScaKey found for user ${sender}`);
|
|
@@ -6673,9 +6577,6 @@ var newScallopTxBlock = (builder, initTxBlock) => {
|
|
|
6673
6577
|
});
|
|
6674
6578
|
};
|
|
6675
6579
|
|
|
6676
|
-
// src/models/scallopQuery.ts
|
|
6677
|
-
var import_sui_kit13 = require("@scallop-io/sui-kit");
|
|
6678
|
-
|
|
6679
6580
|
// src/models/scallopIndexer.ts
|
|
6680
6581
|
var import_axios2 = __toESM(require("axios"));
|
|
6681
6582
|
var import_sui_kit12 = require("@scallop-io/sui-kit");
|
|
@@ -6948,12 +6849,94 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
|
|
|
6948
6849
|
|
|
6949
6850
|
// src/models/scallopQuery.ts
|
|
6950
6851
|
var import_utils23 = require("@mysten/sui/utils");
|
|
6852
|
+
|
|
6853
|
+
// src/queries/isolatedAsset.ts
|
|
6854
|
+
var import_zod4 = require("zod");
|
|
6855
|
+
var isolatedAssetZod = import_zod4.z.object({
|
|
6856
|
+
dataType: import_zod4.z.string(),
|
|
6857
|
+
type: import_zod4.z.string(),
|
|
6858
|
+
hasPublicTransfer: import_zod4.z.boolean(),
|
|
6859
|
+
fields: import_zod4.z.object({
|
|
6860
|
+
id: import_zod4.z.object({
|
|
6861
|
+
id: import_zod4.z.string()
|
|
6862
|
+
}),
|
|
6863
|
+
name: import_zod4.z.object({
|
|
6864
|
+
type: import_zod4.z.string()
|
|
6865
|
+
}),
|
|
6866
|
+
value: import_zod4.z.boolean()
|
|
6867
|
+
})
|
|
6868
|
+
});
|
|
6869
|
+
var ISOLATED_ASSET_KEY = "0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::IsolatedAssetKey";
|
|
6870
|
+
var getIsolatedAssets = async (address) => {
|
|
6871
|
+
try {
|
|
6872
|
+
const marketObject = address.get("core.market");
|
|
6873
|
+
const isolatedAssets = [];
|
|
6874
|
+
if (!marketObject)
|
|
6875
|
+
return isolatedAssets;
|
|
6876
|
+
let hasNextPage = false;
|
|
6877
|
+
let nextCursor = null;
|
|
6878
|
+
const isIsolatedDynamicField = (dynamicField) => {
|
|
6879
|
+
return dynamicField.name.type === ISOLATED_ASSET_KEY;
|
|
6880
|
+
};
|
|
6881
|
+
do {
|
|
6882
|
+
const response = await address.cache.queryGetDynamicFields({
|
|
6883
|
+
parentId: marketObject,
|
|
6884
|
+
cursor: nextCursor,
|
|
6885
|
+
limit: 10
|
|
6886
|
+
});
|
|
6887
|
+
if (!response)
|
|
6888
|
+
break;
|
|
6889
|
+
const isolatedAssetCoinTypes = response.data.filter(isIsolatedDynamicField).map(({ name }) => `0x${name.value.type.name}`);
|
|
6890
|
+
isolatedAssets.push(...isolatedAssetCoinTypes);
|
|
6891
|
+
if (response && response.hasNextPage && response.nextCursor) {
|
|
6892
|
+
hasNextPage = true;
|
|
6893
|
+
nextCursor = response.nextCursor;
|
|
6894
|
+
} else {
|
|
6895
|
+
hasNextPage = false;
|
|
6896
|
+
}
|
|
6897
|
+
} while (hasNextPage);
|
|
6898
|
+
return isolatedAssets;
|
|
6899
|
+
} catch (e) {
|
|
6900
|
+
console.error(e);
|
|
6901
|
+
return [];
|
|
6902
|
+
}
|
|
6903
|
+
};
|
|
6904
|
+
var isIsolatedAsset = async (utils, coinName) => {
|
|
6905
|
+
try {
|
|
6906
|
+
const marketObject = utils.address.get("core.market");
|
|
6907
|
+
const cachedData = utils.address.cache.queryClient.getQueryData([
|
|
6908
|
+
"getDynamicFields",
|
|
6909
|
+
marketObject
|
|
6910
|
+
]);
|
|
6911
|
+
if (cachedData) {
|
|
6912
|
+
const coinType2 = utils.parseCoinType(coinName);
|
|
6913
|
+
return cachedData.includes(coinType2);
|
|
6914
|
+
}
|
|
6915
|
+
const coinType = utils.parseCoinType(coinName).slice(2);
|
|
6916
|
+
const object = await utils.cache.queryGetDynamicFieldObject({
|
|
6917
|
+
parentId: marketObject,
|
|
6918
|
+
name: {
|
|
6919
|
+
type: ISOLATED_ASSET_KEY,
|
|
6920
|
+
value: coinType
|
|
6921
|
+
}
|
|
6922
|
+
});
|
|
6923
|
+
const parsedData = isolatedAssetZod.safeParse(object?.data?.content);
|
|
6924
|
+
if (!parsedData.success)
|
|
6925
|
+
return false;
|
|
6926
|
+
return parsedData.data.fields.value;
|
|
6927
|
+
} catch (e) {
|
|
6928
|
+
console.error(e);
|
|
6929
|
+
return false;
|
|
6930
|
+
}
|
|
6931
|
+
};
|
|
6932
|
+
|
|
6933
|
+
// src/models/scallopQuery.ts
|
|
6951
6934
|
var ScallopQuery = class {
|
|
6952
6935
|
constructor(params, instance) {
|
|
6953
6936
|
this.params = params;
|
|
6954
|
-
this.suiKit = instance?.suiKit ?? instance?.utils?.suiKit ??
|
|
6937
|
+
this.suiKit = instance?.suiKit ?? instance?.utils?.suiKit ?? newSuiKit(params);
|
|
6955
6938
|
this.walletAddress = (0, import_utils23.normalizeSuiAddress)(
|
|
6956
|
-
params.walletAddress
|
|
6939
|
+
params.walletAddress ?? this.suiKit.currentAddress()
|
|
6957
6940
|
);
|
|
6958
6941
|
if (instance?.utils) {
|
|
6959
6942
|
this.utils = instance.utils;
|
|
@@ -6967,7 +6950,7 @@ var ScallopQuery = class {
|
|
|
6967
6950
|
);
|
|
6968
6951
|
this.address = new ScallopAddress(
|
|
6969
6952
|
{
|
|
6970
|
-
id: params?.addressesId
|
|
6953
|
+
id: params?.addressesId ?? ADDRESSES_ID,
|
|
6971
6954
|
network: params?.networkType,
|
|
6972
6955
|
forceInterface: params?.forceAddressesInterface
|
|
6973
6956
|
},
|
|
@@ -7017,11 +7000,10 @@ var ScallopQuery = class {
|
|
|
7017
7000
|
* @param address - ScallopAddress instance.
|
|
7018
7001
|
*/
|
|
7019
7002
|
async init(force = false, address) {
|
|
7020
|
-
if (
|
|
7021
|
-
this.address = address;
|
|
7022
|
-
}
|
|
7023
|
-
if (force || !this.address.getAddresses()) {
|
|
7003
|
+
if (force || !this.address.getAddresses() || !address?.getAddresses()) {
|
|
7024
7004
|
await this.address.read();
|
|
7005
|
+
} else {
|
|
7006
|
+
this.address = address;
|
|
7025
7007
|
}
|
|
7026
7008
|
await this.utils.init(force, this.address);
|
|
7027
7009
|
}
|
|
@@ -7031,8 +7013,8 @@ var ScallopQuery = class {
|
|
|
7031
7013
|
* @param indexer - Whether to use indexer.
|
|
7032
7014
|
* @return Market data.
|
|
7033
7015
|
*/
|
|
7034
|
-
async queryMarket(indexer = false) {
|
|
7035
|
-
return await queryMarket(this, indexer);
|
|
7016
|
+
async queryMarket(indexer = false, args) {
|
|
7017
|
+
return await queryMarket(this, indexer, args?.coinPrices);
|
|
7036
7018
|
}
|
|
7037
7019
|
/**
|
|
7038
7020
|
* Get market pools.
|
|
@@ -7045,8 +7027,8 @@ var ScallopQuery = class {
|
|
|
7045
7027
|
* @param indexer - Whether to use indexer.
|
|
7046
7028
|
* @return Market pools data.
|
|
7047
7029
|
*/
|
|
7048
|
-
async getMarketPools(poolCoinNames, indexer = false) {
|
|
7049
|
-
return await getMarketPools(this, poolCoinNames, indexer);
|
|
7030
|
+
async getMarketPools(poolCoinNames, indexer = false, args) {
|
|
7031
|
+
return await getMarketPools(this, poolCoinNames, indexer, args?.coinPrices);
|
|
7050
7032
|
}
|
|
7051
7033
|
/**
|
|
7052
7034
|
* Get market pool
|
|
@@ -7055,8 +7037,14 @@ var ScallopQuery = class {
|
|
|
7055
7037
|
* @param indexer - Whether to use indexer.
|
|
7056
7038
|
* @return Market pool data.
|
|
7057
7039
|
*/
|
|
7058
|
-
async getMarketPool(poolCoinName, indexer = false) {
|
|
7059
|
-
return await getMarketPool(
|
|
7040
|
+
async getMarketPool(poolCoinName, indexer = false, args) {
|
|
7041
|
+
return await getMarketPool(
|
|
7042
|
+
this,
|
|
7043
|
+
poolCoinName,
|
|
7044
|
+
indexer,
|
|
7045
|
+
args?.marketObject,
|
|
7046
|
+
args?.coinPrice
|
|
7047
|
+
);
|
|
7060
7048
|
}
|
|
7061
7049
|
/**
|
|
7062
7050
|
* Get market collaterals.
|
|
@@ -7166,8 +7154,14 @@ var ScallopQuery = class {
|
|
|
7166
7154
|
* @param indexer - Whether to use indexer.
|
|
7167
7155
|
* @return Spools data.
|
|
7168
7156
|
*/
|
|
7169
|
-
async getSpools(stakeMarketCoinNames, indexer = false) {
|
|
7170
|
-
return await getSpools(
|
|
7157
|
+
async getSpools(stakeMarketCoinNames, indexer = false, args) {
|
|
7158
|
+
return await getSpools(
|
|
7159
|
+
this,
|
|
7160
|
+
stakeMarketCoinNames,
|
|
7161
|
+
indexer,
|
|
7162
|
+
args?.marketPools,
|
|
7163
|
+
args?.coinPrices
|
|
7164
|
+
);
|
|
7171
7165
|
}
|
|
7172
7166
|
/**
|
|
7173
7167
|
* Get spool data.
|
|
@@ -7176,8 +7170,14 @@ var ScallopQuery = class {
|
|
|
7176
7170
|
* @param indexer - Whether to use indexer.
|
|
7177
7171
|
* @return Spool data.
|
|
7178
7172
|
*/
|
|
7179
|
-
async getSpool(stakeMarketCoinName, indexer = false) {
|
|
7180
|
-
return await getSpool(
|
|
7173
|
+
async getSpool(stakeMarketCoinName, indexer = false, args) {
|
|
7174
|
+
return await getSpool(
|
|
7175
|
+
this,
|
|
7176
|
+
stakeMarketCoinName,
|
|
7177
|
+
indexer,
|
|
7178
|
+
args?.marketPool,
|
|
7179
|
+
args?.coinPrices
|
|
7180
|
+
);
|
|
7181
7181
|
}
|
|
7182
7182
|
/**
|
|
7183
7183
|
* Get stake accounts data for all stake pools (spools).
|
|
@@ -7277,8 +7277,13 @@ var ScallopQuery = class {
|
|
|
7277
7277
|
* @param indexer - Whether to use indexer.
|
|
7278
7278
|
* @return Borrow incentive pools data.
|
|
7279
7279
|
*/
|
|
7280
|
-
async getBorrowIncentivePools(coinNames, indexer = false) {
|
|
7281
|
-
return await getBorrowIncentivePools(
|
|
7280
|
+
async getBorrowIncentivePools(coinNames, indexer = false, args) {
|
|
7281
|
+
return await getBorrowIncentivePools(
|
|
7282
|
+
this,
|
|
7283
|
+
coinNames,
|
|
7284
|
+
indexer,
|
|
7285
|
+
args?.coinPrices
|
|
7286
|
+
);
|
|
7282
7287
|
}
|
|
7283
7288
|
/**
|
|
7284
7289
|
* Get borrow incentive accounts data.
|
|
@@ -7491,10 +7496,10 @@ var ScallopQuery = class {
|
|
|
7491
7496
|
// src/models/scallopBuilder.ts
|
|
7492
7497
|
var ScallopBuilder = class {
|
|
7493
7498
|
constructor(params, instance) {
|
|
7494
|
-
this.suiKit = instance?.suiKit ??
|
|
7499
|
+
this.suiKit = instance?.suiKit ?? newSuiKit(params);
|
|
7495
7500
|
this.params = params;
|
|
7496
7501
|
this.walletAddress = (0, import_utils24.normalizeSuiAddress)(
|
|
7497
|
-
params?.walletAddress
|
|
7502
|
+
params?.walletAddress ?? this.suiKit.currentAddress()
|
|
7498
7503
|
);
|
|
7499
7504
|
if (instance?.query) {
|
|
7500
7505
|
this.query = instance.query;
|
|
@@ -7509,7 +7514,7 @@ var ScallopBuilder = class {
|
|
|
7509
7514
|
);
|
|
7510
7515
|
this.address = new ScallopAddress(
|
|
7511
7516
|
{
|
|
7512
|
-
id: params?.addressesId
|
|
7517
|
+
id: params?.addressesId ?? ADDRESSES_ID,
|
|
7513
7518
|
network: params?.networkType,
|
|
7514
7519
|
forceInterface: params?.forceAddressesInterface
|
|
7515
7520
|
},
|
|
@@ -7538,10 +7543,10 @@ var ScallopBuilder = class {
|
|
|
7538
7543
|
* @param address - ScallopAddress instance.
|
|
7539
7544
|
*/
|
|
7540
7545
|
async init(force = false, address) {
|
|
7541
|
-
if (
|
|
7542
|
-
this.address = address;
|
|
7543
|
-
if (force || !this.address.getAddresses()) {
|
|
7546
|
+
if (force || !this.address.getAddresses() || !address?.getAddresses()) {
|
|
7544
7547
|
await this.address.read();
|
|
7548
|
+
} else {
|
|
7549
|
+
this.address = address;
|
|
7545
7550
|
}
|
|
7546
7551
|
await this.query.init(force, this.address);
|
|
7547
7552
|
await this.utils.init(force, this.address);
|
|
@@ -7639,9 +7644,9 @@ var ScallopBuilder = class {
|
|
|
7639
7644
|
var ScallopClient = class {
|
|
7640
7645
|
constructor(params, instance) {
|
|
7641
7646
|
this.params = params;
|
|
7642
|
-
this.suiKit = instance?.suiKit ?? instance?.builder?.suiKit ??
|
|
7647
|
+
this.suiKit = instance?.suiKit ?? instance?.builder?.suiKit ?? newSuiKit(params);
|
|
7643
7648
|
this.walletAddress = (0, import_utils25.normalizeSuiAddress)(
|
|
7644
|
-
params?.walletAddress
|
|
7649
|
+
params?.walletAddress ?? this.suiKit.currentAddress()
|
|
7645
7650
|
);
|
|
7646
7651
|
if (instance?.builder) {
|
|
7647
7652
|
this.builder = instance.builder;
|
|
@@ -7657,7 +7662,7 @@ var ScallopClient = class {
|
|
|
7657
7662
|
);
|
|
7658
7663
|
this.address = new ScallopAddress(
|
|
7659
7664
|
{
|
|
7660
|
-
id: params?.addressesId
|
|
7665
|
+
id: params?.addressesId ?? ADDRESSES_ID,
|
|
7661
7666
|
network: params?.networkType,
|
|
7662
7667
|
forceInterface: params?.forceAddressesInterface
|
|
7663
7668
|
},
|
|
@@ -7711,7 +7716,7 @@ var ScallopClient = class {
|
|
|
7711
7716
|
* @return Obligations data.
|
|
7712
7717
|
*/
|
|
7713
7718
|
async getObligations(ownerAddress) {
|
|
7714
|
-
const owner = ownerAddress
|
|
7719
|
+
const owner = ownerAddress ?? this.walletAddress;
|
|
7715
7720
|
return await this.query.getObligations(owner);
|
|
7716
7721
|
}
|
|
7717
7722
|
/**
|
|
@@ -7736,7 +7741,7 @@ var ScallopClient = class {
|
|
|
7736
7741
|
* @return All stake accounts data.
|
|
7737
7742
|
*/
|
|
7738
7743
|
async getAllStakeAccounts(ownerAddress) {
|
|
7739
|
-
const owner = ownerAddress
|
|
7744
|
+
const owner = ownerAddress ?? this.walletAddress;
|
|
7740
7745
|
return await this.query.getAllStakeAccounts(owner);
|
|
7741
7746
|
}
|
|
7742
7747
|
/**
|
|
@@ -7750,7 +7755,7 @@ var ScallopClient = class {
|
|
|
7750
7755
|
* @return Stake accounts data.
|
|
7751
7756
|
*/
|
|
7752
7757
|
async getStakeAccounts(stakeMarketCoinName, ownerAddress) {
|
|
7753
|
-
const owner = ownerAddress
|
|
7758
|
+
const owner = ownerAddress ?? this.walletAddress;
|
|
7754
7759
|
return await this.query.getStakeAccounts(stakeMarketCoinName, owner);
|
|
7755
7760
|
}
|
|
7756
7761
|
/**
|
|
@@ -7790,10 +7795,10 @@ var ScallopClient = class {
|
|
|
7790
7795
|
}
|
|
7791
7796
|
async depositCollateral(collateralCoinName, amount, sign = true, obligationId, walletAddress) {
|
|
7792
7797
|
const txBlock = this.builder.createTxBlock();
|
|
7793
|
-
const sender = walletAddress
|
|
7798
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7794
7799
|
txBlock.setSender(sender);
|
|
7795
7800
|
const obligations = await this.query.getObligations(sender);
|
|
7796
|
-
const specificObligationId = obligationId
|
|
7801
|
+
const specificObligationId = obligationId ?? obligations[0]?.id;
|
|
7797
7802
|
if (specificObligationId) {
|
|
7798
7803
|
await txBlock.addCollateralQuick(
|
|
7799
7804
|
amount,
|
|
@@ -7827,7 +7832,7 @@ var ScallopClient = class {
|
|
|
7827
7832
|
*/
|
|
7828
7833
|
async withdrawCollateral(collateralCoinName, amount, sign = true, obligationId, obligationKey, walletAddress) {
|
|
7829
7834
|
const txBlock = this.builder.createTxBlock();
|
|
7830
|
-
const sender = walletAddress
|
|
7835
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7831
7836
|
txBlock.setSender(sender);
|
|
7832
7837
|
const collateralCoin = await txBlock.takeCollateralQuick(
|
|
7833
7838
|
amount,
|
|
@@ -7846,7 +7851,7 @@ var ScallopClient = class {
|
|
|
7846
7851
|
}
|
|
7847
7852
|
async deposit(poolCoinName, amount, sign = true, walletAddress) {
|
|
7848
7853
|
const txBlock = this.builder.createTxBlock();
|
|
7849
|
-
const sender = walletAddress
|
|
7854
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7850
7855
|
txBlock.setSender(sender);
|
|
7851
7856
|
const sCoin = await txBlock.depositQuick(amount, poolCoinName);
|
|
7852
7857
|
txBlock.transferObjects([sCoin], sender);
|
|
@@ -7860,11 +7865,11 @@ var ScallopClient = class {
|
|
|
7860
7865
|
}
|
|
7861
7866
|
async depositAndStake(stakeCoinName, amount, sign = true, stakeAccountId, walletAddress) {
|
|
7862
7867
|
const txBlock = this.builder.createTxBlock();
|
|
7863
|
-
const sender = walletAddress
|
|
7868
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7864
7869
|
txBlock.setSender(sender);
|
|
7865
7870
|
const stakeMarketCoinName = this.utils.parseMarketCoinName(stakeCoinName);
|
|
7866
7871
|
const stakeAccounts = await this.query.getStakeAccounts(stakeMarketCoinName);
|
|
7867
|
-
const targetStakeAccount = stakeAccountId
|
|
7872
|
+
const targetStakeAccount = stakeAccountId ?? stakeAccounts[0]?.id;
|
|
7868
7873
|
const marketCoin = await txBlock.depositQuick(amount, stakeCoinName, false);
|
|
7869
7874
|
if (targetStakeAccount) {
|
|
7870
7875
|
await txBlock.stakeQuick(
|
|
@@ -7887,7 +7892,7 @@ var ScallopClient = class {
|
|
|
7887
7892
|
}
|
|
7888
7893
|
async withdraw(poolCoinName, amount, sign = true, walletAddress) {
|
|
7889
7894
|
const txBlock = this.builder.createTxBlock();
|
|
7890
|
-
const sender = walletAddress
|
|
7895
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7891
7896
|
txBlock.setSender(sender);
|
|
7892
7897
|
const coin = await txBlock.withdrawQuick(amount, poolCoinName);
|
|
7893
7898
|
txBlock.transferObjects([coin], sender);
|
|
@@ -7912,7 +7917,7 @@ var ScallopClient = class {
|
|
|
7912
7917
|
*/
|
|
7913
7918
|
async borrow(poolCoinName, amount, sign = true, obligationId, obligationKey, walletAddress) {
|
|
7914
7919
|
const txBlock = this.builder.createTxBlock();
|
|
7915
|
-
const sender = walletAddress
|
|
7920
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7916
7921
|
txBlock.setSender(sender);
|
|
7917
7922
|
const availableStake = SUPPORT_BORROW_INCENTIVE_POOLS.includes(poolCoinName);
|
|
7918
7923
|
if (sign && availableStake) {
|
|
@@ -7948,7 +7953,7 @@ var ScallopClient = class {
|
|
|
7948
7953
|
*/
|
|
7949
7954
|
async repay(poolCoinName, amount, sign = true, obligationId, obligationKey, walletAddress) {
|
|
7950
7955
|
const txBlock = this.builder.createTxBlock();
|
|
7951
|
-
const sender = walletAddress
|
|
7956
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7952
7957
|
txBlock.setSender(sender);
|
|
7953
7958
|
const availableStake = SUPPORT_BORROW_INCENTIVE_POOLS.includes(poolCoinName);
|
|
7954
7959
|
if (sign && availableStake) {
|
|
@@ -7968,7 +7973,7 @@ var ScallopClient = class {
|
|
|
7968
7973
|
}
|
|
7969
7974
|
async flashLoan(poolCoinName, amount, callback, sign = true, walletAddress) {
|
|
7970
7975
|
const txBlock = this.builder.createTxBlock();
|
|
7971
|
-
const sender = walletAddress
|
|
7976
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7972
7977
|
txBlock.setSender(sender);
|
|
7973
7978
|
const [coin, loan] = txBlock.borrowFlashLoan(amount, poolCoinName);
|
|
7974
7979
|
txBlock.repayFlashLoan(await callback(txBlock, coin), loan, poolCoinName);
|
|
@@ -7982,7 +7987,7 @@ var ScallopClient = class {
|
|
|
7982
7987
|
}
|
|
7983
7988
|
async createStakeAccount(marketCoinName, sign = true, walletAddress) {
|
|
7984
7989
|
const txBlock = this.builder.createTxBlock();
|
|
7985
|
-
const sender = walletAddress
|
|
7990
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7986
7991
|
txBlock.setSender(sender);
|
|
7987
7992
|
const stakeAccount = txBlock.createStakeAccount(marketCoinName);
|
|
7988
7993
|
txBlock.transferObjects([stakeAccount], sender);
|
|
@@ -7996,10 +8001,10 @@ var ScallopClient = class {
|
|
|
7996
8001
|
}
|
|
7997
8002
|
async stake(stakeMarketCoinName, amount, sign = true, stakeAccountId, walletAddress) {
|
|
7998
8003
|
const txBlock = this.builder.createTxBlock();
|
|
7999
|
-
const sender = walletAddress
|
|
8004
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
8000
8005
|
txBlock.setSender(sender);
|
|
8001
8006
|
const stakeAccounts = await this.query.getStakeAccounts(stakeMarketCoinName);
|
|
8002
|
-
const targetStakeAccount = stakeAccountId
|
|
8007
|
+
const targetStakeAccount = stakeAccountId ?? stakeAccounts[0]?.id;
|
|
8003
8008
|
if (targetStakeAccount) {
|
|
8004
8009
|
await txBlock.stakeQuick(amount, stakeMarketCoinName, targetStakeAccount);
|
|
8005
8010
|
} else {
|
|
@@ -8017,7 +8022,7 @@ var ScallopClient = class {
|
|
|
8017
8022
|
}
|
|
8018
8023
|
async unstake(stakeMarketCoinName, amount, sign = true, stakeAccountId, walletAddress) {
|
|
8019
8024
|
const txBlock = this.builder.createTxBlock();
|
|
8020
|
-
const sender = walletAddress
|
|
8025
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
8021
8026
|
txBlock.setSender(sender);
|
|
8022
8027
|
const sCoin = await txBlock.unstakeQuick(
|
|
8023
8028
|
amount,
|
|
@@ -8043,7 +8048,7 @@ var ScallopClient = class {
|
|
|
8043
8048
|
}
|
|
8044
8049
|
async unstakeAndWithdraw(stakeMarketCoinName, amount, sign = true, stakeAccountId, walletAddress) {
|
|
8045
8050
|
const txBlock = this.builder.createTxBlock();
|
|
8046
|
-
const sender = walletAddress
|
|
8051
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
8047
8052
|
txBlock.setSender(sender);
|
|
8048
8053
|
const stakeMarketCoin = await txBlock.unstakeQuick(
|
|
8049
8054
|
amount,
|
|
@@ -8074,7 +8079,7 @@ var ScallopClient = class {
|
|
|
8074
8079
|
}
|
|
8075
8080
|
async claim(stakeMarketCoinName, sign = true, stakeAccountId, walletAddress) {
|
|
8076
8081
|
const txBlock = this.builder.createTxBlock();
|
|
8077
|
-
const sender = walletAddress
|
|
8082
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
8078
8083
|
txBlock.setSender(sender);
|
|
8079
8084
|
const rewardCoins = await txBlock.claimQuick(
|
|
8080
8085
|
stakeMarketCoinName,
|
|
@@ -8101,7 +8106,7 @@ var ScallopClient = class {
|
|
|
8101
8106
|
*/
|
|
8102
8107
|
async stakeObligation(obligationId, obligationKeyId, sign = true, walletAddress) {
|
|
8103
8108
|
const txBlock = this.builder.createTxBlock();
|
|
8104
|
-
const sender = walletAddress
|
|
8109
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
8105
8110
|
txBlock.setSender(sender);
|
|
8106
8111
|
await txBlock.stakeObligationWithVeScaQuick(obligationId, obligationKeyId);
|
|
8107
8112
|
if (sign) {
|
|
@@ -8123,7 +8128,7 @@ var ScallopClient = class {
|
|
|
8123
8128
|
*/
|
|
8124
8129
|
async unstakeObligation(obligationId, obligationKeyId, sign = true, walletAddress) {
|
|
8125
8130
|
const txBlock = this.builder.createTxBlock();
|
|
8126
|
-
const sender = walletAddress
|
|
8131
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
8127
8132
|
txBlock.setSender(sender);
|
|
8128
8133
|
await txBlock.unstakeObligationQuick(obligationId, obligationKeyId);
|
|
8129
8134
|
if (sign) {
|
|
@@ -8146,7 +8151,7 @@ var ScallopClient = class {
|
|
|
8146
8151
|
*/
|
|
8147
8152
|
async claimBorrowIncentive(coinName, obligationId, obligationKeyId, sign = true, walletAddress) {
|
|
8148
8153
|
const txBlock = this.builder.createTxBlock();
|
|
8149
|
-
const sender = walletAddress
|
|
8154
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
8150
8155
|
txBlock.setSender(sender);
|
|
8151
8156
|
const rewardCoins = [];
|
|
8152
8157
|
for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
|
|
@@ -8292,7 +8297,7 @@ var ScallopClient = class {
|
|
|
8292
8297
|
throw new Error("Only be used on the test network.");
|
|
8293
8298
|
}
|
|
8294
8299
|
const txBlock = this.builder.createTxBlock();
|
|
8295
|
-
const recipient = receiveAddress
|
|
8300
|
+
const recipient = receiveAddress ?? this.walletAddress;
|
|
8296
8301
|
const packageId = this.address.get("core.packages.testCoin.id");
|
|
8297
8302
|
const treasuryId = this.address.get(`core.coins.${assetCoinName}.treasury`);
|
|
8298
8303
|
const target = `${packageId}::${assetCoinName}::mint`;
|
|
@@ -8312,7 +8317,7 @@ var ScallopClient = class {
|
|
|
8312
8317
|
var Scallop = class {
|
|
8313
8318
|
constructor(params, cacheOptions, tokenBucket, queryClient) {
|
|
8314
8319
|
this.params = params;
|
|
8315
|
-
this.suiKit =
|
|
8320
|
+
this.suiKit = newSuiKit(params);
|
|
8316
8321
|
this.cache = new ScallopCache(
|
|
8317
8322
|
this.suiKit,
|
|
8318
8323
|
params.walletAddress,
|
|
@@ -8322,7 +8327,7 @@ var Scallop = class {
|
|
|
8322
8327
|
);
|
|
8323
8328
|
this.address = new ScallopAddress(
|
|
8324
8329
|
{
|
|
8325
|
-
id: params?.addressesId
|
|
8330
|
+
id: params?.addressesId ?? ADDRESSES_ID,
|
|
8326
8331
|
network: params?.networkType,
|
|
8327
8332
|
forceInterface: params?.forceAddressesInterface
|
|
8328
8333
|
},
|
|
@@ -8473,6 +8478,7 @@ var Scallop = class {
|
|
|
8473
8478
|
marketCoins,
|
|
8474
8479
|
queryKeys,
|
|
8475
8480
|
sCoinIds,
|
|
8481
|
+
sCoinTypeToName,
|
|
8476
8482
|
sCoins,
|
|
8477
8483
|
spoolRewardCoins,
|
|
8478
8484
|
stakeMarketCoins,
|