@scallop-io/sui-scallop-sdk 1.3.3 → 1.3.4-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1258 -1092
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1249 -1092
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/builders/loyaltyProgramBuilder.ts +1 -1
- package/src/constants/coinGecko.ts +18 -0
- package/src/constants/common.ts +0 -1
- package/src/constants/enum.ts +8 -0
- package/src/constants/index.ts +6 -0
- package/src/constants/poolAddress.ts +94 -0
- package/src/constants/pyth.ts +19 -0
- package/src/constants/queryKeys.ts +1 -5
- package/src/constants/rpc.ts +16 -0
- package/src/constants/tokenBucket.ts +1 -1
- package/src/models/scallop.ts +3 -2
- package/src/models/scallopAddress.ts +2 -2
- package/src/models/scallopBuilder.ts +4 -3
- package/src/models/scallopCache.ts +1 -1
- package/src/models/scallopClient.ts +27 -26
- package/src/models/scallopQuery.ts +58 -15
- package/src/models/scallopUtils.ts +96 -96
- package/src/models/suiKit.ts +11 -0
- package/src/queries/borrowIncentiveQuery.ts +6 -13
- package/src/queries/coreQuery.ts +37 -22
- package/src/queries/loyaltyProgramQuery.ts +1 -1
- package/src/queries/portfolioQuery.ts +55 -34
- package/src/queries/spoolQuery.ts +17 -17
- package/src/types/utils.ts +13 -0
- package/src/utils/tokenBucket.ts +2 -1
- package/src/utils/util.ts +2 -1
- package/dist/builders/borrowIncentiveBuilder.d.ts +0 -12
- package/dist/builders/coreBuilder.d.ts +0 -12
- package/dist/builders/index.d.ts +0 -12
- package/dist/builders/loyaltyProgramBuilder.d.ts +0 -12
- package/dist/builders/oracle.d.ts +0 -14
- package/dist/builders/referralBuilder.d.ts +0 -12
- package/dist/builders/sCoinBuilder.d.ts +0 -4
- package/dist/builders/spoolBuilder.d.ts +0 -12
- package/dist/builders/vescaBuilder.d.ts +0 -25
- package/dist/constants/cache.d.ts +0 -14
- package/dist/constants/common.d.ts +0 -20
- package/dist/constants/enum.d.ts +0 -13
- package/dist/constants/flashloan.d.ts +0 -2
- package/dist/constants/index.d.ts +0 -5
- package/dist/constants/pyth.d.ts +0 -3
- package/dist/constants/queryKeys.d.ts +0 -58
- package/dist/constants/testAddress.d.ts +0 -2
- package/dist/constants/tokenBucket.d.ts +0 -2
- package/dist/constants/vesca.d.ts +0 -5
- package/dist/index.d.ts +0 -3
- package/dist/models/index.d.ts +0 -8
- package/dist/models/scallop.d.ts +0 -74
- package/dist/models/scallopAddress.d.ts +0 -150
- package/dist/models/scallopBuilder.d.ts +0 -89
- package/dist/models/scallopCache.d.ts +0 -74
- package/dist/models/scallopClient.d.ts +0 -321
- package/dist/models/scallopIndexer.d.ts +0 -89
- package/dist/models/scallopPrice.d.ts +0 -0
- package/dist/models/scallopQuery.d.ts +0 -474
- package/dist/models/scallopUtils.d.ts +0 -217
- package/dist/queries/borrowIncentiveQuery.d.ts +0 -61
- package/dist/queries/coreQuery.d.ts +0 -167
- package/dist/queries/index.d.ts +0 -8
- package/dist/queries/isolatedAsset.d.ts +0 -14
- package/dist/queries/loyaltyProgramQuery.d.ts +0 -10
- package/dist/queries/portfolioQuery.d.ts +0 -73
- package/dist/queries/priceQuery.d.ts +0 -16
- package/dist/queries/referralQuery.d.ts +0 -7
- package/dist/queries/sCoinQuery.d.ts +0 -41
- package/dist/queries/spoolQuery.d.ts +0 -70
- package/dist/queries/supplyLimit.d.ts +0 -9
- package/dist/queries/vescaQuery.d.ts +0 -36
- package/dist/types/address.d.ts +0 -107
- package/dist/types/builder/borrowIncentive.d.ts +0 -35
- package/dist/types/builder/core.d.ts +0 -56
- package/dist/types/builder/index.d.ts +0 -24
- package/dist/types/builder/loyaltyProgram.d.ts +0 -23
- package/dist/types/builder/referral.d.ts +0 -30
- package/dist/types/builder/sCoin.d.ts +0 -37
- package/dist/types/builder/spool.d.ts +0 -29
- package/dist/types/builder/vesca.d.ts +0 -51
- package/dist/types/constant/common.d.ts +0 -24
- package/dist/types/constant/enum.d.ts +0 -48
- package/dist/types/constant/index.d.ts +0 -2
- package/dist/types/index.d.ts +0 -6
- package/dist/types/model.d.ts +0 -54
- package/dist/types/query/borrowIncentive.d.ts +0 -124
- package/dist/types/query/core.d.ts +0 -361
- package/dist/types/query/index.d.ts +0 -7
- package/dist/types/query/loyaltyProgram.d.ts +0 -5
- package/dist/types/query/portfolio.d.ts +0 -115
- package/dist/types/query/sCoin.d.ts +0 -1
- package/dist/types/query/spool.d.ts +0 -122
- package/dist/types/query/vesca.d.ts +0 -26
- package/dist/types/utils.d.ts +0 -9
- package/dist/utils/builder.d.ts +0 -15
- package/dist/utils/index.d.ts +0 -5
- package/dist/utils/indexer.d.ts +0 -17
- package/dist/utils/query.d.ts +0 -62
- package/dist/utils/tokenBucket.d.ts +0 -11
- package/dist/utils/util.d.ts +0 -26
- package/src/models/scallopPrice.ts +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
// src/constants/cache.ts
|
|
2
|
+
var DEFAULT_CACHE_OPTIONS = {
|
|
3
|
+
defaultOptions: {
|
|
4
|
+
queries: {
|
|
5
|
+
staleTime: 5e3,
|
|
6
|
+
gcTime: 5e3
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// src/constants/coinGecko.ts
|
|
12
|
+
var COIN_GECKGO_IDS = {
|
|
13
|
+
usdc: "usdc-coin",
|
|
14
|
+
sbeth: "ethereum",
|
|
15
|
+
weth: "ethereum",
|
|
16
|
+
wbtc: "bitcoin",
|
|
17
|
+
wusdc: "usdc-coin",
|
|
18
|
+
wusdt: "tether",
|
|
19
|
+
sui: "sui",
|
|
20
|
+
wapt: "aptos",
|
|
21
|
+
wsol: "solana",
|
|
22
|
+
cetus: "cetus-protocol",
|
|
23
|
+
afsui: "sui",
|
|
24
|
+
hasui: "sui",
|
|
25
|
+
vsui: "sui",
|
|
26
|
+
sca: "scallop-2"
|
|
27
|
+
};
|
|
28
|
+
|
|
1
29
|
// src/constants/common.ts
|
|
2
30
|
var API_BASE_URL = "https://sui.apis.scallop.io";
|
|
3
31
|
var SDK_API_BASE_URL = "https://sdk.api.scallop.io";
|
|
@@ -266,6 +294,13 @@ var sCoinIds = {
|
|
|
266
294
|
swsol: "0x1392650f2eca9e3f6ffae3ff89e42a3590d7102b80e2b430f674730bc30d3259::scallop_wormhole_sol::SCALLOP_WORMHOLE_SOL",
|
|
267
295
|
swbtc: "0x2cf76a9cf5d3337961d1154283234f94da2dcff18544dfe5cbdef65f319591b5::scallop_wormhole_btc::SCALLOP_WORMHOLE_BTC"
|
|
268
296
|
};
|
|
297
|
+
var sCoinTypeToName = Object.entries(sCoinIds).reduce(
|
|
298
|
+
(acc, [coinName, coinType]) => {
|
|
299
|
+
acc[coinType] = coinName;
|
|
300
|
+
return acc;
|
|
301
|
+
},
|
|
302
|
+
{}
|
|
303
|
+
);
|
|
269
304
|
|
|
270
305
|
// src/constants/flashloan.ts
|
|
271
306
|
var FlashLoanFeeObjectMap = {
|
|
@@ -283,6 +318,88 @@ var FlashLoanFeeObjectMap = {
|
|
|
283
318
|
wsol: "0xe84bdb35b790fc7bdd1645122ac6ac0fc904531d6772c9e25904fece322c5f34"
|
|
284
319
|
};
|
|
285
320
|
|
|
321
|
+
// src/constants/poolAddress.ts
|
|
322
|
+
var POOL_ADDRESSES = {
|
|
323
|
+
usdc: {
|
|
324
|
+
lendingPoolAddress: "0xd3be98bf540f7603eeb550c0c0a19dbfc78822f25158b5fa84ebd9609def415f",
|
|
325
|
+
collateralPoolAddress: "0x8f0d529ba179c5b3d508213003eab813aaae31f78226099639b9a69d1aec17af"
|
|
326
|
+
},
|
|
327
|
+
sbeth: {
|
|
328
|
+
lendingPoolAddress: "0x5f08c4f71d56dd3342c452cc70ffc47f2f4180146d821941b0b9c04761bb42e7",
|
|
329
|
+
collateralPoolAddress: "0xce0549a1cbe952e734f56646988e6b02bbae14667889a60e24d0d03540a6119f"
|
|
330
|
+
},
|
|
331
|
+
weth: {
|
|
332
|
+
lendingPoolAddress: "0xc8fcdff48efc265740ae0b74aae3faccae9ec00034039a113f3339798035108c",
|
|
333
|
+
collateralPoolAddress: "0xad7ced91ed6e7f2b81805561eee27fa6f3e72fdae561077334c7248583db4dbf"
|
|
334
|
+
},
|
|
335
|
+
wbtc: {
|
|
336
|
+
lendingPoolAddress: "0x65cc08a5aca0a0b8d72e1993ded8d145f06dd102fd0d8f285b92934faed564ab",
|
|
337
|
+
collateralPoolAddress: "0x1aa4e5cf743cd797b4eb8bf1e614f80ae2cf556ced426cddaaf190ffcd0e59c3"
|
|
338
|
+
},
|
|
339
|
+
wusdc: {
|
|
340
|
+
lendingPoolAddress: "0x9c9077abf7a29eebce41e33addbcd6f5246a5221dd733e56ea0f00ae1b25c9e8",
|
|
341
|
+
collateralPoolAddress: "0x75aacfb7dcbf92ee0111fc1bf975b12569e4ba632e81ed7ae5ac090d40cd3acb"
|
|
342
|
+
},
|
|
343
|
+
wusdt: {
|
|
344
|
+
lendingPoolAddress: "0xfbc056f126dd35adc1f8fe985e2cedc8010e687e8e851e1c5b99fdf63cd1c879",
|
|
345
|
+
collateralPoolAddress: "0x2260cb5b24929dd20a1742f37a61ff3ce4fde5cdb023e2d3ce2e0ce2d90719e3"
|
|
346
|
+
},
|
|
347
|
+
sui: {
|
|
348
|
+
lendingPoolAddress: "0x9c9077abf7a29eebce41e33addbcd6f5246a5221dd733e56ea0f00ae1b25c9e8",
|
|
349
|
+
collateralPoolAddress: "0x75aacfb7dcbf92ee0111fc1bf975b12569e4ba632e81ed7ae5ac090d40cd3acb"
|
|
350
|
+
},
|
|
351
|
+
wapt: {
|
|
352
|
+
lendingPoolAddress: "0xca8c14a24e0c32b198eaf479a3317461e3cc339097ce88eaf296a15df8dcfdf5",
|
|
353
|
+
collateralPoolAddress: "0xde33f9ac5bb0ed34598da4e64b4983832716ced65f172fbf267bcfe859c4ad9c"
|
|
354
|
+
},
|
|
355
|
+
wsol: {
|
|
356
|
+
lendingPoolAddress: "0x985682c42984cdfb03f9ff7d8923344c2fe096b1ae4b82ea17721af19d22a21f",
|
|
357
|
+
collateralPoolAddress: "0xdc1cc2c371a043ae8e3c3fe2d013c35f1346960b7dbb4c072982c5b794ed144f"
|
|
358
|
+
},
|
|
359
|
+
cetus: {
|
|
360
|
+
lendingPoolAddress: "0xc09858f60e74a1b671635bec4e8a2c84a0ff313eb87f525fba3258e88c6b6282",
|
|
361
|
+
collateralPoolAddress: "0xe363967e29b7b9c1245d6d46d63e719de8f90b37e3358c545b55d945ea0b676a"
|
|
362
|
+
},
|
|
363
|
+
afsui: {
|
|
364
|
+
lendingPoolAddress: "0x9b942a24ce390b7f5016d34a0217057bf9487b92aa6d7cc9894271dbbe62471a",
|
|
365
|
+
collateralPoolAddress: "0xe5e56f5c0e3072760b21f9d49a5cc793f37d736c412a9065c16e1265c74e6341"
|
|
366
|
+
},
|
|
367
|
+
hasui: {
|
|
368
|
+
lendingPoolAddress: "0x7ebc607f6bdeb659fb6506cb91c5cc1d47bb365cfd5d2e637ea765346ec84ed4",
|
|
369
|
+
collateralPoolAddress: "0xad9ed40d6486e4c26cec7370dffce8dc4821eb79178250b5938a34ccafd61e6d"
|
|
370
|
+
},
|
|
371
|
+
vsui: {
|
|
372
|
+
lendingPoolAddress: "0xda9257c0731d8822e8a438ebced13415850d705b779c79958dcf2aeb21fcb43d",
|
|
373
|
+
collateralPoolAddress: "0x4435e8b8ec2a04094d863aa52deb6ab6f8f47ed8778f4d9f1b27afc4a6e85f1e"
|
|
374
|
+
},
|
|
375
|
+
sca: {
|
|
376
|
+
lendingPoolAddress: "0x6fc7d4211fc7018b6c75e7b908b88f2e0536443239804a3d32af547637bd28d7",
|
|
377
|
+
collateralPoolAddress: "0xff677a5d9e9dc8f08f0a8681ebfc7481d1c7d57bc441f2881974adcdd7b13c31"
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
// src/constants/pyth.ts
|
|
382
|
+
var PYTH_ENDPOINTS = {
|
|
383
|
+
testnet: ["https://hermes-beta.pyth.network"],
|
|
384
|
+
mainnet: ["https://hermes.pyth.network", "https://scallop.rpc.p2p.world"]
|
|
385
|
+
};
|
|
386
|
+
var PYTH_FEED_IDS = {
|
|
387
|
+
usdc: "eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
|
|
388
|
+
sbeth: "ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",
|
|
389
|
+
weth: "ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",
|
|
390
|
+
wbtc: "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43",
|
|
391
|
+
wusdc: "eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
|
|
392
|
+
wusdt: "2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b",
|
|
393
|
+
sui: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
394
|
+
wapt: "03ae4db29ed4ae33d323568895aa00337e658e348b37509f5372ae51f0af00d5",
|
|
395
|
+
wsol: "ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d",
|
|
396
|
+
cetus: "e5b274b2611143df055d6e7cd8d93fe1961716bcd4dca1cad87a83bc1e78c1ef",
|
|
397
|
+
afsui: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
398
|
+
hasui: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
399
|
+
vsui: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
400
|
+
sca: "7e17f0ac105abe9214deb9944c30264f5986bf292869c6bd8e8da3ccd92d79bc"
|
|
401
|
+
};
|
|
402
|
+
|
|
286
403
|
// src/constants/queryKeys.ts
|
|
287
404
|
var queryKeys = {
|
|
288
405
|
api: {
|
|
@@ -359,232 +476,609 @@ var queryKeys = {
|
|
|
359
476
|
]
|
|
360
477
|
},
|
|
361
478
|
oracle: {
|
|
362
|
-
|
|
363
|
-
"oracle",
|
|
364
|
-
"getPythPriceId",
|
|
365
|
-
{ pythPriceId }
|
|
366
|
-
]
|
|
367
|
-
}
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
// src/constants/vesca.ts
|
|
371
|
-
var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
|
|
372
|
-
var MAX_LOCK_ROUNDS = 1460;
|
|
373
|
-
var MAX_LOCK_DURATION = MAX_LOCK_ROUNDS * UNLOCK_ROUND_DURATION;
|
|
374
|
-
var MIN_INITIAL_LOCK_AMOUNT = 1e10;
|
|
375
|
-
var MIN_TOP_UP_AMOUNT = 1e9;
|
|
376
|
-
|
|
377
|
-
// src/models/scallop.ts
|
|
378
|
-
import { SuiKit as SuiKit7 } from "@scallop-io/sui-kit";
|
|
379
|
-
|
|
380
|
-
// src/models/scallopAddress.ts
|
|
381
|
-
import { SuiKit } from "@scallop-io/sui-kit";
|
|
382
|
-
|
|
383
|
-
// src/models/scallopCache.ts
|
|
384
|
-
import { QueryClient } from "@tanstack/query-core";
|
|
385
|
-
import {
|
|
386
|
-
SuiTxBlock,
|
|
387
|
-
normalizeStructTag as normalizeStructTag2
|
|
388
|
-
} from "@scallop-io/sui-kit";
|
|
389
|
-
|
|
390
|
-
// src/constants/cache.ts
|
|
391
|
-
var DEFAULT_CACHE_OPTIONS = {
|
|
392
|
-
defaultOptions: {
|
|
393
|
-
queries: {
|
|
394
|
-
staleTime: 5e3,
|
|
395
|
-
gcTime: 5e3
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
|
|
400
|
-
// src/utils/builder.ts
|
|
401
|
-
var requireSender = (txBlock) => {
|
|
402
|
-
const sender = txBlock.blockData.sender;
|
|
403
|
-
if (!sender) {
|
|
404
|
-
throw new Error("Sender is required");
|
|
405
|
-
}
|
|
406
|
-
return sender;
|
|
407
|
-
};
|
|
408
|
-
var checkVesca = (prevUnlockAtInMillisTimestamp) => {
|
|
409
|
-
if (prevUnlockAtInMillisTimestamp === void 0) {
|
|
410
|
-
throw new Error("veSca not found");
|
|
411
|
-
}
|
|
412
|
-
};
|
|
413
|
-
var checkVescaExpired = (prevUnlockAtInMillisTimestamp) => {
|
|
414
|
-
if (prevUnlockAtInMillisTimestamp <= (/* @__PURE__ */ new Date()).getTime()) {
|
|
415
|
-
throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
var checkExtendLockPeriod = (lockPeriodInDays, newUnlockAtInSecondTimestamp, prevUnlockAtInMillisTimestamp) => {
|
|
419
|
-
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
420
|
-
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
421
|
-
const prevUnlockAtInSecondTimestamp = Math.floor(
|
|
422
|
-
prevUnlockAtInMillisTimestamp / 1e3
|
|
423
|
-
);
|
|
424
|
-
if (lockPeriodInDays < 1) {
|
|
425
|
-
throw new Error("Minimum lock period is 1 day");
|
|
426
|
-
}
|
|
427
|
-
const availableLockPeriodInDays = Math.floor(
|
|
428
|
-
(newUnlockAtInSecondTimestamp - prevUnlockAtInSecondTimestamp) / UNLOCK_ROUND_DURATION
|
|
429
|
-
);
|
|
430
|
-
if (lockPeriodInDays > availableLockPeriodInDays) {
|
|
431
|
-
throw new Error(
|
|
432
|
-
`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}`
|
|
433
|
-
);
|
|
434
|
-
}
|
|
435
|
-
};
|
|
436
|
-
var checkLockSca = (scaAmountOrCoin, lockPeriodInDays, newUnlockAtInSecondTimestamp, prevUnlockAtInMillisTimestamp) => {
|
|
437
|
-
const prevUnlockAtInSecondTimestamp = prevUnlockAtInMillisTimestamp ? Math.floor(prevUnlockAtInMillisTimestamp / 1e3) : void 0;
|
|
438
|
-
const isInitialLock = !prevUnlockAtInSecondTimestamp;
|
|
439
|
-
const isLockExpired = !isInitialLock && prevUnlockAtInSecondTimestamp * 1e3 <= (/* @__PURE__ */ new Date()).getTime();
|
|
440
|
-
if (isInitialLock || isLockExpired) {
|
|
441
|
-
if (scaAmountOrCoin !== void 0 && lockPeriodInDays !== void 0) {
|
|
442
|
-
if (lockPeriodInDays <= 0) {
|
|
443
|
-
throw new Error("Lock period must be greater than 0");
|
|
444
|
-
}
|
|
445
|
-
if (typeof scaAmountOrCoin === "number" && scaAmountOrCoin < MIN_INITIAL_LOCK_AMOUNT) {
|
|
446
|
-
throw new Error(
|
|
447
|
-
`Minimum lock amount for ${isLockExpired ? "renewing expired veSca" : "initial lock"} is 10 SCA`
|
|
448
|
-
);
|
|
449
|
-
}
|
|
450
|
-
const extendLockPeriodInSecond = lockPeriodInDays * UNLOCK_ROUND_DURATION;
|
|
451
|
-
if (extendLockPeriodInSecond > MAX_LOCK_DURATION) {
|
|
452
|
-
throw new Error(
|
|
453
|
-
`Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS} days)`
|
|
454
|
-
);
|
|
455
|
-
}
|
|
456
|
-
} else {
|
|
457
|
-
throw new Error(
|
|
458
|
-
`SCA amount and lock period is required for ${isLockExpired ? "renewing expired veSca" : "initial lock"}`
|
|
459
|
-
);
|
|
460
|
-
}
|
|
461
|
-
} else {
|
|
462
|
-
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
463
|
-
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
464
|
-
if (typeof scaAmountOrCoin === "number" && scaAmountOrCoin < MIN_TOP_UP_AMOUNT) {
|
|
465
|
-
throw new Error("Minimum top up amount is 1 SCA");
|
|
466
|
-
}
|
|
467
|
-
if (newUnlockAtInSecondTimestamp && lockPeriodInDays) {
|
|
468
|
-
checkExtendLockPeriod(
|
|
469
|
-
lockPeriodInDays,
|
|
470
|
-
newUnlockAtInSecondTimestamp,
|
|
471
|
-
prevUnlockAtInMillisTimestamp
|
|
472
|
-
);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
};
|
|
476
|
-
var checkExtendLockAmount = (scaAmount, prevUnlockAtInMillisTimestamp) => {
|
|
477
|
-
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
478
|
-
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
479
|
-
if (scaAmount < MIN_TOP_UP_AMOUNT) {
|
|
480
|
-
throw new Error("Minimum top up amount is 1 SCA");
|
|
481
|
-
}
|
|
482
|
-
const isInitialLock = !prevUnlockAtInMillisTimestamp;
|
|
483
|
-
const isLockExpired = !isInitialLock && prevUnlockAtInMillisTimestamp <= (/* @__PURE__ */ new Date()).getTime();
|
|
484
|
-
if (isLockExpired) {
|
|
485
|
-
throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
|
|
486
|
-
}
|
|
487
|
-
};
|
|
488
|
-
var checkRenewExpiredVeSca = (scaAmount, lockPeriodInDays, prevUnlockAtInMillisTimestamp) => {
|
|
489
|
-
if (!prevUnlockAtInMillisTimestamp || prevUnlockAtInMillisTimestamp > (/* @__PURE__ */ new Date()).getTime()) {
|
|
490
|
-
throw new Error("Renew method can only be used for expired veSca");
|
|
491
|
-
}
|
|
492
|
-
if (scaAmount < MIN_INITIAL_LOCK_AMOUNT) {
|
|
493
|
-
throw new Error("Minimum lock amount for renewing expired vesca 10 SCA");
|
|
494
|
-
}
|
|
495
|
-
const extendLockPeriodInSecond = lockPeriodInDays * UNLOCK_ROUND_DURATION;
|
|
496
|
-
if (extendLockPeriodInSecond >= MAX_LOCK_DURATION - UNLOCK_ROUND_DURATION) {
|
|
497
|
-
throw new Error(
|
|
498
|
-
`Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS - 1} days)`
|
|
499
|
-
);
|
|
479
|
+
getPythLatestPriceFeeds: () => ["oracle", "getPythPriceIds"]
|
|
500
480
|
}
|
|
501
481
|
};
|
|
502
482
|
|
|
503
|
-
// src/
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
483
|
+
// src/constants/testAddress.ts
|
|
484
|
+
var TEST_ADDRESSES = {
|
|
485
|
+
core: {
|
|
486
|
+
// version:
|
|
487
|
+
// '0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7',
|
|
488
|
+
version: "0x6156d5cd1538bec8a167a40fe1209a4ec9cf8137921fe0a697f191ac561f0b09",
|
|
489
|
+
versionCap: "0x590a4011cb649b3878f3ea14b3a78674642a9548d79b7e091ef679574b158a07",
|
|
490
|
+
// object:
|
|
491
|
+
// '0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf',
|
|
492
|
+
object: "0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1",
|
|
493
|
+
// market:
|
|
494
|
+
// '0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9',
|
|
495
|
+
market: "0x8606ed145cc887985b8ed793f7753ff5dc762a42c379dac035f568e1bac58490",
|
|
496
|
+
adminCap: "0x09689d018e71c337d9db6d67cbca06b74ed92196103624028ccc3ecea411777c",
|
|
497
|
+
coinDecimalsRegistry: "0x200abe9bf19751cc566ae35aa58e2b7e4ff688fc1130f8d8909ea09bc137d668",
|
|
498
|
+
// obligationAccessStore:
|
|
499
|
+
// '0x733e30b7c94d619d78cb8f5bc4bfbb759ced9a531239028caabb2474e5be59c9',
|
|
500
|
+
obligationAccessStore: "0x48b472d68ca910c45f7f3b6c26836b6aa6d2569810d94b1b939023da05ae0a23",
|
|
501
|
+
coins: {
|
|
502
|
+
cetus: {
|
|
503
|
+
id: "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b",
|
|
504
|
+
metaData: "0x4c0dce55eff2db5419bbd2d239d1aa22b4a400c01bbb648b058a9883989025da",
|
|
505
|
+
treasury: "",
|
|
506
|
+
oracle: {
|
|
507
|
+
supra: "",
|
|
508
|
+
switchboard: "",
|
|
509
|
+
pyth: {
|
|
510
|
+
feed: "e5b274b2611143df055d6e7cd8d93fe1961716bcd4dca1cad87a83bc1e78c1ef",
|
|
511
|
+
feedObject: "0x24c0247fb22457a719efac7f670cdc79be321b521460bd6bd2ccfa9f80713b14"
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
},
|
|
515
|
+
wapt: {
|
|
516
|
+
id: "0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37",
|
|
517
|
+
metaData: "0xc969c5251f372c0f34c32759f1d315cf1ea0ee5e4454b52aea08778eacfdd0a8",
|
|
518
|
+
treasury: "",
|
|
519
|
+
oracle: {
|
|
520
|
+
supra: "",
|
|
521
|
+
switchboard: "",
|
|
522
|
+
pyth: {
|
|
523
|
+
feed: "03ae4db29ed4ae33d323568895aa00337e658e348b37509f5372ae51f0af00d5",
|
|
524
|
+
feedObject: "0x7c5b7837c44a69b469325463ac0673ac1aa8435ff44ddb4191c9ae380463647f"
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
},
|
|
528
|
+
wsol: {
|
|
529
|
+
id: "0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8",
|
|
530
|
+
metaData: "0x4d2c39082b4477e3e79dc4562d939147ab90c42fc5f3e4acf03b94383cd69b6e",
|
|
531
|
+
treasury: "",
|
|
532
|
+
oracle: {
|
|
533
|
+
supra: "",
|
|
534
|
+
switchboard: "",
|
|
535
|
+
pyth: {
|
|
536
|
+
feed: "ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d",
|
|
537
|
+
feedObject: "0x9d0d275efbd37d8a8855f6f2c761fa5983293dd8ce202ee5196626de8fcd4469"
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
},
|
|
541
|
+
wbtc: {
|
|
542
|
+
id: "0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881",
|
|
543
|
+
metaData: "0x5d3c6e60eeff8a05b693b481539e7847dfe33013e7070cdcb387f5c0cac05dfd",
|
|
544
|
+
treasury: "",
|
|
545
|
+
oracle: {
|
|
546
|
+
supra: "",
|
|
547
|
+
switchboard: "",
|
|
548
|
+
pyth: {
|
|
549
|
+
feed: "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43",
|
|
550
|
+
feedObject: "0x9a62b4863bdeaabdc9500fce769cf7e72d5585eeb28a6d26e4cafadc13f76ab2"
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
},
|
|
554
|
+
weth: {
|
|
555
|
+
id: "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",
|
|
556
|
+
metaData: "0x8900e4ceede3363bef086d6b50ca89d816d0e90bf6bc46efefe1f8455e08f50f",
|
|
557
|
+
treasury: "",
|
|
558
|
+
oracle: {
|
|
559
|
+
supra: "",
|
|
560
|
+
switchboard: "",
|
|
561
|
+
pyth: {
|
|
562
|
+
feed: "ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",
|
|
563
|
+
feedObject: "0x9193fd47f9a0ab99b6e365a464c8a9ae30e6150fc37ed2a89c1586631f6fc4ab"
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
},
|
|
567
|
+
wusdc: {
|
|
568
|
+
id: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf",
|
|
569
|
+
metaData: "0x4fbf84f3029bd0c0b77164b587963be957f853eccf834a67bb9ecba6ec80f189",
|
|
570
|
+
treasury: "",
|
|
571
|
+
oracle: {
|
|
572
|
+
supra: "",
|
|
573
|
+
switchboard: "",
|
|
574
|
+
pyth: {
|
|
575
|
+
feed: "eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
|
|
576
|
+
feedObject: "0x5dec622733a204ca27f5a90d8c2fad453cc6665186fd5dff13a83d0b6c9027ab"
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
},
|
|
580
|
+
wusdt: {
|
|
581
|
+
id: "0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c",
|
|
582
|
+
metaData: "0xfb0e3eb97dd158a5ae979dddfa24348063843c5b20eb8381dd5fa7c93699e45c",
|
|
583
|
+
treasury: "",
|
|
584
|
+
oracle: {
|
|
585
|
+
supra: "",
|
|
586
|
+
switchboard: "",
|
|
587
|
+
pyth: {
|
|
588
|
+
feed: "2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b",
|
|
589
|
+
feedObject: "0x985e3db9f93f76ee8bace7c3dd5cc676a096accd5d9e09e9ae0fb6e492b14572"
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
},
|
|
593
|
+
sui: {
|
|
594
|
+
id: "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
595
|
+
metaData: "0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3",
|
|
596
|
+
treasury: "",
|
|
597
|
+
oracle: {
|
|
598
|
+
supra: "",
|
|
599
|
+
switchboard: "0xbca474133638352ba83ccf7b5c931d50f764b09550e16612c9f70f1e21f3f594",
|
|
600
|
+
pyth: {
|
|
601
|
+
feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
602
|
+
feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
},
|
|
606
|
+
afsui: {
|
|
607
|
+
id: "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc",
|
|
608
|
+
metaData: "0x2f9217f533e51334873a39b8026a4aa6919497b47f49d0986a4f1aec66f8a34d",
|
|
609
|
+
treasury: "",
|
|
610
|
+
oracle: {
|
|
611
|
+
supra: "",
|
|
612
|
+
switchboard: "",
|
|
613
|
+
pyth: {
|
|
614
|
+
feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
615
|
+
feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
},
|
|
619
|
+
hasui: {
|
|
620
|
+
id: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",
|
|
621
|
+
metaData: "0x2c5f33af93f6511df699aaaa5822d823aac6ed99d4a0de2a4a50b3afa0172e24",
|
|
622
|
+
treasury: "",
|
|
623
|
+
oracle: {
|
|
624
|
+
supra: "",
|
|
625
|
+
switchboard: "",
|
|
626
|
+
pyth: {
|
|
627
|
+
feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
628
|
+
feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
},
|
|
632
|
+
vsui: {
|
|
633
|
+
id: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",
|
|
634
|
+
metaData: "0xabd84a23467b33854ab25cf862006fd97479f8f6f53e50fe732c43a274d939bd",
|
|
635
|
+
treasury: "",
|
|
636
|
+
oracle: {
|
|
637
|
+
supra: "",
|
|
638
|
+
switchboard: "",
|
|
639
|
+
pyth: {
|
|
640
|
+
feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
641
|
+
feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
},
|
|
645
|
+
sca: {
|
|
646
|
+
id: "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6",
|
|
647
|
+
metaData: "0x5d26a1e9a55c88147ac870bfa31b729d7f49f8804b8b3adfdf3582d301cca844",
|
|
648
|
+
treasury: "",
|
|
649
|
+
oracle: {
|
|
650
|
+
supra: "",
|
|
651
|
+
switchboard: "",
|
|
652
|
+
pyth: {
|
|
653
|
+
feed: "7e17f0ac105abe9214deb9944c30264f5986bf292869c6bd8e8da3ccd92d79bc",
|
|
654
|
+
feedObject: "0xf6de1d3279a269a597d813cbaca59aa906543ab9a8c64e84a4722f1a20863985"
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
},
|
|
659
|
+
oracles: {
|
|
660
|
+
xOracle: "0x93d5bf0936b71eb27255941e532fac33b5a5c7759e377b4923af0a1359ad494f",
|
|
661
|
+
xOracleCap: "0x1edeae568fde99e090dbdec4bcdbd33a15f53a1ce1f87aeef1a560dedf4b4a90",
|
|
662
|
+
supra: { registry: "", registryCap: "", holder: "" },
|
|
663
|
+
switchboard: { registry: "", registryCap: "" },
|
|
664
|
+
pyth: {
|
|
665
|
+
registry: "0xedc293f9413a5a7a5d53bdba1fd889d0a4030894469228f0acdae4aa3c55a213",
|
|
666
|
+
registryCap: "0xbcb07141eb1f7e01fbda4130ecf5f5adaeabb77f5d9c32158b7532bcd2197acd",
|
|
667
|
+
state: "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8",
|
|
668
|
+
wormhole: "0x5306f64e312b581766351c07af79c72fcb1cd25147157fdc2f8ad76de9a3fb6a",
|
|
669
|
+
wormholeState: "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c"
|
|
670
|
+
}
|
|
671
|
+
},
|
|
672
|
+
packages: {
|
|
673
|
+
coinDecimalsRegistry: {
|
|
674
|
+
id: "0xca5a5a62f01c79a104bf4d31669e29daa387f325c241de4edbe30986a9bc8b0d",
|
|
675
|
+
upgradeCap: "0x34e76a945d29f195bc53ca704fa70877d1cf3a5d7bbfdda1b13e633fff13c0f6"
|
|
676
|
+
},
|
|
677
|
+
math: {
|
|
678
|
+
id: "0xad013d5fde39e15eabda32b3dbdafd67dac32b798ce63237c27a8f73339b9b6f",
|
|
679
|
+
upgradeCap: "0x3a329598231de02e6135c62284b66005b41cad1d9ab7ca2dc79c08293aba2ec6"
|
|
680
|
+
},
|
|
681
|
+
whitelist: {
|
|
682
|
+
id: "0x1318fdc90319ec9c24df1456d960a447521b0a658316155895014a6e39b5482f",
|
|
683
|
+
upgradeCap: "0xf5a22aea23db664f7b69855b6a546747f17c1ec4230319cfc17225e462b05761"
|
|
684
|
+
},
|
|
685
|
+
x: {
|
|
686
|
+
id: "0x779b5c547976899f5474f3a5bc0db36ddf4697ad7e5a901db0415c2281d28162",
|
|
687
|
+
upgradeCap: "0x3f203f6fff6a69d151e4f1cd931f22b68c489ef2759765662fc7baf673943c9e"
|
|
688
|
+
},
|
|
689
|
+
protocol: {
|
|
690
|
+
id: "0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1",
|
|
691
|
+
upgradeCap: "0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a"
|
|
692
|
+
},
|
|
693
|
+
// protocol: {
|
|
694
|
+
// id: '0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e',
|
|
695
|
+
// upgradeCap:
|
|
696
|
+
// '0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a',
|
|
697
|
+
// },
|
|
698
|
+
protocolWhitelist: {
|
|
699
|
+
id: "0x4c262d9343dac53ecb28f482a2a3f62c73d0ebac5b5f03d57383d56ff219acdf",
|
|
700
|
+
upgradeCap: "0x4a5e88a75039b00988f633f811f58117f31b8627a46bf822aa114d9010049449"
|
|
701
|
+
},
|
|
702
|
+
// query: {
|
|
703
|
+
// id: '0xb8d603a39114a5efef3dd0bf84df0bed1be1fbd39b78b7dd6e8a61ccc5e6006f',
|
|
704
|
+
// upgradeCap:
|
|
705
|
+
// '0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f',
|
|
706
|
+
// },
|
|
707
|
+
query: {
|
|
708
|
+
id: "0xe4f9d62d17746d5b9dbf0d5557747430021a71575780b515161210cdba0a4c1c",
|
|
709
|
+
upgradeCap: "0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f"
|
|
710
|
+
},
|
|
711
|
+
supra: { id: "", upgradeCap: "" },
|
|
712
|
+
pyth: {
|
|
713
|
+
id: "0x910f30cbc7f601f75a5141a01265cd47c62d468707c5e1aecb32a18f448cb25a",
|
|
714
|
+
upgradeCap: "0xdf0ffbae1ea5bb25fbca5efba433dcf00c7cced65679af2f04728901275c6157"
|
|
715
|
+
},
|
|
716
|
+
switchboard: { id: "", upgradeCap: "" },
|
|
717
|
+
xOracle: {
|
|
718
|
+
id: "0x1478a432123e4b3d61878b629f2c692969fdb375644f1251cd278a4b1e7d7cd6",
|
|
719
|
+
upgradeCap: "0x0f928a6b2e26b73330fecaf9b44acfc9800a4a9794d6415c2a3153bc70e3c1f0"
|
|
720
|
+
},
|
|
721
|
+
testCoin: { id: "", upgradeCap: "" }
|
|
722
|
+
}
|
|
723
|
+
},
|
|
724
|
+
spool: {
|
|
725
|
+
// id: '0x7c4fdabe81c31b19a45d1e572a52a539997a90903fbb5bfab71480abe0fa62c3',
|
|
726
|
+
id: "0x1742655fe5872dfa6456673f9e38612a4965e6979e6cd7696a7f1225f28bae21",
|
|
727
|
+
adminCap: "0xdd8a047cbbf802bfcde5288b8ef1910965d789cc614da11d39af05fca0bd020a",
|
|
728
|
+
// object:
|
|
729
|
+
// '0xe87f1b2d498106a2c61421cec75b7b5c5e348512b0dc263949a0e7a3c256571a',
|
|
730
|
+
object: "0x1742655fe5872dfa6456673f9e38612a4965e6979e6cd7696a7f1225f28bae21",
|
|
731
|
+
pools: {
|
|
732
|
+
sweth: {
|
|
733
|
+
id: "0xeec40beccb07c575bebd842eeaabb835f77cd3dab73add433477e57f583a6787",
|
|
734
|
+
rewardPoolId: "0x957de68a18d87817de8309b30c1ec269a4d87ae513abbeed86b5619cb9ce1077"
|
|
735
|
+
},
|
|
736
|
+
ssui: {
|
|
737
|
+
// id: '0x4f0ba970d3c11db05c8f40c64a15b6a33322db3702d634ced6536960ab6f3ee4',
|
|
738
|
+
id: "0xb9617f83c06ebdeac0a8834782b1015e1cc7ea23739e30c132c4bfb95c37a579",
|
|
739
|
+
rewardPoolId: (
|
|
740
|
+
// '0x162250ef72393a4ad3d46294c4e1bdfcb03f04c869d390e7efbfc995353a7ee9',
|
|
741
|
+
"0xc3206071a8d43212efb6e3b5504f2321f8df97ab122b466c0bc7cfdf398dc13a"
|
|
742
|
+
)
|
|
743
|
+
},
|
|
744
|
+
swusdc: {
|
|
745
|
+
// id: '0x4ace6648ddc64e646ba47a957c562c32c9599b3bba8f5ac1aadb2ae23a2f8ca0',
|
|
746
|
+
id: "0xf1b383b9cf2e9f515fc69567df1053098f273849d09cd84b0278a773429bd2b2",
|
|
747
|
+
rewardPoolId: (
|
|
748
|
+
// '0xf4268cc9b9413b9bfe09e8966b8de650494c9e5784bf0930759cfef4904daff8',
|
|
749
|
+
"0xc71c53ee6505d928ba15bea4fe4f45d98c9c31eced94b72d00a7827d4b7ba3ff"
|
|
750
|
+
)
|
|
751
|
+
},
|
|
752
|
+
swusdt: {
|
|
753
|
+
// id: '0xcb328f7ffa7f9342ed85af3fdb2f22919e1a06dfb2f713c04c73543870d7548f',
|
|
754
|
+
id: "0xb5567dfa5c7fc17a249e959732664c50713dd8c23db1a11376b27df800c17418",
|
|
755
|
+
rewardPoolId: (
|
|
756
|
+
// '0x2c9f934d67a5baa586ceec2cc24163a2f049a6af3d5ba36b84d8ac40f25c4080',
|
|
757
|
+
"0x60768b0687ff0235e376a039709a683e4c436098785e473b67b32dbab47b69ab"
|
|
758
|
+
)
|
|
759
|
+
},
|
|
760
|
+
scetus: {
|
|
761
|
+
id: "0xac1bb13bf4472a637c18c2415fb0e3c1227ea2bcf35242e50563c98215bd298e",
|
|
762
|
+
rewardPoolId: "0x6835c1224126a45086fc6406adc249e3f30df18d779ca4f4e570e38716a17f3f"
|
|
763
|
+
},
|
|
764
|
+
safsui: {
|
|
765
|
+
// id: '0xeedf438abcaa6ce4d9625ffca110920592d5867e4c5637d84ad9f466c4feb800',
|
|
766
|
+
id: "0xc568bb4c991258e839aa54802ecda04fcd9838c826bc3b42b40af81b23c458c8",
|
|
767
|
+
rewardPoolId: (
|
|
768
|
+
// '0x89255a2f86ed7fbfef35ab8b7be48cc7667015975be2685dd9a55a9a64baf76e',
|
|
769
|
+
"0x389a3cbeda742b918941bb24fd00e077bad3367484394d6234f8209b9a6aa03d"
|
|
770
|
+
)
|
|
771
|
+
},
|
|
772
|
+
shasui: {
|
|
773
|
+
// id: '0xa6148bc1b623e936d39a952ceb5bea79e8b37228a8f595067bf1852efd3c34aa',
|
|
774
|
+
id: "0x93f3f4499bf89f2d05ddc1f8b15f51701a7c6c4d0ac0b9c3bc99462cbbd8e321",
|
|
775
|
+
rewardPoolId: (
|
|
776
|
+
// '0x6f3563644d3e2ef13176dbf9d865bd93479df60ccbe07b7e66db57f6309f5a66',
|
|
777
|
+
"0x94cee1be7f5ff34193f3aabef0b14142cb28af4d905fe487a9a7d85a15edb6aa"
|
|
778
|
+
)
|
|
779
|
+
},
|
|
780
|
+
svsui: {
|
|
781
|
+
// id: '0x69ce8e537e750a95381e6040794afa5ab1758353a1a2e1de7760391b01f91670',
|
|
782
|
+
id: "0xa970e9087f80cb59e9299b8e7af7175d977ad6c9af0322aa4440e138fbd7ae00",
|
|
783
|
+
rewardPoolId: (
|
|
784
|
+
// '0xbca914adce058ad0902c7f3cfcd698392a475f00dcfdc3f76001d0370b98777a',
|
|
785
|
+
"0x38eee9699c4fc132a6623e54b865f047df4fc6eb83af807300f44e8f4b235ff0"
|
|
786
|
+
)
|
|
787
|
+
}
|
|
788
|
+
},
|
|
789
|
+
config: ""
|
|
790
|
+
},
|
|
791
|
+
borrowIncentive: {
|
|
792
|
+
id: "0x6152f696fc3a658f33c4b891764731a59153125ffedfa8bff7167c42823f58a9",
|
|
793
|
+
adminCap: "0xc486afa253646f4d381e81d7f1df8aa4723b845a6bb356f69bad635ffefffe2c",
|
|
794
|
+
object: "0x002875153e09f8145ab63527bc85c00f2bd102e12f9573c47f8cdf1a1cb62934",
|
|
795
|
+
query: "0x529edc54a3dce2207703ceebbccb0ac14133f7825c1f528775ba0d85a4063489",
|
|
796
|
+
incentivePools: "0x6547e143d406b5ccd5f46aae482497de279cc1a68c406f701df70a05f9212ab4",
|
|
797
|
+
incentiveAccounts: "0xc4701fdbc1c92f9a636d334d66012b3027659e9fb8aff27279a82edfb6b77d02",
|
|
798
|
+
config: "0xdf5d04b4691cc67e82fd4db8394d89ff44823a9de29716c924f74bb4f11cc1f7"
|
|
799
|
+
},
|
|
800
|
+
referral: {
|
|
801
|
+
id: "0xa3654ebb63eb06c0f4ff52f8aa6512df9f164f7772bdf15dac3709bd3798dda9",
|
|
802
|
+
object: "0x5658d4bf5ddcba27e4337b4262108b3ad1716643cac8c2054ac341538adc72ec",
|
|
803
|
+
adminCap: "0xc5dc06b9074291259f2cac460c940012c781c4430e42125c541cc43101c3bcbd",
|
|
804
|
+
referralBindings: "0xf63299d58789d99de94092b9011323466e55ca0c1ea1a7a3786a589af46e1c09",
|
|
805
|
+
bindingTableId: "0x1c8202b17267ec8d6cf97ca013615354181a04f179570e42601ff2dae19294b1",
|
|
806
|
+
referralRevenuePool: "0x6abd852caf90769c1b185cdf636d841673fa95528f0550f018b8a138bd283c07",
|
|
807
|
+
revenueTableId: "0x595baa3654c297bff84ab7786a2d250f019cefc66e8df8e89fd9d41e02bd30dd",
|
|
808
|
+
referralTiers: "0x962cb903d8d7346190c5204785ccbb91b61086aa764f674c8145df82335cf83e",
|
|
809
|
+
tiersTableId: "0xeac755a7a8b7798530905ac79e8c114f19d0f130f6eab012954f08faac29c75d",
|
|
810
|
+
// authorizedWitnessList:
|
|
811
|
+
// '0xf21b0ed043c9bb70842c0129159f4943dbcc3c9ef2f2f808af65f8be25cfd20e',
|
|
812
|
+
authorizedWitnessList: "0x9d6223dc52015b8a3986a573590ef2af8f1b8f3e4685513888c052f001b87e7f",
|
|
813
|
+
version: "0x1bd4b7285f72e11c316b828c7c47b3f4da18dcec9f9b3dba6d8629cbb6f93e5e"
|
|
814
|
+
},
|
|
815
|
+
vesca: {
|
|
816
|
+
id: "0xb15b6e0cdd85afb5028bea851dd249405e734d800a259147bbc24980629723a4",
|
|
817
|
+
object: "0xb15b6e0cdd85afb5028bea851dd249405e734d800a259147bbc24980629723a4",
|
|
818
|
+
adminCap: "0x8ffa76135c5b85c5fbd73a6448a4a733d826cb63a267ab817656acb77c72d4a5",
|
|
819
|
+
tableId: "0xe3153b2bf124be0b86cb8bd468346a861efd0da52fc42197b54d2f616488a311",
|
|
820
|
+
table: "0x611cb8d9d4d90867467b5ebdf4cc447a0047ed5b01334a28a29fcfe733e3d609",
|
|
821
|
+
treasury: "0xe8c112c09b88158dc6c8e23d1fbae5b3c7136cdee54b7dafc08e65db28c4a5bc",
|
|
822
|
+
config: "0xe0a2ff281e73c1d53cfa85807080f87e833e4f1a7f93dcf8800b3865269a76b9"
|
|
823
|
+
},
|
|
824
|
+
loyaltyProgram: {
|
|
825
|
+
id: "0xd17bcf8b5a59652c36225d478564a8593ae0ed7d650bcacdda1d6fe179127907",
|
|
826
|
+
object: "0xd17bcf8b5a59652c36225d478564a8593ae0ed7d650bcacdda1d6fe179127907",
|
|
827
|
+
rewardPool: "0xf9c090492ef476bd542109d0913ffe871cbfa28578b7114eca2a8c0e5671786f",
|
|
828
|
+
userRewardTableId: "0x748a80395849ed37db1b0e14f2ab5d1d96458d2359ab3a84eb079d0f4ac7cf2e"
|
|
829
|
+
},
|
|
830
|
+
scoin: {
|
|
831
|
+
id: "0xad2ca2aa5089df94bb2d444d5eb3520378c2f2dfb3a0bd2a2c994145ac4b0a53",
|
|
832
|
+
coins: {
|
|
833
|
+
ssui: {
|
|
834
|
+
coinType: "0xfac769100bccc0caebcf4f4e2d00ac2f8883f07f724be28940df90605f5e7e9a::scallop_sui::SCALLOP_SUI",
|
|
835
|
+
treasury: "0x9cb4551b36c17d37e19d700147fa819ea1c487ff8bcf18374de2cceb2e9d4845"
|
|
836
|
+
},
|
|
837
|
+
scetus: {
|
|
838
|
+
coinType: "0x8b71e6d323ed78515af2bead13bf3d0da1562ba4a99234eb7c4f14fd39ef0427::scallop_cetus::SCALLOP_CETUS",
|
|
839
|
+
treasury: "0xd786f4b2d26278cc7911a3445b1b085eab60f269ef9dbb6b87e803d52f155003"
|
|
840
|
+
},
|
|
841
|
+
ssca: {
|
|
842
|
+
coinType: "0x0a9d3c6c9af9f6e8def82921541bcbd17f73ed31bed3adcb684f2a4c267e42f0::scallop_sca::SCALLOP_SCA",
|
|
843
|
+
treasury: "0xe818636d1d6c46d6ea1a2dce9d94696d7cbc18ce27451b603eeaa47aba8d75e0"
|
|
844
|
+
},
|
|
845
|
+
swusdc: {
|
|
846
|
+
coinType: "0xaedc3ab75db8680b81a755015fa90124d217be93457b893c05bac033817defaf::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
847
|
+
treasury: "0xfc6971648f867f7fd6928d1b873af71577e2eaf2c7543ef8bc82c431d833ae78"
|
|
848
|
+
},
|
|
849
|
+
swusdt: {
|
|
850
|
+
coinType: "0xbf02fc87ddc104b342ad8414c85ceadf5b0c823c055a06fb0ed776272c01a52a::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
|
|
851
|
+
treasury: "0xb9593e2c3a0ba796ee815012b75ae46468ea78cda0188b9ac6816efe65503521"
|
|
852
|
+
},
|
|
853
|
+
sweth: {
|
|
854
|
+
coinType: "0x27d54f43e3eda701be56b82e5756e41c84467cd202f5cf713d5f9e45a9f1b6bc::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
|
|
855
|
+
treasury: "0x032b4c8fac94c038dbe986f7587e9b1e4ef580b5ee06d2ef249d85459b7ef05d"
|
|
856
|
+
},
|
|
857
|
+
safsui: {
|
|
858
|
+
coinType: "0xb75b46d975d8d80670b53a6bee90baaa8ce2e0b7d397f079447d641eef6b44ad::scallop_af_sui::SCALLOP_AF_SUI",
|
|
859
|
+
treasury: "0x21450ef0570ef3d224ffa3b873ab802e439ece7b93cc7efad10ae0c1e3b3fcfe"
|
|
860
|
+
},
|
|
861
|
+
shasui: {
|
|
862
|
+
coinType: "0xd973a723874e2c7cde196602a79155a1343a933f8cf87d9b1bb7408bc1acbc58::scallop_ha_sui::SCALLOP_HA_SUI",
|
|
863
|
+
treasury: "0xf822fc1402207e47d2e3ba8ff6e1e594bf1de777dc5ebd2744619cd2726e3b0d"
|
|
864
|
+
},
|
|
865
|
+
svsui: {
|
|
866
|
+
coinType: "0x97023a317320c4498cc4cd239dd02fd30c28246e5e8f81325d63f2bd8d70f6b3::scallop_v_sui::SCALLOP_V_SUI",
|
|
867
|
+
treasury: "0x327114f0bf3559d7e2de10282147ed76a236c7c6775029165c4db09a6062ead6\u0192"
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
};
|
|
872
|
+
|
|
873
|
+
// src/constants/tokenBucket.ts
|
|
874
|
+
var DEFAULT_TOKENS_PER_INTERVAL = 10;
|
|
875
|
+
var DEFAULT_INTERVAL_IN_MS = 300;
|
|
876
|
+
|
|
877
|
+
// src/constants/vesca.ts
|
|
878
|
+
var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
|
|
879
|
+
var MAX_LOCK_ROUNDS = 1460;
|
|
880
|
+
var MAX_LOCK_DURATION = MAX_LOCK_ROUNDS * UNLOCK_ROUND_DURATION;
|
|
881
|
+
var MIN_INITIAL_LOCK_AMOUNT = 1e10;
|
|
882
|
+
var MIN_TOP_UP_AMOUNT = 1e9;
|
|
883
|
+
|
|
884
|
+
// src/models/scallopAddress.ts
|
|
885
|
+
import { SuiKit } from "@scallop-io/sui-kit";
|
|
886
|
+
|
|
887
|
+
// src/models/scallopCache.ts
|
|
888
|
+
import { QueryClient } from "@tanstack/query-core";
|
|
889
|
+
import {
|
|
890
|
+
SuiTxBlock,
|
|
891
|
+
normalizeStructTag as normalizeStructTag2
|
|
892
|
+
} from "@scallop-io/sui-kit";
|
|
893
|
+
|
|
894
|
+
// src/utils/builder.ts
|
|
895
|
+
var requireSender = (txBlock) => {
|
|
896
|
+
const sender = txBlock.blockData.sender;
|
|
897
|
+
if (!sender) {
|
|
898
|
+
throw new Error("Sender is required");
|
|
899
|
+
}
|
|
900
|
+
return sender;
|
|
901
|
+
};
|
|
902
|
+
var checkVesca = (prevUnlockAtInMillisTimestamp) => {
|
|
903
|
+
if (prevUnlockAtInMillisTimestamp === void 0) {
|
|
904
|
+
throw new Error("veSca not found");
|
|
905
|
+
}
|
|
906
|
+
};
|
|
907
|
+
var checkVescaExpired = (prevUnlockAtInMillisTimestamp) => {
|
|
908
|
+
if (prevUnlockAtInMillisTimestamp <= (/* @__PURE__ */ new Date()).getTime()) {
|
|
909
|
+
throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
var checkExtendLockPeriod = (lockPeriodInDays, newUnlockAtInSecondTimestamp, prevUnlockAtInMillisTimestamp) => {
|
|
913
|
+
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
914
|
+
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
915
|
+
const prevUnlockAtInSecondTimestamp = Math.floor(
|
|
916
|
+
prevUnlockAtInMillisTimestamp / 1e3
|
|
917
|
+
);
|
|
918
|
+
if (lockPeriodInDays < 1) {
|
|
919
|
+
throw new Error("Minimum lock period is 1 day");
|
|
920
|
+
}
|
|
921
|
+
const availableLockPeriodInDays = Math.floor(
|
|
922
|
+
(newUnlockAtInSecondTimestamp - prevUnlockAtInSecondTimestamp) / UNLOCK_ROUND_DURATION
|
|
923
|
+
);
|
|
924
|
+
if (lockPeriodInDays > availableLockPeriodInDays) {
|
|
925
|
+
throw new Error(
|
|
926
|
+
`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}`
|
|
927
|
+
);
|
|
928
|
+
}
|
|
929
|
+
};
|
|
930
|
+
var checkLockSca = (scaAmountOrCoin, lockPeriodInDays, newUnlockAtInSecondTimestamp, prevUnlockAtInMillisTimestamp) => {
|
|
931
|
+
const prevUnlockAtInSecondTimestamp = prevUnlockAtInMillisTimestamp ? Math.floor(prevUnlockAtInMillisTimestamp / 1e3) : void 0;
|
|
932
|
+
const isInitialLock = !prevUnlockAtInSecondTimestamp;
|
|
933
|
+
const isLockExpired = !isInitialLock && prevUnlockAtInSecondTimestamp * 1e3 <= (/* @__PURE__ */ new Date()).getTime();
|
|
934
|
+
if (isInitialLock || isLockExpired) {
|
|
935
|
+
if (scaAmountOrCoin !== void 0 && lockPeriodInDays !== void 0) {
|
|
936
|
+
if (lockPeriodInDays <= 0) {
|
|
937
|
+
throw new Error("Lock period must be greater than 0");
|
|
938
|
+
}
|
|
939
|
+
if (typeof scaAmountOrCoin === "number" && scaAmountOrCoin < MIN_INITIAL_LOCK_AMOUNT) {
|
|
940
|
+
throw new Error(
|
|
941
|
+
`Minimum lock amount for ${isLockExpired ? "renewing expired veSca" : "initial lock"} is 10 SCA`
|
|
942
|
+
);
|
|
943
|
+
}
|
|
944
|
+
const extendLockPeriodInSecond = lockPeriodInDays * UNLOCK_ROUND_DURATION;
|
|
945
|
+
if (extendLockPeriodInSecond > MAX_LOCK_DURATION) {
|
|
946
|
+
throw new Error(
|
|
947
|
+
`Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS} days)`
|
|
948
|
+
);
|
|
949
|
+
}
|
|
950
|
+
} else {
|
|
951
|
+
throw new Error(
|
|
952
|
+
`SCA amount and lock period is required for ${isLockExpired ? "renewing expired veSca" : "initial lock"}`
|
|
953
|
+
);
|
|
954
|
+
}
|
|
955
|
+
} else {
|
|
956
|
+
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
957
|
+
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
958
|
+
if (typeof scaAmountOrCoin === "number" && scaAmountOrCoin < MIN_TOP_UP_AMOUNT) {
|
|
959
|
+
throw new Error("Minimum top up amount is 1 SCA");
|
|
960
|
+
}
|
|
961
|
+
if (newUnlockAtInSecondTimestamp && lockPeriodInDays) {
|
|
962
|
+
checkExtendLockPeriod(
|
|
963
|
+
lockPeriodInDays,
|
|
964
|
+
newUnlockAtInSecondTimestamp,
|
|
965
|
+
prevUnlockAtInMillisTimestamp
|
|
966
|
+
);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
};
|
|
970
|
+
var checkExtendLockAmount = (scaAmount, prevUnlockAtInMillisTimestamp) => {
|
|
971
|
+
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
972
|
+
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
973
|
+
if (scaAmount < MIN_TOP_UP_AMOUNT) {
|
|
974
|
+
throw new Error("Minimum top up amount is 1 SCA");
|
|
975
|
+
}
|
|
976
|
+
const isInitialLock = !prevUnlockAtInMillisTimestamp;
|
|
977
|
+
const isLockExpired = !isInitialLock && prevUnlockAtInMillisTimestamp <= (/* @__PURE__ */ new Date()).getTime();
|
|
978
|
+
if (isLockExpired) {
|
|
979
|
+
throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
|
|
980
|
+
}
|
|
981
|
+
};
|
|
982
|
+
var checkRenewExpiredVeSca = (scaAmount, lockPeriodInDays, prevUnlockAtInMillisTimestamp) => {
|
|
983
|
+
if (!prevUnlockAtInMillisTimestamp || prevUnlockAtInMillisTimestamp > (/* @__PURE__ */ new Date()).getTime()) {
|
|
984
|
+
throw new Error("Renew method can only be used for expired veSca");
|
|
985
|
+
}
|
|
986
|
+
if (scaAmount < MIN_INITIAL_LOCK_AMOUNT) {
|
|
987
|
+
throw new Error("Minimum lock amount for renewing expired vesca 10 SCA");
|
|
988
|
+
}
|
|
989
|
+
const extendLockPeriodInSecond = lockPeriodInDays * UNLOCK_ROUND_DURATION;
|
|
990
|
+
if (extendLockPeriodInSecond >= MAX_LOCK_DURATION - UNLOCK_ROUND_DURATION) {
|
|
991
|
+
throw new Error(
|
|
992
|
+
`Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS - 1} days)`
|
|
993
|
+
);
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
|
|
997
|
+
// src/utils/query.ts
|
|
998
|
+
import BigNumber from "bignumber.js";
|
|
999
|
+
import { normalizeStructTag, parseStructTag } from "@mysten/sui/utils";
|
|
1000
|
+
var parseOriginMarketPoolData = (originMarketPoolData) => {
|
|
1001
|
+
return {
|
|
1002
|
+
coinType: normalizeStructTag(originMarketPoolData.type.name),
|
|
1003
|
+
// Parse origin data required for basic calculations.
|
|
1004
|
+
maxBorrowRate: Number(originMarketPoolData.maxBorrowRate.value) / 2 ** 32,
|
|
1005
|
+
borrowRate: Number(originMarketPoolData.interestRate.value) / 2 ** 32,
|
|
1006
|
+
borrowRateScale: Number(originMarketPoolData.interestRateScale),
|
|
1007
|
+
borrowIndex: Number(originMarketPoolData.borrowIndex),
|
|
1008
|
+
lastUpdated: Number(originMarketPoolData.lastUpdated),
|
|
1009
|
+
cashAmount: Number(originMarketPoolData.cash),
|
|
1010
|
+
debtAmount: Number(originMarketPoolData.debt),
|
|
1011
|
+
marketCoinSupplyAmount: Number(originMarketPoolData.marketCoinSupply),
|
|
1012
|
+
reserveAmount: Number(originMarketPoolData.reserve),
|
|
1013
|
+
reserveFactor: Number(originMarketPoolData.reserveFactor.value) / 2 ** 32,
|
|
1014
|
+
borrowWeight: Number(originMarketPoolData.borrowWeight.value) / 2 ** 32,
|
|
1015
|
+
borrowFee: Number(originMarketPoolData.borrowFeeRate.value) / 2 ** 32,
|
|
1016
|
+
// Parse origin data required for additional display.
|
|
1017
|
+
baseBorrowRate: Number(originMarketPoolData.baseBorrowRatePerSec.value) / 2 ** 32,
|
|
1018
|
+
borrowRateOnHighKink: Number(originMarketPoolData.borrowRateOnHighKink.value) / 2 ** 32,
|
|
1019
|
+
borrowRateOnMidKink: Number(originMarketPoolData.borrowRateOnMidKink.value) / 2 ** 32,
|
|
1020
|
+
highKink: Number(originMarketPoolData.highKink.value) / 2 ** 32,
|
|
1021
|
+
midKink: Number(originMarketPoolData.midKink.value) / 2 ** 32,
|
|
1022
|
+
minBorrowAmount: Number(originMarketPoolData.minBorrowAmount)
|
|
1023
|
+
};
|
|
1024
|
+
};
|
|
1025
|
+
var calculateMarketPoolData = (utils, parsedMarketPoolData) => {
|
|
1026
|
+
const poolCoinName = utils.parseCoinNameFromType(
|
|
1027
|
+
parsedMarketPoolData.coinType
|
|
1028
|
+
);
|
|
1029
|
+
const coinDecimal = utils.getCoinDecimal(poolCoinName);
|
|
1030
|
+
const borrowYearFactor = 24 * 365 * 3600;
|
|
1031
|
+
const baseBorrowApr = parsedMarketPoolData.baseBorrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
1032
|
+
const borrowAprOnHighKink = parsedMarketPoolData.borrowRateOnHighKink * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
1033
|
+
const borrowAprOnMidKink = parsedMarketPoolData.borrowRateOnMidKink * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
1034
|
+
const maxBorrowApr = parsedMarketPoolData.maxBorrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
1035
|
+
const borrowApr = parsedMarketPoolData.borrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
1036
|
+
const timeDelta = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedMarketPoolData.lastUpdated;
|
|
1037
|
+
const borrowIndexDelta = BigNumber(parsedMarketPoolData.borrowIndex).multipliedBy(
|
|
1038
|
+
BigNumber(timeDelta).multipliedBy(parsedMarketPoolData.borrowRate)
|
|
1039
|
+
).dividedBy(parsedMarketPoolData.borrowRateScale);
|
|
1040
|
+
const currentBorrowIndex = BigNumber(parsedMarketPoolData.borrowIndex).plus(
|
|
1041
|
+
borrowIndexDelta
|
|
1042
|
+
);
|
|
1043
|
+
const growthInterest = BigNumber(currentBorrowIndex).dividedBy(parsedMarketPoolData.borrowIndex).minus(1);
|
|
1044
|
+
const increasedDebtAmount = BigNumber(
|
|
1045
|
+
parsedMarketPoolData.debtAmount
|
|
1046
|
+
).multipliedBy(growthInterest);
|
|
1047
|
+
const borrowAmount = increasedDebtAmount.plus(
|
|
1048
|
+
parsedMarketPoolData.debtAmount
|
|
1049
|
+
);
|
|
1050
|
+
const borrowCoin = borrowAmount.shiftedBy(-1 * coinDecimal);
|
|
1051
|
+
const reserveAmount = BigNumber(parsedMarketPoolData.reserveAmount).plus(
|
|
1052
|
+
increasedDebtAmount.multipliedBy(parsedMarketPoolData.reserveFactor)
|
|
1053
|
+
);
|
|
1054
|
+
const reserveCoin = reserveAmount.shiftedBy(-1 * coinDecimal);
|
|
1055
|
+
const supplyAmount = BigNumber(borrowAmount).plus(
|
|
1056
|
+
Math.max(parsedMarketPoolData.cashAmount - reserveAmount.toNumber(), 0)
|
|
1057
|
+
);
|
|
1058
|
+
const supplyCoin = supplyAmount.shiftedBy(-1 * coinDecimal);
|
|
1059
|
+
let utilizationRate = BigNumber(borrowAmount).dividedBy(supplyAmount);
|
|
1060
|
+
utilizationRate = utilizationRate.isFinite() ? utilizationRate : BigNumber(0);
|
|
1061
|
+
let supplyApr = BigNumber(borrowApr).multipliedBy(utilizationRate).multipliedBy(1 - parsedMarketPoolData.reserveFactor);
|
|
1062
|
+
supplyApr = supplyApr.isFinite() ? supplyApr : BigNumber(0);
|
|
1063
|
+
let conversionRate = supplyAmount.dividedBy(
|
|
1064
|
+
parsedMarketPoolData.marketCoinSupplyAmount
|
|
1065
|
+
);
|
|
1066
|
+
conversionRate = conversionRate.isFinite() && !conversionRate.isNaN() ? conversionRate : BigNumber(1);
|
|
1067
|
+
return {
|
|
1068
|
+
baseBorrowApr,
|
|
1069
|
+
baseBorrowApy: utils.parseAprToApy(baseBorrowApr),
|
|
1070
|
+
borrowAprOnHighKink,
|
|
1071
|
+
borrowApyOnHighKink: utils.parseAprToApy(borrowAprOnHighKink),
|
|
1072
|
+
borrowAprOnMidKink,
|
|
1073
|
+
borrowApyOnMidKink: utils.parseAprToApy(borrowAprOnMidKink),
|
|
1074
|
+
maxBorrowApr,
|
|
1075
|
+
maxBorrowApy: utils.parseAprToApy(maxBorrowApr),
|
|
1076
|
+
borrowApr: Math.min(borrowApr, maxBorrowApr),
|
|
1077
|
+
borrowApy: Math.min(
|
|
1078
|
+
utils.parseAprToApy(borrowApr),
|
|
1079
|
+
utils.parseAprToApy(maxBorrowApr)
|
|
1080
|
+
),
|
|
1081
|
+
borrowIndex: currentBorrowIndex.toNumber(),
|
|
588
1082
|
growthInterest: growthInterest.toNumber(),
|
|
589
1083
|
supplyAmount: supplyAmount.toNumber(),
|
|
590
1084
|
supplyCoin: supplyCoin.toNumber(),
|
|
@@ -933,676 +1427,280 @@ var parseDataFromPythPriceFeed = (feed, address) => {
|
|
|
933
1427
|
});
|
|
934
1428
|
if (assetCoinName) {
|
|
935
1429
|
const price = feed.price.price * 10 ** feed.price.expo;
|
|
936
|
-
return {
|
|
937
|
-
coinName: assetCoinName,
|
|
938
|
-
price,
|
|
939
|
-
publishTime: Number(feed.price.publishTime) * 10 ** 3
|
|
940
|
-
};
|
|
941
|
-
} else {
|
|
942
|
-
throw new Error("Invalid feed id");
|
|
943
|
-
}
|
|
944
|
-
};
|
|
945
|
-
var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
|
|
946
|
-
const unlockDate = new Date(unlockAtInSecondTimestamp * 1e3);
|
|
947
|
-
const closestTwelveAM = new Date(unlockAtInSecondTimestamp * 1e3);
|
|
948
|
-
closestTwelveAM.setUTCHours(0, 0, 0, 0);
|
|
949
|
-
if (unlockDate.getUTCHours() >= 0) {
|
|
950
|
-
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() + 1);
|
|
951
|
-
}
|
|
952
|
-
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
953
|
-
if (closestTwelveAM.getTime() - now > MAX_LOCK_DURATION * 1e3) {
|
|
954
|
-
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() - 1);
|
|
955
|
-
}
|
|
956
|
-
return Math.floor(closestTwelveAM.getTime() / 1e3);
|
|
957
|
-
};
|
|
958
|
-
|
|
959
|
-
// src/constants/tokenBucket.ts
|
|
960
|
-
var DEFAULT_TOKENS_PER_INTERVAL = 50;
|
|
961
|
-
var DEFAULT_INTERVAL_IN_MS = 300;
|
|
962
|
-
|
|
963
|
-
// src/utils/tokenBucket.ts
|
|
964
|
-
var TokenBucket = class {
|
|
965
|
-
constructor(tokensPerInterval, intervalInMs) {
|
|
966
|
-
this.tokensPerInterval = tokensPerInterval;
|
|
967
|
-
this.interval = intervalInMs;
|
|
968
|
-
this.tokens = tokensPerInterval;
|
|
969
|
-
this.lastRefill = Date.now();
|
|
970
|
-
}
|
|
971
|
-
refill() {
|
|
972
|
-
const now = Date.now();
|
|
973
|
-
const elapsed = now - this.lastRefill;
|
|
974
|
-
if (elapsed > this.interval) {
|
|
975
|
-
const tokensToAdd = Math.floor(elapsed / this.interval) * this.tokensPerInterval;
|
|
976
|
-
this.tokens = Math.min(this.tokens + tokensToAdd, this.tokensPerInterval);
|
|
977
|
-
this.lastRefill = now;
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
removeTokens(count) {
|
|
981
|
-
this.refill();
|
|
982
|
-
if (this.tokens >= count) {
|
|
983
|
-
this.tokens -= count;
|
|
984
|
-
return true;
|
|
985
|
-
}
|
|
986
|
-
return false;
|
|
987
|
-
}
|
|
988
|
-
};
|
|
989
|
-
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 15, backoffFactor = 1.25) => {
|
|
990
|
-
let retries = 0;
|
|
991
|
-
const tryRequest = async () => {
|
|
992
|
-
if (tokenBucket.removeTokens(1)) {
|
|
993
|
-
try {
|
|
994
|
-
const result = await fn();
|
|
995
|
-
if (result && result.status === 429) {
|
|
996
|
-
throw new Error("Unexpected status code: 429");
|
|
997
|
-
}
|
|
998
|
-
return result;
|
|
999
|
-
} catch (error) {
|
|
1000
|
-
if (error.message === "Unexpected status code: 429" && retries < maxRetries) {
|
|
1001
|
-
retries++;
|
|
1002
|
-
const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
|
|
1003
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1004
|
-
return tryRequest();
|
|
1005
|
-
} else {
|
|
1006
|
-
console.error("An error occurred:", error.message);
|
|
1007
|
-
return null;
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
} else if (retries < maxRetries) {
|
|
1011
|
-
retries++;
|
|
1012
|
-
const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
|
|
1013
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1014
|
-
return tryRequest();
|
|
1015
|
-
} else {
|
|
1016
|
-
console.error("Maximum retries reached");
|
|
1017
|
-
return null;
|
|
1018
|
-
}
|
|
1019
|
-
};
|
|
1020
|
-
return tryRequest();
|
|
1021
|
-
};
|
|
1022
|
-
|
|
1023
|
-
// src/utils/indexer.ts
|
|
1024
|
-
async function callMethodWithIndexerFallback(method, context, ...args) {
|
|
1025
|
-
const indexer = args[args.length - 1];
|
|
1026
|
-
if (indexer) {
|
|
1027
|
-
try {
|
|
1028
|
-
return await method.apply(context, args);
|
|
1029
|
-
} catch (e) {
|
|
1030
|
-
console.warn(`Indexer requests failed: ${e}. Retrying without indexer..`);
|
|
1031
|
-
return await method.apply(context, [...args.slice(0, -1), false]);
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
return await method.apply(context, args);
|
|
1035
|
-
}
|
|
1036
|
-
function withIndexerFallback(method) {
|
|
1037
|
-
return (...args) => {
|
|
1038
|
-
return callMethodWithIndexerFallback(method, this, ...args);
|
|
1039
|
-
};
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
// src/models/scallopCache.ts
|
|
1043
|
-
var ScallopCache = class {
|
|
1044
|
-
constructor(suiKit, walletAddress, cacheOptions, tokenBucket, queryClient) {
|
|
1045
|
-
this.queryClient = queryClient ?? new QueryClient(cacheOptions ?? DEFAULT_CACHE_OPTIONS);
|
|
1046
|
-
this._suiKit = suiKit;
|
|
1047
|
-
this.tokenBucket = tokenBucket ?? new TokenBucket(DEFAULT_TOKENS_PER_INTERVAL, DEFAULT_INTERVAL_IN_MS);
|
|
1048
|
-
this.walletAddress = walletAddress ?? suiKit.currentAddress();
|
|
1049
|
-
}
|
|
1050
|
-
get suiKit() {
|
|
1051
|
-
if (!this._suiKit) {
|
|
1052
|
-
throw new Error("SuiKit instance is not initialized");
|
|
1053
|
-
}
|
|
1054
|
-
return this._suiKit;
|
|
1055
|
-
}
|
|
1056
|
-
get client() {
|
|
1057
|
-
return this.suiKit.client();
|
|
1058
|
-
}
|
|
1059
|
-
/**
|
|
1060
|
-
* @description Invalidate cache based on the refetchType parameter
|
|
1061
|
-
* @param refetchType Determines the type of queries to be refetched. Defaults to `active`.
|
|
1062
|
-
*
|
|
1063
|
-
* - `active`: Only queries that match the refetch predicate and are actively being rendered via useQuery and related functions will be refetched in the background.
|
|
1064
|
-
* - `inactive`: Only queries that match the refetch predicate and are NOT actively being rendered via useQuery and related functions will be refetched in the background.
|
|
1065
|
-
* - `all`: All queries that match the refetch predicate will be refetched in the background.
|
|
1066
|
-
* - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
|
|
1067
|
-
*/
|
|
1068
|
-
async invalidateAllCache() {
|
|
1069
|
-
return Object.values(queryKeys.rpc).map(
|
|
1070
|
-
(t) => this.queryClient.invalidateQueries({
|
|
1071
|
-
queryKey: t(),
|
|
1072
|
-
type: "all"
|
|
1073
|
-
})
|
|
1074
|
-
);
|
|
1075
|
-
}
|
|
1076
|
-
/**
|
|
1077
|
-
* @description Provides cache for inspectTxn of the SuiKit.
|
|
1078
|
-
* @param QueryInspectTxnParams
|
|
1079
|
-
* @param txBlock
|
|
1080
|
-
* @returns Promise<DevInspectResults>
|
|
1081
|
-
*/
|
|
1082
|
-
async queryInspectTxn({
|
|
1083
|
-
queryTarget,
|
|
1084
|
-
args,
|
|
1085
|
-
typeArgs
|
|
1086
|
-
}) {
|
|
1087
|
-
const txBlock = new SuiTxBlock();
|
|
1088
|
-
txBlock.moveCall(queryTarget, args, typeArgs);
|
|
1089
|
-
const query = await this.queryClient.fetchQuery({
|
|
1090
|
-
queryKey: queryKeys.rpc.getInspectTxn(queryTarget, args, typeArgs),
|
|
1091
|
-
queryFn: async () => {
|
|
1092
|
-
return await callWithRateLimit(
|
|
1093
|
-
this.tokenBucket,
|
|
1094
|
-
() => this.suiKit.inspectTxn(txBlock)
|
|
1095
|
-
);
|
|
1096
|
-
}
|
|
1097
|
-
});
|
|
1098
|
-
return query;
|
|
1099
|
-
}
|
|
1100
|
-
/**
|
|
1101
|
-
* @description Provides cache for getObject of the SuiKit.
|
|
1102
|
-
* @param objectId
|
|
1103
|
-
* @param QueryObjectParams
|
|
1104
|
-
* @returns Promise<SuiObjectResponse>
|
|
1105
|
-
*/
|
|
1106
|
-
async queryGetObject(objectId, options) {
|
|
1107
|
-
return this.queryClient.fetchQuery({
|
|
1108
|
-
queryKey: queryKeys.rpc.getObject(objectId, this.walletAddress, options),
|
|
1109
|
-
queryFn: async () => {
|
|
1110
|
-
return await callWithRateLimit(
|
|
1111
|
-
this.tokenBucket,
|
|
1112
|
-
() => this.client.getObject({
|
|
1113
|
-
id: objectId,
|
|
1114
|
-
options
|
|
1115
|
-
})
|
|
1116
|
-
);
|
|
1117
|
-
}
|
|
1118
|
-
});
|
|
1119
|
-
}
|
|
1120
|
-
/**
|
|
1121
|
-
* @description Provides cache for getObjects of the SuiKit.
|
|
1122
|
-
* @param objectIds
|
|
1123
|
-
* @returns Promise<SuiObjectData[]>
|
|
1124
|
-
*/
|
|
1125
|
-
async queryGetObjects(objectIds, options = {
|
|
1126
|
-
showContent: true
|
|
1127
|
-
}) {
|
|
1128
|
-
if (objectIds.length === 0)
|
|
1129
|
-
return [];
|
|
1130
|
-
return this.queryClient.fetchQuery({
|
|
1131
|
-
queryKey: queryKeys.rpc.getObjects(
|
|
1132
|
-
objectIds,
|
|
1133
|
-
this.walletAddress,
|
|
1134
|
-
options
|
|
1135
|
-
),
|
|
1136
|
-
queryFn: async () => {
|
|
1137
|
-
return await callWithRateLimit(
|
|
1138
|
-
this.tokenBucket,
|
|
1139
|
-
() => this.suiKit.getObjects(objectIds, options)
|
|
1140
|
-
);
|
|
1141
|
-
}
|
|
1142
|
-
});
|
|
1143
|
-
}
|
|
1144
|
-
/**
|
|
1145
|
-
* @description Provides cache for getOwnedObjects of the SuiKit.
|
|
1146
|
-
* @param input
|
|
1147
|
-
* @returns Promise<PaginatedObjectsResponse>
|
|
1148
|
-
*/
|
|
1149
|
-
async queryGetOwnedObjects(input) {
|
|
1150
|
-
return this.queryClient.fetchQuery({
|
|
1151
|
-
queryKey: queryKeys.rpc.getOwnedObjects(input),
|
|
1152
|
-
queryFn: async () => {
|
|
1153
|
-
return await callWithRateLimit(
|
|
1154
|
-
this.tokenBucket,
|
|
1155
|
-
() => this.client.getOwnedObjects(input)
|
|
1156
|
-
);
|
|
1157
|
-
}
|
|
1158
|
-
});
|
|
1159
|
-
}
|
|
1160
|
-
async queryGetDynamicFields(input) {
|
|
1161
|
-
return this.queryClient.fetchQuery({
|
|
1162
|
-
queryKey: queryKeys.rpc.getDynamicFields(input),
|
|
1163
|
-
queryFn: async () => {
|
|
1164
|
-
return await callWithRateLimit(
|
|
1165
|
-
this.tokenBucket,
|
|
1166
|
-
() => this.client.getDynamicFields(input)
|
|
1167
|
-
);
|
|
1168
|
-
}
|
|
1169
|
-
});
|
|
1170
|
-
}
|
|
1171
|
-
async queryGetDynamicFieldObject(input) {
|
|
1172
|
-
return this.queryClient.fetchQuery({
|
|
1173
|
-
queryKey: queryKeys.rpc.getDynamicFieldObject(input),
|
|
1174
|
-
queryFn: async () => {
|
|
1175
|
-
return await callWithRateLimit(
|
|
1176
|
-
this.tokenBucket,
|
|
1177
|
-
() => this.client.getDynamicFieldObject(input)
|
|
1178
|
-
);
|
|
1179
|
-
}
|
|
1180
|
-
});
|
|
1430
|
+
return {
|
|
1431
|
+
coinName: assetCoinName,
|
|
1432
|
+
price,
|
|
1433
|
+
publishTime: Number(feed.price.publishTime) * 10 ** 3
|
|
1434
|
+
};
|
|
1435
|
+
} else {
|
|
1436
|
+
throw new Error("Invalid feed id");
|
|
1181
1437
|
}
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
);
|
|
1190
|
-
if (!allBalances)
|
|
1191
|
-
return {};
|
|
1192
|
-
const balances = allBalances.reduce(
|
|
1193
|
-
(acc, coinBalance) => {
|
|
1194
|
-
if (coinBalance.totalBalance !== "0") {
|
|
1195
|
-
acc[normalizeStructTag2(coinBalance.coinType)] = coinBalance.totalBalance;
|
|
1196
|
-
}
|
|
1197
|
-
return acc;
|
|
1198
|
-
},
|
|
1199
|
-
{}
|
|
1200
|
-
);
|
|
1201
|
-
return balances;
|
|
1202
|
-
}
|
|
1203
|
-
});
|
|
1438
|
+
};
|
|
1439
|
+
var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
|
|
1440
|
+
const unlockDate = new Date(unlockAtInSecondTimestamp * 1e3);
|
|
1441
|
+
const closestTwelveAM = new Date(unlockAtInSecondTimestamp * 1e3);
|
|
1442
|
+
closestTwelveAM.setUTCHours(0, 0, 0, 0);
|
|
1443
|
+
if (unlockDate.getUTCHours() >= 0) {
|
|
1444
|
+
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() + 1);
|
|
1204
1445
|
}
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
return (await this.queryGetAllCoinBalances(input.owner) || {})[normalizeStructTag2(input.coinType)] ?? "0";
|
|
1446
|
+
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
1447
|
+
if (closestTwelveAM.getTime() - now > MAX_LOCK_DURATION * 1e3) {
|
|
1448
|
+
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() - 1);
|
|
1209
1449
|
}
|
|
1450
|
+
return Math.floor(closestTwelveAM.getTime() / 1e3);
|
|
1210
1451
|
};
|
|
1211
1452
|
|
|
1212
|
-
// src/
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
},
|
|
1247
|
-
wapt: {
|
|
1248
|
-
id: "0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37",
|
|
1249
|
-
metaData: "0xc969c5251f372c0f34c32759f1d315cf1ea0ee5e4454b52aea08778eacfdd0a8",
|
|
1250
|
-
treasury: "",
|
|
1251
|
-
oracle: {
|
|
1252
|
-
supra: "",
|
|
1253
|
-
switchboard: "",
|
|
1254
|
-
pyth: {
|
|
1255
|
-
feed: "03ae4db29ed4ae33d323568895aa00337e658e348b37509f5372ae51f0af00d5",
|
|
1256
|
-
feedObject: "0x7c5b7837c44a69b469325463ac0673ac1aa8435ff44ddb4191c9ae380463647f"
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
|
-
},
|
|
1260
|
-
wsol: {
|
|
1261
|
-
id: "0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8",
|
|
1262
|
-
metaData: "0x4d2c39082b4477e3e79dc4562d939147ab90c42fc5f3e4acf03b94383cd69b6e",
|
|
1263
|
-
treasury: "",
|
|
1264
|
-
oracle: {
|
|
1265
|
-
supra: "",
|
|
1266
|
-
switchboard: "",
|
|
1267
|
-
pyth: {
|
|
1268
|
-
feed: "ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d",
|
|
1269
|
-
feedObject: "0x9d0d275efbd37d8a8855f6f2c761fa5983293dd8ce202ee5196626de8fcd4469"
|
|
1270
|
-
}
|
|
1271
|
-
}
|
|
1272
|
-
},
|
|
1273
|
-
wbtc: {
|
|
1274
|
-
id: "0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881",
|
|
1275
|
-
metaData: "0x5d3c6e60eeff8a05b693b481539e7847dfe33013e7070cdcb387f5c0cac05dfd",
|
|
1276
|
-
treasury: "",
|
|
1277
|
-
oracle: {
|
|
1278
|
-
supra: "",
|
|
1279
|
-
switchboard: "",
|
|
1280
|
-
pyth: {
|
|
1281
|
-
feed: "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43",
|
|
1282
|
-
feedObject: "0x9a62b4863bdeaabdc9500fce769cf7e72d5585eeb28a6d26e4cafadc13f76ab2"
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
},
|
|
1286
|
-
weth: {
|
|
1287
|
-
id: "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",
|
|
1288
|
-
metaData: "0x8900e4ceede3363bef086d6b50ca89d816d0e90bf6bc46efefe1f8455e08f50f",
|
|
1289
|
-
treasury: "",
|
|
1290
|
-
oracle: {
|
|
1291
|
-
supra: "",
|
|
1292
|
-
switchboard: "",
|
|
1293
|
-
pyth: {
|
|
1294
|
-
feed: "ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",
|
|
1295
|
-
feedObject: "0x9193fd47f9a0ab99b6e365a464c8a9ae30e6150fc37ed2a89c1586631f6fc4ab"
|
|
1296
|
-
}
|
|
1297
|
-
}
|
|
1298
|
-
},
|
|
1299
|
-
wusdc: {
|
|
1300
|
-
id: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf",
|
|
1301
|
-
metaData: "0x4fbf84f3029bd0c0b77164b587963be957f853eccf834a67bb9ecba6ec80f189",
|
|
1302
|
-
treasury: "",
|
|
1303
|
-
oracle: {
|
|
1304
|
-
supra: "",
|
|
1305
|
-
switchboard: "",
|
|
1306
|
-
pyth: {
|
|
1307
|
-
feed: "eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
|
|
1308
|
-
feedObject: "0x5dec622733a204ca27f5a90d8c2fad453cc6665186fd5dff13a83d0b6c9027ab"
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
},
|
|
1312
|
-
wusdt: {
|
|
1313
|
-
id: "0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c",
|
|
1314
|
-
metaData: "0xfb0e3eb97dd158a5ae979dddfa24348063843c5b20eb8381dd5fa7c93699e45c",
|
|
1315
|
-
treasury: "",
|
|
1316
|
-
oracle: {
|
|
1317
|
-
supra: "",
|
|
1318
|
-
switchboard: "",
|
|
1319
|
-
pyth: {
|
|
1320
|
-
feed: "2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b",
|
|
1321
|
-
feedObject: "0x985e3db9f93f76ee8bace7c3dd5cc676a096accd5d9e09e9ae0fb6e492b14572"
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
},
|
|
1325
|
-
sui: {
|
|
1326
|
-
id: "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
1327
|
-
metaData: "0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3",
|
|
1328
|
-
treasury: "",
|
|
1329
|
-
oracle: {
|
|
1330
|
-
supra: "",
|
|
1331
|
-
switchboard: "0xbca474133638352ba83ccf7b5c931d50f764b09550e16612c9f70f1e21f3f594",
|
|
1332
|
-
pyth: {
|
|
1333
|
-
feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
1334
|
-
feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
|
-
},
|
|
1338
|
-
afsui: {
|
|
1339
|
-
id: "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc",
|
|
1340
|
-
metaData: "0x2f9217f533e51334873a39b8026a4aa6919497b47f49d0986a4f1aec66f8a34d",
|
|
1341
|
-
treasury: "",
|
|
1342
|
-
oracle: {
|
|
1343
|
-
supra: "",
|
|
1344
|
-
switchboard: "",
|
|
1345
|
-
pyth: {
|
|
1346
|
-
feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
1347
|
-
feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
|
|
1348
|
-
}
|
|
1349
|
-
}
|
|
1350
|
-
},
|
|
1351
|
-
hasui: {
|
|
1352
|
-
id: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",
|
|
1353
|
-
metaData: "0x2c5f33af93f6511df699aaaa5822d823aac6ed99d4a0de2a4a50b3afa0172e24",
|
|
1354
|
-
treasury: "",
|
|
1355
|
-
oracle: {
|
|
1356
|
-
supra: "",
|
|
1357
|
-
switchboard: "",
|
|
1358
|
-
pyth: {
|
|
1359
|
-
feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
1360
|
-
feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
},
|
|
1364
|
-
vsui: {
|
|
1365
|
-
id: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",
|
|
1366
|
-
metaData: "0xabd84a23467b33854ab25cf862006fd97479f8f6f53e50fe732c43a274d939bd",
|
|
1367
|
-
treasury: "",
|
|
1368
|
-
oracle: {
|
|
1369
|
-
supra: "",
|
|
1370
|
-
switchboard: "",
|
|
1371
|
-
pyth: {
|
|
1372
|
-
feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
1373
|
-
feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
|
|
1374
|
-
}
|
|
1453
|
+
// src/utils/tokenBucket.ts
|
|
1454
|
+
var TokenBucket = class {
|
|
1455
|
+
constructor(tokensPerInterval, intervalInMs) {
|
|
1456
|
+
this.tokensPerInterval = tokensPerInterval;
|
|
1457
|
+
this.interval = intervalInMs;
|
|
1458
|
+
this.tokens = tokensPerInterval;
|
|
1459
|
+
this.lastRefill = Date.now();
|
|
1460
|
+
}
|
|
1461
|
+
refill() {
|
|
1462
|
+
const now = Date.now();
|
|
1463
|
+
const elapsed = now - this.lastRefill;
|
|
1464
|
+
if (elapsed > this.interval) {
|
|
1465
|
+
const tokensToAdd = Math.floor(elapsed / this.interval) * this.tokensPerInterval;
|
|
1466
|
+
this.tokens = Math.min(this.tokens + tokensToAdd, this.tokensPerInterval);
|
|
1467
|
+
this.lastRefill = now;
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
removeTokens(count) {
|
|
1471
|
+
this.refill();
|
|
1472
|
+
if (this.tokens >= count) {
|
|
1473
|
+
this.tokens -= count;
|
|
1474
|
+
return true;
|
|
1475
|
+
}
|
|
1476
|
+
return false;
|
|
1477
|
+
}
|
|
1478
|
+
};
|
|
1479
|
+
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 30, backoffFactor = 1.25) => {
|
|
1480
|
+
let retries = 0;
|
|
1481
|
+
const tryRequest = async () => {
|
|
1482
|
+
if (tokenBucket.removeTokens(1)) {
|
|
1483
|
+
try {
|
|
1484
|
+
const result = await fn();
|
|
1485
|
+
if (result && result.status === 429) {
|
|
1486
|
+
throw new Error("Unexpected status code: 429");
|
|
1375
1487
|
}
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
feedObject: "0xf6de1d3279a269a597d813cbaca59aa906543ab9a8c64e84a4722f1a20863985"
|
|
1387
|
-
}
|
|
1488
|
+
return result;
|
|
1489
|
+
} catch (error) {
|
|
1490
|
+
if (error.message === "Unexpected status code: 429" && retries < maxRetries) {
|
|
1491
|
+
retries++;
|
|
1492
|
+
const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
|
|
1493
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1494
|
+
return tryRequest();
|
|
1495
|
+
} else {
|
|
1496
|
+
console.error("An error occurred:", error.message);
|
|
1497
|
+
return null;
|
|
1388
1498
|
}
|
|
1389
1499
|
}
|
|
1390
|
-
}
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
registryCap: "0xbcb07141eb1f7e01fbda4130ecf5f5adaeabb77f5d9c32158b7532bcd2197acd",
|
|
1399
|
-
state: "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8",
|
|
1400
|
-
wormhole: "0x5306f64e312b581766351c07af79c72fcb1cd25147157fdc2f8ad76de9a3fb6a",
|
|
1401
|
-
wormholeState: "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c"
|
|
1402
|
-
}
|
|
1403
|
-
},
|
|
1404
|
-
packages: {
|
|
1405
|
-
coinDecimalsRegistry: {
|
|
1406
|
-
id: "0xca5a5a62f01c79a104bf4d31669e29daa387f325c241de4edbe30986a9bc8b0d",
|
|
1407
|
-
upgradeCap: "0x34e76a945d29f195bc53ca704fa70877d1cf3a5d7bbfdda1b13e633fff13c0f6"
|
|
1408
|
-
},
|
|
1409
|
-
math: {
|
|
1410
|
-
id: "0xad013d5fde39e15eabda32b3dbdafd67dac32b798ce63237c27a8f73339b9b6f",
|
|
1411
|
-
upgradeCap: "0x3a329598231de02e6135c62284b66005b41cad1d9ab7ca2dc79c08293aba2ec6"
|
|
1412
|
-
},
|
|
1413
|
-
whitelist: {
|
|
1414
|
-
id: "0x1318fdc90319ec9c24df1456d960a447521b0a658316155895014a6e39b5482f",
|
|
1415
|
-
upgradeCap: "0xf5a22aea23db664f7b69855b6a546747f17c1ec4230319cfc17225e462b05761"
|
|
1416
|
-
},
|
|
1417
|
-
x: {
|
|
1418
|
-
id: "0x779b5c547976899f5474f3a5bc0db36ddf4697ad7e5a901db0415c2281d28162",
|
|
1419
|
-
upgradeCap: "0x3f203f6fff6a69d151e4f1cd931f22b68c489ef2759765662fc7baf673943c9e"
|
|
1420
|
-
},
|
|
1421
|
-
protocol: {
|
|
1422
|
-
id: "0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1",
|
|
1423
|
-
upgradeCap: "0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a"
|
|
1424
|
-
},
|
|
1425
|
-
// protocol: {
|
|
1426
|
-
// id: '0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e',
|
|
1427
|
-
// upgradeCap:
|
|
1428
|
-
// '0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a',
|
|
1429
|
-
// },
|
|
1430
|
-
protocolWhitelist: {
|
|
1431
|
-
id: "0x4c262d9343dac53ecb28f482a2a3f62c73d0ebac5b5f03d57383d56ff219acdf",
|
|
1432
|
-
upgradeCap: "0x4a5e88a75039b00988f633f811f58117f31b8627a46bf822aa114d9010049449"
|
|
1433
|
-
},
|
|
1434
|
-
// query: {
|
|
1435
|
-
// id: '0xb8d603a39114a5efef3dd0bf84df0bed1be1fbd39b78b7dd6e8a61ccc5e6006f',
|
|
1436
|
-
// upgradeCap:
|
|
1437
|
-
// '0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f',
|
|
1438
|
-
// },
|
|
1439
|
-
query: {
|
|
1440
|
-
id: "0xe4f9d62d17746d5b9dbf0d5557747430021a71575780b515161210cdba0a4c1c",
|
|
1441
|
-
upgradeCap: "0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f"
|
|
1442
|
-
},
|
|
1443
|
-
supra: { id: "", upgradeCap: "" },
|
|
1444
|
-
pyth: {
|
|
1445
|
-
id: "0x910f30cbc7f601f75a5141a01265cd47c62d468707c5e1aecb32a18f448cb25a",
|
|
1446
|
-
upgradeCap: "0xdf0ffbae1ea5bb25fbca5efba433dcf00c7cced65679af2f04728901275c6157"
|
|
1447
|
-
},
|
|
1448
|
-
switchboard: { id: "", upgradeCap: "" },
|
|
1449
|
-
xOracle: {
|
|
1450
|
-
id: "0x1478a432123e4b3d61878b629f2c692969fdb375644f1251cd278a4b1e7d7cd6",
|
|
1451
|
-
upgradeCap: "0x0f928a6b2e26b73330fecaf9b44acfc9800a4a9794d6415c2a3153bc70e3c1f0"
|
|
1452
|
-
},
|
|
1453
|
-
testCoin: { id: "", upgradeCap: "" }
|
|
1500
|
+
} else if (retries < maxRetries) {
|
|
1501
|
+
retries++;
|
|
1502
|
+
const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
|
|
1503
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1504
|
+
return tryRequest();
|
|
1505
|
+
} else {
|
|
1506
|
+
console.error("Maximum retries reached");
|
|
1507
|
+
return null;
|
|
1454
1508
|
}
|
|
1455
|
-
}
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1509
|
+
};
|
|
1510
|
+
return tryRequest();
|
|
1511
|
+
};
|
|
1512
|
+
|
|
1513
|
+
// src/utils/indexer.ts
|
|
1514
|
+
async function callMethodWithIndexerFallback(method, context, ...args) {
|
|
1515
|
+
const indexer = args[args.length - 1];
|
|
1516
|
+
if (indexer) {
|
|
1517
|
+
try {
|
|
1518
|
+
return await method.apply(context, args);
|
|
1519
|
+
} catch (e) {
|
|
1520
|
+
console.warn(`Indexer requests failed: ${e}. Retrying without indexer..`);
|
|
1521
|
+
return await method.apply(context, [...args.slice(0, -1), false]);
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
return await method.apply(context, args);
|
|
1525
|
+
}
|
|
1526
|
+
function withIndexerFallback(method) {
|
|
1527
|
+
return (...args) => {
|
|
1528
|
+
return callMethodWithIndexerFallback(method, this, ...args);
|
|
1529
|
+
};
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
// src/models/scallopCache.ts
|
|
1533
|
+
var ScallopCache = class {
|
|
1534
|
+
constructor(suiKit, walletAddress, cacheOptions, tokenBucket, queryClient) {
|
|
1535
|
+
this.queryClient = queryClient ?? new QueryClient(cacheOptions ?? DEFAULT_CACHE_OPTIONS);
|
|
1536
|
+
this._suiKit = suiKit;
|
|
1537
|
+
this.tokenBucket = tokenBucket ?? new TokenBucket(DEFAULT_TOKENS_PER_INTERVAL, DEFAULT_INTERVAL_IN_MS);
|
|
1538
|
+
this.walletAddress = walletAddress ?? suiKit.currentAddress();
|
|
1539
|
+
}
|
|
1540
|
+
get suiKit() {
|
|
1541
|
+
if (!this._suiKit) {
|
|
1542
|
+
throw new Error("SuiKit instance is not initialized");
|
|
1543
|
+
}
|
|
1544
|
+
return this._suiKit;
|
|
1545
|
+
}
|
|
1546
|
+
get client() {
|
|
1547
|
+
return this.suiKit.client();
|
|
1548
|
+
}
|
|
1549
|
+
/**
|
|
1550
|
+
* @description Invalidate cache based on the refetchType parameter
|
|
1551
|
+
* @param refetchType Determines the type of queries to be refetched. Defaults to `active`.
|
|
1552
|
+
*
|
|
1553
|
+
* - `active`: Only queries that match the refetch predicate and are actively being rendered via useQuery and related functions will be refetched in the background.
|
|
1554
|
+
* - `inactive`: Only queries that match the refetch predicate and are NOT actively being rendered via useQuery and related functions will be refetched in the background.
|
|
1555
|
+
* - `all`: All queries that match the refetch predicate will be refetched in the background.
|
|
1556
|
+
* - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
|
|
1557
|
+
*/
|
|
1558
|
+
async invalidateAllCache() {
|
|
1559
|
+
return Object.values(queryKeys.rpc).map(
|
|
1560
|
+
(t) => this.queryClient.invalidateQueries({
|
|
1561
|
+
queryKey: t(),
|
|
1562
|
+
type: "all"
|
|
1563
|
+
})
|
|
1564
|
+
);
|
|
1565
|
+
}
|
|
1566
|
+
/**
|
|
1567
|
+
* @description Provides cache for inspectTxn of the SuiKit.
|
|
1568
|
+
* @param QueryInspectTxnParams
|
|
1569
|
+
* @param txBlock
|
|
1570
|
+
* @returns Promise<DevInspectResults>
|
|
1571
|
+
*/
|
|
1572
|
+
async queryInspectTxn({
|
|
1573
|
+
queryTarget,
|
|
1574
|
+
args,
|
|
1575
|
+
typeArgs
|
|
1576
|
+
}) {
|
|
1577
|
+
const txBlock = new SuiTxBlock();
|
|
1578
|
+
txBlock.moveCall(queryTarget, args, typeArgs);
|
|
1579
|
+
const query = await this.queryClient.fetchQuery({
|
|
1580
|
+
queryKey: queryKeys.rpc.getInspectTxn(queryTarget, args, typeArgs),
|
|
1581
|
+
queryFn: async () => {
|
|
1582
|
+
return await callWithRateLimit(
|
|
1583
|
+
this.tokenBucket,
|
|
1584
|
+
() => this.suiKit.inspectTxn(txBlock)
|
|
1585
|
+
);
|
|
1586
|
+
}
|
|
1587
|
+
});
|
|
1588
|
+
return query;
|
|
1589
|
+
}
|
|
1590
|
+
/**
|
|
1591
|
+
* @description Provides cache for getObject of the SuiKit.
|
|
1592
|
+
* @param objectId
|
|
1593
|
+
* @param QueryObjectParams
|
|
1594
|
+
* @returns Promise<SuiObjectResponse>
|
|
1595
|
+
*/
|
|
1596
|
+
async queryGetObject(objectId, options) {
|
|
1597
|
+
return this.queryClient.fetchQuery({
|
|
1598
|
+
queryKey: queryKeys.rpc.getObject(objectId, this.walletAddress, options),
|
|
1599
|
+
queryFn: async () => {
|
|
1600
|
+
return await callWithRateLimit(
|
|
1601
|
+
this.tokenBucket,
|
|
1602
|
+
() => this.client.getObject({
|
|
1603
|
+
id: objectId,
|
|
1604
|
+
options
|
|
1605
|
+
})
|
|
1606
|
+
);
|
|
1607
|
+
}
|
|
1608
|
+
});
|
|
1609
|
+
}
|
|
1610
|
+
/**
|
|
1611
|
+
* @description Provides cache for getObjects of the SuiKit.
|
|
1612
|
+
* @param objectIds
|
|
1613
|
+
* @returns Promise<SuiObjectData[]>
|
|
1614
|
+
*/
|
|
1615
|
+
async queryGetObjects(objectIds, options = {
|
|
1616
|
+
showContent: true
|
|
1617
|
+
}) {
|
|
1618
|
+
if (objectIds.length === 0)
|
|
1619
|
+
return [];
|
|
1620
|
+
return this.queryClient.fetchQuery({
|
|
1621
|
+
queryKey: queryKeys.rpc.getObjects(
|
|
1622
|
+
objectIds,
|
|
1623
|
+
this.walletAddress,
|
|
1624
|
+
options
|
|
1625
|
+
),
|
|
1626
|
+
queryFn: async () => {
|
|
1627
|
+
return await callWithRateLimit(
|
|
1628
|
+
this.tokenBucket,
|
|
1629
|
+
() => this.suiKit.getObjects(objectIds, options)
|
|
1630
|
+
);
|
|
1519
1631
|
}
|
|
1520
|
-
}
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
adminCap: "0xc5dc06b9074291259f2cac460c940012c781c4430e42125c541cc43101c3bcbd",
|
|
1536
|
-
referralBindings: "0xf63299d58789d99de94092b9011323466e55ca0c1ea1a7a3786a589af46e1c09",
|
|
1537
|
-
bindingTableId: "0x1c8202b17267ec8d6cf97ca013615354181a04f179570e42601ff2dae19294b1",
|
|
1538
|
-
referralRevenuePool: "0x6abd852caf90769c1b185cdf636d841673fa95528f0550f018b8a138bd283c07",
|
|
1539
|
-
revenueTableId: "0x595baa3654c297bff84ab7786a2d250f019cefc66e8df8e89fd9d41e02bd30dd",
|
|
1540
|
-
referralTiers: "0x962cb903d8d7346190c5204785ccbb91b61086aa764f674c8145df82335cf83e",
|
|
1541
|
-
tiersTableId: "0xeac755a7a8b7798530905ac79e8c114f19d0f130f6eab012954f08faac29c75d",
|
|
1542
|
-
// authorizedWitnessList:
|
|
1543
|
-
// '0xf21b0ed043c9bb70842c0129159f4943dbcc3c9ef2f2f808af65f8be25cfd20e',
|
|
1544
|
-
authorizedWitnessList: "0x9d6223dc52015b8a3986a573590ef2af8f1b8f3e4685513888c052f001b87e7f",
|
|
1545
|
-
version: "0x1bd4b7285f72e11c316b828c7c47b3f4da18dcec9f9b3dba6d8629cbb6f93e5e"
|
|
1546
|
-
},
|
|
1547
|
-
vesca: {
|
|
1548
|
-
id: "0xb15b6e0cdd85afb5028bea851dd249405e734d800a259147bbc24980629723a4",
|
|
1549
|
-
object: "0xb15b6e0cdd85afb5028bea851dd249405e734d800a259147bbc24980629723a4",
|
|
1550
|
-
adminCap: "0x8ffa76135c5b85c5fbd73a6448a4a733d826cb63a267ab817656acb77c72d4a5",
|
|
1551
|
-
tableId: "0xe3153b2bf124be0b86cb8bd468346a861efd0da52fc42197b54d2f616488a311",
|
|
1552
|
-
table: "0x611cb8d9d4d90867467b5ebdf4cc447a0047ed5b01334a28a29fcfe733e3d609",
|
|
1553
|
-
treasury: "0xe8c112c09b88158dc6c8e23d1fbae5b3c7136cdee54b7dafc08e65db28c4a5bc",
|
|
1554
|
-
config: "0xe0a2ff281e73c1d53cfa85807080f87e833e4f1a7f93dcf8800b3865269a76b9"
|
|
1555
|
-
},
|
|
1556
|
-
loyaltyProgram: {
|
|
1557
|
-
id: "0xd17bcf8b5a59652c36225d478564a8593ae0ed7d650bcacdda1d6fe179127907",
|
|
1558
|
-
object: "0xd17bcf8b5a59652c36225d478564a8593ae0ed7d650bcacdda1d6fe179127907",
|
|
1559
|
-
rewardPool: "0xf9c090492ef476bd542109d0913ffe871cbfa28578b7114eca2a8c0e5671786f",
|
|
1560
|
-
userRewardTableId: "0x748a80395849ed37db1b0e14f2ab5d1d96458d2359ab3a84eb079d0f4ac7cf2e"
|
|
1561
|
-
},
|
|
1562
|
-
scoin: {
|
|
1563
|
-
id: "0xad2ca2aa5089df94bb2d444d5eb3520378c2f2dfb3a0bd2a2c994145ac4b0a53",
|
|
1564
|
-
coins: {
|
|
1565
|
-
ssui: {
|
|
1566
|
-
coinType: "0xfac769100bccc0caebcf4f4e2d00ac2f8883f07f724be28940df90605f5e7e9a::scallop_sui::SCALLOP_SUI",
|
|
1567
|
-
treasury: "0x9cb4551b36c17d37e19d700147fa819ea1c487ff8bcf18374de2cceb2e9d4845"
|
|
1568
|
-
},
|
|
1569
|
-
scetus: {
|
|
1570
|
-
coinType: "0x8b71e6d323ed78515af2bead13bf3d0da1562ba4a99234eb7c4f14fd39ef0427::scallop_cetus::SCALLOP_CETUS",
|
|
1571
|
-
treasury: "0xd786f4b2d26278cc7911a3445b1b085eab60f269ef9dbb6b87e803d52f155003"
|
|
1572
|
-
},
|
|
1573
|
-
ssca: {
|
|
1574
|
-
coinType: "0x0a9d3c6c9af9f6e8def82921541bcbd17f73ed31bed3adcb684f2a4c267e42f0::scallop_sca::SCALLOP_SCA",
|
|
1575
|
-
treasury: "0xe818636d1d6c46d6ea1a2dce9d94696d7cbc18ce27451b603eeaa47aba8d75e0"
|
|
1576
|
-
},
|
|
1577
|
-
swusdc: {
|
|
1578
|
-
coinType: "0xaedc3ab75db8680b81a755015fa90124d217be93457b893c05bac033817defaf::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
1579
|
-
treasury: "0xfc6971648f867f7fd6928d1b873af71577e2eaf2c7543ef8bc82c431d833ae78"
|
|
1580
|
-
},
|
|
1581
|
-
swusdt: {
|
|
1582
|
-
coinType: "0xbf02fc87ddc104b342ad8414c85ceadf5b0c823c055a06fb0ed776272c01a52a::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
|
|
1583
|
-
treasury: "0xb9593e2c3a0ba796ee815012b75ae46468ea78cda0188b9ac6816efe65503521"
|
|
1584
|
-
},
|
|
1585
|
-
sweth: {
|
|
1586
|
-
coinType: "0x27d54f43e3eda701be56b82e5756e41c84467cd202f5cf713d5f9e45a9f1b6bc::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
|
|
1587
|
-
treasury: "0x032b4c8fac94c038dbe986f7587e9b1e4ef580b5ee06d2ef249d85459b7ef05d"
|
|
1588
|
-
},
|
|
1589
|
-
safsui: {
|
|
1590
|
-
coinType: "0xb75b46d975d8d80670b53a6bee90baaa8ce2e0b7d397f079447d641eef6b44ad::scallop_af_sui::SCALLOP_AF_SUI",
|
|
1591
|
-
treasury: "0x21450ef0570ef3d224ffa3b873ab802e439ece7b93cc7efad10ae0c1e3b3fcfe"
|
|
1592
|
-
},
|
|
1593
|
-
shasui: {
|
|
1594
|
-
coinType: "0xd973a723874e2c7cde196602a79155a1343a933f8cf87d9b1bb7408bc1acbc58::scallop_ha_sui::SCALLOP_HA_SUI",
|
|
1595
|
-
treasury: "0xf822fc1402207e47d2e3ba8ff6e1e594bf1de777dc5ebd2744619cd2726e3b0d"
|
|
1596
|
-
},
|
|
1597
|
-
svsui: {
|
|
1598
|
-
coinType: "0x97023a317320c4498cc4cd239dd02fd30c28246e5e8f81325d63f2bd8d70f6b3::scallop_v_sui::SCALLOP_V_SUI",
|
|
1599
|
-
treasury: "0x327114f0bf3559d7e2de10282147ed76a236c7c6775029165c4db09a6062ead6\u0192"
|
|
1632
|
+
});
|
|
1633
|
+
}
|
|
1634
|
+
/**
|
|
1635
|
+
* @description Provides cache for getOwnedObjects of the SuiKit.
|
|
1636
|
+
* @param input
|
|
1637
|
+
* @returns Promise<PaginatedObjectsResponse>
|
|
1638
|
+
*/
|
|
1639
|
+
async queryGetOwnedObjects(input) {
|
|
1640
|
+
return this.queryClient.fetchQuery({
|
|
1641
|
+
queryKey: queryKeys.rpc.getOwnedObjects(input),
|
|
1642
|
+
queryFn: async () => {
|
|
1643
|
+
return await callWithRateLimit(
|
|
1644
|
+
this.tokenBucket,
|
|
1645
|
+
() => this.client.getOwnedObjects(input)
|
|
1646
|
+
);
|
|
1600
1647
|
}
|
|
1601
|
-
}
|
|
1648
|
+
});
|
|
1649
|
+
}
|
|
1650
|
+
async queryGetDynamicFields(input) {
|
|
1651
|
+
return this.queryClient.fetchQuery({
|
|
1652
|
+
queryKey: queryKeys.rpc.getDynamicFields(input),
|
|
1653
|
+
queryFn: async () => {
|
|
1654
|
+
return await callWithRateLimit(
|
|
1655
|
+
this.tokenBucket,
|
|
1656
|
+
() => this.client.getDynamicFields(input)
|
|
1657
|
+
);
|
|
1658
|
+
}
|
|
1659
|
+
});
|
|
1660
|
+
}
|
|
1661
|
+
async queryGetDynamicFieldObject(input) {
|
|
1662
|
+
return this.queryClient.fetchQuery({
|
|
1663
|
+
queryKey: queryKeys.rpc.getDynamicFieldObject(input),
|
|
1664
|
+
queryFn: async () => {
|
|
1665
|
+
return await callWithRateLimit(
|
|
1666
|
+
this.tokenBucket,
|
|
1667
|
+
() => this.client.getDynamicFieldObject(input)
|
|
1668
|
+
);
|
|
1669
|
+
}
|
|
1670
|
+
});
|
|
1671
|
+
}
|
|
1672
|
+
async queryGetAllCoinBalances(owner) {
|
|
1673
|
+
return this.queryClient.fetchQuery({
|
|
1674
|
+
queryKey: queryKeys.rpc.getAllCoinBalances(owner),
|
|
1675
|
+
queryFn: async () => {
|
|
1676
|
+
const allBalances = await callWithRateLimit(
|
|
1677
|
+
this.tokenBucket,
|
|
1678
|
+
() => this.client.getAllBalances({ owner })
|
|
1679
|
+
);
|
|
1680
|
+
if (!allBalances)
|
|
1681
|
+
return {};
|
|
1682
|
+
const balances = allBalances.reduce(
|
|
1683
|
+
(acc, coinBalance) => {
|
|
1684
|
+
if (coinBalance.totalBalance !== "0") {
|
|
1685
|
+
acc[normalizeStructTag2(coinBalance.coinType)] = coinBalance.totalBalance;
|
|
1686
|
+
}
|
|
1687
|
+
return acc;
|
|
1688
|
+
},
|
|
1689
|
+
{}
|
|
1690
|
+
);
|
|
1691
|
+
return balances;
|
|
1692
|
+
}
|
|
1693
|
+
});
|
|
1694
|
+
}
|
|
1695
|
+
async queryGetCoinBalance(input) {
|
|
1696
|
+
if (!input.coinType)
|
|
1697
|
+
return "0";
|
|
1698
|
+
return (await this.queryGetAllCoinBalances(input.owner) ?? {})[normalizeStructTag2(input.coinType)] ?? "0";
|
|
1602
1699
|
}
|
|
1603
1700
|
};
|
|
1604
1701
|
|
|
1605
1702
|
// src/models/scallopAddress.ts
|
|
1703
|
+
import axios from "axios";
|
|
1606
1704
|
var EMPTY_ADDRESSES = {
|
|
1607
1705
|
core: {
|
|
1608
1706
|
version: "",
|
|
@@ -1958,12 +2056,12 @@ var ScallopAddress = class {
|
|
|
1958
2056
|
"Content-Type": "application/json",
|
|
1959
2057
|
Accept: "application/json"
|
|
1960
2058
|
},
|
|
1961
|
-
timeout:
|
|
2059
|
+
timeout: 8e3
|
|
1962
2060
|
});
|
|
1963
2061
|
if (auth)
|
|
1964
2062
|
this._auth = auth;
|
|
1965
2063
|
this._id = id;
|
|
1966
|
-
this._network = network
|
|
2064
|
+
this._network = network ?? "mainnet";
|
|
1967
2065
|
this._addressesMap = USE_TEST_ADDRESS ? /* @__PURE__ */ new Map([["mainnet", TEST_ADDRESSES]]) : /* @__PURE__ */ new Map();
|
|
1968
2066
|
if (USE_TEST_ADDRESS)
|
|
1969
2067
|
this._currentAddresses = TEST_ADDRESSES;
|
|
@@ -2266,11 +2364,9 @@ var ScallopAddress = class {
|
|
|
2266
2364
|
|
|
2267
2365
|
// src/models/scallopClient.ts
|
|
2268
2366
|
import { normalizeSuiAddress as normalizeSuiAddress3 } from "@mysten/sui/utils";
|
|
2269
|
-
import { SuiKit as SuiKit6 } from "@scallop-io/sui-kit";
|
|
2270
2367
|
|
|
2271
2368
|
// src/models/scallopUtils.ts
|
|
2272
2369
|
import { SUI_TYPE_ARG, normalizeStructTag as normalizeStructTag6 } from "@mysten/sui/utils";
|
|
2273
|
-
import { SuiKit as SuiKit2 } from "@scallop-io/sui-kit";
|
|
2274
2370
|
import { SuiPriceServiceConnection } from "@pythnetwork/pyth-sui-js";
|
|
2275
2371
|
|
|
2276
2372
|
// src/queries/coreQuery.ts
|
|
@@ -2313,19 +2409,19 @@ var getSupplyLimit = async (utils, poolName) => {
|
|
|
2313
2409
|
};
|
|
2314
2410
|
|
|
2315
2411
|
// src/queries/coreQuery.ts
|
|
2316
|
-
var queryMarket = async (query, indexer = false) => {
|
|
2317
|
-
|
|
2412
|
+
var queryMarket = async (query, indexer = false, coinPrices) => {
|
|
2413
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
|
|
2318
2414
|
const pools = {};
|
|
2319
2415
|
const collaterals = {};
|
|
2320
2416
|
if (indexer) {
|
|
2321
2417
|
const marketIndexer = await query.indexer.getMarket();
|
|
2322
2418
|
const updatePools = (item) => {
|
|
2323
|
-
item.coinPrice = coinPrices[item.coinName]
|
|
2419
|
+
item.coinPrice = coinPrices[item.coinName] ?? item.coinPrice;
|
|
2324
2420
|
item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
|
|
2325
2421
|
pools[item.coinName] = item;
|
|
2326
2422
|
};
|
|
2327
2423
|
const updateCollaterals = (item) => {
|
|
2328
|
-
item.coinPrice = coinPrices[item.coinName]
|
|
2424
|
+
item.coinPrice = coinPrices[item.coinName] ?? item.coinPrice;
|
|
2329
2425
|
item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
|
|
2330
2426
|
collaterals[item.coinName] = item;
|
|
2331
2427
|
};
|
|
@@ -2445,19 +2541,19 @@ var queryMarket = async (query, indexer = false) => {
|
|
|
2445
2541
|
// data: marketData,
|
|
2446
2542
|
};
|
|
2447
2543
|
};
|
|
2448
|
-
var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer = false) => {
|
|
2544
|
+
var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer = false, coinPrices) => {
|
|
2449
2545
|
const marketId = query.address.get("core.market");
|
|
2450
2546
|
const marketObjectResponse = await query.cache.queryGetObject(marketId, {
|
|
2451
2547
|
showContent: true
|
|
2452
2548
|
});
|
|
2453
|
-
|
|
2549
|
+
coinPrices = await query.utils.getCoinPrices(poolCoinNames) ?? {};
|
|
2454
2550
|
const marketPools = {};
|
|
2455
2551
|
if (indexer) {
|
|
2456
2552
|
const marketPoolsIndexer = await query.indexer.getMarketPools();
|
|
2457
2553
|
const updateMarketPool = (marketPool) => {
|
|
2458
2554
|
if (!poolCoinNames.includes(marketPool.coinName))
|
|
2459
2555
|
return;
|
|
2460
|
-
marketPool.coinPrice = coinPrices[marketPool.coinName]
|
|
2556
|
+
marketPool.coinPrice = coinPrices[marketPool.coinName] ?? marketPool.coinPrice;
|
|
2461
2557
|
marketPool.coinWrappedType = query.utils.getCoinWrappedType(
|
|
2462
2558
|
marketPool.coinName
|
|
2463
2559
|
);
|
|
@@ -2488,17 +2584,17 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2488
2584
|
let borrowIndex;
|
|
2489
2585
|
let interestModel;
|
|
2490
2586
|
let borrowFeeRate;
|
|
2491
|
-
coinPrice = coinPrice
|
|
2587
|
+
coinPrice = coinPrice ?? (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
2492
2588
|
if (indexer) {
|
|
2493
2589
|
const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
|
|
2494
|
-
marketPoolIndexer.coinPrice = coinPrice
|
|
2590
|
+
marketPoolIndexer.coinPrice = coinPrice ?? marketPoolIndexer.coinPrice;
|
|
2495
2591
|
marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
2496
2592
|
marketPoolIndexer.coinName
|
|
2497
2593
|
);
|
|
2498
2594
|
return marketPoolIndexer;
|
|
2499
2595
|
}
|
|
2500
2596
|
const marketId = query.address.get("core.market");
|
|
2501
|
-
marketObject = marketObject
|
|
2597
|
+
marketObject = marketObject ?? (await query.cache.queryGetObject(marketId, {
|
|
2502
2598
|
showContent: true
|
|
2503
2599
|
}))?.data;
|
|
2504
2600
|
if (marketObject) {
|
|
@@ -2516,7 +2612,9 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2516
2612
|
}
|
|
2517
2613
|
});
|
|
2518
2614
|
if (!balanceSheetDynamicFieldObjectResponse)
|
|
2519
|
-
|
|
2615
|
+
throw new Error(
|
|
2616
|
+
`Failed to fetch balanceSheetDynamicFieldObjectResponse for ${poolCoinName}`
|
|
2617
|
+
);
|
|
2520
2618
|
const balanceSheetDynamicFieldObject = balanceSheetDynamicFieldObjectResponse.data;
|
|
2521
2619
|
if (balanceSheetDynamicFieldObject && balanceSheetDynamicFieldObject.content && "fields" in balanceSheetDynamicFieldObject.content) {
|
|
2522
2620
|
const dynamicFields = balanceSheetDynamicFieldObject.content.fields;
|
|
@@ -2533,7 +2631,9 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2533
2631
|
}
|
|
2534
2632
|
});
|
|
2535
2633
|
if (!borrowIndexDynamicFieldObjectResponse)
|
|
2536
|
-
|
|
2634
|
+
throw new Error(
|
|
2635
|
+
`Failed to fetch borrowIndexDynamicFieldObjectResponse for ${poolCoinName}`
|
|
2636
|
+
);
|
|
2537
2637
|
const borrowIndexDynamicFieldObject = borrowIndexDynamicFieldObjectResponse.data;
|
|
2538
2638
|
if (borrowIndexDynamicFieldObject && borrowIndexDynamicFieldObject.content && "fields" in borrowIndexDynamicFieldObject.content) {
|
|
2539
2639
|
const dynamicFields = borrowIndexDynamicFieldObject.content.fields;
|
|
@@ -2550,7 +2650,9 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2550
2650
|
}
|
|
2551
2651
|
});
|
|
2552
2652
|
if (!interestModelDynamicFieldObjectResponse)
|
|
2553
|
-
|
|
2653
|
+
throw new Error(
|
|
2654
|
+
`Failed to fetch interestModelDynamicFieldObjectResponse for ${poolCoinName}`
|
|
2655
|
+
);
|
|
2554
2656
|
const interestModelDynamicFieldObject = interestModelDynamicFieldObjectResponse.data;
|
|
2555
2657
|
if (interestModelDynamicFieldObject && interestModelDynamicFieldObject.content && "fields" in interestModelDynamicFieldObject.content) {
|
|
2556
2658
|
const dynamicFields = interestModelDynamicFieldObject.content.fields;
|
|
@@ -2568,7 +2670,9 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2568
2670
|
}
|
|
2569
2671
|
});
|
|
2570
2672
|
if (!borrowFeeDynamicFieldObjectResponse)
|
|
2571
|
-
|
|
2673
|
+
throw new Error(
|
|
2674
|
+
`Failed to fetch borrowFeeDynamicFieldObjectResponse for ${poolCoinName}`
|
|
2675
|
+
);
|
|
2572
2676
|
const borrowFeeDynamicFieldObject = borrowFeeDynamicFieldObjectResponse.data;
|
|
2573
2677
|
if (borrowFeeDynamicFieldObject && borrowFeeDynamicFieldObject.content && "fields" in borrowFeeDynamicFieldObject.content) {
|
|
2574
2678
|
const dynamicFields = borrowFeeDynamicFieldObject.content.fields;
|
|
@@ -2590,7 +2694,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2590
2694
|
reserve: balanceSheet.revenue,
|
|
2591
2695
|
reserveFactor: interestModel.revenue_factor.fields,
|
|
2592
2696
|
borrowWeight: interestModel.borrow_weight.fields,
|
|
2593
|
-
borrowFeeRate: borrowFeeRate
|
|
2697
|
+
borrowFeeRate: borrowFeeRate ?? { value: "0" },
|
|
2594
2698
|
baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
|
|
2595
2699
|
borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
|
|
2596
2700
|
borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
|
|
@@ -2641,7 +2745,7 @@ var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLA
|
|
|
2641
2745
|
const updateMarketCollateral = (marketCollateral) => {
|
|
2642
2746
|
if (!collateralCoinNames.includes(marketCollateral.coinName))
|
|
2643
2747
|
return;
|
|
2644
|
-
marketCollateral.coinPrice = coinPrices[marketCollateral.coinName]
|
|
2748
|
+
marketCollateral.coinPrice = coinPrices[marketCollateral.coinName] ?? marketCollateral.coinPrice;
|
|
2645
2749
|
marketCollateral.coinWrappedType = query.utils.getCoinWrappedType(
|
|
2646
2750
|
marketCollateral.coinName
|
|
2647
2751
|
);
|
|
@@ -2673,7 +2777,7 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
|
|
|
2673
2777
|
coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
|
|
2674
2778
|
if (indexer) {
|
|
2675
2779
|
const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
|
|
2676
|
-
marketCollateralIndexer.coinPrice = coinPrice
|
|
2780
|
+
marketCollateralIndexer.coinPrice = coinPrice ?? marketCollateralIndexer.coinPrice;
|
|
2677
2781
|
marketCollateralIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
2678
2782
|
marketCollateralIndexer.coinName
|
|
2679
2783
|
);
|
|
@@ -2763,7 +2867,7 @@ var getObligations = async ({
|
|
|
2763
2867
|
address
|
|
2764
2868
|
}, ownerAddress) => {
|
|
2765
2869
|
const owner = ownerAddress;
|
|
2766
|
-
const protocolObjectId = address.get("core.object")
|
|
2870
|
+
const protocolObjectId = address.get("core.object") ?? PROTOCOL_OBJECT_ID;
|
|
2767
2871
|
const keyObjectsResponse = [];
|
|
2768
2872
|
let hasNextPage = false;
|
|
2769
2873
|
let nextCursor = null;
|
|
@@ -2830,7 +2934,7 @@ var queryObligation = async ({
|
|
|
2830
2934
|
return queryResult?.events[0]?.parsedJson;
|
|
2831
2935
|
};
|
|
2832
2936
|
var getCoinAmounts = async (query, assetCoinNames = [...SUPPORT_POOLS], ownerAddress) => {
|
|
2833
|
-
const owner = ownerAddress
|
|
2937
|
+
const owner = ownerAddress ?? query.suiKit.currentAddress();
|
|
2834
2938
|
const assetCoins2 = {};
|
|
2835
2939
|
await Promise.allSettled(
|
|
2836
2940
|
assetCoinNames.map(async (assetCoinName) => {
|
|
@@ -2841,7 +2945,7 @@ var getCoinAmounts = async (query, assetCoinNames = [...SUPPORT_POOLS], ownerAdd
|
|
|
2841
2945
|
return assetCoins2;
|
|
2842
2946
|
};
|
|
2843
2947
|
var getCoinAmount = async (query, assetCoinName, ownerAddress) => {
|
|
2844
|
-
const owner = ownerAddress
|
|
2948
|
+
const owner = ownerAddress ?? query.suiKit.currentAddress();
|
|
2845
2949
|
const coinType = query.utils.parseCoinType(assetCoinName);
|
|
2846
2950
|
const amount = await query.cache.queryGetCoinBalance({
|
|
2847
2951
|
owner,
|
|
@@ -2853,7 +2957,7 @@ var getMarketCoinAmounts = async (query, marketCoinNames, ownerAddress) => {
|
|
|
2853
2957
|
marketCoinNames = marketCoinNames || [...SUPPORT_POOLS].map(
|
|
2854
2958
|
(poolCoinName) => query.utils.parseMarketCoinName(poolCoinName)
|
|
2855
2959
|
);
|
|
2856
|
-
const owner = ownerAddress
|
|
2960
|
+
const owner = ownerAddress ?? query.suiKit.currentAddress();
|
|
2857
2961
|
const marketCoins2 = {};
|
|
2858
2962
|
await Promise.allSettled(
|
|
2859
2963
|
marketCoinNames.map(async (marketCoinName) => {
|
|
@@ -2868,7 +2972,7 @@ var getMarketCoinAmounts = async (query, marketCoinNames, ownerAddress) => {
|
|
|
2868
2972
|
return marketCoins2;
|
|
2869
2973
|
};
|
|
2870
2974
|
var getMarketCoinAmount = async (query, marketCoinName, ownerAddress) => {
|
|
2871
|
-
const owner = ownerAddress
|
|
2975
|
+
const owner = ownerAddress ?? query.suiKit.currentAddress();
|
|
2872
2976
|
const marketCoinType = query.utils.parseMarketCoinType(marketCoinName);
|
|
2873
2977
|
const amount = await query.cache.queryGetCoinBalance({
|
|
2874
2978
|
owner,
|
|
@@ -2937,18 +3041,14 @@ var getFlashLoanFees = async (query, assetNames) => {
|
|
|
2937
3041
|
|
|
2938
3042
|
// src/queries/spoolQuery.ts
|
|
2939
3043
|
import { normalizeStructTag as normalizeStructTag4 } from "@mysten/sui/utils";
|
|
2940
|
-
var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexer = false) => {
|
|
3044
|
+
var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexer = false, marketPools, coinPrices) => {
|
|
2941
3045
|
const stakeCoinNames = stakeMarketCoinNames.map(
|
|
2942
3046
|
(stakeMarketCoinName) => query.utils.parseCoinName(stakeMarketCoinName)
|
|
2943
3047
|
);
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
const coinPrices = await query.utils.getCoinPrices([
|
|
2949
|
-
.../* @__PURE__ */ new Set([...stakeCoinNames, ...rewardCoinNames])
|
|
2950
|
-
]) ?? {};
|
|
2951
|
-
const marketPools = await query.getMarketPools(stakeCoinNames, indexer);
|
|
3048
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
|
|
3049
|
+
marketPools = marketPools ?? await query.getMarketPools(stakeCoinNames, indexer);
|
|
3050
|
+
if (!marketPools)
|
|
3051
|
+
throw new Error(`Fail to fetch marketPools for ${stakeCoinNames}`);
|
|
2952
3052
|
const spools = {};
|
|
2953
3053
|
if (indexer) {
|
|
2954
3054
|
const spoolsIndexer = await query.indexer.getSpools();
|
|
@@ -2962,9 +3062,9 @@ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexe
|
|
|
2962
3062
|
spool.marketCoinName
|
|
2963
3063
|
);
|
|
2964
3064
|
const marketPool = marketPools[coinName];
|
|
2965
|
-
spool.coinPrice = coinPrices[coinName]
|
|
2966
|
-
spool.marketCoinPrice = (coinPrices[coinName] ?? 0) * (marketPool ? marketPool.conversionRate : 0)
|
|
2967
|
-
spool.rewardCoinPrice = coinPrices[rewardCoinName]
|
|
3065
|
+
spool.coinPrice = coinPrices[coinName] ?? spool.coinPrice;
|
|
3066
|
+
spool.marketCoinPrice = coinPrices[coinName] ? (coinPrices[coinName] ?? 0) * (marketPool ? marketPool.conversionRate : 0) : spool.marketCoinPrice;
|
|
3067
|
+
spool.rewardCoinPrice = coinPrices[rewardCoinName] ?? spool.rewardCoinPrice;
|
|
2968
3068
|
spools[spool.marketCoinName] = spool;
|
|
2969
3069
|
};
|
|
2970
3070
|
Object.values(spoolsIndexer).forEach(updateSpools);
|
|
@@ -2989,7 +3089,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
|
|
|
2989
3089
|
const coinName = query.utils.parseCoinName(marketCoinName);
|
|
2990
3090
|
marketPool = marketPool || await query.getMarketPool(coinName, indexer);
|
|
2991
3091
|
if (!marketPool) {
|
|
2992
|
-
throw new Error(
|
|
3092
|
+
throw new Error(`Fail to fetch marketPool for ${coinName}`);
|
|
2993
3093
|
}
|
|
2994
3094
|
const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
|
|
2995
3095
|
const rewardPoolId = query.address.get(
|
|
@@ -3276,20 +3376,15 @@ var queryBorrowIncentivePools = async (address) => {
|
|
|
3276
3376
|
};
|
|
3277
3377
|
var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
|
|
3278
3378
|
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
3279
|
-
], indexer = false) => {
|
|
3379
|
+
], indexer = false, coinPrices) => {
|
|
3280
3380
|
const borrowIncentivePools = {};
|
|
3281
|
-
|
|
3282
|
-
.../* @__PURE__ */ new Set([
|
|
3283
|
-
...borrowIncentiveCoinNames,
|
|
3284
|
-
...SUPPORT_BORROW_INCENTIVE_REWARDS
|
|
3285
|
-
])
|
|
3286
|
-
]) ?? {};
|
|
3381
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
|
|
3287
3382
|
if (indexer) {
|
|
3288
3383
|
const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
|
|
3289
3384
|
const updateBorrowIncentivePool = (pool) => {
|
|
3290
3385
|
if (!borrowIncentiveCoinNames.includes(pool.coinName))
|
|
3291
3386
|
return;
|
|
3292
|
-
pool.coinPrice = coinPrices[pool.coinName]
|
|
3387
|
+
pool.coinPrice = coinPrices[pool.coinName] ?? pool.coinPrice;
|
|
3293
3388
|
borrowIncentivePools[pool.coinName] = pool;
|
|
3294
3389
|
};
|
|
3295
3390
|
Object.values(borrowIncentivePoolsIndexer).forEach(
|
|
@@ -3536,20 +3631,18 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
|
|
|
3536
3631
|
const stakeMarketCoinNames = marketCoinNames.filter(
|
|
3537
3632
|
(marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
|
|
3538
3633
|
);
|
|
3539
|
-
const
|
|
3634
|
+
const coinPrices = await query.utils.getCoinPrices(poolCoinNames);
|
|
3635
|
+
const marketPools = await query.getMarketPools(poolCoinNames, indexer, {
|
|
3636
|
+
coinPrices
|
|
3637
|
+
});
|
|
3638
|
+
const spools = await query.getSpools(stakeMarketCoinNames, indexer, {
|
|
3540
3639
|
marketPools,
|
|
3541
|
-
spools,
|
|
3542
|
-
coinAmounts,
|
|
3543
|
-
marketCoinAmounts,
|
|
3544
|
-
allStakeAccounts,
|
|
3545
3640
|
coinPrices
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
query.getSpools(stakeMarketCoinNames, indexer),
|
|
3641
|
+
});
|
|
3642
|
+
const [coinAmounts, marketCoinAmounts, allStakeAccounts] = await Promise.all([
|
|
3549
3643
|
query.getCoinAmounts(poolCoinNames, ownerAddress),
|
|
3550
3644
|
query.getMarketCoinAmounts(marketCoinNames, ownerAddress),
|
|
3551
|
-
query.getAllStakeAccounts(ownerAddress)
|
|
3552
|
-
query.utils.getCoinPrices(poolCoinNames)
|
|
3645
|
+
query.getAllStakeAccounts(ownerAddress)
|
|
3553
3646
|
]);
|
|
3554
3647
|
const lendings = {};
|
|
3555
3648
|
await Promise.allSettled(
|
|
@@ -3565,7 +3658,7 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
|
|
|
3565
3658
|
indexer,
|
|
3566
3659
|
marketPools?.[poolCoinName],
|
|
3567
3660
|
stakeMarketCoinName ? spools[stakeMarketCoinName] : void 0,
|
|
3568
|
-
stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] :
|
|
3661
|
+
stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : [],
|
|
3569
3662
|
coinAmounts?.[poolCoinName],
|
|
3570
3663
|
marketCoinAmounts?.[marketCoinName],
|
|
3571
3664
|
coinPrices?.[poolCoinName] ?? 0
|
|
@@ -3576,8 +3669,22 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
|
|
|
3576
3669
|
};
|
|
3577
3670
|
var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice, sCoinAmount) => {
|
|
3578
3671
|
const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
|
|
3579
|
-
|
|
3580
|
-
|
|
3672
|
+
coinPrice = coinPrice ?? (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
|
|
3673
|
+
marketPool = marketPool ?? await query.getMarketPool(poolCoinName, indexer, {
|
|
3674
|
+
coinPrice
|
|
3675
|
+
});
|
|
3676
|
+
if (!marketPool)
|
|
3677
|
+
throw new Error(`Failed to fetch marketPool for ${poolCoinName}`);
|
|
3678
|
+
spool = spool ?? SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(
|
|
3679
|
+
marketCoinName,
|
|
3680
|
+
indexer,
|
|
3681
|
+
{
|
|
3682
|
+
marketPool,
|
|
3683
|
+
coinPrices: {
|
|
3684
|
+
[poolCoinName]: coinPrice
|
|
3685
|
+
}
|
|
3686
|
+
}
|
|
3687
|
+
) : void 0;
|
|
3581
3688
|
stakeAccounts = stakeAccounts || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getStakeAccounts(
|
|
3582
3689
|
marketCoinName,
|
|
3583
3690
|
ownerAddress
|
|
@@ -3585,7 +3692,6 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
3585
3692
|
coinAmount = coinAmount || await query.getCoinAmount(poolCoinName, ownerAddress);
|
|
3586
3693
|
marketCoinAmount = marketCoinAmount || await query.getMarketCoinAmount(marketCoinName, ownerAddress);
|
|
3587
3694
|
sCoinAmount = sCoinAmount || await query.getSCoinAmount(marketCoinName, ownerAddress);
|
|
3588
|
-
coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
3589
3695
|
const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
3590
3696
|
let stakedMarketAmount = BigNumber4(0);
|
|
3591
3697
|
let stakedMarketCoin = BigNumber4(0);
|
|
@@ -3697,10 +3803,12 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
3697
3803
|
return lending;
|
|
3698
3804
|
};
|
|
3699
3805
|
var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
|
|
3700
|
-
const market = await query.queryMarket(indexer);
|
|
3701
3806
|
const coinPrices = await query.utils.getCoinPrices();
|
|
3702
|
-
const
|
|
3703
|
-
const obligations = await
|
|
3807
|
+
const market = await query.queryMarket(indexer, { coinPrices });
|
|
3808
|
+
const [coinAmounts, obligations] = await Promise.all([
|
|
3809
|
+
query.getCoinAmounts(void 0, ownerAddress),
|
|
3810
|
+
query.getObligations(ownerAddress)
|
|
3811
|
+
]);
|
|
3704
3812
|
const obligationAccounts = {};
|
|
3705
3813
|
await Promise.allSettled(
|
|
3706
3814
|
obligations.map(async (obligation) => {
|
|
@@ -3718,22 +3826,19 @@ var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
|
|
|
3718
3826
|
return obligationAccounts;
|
|
3719
3827
|
};
|
|
3720
3828
|
var getObligationAccount = async (query, obligationId, ownerAddress, indexer = false, market, coinPrices, coinAmounts) => {
|
|
3721
|
-
market = market || await query.queryMarket(indexer);
|
|
3722
3829
|
const collateralAssetCoinNames = [
|
|
3723
|
-
|
|
3724
|
-
...Object.values(market.collaterals).map(
|
|
3725
|
-
(collateral) => collateral.coinName
|
|
3726
|
-
)
|
|
3727
|
-
])
|
|
3830
|
+
...SUPPORT_COLLATERALS
|
|
3728
3831
|
];
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
void 0,
|
|
3732
|
-
indexer
|
|
3733
|
-
);
|
|
3734
|
-
const borrowIncentiveAccounts = await query.getBorrowIncentiveAccounts(obligationId);
|
|
3735
|
-
coinPrices = coinPrices || await query.utils.getCoinPrices(collateralAssetCoinNames);
|
|
3832
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices(collateralAssetCoinNames);
|
|
3833
|
+
market = market ?? await query.queryMarket(indexer, { coinPrices });
|
|
3736
3834
|
coinAmounts = coinAmounts || await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress);
|
|
3835
|
+
const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] = await Promise.all([
|
|
3836
|
+
query.queryObligation(obligationId),
|
|
3837
|
+
query.getBorrowIncentivePools(void 0, indexer, {
|
|
3838
|
+
coinPrices
|
|
3839
|
+
}),
|
|
3840
|
+
query.getBorrowIncentiveAccounts(obligationId)
|
|
3841
|
+
]);
|
|
3737
3842
|
const collaterals = {};
|
|
3738
3843
|
const debts = {};
|
|
3739
3844
|
const borrowIncentives = {};
|
|
@@ -4262,7 +4367,7 @@ var getLoyaltyProgramInformations = async (query, veScaKey) => {
|
|
|
4262
4367
|
totalPoolReward,
|
|
4263
4368
|
isClaimEnabled
|
|
4264
4369
|
};
|
|
4265
|
-
veScaKey = veScaKey
|
|
4370
|
+
veScaKey = veScaKey ?? (await query.getVeScas())[0]?.keyObject;
|
|
4266
4371
|
if (!veScaKey)
|
|
4267
4372
|
return result;
|
|
4268
4373
|
const userRewardTableId = query.address.get(
|
|
@@ -4284,16 +4389,39 @@ var getLoyaltyProgramInformations = async (query, veScaKey) => {
|
|
|
4284
4389
|
return result;
|
|
4285
4390
|
};
|
|
4286
4391
|
|
|
4287
|
-
// src/
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4392
|
+
// src/models/suiKit.ts
|
|
4393
|
+
import { SuiKit as SuiKit2 } from "@scallop-io/sui-kit";
|
|
4394
|
+
|
|
4395
|
+
// src/constants/rpc.ts
|
|
4396
|
+
import { getFullnodeUrl } from "@mysten/sui/client";
|
|
4397
|
+
var RPC_PROVIDERS = [
|
|
4398
|
+
getFullnodeUrl("mainnet"),
|
|
4399
|
+
"https://sui-mainnet.public.blastapi.io",
|
|
4400
|
+
"https://sui-mainnet-ca-2.cosmostation.io",
|
|
4401
|
+
"https://sui-mainnet-eu-4.cosmostation.io",
|
|
4402
|
+
"https://sui-mainnet-endpoint.blockvision.org",
|
|
4403
|
+
"https://sui-rpc.publicnode.com",
|
|
4404
|
+
"https://sui-mainnet-rpc.allthatnode.com",
|
|
4405
|
+
"https://mainnet.suiet.app",
|
|
4406
|
+
"https://mainnet.sui.rpcpool.com",
|
|
4407
|
+
"https://sui1mainnet-rpc.chainode.tech",
|
|
4408
|
+
"https://fullnode.mainnet.apis.scallop.io",
|
|
4409
|
+
"https://sui-mainnet-us-2.cosmostation.io"
|
|
4410
|
+
];
|
|
4411
|
+
|
|
4412
|
+
// src/models/suiKit.ts
|
|
4413
|
+
var newSuiKit = (params) => {
|
|
4414
|
+
return new SuiKit2({
|
|
4415
|
+
...params,
|
|
4416
|
+
fullnodeUrls: Array.from(
|
|
4417
|
+
/* @__PURE__ */ new Set([...params.fullnodeUrls ?? [], ...RPC_PROVIDERS])
|
|
4418
|
+
)
|
|
4419
|
+
});
|
|
4291
4420
|
};
|
|
4292
4421
|
|
|
4293
4422
|
// src/models/scallopUtils.ts
|
|
4294
4423
|
var ScallopUtils = class {
|
|
4295
4424
|
constructor(params, instance) {
|
|
4296
|
-
this._priceMap = /* @__PURE__ */ new Map();
|
|
4297
4425
|
/**
|
|
4298
4426
|
* Get reward type of spool.
|
|
4299
4427
|
*
|
|
@@ -4316,7 +4444,7 @@ var ScallopUtils = class {
|
|
|
4316
4444
|
pythEndpoints: params.pythEndpoints ?? PYTH_ENDPOINTS["mainnet"],
|
|
4317
4445
|
...params
|
|
4318
4446
|
};
|
|
4319
|
-
this.suiKit = instance?.suiKit ?? instance?.address?.cache._suiKit ??
|
|
4447
|
+
this.suiKit = instance?.suiKit ?? instance?.address?.cache._suiKit ?? newSuiKit(params);
|
|
4320
4448
|
this.walletAddress = params.walletAddress ?? this.suiKit.currentAddress();
|
|
4321
4449
|
if (instance?.address) {
|
|
4322
4450
|
this.address = instance.address;
|
|
@@ -4330,7 +4458,7 @@ var ScallopUtils = class {
|
|
|
4330
4458
|
);
|
|
4331
4459
|
this.address = instance?.address ?? new ScallopAddress(
|
|
4332
4460
|
{
|
|
4333
|
-
id: params?.addressesId
|
|
4461
|
+
id: params?.addressesId ?? ADDRESSES_ID,
|
|
4334
4462
|
network: params?.networkType,
|
|
4335
4463
|
forceInterface: params?.forceAddressesInterface
|
|
4336
4464
|
},
|
|
@@ -4444,6 +4572,14 @@ var ScallopUtils = class {
|
|
|
4444
4572
|
parseSCoinType(sCoinName) {
|
|
4445
4573
|
return sCoinIds[sCoinName];
|
|
4446
4574
|
}
|
|
4575
|
+
/**
|
|
4576
|
+
* Convert sCoinType into sCoin name
|
|
4577
|
+
* @param sCoinType
|
|
4578
|
+
* @returns sCoin name
|
|
4579
|
+
*/
|
|
4580
|
+
parseSCoinNameFromType(sCoinType) {
|
|
4581
|
+
return sCoinTypeToName[sCoinType];
|
|
4582
|
+
}
|
|
4447
4583
|
/**
|
|
4448
4584
|
* Convert sCoin name into its underlying coin type
|
|
4449
4585
|
* @param sCoinName
|
|
@@ -4469,7 +4605,7 @@ var ScallopUtils = class {
|
|
|
4469
4605
|
* @return Market coin type.
|
|
4470
4606
|
*/
|
|
4471
4607
|
parseMarketCoinType(coinName) {
|
|
4472
|
-
const protocolObjectId = this.address.get("core.object")
|
|
4608
|
+
const protocolObjectId = this.address.get("core.object") ?? PROTOCOL_OBJECT_ID;
|
|
4473
4609
|
const coinType = this.parseCoinType(coinName);
|
|
4474
4610
|
return `${protocolObjectId}::reserve::MarketCoin<${coinType}>`;
|
|
4475
4611
|
}
|
|
@@ -4478,7 +4614,7 @@ var ScallopUtils = class {
|
|
|
4478
4614
|
const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
|
|
4479
4615
|
const coinTypeMatch = coinType.match(coinTypeRegex);
|
|
4480
4616
|
const isMarketCoinType = coinType.includes("reserve::MarketCoin");
|
|
4481
|
-
coinType = coinTypeMatch?.[1]
|
|
4617
|
+
coinType = coinTypeMatch?.[1] ?? coinType;
|
|
4482
4618
|
const wormHoleCoinTypeMap = {
|
|
4483
4619
|
[`${this.address.get("core.coins.wusdc.id") ?? wormholeCoinIds.wusdc}::coin::COIN`]: "wusdc",
|
|
4484
4620
|
[`${this.address.get("core.coins.wusdt.id") ?? wormholeCoinIds.wusdt}::coin::COIN`]: "wusdt",
|
|
@@ -4556,7 +4692,7 @@ var ScallopUtils = class {
|
|
|
4556
4692
|
* @return The selected transaction coin arguments.
|
|
4557
4693
|
*/
|
|
4558
4694
|
async selectCoins(amount, coinType = SUI_TYPE_ARG, ownerAddress) {
|
|
4559
|
-
ownerAddress = ownerAddress
|
|
4695
|
+
ownerAddress = ownerAddress ?? this.suiKit.currentAddress();
|
|
4560
4696
|
const coins = await this.suiKit.suiInteractor.selectCoins(
|
|
4561
4697
|
ownerAddress,
|
|
4562
4698
|
amount,
|
|
@@ -4624,86 +4760,59 @@ var ScallopUtils = class {
|
|
|
4624
4760
|
* @param assetCoinNames - Specific an array of support asset coin name.
|
|
4625
4761
|
* @return Asset coin price.
|
|
4626
4762
|
*/
|
|
4627
|
-
async getCoinPrices(
|
|
4763
|
+
async getCoinPrices(_ = [
|
|
4628
4764
|
.../* @__PURE__ */ new Set([...SUPPORT_POOLS, ...SUPPORT_COLLATERALS])
|
|
4629
4765
|
]) {
|
|
4630
|
-
|
|
4631
|
-
const
|
|
4632
|
-
const
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
)
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
for (const coinName of existPricesCoinNames) {
|
|
4647
|
-
coinPrices[coinName] = this._priceMap.get(coinName).price;
|
|
4648
|
-
}
|
|
4649
|
-
}
|
|
4650
|
-
if (lackPricesCoinNames.length > 0) {
|
|
4651
|
-
const endpoints = this.params.pythEndpoints ?? PYTH_ENDPOINTS[this.isTestnet ? "testnet" : "mainnet"];
|
|
4652
|
-
const failedRequests = new Set(
|
|
4653
|
-
lackPricesCoinNames
|
|
4766
|
+
let coinPrices = {};
|
|
4767
|
+
const endpoints = this.params.pythEndpoints ?? PYTH_ENDPOINTS[this.isTestnet ? "testnet" : "mainnet"];
|
|
4768
|
+
const failedRequests = /* @__PURE__ */ new Set([
|
|
4769
|
+
...SUPPORT_POOLS,
|
|
4770
|
+
...SUPPORT_COLLATERALS
|
|
4771
|
+
]);
|
|
4772
|
+
for (const endpoint of endpoints) {
|
|
4773
|
+
const priceIdPairs = Array.from(failedRequests.values()).reduce(
|
|
4774
|
+
(acc, coinName) => {
|
|
4775
|
+
const priceId = this.address.get(
|
|
4776
|
+
`core.coins.${coinName}.oracle.pyth.feed`
|
|
4777
|
+
);
|
|
4778
|
+
acc.push([coinName, priceId]);
|
|
4779
|
+
return acc;
|
|
4780
|
+
},
|
|
4781
|
+
[]
|
|
4654
4782
|
);
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4783
|
+
const priceIds = priceIdPairs.map(([_2, priceId]) => priceId);
|
|
4784
|
+
const pythConnection = new SuiPriceServiceConnection(endpoint, {
|
|
4785
|
+
timeout: 2e3
|
|
4786
|
+
});
|
|
4787
|
+
try {
|
|
4788
|
+
const feeds = await this.cache.queryClient.fetchQuery({
|
|
4789
|
+
queryKey: queryKeys.oracle.getPythLatestPriceFeeds(),
|
|
4790
|
+
queryFn: async () => {
|
|
4791
|
+
return await pythConnection.getLatestPriceFeeds(priceIds);
|
|
4663
4792
|
},
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
const data = parseDataFromPythPriceFeed(feed[0], this.address);
|
|
4678
|
-
this._priceMap.set(coinName, {
|
|
4679
|
-
price: data.price,
|
|
4680
|
-
publishTime: data.publishTime
|
|
4681
|
-
});
|
|
4682
|
-
coinPrices[coinName] = data.price;
|
|
4683
|
-
}
|
|
4684
|
-
failedRequests.delete(coinName);
|
|
4685
|
-
} catch (e) {
|
|
4686
|
-
console.warn(
|
|
4687
|
-
`Failed to get price ${coinName} feeds with endpoint ${endpoint}: ${e}`
|
|
4688
|
-
);
|
|
4689
|
-
}
|
|
4690
|
-
})
|
|
4691
|
-
);
|
|
4692
|
-
if (failedRequests.size === 0)
|
|
4693
|
-
break;
|
|
4694
|
-
}
|
|
4695
|
-
if (failedRequests.size > 0) {
|
|
4696
|
-
await Promise.allSettled(
|
|
4697
|
-
Array.from(failedRequests.values()).map(async (coinName) => {
|
|
4698
|
-
const price = await getPythPrice(this, coinName);
|
|
4699
|
-
this._priceMap.set(coinName, {
|
|
4700
|
-
price,
|
|
4701
|
-
publishTime: Date.now()
|
|
4702
|
-
});
|
|
4703
|
-
coinPrices[coinName] = price;
|
|
4704
|
-
})
|
|
4705
|
-
);
|
|
4793
|
+
staleTime: 3e4,
|
|
4794
|
+
gcTime: 3e4
|
|
4795
|
+
});
|
|
4796
|
+
if (feeds) {
|
|
4797
|
+
feeds.forEach((feed, idx) => {
|
|
4798
|
+
const coinName = priceIdPairs[idx][0];
|
|
4799
|
+
const data = parseDataFromPythPriceFeed(feed, this.address);
|
|
4800
|
+
coinPrices[coinName] = data.price;
|
|
4801
|
+
failedRequests.delete(coinName);
|
|
4802
|
+
});
|
|
4803
|
+
}
|
|
4804
|
+
} catch (e) {
|
|
4805
|
+
console.error(e.message);
|
|
4706
4806
|
}
|
|
4807
|
+
if (failedRequests.size === 0)
|
|
4808
|
+
break;
|
|
4809
|
+
}
|
|
4810
|
+
if (failedRequests.size > 0) {
|
|
4811
|
+
coinPrices = {
|
|
4812
|
+
...coinPrices,
|
|
4813
|
+
...await getPythPrices(this, Array.from(failedRequests.values()))
|
|
4814
|
+
};
|
|
4815
|
+
failedRequests.clear();
|
|
4707
4816
|
}
|
|
4708
4817
|
return coinPrices;
|
|
4709
4818
|
}
|
|
@@ -4759,11 +4868,30 @@ var ScallopUtils = class {
|
|
|
4759
4868
|
}
|
|
4760
4869
|
return findClosestUnlockRound(newUnlockAtInSecondTimestamp);
|
|
4761
4870
|
}
|
|
4871
|
+
/**
|
|
4872
|
+
* Get detailed contract address and price id information for supported pool in Scallop
|
|
4873
|
+
* @returns Supported pool informations
|
|
4874
|
+
*/
|
|
4875
|
+
getSupportedPoolAddresses() {
|
|
4876
|
+
return SUPPORT_POOLS.map((poolName) => {
|
|
4877
|
+
const sCoinName = this.parseSCoinName(poolName);
|
|
4878
|
+
return {
|
|
4879
|
+
name: this.parseSymbol(poolName),
|
|
4880
|
+
coingeckoId: COIN_GECKGO_IDS[poolName],
|
|
4881
|
+
decimal: coinDecimals[poolName],
|
|
4882
|
+
pythFeedId: PYTH_FEED_IDS[poolName],
|
|
4883
|
+
...POOL_ADDRESSES[poolName],
|
|
4884
|
+
sCoinAddress: sCoinIds[sCoinName],
|
|
4885
|
+
marketCoinAddress: this.parseMarketCoinType(poolName),
|
|
4886
|
+
coinAddress: this.parseCoinType(poolName),
|
|
4887
|
+
sCoinName: sCoinName ? this.parseSymbol(sCoinName) : void 0
|
|
4888
|
+
};
|
|
4889
|
+
});
|
|
4890
|
+
}
|
|
4762
4891
|
};
|
|
4763
4892
|
|
|
4764
4893
|
// src/models/scallopBuilder.ts
|
|
4765
4894
|
import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui/utils";
|
|
4766
|
-
import { SuiKit as SuiKit5 } from "@scallop-io/sui-kit";
|
|
4767
4895
|
|
|
4768
4896
|
// src/builders/coreBuilder.ts
|
|
4769
4897
|
import { Transaction } from "@mysten/sui/transactions";
|
|
@@ -6208,7 +6336,7 @@ var generateLoyaltyProgramQuickMethod = ({
|
|
|
6208
6336
|
}) => {
|
|
6209
6337
|
return {
|
|
6210
6338
|
claimLoyaltyRevenueQuick: async (veScaKey) => {
|
|
6211
|
-
veScaKey = veScaKey
|
|
6339
|
+
veScaKey = veScaKey ?? (await builder.query.getVeScas())[0]?.keyObject;
|
|
6212
6340
|
const sender = requireSender(txBlock);
|
|
6213
6341
|
if (!veScaKey)
|
|
6214
6342
|
throw new Error(`No veScaKey found for user ${sender}`);
|
|
@@ -6372,9 +6500,6 @@ var newScallopTxBlock = (builder, initTxBlock) => {
|
|
|
6372
6500
|
});
|
|
6373
6501
|
};
|
|
6374
6502
|
|
|
6375
|
-
// src/models/scallopQuery.ts
|
|
6376
|
-
import { SuiKit as SuiKit4 } from "@scallop-io/sui-kit";
|
|
6377
|
-
|
|
6378
6503
|
// src/models/scallopIndexer.ts
|
|
6379
6504
|
import axios2 from "axios";
|
|
6380
6505
|
import { SuiKit as SuiKit3 } from "@scallop-io/sui-kit";
|
|
@@ -6732,9 +6857,9 @@ var isIsolatedAsset = async (utils, coinName) => {
|
|
|
6732
6857
|
var ScallopQuery = class {
|
|
6733
6858
|
constructor(params, instance) {
|
|
6734
6859
|
this.params = params;
|
|
6735
|
-
this.suiKit = instance?.suiKit ?? instance?.utils?.suiKit ??
|
|
6860
|
+
this.suiKit = instance?.suiKit ?? instance?.utils?.suiKit ?? newSuiKit(params);
|
|
6736
6861
|
this.walletAddress = normalizeSuiAddress(
|
|
6737
|
-
params.walletAddress
|
|
6862
|
+
params.walletAddress ?? this.suiKit.currentAddress()
|
|
6738
6863
|
);
|
|
6739
6864
|
if (instance?.utils) {
|
|
6740
6865
|
this.utils = instance.utils;
|
|
@@ -6748,7 +6873,7 @@ var ScallopQuery = class {
|
|
|
6748
6873
|
);
|
|
6749
6874
|
this.address = new ScallopAddress(
|
|
6750
6875
|
{
|
|
6751
|
-
id: params?.addressesId
|
|
6876
|
+
id: params?.addressesId ?? ADDRESSES_ID,
|
|
6752
6877
|
network: params?.networkType,
|
|
6753
6878
|
forceInterface: params?.forceAddressesInterface
|
|
6754
6879
|
},
|
|
@@ -6811,8 +6936,8 @@ var ScallopQuery = class {
|
|
|
6811
6936
|
* @param indexer - Whether to use indexer.
|
|
6812
6937
|
* @return Market data.
|
|
6813
6938
|
*/
|
|
6814
|
-
async queryMarket(indexer = false) {
|
|
6815
|
-
return await queryMarket(this, indexer);
|
|
6939
|
+
async queryMarket(indexer = false, args) {
|
|
6940
|
+
return await queryMarket(this, indexer, args?.coinPrices);
|
|
6816
6941
|
}
|
|
6817
6942
|
/**
|
|
6818
6943
|
* Get market pools.
|
|
@@ -6825,8 +6950,8 @@ var ScallopQuery = class {
|
|
|
6825
6950
|
* @param indexer - Whether to use indexer.
|
|
6826
6951
|
* @return Market pools data.
|
|
6827
6952
|
*/
|
|
6828
|
-
async getMarketPools(poolCoinNames, indexer = false) {
|
|
6829
|
-
return await getMarketPools(this, poolCoinNames, indexer);
|
|
6953
|
+
async getMarketPools(poolCoinNames, indexer = false, args) {
|
|
6954
|
+
return await getMarketPools(this, poolCoinNames, indexer, args?.coinPrices);
|
|
6830
6955
|
}
|
|
6831
6956
|
/**
|
|
6832
6957
|
* Get market pool
|
|
@@ -6835,8 +6960,14 @@ var ScallopQuery = class {
|
|
|
6835
6960
|
* @param indexer - Whether to use indexer.
|
|
6836
6961
|
* @return Market pool data.
|
|
6837
6962
|
*/
|
|
6838
|
-
async getMarketPool(poolCoinName, indexer = false) {
|
|
6839
|
-
return await getMarketPool(
|
|
6963
|
+
async getMarketPool(poolCoinName, indexer = false, args) {
|
|
6964
|
+
return await getMarketPool(
|
|
6965
|
+
this,
|
|
6966
|
+
poolCoinName,
|
|
6967
|
+
indexer,
|
|
6968
|
+
args?.marketObject,
|
|
6969
|
+
args?.coinPrice
|
|
6970
|
+
);
|
|
6840
6971
|
}
|
|
6841
6972
|
/**
|
|
6842
6973
|
* Get market collaterals.
|
|
@@ -6946,8 +7077,14 @@ var ScallopQuery = class {
|
|
|
6946
7077
|
* @param indexer - Whether to use indexer.
|
|
6947
7078
|
* @return Spools data.
|
|
6948
7079
|
*/
|
|
6949
|
-
async getSpools(stakeMarketCoinNames, indexer = false) {
|
|
6950
|
-
return await getSpools(
|
|
7080
|
+
async getSpools(stakeMarketCoinNames, indexer = false, args) {
|
|
7081
|
+
return await getSpools(
|
|
7082
|
+
this,
|
|
7083
|
+
stakeMarketCoinNames,
|
|
7084
|
+
indexer,
|
|
7085
|
+
args?.marketPools,
|
|
7086
|
+
args?.coinPrices
|
|
7087
|
+
);
|
|
6951
7088
|
}
|
|
6952
7089
|
/**
|
|
6953
7090
|
* Get spool data.
|
|
@@ -6956,8 +7093,14 @@ var ScallopQuery = class {
|
|
|
6956
7093
|
* @param indexer - Whether to use indexer.
|
|
6957
7094
|
* @return Spool data.
|
|
6958
7095
|
*/
|
|
6959
|
-
async getSpool(stakeMarketCoinName, indexer = false) {
|
|
6960
|
-
return await getSpool(
|
|
7096
|
+
async getSpool(stakeMarketCoinName, indexer = false, args) {
|
|
7097
|
+
return await getSpool(
|
|
7098
|
+
this,
|
|
7099
|
+
stakeMarketCoinName,
|
|
7100
|
+
indexer,
|
|
7101
|
+
args?.marketPool,
|
|
7102
|
+
args?.coinPrices
|
|
7103
|
+
);
|
|
6961
7104
|
}
|
|
6962
7105
|
/**
|
|
6963
7106
|
* Get stake accounts data for all stake pools (spools).
|
|
@@ -7057,8 +7200,13 @@ var ScallopQuery = class {
|
|
|
7057
7200
|
* @param indexer - Whether to use indexer.
|
|
7058
7201
|
* @return Borrow incentive pools data.
|
|
7059
7202
|
*/
|
|
7060
|
-
async getBorrowIncentivePools(coinNames, indexer = false) {
|
|
7061
|
-
return await getBorrowIncentivePools(
|
|
7203
|
+
async getBorrowIncentivePools(coinNames, indexer = false, args) {
|
|
7204
|
+
return await getBorrowIncentivePools(
|
|
7205
|
+
this,
|
|
7206
|
+
coinNames,
|
|
7207
|
+
indexer,
|
|
7208
|
+
args?.coinPrices
|
|
7209
|
+
);
|
|
7062
7210
|
}
|
|
7063
7211
|
/**
|
|
7064
7212
|
* Get borrow incentive accounts data.
|
|
@@ -7271,10 +7419,10 @@ var ScallopQuery = class {
|
|
|
7271
7419
|
// src/models/scallopBuilder.ts
|
|
7272
7420
|
var ScallopBuilder = class {
|
|
7273
7421
|
constructor(params, instance) {
|
|
7274
|
-
this.suiKit = instance?.suiKit ??
|
|
7422
|
+
this.suiKit = instance?.suiKit ?? newSuiKit(params);
|
|
7275
7423
|
this.params = params;
|
|
7276
7424
|
this.walletAddress = normalizeSuiAddress2(
|
|
7277
|
-
params?.walletAddress
|
|
7425
|
+
params?.walletAddress ?? this.suiKit.currentAddress()
|
|
7278
7426
|
);
|
|
7279
7427
|
if (instance?.query) {
|
|
7280
7428
|
this.query = instance.query;
|
|
@@ -7289,7 +7437,7 @@ var ScallopBuilder = class {
|
|
|
7289
7437
|
);
|
|
7290
7438
|
this.address = new ScallopAddress(
|
|
7291
7439
|
{
|
|
7292
|
-
id: params?.addressesId
|
|
7440
|
+
id: params?.addressesId ?? ADDRESSES_ID,
|
|
7293
7441
|
network: params?.networkType,
|
|
7294
7442
|
forceInterface: params?.forceAddressesInterface
|
|
7295
7443
|
},
|
|
@@ -7419,9 +7567,9 @@ var ScallopBuilder = class {
|
|
|
7419
7567
|
var ScallopClient = class {
|
|
7420
7568
|
constructor(params, instance) {
|
|
7421
7569
|
this.params = params;
|
|
7422
|
-
this.suiKit = instance?.suiKit ?? instance?.builder?.suiKit ??
|
|
7570
|
+
this.suiKit = instance?.suiKit ?? instance?.builder?.suiKit ?? newSuiKit(params);
|
|
7423
7571
|
this.walletAddress = normalizeSuiAddress3(
|
|
7424
|
-
params?.walletAddress
|
|
7572
|
+
params?.walletAddress ?? this.suiKit.currentAddress()
|
|
7425
7573
|
);
|
|
7426
7574
|
if (instance?.builder) {
|
|
7427
7575
|
this.builder = instance.builder;
|
|
@@ -7437,7 +7585,7 @@ var ScallopClient = class {
|
|
|
7437
7585
|
);
|
|
7438
7586
|
this.address = new ScallopAddress(
|
|
7439
7587
|
{
|
|
7440
|
-
id: params?.addressesId
|
|
7588
|
+
id: params?.addressesId ?? ADDRESSES_ID,
|
|
7441
7589
|
network: params?.networkType,
|
|
7442
7590
|
forceInterface: params?.forceAddressesInterface
|
|
7443
7591
|
},
|
|
@@ -7491,7 +7639,7 @@ var ScallopClient = class {
|
|
|
7491
7639
|
* @return Obligations data.
|
|
7492
7640
|
*/
|
|
7493
7641
|
async getObligations(ownerAddress) {
|
|
7494
|
-
const owner = ownerAddress
|
|
7642
|
+
const owner = ownerAddress ?? this.walletAddress;
|
|
7495
7643
|
return await this.query.getObligations(owner);
|
|
7496
7644
|
}
|
|
7497
7645
|
/**
|
|
@@ -7516,7 +7664,7 @@ var ScallopClient = class {
|
|
|
7516
7664
|
* @return All stake accounts data.
|
|
7517
7665
|
*/
|
|
7518
7666
|
async getAllStakeAccounts(ownerAddress) {
|
|
7519
|
-
const owner = ownerAddress
|
|
7667
|
+
const owner = ownerAddress ?? this.walletAddress;
|
|
7520
7668
|
return await this.query.getAllStakeAccounts(owner);
|
|
7521
7669
|
}
|
|
7522
7670
|
/**
|
|
@@ -7530,7 +7678,7 @@ var ScallopClient = class {
|
|
|
7530
7678
|
* @return Stake accounts data.
|
|
7531
7679
|
*/
|
|
7532
7680
|
async getStakeAccounts(stakeMarketCoinName, ownerAddress) {
|
|
7533
|
-
const owner = ownerAddress
|
|
7681
|
+
const owner = ownerAddress ?? this.walletAddress;
|
|
7534
7682
|
return await this.query.getStakeAccounts(stakeMarketCoinName, owner);
|
|
7535
7683
|
}
|
|
7536
7684
|
/**
|
|
@@ -7570,10 +7718,10 @@ var ScallopClient = class {
|
|
|
7570
7718
|
}
|
|
7571
7719
|
async depositCollateral(collateralCoinName, amount, sign = true, obligationId, walletAddress) {
|
|
7572
7720
|
const txBlock = this.builder.createTxBlock();
|
|
7573
|
-
const sender = walletAddress
|
|
7721
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7574
7722
|
txBlock.setSender(sender);
|
|
7575
7723
|
const obligations = await this.query.getObligations(sender);
|
|
7576
|
-
const specificObligationId = obligationId
|
|
7724
|
+
const specificObligationId = obligationId ?? obligations[0]?.id;
|
|
7577
7725
|
if (specificObligationId) {
|
|
7578
7726
|
await txBlock.addCollateralQuick(
|
|
7579
7727
|
amount,
|
|
@@ -7607,7 +7755,7 @@ var ScallopClient = class {
|
|
|
7607
7755
|
*/
|
|
7608
7756
|
async withdrawCollateral(collateralCoinName, amount, sign = true, obligationId, obligationKey, walletAddress) {
|
|
7609
7757
|
const txBlock = this.builder.createTxBlock();
|
|
7610
|
-
const sender = walletAddress
|
|
7758
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7611
7759
|
txBlock.setSender(sender);
|
|
7612
7760
|
const collateralCoin = await txBlock.takeCollateralQuick(
|
|
7613
7761
|
amount,
|
|
@@ -7626,7 +7774,7 @@ var ScallopClient = class {
|
|
|
7626
7774
|
}
|
|
7627
7775
|
async deposit(poolCoinName, amount, sign = true, walletAddress) {
|
|
7628
7776
|
const txBlock = this.builder.createTxBlock();
|
|
7629
|
-
const sender = walletAddress
|
|
7777
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7630
7778
|
txBlock.setSender(sender);
|
|
7631
7779
|
const sCoin = await txBlock.depositQuick(amount, poolCoinName);
|
|
7632
7780
|
txBlock.transferObjects([sCoin], sender);
|
|
@@ -7640,11 +7788,11 @@ var ScallopClient = class {
|
|
|
7640
7788
|
}
|
|
7641
7789
|
async depositAndStake(stakeCoinName, amount, sign = true, stakeAccountId, walletAddress) {
|
|
7642
7790
|
const txBlock = this.builder.createTxBlock();
|
|
7643
|
-
const sender = walletAddress
|
|
7791
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7644
7792
|
txBlock.setSender(sender);
|
|
7645
7793
|
const stakeMarketCoinName = this.utils.parseMarketCoinName(stakeCoinName);
|
|
7646
7794
|
const stakeAccounts = await this.query.getStakeAccounts(stakeMarketCoinName);
|
|
7647
|
-
const targetStakeAccount = stakeAccountId
|
|
7795
|
+
const targetStakeAccount = stakeAccountId ?? stakeAccounts[0]?.id;
|
|
7648
7796
|
const marketCoin = await txBlock.depositQuick(amount, stakeCoinName, false);
|
|
7649
7797
|
if (targetStakeAccount) {
|
|
7650
7798
|
await txBlock.stakeQuick(
|
|
@@ -7667,7 +7815,7 @@ var ScallopClient = class {
|
|
|
7667
7815
|
}
|
|
7668
7816
|
async withdraw(poolCoinName, amount, sign = true, walletAddress) {
|
|
7669
7817
|
const txBlock = this.builder.createTxBlock();
|
|
7670
|
-
const sender = walletAddress
|
|
7818
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7671
7819
|
txBlock.setSender(sender);
|
|
7672
7820
|
const coin = await txBlock.withdrawQuick(amount, poolCoinName);
|
|
7673
7821
|
txBlock.transferObjects([coin], sender);
|
|
@@ -7692,7 +7840,7 @@ var ScallopClient = class {
|
|
|
7692
7840
|
*/
|
|
7693
7841
|
async borrow(poolCoinName, amount, sign = true, obligationId, obligationKey, walletAddress) {
|
|
7694
7842
|
const txBlock = this.builder.createTxBlock();
|
|
7695
|
-
const sender = walletAddress
|
|
7843
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7696
7844
|
txBlock.setSender(sender);
|
|
7697
7845
|
const availableStake = SUPPORT_BORROW_INCENTIVE_POOLS.includes(poolCoinName);
|
|
7698
7846
|
if (sign && availableStake) {
|
|
@@ -7728,7 +7876,7 @@ var ScallopClient = class {
|
|
|
7728
7876
|
*/
|
|
7729
7877
|
async repay(poolCoinName, amount, sign = true, obligationId, obligationKey, walletAddress) {
|
|
7730
7878
|
const txBlock = this.builder.createTxBlock();
|
|
7731
|
-
const sender = walletAddress
|
|
7879
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7732
7880
|
txBlock.setSender(sender);
|
|
7733
7881
|
const availableStake = SUPPORT_BORROW_INCENTIVE_POOLS.includes(poolCoinName);
|
|
7734
7882
|
if (sign && availableStake) {
|
|
@@ -7748,7 +7896,7 @@ var ScallopClient = class {
|
|
|
7748
7896
|
}
|
|
7749
7897
|
async flashLoan(poolCoinName, amount, callback, sign = true, walletAddress) {
|
|
7750
7898
|
const txBlock = this.builder.createTxBlock();
|
|
7751
|
-
const sender = walletAddress
|
|
7899
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7752
7900
|
txBlock.setSender(sender);
|
|
7753
7901
|
const [coin, loan] = txBlock.borrowFlashLoan(amount, poolCoinName);
|
|
7754
7902
|
txBlock.repayFlashLoan(await callback(txBlock, coin), loan, poolCoinName);
|
|
@@ -7762,7 +7910,7 @@ var ScallopClient = class {
|
|
|
7762
7910
|
}
|
|
7763
7911
|
async createStakeAccount(marketCoinName, sign = true, walletAddress) {
|
|
7764
7912
|
const txBlock = this.builder.createTxBlock();
|
|
7765
|
-
const sender = walletAddress
|
|
7913
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7766
7914
|
txBlock.setSender(sender);
|
|
7767
7915
|
const stakeAccount = txBlock.createStakeAccount(marketCoinName);
|
|
7768
7916
|
txBlock.transferObjects([stakeAccount], sender);
|
|
@@ -7776,10 +7924,10 @@ var ScallopClient = class {
|
|
|
7776
7924
|
}
|
|
7777
7925
|
async stake(stakeMarketCoinName, amount, sign = true, stakeAccountId, walletAddress) {
|
|
7778
7926
|
const txBlock = this.builder.createTxBlock();
|
|
7779
|
-
const sender = walletAddress
|
|
7927
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7780
7928
|
txBlock.setSender(sender);
|
|
7781
7929
|
const stakeAccounts = await this.query.getStakeAccounts(stakeMarketCoinName);
|
|
7782
|
-
const targetStakeAccount = stakeAccountId
|
|
7930
|
+
const targetStakeAccount = stakeAccountId ?? stakeAccounts[0]?.id;
|
|
7783
7931
|
if (targetStakeAccount) {
|
|
7784
7932
|
await txBlock.stakeQuick(amount, stakeMarketCoinName, targetStakeAccount);
|
|
7785
7933
|
} else {
|
|
@@ -7797,7 +7945,7 @@ var ScallopClient = class {
|
|
|
7797
7945
|
}
|
|
7798
7946
|
async unstake(stakeMarketCoinName, amount, sign = true, stakeAccountId, walletAddress) {
|
|
7799
7947
|
const txBlock = this.builder.createTxBlock();
|
|
7800
|
-
const sender = walletAddress
|
|
7948
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7801
7949
|
txBlock.setSender(sender);
|
|
7802
7950
|
const sCoin = await txBlock.unstakeQuick(
|
|
7803
7951
|
amount,
|
|
@@ -7823,7 +7971,7 @@ var ScallopClient = class {
|
|
|
7823
7971
|
}
|
|
7824
7972
|
async unstakeAndWithdraw(stakeMarketCoinName, amount, sign = true, stakeAccountId, walletAddress) {
|
|
7825
7973
|
const txBlock = this.builder.createTxBlock();
|
|
7826
|
-
const sender = walletAddress
|
|
7974
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7827
7975
|
txBlock.setSender(sender);
|
|
7828
7976
|
const stakeMarketCoin = await txBlock.unstakeQuick(
|
|
7829
7977
|
amount,
|
|
@@ -7854,7 +8002,7 @@ var ScallopClient = class {
|
|
|
7854
8002
|
}
|
|
7855
8003
|
async claim(stakeMarketCoinName, sign = true, stakeAccountId, walletAddress) {
|
|
7856
8004
|
const txBlock = this.builder.createTxBlock();
|
|
7857
|
-
const sender = walletAddress
|
|
8005
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7858
8006
|
txBlock.setSender(sender);
|
|
7859
8007
|
const rewardCoins = await txBlock.claimQuick(
|
|
7860
8008
|
stakeMarketCoinName,
|
|
@@ -7881,7 +8029,7 @@ var ScallopClient = class {
|
|
|
7881
8029
|
*/
|
|
7882
8030
|
async stakeObligation(obligationId, obligationKeyId, sign = true, walletAddress) {
|
|
7883
8031
|
const txBlock = this.builder.createTxBlock();
|
|
7884
|
-
const sender = walletAddress
|
|
8032
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7885
8033
|
txBlock.setSender(sender);
|
|
7886
8034
|
await txBlock.stakeObligationWithVeScaQuick(obligationId, obligationKeyId);
|
|
7887
8035
|
if (sign) {
|
|
@@ -7903,7 +8051,7 @@ var ScallopClient = class {
|
|
|
7903
8051
|
*/
|
|
7904
8052
|
async unstakeObligation(obligationId, obligationKeyId, sign = true, walletAddress) {
|
|
7905
8053
|
const txBlock = this.builder.createTxBlock();
|
|
7906
|
-
const sender = walletAddress
|
|
8054
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7907
8055
|
txBlock.setSender(sender);
|
|
7908
8056
|
await txBlock.unstakeObligationQuick(obligationId, obligationKeyId);
|
|
7909
8057
|
if (sign) {
|
|
@@ -7926,7 +8074,7 @@ var ScallopClient = class {
|
|
|
7926
8074
|
*/
|
|
7927
8075
|
async claimBorrowIncentive(coinName, obligationId, obligationKeyId, sign = true, walletAddress) {
|
|
7928
8076
|
const txBlock = this.builder.createTxBlock();
|
|
7929
|
-
const sender = walletAddress
|
|
8077
|
+
const sender = walletAddress ?? this.walletAddress;
|
|
7930
8078
|
txBlock.setSender(sender);
|
|
7931
8079
|
const rewardCoins = [];
|
|
7932
8080
|
for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
|
|
@@ -8072,7 +8220,7 @@ var ScallopClient = class {
|
|
|
8072
8220
|
throw new Error("Only be used on the test network.");
|
|
8073
8221
|
}
|
|
8074
8222
|
const txBlock = this.builder.createTxBlock();
|
|
8075
|
-
const recipient = receiveAddress
|
|
8223
|
+
const recipient = receiveAddress ?? this.walletAddress;
|
|
8076
8224
|
const packageId = this.address.get("core.packages.testCoin.id");
|
|
8077
8225
|
const treasuryId = this.address.get(`core.coins.${assetCoinName}.treasury`);
|
|
8078
8226
|
const target = `${packageId}::${assetCoinName}::mint`;
|
|
@@ -8092,7 +8240,7 @@ var ScallopClient = class {
|
|
|
8092
8240
|
var Scallop = class {
|
|
8093
8241
|
constructor(params, cacheOptions, tokenBucket, queryClient) {
|
|
8094
8242
|
this.params = params;
|
|
8095
|
-
this.suiKit =
|
|
8243
|
+
this.suiKit = newSuiKit(params);
|
|
8096
8244
|
this.cache = new ScallopCache(
|
|
8097
8245
|
this.suiKit,
|
|
8098
8246
|
params.walletAddress,
|
|
@@ -8102,7 +8250,7 @@ var Scallop = class {
|
|
|
8102
8250
|
);
|
|
8103
8251
|
this.address = new ScallopAddress(
|
|
8104
8252
|
{
|
|
8105
|
-
id: params?.addressesId
|
|
8253
|
+
id: params?.addressesId ?? ADDRESSES_ID,
|
|
8106
8254
|
network: params?.networkType,
|
|
8107
8255
|
forceInterface: params?.forceAddressesInterface
|
|
8108
8256
|
},
|
|
@@ -8206,6 +8354,10 @@ export {
|
|
|
8206
8354
|
ADDRESSES_ID,
|
|
8207
8355
|
API_BASE_URL,
|
|
8208
8356
|
BORROW_FEE_PROTOCOL_ID,
|
|
8357
|
+
COIN_GECKGO_IDS,
|
|
8358
|
+
DEFAULT_CACHE_OPTIONS,
|
|
8359
|
+
DEFAULT_INTERVAL_IN_MS,
|
|
8360
|
+
DEFAULT_TOKENS_PER_INTERVAL,
|
|
8209
8361
|
FlashLoanFeeObjectMap,
|
|
8210
8362
|
IS_VE_SCA_TEST,
|
|
8211
8363
|
MAX_LOCK_DURATION,
|
|
@@ -8213,7 +8365,10 @@ export {
|
|
|
8213
8365
|
MIN_INITIAL_LOCK_AMOUNT,
|
|
8214
8366
|
MIN_TOP_UP_AMOUNT,
|
|
8215
8367
|
OLD_BORROW_INCENTIVE_PROTOCOL_ID,
|
|
8368
|
+
POOL_ADDRESSES,
|
|
8216
8369
|
PROTOCOL_OBJECT_ID,
|
|
8370
|
+
PYTH_ENDPOINTS,
|
|
8371
|
+
PYTH_FEED_IDS,
|
|
8217
8372
|
SCA_COIN_TYPE,
|
|
8218
8373
|
SDK_API_BASE_URL,
|
|
8219
8374
|
SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
@@ -8235,6 +8390,7 @@ export {
|
|
|
8235
8390
|
ScallopIndexer,
|
|
8236
8391
|
ScallopQuery,
|
|
8237
8392
|
ScallopUtils,
|
|
8393
|
+
TEST_ADDRESSES,
|
|
8238
8394
|
UNLOCK_ROUND_DURATION,
|
|
8239
8395
|
USE_TEST_ADDRESS,
|
|
8240
8396
|
assetCoins,
|
|
@@ -8244,6 +8400,7 @@ export {
|
|
|
8244
8400
|
marketCoins,
|
|
8245
8401
|
queryKeys,
|
|
8246
8402
|
sCoinIds,
|
|
8403
|
+
sCoinTypeToName,
|
|
8247
8404
|
sCoins,
|
|
8248
8405
|
spoolRewardCoins,
|
|
8249
8406
|
stakeMarketCoins,
|