@scallop-io/sui-scallop-sdk 0.46.40 → 0.46.42
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/builders/loyaltyProgramBuilder.d.ts +1 -1
- package/dist/builders/sCoinBuilder.d.ts +4 -0
- package/dist/constants/common.d.ts +3 -1
- package/dist/constants/enum.d.ts +12 -10
- package/dist/index.js +660 -97
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +658 -92
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopBuilder.d.ts +16 -1
- package/dist/models/scallopClient.d.ts +5 -0
- package/dist/models/scallopQuery.d.ts +21 -2
- package/dist/models/scallopUtils.d.ts +32 -2
- package/dist/queries/portfolioQuery.d.ts +1 -1
- package/dist/queries/sCoinQuery.d.ts +27 -0
- package/dist/test.d.ts +1 -0
- package/dist/types/address.d.ts +8 -1
- package/dist/types/builder/core.d.ts +12 -4
- package/dist/types/builder/index.d.ts +6 -1
- package/dist/types/builder/sCoin.d.ts +37 -0
- package/dist/types/builder/spool.d.ts +2 -1
- package/dist/types/constant/common.d.ts +3 -2
- package/dist/types/constant/enum.d.ts +13 -1
- package/dist/types/query/core.d.ts +2 -1
- package/dist/types/query/index.d.ts +1 -0
- package/dist/types/query/portfolio.d.ts +1 -0
- package/dist/types/query/sCoin.d.ts +1 -0
- package/package.json +3 -3
- package/src/builders/coreBuilder.ts +72 -17
- package/src/builders/index.ts +5 -1
- package/src/builders/loyaltyProgramBuilder.ts +1 -1
- package/src/builders/referralBuilder.ts +1 -1
- package/src/builders/sCoinBuilder.ts +119 -0
- package/src/builders/spoolBuilder.ts +1 -1
- package/src/builders/vescaBuilder.ts +3 -3
- package/src/constants/common.ts +19 -5
- package/src/constants/enum.ts +98 -20
- package/src/constants/testAddress.ts +115 -21
- package/src/models/scallopAddress.ts +44 -3
- package/src/models/scallopBuilder.ts +43 -7
- package/src/models/scallopCache.ts +32 -4
- package/src/models/scallopClient.ts +121 -0
- package/src/models/scallopQuery.ts +46 -0
- package/src/models/scallopUtils.ts +56 -2
- package/src/queries/coreQuery.ts +10 -4
- package/src/queries/portfolioQuery.ts +26 -4
- package/src/queries/sCoinQuery.ts +94 -0
- package/src/queries/vescaQuery.ts +0 -1
- package/src/test.ts +19 -0
- package/src/types/address.ts +13 -0
- package/src/types/builder/core.ts +19 -4
- package/src/types/builder/index.ts +11 -3
- package/src/types/builder/sCoin.ts +61 -0
- package/src/types/builder/spool.ts +2 -0
- package/src/types/constant/common.ts +4 -1
- package/src/types/constant/enum.ts +17 -0
- package/src/types/query/core.ts +3 -0
- package/src/types/query/index.ts +1 -0
- package/src/types/query/portfolio.ts +1 -0
- package/src/types/query/sCoin.ts +1 -0
- package/src/utils/builder.ts +1 -1
- package/src/utils/util.ts +13 -17
package/dist/index.js
CHANGED
|
@@ -49,6 +49,7 @@ __export(src_exports, {
|
|
|
49
49
|
SUPPORT_ORACLES: () => SUPPORT_ORACLES,
|
|
50
50
|
SUPPORT_PACKAGES: () => SUPPORT_PACKAGES,
|
|
51
51
|
SUPPORT_POOLS: () => SUPPORT_POOLS,
|
|
52
|
+
SUPPORT_SCOIN: () => SUPPORT_SCOIN,
|
|
52
53
|
SUPPORT_SPOOLS: () => SUPPORT_SPOOLS,
|
|
53
54
|
SUPPORT_SPOOLS_REWARDS: () => SUPPORT_SPOOLS_REWARDS,
|
|
54
55
|
Scallop: () => Scallop,
|
|
@@ -60,11 +61,14 @@ __export(src_exports, {
|
|
|
60
61
|
ScallopQuery: () => ScallopQuery,
|
|
61
62
|
ScallopUtils: () => ScallopUtils,
|
|
62
63
|
UNLOCK_ROUND_DURATION: () => UNLOCK_ROUND_DURATION,
|
|
64
|
+
USE_TEST_ADDRESS: () => USE_TEST_ADDRESS,
|
|
63
65
|
assetCoins: () => assetCoins,
|
|
64
66
|
borrowIncentiveRewardCoins: () => borrowIncentiveRewardCoins,
|
|
65
67
|
coinDecimals: () => coinDecimals,
|
|
66
68
|
coinIds: () => coinIds,
|
|
67
69
|
marketCoins: () => marketCoins,
|
|
70
|
+
sCoinIds: () => sCoinIds,
|
|
71
|
+
sCoins: () => sCoins,
|
|
68
72
|
spoolRewardCoins: () => spoolRewardCoins,
|
|
69
73
|
stakeMarketCoins: () => stakeMarketCoins,
|
|
70
74
|
voloCoinIds: () => voloCoinIds,
|
|
@@ -73,13 +77,11 @@ __export(src_exports, {
|
|
|
73
77
|
module.exports = __toCommonJS(src_exports);
|
|
74
78
|
|
|
75
79
|
// src/constants/common.ts
|
|
76
|
-
var API_BASE_URL = "https://sui.
|
|
80
|
+
var API_BASE_URL = "https://sui.apis.scallop.io";
|
|
77
81
|
var SDK_API_BASE_URL = "https://sdk.api.scallop.io";
|
|
78
82
|
var IS_VE_SCA_TEST = false;
|
|
79
|
-
var
|
|
80
|
-
|
|
81
|
-
"65fb07c39c845425d71d7b18"
|
|
82
|
-
) : "664dfe22898c36c159e28bc8";
|
|
83
|
+
var USE_TEST_ADDRESS = false;
|
|
84
|
+
var ADDRESSES_ID = IS_VE_SCA_TEST || USE_TEST_ADDRESS ? "65fb07c39c845425d71d7b18" : "664dfe22898c36c159e28bc8";
|
|
83
85
|
var PROTOCOL_OBJECT_ID = IS_VE_SCA_TEST ? "0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778" : "0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf";
|
|
84
86
|
var BORROW_FEE_PROTOCOL_ID = IS_VE_SCA_TEST ? "0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778" : "0xc38f849e81cfe46d4e4320f508ea7dda42934a329d5a6571bb4c3cb6ea63f5da";
|
|
85
87
|
var SCA_COIN_TYPE = IS_VE_SCA_TEST ? `0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524::sca::SCA` : "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA";
|
|
@@ -122,6 +124,17 @@ var SUPPORT_SPOOLS = [
|
|
|
122
124
|
"shasui",
|
|
123
125
|
"svsui"
|
|
124
126
|
];
|
|
127
|
+
var SUPPORT_SCOIN = [
|
|
128
|
+
"ssui",
|
|
129
|
+
"susdc",
|
|
130
|
+
"susdt",
|
|
131
|
+
"safsui",
|
|
132
|
+
"shasui",
|
|
133
|
+
"svsui",
|
|
134
|
+
"seth",
|
|
135
|
+
"ssca",
|
|
136
|
+
"scetus"
|
|
137
|
+
];
|
|
125
138
|
var SUPPORT_SPOOLS_REWARDS = ["sui"];
|
|
126
139
|
var SUPPORT_BORROW_INCENTIVE_POOLS = [
|
|
127
140
|
"sui",
|
|
@@ -205,6 +218,17 @@ var marketCoins = {
|
|
|
205
218
|
svsui: "svsui",
|
|
206
219
|
ssca: "ssca"
|
|
207
220
|
};
|
|
221
|
+
var sCoins = {
|
|
222
|
+
seth: "seth",
|
|
223
|
+
susdc: "susdc",
|
|
224
|
+
susdt: "susdt",
|
|
225
|
+
ssui: "ssui",
|
|
226
|
+
scetus: "scetus",
|
|
227
|
+
safsui: "safsui",
|
|
228
|
+
shasui: "shasui",
|
|
229
|
+
svsui: "svsui",
|
|
230
|
+
ssca: "ssca"
|
|
231
|
+
};
|
|
208
232
|
var stakeMarketCoins = {
|
|
209
233
|
seth: "seth",
|
|
210
234
|
ssui: "ssui",
|
|
@@ -260,6 +284,17 @@ var wormholeCoinIds = {
|
|
|
260
284
|
var voloCoinIds = {
|
|
261
285
|
vsui: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55"
|
|
262
286
|
};
|
|
287
|
+
var sCoinIds = {
|
|
288
|
+
ssui: "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI",
|
|
289
|
+
scetus: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
|
|
290
|
+
ssca: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
|
|
291
|
+
susdc: "0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
292
|
+
susdt: "0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
|
|
293
|
+
seth: "0x67540ceb850d418679e69f1fb6b2093d6df78a2a699ffc733f7646096d552e9b::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
|
|
294
|
+
safsui: "0x00671b1fa2a124f5be8bdae8b91ee711462c5d9e31bda232e70fd9607b523c88::scallop_af_sui::SCALLOP_AF_SUI",
|
|
295
|
+
shasui: "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI",
|
|
296
|
+
svsui: "0xe1a1cc6bcf0001a015eab84bcc6713393ce20535f55b8b6f35c142e057a25fbe::scallop_v_sui::SCALLOP_V_SUI"
|
|
297
|
+
};
|
|
263
298
|
|
|
264
299
|
// src/constants/vesca.ts
|
|
265
300
|
var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
|
|
@@ -285,7 +320,7 @@ var FlashLoanFeeObjectMap = {
|
|
|
285
320
|
};
|
|
286
321
|
|
|
287
322
|
// src/models/scallop.ts
|
|
288
|
-
var
|
|
323
|
+
var import_sui_kit14 = require("@scallop-io/sui-kit");
|
|
289
324
|
|
|
290
325
|
// src/models/scallopCache.ts
|
|
291
326
|
var import_query_core = require("@tanstack/query-core");
|
|
@@ -405,6 +440,8 @@ var ScallopCache = class {
|
|
|
405
440
|
* @returns Promise<SuiObjectData[]>
|
|
406
441
|
*/
|
|
407
442
|
async queryGetObjects(objectIds, options) {
|
|
443
|
+
if (objectIds.length === 0)
|
|
444
|
+
return [];
|
|
408
445
|
const queryKey = [
|
|
409
446
|
"getObjects",
|
|
410
447
|
JSON.stringify(objectIds),
|
|
@@ -481,7 +518,7 @@ var ScallopCache = class {
|
|
|
481
518
|
queryKey,
|
|
482
519
|
queryFn: async () => {
|
|
483
520
|
const allBalances = await this.suiKit.client().getAllBalances({ owner });
|
|
484
|
-
|
|
521
|
+
const balances = allBalances.reduce(
|
|
485
522
|
(acc, coinBalance) => {
|
|
486
523
|
if (coinBalance.totalBalance !== "0") {
|
|
487
524
|
acc[(0, import_sui_kit.normalizeStructTag)(coinBalance.coinType)] = coinBalance.totalBalance;
|
|
@@ -490,11 +527,30 @@ var ScallopCache = class {
|
|
|
490
527
|
},
|
|
491
528
|
{}
|
|
492
529
|
);
|
|
493
|
-
|
|
530
|
+
for (const coinType in balances) {
|
|
531
|
+
const coinBalanceQueryKey = [
|
|
532
|
+
"getCoinBalance",
|
|
533
|
+
(0, import_sui_kit.normalizeSuiAddress)(owner),
|
|
534
|
+
(0, import_sui_kit.normalizeStructTag)(coinType)
|
|
535
|
+
];
|
|
536
|
+
this.queryClient.setQueryData(
|
|
537
|
+
coinBalanceQueryKey,
|
|
538
|
+
balances[coinType]
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
return balances;
|
|
542
|
+
},
|
|
543
|
+
staleTime: 5e3
|
|
494
544
|
});
|
|
495
545
|
}
|
|
496
546
|
async queryGetCoinBalance(input) {
|
|
497
|
-
|
|
547
|
+
if (!input.coinType)
|
|
548
|
+
return "0";
|
|
549
|
+
const queryKey = [
|
|
550
|
+
"getCoinBalance",
|
|
551
|
+
(0, import_sui_kit.normalizeSuiAddress)(input.owner),
|
|
552
|
+
(0, import_sui_kit.normalizeStructTag)(input.coinType)
|
|
553
|
+
];
|
|
498
554
|
return this.queryClient.fetchQuery({
|
|
499
555
|
queryKey,
|
|
500
556
|
queryFn: async () => {
|
|
@@ -512,13 +568,21 @@ var import_axios = __toESM(require("axios"));
|
|
|
512
568
|
// src/constants/testAddress.ts
|
|
513
569
|
var TEST_ADDRESSES = {
|
|
514
570
|
core: {
|
|
515
|
-
version:
|
|
571
|
+
// version:
|
|
572
|
+
// '0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7',
|
|
573
|
+
version: "0x6156d5cd1538bec8a167a40fe1209a4ec9cf8137921fe0a697f191ac561f0b09",
|
|
516
574
|
versionCap: "0x590a4011cb649b3878f3ea14b3a78674642a9548d79b7e091ef679574b158a07",
|
|
517
|
-
object:
|
|
518
|
-
|
|
575
|
+
// object:
|
|
576
|
+
// '0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf',
|
|
577
|
+
object: "0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1",
|
|
578
|
+
// market:
|
|
579
|
+
// '0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9',
|
|
580
|
+
market: "0x8606ed145cc887985b8ed793f7753ff5dc762a42c379dac035f568e1bac58490",
|
|
519
581
|
adminCap: "0x09689d018e71c337d9db6d67cbca06b74ed92196103624028ccc3ecea411777c",
|
|
520
582
|
coinDecimalsRegistry: "0x200abe9bf19751cc566ae35aa58e2b7e4ff688fc1130f8d8909ea09bc137d668",
|
|
521
|
-
obligationAccessStore:
|
|
583
|
+
// obligationAccessStore:
|
|
584
|
+
// '0x733e30b7c94d619d78cb8f5bc4bfbb759ced9a531239028caabb2474e5be59c9',
|
|
585
|
+
obligationAccessStore: "0x48b472d68ca910c45f7f3b6c26836b6aa6d2569810d94b1b939023da05ae0a23",
|
|
522
586
|
coins: {
|
|
523
587
|
cetus: {
|
|
524
588
|
id: "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b",
|
|
@@ -708,15 +772,25 @@ var TEST_ADDRESSES = {
|
|
|
708
772
|
upgradeCap: "0x3f203f6fff6a69d151e4f1cd931f22b68c489ef2759765662fc7baf673943c9e"
|
|
709
773
|
},
|
|
710
774
|
protocol: {
|
|
711
|
-
id: "
|
|
775
|
+
id: "0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1",
|
|
712
776
|
upgradeCap: "0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a"
|
|
713
777
|
},
|
|
778
|
+
// protocol: {
|
|
779
|
+
// id: '0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e',
|
|
780
|
+
// upgradeCap:
|
|
781
|
+
// '0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a',
|
|
782
|
+
// },
|
|
714
783
|
protocolWhitelist: {
|
|
715
784
|
id: "0x4c262d9343dac53ecb28f482a2a3f62c73d0ebac5b5f03d57383d56ff219acdf",
|
|
716
785
|
upgradeCap: "0x4a5e88a75039b00988f633f811f58117f31b8627a46bf822aa114d9010049449"
|
|
717
786
|
},
|
|
787
|
+
// query: {
|
|
788
|
+
// id: '0xb8d603a39114a5efef3dd0bf84df0bed1be1fbd39b78b7dd6e8a61ccc5e6006f',
|
|
789
|
+
// upgradeCap:
|
|
790
|
+
// '0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f',
|
|
791
|
+
// },
|
|
718
792
|
query: {
|
|
719
|
-
id: "
|
|
793
|
+
id: "0xe4f9d62d17746d5b9dbf0d5557747430021a71575780b515161210cdba0a4c1c",
|
|
720
794
|
upgradeCap: "0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f"
|
|
721
795
|
},
|
|
722
796
|
supra: { id: "", upgradeCap: "" },
|
|
@@ -733,41 +807,68 @@ var TEST_ADDRESSES = {
|
|
|
733
807
|
}
|
|
734
808
|
},
|
|
735
809
|
spool: {
|
|
736
|
-
id:
|
|
810
|
+
// id: '0x7c4fdabe81c31b19a45d1e572a52a539997a90903fbb5bfab71480abe0fa62c3',
|
|
811
|
+
id: "0x1742655fe5872dfa6456673f9e38612a4965e6979e6cd7696a7f1225f28bae21",
|
|
737
812
|
adminCap: "0xdd8a047cbbf802bfcde5288b8ef1910965d789cc614da11d39af05fca0bd020a",
|
|
738
|
-
object:
|
|
813
|
+
// object:
|
|
814
|
+
// '0xe87f1b2d498106a2c61421cec75b7b5c5e348512b0dc263949a0e7a3c256571a',
|
|
815
|
+
object: "0x1742655fe5872dfa6456673f9e38612a4965e6979e6cd7696a7f1225f28bae21",
|
|
739
816
|
pools: {
|
|
740
817
|
seth: {
|
|
741
818
|
id: "0xeec40beccb07c575bebd842eeaabb835f77cd3dab73add433477e57f583a6787",
|
|
742
819
|
rewardPoolId: "0x957de68a18d87817de8309b30c1ec269a4d87ae513abbeed86b5619cb9ce1077"
|
|
743
820
|
},
|
|
744
821
|
ssui: {
|
|
745
|
-
id:
|
|
746
|
-
|
|
822
|
+
// id: '0x4f0ba970d3c11db05c8f40c64a15b6a33322db3702d634ced6536960ab6f3ee4',
|
|
823
|
+
id: "0xb9617f83c06ebdeac0a8834782b1015e1cc7ea23739e30c132c4bfb95c37a579",
|
|
824
|
+
rewardPoolId: (
|
|
825
|
+
// '0x162250ef72393a4ad3d46294c4e1bdfcb03f04c869d390e7efbfc995353a7ee9',
|
|
826
|
+
"0xc3206071a8d43212efb6e3b5504f2321f8df97ab122b466c0bc7cfdf398dc13a"
|
|
827
|
+
)
|
|
747
828
|
},
|
|
748
829
|
susdc: {
|
|
749
|
-
id:
|
|
750
|
-
|
|
830
|
+
// id: '0x4ace6648ddc64e646ba47a957c562c32c9599b3bba8f5ac1aadb2ae23a2f8ca0',
|
|
831
|
+
id: "0xf1b383b9cf2e9f515fc69567df1053098f273849d09cd84b0278a773429bd2b2",
|
|
832
|
+
rewardPoolId: (
|
|
833
|
+
// '0xf4268cc9b9413b9bfe09e8966b8de650494c9e5784bf0930759cfef4904daff8',
|
|
834
|
+
"0xc71c53ee6505d928ba15bea4fe4f45d98c9c31eced94b72d00a7827d4b7ba3ff"
|
|
835
|
+
)
|
|
751
836
|
},
|
|
752
837
|
susdt: {
|
|
753
|
-
id:
|
|
754
|
-
|
|
838
|
+
// id: '0xcb328f7ffa7f9342ed85af3fdb2f22919e1a06dfb2f713c04c73543870d7548f',
|
|
839
|
+
id: "0xb5567dfa5c7fc17a249e959732664c50713dd8c23db1a11376b27df800c17418",
|
|
840
|
+
rewardPoolId: (
|
|
841
|
+
// '0x2c9f934d67a5baa586ceec2cc24163a2f049a6af3d5ba36b84d8ac40f25c4080',
|
|
842
|
+
"0x60768b0687ff0235e376a039709a683e4c436098785e473b67b32dbab47b69ab"
|
|
843
|
+
)
|
|
755
844
|
},
|
|
756
845
|
scetus: {
|
|
757
846
|
id: "0xac1bb13bf4472a637c18c2415fb0e3c1227ea2bcf35242e50563c98215bd298e",
|
|
758
847
|
rewardPoolId: "0x6835c1224126a45086fc6406adc249e3f30df18d779ca4f4e570e38716a17f3f"
|
|
759
848
|
},
|
|
760
849
|
safsui: {
|
|
761
|
-
id:
|
|
762
|
-
|
|
850
|
+
// id: '0xeedf438abcaa6ce4d9625ffca110920592d5867e4c5637d84ad9f466c4feb800',
|
|
851
|
+
id: "0xc568bb4c991258e839aa54802ecda04fcd9838c826bc3b42b40af81b23c458c8",
|
|
852
|
+
rewardPoolId: (
|
|
853
|
+
// '0x89255a2f86ed7fbfef35ab8b7be48cc7667015975be2685dd9a55a9a64baf76e',
|
|
854
|
+
"0x389a3cbeda742b918941bb24fd00e077bad3367484394d6234f8209b9a6aa03d"
|
|
855
|
+
)
|
|
763
856
|
},
|
|
764
857
|
shasui: {
|
|
765
|
-
id:
|
|
766
|
-
|
|
858
|
+
// id: '0xa6148bc1b623e936d39a952ceb5bea79e8b37228a8f595067bf1852efd3c34aa',
|
|
859
|
+
id: "0x93f3f4499bf89f2d05ddc1f8b15f51701a7c6c4d0ac0b9c3bc99462cbbd8e321",
|
|
860
|
+
rewardPoolId: (
|
|
861
|
+
// '0x6f3563644d3e2ef13176dbf9d865bd93479df60ccbe07b7e66db57f6309f5a66',
|
|
862
|
+
"0x94cee1be7f5ff34193f3aabef0b14142cb28af4d905fe487a9a7d85a15edb6aa"
|
|
863
|
+
)
|
|
767
864
|
},
|
|
768
865
|
svsui: {
|
|
769
|
-
id:
|
|
770
|
-
|
|
866
|
+
// id: '0x69ce8e537e750a95381e6040794afa5ab1758353a1a2e1de7760391b01f91670',
|
|
867
|
+
id: "0xa970e9087f80cb59e9299b8e7af7175d977ad6c9af0322aa4440e138fbd7ae00",
|
|
868
|
+
rewardPoolId: (
|
|
869
|
+
// '0xbca914adce058ad0902c7f3cfcd698392a475f00dcfdc3f76001d0370b98777a',
|
|
870
|
+
"0x38eee9699c4fc132a6623e54b865f047df4fc6eb83af807300f44e8f4b235ff0"
|
|
871
|
+
)
|
|
771
872
|
}
|
|
772
873
|
},
|
|
773
874
|
config: ""
|
|
@@ -791,7 +892,9 @@ var TEST_ADDRESSES = {
|
|
|
791
892
|
revenueTableId: "0x595baa3654c297bff84ab7786a2d250f019cefc66e8df8e89fd9d41e02bd30dd",
|
|
792
893
|
referralTiers: "0x962cb903d8d7346190c5204785ccbb91b61086aa764f674c8145df82335cf83e",
|
|
793
894
|
tiersTableId: "0xeac755a7a8b7798530905ac79e8c114f19d0f130f6eab012954f08faac29c75d",
|
|
794
|
-
authorizedWitnessList:
|
|
895
|
+
// authorizedWitnessList:
|
|
896
|
+
// '0xf21b0ed043c9bb70842c0129159f4943dbcc3c9ef2f2f808af65f8be25cfd20e',
|
|
897
|
+
authorizedWitnessList: "0x9d6223dc52015b8a3986a573590ef2af8f1b8f3e4685513888c052f001b87e7f",
|
|
795
898
|
version: "0x1bd4b7285f72e11c316b828c7c47b3f4da18dcec9f9b3dba6d8629cbb6f93e5e"
|
|
796
899
|
},
|
|
797
900
|
vesca: {
|
|
@@ -808,6 +911,47 @@ var TEST_ADDRESSES = {
|
|
|
808
911
|
object: "0xd17bcf8b5a59652c36225d478564a8593ae0ed7d650bcacdda1d6fe179127907",
|
|
809
912
|
rewardPool: "0xf9c090492ef476bd542109d0913ffe871cbfa28578b7114eca2a8c0e5671786f",
|
|
810
913
|
userRewardTableId: "0x748a80395849ed37db1b0e14f2ab5d1d96458d2359ab3a84eb079d0f4ac7cf2e"
|
|
914
|
+
},
|
|
915
|
+
scoin: {
|
|
916
|
+
id: "0xad2ca2aa5089df94bb2d444d5eb3520378c2f2dfb3a0bd2a2c994145ac4b0a53",
|
|
917
|
+
coins: {
|
|
918
|
+
ssui: {
|
|
919
|
+
coinType: "0xfac769100bccc0caebcf4f4e2d00ac2f8883f07f724be28940df90605f5e7e9a::scallop_sui::SCALLOP_SUI",
|
|
920
|
+
treasury: "0x9cb4551b36c17d37e19d700147fa819ea1c487ff8bcf18374de2cceb2e9d4845"
|
|
921
|
+
},
|
|
922
|
+
scetus: {
|
|
923
|
+
coinType: "0x8b71e6d323ed78515af2bead13bf3d0da1562ba4a99234eb7c4f14fd39ef0427::scallop_cetus::SCALLOP_CETUS",
|
|
924
|
+
treasury: "0xd786f4b2d26278cc7911a3445b1b085eab60f269ef9dbb6b87e803d52f155003"
|
|
925
|
+
},
|
|
926
|
+
ssca: {
|
|
927
|
+
coinType: "0x0a9d3c6c9af9f6e8def82921541bcbd17f73ed31bed3adcb684f2a4c267e42f0::scallop_sca::SCALLOP_SCA",
|
|
928
|
+
treasury: "0xe818636d1d6c46d6ea1a2dce9d94696d7cbc18ce27451b603eeaa47aba8d75e0"
|
|
929
|
+
},
|
|
930
|
+
susdc: {
|
|
931
|
+
coinType: "0xaedc3ab75db8680b81a755015fa90124d217be93457b893c05bac033817defaf::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
932
|
+
treasury: "0xfc6971648f867f7fd6928d1b873af71577e2eaf2c7543ef8bc82c431d833ae78"
|
|
933
|
+
},
|
|
934
|
+
susdt: {
|
|
935
|
+
coinType: "0xbf02fc87ddc104b342ad8414c85ceadf5b0c823c055a06fb0ed776272c01a52a::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
|
|
936
|
+
treasury: "0xb9593e2c3a0ba796ee815012b75ae46468ea78cda0188b9ac6816efe65503521"
|
|
937
|
+
},
|
|
938
|
+
seth: {
|
|
939
|
+
coinType: "0x27d54f43e3eda701be56b82e5756e41c84467cd202f5cf713d5f9e45a9f1b6bc::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
|
|
940
|
+
treasury: "0x032b4c8fac94c038dbe986f7587e9b1e4ef580b5ee06d2ef249d85459b7ef05d"
|
|
941
|
+
},
|
|
942
|
+
safsui: {
|
|
943
|
+
coinType: "0xb75b46d975d8d80670b53a6bee90baaa8ce2e0b7d397f079447d641eef6b44ad::scallop_af_sui::SCALLOP_AF_SUI",
|
|
944
|
+
treasury: "0x21450ef0570ef3d224ffa3b873ab802e439ece7b93cc7efad10ae0c1e3b3fcfe"
|
|
945
|
+
},
|
|
946
|
+
shasui: {
|
|
947
|
+
coinType: "0xd973a723874e2c7cde196602a79155a1343a933f8cf87d9b1bb7408bc1acbc58::scallop_ha_sui::SCALLOP_HA_SUI",
|
|
948
|
+
treasury: "0xf822fc1402207e47d2e3ba8ff6e1e594bf1de777dc5ebd2744619cd2726e3b0d"
|
|
949
|
+
},
|
|
950
|
+
svsui: {
|
|
951
|
+
coinType: "0x97023a317320c4498cc4cd239dd02fd30c28246e5e8f81325d63f2bd8d70f6b3::scallop_v_sui::SCALLOP_V_SUI",
|
|
952
|
+
treasury: "0x327114f0bf3559d7e2de10282147ed76a236c7c6775029165c4db09a6062ead6\u0192"
|
|
953
|
+
}
|
|
954
|
+
}
|
|
811
955
|
}
|
|
812
956
|
};
|
|
813
957
|
|
|
@@ -1110,6 +1254,47 @@ var EMPTY_ADDRESSES = {
|
|
|
1110
1254
|
object: "",
|
|
1111
1255
|
rewardPool: "",
|
|
1112
1256
|
userRewardTableId: ""
|
|
1257
|
+
},
|
|
1258
|
+
scoin: {
|
|
1259
|
+
id: "",
|
|
1260
|
+
coins: {
|
|
1261
|
+
ssui: {
|
|
1262
|
+
coinType: "",
|
|
1263
|
+
treasury: ""
|
|
1264
|
+
},
|
|
1265
|
+
scetus: {
|
|
1266
|
+
coinType: "",
|
|
1267
|
+
treasury: ""
|
|
1268
|
+
},
|
|
1269
|
+
ssca: {
|
|
1270
|
+
coinType: "",
|
|
1271
|
+
treasury: ""
|
|
1272
|
+
},
|
|
1273
|
+
susdc: {
|
|
1274
|
+
coinType: "",
|
|
1275
|
+
treasury: ""
|
|
1276
|
+
},
|
|
1277
|
+
susdt: {
|
|
1278
|
+
coinType: "",
|
|
1279
|
+
treasury: ""
|
|
1280
|
+
},
|
|
1281
|
+
seth: {
|
|
1282
|
+
coinType: "",
|
|
1283
|
+
treasury: ""
|
|
1284
|
+
},
|
|
1285
|
+
safsui: {
|
|
1286
|
+
coinType: "",
|
|
1287
|
+
treasury: ""
|
|
1288
|
+
},
|
|
1289
|
+
shasui: {
|
|
1290
|
+
coinType: "",
|
|
1291
|
+
treasury: ""
|
|
1292
|
+
},
|
|
1293
|
+
svsui: {
|
|
1294
|
+
coinType: "",
|
|
1295
|
+
treasury: ""
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1113
1298
|
}
|
|
1114
1299
|
};
|
|
1115
1300
|
var ScallopAddress = class {
|
|
@@ -1128,8 +1313,8 @@ var ScallopAddress = class {
|
|
|
1128
1313
|
this._auth = auth;
|
|
1129
1314
|
this._id = id;
|
|
1130
1315
|
this._network = network || "mainnet";
|
|
1131
|
-
this._addressesMap =
|
|
1132
|
-
if (
|
|
1316
|
+
this._addressesMap = USE_TEST_ADDRESS ? /* @__PURE__ */ new Map([["mainnet", TEST_ADDRESSES]]) : /* @__PURE__ */ new Map();
|
|
1317
|
+
if (USE_TEST_ADDRESS)
|
|
1133
1318
|
this._currentAddresses = TEST_ADDRESSES;
|
|
1134
1319
|
}
|
|
1135
1320
|
/**
|
|
@@ -1418,8 +1603,8 @@ var ScallopAddress = class {
|
|
|
1418
1603
|
};
|
|
1419
1604
|
|
|
1420
1605
|
// src/models/scallopClient.ts
|
|
1421
|
-
var
|
|
1422
|
-
var
|
|
1606
|
+
var import_utils23 = require("@mysten/sui.js/utils");
|
|
1607
|
+
var import_sui_kit13 = require("@scallop-io/sui-kit");
|
|
1423
1608
|
|
|
1424
1609
|
// src/models/scallopUtils.ts
|
|
1425
1610
|
var import_utils9 = require("@mysten/sui.js/utils");
|
|
@@ -1462,7 +1647,6 @@ var checkExtendLockPeriod = (lockPeriodInDays, newUnlockAtInSecondTimestamp, pre
|
|
|
1462
1647
|
const availableLockPeriodInDays = Math.floor(
|
|
1463
1648
|
(newUnlockAtInSecondTimestamp - prevUnlockAtInSecondTimestamp) / UNLOCK_ROUND_DURATION
|
|
1464
1649
|
);
|
|
1465
|
-
console.log("availableLockPeriodInDays", availableLockPeriodInDays);
|
|
1466
1650
|
if (lockPeriodInDays > availableLockPeriodInDays) {
|
|
1467
1651
|
throw new Error(
|
|
1468
1652
|
`Cannot extend lock period by ${lockPeriodInDays} days, maximum lock period is ~4 years (${MAX_LOCK_ROUNDS} days), remaining lock period is ${MAX_LOCK_ROUNDS - availableLockPeriodInDays}`
|
|
@@ -1921,16 +2105,18 @@ var estimatedFactor = (amount, scaleStep, type) => {
|
|
|
1921
2105
|
};
|
|
1922
2106
|
|
|
1923
2107
|
// src/utils/util.ts
|
|
2108
|
+
var COIN_SET = Array.from(
|
|
2109
|
+
/* @__PURE__ */ new Set([
|
|
2110
|
+
...SUPPORT_POOLS,
|
|
2111
|
+
...SUPPORT_COLLATERALS,
|
|
2112
|
+
...SUPPORT_SPOOLS_REWARDS,
|
|
2113
|
+
...SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
2114
|
+
...SUPPORT_SCOIN
|
|
2115
|
+
])
|
|
2116
|
+
);
|
|
1924
2117
|
var isMarketCoin = (coinName) => {
|
|
1925
2118
|
const assetCoinName = coinName.slice(1).toLowerCase();
|
|
1926
|
-
return coinName.charAt(0).toLowerCase() === "s" &&
|
|
1927
|
-
.../* @__PURE__ */ new Set([
|
|
1928
|
-
...SUPPORT_POOLS,
|
|
1929
|
-
...SUPPORT_COLLATERALS,
|
|
1930
|
-
...SUPPORT_SPOOLS_REWARDS,
|
|
1931
|
-
...SUPPORT_BORROW_INCENTIVE_REWARDS
|
|
1932
|
-
])
|
|
1933
|
-
].includes(assetCoinName);
|
|
2119
|
+
return coinName.charAt(0).toLowerCase() === "s" && COIN_SET.includes(assetCoinName);
|
|
1934
2120
|
};
|
|
1935
2121
|
var parseAssetSymbol = (coinName) => {
|
|
1936
2122
|
switch (coinName) {
|
|
@@ -1945,14 +2131,7 @@ var parseAssetSymbol = (coinName) => {
|
|
|
1945
2131
|
}
|
|
1946
2132
|
};
|
|
1947
2133
|
var parseDataFromPythPriceFeed = (feed, address) => {
|
|
1948
|
-
const assetCoinNames =
|
|
1949
|
-
.../* @__PURE__ */ new Set([
|
|
1950
|
-
...SUPPORT_POOLS,
|
|
1951
|
-
...SUPPORT_COLLATERALS,
|
|
1952
|
-
...SUPPORT_SPOOLS_REWARDS,
|
|
1953
|
-
...SUPPORT_BORROW_INCENTIVE_REWARDS
|
|
1954
|
-
])
|
|
1955
|
-
];
|
|
2134
|
+
const assetCoinNames = COIN_SET;
|
|
1956
2135
|
const assetCoinName = assetCoinNames.find((assetCoinName2) => {
|
|
1957
2136
|
return address.get(`core.coins.${assetCoinName2}.oracle.pyth.feed`) === feed.id;
|
|
1958
2137
|
});
|
|
@@ -2226,7 +2405,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2226
2405
|
}
|
|
2227
2406
|
}
|
|
2228
2407
|
}
|
|
2229
|
-
if (balanceSheet && borrowIndex && interestModel && borrowFeeRate) {
|
|
2408
|
+
if (balanceSheet && borrowIndex && interestModel && (USE_TEST_ADDRESS || borrowFeeRate)) {
|
|
2230
2409
|
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
2231
2410
|
type: interestModel.type.fields,
|
|
2232
2411
|
maxBorrowRate: interestModel.max_borrow_rate.fields,
|
|
@@ -2240,7 +2419,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2240
2419
|
reserve: balanceSheet.revenue,
|
|
2241
2420
|
reserveFactor: interestModel.revenue_factor.fields,
|
|
2242
2421
|
borrowWeight: interestModel.borrow_weight.fields,
|
|
2243
|
-
borrowFeeRate,
|
|
2422
|
+
borrowFeeRate: borrowFeeRate || { value: "0" },
|
|
2244
2423
|
baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
|
|
2245
2424
|
borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
|
|
2246
2425
|
borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
|
|
@@ -2276,10 +2455,10 @@ var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) =
|
|
|
2276
2455
|
collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
|
|
2277
2456
|
const marketId = query.address.get("core.market");
|
|
2278
2457
|
const [marketObjectResponse, coinPrices] = await Promise.all([
|
|
2279
|
-
query.cache.queryGetObject(marketId, {
|
|
2458
|
+
await query.cache.queryGetObject(marketId, {
|
|
2280
2459
|
showContent: true
|
|
2281
2460
|
}),
|
|
2282
|
-
query.utils.getCoinPrices(collateralCoinNames ?? [])
|
|
2461
|
+
await query.utils.getCoinPrices(collateralCoinNames ?? [])
|
|
2283
2462
|
]);
|
|
2284
2463
|
const marketCollaterals = {};
|
|
2285
2464
|
if (indexer) {
|
|
@@ -3218,7 +3397,7 @@ var getLendings = async (query, poolCoinNames, ownerAddress, indexer = false) =>
|
|
|
3218
3397
|
);
|
|
3219
3398
|
return lendings;
|
|
3220
3399
|
};
|
|
3221
|
-
var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice) => {
|
|
3400
|
+
var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice, sCoinAmount) => {
|
|
3222
3401
|
const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
|
|
3223
3402
|
marketPool = marketPool || await query.getMarketPool(poolCoinName, indexer);
|
|
3224
3403
|
spool = spool || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(marketCoinName, indexer) : void 0;
|
|
@@ -3228,6 +3407,7 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
3228
3407
|
) : [];
|
|
3229
3408
|
coinAmount = coinAmount || await query.getCoinAmount(poolCoinName, ownerAddress);
|
|
3230
3409
|
marketCoinAmount = marketCoinAmount || await query.getMarketCoinAmount(marketCoinName, ownerAddress);
|
|
3410
|
+
sCoinAmount = sCoinAmount || await query.getSCoinAmount(marketCoinName, ownerAddress);
|
|
3231
3411
|
coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
3232
3412
|
const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
3233
3413
|
let stakedMarketAmount = (0, import_bignumber4.default)(0);
|
|
@@ -3279,9 +3459,7 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
3279
3459
|
);
|
|
3280
3460
|
}
|
|
3281
3461
|
}
|
|
3282
|
-
const suppliedAmount = (0, import_bignumber4.default)(marketCoinAmount).multipliedBy(
|
|
3283
|
-
marketPool?.conversionRate ?? 1
|
|
3284
|
-
);
|
|
3462
|
+
const suppliedAmount = (0, import_bignumber4.default)(marketCoinAmount).plus((0, import_bignumber4.default)(sCoinAmount)).multipliedBy(marketPool?.conversionRate ?? 1);
|
|
3285
3463
|
const suppliedCoin = suppliedAmount.shiftedBy(-1 * coinDecimal);
|
|
3286
3464
|
const suppliedValue = suppliedCoin.multipliedBy(coinPrice ?? 0);
|
|
3287
3465
|
const marketCoinPrice = (0, import_bignumber4.default)(coinPrice ?? 0).multipliedBy(
|
|
@@ -3383,6 +3561,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3383
3561
|
let totalBorrowCapacityValue = (0, import_bignumber4.default)(0);
|
|
3384
3562
|
let totalRequiredCollateralValue = (0, import_bignumber4.default)(0);
|
|
3385
3563
|
let totalBorrowedPools = 0;
|
|
3564
|
+
let totalRewardedPools = 0;
|
|
3386
3565
|
let totalBorrowedValue = (0, import_bignumber4.default)(0);
|
|
3387
3566
|
let totalBorrowedValueWithWeight = (0, import_bignumber4.default)(0);
|
|
3388
3567
|
for (const assetCoinName of collateralAssetCoinNames) {
|
|
@@ -3544,6 +3723,12 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3544
3723
|
}
|
|
3545
3724
|
}
|
|
3546
3725
|
}
|
|
3726
|
+
if (Object.keys(borrowIncentivePool.points).some((coinName2) => {
|
|
3727
|
+
const rewardApr = borrowIncentivePool.points[coinName2]?.rewardApr;
|
|
3728
|
+
return rewardApr !== Infinity && typeof rewardApr == "number" && rewardApr > 0;
|
|
3729
|
+
}) && borrowIncentiveAccount.debtAmount > 0) {
|
|
3730
|
+
totalRewardedPools++;
|
|
3731
|
+
}
|
|
3547
3732
|
borrowIncentives[coinName] = {
|
|
3548
3733
|
coinName: borrowIncentivePool.coinName,
|
|
3549
3734
|
coinType: borrowIncentivePool.coinType,
|
|
@@ -3581,6 +3766,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3581
3766
|
totalRiskLevel: riskLevel.toNumber(),
|
|
3582
3767
|
totalDepositedPools,
|
|
3583
3768
|
totalBorrowedPools,
|
|
3769
|
+
totalRewardedPools,
|
|
3584
3770
|
collaterals,
|
|
3585
3771
|
debts,
|
|
3586
3772
|
borrowIncentives
|
|
@@ -3823,7 +4009,6 @@ var getVeScaTreasuryInfo = async (query) => {
|
|
|
3823
4009
|
if (!veScaTreasury || veScaTreasury.data?.content?.dataType !== "moveObject")
|
|
3824
4010
|
return null;
|
|
3825
4011
|
const treasuryFields = veScaTreasury.data.content.fields;
|
|
3826
|
-
console.log(treasuryFields);
|
|
3827
4012
|
const totalLockedSca = (0, import_bignumber5.default)(
|
|
3828
4013
|
treasuryFields.unlock_schedule.fields.locked_sca_amount
|
|
3829
4014
|
).shiftedBy(-9).toNumber();
|
|
@@ -4075,6 +4260,56 @@ var ScallopIndexer = class {
|
|
|
4075
4260
|
}
|
|
4076
4261
|
};
|
|
4077
4262
|
|
|
4263
|
+
// src/queries/sCoinQuery.ts
|
|
4264
|
+
var import_bcs2 = require("@mysten/sui.js/bcs");
|
|
4265
|
+
var import_assert = __toESM(require("assert"));
|
|
4266
|
+
var import_bignumber7 = __toESM(require("bignumber.js"));
|
|
4267
|
+
var getSCoinTotalSupply = async (query, sCoinName) => {
|
|
4268
|
+
const sCoinPkgId = query.address.get("scoin.id");
|
|
4269
|
+
const args = [query.utils.getSCoinTreasury(sCoinName)];
|
|
4270
|
+
const typeArgs = [
|
|
4271
|
+
query.utils.parseSCoinType(sCoinName),
|
|
4272
|
+
query.utils.parseUnderlyingSCoinType(sCoinName)
|
|
4273
|
+
];
|
|
4274
|
+
const queryTarget = `${sCoinPkgId}::s_coin_converter::total_supply`;
|
|
4275
|
+
const queryResults = await query.cache.queryInspectTxn({
|
|
4276
|
+
queryTarget,
|
|
4277
|
+
args,
|
|
4278
|
+
typeArgs
|
|
4279
|
+
});
|
|
4280
|
+
const results = queryResults.results;
|
|
4281
|
+
if (results && results[0].returnValues) {
|
|
4282
|
+
const value = Uint8Array.from(results[0].returnValues[0][0]);
|
|
4283
|
+
const type = results[0].returnValues[0][1];
|
|
4284
|
+
(0, import_assert.default)(type === "u64", "Result type is not u64");
|
|
4285
|
+
return (0, import_bignumber7.default)(import_bcs2.bcs.de(type, value)).shiftedBy(
|
|
4286
|
+
query.utils.getCoinDecimal(query.utils.parseCoinName(sCoinName))
|
|
4287
|
+
).toNumber();
|
|
4288
|
+
}
|
|
4289
|
+
return 0;
|
|
4290
|
+
};
|
|
4291
|
+
var getSCoinAmounts = async (query, sCoinNames, ownerAddress) => {
|
|
4292
|
+
sCoinNames = sCoinNames || [...SUPPORT_SCOIN];
|
|
4293
|
+
const owner = ownerAddress || query.suiKit.currentAddress();
|
|
4294
|
+
const sCoins2 = {};
|
|
4295
|
+
await Promise.allSettled(
|
|
4296
|
+
sCoinNames.map(async (sCoinName) => {
|
|
4297
|
+
const sCoin = await getSCoinAmount(query, sCoinName, owner);
|
|
4298
|
+
sCoins2[sCoinName] = sCoin;
|
|
4299
|
+
})
|
|
4300
|
+
);
|
|
4301
|
+
return sCoins2;
|
|
4302
|
+
};
|
|
4303
|
+
var getSCoinAmount = async (query, sCoinName, ownerAddress) => {
|
|
4304
|
+
const owner = ownerAddress || query.suiKit.currentAddress();
|
|
4305
|
+
const sCoinType = query.utils.parseSCoinType(sCoinName);
|
|
4306
|
+
const amount = await query.cache.queryGetCoinBalance({
|
|
4307
|
+
owner,
|
|
4308
|
+
coinType: sCoinType
|
|
4309
|
+
});
|
|
4310
|
+
return (0, import_bignumber7.default)(amount).toNumber();
|
|
4311
|
+
};
|
|
4312
|
+
|
|
4078
4313
|
// src/models/scallopQuery.ts
|
|
4079
4314
|
var ScallopQuery = class {
|
|
4080
4315
|
constructor(params, instance) {
|
|
@@ -4491,6 +4726,35 @@ var ScallopQuery = class {
|
|
|
4491
4726
|
return await getLoyaltyProgramInformations(this, veScaKey);
|
|
4492
4727
|
}
|
|
4493
4728
|
/**
|
|
4729
|
+
* Get total supply of sCoin
|
|
4730
|
+
* @param sCoinName - Supported sCoin name
|
|
4731
|
+
* @returns Total Supply
|
|
4732
|
+
*/
|
|
4733
|
+
async getSCoinTotalSupply(sCoinName) {
|
|
4734
|
+
return await getSCoinTotalSupply(this, sCoinName);
|
|
4735
|
+
}
|
|
4736
|
+
/**
|
|
4737
|
+
* Get all sCoin amounts.
|
|
4738
|
+
*
|
|
4739
|
+
* @param sCoinNames - Specific an array of support sCoin name.
|
|
4740
|
+
* @param ownerAddress - The owner address.
|
|
4741
|
+
* @return All market sCoin amounts.
|
|
4742
|
+
*/
|
|
4743
|
+
async getSCoinAmounts(sCoinNames, ownerAddress) {
|
|
4744
|
+
return await getSCoinAmounts(this, sCoinNames, ownerAddress);
|
|
4745
|
+
}
|
|
4746
|
+
/**
|
|
4747
|
+
* Get sCoin amount.
|
|
4748
|
+
*
|
|
4749
|
+
* @param coinNames - Specific support sCoin name.
|
|
4750
|
+
* @param ownerAddress - The owner address.
|
|
4751
|
+
* @return sCoin amount.
|
|
4752
|
+
*/
|
|
4753
|
+
async getSCoinAmount(sCoinName, ownerAddress) {
|
|
4754
|
+
const parsedSCoinName = this.utils.parseSCoinName(sCoinName);
|
|
4755
|
+
return parsedSCoinName ? await getSCoinAmount(this, parsedSCoinName, ownerAddress) : 0;
|
|
4756
|
+
}
|
|
4757
|
+
/*
|
|
4494
4758
|
* Get flashloan fee for specified assets
|
|
4495
4759
|
*/
|
|
4496
4760
|
async getFlashLoanFees(assetCoinNames = [...SUPPORT_POOLS]) {
|
|
@@ -4611,6 +4875,48 @@ var ScallopUtils = class {
|
|
|
4611
4875
|
return `${coinPackageId}::${coinName}::${coinName.toUpperCase()}`;
|
|
4612
4876
|
}
|
|
4613
4877
|
}
|
|
4878
|
+
/**
|
|
4879
|
+
* Convert coin name to sCoin name.
|
|
4880
|
+
*
|
|
4881
|
+
* @param coinName - Specific support coin name.
|
|
4882
|
+
* @return sCoin name.
|
|
4883
|
+
*/
|
|
4884
|
+
parseSCoinName(coinName) {
|
|
4885
|
+
if (isMarketCoin(coinName) && SUPPORT_SCOIN.includes(coinName)) {
|
|
4886
|
+
return coinName;
|
|
4887
|
+
} else {
|
|
4888
|
+
const marketCoinName = `s${coinName}`;
|
|
4889
|
+
if (SUPPORT_SCOIN.includes(marketCoinName)) {
|
|
4890
|
+
return marketCoinName;
|
|
4891
|
+
}
|
|
4892
|
+
return void 0;
|
|
4893
|
+
}
|
|
4894
|
+
}
|
|
4895
|
+
/**
|
|
4896
|
+
* Convert sCoin name into sCoin type
|
|
4897
|
+
* @param sCoinName
|
|
4898
|
+
* @returns sCoin type
|
|
4899
|
+
*/
|
|
4900
|
+
parseSCoinType(sCoinName) {
|
|
4901
|
+
return sCoinIds[sCoinName];
|
|
4902
|
+
}
|
|
4903
|
+
/**
|
|
4904
|
+
* Convert sCoin name into its underlying coin type
|
|
4905
|
+
* @param sCoinName
|
|
4906
|
+
* @returns coin type
|
|
4907
|
+
*/
|
|
4908
|
+
parseUnderlyingSCoinType(sCoinName) {
|
|
4909
|
+
const coinName = this.parseCoinName(sCoinName);
|
|
4910
|
+
return this.parseCoinType(coinName);
|
|
4911
|
+
}
|
|
4912
|
+
/**
|
|
4913
|
+
* Get sCoin treasury id from sCoin name
|
|
4914
|
+
* @param sCoinName
|
|
4915
|
+
* @returns sCoin treasury id
|
|
4916
|
+
*/
|
|
4917
|
+
getSCoinTreasury(sCoinName) {
|
|
4918
|
+
return this._address.get(`scoin.coins.${sCoinName}.treasury`);
|
|
4919
|
+
}
|
|
4614
4920
|
/**
|
|
4615
4921
|
* Convert coin name to market coin type.
|
|
4616
4922
|
*
|
|
@@ -4688,14 +4994,14 @@ var ScallopUtils = class {
|
|
|
4688
4994
|
* @param coinType - The coin type, default is 0x2::SUI::SUI.
|
|
4689
4995
|
* @return The selected transaction coin arguments.
|
|
4690
4996
|
*/
|
|
4691
|
-
async
|
|
4997
|
+
async selectCoins(amount, coinType = import_utils9.SUI_TYPE_ARG, ownerAddress) {
|
|
4692
4998
|
ownerAddress = ownerAddress || this._suiKit.currentAddress();
|
|
4693
4999
|
const coins = await this._suiKit.suiInteractor.selectCoins(
|
|
4694
5000
|
ownerAddress,
|
|
4695
5001
|
amount,
|
|
4696
5002
|
coinType
|
|
4697
5003
|
);
|
|
4698
|
-
return coins
|
|
5004
|
+
return coins;
|
|
4699
5005
|
}
|
|
4700
5006
|
/**
|
|
4701
5007
|
* Get all asset coin names in the obligation record by obligation id.
|
|
@@ -4869,8 +5175,8 @@ var ScallopUtils = class {
|
|
|
4869
5175
|
};
|
|
4870
5176
|
|
|
4871
5177
|
// src/models/scallopBuilder.ts
|
|
4872
|
-
var
|
|
4873
|
-
var
|
|
5178
|
+
var import_utils22 = require("@mysten/sui.js/utils");
|
|
5179
|
+
var import_sui_kit12 = require("@scallop-io/sui-kit");
|
|
4874
5180
|
|
|
4875
5181
|
// src/builders/coreBuilder.ts
|
|
4876
5182
|
var import_transactions = require("@mysten/sui.js/transactions");
|
|
@@ -5048,10 +5354,13 @@ var generateCoreNormalMethod = ({
|
|
|
5048
5354
|
const referralPkgId = builder.address.get("referral.id");
|
|
5049
5355
|
const referralWitnessType = `${referralPkgId}::scallop_referral_program::REFERRAL_WITNESS`;
|
|
5050
5356
|
return {
|
|
5051
|
-
openObligation: () =>
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5357
|
+
openObligation: () => {
|
|
5358
|
+
const [obligation, obligationKey, obligationHotPotato] = txBlock.moveCall(
|
|
5359
|
+
`${coreIds.protocolPkg}::open_obligation::open_obligation`,
|
|
5360
|
+
[coreIds.version]
|
|
5361
|
+
);
|
|
5362
|
+
return [obligation, obligationKey, obligationHotPotato];
|
|
5363
|
+
},
|
|
5055
5364
|
returnObligation: (obligation, obligationHotPotato) => txBlock.moveCall(
|
|
5056
5365
|
`${coreIds.protocolPkg}::open_obligation::return_obligation`,
|
|
5057
5366
|
[coreIds.version, obligation, obligationHotPotato]
|
|
@@ -5245,11 +5554,12 @@ var generateCoreQuickMethod = ({
|
|
|
5245
5554
|
collateralCoinName
|
|
5246
5555
|
);
|
|
5247
5556
|
},
|
|
5248
|
-
depositQuick: async (amount, poolCoinName) => {
|
|
5557
|
+
depositQuick: async (amount, poolCoinName, returnSCoin = true) => {
|
|
5249
5558
|
const sender = requireSender(txBlock);
|
|
5559
|
+
let marketCoinDeposit;
|
|
5250
5560
|
if (poolCoinName === "sui") {
|
|
5251
5561
|
const [suiCoin] = txBlock.splitSUIFromGas([amount]);
|
|
5252
|
-
|
|
5562
|
+
marketCoinDeposit = txBlock.deposit(suiCoin, poolCoinName);
|
|
5253
5563
|
} else {
|
|
5254
5564
|
const { leftCoin, takeCoin } = await builder.selectCoin(
|
|
5255
5565
|
txBlock,
|
|
@@ -5258,20 +5568,56 @@ var generateCoreQuickMethod = ({
|
|
|
5258
5568
|
sender
|
|
5259
5569
|
);
|
|
5260
5570
|
txBlock.transferObjects([leftCoin], sender);
|
|
5261
|
-
|
|
5571
|
+
marketCoinDeposit = txBlock.deposit(takeCoin, poolCoinName);
|
|
5262
5572
|
}
|
|
5573
|
+
return returnSCoin ? txBlock.mintSCoin(
|
|
5574
|
+
builder.utils.parseMarketCoinName(poolCoinName),
|
|
5575
|
+
marketCoinDeposit
|
|
5576
|
+
) : marketCoinDeposit;
|
|
5263
5577
|
},
|
|
5264
5578
|
withdrawQuick: async (amount, poolCoinName) => {
|
|
5265
5579
|
const sender = requireSender(txBlock);
|
|
5266
5580
|
const marketCoinName = builder.utils.parseMarketCoinName(poolCoinName);
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5271
|
-
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
|
|
5581
|
+
try {
|
|
5582
|
+
const sCoinName = builder.utils.parseSCoinName(poolCoinName);
|
|
5583
|
+
if (!sCoinName)
|
|
5584
|
+
throw new Error(`No sCoin for ${poolCoinName}`);
|
|
5585
|
+
const { leftCoin, takeCoin, totalAmount } = await builder.selectSCoin(
|
|
5586
|
+
txBlock,
|
|
5587
|
+
sCoinName,
|
|
5588
|
+
amount,
|
|
5589
|
+
sender
|
|
5590
|
+
);
|
|
5591
|
+
txBlock.transferObjects([leftCoin], sender);
|
|
5592
|
+
const marketCoin = txBlock.burnSCoin(sCoinName, takeCoin);
|
|
5593
|
+
const txResult = txBlock.withdraw(marketCoin, poolCoinName);
|
|
5594
|
+
amount -= totalAmount;
|
|
5595
|
+
try {
|
|
5596
|
+
if (amount > 0) {
|
|
5597
|
+
const { leftCoin: leftCoin2, takeCoin: takeCoin2 } = await builder.selectMarketCoin(
|
|
5598
|
+
txBlock,
|
|
5599
|
+
marketCoinName,
|
|
5600
|
+
amount,
|
|
5601
|
+
sender
|
|
5602
|
+
);
|
|
5603
|
+
txBlock.transferObjects([leftCoin2], sender);
|
|
5604
|
+
txBlock.mergeCoins(txResult, [
|
|
5605
|
+
txBlock.withdraw(takeCoin2, poolCoinName)
|
|
5606
|
+
]);
|
|
5607
|
+
}
|
|
5608
|
+
} catch (e) {
|
|
5609
|
+
}
|
|
5610
|
+
return txResult;
|
|
5611
|
+
} catch (e) {
|
|
5612
|
+
const { leftCoin, takeCoin } = await builder.selectMarketCoin(
|
|
5613
|
+
txBlock,
|
|
5614
|
+
marketCoinName,
|
|
5615
|
+
amount,
|
|
5616
|
+
sender
|
|
5617
|
+
);
|
|
5618
|
+
txBlock.transferObjects([leftCoin], sender);
|
|
5619
|
+
return txBlock.withdraw(takeCoin, poolCoinName);
|
|
5620
|
+
}
|
|
5275
5621
|
},
|
|
5276
5622
|
borrowQuick: async (amount, poolCoinName, obligationId, obligationKey) => {
|
|
5277
5623
|
const obligationInfo = await requireObligationInfo(
|
|
@@ -5475,7 +5821,7 @@ var generateSpoolQuickMethod = ({
|
|
|
5475
5821
|
);
|
|
5476
5822
|
const marketCoinType = builder.utils.parseMarketCoinType(stakeMarketCoinName);
|
|
5477
5823
|
if (typeof amountOrMarketCoin === "number") {
|
|
5478
|
-
const coins = await builder.utils.
|
|
5824
|
+
const coins = await builder.utils.selectCoins(
|
|
5479
5825
|
amountOrMarketCoin,
|
|
5480
5826
|
marketCoinType,
|
|
5481
5827
|
sender
|
|
@@ -5686,7 +6032,7 @@ var generateQuickVeScaMethod = ({
|
|
|
5686
6032
|
let scaCoin = void 0;
|
|
5687
6033
|
const transferObjects = [];
|
|
5688
6034
|
if (amountOrCoin !== void 0 && typeof amountOrCoin === "number") {
|
|
5689
|
-
const coins = await builder.utils.
|
|
6035
|
+
const coins = await builder.utils.selectCoins(
|
|
5690
6036
|
amountOrCoin,
|
|
5691
6037
|
SCA_COIN_TYPE,
|
|
5692
6038
|
sender
|
|
@@ -5758,7 +6104,7 @@ var generateQuickVeScaMethod = ({
|
|
|
5758
6104
|
if (autoCheck)
|
|
5759
6105
|
checkExtendLockAmount(scaAmount, veSca?.unlockAt);
|
|
5760
6106
|
if (veSca) {
|
|
5761
|
-
const scaCoins = await builder.utils.
|
|
6107
|
+
const scaCoins = await builder.utils.selectCoins(
|
|
5762
6108
|
scaAmount,
|
|
5763
6109
|
SCA_COIN_TYPE,
|
|
5764
6110
|
sender
|
|
@@ -5786,7 +6132,7 @@ var generateQuickVeScaMethod = ({
|
|
|
5786
6132
|
const unlockedSca = txBlock.redeemSca(veSca.keyId);
|
|
5787
6133
|
transferObjects.push(unlockedSca);
|
|
5788
6134
|
}
|
|
5789
|
-
const scaCoins = await builder.utils.
|
|
6135
|
+
const scaCoins = await builder.utils.selectCoins(
|
|
5790
6136
|
scaAmount,
|
|
5791
6137
|
SCA_COIN_TYPE,
|
|
5792
6138
|
sender
|
|
@@ -6170,7 +6516,7 @@ var generateReferralQuickMethod = ({
|
|
|
6170
6516
|
Infinity,
|
|
6171
6517
|
builder.utils.parseCoinType(coinName)
|
|
6172
6518
|
);
|
|
6173
|
-
txBlock.mergeCoins(rewardCoin, coins);
|
|
6519
|
+
txBlock.mergeCoins(rewardCoin, coins.slice(0, 500));
|
|
6174
6520
|
} catch (e) {
|
|
6175
6521
|
} finally {
|
|
6176
6522
|
objToTransfer.push(rewardCoin);
|
|
@@ -6288,6 +6634,95 @@ var newLoyaltyProgramTxBlock = (builder, initTxBlock) => {
|
|
|
6288
6634
|
});
|
|
6289
6635
|
};
|
|
6290
6636
|
|
|
6637
|
+
// src/builders/sCoinBuilder.ts
|
|
6638
|
+
var import_sui_kit11 = require("@scallop-io/sui-kit");
|
|
6639
|
+
var generateSCoinNormalMethod = ({
|
|
6640
|
+
builder,
|
|
6641
|
+
txBlock
|
|
6642
|
+
}) => {
|
|
6643
|
+
const sCoinPkgIds = {
|
|
6644
|
+
pkgId: builder.address.get("scoin.id")
|
|
6645
|
+
};
|
|
6646
|
+
return {
|
|
6647
|
+
mintSCoin: (marketCoinName, marketCoin) => {
|
|
6648
|
+
return txBlock.moveCall(
|
|
6649
|
+
`${sCoinPkgIds.pkgId}::s_coin_converter::mint_s_coin`,
|
|
6650
|
+
[builder.utils.getSCoinTreasury(marketCoinName), marketCoin],
|
|
6651
|
+
[
|
|
6652
|
+
builder.utils.parseSCoinType(marketCoinName),
|
|
6653
|
+
builder.utils.parseUnderlyingSCoinType(marketCoinName)
|
|
6654
|
+
]
|
|
6655
|
+
);
|
|
6656
|
+
},
|
|
6657
|
+
burnSCoin: (sCoinName, sCoin) => {
|
|
6658
|
+
return txBlock.moveCall(
|
|
6659
|
+
`${sCoinPkgIds.pkgId}::s_coin_converter::burn_s_coin`,
|
|
6660
|
+
[builder.utils.getSCoinTreasury(sCoinName), sCoin],
|
|
6661
|
+
[
|
|
6662
|
+
builder.utils.parseSCoinType(sCoinName),
|
|
6663
|
+
builder.utils.parseUnderlyingSCoinType(sCoinName)
|
|
6664
|
+
]
|
|
6665
|
+
);
|
|
6666
|
+
}
|
|
6667
|
+
};
|
|
6668
|
+
};
|
|
6669
|
+
var generateSCoinQuickMethod = ({
|
|
6670
|
+
builder,
|
|
6671
|
+
txBlock
|
|
6672
|
+
}) => {
|
|
6673
|
+
return {
|
|
6674
|
+
mintSCoinQuick: async (marketCoinName, amount) => {
|
|
6675
|
+
const sender = requireSender(txBlock);
|
|
6676
|
+
const { leftCoin, takeCoin } = await builder.selectMarketCoin(
|
|
6677
|
+
txBlock,
|
|
6678
|
+
marketCoinName,
|
|
6679
|
+
amount,
|
|
6680
|
+
sender
|
|
6681
|
+
);
|
|
6682
|
+
txBlock.transferObjects([leftCoin], sender);
|
|
6683
|
+
return txBlock.mintSCoin(marketCoinName, takeCoin);
|
|
6684
|
+
},
|
|
6685
|
+
burnSCoinQuick: async (sCoinName, amount) => {
|
|
6686
|
+
const sender = requireSender(txBlock);
|
|
6687
|
+
const { leftCoin, takeCoin } = await builder.selectSCoin(
|
|
6688
|
+
txBlock,
|
|
6689
|
+
sCoinName,
|
|
6690
|
+
amount,
|
|
6691
|
+
sender
|
|
6692
|
+
);
|
|
6693
|
+
txBlock.transferObjects([leftCoin], sender);
|
|
6694
|
+
return txBlock.burnSCoin(sCoinName, takeCoin);
|
|
6695
|
+
}
|
|
6696
|
+
};
|
|
6697
|
+
};
|
|
6698
|
+
var newSCoinTxBlock = (builder, initTxBlock) => {
|
|
6699
|
+
const txBlock = initTxBlock instanceof import_sui_kit11.TransactionBlock ? new import_sui_kit11.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit11.SuiTxBlock();
|
|
6700
|
+
const normalMethod = generateSCoinNormalMethod({
|
|
6701
|
+
builder,
|
|
6702
|
+
txBlock
|
|
6703
|
+
});
|
|
6704
|
+
const normalTxBlock = new Proxy(txBlock, {
|
|
6705
|
+
get: (target, prop) => {
|
|
6706
|
+
if (prop in normalMethod) {
|
|
6707
|
+
return Reflect.get(normalMethod, prop);
|
|
6708
|
+
}
|
|
6709
|
+
return Reflect.get(target, prop);
|
|
6710
|
+
}
|
|
6711
|
+
});
|
|
6712
|
+
const quickMethod = generateSCoinQuickMethod({
|
|
6713
|
+
builder,
|
|
6714
|
+
txBlock: normalTxBlock
|
|
6715
|
+
});
|
|
6716
|
+
return new Proxy(normalTxBlock, {
|
|
6717
|
+
get: (target, prop) => {
|
|
6718
|
+
if (prop in quickMethod) {
|
|
6719
|
+
return Reflect.get(quickMethod, prop);
|
|
6720
|
+
}
|
|
6721
|
+
return Reflect.get(target, prop);
|
|
6722
|
+
}
|
|
6723
|
+
});
|
|
6724
|
+
};
|
|
6725
|
+
|
|
6291
6726
|
// src/builders/index.ts
|
|
6292
6727
|
var newScallopTxBlock = (builder, initTxBlock) => {
|
|
6293
6728
|
const vescaTxBlock = newVeScaTxBlock(builder, initTxBlock);
|
|
@@ -6298,7 +6733,8 @@ var newScallopTxBlock = (builder, initTxBlock) => {
|
|
|
6298
6733
|
);
|
|
6299
6734
|
const referralTxBlock = newReferralTxBlock(builder, borrowIncentiveTxBlock);
|
|
6300
6735
|
const spoolTxBlock = newSpoolTxBlock(builder, referralTxBlock);
|
|
6301
|
-
const
|
|
6736
|
+
const sCoinTxBlock = newSCoinTxBlock(builder, spoolTxBlock);
|
|
6737
|
+
const coreTxBlock = newCoreTxBlock(builder, sCoinTxBlock);
|
|
6302
6738
|
return new Proxy(coreTxBlock, {
|
|
6303
6739
|
get: (target, prop) => {
|
|
6304
6740
|
if (prop in vescaTxBlock) {
|
|
@@ -6311,6 +6747,8 @@ var newScallopTxBlock = (builder, initTxBlock) => {
|
|
|
6311
6747
|
return Reflect.get(spoolTxBlock, prop);
|
|
6312
6748
|
} else if (prop in loyaltyTxBlock) {
|
|
6313
6749
|
return Reflect.get(loyaltyTxBlock, prop);
|
|
6750
|
+
} else if (prop in sCoinTxBlock) {
|
|
6751
|
+
return Reflect.get(sCoinTxBlock, prop);
|
|
6314
6752
|
}
|
|
6315
6753
|
return Reflect.get(target, prop);
|
|
6316
6754
|
}
|
|
@@ -6321,7 +6759,7 @@ var newScallopTxBlock = (builder, initTxBlock) => {
|
|
|
6321
6759
|
var ScallopBuilder = class {
|
|
6322
6760
|
constructor(params, instance) {
|
|
6323
6761
|
this.params = params;
|
|
6324
|
-
this.suiKit = instance?.suiKit ?? new
|
|
6762
|
+
this.suiKit = instance?.suiKit ?? new import_sui_kit12.SuiKit(params);
|
|
6325
6763
|
this.cache = instance?.cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS, this.suiKit);
|
|
6326
6764
|
this.address = instance?.address ?? new ScallopAddress(
|
|
6327
6765
|
{
|
|
@@ -6341,7 +6779,7 @@ var ScallopBuilder = class {
|
|
|
6341
6779
|
query: this.query,
|
|
6342
6780
|
cache: this.cache
|
|
6343
6781
|
});
|
|
6344
|
-
this.walletAddress = (0,
|
|
6782
|
+
this.walletAddress = (0, import_utils22.normalizeSuiAddress)(
|
|
6345
6783
|
params?.walletAddress || this.suiKit.currentAddress()
|
|
6346
6784
|
);
|
|
6347
6785
|
this.isTestnet = params.networkType ? params.networkType === "testnet" : false;
|
|
@@ -6381,7 +6819,7 @@ var ScallopBuilder = class {
|
|
|
6381
6819
|
*/
|
|
6382
6820
|
async selectCoin(txBlock, assetCoinName, amount, sender) {
|
|
6383
6821
|
const coinType = this.utils.parseCoinType(assetCoinName);
|
|
6384
|
-
const coins = await this.utils.
|
|
6822
|
+
const coins = await this.utils.selectCoins(amount, coinType, sender);
|
|
6385
6823
|
const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(coins, amount);
|
|
6386
6824
|
return { takeCoin, leftCoin };
|
|
6387
6825
|
}
|
|
@@ -6396,13 +6834,42 @@ var ScallopBuilder = class {
|
|
|
6396
6834
|
*/
|
|
6397
6835
|
async selectMarketCoin(txBlock, marketCoinName, amount, sender) {
|
|
6398
6836
|
const marketCoinType = this.utils.parseMarketCoinType(marketCoinName);
|
|
6399
|
-
const coins = await this.utils.
|
|
6400
|
-
|
|
6401
|
-
|
|
6402
|
-
|
|
6837
|
+
const coins = await this.utils.selectCoins(amount, marketCoinType, sender);
|
|
6838
|
+
const totalAmount = coins.reduce((prev, coin) => {
|
|
6839
|
+
prev += Number(coin.balance);
|
|
6840
|
+
return prev;
|
|
6841
|
+
}, 0);
|
|
6842
|
+
const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(
|
|
6843
|
+
coins,
|
|
6844
|
+
Math.min(amount, totalAmount)
|
|
6403
6845
|
);
|
|
6404
|
-
|
|
6405
|
-
|
|
6846
|
+
return { takeCoin, leftCoin, totalAmount };
|
|
6847
|
+
}
|
|
6848
|
+
/**
|
|
6849
|
+
* Specifying the sender's amount of sCoins to get coins args from transaction result.
|
|
6850
|
+
*
|
|
6851
|
+
* @param txBlock - Scallop txBlock or txBlock created by SuiKit .
|
|
6852
|
+
* @param marketCoinName - Specific support sCoin name.
|
|
6853
|
+
* @param amount - Amount of coins to be selected.
|
|
6854
|
+
* @param sender - Sender address.
|
|
6855
|
+
* @return Take coin and left coin.
|
|
6856
|
+
*/
|
|
6857
|
+
async selectSCoin(txBlock, sCoinName, amount, sender) {
|
|
6858
|
+
const sCoinType = this.utils.parseSCoinType(sCoinName);
|
|
6859
|
+
const coins = await this.utils.selectCoins(amount, sCoinType, sender);
|
|
6860
|
+
const totalAmount = coins.reduce((prev, coin) => {
|
|
6861
|
+
prev += Number(coin.balance);
|
|
6862
|
+
return prev;
|
|
6863
|
+
}, 0);
|
|
6864
|
+
const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(
|
|
6865
|
+
coins,
|
|
6866
|
+
Math.min(totalAmount, amount)
|
|
6867
|
+
);
|
|
6868
|
+
return {
|
|
6869
|
+
takeCoin,
|
|
6870
|
+
leftCoin,
|
|
6871
|
+
totalAmount
|
|
6872
|
+
};
|
|
6406
6873
|
}
|
|
6407
6874
|
/**
|
|
6408
6875
|
* Execute Scallop txBlock using the `signAndSendTxn` methods in suikit.
|
|
@@ -6420,7 +6887,7 @@ var ScallopBuilder = class {
|
|
|
6420
6887
|
var ScallopClient = class {
|
|
6421
6888
|
constructor(params, instance) {
|
|
6422
6889
|
this.params = params;
|
|
6423
|
-
this.suiKit = instance?.suiKit ?? new
|
|
6890
|
+
this.suiKit = instance?.suiKit ?? new import_sui_kit13.SuiKit(params);
|
|
6424
6891
|
this.cache = instance?.cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS, this.suiKit);
|
|
6425
6892
|
this.address = instance?.address ?? new ScallopAddress(
|
|
6426
6893
|
{
|
|
@@ -6447,7 +6914,7 @@ var ScallopClient = class {
|
|
|
6447
6914
|
utils: this.utils,
|
|
6448
6915
|
cache: this.cache
|
|
6449
6916
|
});
|
|
6450
|
-
this.walletAddress = (0,
|
|
6917
|
+
this.walletAddress = (0, import_utils23.normalizeSuiAddress)(
|
|
6451
6918
|
params?.walletAddress || this.suiKit.currentAddress()
|
|
6452
6919
|
);
|
|
6453
6920
|
}
|
|
@@ -6927,6 +7394,98 @@ var ScallopClient = class {
|
|
|
6927
7394
|
return txBlock.txBlock;
|
|
6928
7395
|
}
|
|
6929
7396
|
}
|
|
7397
|
+
/* ==================== Migrate market coin to sCoin method ==================== */
|
|
7398
|
+
/**
|
|
7399
|
+
* Function to migrate all market coin in user wallet into sCoin
|
|
7400
|
+
* @returns Transaction response
|
|
7401
|
+
*/
|
|
7402
|
+
async migrateAllMarketCoin(sign = true) {
|
|
7403
|
+
const txBlock = this.builder.createTxBlock();
|
|
7404
|
+
txBlock.setSender(this.walletAddress);
|
|
7405
|
+
const toTransfer = [];
|
|
7406
|
+
await Promise.all(
|
|
7407
|
+
SUPPORT_SCOIN.map(async (sCoinName) => {
|
|
7408
|
+
let toDestroyMarketCoin;
|
|
7409
|
+
try {
|
|
7410
|
+
const marketCoins2 = await this.utils.selectCoins(
|
|
7411
|
+
Number.MAX_SAFE_INTEGER,
|
|
7412
|
+
this.utils.parseMarketCoinType(sCoinName),
|
|
7413
|
+
this.walletAddress
|
|
7414
|
+
);
|
|
7415
|
+
const mergedMarketCoin = marketCoins2[0];
|
|
7416
|
+
if (marketCoins2.length > 1) {
|
|
7417
|
+
txBlock.mergeCoins(mergedMarketCoin, marketCoins2.slice(1));
|
|
7418
|
+
}
|
|
7419
|
+
toDestroyMarketCoin = mergedMarketCoin;
|
|
7420
|
+
} catch (e) {
|
|
7421
|
+
const errMsg = e.toString();
|
|
7422
|
+
if (!errMsg.includes("No valid coins found for the transaction"))
|
|
7423
|
+
throw e;
|
|
7424
|
+
}
|
|
7425
|
+
if (SUPPORT_SPOOLS.includes(sCoinName)) {
|
|
7426
|
+
try {
|
|
7427
|
+
const stakedMarketCoins = await txBlock.unstakeQuick(
|
|
7428
|
+
Number.MAX_SAFE_INTEGER,
|
|
7429
|
+
sCoinName
|
|
7430
|
+
);
|
|
7431
|
+
if (stakedMarketCoins.length > 0) {
|
|
7432
|
+
const mergedStakedMarketCoin = stakedMarketCoins[0];
|
|
7433
|
+
if (stakedMarketCoins.length > 1) {
|
|
7434
|
+
txBlock.mergeCoins(
|
|
7435
|
+
mergedStakedMarketCoin,
|
|
7436
|
+
stakedMarketCoins.slice(1)
|
|
7437
|
+
);
|
|
7438
|
+
}
|
|
7439
|
+
if (toDestroyMarketCoin) {
|
|
7440
|
+
txBlock.mergeCoins(toDestroyMarketCoin, [
|
|
7441
|
+
mergedStakedMarketCoin
|
|
7442
|
+
]);
|
|
7443
|
+
} else {
|
|
7444
|
+
toDestroyMarketCoin = mergedStakedMarketCoin;
|
|
7445
|
+
}
|
|
7446
|
+
}
|
|
7447
|
+
} catch (e) {
|
|
7448
|
+
const errMsg = e.toString();
|
|
7449
|
+
if (!errMsg.includes("No stake account found"))
|
|
7450
|
+
throw e;
|
|
7451
|
+
}
|
|
7452
|
+
}
|
|
7453
|
+
if (toDestroyMarketCoin) {
|
|
7454
|
+
const sCoin = txBlock.mintSCoin(
|
|
7455
|
+
sCoinName,
|
|
7456
|
+
toDestroyMarketCoin
|
|
7457
|
+
);
|
|
7458
|
+
try {
|
|
7459
|
+
const existSCoins = await this.utils.selectCoins(
|
|
7460
|
+
Number.MAX_SAFE_INTEGER,
|
|
7461
|
+
this.utils.parseSCoinType(sCoinName),
|
|
7462
|
+
this.walletAddress
|
|
7463
|
+
);
|
|
7464
|
+
const mergedSCoin = existSCoins[0];
|
|
7465
|
+
if (existSCoins.length > 1) {
|
|
7466
|
+
txBlock.mergeCoins(mergedSCoin, existSCoins.slice(1));
|
|
7467
|
+
}
|
|
7468
|
+
txBlock.mergeCoins(sCoin, [mergedSCoin]);
|
|
7469
|
+
} catch (e) {
|
|
7470
|
+
const errMsg = e.toString();
|
|
7471
|
+
if (!errMsg.includes("No valid coins found for the transaction"))
|
|
7472
|
+
throw e;
|
|
7473
|
+
}
|
|
7474
|
+
toTransfer.push(sCoin);
|
|
7475
|
+
}
|
|
7476
|
+
})
|
|
7477
|
+
);
|
|
7478
|
+
if (toTransfer.length > 0) {
|
|
7479
|
+
txBlock.transferObjects(toTransfer, this.walletAddress);
|
|
7480
|
+
}
|
|
7481
|
+
if (sign) {
|
|
7482
|
+
return await this.suiKit.signAndSendTxn(
|
|
7483
|
+
txBlock
|
|
7484
|
+
);
|
|
7485
|
+
} else {
|
|
7486
|
+
return txBlock.txBlock;
|
|
7487
|
+
}
|
|
7488
|
+
}
|
|
6930
7489
|
async mintTestCoin(assetCoinName, amount, sign = true, receiveAddress) {
|
|
6931
7490
|
const isTestnet = this.params.networkType ? this.params.networkType === "testnet" : false;
|
|
6932
7491
|
if (!isTestnet) {
|
|
@@ -6953,7 +7512,7 @@ var ScallopClient = class {
|
|
|
6953
7512
|
var Scallop = class {
|
|
6954
7513
|
constructor(params, cacheOptions) {
|
|
6955
7514
|
this.params = params;
|
|
6956
|
-
this.suiKit = new
|
|
7515
|
+
this.suiKit = new import_sui_kit14.SuiKit(params);
|
|
6957
7516
|
this.cache = new ScallopCache(
|
|
6958
7517
|
cacheOptions ?? DEFAULT_CACHE_OPTIONS,
|
|
6959
7518
|
this.suiKit
|
|
@@ -7069,6 +7628,7 @@ var Scallop = class {
|
|
|
7069
7628
|
SUPPORT_ORACLES,
|
|
7070
7629
|
SUPPORT_PACKAGES,
|
|
7071
7630
|
SUPPORT_POOLS,
|
|
7631
|
+
SUPPORT_SCOIN,
|
|
7072
7632
|
SUPPORT_SPOOLS,
|
|
7073
7633
|
SUPPORT_SPOOLS_REWARDS,
|
|
7074
7634
|
Scallop,
|
|
@@ -7080,11 +7640,14 @@ var Scallop = class {
|
|
|
7080
7640
|
ScallopQuery,
|
|
7081
7641
|
ScallopUtils,
|
|
7082
7642
|
UNLOCK_ROUND_DURATION,
|
|
7643
|
+
USE_TEST_ADDRESS,
|
|
7083
7644
|
assetCoins,
|
|
7084
7645
|
borrowIncentiveRewardCoins,
|
|
7085
7646
|
coinDecimals,
|
|
7086
7647
|
coinIds,
|
|
7087
7648
|
marketCoins,
|
|
7649
|
+
sCoinIds,
|
|
7650
|
+
sCoins,
|
|
7088
7651
|
spoolRewardCoins,
|
|
7089
7652
|
stakeMarketCoins,
|
|
7090
7653
|
voloCoinIds,
|