@scallop-io/sui-scallop-sdk 0.46.39 → 0.46.41
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/constants/flashloan.d.ts +2 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/index.js +742 -97
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +739 -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 +24 -1
- package/dist/models/scallopUtils.d.ts +32 -2
- package/dist/queries/coreQuery.d.ts +7 -0
- 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/flashloan.ts +18 -0
- package/src/constants/index.ts +1 -0
- 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 +57 -1
- package/src/models/scallopUtils.ts +56 -2
- package/src/queries/coreQuery.ts +102 -4
- package/src/queries/portfolioQuery.ts +25 -3
- 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.mjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
// src/constants/common.ts
|
|
2
|
-
var API_BASE_URL = "https://sui.
|
|
2
|
+
var API_BASE_URL = "https://sui.apis.scallop.io";
|
|
3
3
|
var SDK_API_BASE_URL = "https://sdk.api.scallop.io";
|
|
4
4
|
var IS_VE_SCA_TEST = false;
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
"65fb07c39c845425d71d7b18"
|
|
8
|
-
) : "664dfe22898c36c159e28bc8";
|
|
5
|
+
var USE_TEST_ADDRESS = false;
|
|
6
|
+
var ADDRESSES_ID = IS_VE_SCA_TEST || USE_TEST_ADDRESS ? "65fb07c39c845425d71d7b18" : "664dfe22898c36c159e28bc8";
|
|
9
7
|
var PROTOCOL_OBJECT_ID = IS_VE_SCA_TEST ? "0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778" : "0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf";
|
|
10
8
|
var BORROW_FEE_PROTOCOL_ID = IS_VE_SCA_TEST ? "0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778" : "0xc38f849e81cfe46d4e4320f508ea7dda42934a329d5a6571bb4c3cb6ea63f5da";
|
|
11
9
|
var SCA_COIN_TYPE = IS_VE_SCA_TEST ? `0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524::sca::SCA` : "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA";
|
|
@@ -48,6 +46,17 @@ var SUPPORT_SPOOLS = [
|
|
|
48
46
|
"shasui",
|
|
49
47
|
"svsui"
|
|
50
48
|
];
|
|
49
|
+
var SUPPORT_SCOIN = [
|
|
50
|
+
"ssui",
|
|
51
|
+
"susdc",
|
|
52
|
+
"susdt",
|
|
53
|
+
"safsui",
|
|
54
|
+
"shasui",
|
|
55
|
+
"svsui",
|
|
56
|
+
"seth",
|
|
57
|
+
"ssca",
|
|
58
|
+
"scetus"
|
|
59
|
+
];
|
|
51
60
|
var SUPPORT_SPOOLS_REWARDS = ["sui"];
|
|
52
61
|
var SUPPORT_BORROW_INCENTIVE_POOLS = [
|
|
53
62
|
"sui",
|
|
@@ -131,6 +140,17 @@ var marketCoins = {
|
|
|
131
140
|
svsui: "svsui",
|
|
132
141
|
ssca: "ssca"
|
|
133
142
|
};
|
|
143
|
+
var sCoins = {
|
|
144
|
+
seth: "seth",
|
|
145
|
+
susdc: "susdc",
|
|
146
|
+
susdt: "susdt",
|
|
147
|
+
ssui: "ssui",
|
|
148
|
+
scetus: "scetus",
|
|
149
|
+
safsui: "safsui",
|
|
150
|
+
shasui: "shasui",
|
|
151
|
+
svsui: "svsui",
|
|
152
|
+
ssca: "ssca"
|
|
153
|
+
};
|
|
134
154
|
var stakeMarketCoins = {
|
|
135
155
|
seth: "seth",
|
|
136
156
|
ssui: "ssui",
|
|
@@ -186,6 +206,17 @@ var wormholeCoinIds = {
|
|
|
186
206
|
var voloCoinIds = {
|
|
187
207
|
vsui: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55"
|
|
188
208
|
};
|
|
209
|
+
var sCoinIds = {
|
|
210
|
+
ssui: "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI",
|
|
211
|
+
scetus: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
|
|
212
|
+
ssca: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
|
|
213
|
+
susdc: "0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
214
|
+
susdt: "0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
|
|
215
|
+
seth: "0x67540ceb850d418679e69f1fb6b2093d6df78a2a699ffc733f7646096d552e9b::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
|
|
216
|
+
safsui: "0x00671b1fa2a124f5be8bdae8b91ee711462c5d9e31bda232e70fd9607b523c88::scallop_af_sui::SCALLOP_AF_SUI",
|
|
217
|
+
shasui: "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI",
|
|
218
|
+
svsui: "0xe1a1cc6bcf0001a015eab84bcc6713393ce20535f55b8b6f35c142e057a25fbe::scallop_v_sui::SCALLOP_V_SUI"
|
|
219
|
+
};
|
|
189
220
|
|
|
190
221
|
// src/constants/vesca.ts
|
|
191
222
|
var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
|
|
@@ -194,12 +225,32 @@ var MAX_LOCK_DURATION = MAX_LOCK_ROUNDS * UNLOCK_ROUND_DURATION;
|
|
|
194
225
|
var MIN_INITIAL_LOCK_AMOUNT = 1e10;
|
|
195
226
|
var MIN_TOP_UP_AMOUNT = 1e9;
|
|
196
227
|
|
|
228
|
+
// src/constants/flashloan.ts
|
|
229
|
+
var FlashLoanFeeObjectMap = {
|
|
230
|
+
vsui: "0x0069cddee7a5c0b1d34beb5ef0620f978096525f1830b055f38b110f40d73fbb",
|
|
231
|
+
btc: "0x2078490aa37d8fb42b511e5c95e217cb957d141267e16980bc802d76b42719f7",
|
|
232
|
+
sui: "0x27614284a8f0a699ffd35aae8f2572c937ec76771cb21b0d7930ec4491a76ed4",
|
|
233
|
+
usdt: "0x5b61983a19b5159ca348d291e4b595f42db70ccda32852a2ed85528aa65171e4",
|
|
234
|
+
apt: "0x9d5898edcd1e4abcb044273242293a9d036f6a977bf3fe57ab71f5a87c505ee6",
|
|
235
|
+
afsui: "0xac87fde83d434554ec300c1334c9a622aa5b59e82a04334dc99e1cc1f75d4eae",
|
|
236
|
+
hasui: "0xb9f505d532de1d6c9f3a8522a2d16f2958b75c0ed939d4f80b96f584a2a8ed5e",
|
|
237
|
+
usdc: "0xd241d6a7e44ac11a6689370ed9a98eec389b98b8a6695c61fddede9fa7567b90",
|
|
238
|
+
eth: "0xd252acb058e77877810c1290564e290a8f9fcab5bc9aca2884ede8a38810cf34",
|
|
239
|
+
sca: "0xe04e46471754b6f48d81c549ecfec09de02733715a63bec02364c6ac7c4dd2dc",
|
|
240
|
+
cetus: "0xe65a73d11c31b2d323ad2b9f6b4bb0a3c0df9c1b212eef66c854941186a5ddc7",
|
|
241
|
+
sol: "0xe84bdb35b790fc7bdd1645122ac6ac0fc904531d6772c9e25904fece322c5f34"
|
|
242
|
+
};
|
|
243
|
+
|
|
197
244
|
// src/models/scallop.ts
|
|
198
245
|
import { SuiKit as SuiKit5 } from "@scallop-io/sui-kit";
|
|
199
246
|
|
|
200
247
|
// src/models/scallopCache.ts
|
|
201
248
|
import { QueryClient } from "@tanstack/query-core";
|
|
202
|
-
import {
|
|
249
|
+
import {
|
|
250
|
+
SuiTxBlock,
|
|
251
|
+
normalizeStructTag,
|
|
252
|
+
normalizeSuiAddress
|
|
253
|
+
} from "@scallop-io/sui-kit";
|
|
203
254
|
|
|
204
255
|
// src/constants/cache.ts
|
|
205
256
|
var DEFAULT_CACHE_OPTIONS = {
|
|
@@ -315,6 +366,8 @@ var ScallopCache = class {
|
|
|
315
366
|
* @returns Promise<SuiObjectData[]>
|
|
316
367
|
*/
|
|
317
368
|
async queryGetObjects(objectIds, options) {
|
|
369
|
+
if (objectIds.length === 0)
|
|
370
|
+
return [];
|
|
318
371
|
const queryKey = [
|
|
319
372
|
"getObjects",
|
|
320
373
|
JSON.stringify(objectIds),
|
|
@@ -391,7 +444,7 @@ var ScallopCache = class {
|
|
|
391
444
|
queryKey,
|
|
392
445
|
queryFn: async () => {
|
|
393
446
|
const allBalances = await this.suiKit.client().getAllBalances({ owner });
|
|
394
|
-
|
|
447
|
+
const balances = allBalances.reduce(
|
|
395
448
|
(acc, coinBalance) => {
|
|
396
449
|
if (coinBalance.totalBalance !== "0") {
|
|
397
450
|
acc[normalizeStructTag(coinBalance.coinType)] = coinBalance.totalBalance;
|
|
@@ -400,11 +453,30 @@ var ScallopCache = class {
|
|
|
400
453
|
},
|
|
401
454
|
{}
|
|
402
455
|
);
|
|
403
|
-
|
|
456
|
+
for (const coinType in balances) {
|
|
457
|
+
const coinBalanceQueryKey = [
|
|
458
|
+
"getCoinBalance",
|
|
459
|
+
normalizeSuiAddress(owner),
|
|
460
|
+
normalizeStructTag(coinType)
|
|
461
|
+
];
|
|
462
|
+
this.queryClient.setQueryData(
|
|
463
|
+
coinBalanceQueryKey,
|
|
464
|
+
balances[coinType]
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
return balances;
|
|
468
|
+
},
|
|
469
|
+
staleTime: 5e3
|
|
404
470
|
});
|
|
405
471
|
}
|
|
406
472
|
async queryGetCoinBalance(input) {
|
|
407
|
-
|
|
473
|
+
if (!input.coinType)
|
|
474
|
+
return "0";
|
|
475
|
+
const queryKey = [
|
|
476
|
+
"getCoinBalance",
|
|
477
|
+
normalizeSuiAddress(input.owner),
|
|
478
|
+
normalizeStructTag(input.coinType)
|
|
479
|
+
];
|
|
408
480
|
return this.queryClient.fetchQuery({
|
|
409
481
|
queryKey,
|
|
410
482
|
queryFn: async () => {
|
|
@@ -422,13 +494,21 @@ import axios from "axios";
|
|
|
422
494
|
// src/constants/testAddress.ts
|
|
423
495
|
var TEST_ADDRESSES = {
|
|
424
496
|
core: {
|
|
425
|
-
version:
|
|
497
|
+
// version:
|
|
498
|
+
// '0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7',
|
|
499
|
+
version: "0x6156d5cd1538bec8a167a40fe1209a4ec9cf8137921fe0a697f191ac561f0b09",
|
|
426
500
|
versionCap: "0x590a4011cb649b3878f3ea14b3a78674642a9548d79b7e091ef679574b158a07",
|
|
427
|
-
object:
|
|
428
|
-
|
|
501
|
+
// object:
|
|
502
|
+
// '0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf',
|
|
503
|
+
object: "0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1",
|
|
504
|
+
// market:
|
|
505
|
+
// '0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9',
|
|
506
|
+
market: "0x8606ed145cc887985b8ed793f7753ff5dc762a42c379dac035f568e1bac58490",
|
|
429
507
|
adminCap: "0x09689d018e71c337d9db6d67cbca06b74ed92196103624028ccc3ecea411777c",
|
|
430
508
|
coinDecimalsRegistry: "0x200abe9bf19751cc566ae35aa58e2b7e4ff688fc1130f8d8909ea09bc137d668",
|
|
431
|
-
obligationAccessStore:
|
|
509
|
+
// obligationAccessStore:
|
|
510
|
+
// '0x733e30b7c94d619d78cb8f5bc4bfbb759ced9a531239028caabb2474e5be59c9',
|
|
511
|
+
obligationAccessStore: "0x48b472d68ca910c45f7f3b6c26836b6aa6d2569810d94b1b939023da05ae0a23",
|
|
432
512
|
coins: {
|
|
433
513
|
cetus: {
|
|
434
514
|
id: "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b",
|
|
@@ -618,15 +698,25 @@ var TEST_ADDRESSES = {
|
|
|
618
698
|
upgradeCap: "0x3f203f6fff6a69d151e4f1cd931f22b68c489ef2759765662fc7baf673943c9e"
|
|
619
699
|
},
|
|
620
700
|
protocol: {
|
|
621
|
-
id: "
|
|
701
|
+
id: "0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1",
|
|
622
702
|
upgradeCap: "0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a"
|
|
623
703
|
},
|
|
704
|
+
// protocol: {
|
|
705
|
+
// id: '0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e',
|
|
706
|
+
// upgradeCap:
|
|
707
|
+
// '0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a',
|
|
708
|
+
// },
|
|
624
709
|
protocolWhitelist: {
|
|
625
710
|
id: "0x4c262d9343dac53ecb28f482a2a3f62c73d0ebac5b5f03d57383d56ff219acdf",
|
|
626
711
|
upgradeCap: "0x4a5e88a75039b00988f633f811f58117f31b8627a46bf822aa114d9010049449"
|
|
627
712
|
},
|
|
713
|
+
// query: {
|
|
714
|
+
// id: '0xb8d603a39114a5efef3dd0bf84df0bed1be1fbd39b78b7dd6e8a61ccc5e6006f',
|
|
715
|
+
// upgradeCap:
|
|
716
|
+
// '0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f',
|
|
717
|
+
// },
|
|
628
718
|
query: {
|
|
629
|
-
id: "
|
|
719
|
+
id: "0xe4f9d62d17746d5b9dbf0d5557747430021a71575780b515161210cdba0a4c1c",
|
|
630
720
|
upgradeCap: "0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f"
|
|
631
721
|
},
|
|
632
722
|
supra: { id: "", upgradeCap: "" },
|
|
@@ -643,41 +733,68 @@ var TEST_ADDRESSES = {
|
|
|
643
733
|
}
|
|
644
734
|
},
|
|
645
735
|
spool: {
|
|
646
|
-
id:
|
|
736
|
+
// id: '0x7c4fdabe81c31b19a45d1e572a52a539997a90903fbb5bfab71480abe0fa62c3',
|
|
737
|
+
id: "0x1742655fe5872dfa6456673f9e38612a4965e6979e6cd7696a7f1225f28bae21",
|
|
647
738
|
adminCap: "0xdd8a047cbbf802bfcde5288b8ef1910965d789cc614da11d39af05fca0bd020a",
|
|
648
|
-
object:
|
|
739
|
+
// object:
|
|
740
|
+
// '0xe87f1b2d498106a2c61421cec75b7b5c5e348512b0dc263949a0e7a3c256571a',
|
|
741
|
+
object: "0x1742655fe5872dfa6456673f9e38612a4965e6979e6cd7696a7f1225f28bae21",
|
|
649
742
|
pools: {
|
|
650
743
|
seth: {
|
|
651
744
|
id: "0xeec40beccb07c575bebd842eeaabb835f77cd3dab73add433477e57f583a6787",
|
|
652
745
|
rewardPoolId: "0x957de68a18d87817de8309b30c1ec269a4d87ae513abbeed86b5619cb9ce1077"
|
|
653
746
|
},
|
|
654
747
|
ssui: {
|
|
655
|
-
id:
|
|
656
|
-
|
|
748
|
+
// id: '0x4f0ba970d3c11db05c8f40c64a15b6a33322db3702d634ced6536960ab6f3ee4',
|
|
749
|
+
id: "0xb9617f83c06ebdeac0a8834782b1015e1cc7ea23739e30c132c4bfb95c37a579",
|
|
750
|
+
rewardPoolId: (
|
|
751
|
+
// '0x162250ef72393a4ad3d46294c4e1bdfcb03f04c869d390e7efbfc995353a7ee9',
|
|
752
|
+
"0xc3206071a8d43212efb6e3b5504f2321f8df97ab122b466c0bc7cfdf398dc13a"
|
|
753
|
+
)
|
|
657
754
|
},
|
|
658
755
|
susdc: {
|
|
659
|
-
id:
|
|
660
|
-
|
|
756
|
+
// id: '0x4ace6648ddc64e646ba47a957c562c32c9599b3bba8f5ac1aadb2ae23a2f8ca0',
|
|
757
|
+
id: "0xf1b383b9cf2e9f515fc69567df1053098f273849d09cd84b0278a773429bd2b2",
|
|
758
|
+
rewardPoolId: (
|
|
759
|
+
// '0xf4268cc9b9413b9bfe09e8966b8de650494c9e5784bf0930759cfef4904daff8',
|
|
760
|
+
"0xc71c53ee6505d928ba15bea4fe4f45d98c9c31eced94b72d00a7827d4b7ba3ff"
|
|
761
|
+
)
|
|
661
762
|
},
|
|
662
763
|
susdt: {
|
|
663
|
-
id:
|
|
664
|
-
|
|
764
|
+
// id: '0xcb328f7ffa7f9342ed85af3fdb2f22919e1a06dfb2f713c04c73543870d7548f',
|
|
765
|
+
id: "0xb5567dfa5c7fc17a249e959732664c50713dd8c23db1a11376b27df800c17418",
|
|
766
|
+
rewardPoolId: (
|
|
767
|
+
// '0x2c9f934d67a5baa586ceec2cc24163a2f049a6af3d5ba36b84d8ac40f25c4080',
|
|
768
|
+
"0x60768b0687ff0235e376a039709a683e4c436098785e473b67b32dbab47b69ab"
|
|
769
|
+
)
|
|
665
770
|
},
|
|
666
771
|
scetus: {
|
|
667
772
|
id: "0xac1bb13bf4472a637c18c2415fb0e3c1227ea2bcf35242e50563c98215bd298e",
|
|
668
773
|
rewardPoolId: "0x6835c1224126a45086fc6406adc249e3f30df18d779ca4f4e570e38716a17f3f"
|
|
669
774
|
},
|
|
670
775
|
safsui: {
|
|
671
|
-
id:
|
|
672
|
-
|
|
776
|
+
// id: '0xeedf438abcaa6ce4d9625ffca110920592d5867e4c5637d84ad9f466c4feb800',
|
|
777
|
+
id: "0xc568bb4c991258e839aa54802ecda04fcd9838c826bc3b42b40af81b23c458c8",
|
|
778
|
+
rewardPoolId: (
|
|
779
|
+
// '0x89255a2f86ed7fbfef35ab8b7be48cc7667015975be2685dd9a55a9a64baf76e',
|
|
780
|
+
"0x389a3cbeda742b918941bb24fd00e077bad3367484394d6234f8209b9a6aa03d"
|
|
781
|
+
)
|
|
673
782
|
},
|
|
674
783
|
shasui: {
|
|
675
|
-
id:
|
|
676
|
-
|
|
784
|
+
// id: '0xa6148bc1b623e936d39a952ceb5bea79e8b37228a8f595067bf1852efd3c34aa',
|
|
785
|
+
id: "0x93f3f4499bf89f2d05ddc1f8b15f51701a7c6c4d0ac0b9c3bc99462cbbd8e321",
|
|
786
|
+
rewardPoolId: (
|
|
787
|
+
// '0x6f3563644d3e2ef13176dbf9d865bd93479df60ccbe07b7e66db57f6309f5a66',
|
|
788
|
+
"0x94cee1be7f5ff34193f3aabef0b14142cb28af4d905fe487a9a7d85a15edb6aa"
|
|
789
|
+
)
|
|
677
790
|
},
|
|
678
791
|
svsui: {
|
|
679
|
-
id:
|
|
680
|
-
|
|
792
|
+
// id: '0x69ce8e537e750a95381e6040794afa5ab1758353a1a2e1de7760391b01f91670',
|
|
793
|
+
id: "0xa970e9087f80cb59e9299b8e7af7175d977ad6c9af0322aa4440e138fbd7ae00",
|
|
794
|
+
rewardPoolId: (
|
|
795
|
+
// '0xbca914adce058ad0902c7f3cfcd698392a475f00dcfdc3f76001d0370b98777a',
|
|
796
|
+
"0x38eee9699c4fc132a6623e54b865f047df4fc6eb83af807300f44e8f4b235ff0"
|
|
797
|
+
)
|
|
681
798
|
}
|
|
682
799
|
},
|
|
683
800
|
config: ""
|
|
@@ -701,7 +818,9 @@ var TEST_ADDRESSES = {
|
|
|
701
818
|
revenueTableId: "0x595baa3654c297bff84ab7786a2d250f019cefc66e8df8e89fd9d41e02bd30dd",
|
|
702
819
|
referralTiers: "0x962cb903d8d7346190c5204785ccbb91b61086aa764f674c8145df82335cf83e",
|
|
703
820
|
tiersTableId: "0xeac755a7a8b7798530905ac79e8c114f19d0f130f6eab012954f08faac29c75d",
|
|
704
|
-
authorizedWitnessList:
|
|
821
|
+
// authorizedWitnessList:
|
|
822
|
+
// '0xf21b0ed043c9bb70842c0129159f4943dbcc3c9ef2f2f808af65f8be25cfd20e',
|
|
823
|
+
authorizedWitnessList: "0x9d6223dc52015b8a3986a573590ef2af8f1b8f3e4685513888c052f001b87e7f",
|
|
705
824
|
version: "0x1bd4b7285f72e11c316b828c7c47b3f4da18dcec9f9b3dba6d8629cbb6f93e5e"
|
|
706
825
|
},
|
|
707
826
|
vesca: {
|
|
@@ -718,6 +837,47 @@ var TEST_ADDRESSES = {
|
|
|
718
837
|
object: "0xd17bcf8b5a59652c36225d478564a8593ae0ed7d650bcacdda1d6fe179127907",
|
|
719
838
|
rewardPool: "0xf9c090492ef476bd542109d0913ffe871cbfa28578b7114eca2a8c0e5671786f",
|
|
720
839
|
userRewardTableId: "0x748a80395849ed37db1b0e14f2ab5d1d96458d2359ab3a84eb079d0f4ac7cf2e"
|
|
840
|
+
},
|
|
841
|
+
scoin: {
|
|
842
|
+
id: "0xad2ca2aa5089df94bb2d444d5eb3520378c2f2dfb3a0bd2a2c994145ac4b0a53",
|
|
843
|
+
coins: {
|
|
844
|
+
ssui: {
|
|
845
|
+
coinType: "0xfac769100bccc0caebcf4f4e2d00ac2f8883f07f724be28940df90605f5e7e9a::scallop_sui::SCALLOP_SUI",
|
|
846
|
+
treasury: "0x9cb4551b36c17d37e19d700147fa819ea1c487ff8bcf18374de2cceb2e9d4845"
|
|
847
|
+
},
|
|
848
|
+
scetus: {
|
|
849
|
+
coinType: "0x8b71e6d323ed78515af2bead13bf3d0da1562ba4a99234eb7c4f14fd39ef0427::scallop_cetus::SCALLOP_CETUS",
|
|
850
|
+
treasury: "0xd786f4b2d26278cc7911a3445b1b085eab60f269ef9dbb6b87e803d52f155003"
|
|
851
|
+
},
|
|
852
|
+
ssca: {
|
|
853
|
+
coinType: "0x0a9d3c6c9af9f6e8def82921541bcbd17f73ed31bed3adcb684f2a4c267e42f0::scallop_sca::SCALLOP_SCA",
|
|
854
|
+
treasury: "0xe818636d1d6c46d6ea1a2dce9d94696d7cbc18ce27451b603eeaa47aba8d75e0"
|
|
855
|
+
},
|
|
856
|
+
susdc: {
|
|
857
|
+
coinType: "0xaedc3ab75db8680b81a755015fa90124d217be93457b893c05bac033817defaf::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
858
|
+
treasury: "0xfc6971648f867f7fd6928d1b873af71577e2eaf2c7543ef8bc82c431d833ae78"
|
|
859
|
+
},
|
|
860
|
+
susdt: {
|
|
861
|
+
coinType: "0xbf02fc87ddc104b342ad8414c85ceadf5b0c823c055a06fb0ed776272c01a52a::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
|
|
862
|
+
treasury: "0xb9593e2c3a0ba796ee815012b75ae46468ea78cda0188b9ac6816efe65503521"
|
|
863
|
+
},
|
|
864
|
+
seth: {
|
|
865
|
+
coinType: "0x27d54f43e3eda701be56b82e5756e41c84467cd202f5cf713d5f9e45a9f1b6bc::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
|
|
866
|
+
treasury: "0x032b4c8fac94c038dbe986f7587e9b1e4ef580b5ee06d2ef249d85459b7ef05d"
|
|
867
|
+
},
|
|
868
|
+
safsui: {
|
|
869
|
+
coinType: "0xb75b46d975d8d80670b53a6bee90baaa8ce2e0b7d397f079447d641eef6b44ad::scallop_af_sui::SCALLOP_AF_SUI",
|
|
870
|
+
treasury: "0x21450ef0570ef3d224ffa3b873ab802e439ece7b93cc7efad10ae0c1e3b3fcfe"
|
|
871
|
+
},
|
|
872
|
+
shasui: {
|
|
873
|
+
coinType: "0xd973a723874e2c7cde196602a79155a1343a933f8cf87d9b1bb7408bc1acbc58::scallop_ha_sui::SCALLOP_HA_SUI",
|
|
874
|
+
treasury: "0xf822fc1402207e47d2e3ba8ff6e1e594bf1de777dc5ebd2744619cd2726e3b0d"
|
|
875
|
+
},
|
|
876
|
+
svsui: {
|
|
877
|
+
coinType: "0x97023a317320c4498cc4cd239dd02fd30c28246e5e8f81325d63f2bd8d70f6b3::scallop_v_sui::SCALLOP_V_SUI",
|
|
878
|
+
treasury: "0x327114f0bf3559d7e2de10282147ed76a236c7c6775029165c4db09a6062ead6\u0192"
|
|
879
|
+
}
|
|
880
|
+
}
|
|
721
881
|
}
|
|
722
882
|
};
|
|
723
883
|
|
|
@@ -1020,6 +1180,47 @@ var EMPTY_ADDRESSES = {
|
|
|
1020
1180
|
object: "",
|
|
1021
1181
|
rewardPool: "",
|
|
1022
1182
|
userRewardTableId: ""
|
|
1183
|
+
},
|
|
1184
|
+
scoin: {
|
|
1185
|
+
id: "",
|
|
1186
|
+
coins: {
|
|
1187
|
+
ssui: {
|
|
1188
|
+
coinType: "",
|
|
1189
|
+
treasury: ""
|
|
1190
|
+
},
|
|
1191
|
+
scetus: {
|
|
1192
|
+
coinType: "",
|
|
1193
|
+
treasury: ""
|
|
1194
|
+
},
|
|
1195
|
+
ssca: {
|
|
1196
|
+
coinType: "",
|
|
1197
|
+
treasury: ""
|
|
1198
|
+
},
|
|
1199
|
+
susdc: {
|
|
1200
|
+
coinType: "",
|
|
1201
|
+
treasury: ""
|
|
1202
|
+
},
|
|
1203
|
+
susdt: {
|
|
1204
|
+
coinType: "",
|
|
1205
|
+
treasury: ""
|
|
1206
|
+
},
|
|
1207
|
+
seth: {
|
|
1208
|
+
coinType: "",
|
|
1209
|
+
treasury: ""
|
|
1210
|
+
},
|
|
1211
|
+
safsui: {
|
|
1212
|
+
coinType: "",
|
|
1213
|
+
treasury: ""
|
|
1214
|
+
},
|
|
1215
|
+
shasui: {
|
|
1216
|
+
coinType: "",
|
|
1217
|
+
treasury: ""
|
|
1218
|
+
},
|
|
1219
|
+
svsui: {
|
|
1220
|
+
coinType: "",
|
|
1221
|
+
treasury: ""
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1023
1224
|
}
|
|
1024
1225
|
};
|
|
1025
1226
|
var ScallopAddress = class {
|
|
@@ -1038,8 +1239,8 @@ var ScallopAddress = class {
|
|
|
1038
1239
|
this._auth = auth;
|
|
1039
1240
|
this._id = id;
|
|
1040
1241
|
this._network = network || "mainnet";
|
|
1041
|
-
this._addressesMap =
|
|
1042
|
-
if (
|
|
1242
|
+
this._addressesMap = USE_TEST_ADDRESS ? /* @__PURE__ */ new Map([["mainnet", TEST_ADDRESSES]]) : /* @__PURE__ */ new Map();
|
|
1243
|
+
if (USE_TEST_ADDRESS)
|
|
1043
1244
|
this._currentAddresses = TEST_ADDRESSES;
|
|
1044
1245
|
}
|
|
1045
1246
|
/**
|
|
@@ -1328,7 +1529,7 @@ var ScallopAddress = class {
|
|
|
1328
1529
|
};
|
|
1329
1530
|
|
|
1330
1531
|
// src/models/scallopClient.ts
|
|
1331
|
-
import { normalizeSuiAddress as
|
|
1532
|
+
import { normalizeSuiAddress as normalizeSuiAddress3 } from "@mysten/sui.js/utils";
|
|
1332
1533
|
import { SuiKit as SuiKit4 } from "@scallop-io/sui-kit";
|
|
1333
1534
|
|
|
1334
1535
|
// src/models/scallopUtils.ts
|
|
@@ -1372,7 +1573,6 @@ var checkExtendLockPeriod = (lockPeriodInDays, newUnlockAtInSecondTimestamp, pre
|
|
|
1372
1573
|
const availableLockPeriodInDays = Math.floor(
|
|
1373
1574
|
(newUnlockAtInSecondTimestamp - prevUnlockAtInSecondTimestamp) / UNLOCK_ROUND_DURATION
|
|
1374
1575
|
);
|
|
1375
|
-
console.log("availableLockPeriodInDays", availableLockPeriodInDays);
|
|
1376
1576
|
if (lockPeriodInDays > availableLockPeriodInDays) {
|
|
1377
1577
|
throw new Error(
|
|
1378
1578
|
`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}`
|
|
@@ -1831,16 +2031,18 @@ var estimatedFactor = (amount, scaleStep, type) => {
|
|
|
1831
2031
|
};
|
|
1832
2032
|
|
|
1833
2033
|
// src/utils/util.ts
|
|
2034
|
+
var COIN_SET = Array.from(
|
|
2035
|
+
/* @__PURE__ */ new Set([
|
|
2036
|
+
...SUPPORT_POOLS,
|
|
2037
|
+
...SUPPORT_COLLATERALS,
|
|
2038
|
+
...SUPPORT_SPOOLS_REWARDS,
|
|
2039
|
+
...SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
2040
|
+
...SUPPORT_SCOIN
|
|
2041
|
+
])
|
|
2042
|
+
);
|
|
1834
2043
|
var isMarketCoin = (coinName) => {
|
|
1835
2044
|
const assetCoinName = coinName.slice(1).toLowerCase();
|
|
1836
|
-
return coinName.charAt(0).toLowerCase() === "s" &&
|
|
1837
|
-
.../* @__PURE__ */ new Set([
|
|
1838
|
-
...SUPPORT_POOLS,
|
|
1839
|
-
...SUPPORT_COLLATERALS,
|
|
1840
|
-
...SUPPORT_SPOOLS_REWARDS,
|
|
1841
|
-
...SUPPORT_BORROW_INCENTIVE_REWARDS
|
|
1842
|
-
])
|
|
1843
|
-
].includes(assetCoinName);
|
|
2045
|
+
return coinName.charAt(0).toLowerCase() === "s" && COIN_SET.includes(assetCoinName);
|
|
1844
2046
|
};
|
|
1845
2047
|
var parseAssetSymbol = (coinName) => {
|
|
1846
2048
|
switch (coinName) {
|
|
@@ -1855,14 +2057,7 @@ var parseAssetSymbol = (coinName) => {
|
|
|
1855
2057
|
}
|
|
1856
2058
|
};
|
|
1857
2059
|
var parseDataFromPythPriceFeed = (feed, address) => {
|
|
1858
|
-
const assetCoinNames =
|
|
1859
|
-
.../* @__PURE__ */ new Set([
|
|
1860
|
-
...SUPPORT_POOLS,
|
|
1861
|
-
...SUPPORT_COLLATERALS,
|
|
1862
|
-
...SUPPORT_SPOOLS_REWARDS,
|
|
1863
|
-
...SUPPORT_BORROW_INCENTIVE_REWARDS
|
|
1864
|
-
])
|
|
1865
|
-
];
|
|
2060
|
+
const assetCoinNames = COIN_SET;
|
|
1866
2061
|
const assetCoinName = assetCoinNames.find((assetCoinName2) => {
|
|
1867
2062
|
return address.get(`core.coins.${assetCoinName2}.oracle.pyth.feed`) === feed.id;
|
|
1868
2063
|
});
|
|
@@ -2136,7 +2331,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2136
2331
|
}
|
|
2137
2332
|
}
|
|
2138
2333
|
}
|
|
2139
|
-
if (balanceSheet && borrowIndex && interestModel && borrowFeeRate) {
|
|
2334
|
+
if (balanceSheet && borrowIndex && interestModel && (USE_TEST_ADDRESS || borrowFeeRate)) {
|
|
2140
2335
|
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
2141
2336
|
type: interestModel.type.fields,
|
|
2142
2337
|
maxBorrowRate: interestModel.max_borrow_rate.fields,
|
|
@@ -2150,7 +2345,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2150
2345
|
reserve: balanceSheet.revenue,
|
|
2151
2346
|
reserveFactor: interestModel.revenue_factor.fields,
|
|
2152
2347
|
borrowWeight: interestModel.borrow_weight.fields,
|
|
2153
|
-
borrowFeeRate,
|
|
2348
|
+
borrowFeeRate: borrowFeeRate || { value: "0" },
|
|
2154
2349
|
baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
|
|
2155
2350
|
borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
|
|
2156
2351
|
borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
|
|
@@ -2186,10 +2381,10 @@ var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) =
|
|
|
2186
2381
|
collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
|
|
2187
2382
|
const marketId = query.address.get("core.market");
|
|
2188
2383
|
const [marketObjectResponse, coinPrices] = await Promise.all([
|
|
2189
|
-
query.cache.queryGetObject(marketId, {
|
|
2384
|
+
await query.cache.queryGetObject(marketId, {
|
|
2190
2385
|
showContent: true
|
|
2191
2386
|
}),
|
|
2192
|
-
query.utils.getCoinPrices(collateralCoinNames ?? [])
|
|
2387
|
+
await query.utils.getCoinPrices(collateralCoinNames ?? [])
|
|
2193
2388
|
]);
|
|
2194
2389
|
const marketCollaterals = {};
|
|
2195
2390
|
if (indexer) {
|
|
@@ -2416,6 +2611,64 @@ var getMarketCoinAmount = async (query, marketCoinName, ownerAddress) => {
|
|
|
2416
2611
|
});
|
|
2417
2612
|
return BigNumber2(amount).toNumber();
|
|
2418
2613
|
};
|
|
2614
|
+
var getFlashLoanFees = async (query, assetNames) => {
|
|
2615
|
+
const FEE_RATE = 1e4;
|
|
2616
|
+
const missingAssets = [];
|
|
2617
|
+
const assetTypeMap = assetNames.reduce(
|
|
2618
|
+
(prev, curr) => {
|
|
2619
|
+
const assetType = query.utils.parseCoinType(curr).slice(2);
|
|
2620
|
+
prev[assetType] = curr;
|
|
2621
|
+
return prev;
|
|
2622
|
+
},
|
|
2623
|
+
{}
|
|
2624
|
+
);
|
|
2625
|
+
const objIds = assetNames.map((assetName) => {
|
|
2626
|
+
if (!FlashLoanFeeObjectMap[assetName]) {
|
|
2627
|
+
missingAssets.push(assetName);
|
|
2628
|
+
return null;
|
|
2629
|
+
} else {
|
|
2630
|
+
return FlashLoanFeeObjectMap[assetName];
|
|
2631
|
+
}
|
|
2632
|
+
}).filter((t) => !!t);
|
|
2633
|
+
const flashloanFeeObjects = await query.cache.queryGetObjects(objIds, {
|
|
2634
|
+
showContent: true
|
|
2635
|
+
});
|
|
2636
|
+
if (missingAssets.length > 0) {
|
|
2637
|
+
const marketObjectId = query.address.get("core.market");
|
|
2638
|
+
const marketObjectRes = await query.cache.queryGetObject(marketObjectId, {
|
|
2639
|
+
showContent: true
|
|
2640
|
+
});
|
|
2641
|
+
if (marketObjectRes.data?.content?.dataType !== "moveObject")
|
|
2642
|
+
throw new Error("Failed to get market object");
|
|
2643
|
+
const vault = marketObjectRes.data.content.fields.vault;
|
|
2644
|
+
const flashloanFeesTableId = vault.fields.flash_loan_fees.fields.table.fields.id.id;
|
|
2645
|
+
const balanceSheetDynamicFields = await query.cache.queryGetDynamicFields({
|
|
2646
|
+
parentId: flashloanFeesTableId,
|
|
2647
|
+
limit: 50
|
|
2648
|
+
});
|
|
2649
|
+
const dynamicFieldObjectIds = balanceSheetDynamicFields.data.filter((field) => {
|
|
2650
|
+
const assetType = field.name.value.name;
|
|
2651
|
+
return !!assetTypeMap[assetType];
|
|
2652
|
+
}).map((field) => field.objectId);
|
|
2653
|
+
flashloanFeeObjects.push(
|
|
2654
|
+
...await query.cache.queryGetObjects(dynamicFieldObjectIds, {
|
|
2655
|
+
showContent: true
|
|
2656
|
+
})
|
|
2657
|
+
);
|
|
2658
|
+
}
|
|
2659
|
+
return flashloanFeeObjects.reduce(
|
|
2660
|
+
(prev, curr) => {
|
|
2661
|
+
if (curr.content?.dataType === "moveObject") {
|
|
2662
|
+
const objectFields = curr.content.fields;
|
|
2663
|
+
const assetType = curr.content.fields.name.fields.name;
|
|
2664
|
+
const feeNumerator = +objectFields.value;
|
|
2665
|
+
prev[assetTypeMap[assetType]] = feeNumerator / FEE_RATE;
|
|
2666
|
+
}
|
|
2667
|
+
return prev;
|
|
2668
|
+
},
|
|
2669
|
+
{}
|
|
2670
|
+
);
|
|
2671
|
+
};
|
|
2419
2672
|
|
|
2420
2673
|
// src/queries/spoolQuery.ts
|
|
2421
2674
|
import { normalizeStructTag as normalizeStructTag4 } from "@mysten/sui.js/utils";
|
|
@@ -3070,7 +3323,7 @@ var getLendings = async (query, poolCoinNames, ownerAddress, indexer = false) =>
|
|
|
3070
3323
|
);
|
|
3071
3324
|
return lendings;
|
|
3072
3325
|
};
|
|
3073
|
-
var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice) => {
|
|
3326
|
+
var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, sCoinAmount, coinPrice) => {
|
|
3074
3327
|
const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
|
|
3075
3328
|
marketPool = marketPool || await query.getMarketPool(poolCoinName, indexer);
|
|
3076
3329
|
spool = spool || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(marketCoinName, indexer) : void 0;
|
|
@@ -3080,6 +3333,7 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
3080
3333
|
) : [];
|
|
3081
3334
|
coinAmount = coinAmount || await query.getCoinAmount(poolCoinName, ownerAddress);
|
|
3082
3335
|
marketCoinAmount = marketCoinAmount || await query.getMarketCoinAmount(marketCoinName, ownerAddress);
|
|
3336
|
+
sCoinAmount = sCoinAmount || await query.getSCoinAmount(marketCoinName, ownerAddress);
|
|
3083
3337
|
coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
3084
3338
|
const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
3085
3339
|
let stakedMarketAmount = BigNumber4(0);
|
|
@@ -3131,9 +3385,7 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
3131
3385
|
);
|
|
3132
3386
|
}
|
|
3133
3387
|
}
|
|
3134
|
-
const suppliedAmount = BigNumber4(marketCoinAmount).multipliedBy(
|
|
3135
|
-
marketPool?.conversionRate ?? 1
|
|
3136
|
-
);
|
|
3388
|
+
const suppliedAmount = BigNumber4(marketCoinAmount).plus(BigNumber4(sCoinAmount)).multipliedBy(marketPool?.conversionRate ?? 1);
|
|
3137
3389
|
const suppliedCoin = suppliedAmount.shiftedBy(-1 * coinDecimal);
|
|
3138
3390
|
const suppliedValue = suppliedCoin.multipliedBy(coinPrice ?? 0);
|
|
3139
3391
|
const marketCoinPrice = BigNumber4(coinPrice ?? 0).multipliedBy(
|
|
@@ -3235,6 +3487,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3235
3487
|
let totalBorrowCapacityValue = BigNumber4(0);
|
|
3236
3488
|
let totalRequiredCollateralValue = BigNumber4(0);
|
|
3237
3489
|
let totalBorrowedPools = 0;
|
|
3490
|
+
let totalRewardedPools = 0;
|
|
3238
3491
|
let totalBorrowedValue = BigNumber4(0);
|
|
3239
3492
|
let totalBorrowedValueWithWeight = BigNumber4(0);
|
|
3240
3493
|
for (const assetCoinName of collateralAssetCoinNames) {
|
|
@@ -3396,6 +3649,12 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3396
3649
|
}
|
|
3397
3650
|
}
|
|
3398
3651
|
}
|
|
3652
|
+
if (Object.keys(borrowIncentivePool.points).some((coinName2) => {
|
|
3653
|
+
const rewardApr = borrowIncentivePool.points[coinName2]?.rewardApr;
|
|
3654
|
+
return rewardApr !== Infinity && typeof rewardApr == "number" && rewardApr > 0;
|
|
3655
|
+
}) && borrowIncentiveAccount.debtAmount > 0) {
|
|
3656
|
+
totalRewardedPools++;
|
|
3657
|
+
}
|
|
3399
3658
|
borrowIncentives[coinName] = {
|
|
3400
3659
|
coinName: borrowIncentivePool.coinName,
|
|
3401
3660
|
coinType: borrowIncentivePool.coinType,
|
|
@@ -3433,6 +3692,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3433
3692
|
totalRiskLevel: riskLevel.toNumber(),
|
|
3434
3693
|
totalDepositedPools,
|
|
3435
3694
|
totalBorrowedPools,
|
|
3695
|
+
totalRewardedPools,
|
|
3436
3696
|
collaterals,
|
|
3437
3697
|
debts,
|
|
3438
3698
|
borrowIncentives
|
|
@@ -3675,7 +3935,6 @@ var getVeScaTreasuryInfo = async (query) => {
|
|
|
3675
3935
|
if (!veScaTreasury || veScaTreasury.data?.content?.dataType !== "moveObject")
|
|
3676
3936
|
return null;
|
|
3677
3937
|
const treasuryFields = veScaTreasury.data.content.fields;
|
|
3678
|
-
console.log(treasuryFields);
|
|
3679
3938
|
const totalLockedSca = BigNumber5(
|
|
3680
3939
|
treasuryFields.unlock_schedule.fields.locked_sca_amount
|
|
3681
3940
|
).shiftedBy(-9).toNumber();
|
|
@@ -3927,6 +4186,56 @@ var ScallopIndexer = class {
|
|
|
3927
4186
|
}
|
|
3928
4187
|
};
|
|
3929
4188
|
|
|
4189
|
+
// src/queries/sCoinQuery.ts
|
|
4190
|
+
import { bcs as bcs2 } from "@mysten/sui.js/bcs";
|
|
4191
|
+
import assert from "assert";
|
|
4192
|
+
import BigNumber7 from "bignumber.js";
|
|
4193
|
+
var getSCoinTotalSupply = async (query, sCoinName) => {
|
|
4194
|
+
const sCoinPkgId = query.address.get("scoin.id");
|
|
4195
|
+
const args = [query.utils.getSCoinTreasury(sCoinName)];
|
|
4196
|
+
const typeArgs = [
|
|
4197
|
+
query.utils.parseSCoinType(sCoinName),
|
|
4198
|
+
query.utils.parseUnderlyingSCoinType(sCoinName)
|
|
4199
|
+
];
|
|
4200
|
+
const queryTarget = `${sCoinPkgId}::s_coin_converter::total_supply`;
|
|
4201
|
+
const queryResults = await query.cache.queryInspectTxn({
|
|
4202
|
+
queryTarget,
|
|
4203
|
+
args,
|
|
4204
|
+
typeArgs
|
|
4205
|
+
});
|
|
4206
|
+
const results = queryResults.results;
|
|
4207
|
+
if (results && results[0].returnValues) {
|
|
4208
|
+
const value = Uint8Array.from(results[0].returnValues[0][0]);
|
|
4209
|
+
const type = results[0].returnValues[0][1];
|
|
4210
|
+
assert(type === "u64", "Result type is not u64");
|
|
4211
|
+
return BigNumber7(bcs2.de(type, value)).shiftedBy(
|
|
4212
|
+
query.utils.getCoinDecimal(query.utils.parseCoinName(sCoinName))
|
|
4213
|
+
).toNumber();
|
|
4214
|
+
}
|
|
4215
|
+
return 0;
|
|
4216
|
+
};
|
|
4217
|
+
var getSCoinAmounts = async (query, sCoinNames, ownerAddress) => {
|
|
4218
|
+
sCoinNames = sCoinNames || [...SUPPORT_SCOIN];
|
|
4219
|
+
const owner = ownerAddress || query.suiKit.currentAddress();
|
|
4220
|
+
const sCoins2 = {};
|
|
4221
|
+
await Promise.allSettled(
|
|
4222
|
+
sCoinNames.map(async (sCoinName) => {
|
|
4223
|
+
const sCoin = await getSCoinAmount(query, sCoinName, owner);
|
|
4224
|
+
sCoins2[sCoinName] = sCoin;
|
|
4225
|
+
})
|
|
4226
|
+
);
|
|
4227
|
+
return sCoins2;
|
|
4228
|
+
};
|
|
4229
|
+
var getSCoinAmount = async (query, sCoinName, ownerAddress) => {
|
|
4230
|
+
const owner = ownerAddress || query.suiKit.currentAddress();
|
|
4231
|
+
const sCoinType = query.utils.parseSCoinType(sCoinName);
|
|
4232
|
+
const amount = await query.cache.queryGetCoinBalance({
|
|
4233
|
+
owner,
|
|
4234
|
+
coinType: sCoinType
|
|
4235
|
+
});
|
|
4236
|
+
return BigNumber7(amount).toNumber();
|
|
4237
|
+
};
|
|
4238
|
+
|
|
3930
4239
|
// src/models/scallopQuery.ts
|
|
3931
4240
|
var ScallopQuery = class {
|
|
3932
4241
|
constructor(params, instance) {
|
|
@@ -4342,6 +4651,41 @@ var ScallopQuery = class {
|
|
|
4342
4651
|
async getLoyaltyProgramInfos(veScaKey) {
|
|
4343
4652
|
return await getLoyaltyProgramInformations(this, veScaKey);
|
|
4344
4653
|
}
|
|
4654
|
+
/**
|
|
4655
|
+
* Get total supply of sCoin
|
|
4656
|
+
* @param sCoinName - Supported sCoin name
|
|
4657
|
+
* @returns Total Supply
|
|
4658
|
+
*/
|
|
4659
|
+
async getSCoinTotalSupply(sCoinName) {
|
|
4660
|
+
return await getSCoinTotalSupply(this, sCoinName);
|
|
4661
|
+
}
|
|
4662
|
+
/**
|
|
4663
|
+
* Get all sCoin amounts.
|
|
4664
|
+
*
|
|
4665
|
+
* @param sCoinNames - Specific an array of support sCoin name.
|
|
4666
|
+
* @param ownerAddress - The owner address.
|
|
4667
|
+
* @return All market sCoin amounts.
|
|
4668
|
+
*/
|
|
4669
|
+
async getSCoinAmounts(sCoinNames, ownerAddress) {
|
|
4670
|
+
return await getSCoinAmounts(this, sCoinNames, ownerAddress);
|
|
4671
|
+
}
|
|
4672
|
+
/**
|
|
4673
|
+
* Get sCoin amount.
|
|
4674
|
+
*
|
|
4675
|
+
* @param coinNames - Specific support sCoin name.
|
|
4676
|
+
* @param ownerAddress - The owner address.
|
|
4677
|
+
* @return sCoin amount.
|
|
4678
|
+
*/
|
|
4679
|
+
async getSCoinAmount(sCoinName, ownerAddress) {
|
|
4680
|
+
const parsedSCoinName = this.utils.parseSCoinName(sCoinName);
|
|
4681
|
+
return parsedSCoinName ? await getSCoinAmount(this, parsedSCoinName, ownerAddress) : 0;
|
|
4682
|
+
}
|
|
4683
|
+
/*
|
|
4684
|
+
* Get flashloan fee for specified assets
|
|
4685
|
+
*/
|
|
4686
|
+
async getFlashLoanFees(assetCoinNames = [...SUPPORT_POOLS]) {
|
|
4687
|
+
return await getFlashLoanFees(this, assetCoinNames);
|
|
4688
|
+
}
|
|
4345
4689
|
};
|
|
4346
4690
|
|
|
4347
4691
|
// src/constants/pyth.ts
|
|
@@ -4457,6 +4801,48 @@ var ScallopUtils = class {
|
|
|
4457
4801
|
return `${coinPackageId}::${coinName}::${coinName.toUpperCase()}`;
|
|
4458
4802
|
}
|
|
4459
4803
|
}
|
|
4804
|
+
/**
|
|
4805
|
+
* Convert coin name to sCoin name.
|
|
4806
|
+
*
|
|
4807
|
+
* @param coinName - Specific support coin name.
|
|
4808
|
+
* @return sCoin name.
|
|
4809
|
+
*/
|
|
4810
|
+
parseSCoinName(coinName) {
|
|
4811
|
+
if (isMarketCoin(coinName) && SUPPORT_SCOIN.includes(coinName)) {
|
|
4812
|
+
return coinName;
|
|
4813
|
+
} else {
|
|
4814
|
+
const marketCoinName = `s${coinName}`;
|
|
4815
|
+
if (SUPPORT_SCOIN.includes(marketCoinName)) {
|
|
4816
|
+
return marketCoinName;
|
|
4817
|
+
}
|
|
4818
|
+
return void 0;
|
|
4819
|
+
}
|
|
4820
|
+
}
|
|
4821
|
+
/**
|
|
4822
|
+
* Convert sCoin name into sCoin type
|
|
4823
|
+
* @param sCoinName
|
|
4824
|
+
* @returns sCoin type
|
|
4825
|
+
*/
|
|
4826
|
+
parseSCoinType(sCoinName) {
|
|
4827
|
+
return sCoinIds[sCoinName];
|
|
4828
|
+
}
|
|
4829
|
+
/**
|
|
4830
|
+
* Convert sCoin name into its underlying coin type
|
|
4831
|
+
* @param sCoinName
|
|
4832
|
+
* @returns coin type
|
|
4833
|
+
*/
|
|
4834
|
+
parseUnderlyingSCoinType(sCoinName) {
|
|
4835
|
+
const coinName = this.parseCoinName(sCoinName);
|
|
4836
|
+
return this.parseCoinType(coinName);
|
|
4837
|
+
}
|
|
4838
|
+
/**
|
|
4839
|
+
* Get sCoin treasury id from sCoin name
|
|
4840
|
+
* @param sCoinName
|
|
4841
|
+
* @returns sCoin treasury id
|
|
4842
|
+
*/
|
|
4843
|
+
getSCoinTreasury(sCoinName) {
|
|
4844
|
+
return this._address.get(`scoin.coins.${sCoinName}.treasury`);
|
|
4845
|
+
}
|
|
4460
4846
|
/**
|
|
4461
4847
|
* Convert coin name to market coin type.
|
|
4462
4848
|
*
|
|
@@ -4534,14 +4920,14 @@ var ScallopUtils = class {
|
|
|
4534
4920
|
* @param coinType - The coin type, default is 0x2::SUI::SUI.
|
|
4535
4921
|
* @return The selected transaction coin arguments.
|
|
4536
4922
|
*/
|
|
4537
|
-
async
|
|
4923
|
+
async selectCoins(amount, coinType = SUI_TYPE_ARG, ownerAddress) {
|
|
4538
4924
|
ownerAddress = ownerAddress || this._suiKit.currentAddress();
|
|
4539
4925
|
const coins = await this._suiKit.suiInteractor.selectCoins(
|
|
4540
4926
|
ownerAddress,
|
|
4541
4927
|
amount,
|
|
4542
4928
|
coinType
|
|
4543
4929
|
);
|
|
4544
|
-
return coins
|
|
4930
|
+
return coins;
|
|
4545
4931
|
}
|
|
4546
4932
|
/**
|
|
4547
4933
|
* Get all asset coin names in the obligation record by obligation id.
|
|
@@ -4715,7 +5101,7 @@ var ScallopUtils = class {
|
|
|
4715
5101
|
};
|
|
4716
5102
|
|
|
4717
5103
|
// src/models/scallopBuilder.ts
|
|
4718
|
-
import { normalizeSuiAddress } from "@mysten/sui.js/utils";
|
|
5104
|
+
import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui.js/utils";
|
|
4719
5105
|
import { SuiKit as SuiKit3 } from "@scallop-io/sui-kit";
|
|
4720
5106
|
|
|
4721
5107
|
// src/builders/coreBuilder.ts
|
|
@@ -4897,10 +5283,13 @@ var generateCoreNormalMethod = ({
|
|
|
4897
5283
|
const referralPkgId = builder.address.get("referral.id");
|
|
4898
5284
|
const referralWitnessType = `${referralPkgId}::scallop_referral_program::REFERRAL_WITNESS`;
|
|
4899
5285
|
return {
|
|
4900
|
-
openObligation: () =>
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
5286
|
+
openObligation: () => {
|
|
5287
|
+
const [obligation, obligationKey, obligationHotPotato] = txBlock.moveCall(
|
|
5288
|
+
`${coreIds.protocolPkg}::open_obligation::open_obligation`,
|
|
5289
|
+
[coreIds.version]
|
|
5290
|
+
);
|
|
5291
|
+
return [obligation, obligationKey, obligationHotPotato];
|
|
5292
|
+
},
|
|
4904
5293
|
returnObligation: (obligation, obligationHotPotato) => txBlock.moveCall(
|
|
4905
5294
|
`${coreIds.protocolPkg}::open_obligation::return_obligation`,
|
|
4906
5295
|
[coreIds.version, obligation, obligationHotPotato]
|
|
@@ -5094,11 +5483,12 @@ var generateCoreQuickMethod = ({
|
|
|
5094
5483
|
collateralCoinName
|
|
5095
5484
|
);
|
|
5096
5485
|
},
|
|
5097
|
-
depositQuick: async (amount, poolCoinName) => {
|
|
5486
|
+
depositQuick: async (amount, poolCoinName, returnSCoin = true) => {
|
|
5098
5487
|
const sender = requireSender(txBlock);
|
|
5488
|
+
let marketCoinDeposit;
|
|
5099
5489
|
if (poolCoinName === "sui") {
|
|
5100
5490
|
const [suiCoin] = txBlock.splitSUIFromGas([amount]);
|
|
5101
|
-
|
|
5491
|
+
marketCoinDeposit = txBlock.deposit(suiCoin, poolCoinName);
|
|
5102
5492
|
} else {
|
|
5103
5493
|
const { leftCoin, takeCoin } = await builder.selectCoin(
|
|
5104
5494
|
txBlock,
|
|
@@ -5107,20 +5497,56 @@ var generateCoreQuickMethod = ({
|
|
|
5107
5497
|
sender
|
|
5108
5498
|
);
|
|
5109
5499
|
txBlock.transferObjects([leftCoin], sender);
|
|
5110
|
-
|
|
5500
|
+
marketCoinDeposit = txBlock.deposit(takeCoin, poolCoinName);
|
|
5111
5501
|
}
|
|
5502
|
+
return returnSCoin ? txBlock.mintSCoin(
|
|
5503
|
+
builder.utils.parseMarketCoinName(poolCoinName),
|
|
5504
|
+
marketCoinDeposit
|
|
5505
|
+
) : marketCoinDeposit;
|
|
5112
5506
|
},
|
|
5113
5507
|
withdrawQuick: async (amount, poolCoinName) => {
|
|
5114
5508
|
const sender = requireSender(txBlock);
|
|
5115
5509
|
const marketCoinName = builder.utils.parseMarketCoinName(poolCoinName);
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5510
|
+
try {
|
|
5511
|
+
const sCoinName = builder.utils.parseSCoinName(poolCoinName);
|
|
5512
|
+
if (!sCoinName)
|
|
5513
|
+
throw new Error(`No sCoin for ${poolCoinName}`);
|
|
5514
|
+
const { leftCoin, takeCoin, totalAmount } = await builder.selectSCoin(
|
|
5515
|
+
txBlock,
|
|
5516
|
+
sCoinName,
|
|
5517
|
+
amount,
|
|
5518
|
+
sender
|
|
5519
|
+
);
|
|
5520
|
+
txBlock.transferObjects([leftCoin], sender);
|
|
5521
|
+
const marketCoin = txBlock.burnSCoin(sCoinName, takeCoin);
|
|
5522
|
+
const txResult = txBlock.withdraw(marketCoin, poolCoinName);
|
|
5523
|
+
amount -= totalAmount;
|
|
5524
|
+
try {
|
|
5525
|
+
if (amount > 0) {
|
|
5526
|
+
const { leftCoin: leftCoin2, takeCoin: takeCoin2 } = await builder.selectMarketCoin(
|
|
5527
|
+
txBlock,
|
|
5528
|
+
marketCoinName,
|
|
5529
|
+
amount,
|
|
5530
|
+
sender
|
|
5531
|
+
);
|
|
5532
|
+
txBlock.transferObjects([leftCoin2], sender);
|
|
5533
|
+
txBlock.mergeCoins(txResult, [
|
|
5534
|
+
txBlock.withdraw(takeCoin2, poolCoinName)
|
|
5535
|
+
]);
|
|
5536
|
+
}
|
|
5537
|
+
} catch (e) {
|
|
5538
|
+
}
|
|
5539
|
+
return txResult;
|
|
5540
|
+
} catch (e) {
|
|
5541
|
+
const { leftCoin, takeCoin } = await builder.selectMarketCoin(
|
|
5542
|
+
txBlock,
|
|
5543
|
+
marketCoinName,
|
|
5544
|
+
amount,
|
|
5545
|
+
sender
|
|
5546
|
+
);
|
|
5547
|
+
txBlock.transferObjects([leftCoin], sender);
|
|
5548
|
+
return txBlock.withdraw(takeCoin, poolCoinName);
|
|
5549
|
+
}
|
|
5124
5550
|
},
|
|
5125
5551
|
borrowQuick: async (amount, poolCoinName, obligationId, obligationKey) => {
|
|
5126
5552
|
const obligationInfo = await requireObligationInfo(
|
|
@@ -5324,7 +5750,7 @@ var generateSpoolQuickMethod = ({
|
|
|
5324
5750
|
);
|
|
5325
5751
|
const marketCoinType = builder.utils.parseMarketCoinType(stakeMarketCoinName);
|
|
5326
5752
|
if (typeof amountOrMarketCoin === "number") {
|
|
5327
|
-
const coins = await builder.utils.
|
|
5753
|
+
const coins = await builder.utils.selectCoins(
|
|
5328
5754
|
amountOrMarketCoin,
|
|
5329
5755
|
marketCoinType,
|
|
5330
5756
|
sender
|
|
@@ -5539,7 +5965,7 @@ var generateQuickVeScaMethod = ({
|
|
|
5539
5965
|
let scaCoin = void 0;
|
|
5540
5966
|
const transferObjects = [];
|
|
5541
5967
|
if (amountOrCoin !== void 0 && typeof amountOrCoin === "number") {
|
|
5542
|
-
const coins = await builder.utils.
|
|
5968
|
+
const coins = await builder.utils.selectCoins(
|
|
5543
5969
|
amountOrCoin,
|
|
5544
5970
|
SCA_COIN_TYPE,
|
|
5545
5971
|
sender
|
|
@@ -5611,7 +6037,7 @@ var generateQuickVeScaMethod = ({
|
|
|
5611
6037
|
if (autoCheck)
|
|
5612
6038
|
checkExtendLockAmount(scaAmount, veSca?.unlockAt);
|
|
5613
6039
|
if (veSca) {
|
|
5614
|
-
const scaCoins = await builder.utils.
|
|
6040
|
+
const scaCoins = await builder.utils.selectCoins(
|
|
5615
6041
|
scaAmount,
|
|
5616
6042
|
SCA_COIN_TYPE,
|
|
5617
6043
|
sender
|
|
@@ -5639,7 +6065,7 @@ var generateQuickVeScaMethod = ({
|
|
|
5639
6065
|
const unlockedSca = txBlock.redeemSca(veSca.keyId);
|
|
5640
6066
|
transferObjects.push(unlockedSca);
|
|
5641
6067
|
}
|
|
5642
|
-
const scaCoins = await builder.utils.
|
|
6068
|
+
const scaCoins = await builder.utils.selectCoins(
|
|
5643
6069
|
scaAmount,
|
|
5644
6070
|
SCA_COIN_TYPE,
|
|
5645
6071
|
sender
|
|
@@ -6027,7 +6453,7 @@ var generateReferralQuickMethod = ({
|
|
|
6027
6453
|
Infinity,
|
|
6028
6454
|
builder.utils.parseCoinType(coinName)
|
|
6029
6455
|
);
|
|
6030
|
-
txBlock.mergeCoins(rewardCoin, coins);
|
|
6456
|
+
txBlock.mergeCoins(rewardCoin, coins.slice(0, 500));
|
|
6031
6457
|
} catch (e) {
|
|
6032
6458
|
} finally {
|
|
6033
6459
|
objToTransfer.push(rewardCoin);
|
|
@@ -6145,6 +6571,98 @@ var newLoyaltyProgramTxBlock = (builder, initTxBlock) => {
|
|
|
6145
6571
|
});
|
|
6146
6572
|
};
|
|
6147
6573
|
|
|
6574
|
+
// src/builders/sCoinBuilder.ts
|
|
6575
|
+
import {
|
|
6576
|
+
TransactionBlock as TransactionBlock7,
|
|
6577
|
+
SuiTxBlock as SuiKitTxBlock7
|
|
6578
|
+
} from "@scallop-io/sui-kit";
|
|
6579
|
+
var generateSCoinNormalMethod = ({
|
|
6580
|
+
builder,
|
|
6581
|
+
txBlock
|
|
6582
|
+
}) => {
|
|
6583
|
+
const sCoinPkgIds = {
|
|
6584
|
+
pkgId: builder.address.get("scoin.id")
|
|
6585
|
+
};
|
|
6586
|
+
return {
|
|
6587
|
+
mintSCoin: (marketCoinName, marketCoin) => {
|
|
6588
|
+
return txBlock.moveCall(
|
|
6589
|
+
`${sCoinPkgIds.pkgId}::s_coin_converter::mint_s_coin`,
|
|
6590
|
+
[builder.utils.getSCoinTreasury(marketCoinName), marketCoin],
|
|
6591
|
+
[
|
|
6592
|
+
builder.utils.parseSCoinType(marketCoinName),
|
|
6593
|
+
builder.utils.parseUnderlyingSCoinType(marketCoinName)
|
|
6594
|
+
]
|
|
6595
|
+
);
|
|
6596
|
+
},
|
|
6597
|
+
burnSCoin: (sCoinName, sCoin) => {
|
|
6598
|
+
return txBlock.moveCall(
|
|
6599
|
+
`${sCoinPkgIds.pkgId}::s_coin_converter::burn_s_coin`,
|
|
6600
|
+
[builder.utils.getSCoinTreasury(sCoinName), sCoin],
|
|
6601
|
+
[
|
|
6602
|
+
builder.utils.parseSCoinType(sCoinName),
|
|
6603
|
+
builder.utils.parseUnderlyingSCoinType(sCoinName)
|
|
6604
|
+
]
|
|
6605
|
+
);
|
|
6606
|
+
}
|
|
6607
|
+
};
|
|
6608
|
+
};
|
|
6609
|
+
var generateSCoinQuickMethod = ({
|
|
6610
|
+
builder,
|
|
6611
|
+
txBlock
|
|
6612
|
+
}) => {
|
|
6613
|
+
return {
|
|
6614
|
+
mintSCoinQuick: async (marketCoinName, amount) => {
|
|
6615
|
+
const sender = requireSender(txBlock);
|
|
6616
|
+
const { leftCoin, takeCoin } = await builder.selectMarketCoin(
|
|
6617
|
+
txBlock,
|
|
6618
|
+
marketCoinName,
|
|
6619
|
+
amount,
|
|
6620
|
+
sender
|
|
6621
|
+
);
|
|
6622
|
+
txBlock.transferObjects([leftCoin], sender);
|
|
6623
|
+
return txBlock.mintSCoin(marketCoinName, takeCoin);
|
|
6624
|
+
},
|
|
6625
|
+
burnSCoinQuick: async (sCoinName, amount) => {
|
|
6626
|
+
const sender = requireSender(txBlock);
|
|
6627
|
+
const { leftCoin, takeCoin } = await builder.selectSCoin(
|
|
6628
|
+
txBlock,
|
|
6629
|
+
sCoinName,
|
|
6630
|
+
amount,
|
|
6631
|
+
sender
|
|
6632
|
+
);
|
|
6633
|
+
txBlock.transferObjects([leftCoin], sender);
|
|
6634
|
+
return txBlock.burnSCoin(sCoinName, takeCoin);
|
|
6635
|
+
}
|
|
6636
|
+
};
|
|
6637
|
+
};
|
|
6638
|
+
var newSCoinTxBlock = (builder, initTxBlock) => {
|
|
6639
|
+
const txBlock = initTxBlock instanceof TransactionBlock7 ? new SuiKitTxBlock7(initTxBlock) : initTxBlock ? initTxBlock : new SuiKitTxBlock7();
|
|
6640
|
+
const normalMethod = generateSCoinNormalMethod({
|
|
6641
|
+
builder,
|
|
6642
|
+
txBlock
|
|
6643
|
+
});
|
|
6644
|
+
const normalTxBlock = new Proxy(txBlock, {
|
|
6645
|
+
get: (target, prop) => {
|
|
6646
|
+
if (prop in normalMethod) {
|
|
6647
|
+
return Reflect.get(normalMethod, prop);
|
|
6648
|
+
}
|
|
6649
|
+
return Reflect.get(target, prop);
|
|
6650
|
+
}
|
|
6651
|
+
});
|
|
6652
|
+
const quickMethod = generateSCoinQuickMethod({
|
|
6653
|
+
builder,
|
|
6654
|
+
txBlock: normalTxBlock
|
|
6655
|
+
});
|
|
6656
|
+
return new Proxy(normalTxBlock, {
|
|
6657
|
+
get: (target, prop) => {
|
|
6658
|
+
if (prop in quickMethod) {
|
|
6659
|
+
return Reflect.get(quickMethod, prop);
|
|
6660
|
+
}
|
|
6661
|
+
return Reflect.get(target, prop);
|
|
6662
|
+
}
|
|
6663
|
+
});
|
|
6664
|
+
};
|
|
6665
|
+
|
|
6148
6666
|
// src/builders/index.ts
|
|
6149
6667
|
var newScallopTxBlock = (builder, initTxBlock) => {
|
|
6150
6668
|
const vescaTxBlock = newVeScaTxBlock(builder, initTxBlock);
|
|
@@ -6155,7 +6673,8 @@ var newScallopTxBlock = (builder, initTxBlock) => {
|
|
|
6155
6673
|
);
|
|
6156
6674
|
const referralTxBlock = newReferralTxBlock(builder, borrowIncentiveTxBlock);
|
|
6157
6675
|
const spoolTxBlock = newSpoolTxBlock(builder, referralTxBlock);
|
|
6158
|
-
const
|
|
6676
|
+
const sCoinTxBlock = newSCoinTxBlock(builder, spoolTxBlock);
|
|
6677
|
+
const coreTxBlock = newCoreTxBlock(builder, sCoinTxBlock);
|
|
6159
6678
|
return new Proxy(coreTxBlock, {
|
|
6160
6679
|
get: (target, prop) => {
|
|
6161
6680
|
if (prop in vescaTxBlock) {
|
|
@@ -6168,6 +6687,8 @@ var newScallopTxBlock = (builder, initTxBlock) => {
|
|
|
6168
6687
|
return Reflect.get(spoolTxBlock, prop);
|
|
6169
6688
|
} else if (prop in loyaltyTxBlock) {
|
|
6170
6689
|
return Reflect.get(loyaltyTxBlock, prop);
|
|
6690
|
+
} else if (prop in sCoinTxBlock) {
|
|
6691
|
+
return Reflect.get(sCoinTxBlock, prop);
|
|
6171
6692
|
}
|
|
6172
6693
|
return Reflect.get(target, prop);
|
|
6173
6694
|
}
|
|
@@ -6198,7 +6719,7 @@ var ScallopBuilder = class {
|
|
|
6198
6719
|
query: this.query,
|
|
6199
6720
|
cache: this.cache
|
|
6200
6721
|
});
|
|
6201
|
-
this.walletAddress =
|
|
6722
|
+
this.walletAddress = normalizeSuiAddress2(
|
|
6202
6723
|
params?.walletAddress || this.suiKit.currentAddress()
|
|
6203
6724
|
);
|
|
6204
6725
|
this.isTestnet = params.networkType ? params.networkType === "testnet" : false;
|
|
@@ -6238,7 +6759,7 @@ var ScallopBuilder = class {
|
|
|
6238
6759
|
*/
|
|
6239
6760
|
async selectCoin(txBlock, assetCoinName, amount, sender) {
|
|
6240
6761
|
const coinType = this.utils.parseCoinType(assetCoinName);
|
|
6241
|
-
const coins = await this.utils.
|
|
6762
|
+
const coins = await this.utils.selectCoins(amount, coinType, sender);
|
|
6242
6763
|
const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(coins, amount);
|
|
6243
6764
|
return { takeCoin, leftCoin };
|
|
6244
6765
|
}
|
|
@@ -6253,13 +6774,42 @@ var ScallopBuilder = class {
|
|
|
6253
6774
|
*/
|
|
6254
6775
|
async selectMarketCoin(txBlock, marketCoinName, amount, sender) {
|
|
6255
6776
|
const marketCoinType = this.utils.parseMarketCoinType(marketCoinName);
|
|
6256
|
-
const coins = await this.utils.
|
|
6257
|
-
|
|
6258
|
-
|
|
6259
|
-
|
|
6777
|
+
const coins = await this.utils.selectCoins(amount, marketCoinType, sender);
|
|
6778
|
+
const totalAmount = coins.reduce((prev, coin) => {
|
|
6779
|
+
prev += Number(coin.balance);
|
|
6780
|
+
return prev;
|
|
6781
|
+
}, 0);
|
|
6782
|
+
const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(
|
|
6783
|
+
coins,
|
|
6784
|
+
Math.min(amount, totalAmount)
|
|
6260
6785
|
);
|
|
6261
|
-
|
|
6262
|
-
|
|
6786
|
+
return { takeCoin, leftCoin, totalAmount };
|
|
6787
|
+
}
|
|
6788
|
+
/**
|
|
6789
|
+
* Specifying the sender's amount of sCoins to get coins args from transaction result.
|
|
6790
|
+
*
|
|
6791
|
+
* @param txBlock - Scallop txBlock or txBlock created by SuiKit .
|
|
6792
|
+
* @param marketCoinName - Specific support sCoin name.
|
|
6793
|
+
* @param amount - Amount of coins to be selected.
|
|
6794
|
+
* @param sender - Sender address.
|
|
6795
|
+
* @return Take coin and left coin.
|
|
6796
|
+
*/
|
|
6797
|
+
async selectSCoin(txBlock, sCoinName, amount, sender) {
|
|
6798
|
+
const sCoinType = this.utils.parseSCoinType(sCoinName);
|
|
6799
|
+
const coins = await this.utils.selectCoins(amount, sCoinType, sender);
|
|
6800
|
+
const totalAmount = coins.reduce((prev, coin) => {
|
|
6801
|
+
prev += Number(coin.balance);
|
|
6802
|
+
return prev;
|
|
6803
|
+
}, 0);
|
|
6804
|
+
const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(
|
|
6805
|
+
coins,
|
|
6806
|
+
Math.min(totalAmount, amount)
|
|
6807
|
+
);
|
|
6808
|
+
return {
|
|
6809
|
+
takeCoin,
|
|
6810
|
+
leftCoin,
|
|
6811
|
+
totalAmount
|
|
6812
|
+
};
|
|
6263
6813
|
}
|
|
6264
6814
|
/**
|
|
6265
6815
|
* Execute Scallop txBlock using the `signAndSendTxn` methods in suikit.
|
|
@@ -6304,7 +6854,7 @@ var ScallopClient = class {
|
|
|
6304
6854
|
utils: this.utils,
|
|
6305
6855
|
cache: this.cache
|
|
6306
6856
|
});
|
|
6307
|
-
this.walletAddress =
|
|
6857
|
+
this.walletAddress = normalizeSuiAddress3(
|
|
6308
6858
|
params?.walletAddress || this.suiKit.currentAddress()
|
|
6309
6859
|
);
|
|
6310
6860
|
}
|
|
@@ -6784,6 +7334,98 @@ var ScallopClient = class {
|
|
|
6784
7334
|
return txBlock.txBlock;
|
|
6785
7335
|
}
|
|
6786
7336
|
}
|
|
7337
|
+
/* ==================== Migrate market coin to sCoin method ==================== */
|
|
7338
|
+
/**
|
|
7339
|
+
* Function to migrate all market coin in user wallet into sCoin
|
|
7340
|
+
* @returns Transaction response
|
|
7341
|
+
*/
|
|
7342
|
+
async migrateAllMarketCoin(sign = true) {
|
|
7343
|
+
const txBlock = this.builder.createTxBlock();
|
|
7344
|
+
txBlock.setSender(this.walletAddress);
|
|
7345
|
+
const toTransfer = [];
|
|
7346
|
+
await Promise.all(
|
|
7347
|
+
SUPPORT_SCOIN.map(async (sCoinName) => {
|
|
7348
|
+
let toDestroyMarketCoin;
|
|
7349
|
+
try {
|
|
7350
|
+
const marketCoins2 = await this.utils.selectCoins(
|
|
7351
|
+
Number.MAX_SAFE_INTEGER,
|
|
7352
|
+
this.utils.parseMarketCoinType(sCoinName),
|
|
7353
|
+
this.walletAddress
|
|
7354
|
+
);
|
|
7355
|
+
const mergedMarketCoin = marketCoins2[0];
|
|
7356
|
+
if (marketCoins2.length > 1) {
|
|
7357
|
+
txBlock.mergeCoins(mergedMarketCoin, marketCoins2.slice(1));
|
|
7358
|
+
}
|
|
7359
|
+
toDestroyMarketCoin = mergedMarketCoin;
|
|
7360
|
+
} catch (e) {
|
|
7361
|
+
const errMsg = e.toString();
|
|
7362
|
+
if (!errMsg.includes("No valid coins found for the transaction"))
|
|
7363
|
+
throw e;
|
|
7364
|
+
}
|
|
7365
|
+
if (SUPPORT_SPOOLS.includes(sCoinName)) {
|
|
7366
|
+
try {
|
|
7367
|
+
const stakedMarketCoins = await txBlock.unstakeQuick(
|
|
7368
|
+
Number.MAX_SAFE_INTEGER,
|
|
7369
|
+
sCoinName
|
|
7370
|
+
);
|
|
7371
|
+
if (stakedMarketCoins.length > 0) {
|
|
7372
|
+
const mergedStakedMarketCoin = stakedMarketCoins[0];
|
|
7373
|
+
if (stakedMarketCoins.length > 1) {
|
|
7374
|
+
txBlock.mergeCoins(
|
|
7375
|
+
mergedStakedMarketCoin,
|
|
7376
|
+
stakedMarketCoins.slice(1)
|
|
7377
|
+
);
|
|
7378
|
+
}
|
|
7379
|
+
if (toDestroyMarketCoin) {
|
|
7380
|
+
txBlock.mergeCoins(toDestroyMarketCoin, [
|
|
7381
|
+
mergedStakedMarketCoin
|
|
7382
|
+
]);
|
|
7383
|
+
} else {
|
|
7384
|
+
toDestroyMarketCoin = mergedStakedMarketCoin;
|
|
7385
|
+
}
|
|
7386
|
+
}
|
|
7387
|
+
} catch (e) {
|
|
7388
|
+
const errMsg = e.toString();
|
|
7389
|
+
if (!errMsg.includes("No stake account found"))
|
|
7390
|
+
throw e;
|
|
7391
|
+
}
|
|
7392
|
+
}
|
|
7393
|
+
if (toDestroyMarketCoin) {
|
|
7394
|
+
const sCoin = txBlock.mintSCoin(
|
|
7395
|
+
sCoinName,
|
|
7396
|
+
toDestroyMarketCoin
|
|
7397
|
+
);
|
|
7398
|
+
try {
|
|
7399
|
+
const existSCoins = await this.utils.selectCoins(
|
|
7400
|
+
Number.MAX_SAFE_INTEGER,
|
|
7401
|
+
this.utils.parseSCoinType(sCoinName),
|
|
7402
|
+
this.walletAddress
|
|
7403
|
+
);
|
|
7404
|
+
const mergedSCoin = existSCoins[0];
|
|
7405
|
+
if (existSCoins.length > 1) {
|
|
7406
|
+
txBlock.mergeCoins(mergedSCoin, existSCoins.slice(1));
|
|
7407
|
+
}
|
|
7408
|
+
txBlock.mergeCoins(sCoin, [mergedSCoin]);
|
|
7409
|
+
} catch (e) {
|
|
7410
|
+
const errMsg = e.toString();
|
|
7411
|
+
if (!errMsg.includes("No valid coins found for the transaction"))
|
|
7412
|
+
throw e;
|
|
7413
|
+
}
|
|
7414
|
+
toTransfer.push(sCoin);
|
|
7415
|
+
}
|
|
7416
|
+
})
|
|
7417
|
+
);
|
|
7418
|
+
if (toTransfer.length > 0) {
|
|
7419
|
+
txBlock.transferObjects(toTransfer, this.walletAddress);
|
|
7420
|
+
}
|
|
7421
|
+
if (sign) {
|
|
7422
|
+
return await this.suiKit.signAndSendTxn(
|
|
7423
|
+
txBlock
|
|
7424
|
+
);
|
|
7425
|
+
} else {
|
|
7426
|
+
return txBlock.txBlock;
|
|
7427
|
+
}
|
|
7428
|
+
}
|
|
6787
7429
|
async mintTestCoin(assetCoinName, amount, sign = true, receiveAddress) {
|
|
6788
7430
|
const isTestnet = this.params.networkType ? this.params.networkType === "testnet" : false;
|
|
6789
7431
|
if (!isTestnet) {
|
|
@@ -6909,6 +7551,7 @@ export {
|
|
|
6909
7551
|
ADDRESSES_ID,
|
|
6910
7552
|
API_BASE_URL,
|
|
6911
7553
|
BORROW_FEE_PROTOCOL_ID,
|
|
7554
|
+
FlashLoanFeeObjectMap,
|
|
6912
7555
|
IS_VE_SCA_TEST,
|
|
6913
7556
|
MAX_LOCK_DURATION,
|
|
6914
7557
|
MAX_LOCK_ROUNDS,
|
|
@@ -6924,6 +7567,7 @@ export {
|
|
|
6924
7567
|
SUPPORT_ORACLES,
|
|
6925
7568
|
SUPPORT_PACKAGES,
|
|
6926
7569
|
SUPPORT_POOLS,
|
|
7570
|
+
SUPPORT_SCOIN,
|
|
6927
7571
|
SUPPORT_SPOOLS,
|
|
6928
7572
|
SUPPORT_SPOOLS_REWARDS,
|
|
6929
7573
|
Scallop,
|
|
@@ -6935,11 +7579,14 @@ export {
|
|
|
6935
7579
|
ScallopQuery,
|
|
6936
7580
|
ScallopUtils,
|
|
6937
7581
|
UNLOCK_ROUND_DURATION,
|
|
7582
|
+
USE_TEST_ADDRESS,
|
|
6938
7583
|
assetCoins,
|
|
6939
7584
|
borrowIncentiveRewardCoins,
|
|
6940
7585
|
coinDecimals,
|
|
6941
7586
|
coinIds,
|
|
6942
7587
|
marketCoins,
|
|
7588
|
+
sCoinIds,
|
|
7589
|
+
sCoins,
|
|
6943
7590
|
spoolRewardCoins,
|
|
6944
7591
|
stakeMarketCoins,
|
|
6945
7592
|
voloCoinIds,
|