@scallop-io/sui-scallop-sdk 1.3.4-alpha.3 → 1.3.4-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/builders/borrowIncentiveBuilder.d.ts +12 -0
- package/dist/builders/coreBuilder.d.ts +12 -0
- package/dist/builders/index.d.ts +12 -0
- package/dist/builders/loyaltyProgramBuilder.d.ts +12 -0
- package/dist/builders/oracle.d.ts +14 -0
- package/dist/builders/referralBuilder.d.ts +12 -0
- package/dist/builders/sCoinBuilder.d.ts +4 -0
- package/dist/builders/spoolBuilder.d.ts +12 -0
- package/dist/builders/vescaBuilder.d.ts +25 -0
- package/dist/constants/cache.d.ts +14 -0
- package/dist/constants/coinGecko.d.ts +2 -0
- package/dist/constants/common.d.ts +20 -0
- package/dist/constants/enum.d.ts +14 -0
- package/dist/constants/flashloan.d.ts +2 -0
- package/dist/constants/index.d.ts +12 -0
- package/dist/constants/poolAddress.d.ts +5 -0
- package/dist/constants/pyth.d.ts +5 -0
- package/dist/constants/queryKeys.d.ts +56 -0
- package/dist/constants/rpc.d.ts +1 -0
- package/dist/constants/testAddress.d.ts +2 -0
- package/dist/constants/tokenBucket.d.ts +2 -0
- package/dist/constants/vesca.d.ts +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1462 -1464
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1461 -1464
- package/dist/index.mjs.map +1 -1
- package/dist/models/index.d.ts +8 -0
- package/dist/models/scallop.d.ts +74 -0
- package/dist/models/scallopAddress.d.ts +150 -0
- package/dist/models/scallopBuilder.d.ts +89 -0
- package/dist/models/scallopCache.d.ts +74 -0
- package/dist/models/scallopClient.d.ts +321 -0
- package/dist/models/scallopIndexer.d.ts +89 -0
- package/dist/models/scallopQuery.d.ts +489 -0
- package/dist/models/scallopUtils.d.ts +227 -0
- package/dist/models/suiKit.d.ts +2 -0
- package/dist/queries/borrowIncentiveQuery.d.ts +61 -0
- package/dist/queries/coreQuery.d.ts +167 -0
- package/dist/queries/index.d.ts +11 -0
- package/dist/queries/isolatedAssetQuery.d.ts +14 -0
- package/dist/queries/loyaltyProgramQuery.d.ts +10 -0
- package/dist/queries/portfolioQuery.d.ts +73 -0
- package/dist/queries/priceQuery.d.ts +16 -0
- package/dist/queries/referralQuery.d.ts +7 -0
- package/dist/queries/sCoinQuery.d.ts +41 -0
- package/dist/queries/spoolQuery.d.ts +70 -0
- package/dist/queries/supplyLimitQuery.d.ts +9 -0
- package/dist/queries/vescaQuery.d.ts +36 -0
- package/dist/test.d.ts +0 -0
- package/dist/types/address.d.ts +107 -0
- package/dist/types/builder/borrowIncentive.d.ts +35 -0
- package/dist/types/builder/core.d.ts +56 -0
- package/dist/types/builder/index.d.ts +25 -0
- package/dist/types/builder/loyaltyProgram.d.ts +23 -0
- package/dist/types/builder/referral.d.ts +30 -0
- package/dist/types/builder/sCoin.d.ts +37 -0
- package/dist/types/builder/spool.d.ts +29 -0
- package/dist/types/builder/vesca.d.ts +51 -0
- package/dist/types/constant/common.d.ts +24 -0
- package/dist/types/constant/enum.d.ts +48 -0
- package/dist/types/constant/index.d.ts +2 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/model.d.ts +54 -0
- package/dist/types/query/borrowIncentive.d.ts +124 -0
- package/dist/types/query/core.d.ts +361 -0
- package/dist/types/query/index.d.ts +7 -0
- package/dist/types/query/loyaltyProgram.d.ts +5 -0
- package/dist/types/query/portfolio.d.ts +115 -0
- package/dist/types/query/sCoin.d.ts +1 -0
- package/dist/types/query/spool.d.ts +122 -0
- package/dist/types/query/vesca.d.ts +26 -0
- package/dist/types/utils.d.ts +21 -0
- package/dist/utils/builder.d.ts +15 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/indexer.d.ts +17 -0
- package/dist/utils/query.d.ts +62 -0
- package/dist/utils/tokenBucket.d.ts +11 -0
- package/dist/utils/util.d.ts +26 -0
- package/package.json +2 -2
- package/src/builders/borrowIncentiveBuilder.ts +8 -8
- package/src/builders/coreBuilder.ts +5 -5
- package/src/builders/index.ts +2 -2
- package/src/builders/oracle.ts +4 -4
- package/src/builders/referralBuilder.ts +1 -1
- package/src/builders/spoolBuilder.ts +6 -6
- package/src/builders/vescaBuilder.ts +4 -4
- package/src/constants/coinGecko.ts +1 -1
- package/src/constants/enum.ts +1 -1
- package/src/constants/index.ts +1 -0
- package/src/models/scallop.ts +5 -5
- package/src/models/scallopAddress.ts +9 -6
- package/src/models/scallopBuilder.ts +4 -5
- package/src/models/scallopCache.ts +4 -4
- package/src/models/scallopClient.ts +4 -4
- package/src/models/scallopIndexer.ts +3 -4
- package/src/models/scallopQuery.ts +13 -6
- package/src/models/scallopUtils.ts +11 -8
- package/src/models/suiKit.ts +1 -1
- package/src/queries/borrowIncentiveQuery.ts +5 -5
- package/src/queries/coreQuery.ts +5 -5
- package/src/queries/index.ts +8 -5
- package/src/queries/portfolioQuery.ts +4 -4
- package/src/queries/priceQuery.ts +2 -2
- package/src/queries/spoolQuery.ts +5 -5
- package/src/queries/vescaQuery.ts +2 -2
- package/src/test.ts +30 -0
- package/src/types/address.ts +1 -1
- package/src/types/builder/borrowIncentive.ts +3 -3
- package/src/types/builder/core.ts +3 -3
- package/src/types/builder/index.ts +5 -4
- package/src/types/builder/referral.ts +1 -1
- package/src/types/builder/sCoin.ts +1 -1
- package/src/types/builder/spool.ts +2 -2
- package/src/types/constant/common.ts +1 -1
- package/src/types/model.ts +2 -2
- package/src/types/query/borrowIncentive.ts +2 -2
- package/src/types/query/core.ts +1 -1
- package/src/types/query/portfolio.ts +2 -2
- package/src/types/query/spool.ts +1 -1
- package/src/utils/builder.ts +1 -1
- package/src/utils/index.ts +2 -2
- package/src/utils/query.ts +3 -3
- package/src/utils/tokenBucket.ts +1 -1
- package/src/utils/util.ts +4 -4
- /package/src/queries/{isolatedAsset.ts → isolatedAssetQuery.ts} +0 -0
- /package/src/queries/{supplyLimit.ts → supplyLimitQuery.ts} +0 -0
package/dist/index.js
CHANGED
|
@@ -48,6 +48,7 @@ __export(src_exports, {
|
|
|
48
48
|
PROTOCOL_OBJECT_ID: () => PROTOCOL_OBJECT_ID,
|
|
49
49
|
PYTH_ENDPOINTS: () => PYTH_ENDPOINTS,
|
|
50
50
|
PYTH_FEED_IDS: () => PYTH_FEED_IDS,
|
|
51
|
+
RPC_PROVIDERS: () => RPC_PROVIDERS,
|
|
51
52
|
SCA_COIN_TYPE: () => SCA_COIN_TYPE,
|
|
52
53
|
SDK_API_BASE_URL: () => SDK_API_BASE_URL,
|
|
53
54
|
SUPPORT_BORROW_INCENTIVE_POOLS: () => SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
@@ -972,6 +973,23 @@ var MAX_LOCK_DURATION = MAX_LOCK_ROUNDS * UNLOCK_ROUND_DURATION;
|
|
|
972
973
|
var MIN_INITIAL_LOCK_AMOUNT = 1e10;
|
|
973
974
|
var MIN_TOP_UP_AMOUNT = 1e9;
|
|
974
975
|
|
|
976
|
+
// src/constants/rpc.ts
|
|
977
|
+
var import_client = require("@mysten/sui/client");
|
|
978
|
+
var RPC_PROVIDERS = [
|
|
979
|
+
(0, import_client.getFullnodeUrl)("mainnet"),
|
|
980
|
+
"https://sui-mainnet.public.blastapi.io",
|
|
981
|
+
"https://sui-mainnet-ca-2.cosmostation.io",
|
|
982
|
+
"https://sui-mainnet-eu-4.cosmostation.io",
|
|
983
|
+
"https://sui-mainnet-endpoint.blockvision.org",
|
|
984
|
+
"https://sui-rpc.publicnode.com",
|
|
985
|
+
"https://sui-mainnet-rpc.allthatnode.com",
|
|
986
|
+
"https://mainnet.suiet.app",
|
|
987
|
+
"https://mainnet.sui.rpcpool.com",
|
|
988
|
+
"https://sui1mainnet-rpc.chainode.tech",
|
|
989
|
+
"https://fullnode.mainnet.apis.scallop.io",
|
|
990
|
+
"https://sui-mainnet-us-2.cosmostation.io"
|
|
991
|
+
];
|
|
992
|
+
|
|
975
993
|
// src/models/scallopAddress.ts
|
|
976
994
|
var import_sui_kit2 = require("@scallop-io/sui-kit");
|
|
977
995
|
|
|
@@ -1082,6 +1100,25 @@ var checkRenewExpiredVeSca = (scaAmount, lockPeriodInDays, prevUnlockAtInMillisT
|
|
|
1082
1100
|
}
|
|
1083
1101
|
};
|
|
1084
1102
|
|
|
1103
|
+
// src/utils/indexer.ts
|
|
1104
|
+
async function callMethodWithIndexerFallback(method, context, ...args) {
|
|
1105
|
+
const indexer = args[args.length - 1];
|
|
1106
|
+
if (indexer) {
|
|
1107
|
+
try {
|
|
1108
|
+
return await method.apply(context, args);
|
|
1109
|
+
} catch (e) {
|
|
1110
|
+
console.warn(`Indexer requests failed: ${e}. Retrying without indexer..`);
|
|
1111
|
+
return await method.apply(context, [...args.slice(0, -1), false]);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
return await method.apply(context, args);
|
|
1115
|
+
}
|
|
1116
|
+
function withIndexerFallback(method) {
|
|
1117
|
+
return (...args) => {
|
|
1118
|
+
return callMethodWithIndexerFallback(method, this, ...args);
|
|
1119
|
+
};
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1085
1122
|
// src/utils/query.ts
|
|
1086
1123
|
var import_bignumber = __toESM(require("bignumber.js"));
|
|
1087
1124
|
var import_utils = require("@mysten/sui/utils");
|
|
@@ -1466,6 +1503,66 @@ var estimatedFactor = (amount, scaleStep, type) => {
|
|
|
1466
1503
|
return adjustFactor;
|
|
1467
1504
|
};
|
|
1468
1505
|
|
|
1506
|
+
// src/utils/tokenBucket.ts
|
|
1507
|
+
var TokenBucket = class {
|
|
1508
|
+
constructor(tokensPerInterval, intervalInMs) {
|
|
1509
|
+
this.tokensPerInterval = tokensPerInterval;
|
|
1510
|
+
this.interval = intervalInMs;
|
|
1511
|
+
this.tokens = tokensPerInterval;
|
|
1512
|
+
this.lastRefill = Date.now();
|
|
1513
|
+
}
|
|
1514
|
+
refill() {
|
|
1515
|
+
const now = Date.now();
|
|
1516
|
+
const elapsed = now - this.lastRefill;
|
|
1517
|
+
if (elapsed > this.interval) {
|
|
1518
|
+
const tokensToAdd = Math.floor(elapsed / this.interval) * this.tokensPerInterval;
|
|
1519
|
+
this.tokens = Math.min(this.tokens + tokensToAdd, this.tokensPerInterval);
|
|
1520
|
+
this.lastRefill = now;
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
removeTokens(count) {
|
|
1524
|
+
this.refill();
|
|
1525
|
+
if (this.tokens >= count) {
|
|
1526
|
+
this.tokens -= count;
|
|
1527
|
+
return true;
|
|
1528
|
+
}
|
|
1529
|
+
return false;
|
|
1530
|
+
}
|
|
1531
|
+
};
|
|
1532
|
+
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 30, backoffFactor = 1.25) => {
|
|
1533
|
+
let retries = 0;
|
|
1534
|
+
const tryRequest = async () => {
|
|
1535
|
+
if (tokenBucket.removeTokens(1)) {
|
|
1536
|
+
try {
|
|
1537
|
+
const result = await fn();
|
|
1538
|
+
if (result && result.status === 429) {
|
|
1539
|
+
throw new Error("Unexpected status code: 429");
|
|
1540
|
+
}
|
|
1541
|
+
return result;
|
|
1542
|
+
} catch (error) {
|
|
1543
|
+
if (error.message === "Unexpected status code: 429" && retries < maxRetries) {
|
|
1544
|
+
retries++;
|
|
1545
|
+
const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
|
|
1546
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1547
|
+
return tryRequest();
|
|
1548
|
+
} else {
|
|
1549
|
+
console.error("An error occurred:", error.message);
|
|
1550
|
+
return null;
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
} else if (retries < maxRetries) {
|
|
1554
|
+
retries++;
|
|
1555
|
+
const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
|
|
1556
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1557
|
+
return tryRequest();
|
|
1558
|
+
} else {
|
|
1559
|
+
console.error("Maximum retries reached");
|
|
1560
|
+
return null;
|
|
1561
|
+
}
|
|
1562
|
+
};
|
|
1563
|
+
return tryRequest();
|
|
1564
|
+
};
|
|
1565
|
+
|
|
1469
1566
|
// src/utils/util.ts
|
|
1470
1567
|
var COIN_SET = Array.from(
|
|
1471
1568
|
/* @__PURE__ */ new Set([
|
|
@@ -1538,85 +1635,6 @@ var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
|
|
|
1538
1635
|
return Math.floor(closestTwelveAM.getTime() / 1e3);
|
|
1539
1636
|
};
|
|
1540
1637
|
|
|
1541
|
-
// src/utils/tokenBucket.ts
|
|
1542
|
-
var TokenBucket = class {
|
|
1543
|
-
constructor(tokensPerInterval, intervalInMs) {
|
|
1544
|
-
this.tokensPerInterval = tokensPerInterval;
|
|
1545
|
-
this.interval = intervalInMs;
|
|
1546
|
-
this.tokens = tokensPerInterval;
|
|
1547
|
-
this.lastRefill = Date.now();
|
|
1548
|
-
}
|
|
1549
|
-
refill() {
|
|
1550
|
-
const now = Date.now();
|
|
1551
|
-
const elapsed = now - this.lastRefill;
|
|
1552
|
-
if (elapsed > this.interval) {
|
|
1553
|
-
const tokensToAdd = Math.floor(elapsed / this.interval) * this.tokensPerInterval;
|
|
1554
|
-
this.tokens = Math.min(this.tokens + tokensToAdd, this.tokensPerInterval);
|
|
1555
|
-
this.lastRefill = now;
|
|
1556
|
-
}
|
|
1557
|
-
}
|
|
1558
|
-
removeTokens(count) {
|
|
1559
|
-
this.refill();
|
|
1560
|
-
if (this.tokens >= count) {
|
|
1561
|
-
this.tokens -= count;
|
|
1562
|
-
return true;
|
|
1563
|
-
}
|
|
1564
|
-
return false;
|
|
1565
|
-
}
|
|
1566
|
-
};
|
|
1567
|
-
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 30, backoffFactor = 1.25) => {
|
|
1568
|
-
let retries = 0;
|
|
1569
|
-
const tryRequest = async () => {
|
|
1570
|
-
if (tokenBucket.removeTokens(1)) {
|
|
1571
|
-
try {
|
|
1572
|
-
const result = await fn();
|
|
1573
|
-
if (result && result.status === 429) {
|
|
1574
|
-
throw new Error("Unexpected status code: 429");
|
|
1575
|
-
}
|
|
1576
|
-
return result;
|
|
1577
|
-
} catch (error) {
|
|
1578
|
-
if (error.message === "Unexpected status code: 429" && retries < maxRetries) {
|
|
1579
|
-
retries++;
|
|
1580
|
-
const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
|
|
1581
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1582
|
-
return tryRequest();
|
|
1583
|
-
} else {
|
|
1584
|
-
console.error("An error occurred:", error.message);
|
|
1585
|
-
return null;
|
|
1586
|
-
}
|
|
1587
|
-
}
|
|
1588
|
-
} else if (retries < maxRetries) {
|
|
1589
|
-
retries++;
|
|
1590
|
-
const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
|
|
1591
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1592
|
-
return tryRequest();
|
|
1593
|
-
} else {
|
|
1594
|
-
console.error("Maximum retries reached");
|
|
1595
|
-
return null;
|
|
1596
|
-
}
|
|
1597
|
-
};
|
|
1598
|
-
return tryRequest();
|
|
1599
|
-
};
|
|
1600
|
-
|
|
1601
|
-
// src/utils/indexer.ts
|
|
1602
|
-
async function callMethodWithIndexerFallback(method, context, ...args) {
|
|
1603
|
-
const indexer = args[args.length - 1];
|
|
1604
|
-
if (indexer) {
|
|
1605
|
-
try {
|
|
1606
|
-
return await method.apply(context, args);
|
|
1607
|
-
} catch (e) {
|
|
1608
|
-
console.warn(`Indexer requests failed: ${e}. Retrying without indexer..`);
|
|
1609
|
-
return await method.apply(context, [...args.slice(0, -1), false]);
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
return await method.apply(context, args);
|
|
1613
|
-
}
|
|
1614
|
-
function withIndexerFallback(method) {
|
|
1615
|
-
return (...args) => {
|
|
1616
|
-
return callMethodWithIndexerFallback(method, this, ...args);
|
|
1617
|
-
};
|
|
1618
|
-
}
|
|
1619
|
-
|
|
1620
1638
|
// src/models/scallopCache.ts
|
|
1621
1639
|
var ScallopCache = class {
|
|
1622
1640
|
constructor(suiKit, walletAddress, cacheOptions, tokenBucket, queryClient) {
|
|
@@ -2457,77 +2475,259 @@ var import_utils25 = require("@mysten/sui/utils");
|
|
|
2457
2475
|
var import_utils10 = require("@mysten/sui/utils");
|
|
2458
2476
|
var import_pyth_sui_js = require("@pythnetwork/pyth-sui-js");
|
|
2459
2477
|
|
|
2460
|
-
// src/queries/
|
|
2478
|
+
// src/queries/borrowIncentiveQuery.ts
|
|
2461
2479
|
var import_utils3 = require("@mysten/sui/utils");
|
|
2462
2480
|
var import_bignumber2 = __toESM(require("bignumber.js"));
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
id: import_zod.z.object({
|
|
2472
|
-
id: import_zod.z.string()
|
|
2473
|
-
}),
|
|
2474
|
-
name: import_zod.z.object({
|
|
2475
|
-
type: import_zod.z.string()
|
|
2476
|
-
}),
|
|
2477
|
-
value: import_zod.z.string()
|
|
2478
|
-
})
|
|
2479
|
-
});
|
|
2480
|
-
var SUPPLY_LIMIT_KEY = "0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::SupplyLimitKey";
|
|
2481
|
-
var getSupplyLimit = async (utils, poolName) => {
|
|
2482
|
-
const poolCoinType = utils.parseCoinType(poolName).slice(2);
|
|
2483
|
-
const marketObject = utils.address.get("core.market");
|
|
2484
|
-
if (!marketObject)
|
|
2485
|
-
return null;
|
|
2486
|
-
const object = await utils.cache.queryGetDynamicFieldObject({
|
|
2487
|
-
parentId: marketObject,
|
|
2488
|
-
name: {
|
|
2489
|
-
type: SUPPLY_LIMIT_KEY,
|
|
2490
|
-
value: poolCoinType
|
|
2491
|
-
}
|
|
2481
|
+
var queryBorrowIncentivePools = async (address) => {
|
|
2482
|
+
const queryPkgId = address.get("borrowIncentive.query");
|
|
2483
|
+
const incentivePoolsId = address.get("borrowIncentive.incentivePools");
|
|
2484
|
+
const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
|
|
2485
|
+
const args = [incentivePoolsId];
|
|
2486
|
+
const queryResult = await address.cache.queryInspectTxn({
|
|
2487
|
+
queryTarget,
|
|
2488
|
+
args
|
|
2492
2489
|
});
|
|
2493
|
-
const
|
|
2494
|
-
|
|
2495
|
-
return null;
|
|
2496
|
-
return parsedData.data.fields.value;
|
|
2490
|
+
const borrowIncentivePoolsQueryData = queryResult?.events[0].parsedJson;
|
|
2491
|
+
return borrowIncentivePoolsQueryData;
|
|
2497
2492
|
};
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2493
|
+
var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
|
|
2494
|
+
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
2495
|
+
], indexer = false, coinPrices) => {
|
|
2496
|
+
const borrowIncentivePools = {};
|
|
2501
2497
|
coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
|
|
2502
|
-
const pools = {};
|
|
2503
|
-
const collaterals = {};
|
|
2504
2498
|
if (indexer) {
|
|
2505
|
-
const
|
|
2506
|
-
const
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
const updateCollaterals = (item) => {
|
|
2512
|
-
item.coinPrice = coinPrices[item.coinName] ?? item.coinPrice;
|
|
2513
|
-
item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
|
|
2514
|
-
collaterals[item.coinName] = item;
|
|
2515
|
-
};
|
|
2516
|
-
Object.values(marketIndexer.pools).forEach(updatePools);
|
|
2517
|
-
Object.values(marketIndexer.collaterals).forEach(updateCollaterals);
|
|
2518
|
-
return {
|
|
2519
|
-
pools,
|
|
2520
|
-
collaterals
|
|
2499
|
+
const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
|
|
2500
|
+
const updateBorrowIncentivePool = (pool) => {
|
|
2501
|
+
if (!borrowIncentiveCoinNames.includes(pool.coinName))
|
|
2502
|
+
return;
|
|
2503
|
+
pool.coinPrice = coinPrices[pool.coinName] ?? pool.coinPrice;
|
|
2504
|
+
borrowIncentivePools[pool.coinName] = pool;
|
|
2521
2505
|
};
|
|
2506
|
+
Object.values(borrowIncentivePoolsIndexer).forEach(
|
|
2507
|
+
updateBorrowIncentivePool
|
|
2508
|
+
);
|
|
2509
|
+
return borrowIncentivePools;
|
|
2522
2510
|
}
|
|
2523
|
-
const
|
|
2524
|
-
|
|
2511
|
+
const borrowIncentivePoolsQueryData = await queryBorrowIncentivePools(
|
|
2512
|
+
query.address
|
|
2513
|
+
);
|
|
2514
|
+
for (const pool of borrowIncentivePoolsQueryData?.incentive_pools ?? []) {
|
|
2515
|
+
const borrowIncentivePoolPoints = {};
|
|
2516
|
+
const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(pool);
|
|
2517
|
+
const poolCoinType = (0, import_utils3.normalizeStructTag)(pool.pool_type.name);
|
|
2518
|
+
const poolCoinName = query.utils.parseCoinNameFromType(
|
|
2519
|
+
poolCoinType
|
|
2520
|
+
);
|
|
2521
|
+
const poolCoinPrice = coinPrices?.[poolCoinName] ?? 0;
|
|
2522
|
+
const poolCoinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
2523
|
+
if (!borrowIncentiveCoinNames.includes(poolCoinName)) {
|
|
2524
|
+
continue;
|
|
2525
|
+
}
|
|
2526
|
+
for (const [coinName, poolPoint] of Object.entries(
|
|
2527
|
+
parsedBorrowIncentivePoolData.poolPoints
|
|
2528
|
+
)) {
|
|
2529
|
+
const rewardCoinType = (0, import_utils3.normalizeStructTag)(poolPoint.pointType);
|
|
2530
|
+
const rewardCoinName = query.utils.parseCoinNameFromType(
|
|
2531
|
+
rewardCoinType
|
|
2532
|
+
);
|
|
2533
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
2534
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2535
|
+
const symbol = query.utils.parseSymbol(rewardCoinName);
|
|
2536
|
+
const coinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2537
|
+
const calculatedPoolPoint = calculateBorrowIncentivePoolPointData(
|
|
2538
|
+
// parsedBorrowIncentivePoolData,
|
|
2539
|
+
poolPoint,
|
|
2540
|
+
rewardCoinPrice,
|
|
2541
|
+
rewardCoinDecimal,
|
|
2542
|
+
poolCoinPrice,
|
|
2543
|
+
poolCoinDecimal
|
|
2544
|
+
);
|
|
2545
|
+
borrowIncentivePoolPoints[coinName] = {
|
|
2546
|
+
symbol,
|
|
2547
|
+
coinName: rewardCoinName,
|
|
2548
|
+
coinType: rewardCoinType,
|
|
2549
|
+
coinDecimal,
|
|
2550
|
+
coinPrice: rewardCoinPrice,
|
|
2551
|
+
points: poolPoint.points,
|
|
2552
|
+
distributedPoint: poolPoint.distributedPoint,
|
|
2553
|
+
weightedAmount: poolPoint.weightedAmount,
|
|
2554
|
+
...calculatedPoolPoint
|
|
2555
|
+
};
|
|
2556
|
+
}
|
|
2557
|
+
const stakedAmount = (0, import_bignumber2.default)(parsedBorrowIncentivePoolData.staked);
|
|
2558
|
+
const stakedCoin = stakedAmount.shiftedBy(-1 * poolCoinDecimal);
|
|
2559
|
+
const stakedValue = stakedCoin.multipliedBy(poolCoinPrice);
|
|
2560
|
+
borrowIncentivePools[poolCoinName] = {
|
|
2561
|
+
coinName: poolCoinName,
|
|
2562
|
+
symbol: query.utils.parseSymbol(poolCoinName),
|
|
2563
|
+
coinType: poolCoinType,
|
|
2564
|
+
coinDecimal: poolCoinDecimal,
|
|
2565
|
+
coinPrice: poolCoinPrice,
|
|
2566
|
+
stakedAmount: stakedAmount.toNumber(),
|
|
2567
|
+
stakedCoin: stakedCoin.toNumber(),
|
|
2568
|
+
stakedValue: stakedValue.toNumber(),
|
|
2569
|
+
points: borrowIncentivePoolPoints
|
|
2570
|
+
};
|
|
2571
|
+
}
|
|
2572
|
+
return borrowIncentivePools;
|
|
2573
|
+
};
|
|
2574
|
+
var queryBorrowIncentiveAccounts = async ({
|
|
2575
|
+
utils
|
|
2576
|
+
}, obligationId, borrowIncentiveCoinNames = [
|
|
2577
|
+
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
2578
|
+
]) => {
|
|
2579
|
+
const queryPkgId = utils.address.get("borrowIncentive.query");
|
|
2580
|
+
const incentiveAccountsId = utils.address.get(
|
|
2581
|
+
"borrowIncentive.incentiveAccounts"
|
|
2582
|
+
);
|
|
2583
|
+
const queryTarget = `${queryPkgId}::incentive_account_query::incentive_account_data`;
|
|
2584
|
+
const args = [incentiveAccountsId, obligationId];
|
|
2585
|
+
const queryResult = await utils.cache.queryInspectTxn({ queryTarget, args });
|
|
2586
|
+
const borrowIncentiveAccountsQueryData = queryResult?.events[0]?.parsedJson;
|
|
2587
|
+
const borrowIncentiveAccounts = Object.values(
|
|
2588
|
+
borrowIncentiveAccountsQueryData?.pool_records ?? []
|
|
2589
|
+
).reduce((accounts, accountData) => {
|
|
2590
|
+
const parsedBorrowIncentiveAccount = parseOriginBorrowIncentiveAccountData(accountData);
|
|
2591
|
+
const poolType = parsedBorrowIncentiveAccount.poolType;
|
|
2592
|
+
const coinName = utils.parseCoinNameFromType(poolType);
|
|
2593
|
+
if (borrowIncentiveCoinNames && borrowIncentiveCoinNames.includes(coinName)) {
|
|
2594
|
+
accounts[coinName] = parsedBorrowIncentiveAccount;
|
|
2595
|
+
}
|
|
2596
|
+
return accounts;
|
|
2597
|
+
}, {});
|
|
2598
|
+
return borrowIncentiveAccounts;
|
|
2599
|
+
};
|
|
2600
|
+
var getBindedObligationId = async ({
|
|
2601
|
+
address
|
|
2602
|
+
}, veScaKeyId) => {
|
|
2603
|
+
const borrowIncentiveObjectId = address.get("borrowIncentive.object");
|
|
2604
|
+
const incentivePoolsId = address.get("borrowIncentive.incentivePools");
|
|
2605
|
+
const veScaObjId = address.get("vesca.object");
|
|
2606
|
+
const incentivePoolsResponse = await address.cache.queryGetObject(
|
|
2607
|
+
incentivePoolsId,
|
|
2608
|
+
{
|
|
2609
|
+
showContent: true
|
|
2610
|
+
}
|
|
2611
|
+
);
|
|
2612
|
+
if (incentivePoolsResponse?.data?.content?.dataType !== "moveObject")
|
|
2613
|
+
return null;
|
|
2614
|
+
const incentivePoolFields = incentivePoolsResponse.data.content.fields;
|
|
2615
|
+
const veScaBindTableId = incentivePoolFields.ve_sca_bind.fields.id.id;
|
|
2616
|
+
const keyType = `${borrowIncentiveObjectId}::typed_id::TypedID<${veScaObjId}::ve_sca::VeScaKey>`;
|
|
2617
|
+
const veScaBindTableResponse = await address.cache.queryGetDynamicFieldObject(
|
|
2618
|
+
{
|
|
2619
|
+
parentId: veScaBindTableId,
|
|
2620
|
+
name: {
|
|
2621
|
+
type: keyType,
|
|
2622
|
+
value: veScaKeyId
|
|
2623
|
+
}
|
|
2624
|
+
}
|
|
2625
|
+
);
|
|
2626
|
+
if (veScaBindTableResponse?.data?.content?.dataType !== "moveObject")
|
|
2627
|
+
return null;
|
|
2628
|
+
const veScaBindTableFields = veScaBindTableResponse.data.content.fields;
|
|
2629
|
+
const obligationId = veScaBindTableFields.value.fields.id;
|
|
2630
|
+
return obligationId;
|
|
2631
|
+
};
|
|
2632
|
+
var getBindedVeScaKey = async ({
|
|
2633
|
+
address
|
|
2634
|
+
}, obligationId) => {
|
|
2635
|
+
const borrowIncentiveObjectId = address.get("borrowIncentive.object");
|
|
2636
|
+
const incentiveAccountsId = address.get("borrowIncentive.incentiveAccounts");
|
|
2637
|
+
const corePkg = address.get("core.object");
|
|
2638
|
+
const incentiveAccountsObject = await address.cache.queryGetObject(
|
|
2639
|
+
incentiveAccountsId,
|
|
2640
|
+
{
|
|
2641
|
+
showContent: true
|
|
2642
|
+
}
|
|
2643
|
+
);
|
|
2644
|
+
if (incentiveAccountsObject?.data?.content?.dataType !== "moveObject")
|
|
2645
|
+
return null;
|
|
2646
|
+
const incentiveAccountsTableId = incentiveAccountsObject.data.content.fields.accounts.fields.id.id;
|
|
2647
|
+
const bindedIncentiveAcc = await address.cache.queryGetDynamicFieldObject({
|
|
2648
|
+
parentId: incentiveAccountsTableId,
|
|
2649
|
+
name: {
|
|
2650
|
+
type: `${borrowIncentiveObjectId}::typed_id::TypedID<${corePkg}::obligation::Obligation>`,
|
|
2651
|
+
value: obligationId
|
|
2652
|
+
}
|
|
2653
|
+
});
|
|
2654
|
+
if (bindedIncentiveAcc?.data?.content?.dataType !== "moveObject")
|
|
2655
|
+
return null;
|
|
2656
|
+
const bindedIncentiveAccFields = bindedIncentiveAcc.data.content.fields;
|
|
2657
|
+
return bindedIncentiveAccFields.value.fields.binded_ve_sca_key?.fields.id ?? null;
|
|
2658
|
+
};
|
|
2659
|
+
|
|
2660
|
+
// src/queries/coreQuery.ts
|
|
2661
|
+
var import_utils5 = require("@mysten/sui/utils");
|
|
2662
|
+
var import_bignumber3 = __toESM(require("bignumber.js"));
|
|
2663
|
+
|
|
2664
|
+
// src/queries/supplyLimitQuery.ts
|
|
2665
|
+
var import_zod = require("zod");
|
|
2666
|
+
var supplyLimitZod = import_zod.z.object({
|
|
2667
|
+
dataType: import_zod.z.string(),
|
|
2668
|
+
type: import_zod.z.string(),
|
|
2669
|
+
hasPublicTransfer: import_zod.z.boolean(),
|
|
2670
|
+
fields: import_zod.z.object({
|
|
2671
|
+
id: import_zod.z.object({
|
|
2672
|
+
id: import_zod.z.string()
|
|
2673
|
+
}),
|
|
2674
|
+
name: import_zod.z.object({
|
|
2675
|
+
type: import_zod.z.string()
|
|
2676
|
+
}),
|
|
2677
|
+
value: import_zod.z.string()
|
|
2678
|
+
})
|
|
2679
|
+
});
|
|
2680
|
+
var SUPPLY_LIMIT_KEY = "0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::SupplyLimitKey";
|
|
2681
|
+
var getSupplyLimit = async (utils, poolName) => {
|
|
2682
|
+
const poolCoinType = utils.parseCoinType(poolName).slice(2);
|
|
2683
|
+
const marketObject = utils.address.get("core.market");
|
|
2684
|
+
if (!marketObject)
|
|
2685
|
+
return null;
|
|
2686
|
+
const object = await utils.cache.queryGetDynamicFieldObject({
|
|
2687
|
+
parentId: marketObject,
|
|
2688
|
+
name: {
|
|
2689
|
+
type: SUPPLY_LIMIT_KEY,
|
|
2690
|
+
value: poolCoinType
|
|
2691
|
+
}
|
|
2692
|
+
});
|
|
2693
|
+
const parsedData = supplyLimitZod.safeParse(object?.data?.content);
|
|
2694
|
+
if (!parsedData.success)
|
|
2695
|
+
return null;
|
|
2696
|
+
return parsedData.data.fields.value;
|
|
2697
|
+
};
|
|
2698
|
+
|
|
2699
|
+
// src/queries/coreQuery.ts
|
|
2700
|
+
var queryMarket = async (query, indexer = false, coinPrices) => {
|
|
2701
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
|
|
2702
|
+
const pools = {};
|
|
2703
|
+
const collaterals = {};
|
|
2704
|
+
if (indexer) {
|
|
2705
|
+
const marketIndexer = await query.indexer.getMarket();
|
|
2706
|
+
const updatePools = (item) => {
|
|
2707
|
+
item.coinPrice = coinPrices[item.coinName] ?? item.coinPrice;
|
|
2708
|
+
item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
|
|
2709
|
+
pools[item.coinName] = item;
|
|
2710
|
+
};
|
|
2711
|
+
const updateCollaterals = (item) => {
|
|
2712
|
+
item.coinPrice = coinPrices[item.coinName] ?? item.coinPrice;
|
|
2713
|
+
item.coinWrappedType = query.utils.getCoinWrappedType(item.coinName);
|
|
2714
|
+
collaterals[item.coinName] = item;
|
|
2715
|
+
};
|
|
2716
|
+
Object.values(marketIndexer.pools).forEach(updatePools);
|
|
2717
|
+
Object.values(marketIndexer.collaterals).forEach(updateCollaterals);
|
|
2718
|
+
return {
|
|
2719
|
+
pools,
|
|
2720
|
+
collaterals
|
|
2721
|
+
};
|
|
2722
|
+
}
|
|
2723
|
+
const packageId = query.address.get("core.packages.query.id");
|
|
2724
|
+
const marketId = query.address.get("core.market");
|
|
2525
2725
|
const queryTarget = `${packageId}::market_query::market_data`;
|
|
2526
2726
|
const args = [marketId];
|
|
2527
2727
|
const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
|
|
2528
2728
|
const marketData = queryResult?.events[0]?.parsedJson;
|
|
2529
2729
|
for (const pool of marketData?.pools ?? []) {
|
|
2530
|
-
const coinType = (0,
|
|
2730
|
+
const coinType = (0, import_utils5.normalizeStructTag)(pool.type.name);
|
|
2531
2731
|
const poolCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
2532
2732
|
const coinPrice = coinPrices[poolCoinName] ?? 0;
|
|
2533
2733
|
if (!SUPPORT_POOLS.includes(poolCoinName)) {
|
|
@@ -2559,7 +2759,7 @@ var queryMarket = async (query, indexer = false, coinPrices) => {
|
|
|
2559
2759
|
parsedMarketPoolData
|
|
2560
2760
|
);
|
|
2561
2761
|
const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
2562
|
-
const maxSupplyCoin = (0,
|
|
2762
|
+
const maxSupplyCoin = (0, import_bignumber3.default)(
|
|
2563
2763
|
await getSupplyLimit(query.utils, poolCoinName) ?? "0"
|
|
2564
2764
|
).shiftedBy(-coinDecimal).toNumber();
|
|
2565
2765
|
pools[poolCoinName] = {
|
|
@@ -2587,7 +2787,7 @@ var queryMarket = async (query, indexer = false, coinPrices) => {
|
|
|
2587
2787
|
};
|
|
2588
2788
|
}
|
|
2589
2789
|
for (const collateral of marketData?.collaterals ?? []) {
|
|
2590
|
-
const coinType = (0,
|
|
2790
|
+
const coinType = (0, import_utils5.normalizeStructTag)(collateral.type.name);
|
|
2591
2791
|
const collateralCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
2592
2792
|
const coinPrice = coinPrices[collateralCoinName] ?? 0;
|
|
2593
2793
|
if (!SUPPORT_COLLATERALS.includes(collateralCoinName)) {
|
|
@@ -2795,7 +2995,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2795
2995
|
parsedMarketPoolData
|
|
2796
2996
|
);
|
|
2797
2997
|
const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
2798
|
-
const maxSupplyCoin = (0,
|
|
2998
|
+
const maxSupplyCoin = (0, import_bignumber3.default)(
|
|
2799
2999
|
await getSupplyLimit(query.utils, poolCoinName) ?? "0"
|
|
2800
3000
|
).shiftedBy(-coinDecimal).toNumber();
|
|
2801
3001
|
marketPool = {
|
|
@@ -3039,7 +3239,7 @@ var getCoinAmount = async (query, assetCoinName, ownerAddress) => {
|
|
|
3039
3239
|
owner,
|
|
3040
3240
|
coinType
|
|
3041
3241
|
});
|
|
3042
|
-
return (0,
|
|
3242
|
+
return (0, import_bignumber3.default)(amount).toNumber();
|
|
3043
3243
|
};
|
|
3044
3244
|
var getMarketCoinAmounts = async (query, marketCoinNames, ownerAddress) => {
|
|
3045
3245
|
marketCoinNames = marketCoinNames || [...SUPPORT_POOLS].map(
|
|
@@ -3066,7 +3266,7 @@ var getMarketCoinAmount = async (query, marketCoinName, ownerAddress) => {
|
|
|
3066
3266
|
owner,
|
|
3067
3267
|
coinType: marketCoinType
|
|
3068
3268
|
});
|
|
3069
|
-
return (0,
|
|
3269
|
+
return (0, import_bignumber3.default)(amount).toNumber();
|
|
3070
3270
|
};
|
|
3071
3271
|
var getFlashLoanFees = async (query, assetNames) => {
|
|
3072
3272
|
const FEE_RATE = 1e4;
|
|
@@ -3127,1124 +3327,1182 @@ var getFlashLoanFees = async (query, assetNames) => {
|
|
|
3127
3327
|
);
|
|
3128
3328
|
};
|
|
3129
3329
|
|
|
3130
|
-
// src/queries/
|
|
3131
|
-
var
|
|
3132
|
-
var
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
)
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3330
|
+
// src/queries/isolatedAssetQuery.ts
|
|
3331
|
+
var import_zod2 = require("zod");
|
|
3332
|
+
var isolatedAssetZod = import_zod2.z.object({
|
|
3333
|
+
dataType: import_zod2.z.string(),
|
|
3334
|
+
type: import_zod2.z.string(),
|
|
3335
|
+
hasPublicTransfer: import_zod2.z.boolean(),
|
|
3336
|
+
fields: import_zod2.z.object({
|
|
3337
|
+
id: import_zod2.z.object({
|
|
3338
|
+
id: import_zod2.z.string()
|
|
3339
|
+
}),
|
|
3340
|
+
name: import_zod2.z.object({
|
|
3341
|
+
type: import_zod2.z.string()
|
|
3342
|
+
}),
|
|
3343
|
+
value: import_zod2.z.boolean()
|
|
3344
|
+
})
|
|
3345
|
+
});
|
|
3346
|
+
var ISOLATED_ASSET_KEY = "0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::IsolatedAssetKey";
|
|
3347
|
+
var getIsolatedAssets = async (address) => {
|
|
3348
|
+
try {
|
|
3349
|
+
const marketObject = address.get("core.market");
|
|
3350
|
+
const isolatedAssets = [];
|
|
3351
|
+
if (!marketObject)
|
|
3352
|
+
return isolatedAssets;
|
|
3353
|
+
let hasNextPage = false;
|
|
3354
|
+
let nextCursor = null;
|
|
3355
|
+
const isIsolatedDynamicField = (dynamicField) => {
|
|
3356
|
+
return dynamicField.name.type === ISOLATED_ASSET_KEY;
|
|
3157
3357
|
};
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3358
|
+
do {
|
|
3359
|
+
const response = await address.cache.queryGetDynamicFields({
|
|
3360
|
+
parentId: marketObject,
|
|
3361
|
+
cursor: nextCursor,
|
|
3362
|
+
limit: 10
|
|
3363
|
+
});
|
|
3364
|
+
if (!response)
|
|
3365
|
+
break;
|
|
3366
|
+
const isolatedAssetCoinTypes = response.data.filter(isIsolatedDynamicField).map(({ name }) => `0x${name.value.type.name}`);
|
|
3367
|
+
isolatedAssets.push(...isolatedAssetCoinTypes);
|
|
3368
|
+
if (response && response.hasNextPage && response.nextCursor) {
|
|
3369
|
+
hasNextPage = true;
|
|
3370
|
+
nextCursor = response.nextCursor;
|
|
3371
|
+
} else {
|
|
3372
|
+
hasNextPage = false;
|
|
3373
|
+
}
|
|
3374
|
+
} while (hasNextPage);
|
|
3375
|
+
return isolatedAssets;
|
|
3376
|
+
} catch (e) {
|
|
3377
|
+
console.error(e);
|
|
3378
|
+
return [];
|
|
3173
3379
|
}
|
|
3174
|
-
return spools;
|
|
3175
3380
|
};
|
|
3176
|
-
var
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
let spool = void 0;
|
|
3187
|
-
coinPrices = coinPrices || await query.utils.getCoinPrices([coinName]);
|
|
3188
|
-
if (indexer) {
|
|
3189
|
-
const spoolIndexer = await query.indexer.getSpool(marketCoinName);
|
|
3190
|
-
const coinName2 = query.utils.parseCoinName(marketCoinName);
|
|
3191
|
-
const rewardCoinName2 = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
3192
|
-
spoolIndexer.coinPrice = coinPrices?.[coinName2] || spoolIndexer.coinPrice;
|
|
3193
|
-
spoolIndexer.marketCoinPrice = (coinPrices?.[coinName2] ?? 0) * (marketPool ? marketPool.conversionRate : 0) || spoolIndexer.marketCoinPrice;
|
|
3194
|
-
spoolIndexer.rewardCoinPrice = coinPrices?.[rewardCoinName2] || spoolIndexer.rewardCoinPrice;
|
|
3195
|
-
return spoolIndexer;
|
|
3196
|
-
}
|
|
3197
|
-
const spoolObjectResponse = await query.cache.queryGetObjects(
|
|
3198
|
-
[poolId, rewardPoolId],
|
|
3199
|
-
{
|
|
3200
|
-
showContent: true
|
|
3381
|
+
var isIsolatedAsset = async (utils, coinName) => {
|
|
3382
|
+
try {
|
|
3383
|
+
const marketObject = utils.address.get("core.market");
|
|
3384
|
+
const cachedData = utils.address.cache.queryClient.getQueryData([
|
|
3385
|
+
"getDynamicFields",
|
|
3386
|
+
marketObject
|
|
3387
|
+
]);
|
|
3388
|
+
if (cachedData) {
|
|
3389
|
+
const coinType2 = utils.parseCoinType(coinName);
|
|
3390
|
+
return cachedData.includes(coinType2);
|
|
3201
3391
|
}
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
const rewardPoolObject = spoolObjectResponse[1];
|
|
3210
|
-
if (spoolObject.content && "fields" in spoolObject.content) {
|
|
3211
|
-
const spoolFields = spoolObject.content.fields;
|
|
3212
|
-
const parsedSpoolData = parseOriginSpoolData({
|
|
3213
|
-
stakeType: spoolFields.stake_type,
|
|
3214
|
-
maxDistributedPoint: spoolFields.max_distributed_point,
|
|
3215
|
-
distributedPoint: spoolFields.distributed_point,
|
|
3216
|
-
distributedPointPerPeriod: spoolFields.distributed_point_per_period,
|
|
3217
|
-
pointDistributionTime: spoolFields.point_distribution_time,
|
|
3218
|
-
maxStake: spoolFields.max_stakes,
|
|
3219
|
-
stakes: spoolFields.stakes,
|
|
3220
|
-
index: spoolFields.index,
|
|
3221
|
-
createdAt: spoolFields.created_at,
|
|
3222
|
-
lastUpdate: spoolFields.last_update
|
|
3392
|
+
const coinType = utils.parseCoinType(coinName).slice(2);
|
|
3393
|
+
const object = await utils.cache.queryGetDynamicFieldObject({
|
|
3394
|
+
parentId: marketObject,
|
|
3395
|
+
name: {
|
|
3396
|
+
type: ISOLATED_ASSET_KEY,
|
|
3397
|
+
value: coinType
|
|
3398
|
+
}
|
|
3223
3399
|
});
|
|
3224
|
-
const
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
if (rewardPoolObject.content && "fields" in rewardPoolObject.content) {
|
|
3232
|
-
const rewardPoolFields = rewardPoolObject.content.fields;
|
|
3233
|
-
const parsedSpoolRewardPoolData = parseOriginSpoolRewardPoolData({
|
|
3234
|
-
claimed_rewards: rewardPoolFields.claimed_rewards,
|
|
3235
|
-
exchange_rate_numerator: rewardPoolFields.exchange_rate_numerator,
|
|
3236
|
-
exchange_rate_denominator: rewardPoolFields.exchange_rate_denominator,
|
|
3237
|
-
rewards: rewardPoolFields.rewards,
|
|
3238
|
-
spool_id: rewardPoolFields.spool_id
|
|
3239
|
-
});
|
|
3240
|
-
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
3241
|
-
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
3242
|
-
const calculatedRewardPoolData = calculateSpoolRewardPoolData(
|
|
3243
|
-
parsedSpoolData,
|
|
3244
|
-
parsedSpoolRewardPoolData,
|
|
3245
|
-
calculatedSpoolData,
|
|
3246
|
-
rewardCoinPrice,
|
|
3247
|
-
rewardCoinDecimal
|
|
3248
|
-
);
|
|
3249
|
-
spool = {
|
|
3250
|
-
marketCoinName,
|
|
3251
|
-
symbol: query.utils.parseSymbol(marketCoinName),
|
|
3252
|
-
coinType: query.utils.parseCoinType(coinName),
|
|
3253
|
-
marketCoinType: query.utils.parseMarketCoinType(coinName),
|
|
3254
|
-
rewardCoinType: isMarketCoin(rewardCoinName) ? query.utils.parseMarketCoinType(rewardCoinName) : query.utils.parseCoinType(rewardCoinName),
|
|
3255
|
-
sCoinType: marketPool.sCoinType,
|
|
3256
|
-
coinDecimal: query.utils.getCoinDecimal(coinName),
|
|
3257
|
-
rewardCoinDecimal: query.utils.getCoinDecimal(rewardCoinName),
|
|
3258
|
-
coinPrice: coinPrices?.[coinName] ?? 0,
|
|
3259
|
-
marketCoinPrice,
|
|
3260
|
-
rewardCoinPrice,
|
|
3261
|
-
maxPoint: parsedSpoolData.maxPoint,
|
|
3262
|
-
distributedPoint: parsedSpoolData.distributedPoint,
|
|
3263
|
-
maxStake: parsedSpoolData.maxStake,
|
|
3264
|
-
...calculatedSpoolData,
|
|
3265
|
-
exchangeRateNumerator: parsedSpoolRewardPoolData.exchangeRateNumerator,
|
|
3266
|
-
exchangeRateDenominator: parsedSpoolRewardPoolData.exchangeRateDenominator,
|
|
3267
|
-
...calculatedRewardPoolData
|
|
3268
|
-
};
|
|
3269
|
-
}
|
|
3400
|
+
const parsedData = isolatedAssetZod.safeParse(object?.data?.content);
|
|
3401
|
+
if (!parsedData.success)
|
|
3402
|
+
return false;
|
|
3403
|
+
return parsedData.data.fields.value;
|
|
3404
|
+
} catch (e) {
|
|
3405
|
+
console.error(e);
|
|
3406
|
+
return false;
|
|
3270
3407
|
}
|
|
3271
|
-
return spool;
|
|
3272
3408
|
};
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3409
|
+
|
|
3410
|
+
// src/queries/loyaltyProgramQuery.ts
|
|
3411
|
+
var import_bignumber4 = __toESM(require("bignumber.js"));
|
|
3412
|
+
var import_zod3 = require("zod");
|
|
3413
|
+
var rewardPoolFieldsZod = import_zod3.z.object({
|
|
3414
|
+
balance: import_zod3.z.string(),
|
|
3415
|
+
enable_claim: import_zod3.z.boolean()
|
|
3416
|
+
}).transform((value) => ({
|
|
3417
|
+
totalPoolReward: (0, import_bignumber4.default)(value.balance).shiftedBy(-9).toNumber(),
|
|
3418
|
+
isClaimEnabled: value.enable_claim
|
|
3419
|
+
}));
|
|
3420
|
+
var userRewardFieldsZod = import_zod3.z.object({
|
|
3421
|
+
value: import_zod3.z.string()
|
|
3422
|
+
}).transform((value) => (0, import_bignumber4.default)(value.value).shiftedBy(-9).toNumber());
|
|
3423
|
+
var getLoyaltyProgramInformations = async (query, veScaKey) => {
|
|
3424
|
+
const rewardPool = query.address.get("loyaltyProgram.rewardPool");
|
|
3425
|
+
const rewardPoolObject = await query.cache.queryGetObject(rewardPool, {
|
|
3426
|
+
showContent: true
|
|
3427
|
+
});
|
|
3428
|
+
if (rewardPoolObject?.data?.content?.dataType !== "moveObject")
|
|
3429
|
+
return null;
|
|
3430
|
+
const rewardPoolFields = rewardPoolObject.data.content.fields;
|
|
3431
|
+
const { isClaimEnabled, totalPoolReward } = rewardPoolFieldsZod.parse(
|
|
3432
|
+
rewardPoolFields
|
|
3433
|
+
);
|
|
3434
|
+
const result = {
|
|
3435
|
+
pendingReward: 0,
|
|
3436
|
+
totalPoolReward,
|
|
3437
|
+
isClaimEnabled
|
|
3438
|
+
};
|
|
3439
|
+
veScaKey = veScaKey ?? (await query.getVeScas())[0]?.keyObject;
|
|
3440
|
+
if (!veScaKey)
|
|
3441
|
+
return result;
|
|
3442
|
+
const userRewardTableId = query.address.get(
|
|
3443
|
+
"loyaltyProgram.userRewardTableId"
|
|
3444
|
+
);
|
|
3445
|
+
const userRewardObject = await query.cache.queryGetDynamicFieldObject({
|
|
3446
|
+
parentId: userRewardTableId,
|
|
3447
|
+
name: {
|
|
3448
|
+
type: "0x2::object::ID",
|
|
3449
|
+
value: typeof veScaKey === "string" ? veScaKey : veScaKey.objectId
|
|
3301
3450
|
}
|
|
3302
|
-
}
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
{}
|
|
3451
|
+
});
|
|
3452
|
+
if (userRewardObject?.data?.content?.dataType !== "moveObject")
|
|
3453
|
+
return result;
|
|
3454
|
+
const userRewardFields = userRewardObject.data.content.fields;
|
|
3455
|
+
result.pendingReward = userRewardFieldsZod.parse(
|
|
3456
|
+
userRewardFields
|
|
3309
3457
|
);
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3458
|
+
return result;
|
|
3459
|
+
};
|
|
3460
|
+
|
|
3461
|
+
// src/queries/portfolioQuery.ts
|
|
3462
|
+
var import_bignumber5 = __toESM(require("bignumber.js"));
|
|
3463
|
+
var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress, indexer = false) => {
|
|
3464
|
+
const marketCoinNames = poolCoinNames.map(
|
|
3465
|
+
(poolCoinName) => query.utils.parseMarketCoinName(poolCoinName)
|
|
3318
3466
|
);
|
|
3319
|
-
const
|
|
3320
|
-
(
|
|
3321
|
-
reversedTypes[value] = key;
|
|
3322
|
-
return reversedTypes;
|
|
3323
|
-
},
|
|
3324
|
-
{}
|
|
3467
|
+
const stakeMarketCoinNames = marketCoinNames.filter(
|
|
3468
|
+
(marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
|
|
3325
3469
|
);
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
if (id && stakeObject?.content && "fields" in stakeObject.content) {
|
|
3330
|
-
const fields = stakeObject.content.fields;
|
|
3331
|
-
const stakePoolId = String(fields.spool_id);
|
|
3332
|
-
const stakeType = String(fields.stake_type.fields.name);
|
|
3333
|
-
const staked = Number(fields.stakes);
|
|
3334
|
-
const index = Number(fields.index);
|
|
3335
|
-
const points = Number(fields.points);
|
|
3336
|
-
const totalPoints = Number(fields.total_points);
|
|
3337
|
-
const stakeMarketCoinTypeMap = {
|
|
3338
|
-
sweth: stakeAccounts.sweth,
|
|
3339
|
-
ssui: stakeAccounts.ssui,
|
|
3340
|
-
swusdc: stakeAccounts.swusdc,
|
|
3341
|
-
swusdt: stakeAccounts.swusdt,
|
|
3342
|
-
scetus: stakeAccounts.scetus,
|
|
3343
|
-
safsui: stakeAccounts.safsui,
|
|
3344
|
-
shasui: stakeAccounts.shasui,
|
|
3345
|
-
svsui: stakeAccounts.svsui,
|
|
3346
|
-
susdc: stakeAccounts.susdc
|
|
3347
|
-
};
|
|
3348
|
-
const normalizedType = (0, import_utils5.normalizeStructTag)(type);
|
|
3349
|
-
const stakeAccountArray = stakeMarketCoinTypeMap[reversedStakeMarketCoinTypes[normalizedType]];
|
|
3350
|
-
if (stakeAccountArray) {
|
|
3351
|
-
stakeAccountArray.push({
|
|
3352
|
-
id,
|
|
3353
|
-
type: normalizedType,
|
|
3354
|
-
stakePoolId,
|
|
3355
|
-
stakeType: (0, import_utils5.normalizeStructTag)(stakeType),
|
|
3356
|
-
staked,
|
|
3357
|
-
index,
|
|
3358
|
-
points,
|
|
3359
|
-
totalPoints
|
|
3360
|
-
});
|
|
3361
|
-
}
|
|
3362
|
-
}
|
|
3363
|
-
}
|
|
3364
|
-
return stakeAccounts;
|
|
3365
|
-
};
|
|
3366
|
-
var getStakePool = async ({
|
|
3367
|
-
utils
|
|
3368
|
-
}, marketCoinName) => {
|
|
3369
|
-
const poolId = utils.address.get(`spool.pools.${marketCoinName}.id`);
|
|
3370
|
-
let stakePool = void 0;
|
|
3371
|
-
const stakePoolObjectResponse = await utils.cache.queryGetObject(poolId, {
|
|
3372
|
-
showContent: true,
|
|
3373
|
-
showType: true
|
|
3470
|
+
const coinPrices = await query.utils.getCoinPrices(poolCoinNames);
|
|
3471
|
+
const marketPools = await query.getMarketPools(poolCoinNames, indexer, {
|
|
3472
|
+
coinPrices
|
|
3374
3473
|
});
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
const
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
const
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
};
|
|
3405
|
-
}
|
|
3406
|
-
}
|
|
3407
|
-
return stakePool;
|
|
3408
|
-
};
|
|
3409
|
-
var getStakeRewardPool = async ({
|
|
3410
|
-
utils
|
|
3411
|
-
}, marketCoinName) => {
|
|
3412
|
-
const poolId = utils.address.get(
|
|
3413
|
-
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
3474
|
+
const spools = await query.getSpools(stakeMarketCoinNames, indexer, {
|
|
3475
|
+
marketPools,
|
|
3476
|
+
coinPrices
|
|
3477
|
+
});
|
|
3478
|
+
const [coinAmounts, marketCoinAmounts, allStakeAccounts] = await Promise.all([
|
|
3479
|
+
query.getCoinAmounts(poolCoinNames, ownerAddress),
|
|
3480
|
+
query.getMarketCoinAmounts(marketCoinNames, ownerAddress),
|
|
3481
|
+
query.getAllStakeAccounts(ownerAddress)
|
|
3482
|
+
]);
|
|
3483
|
+
const lendings = {};
|
|
3484
|
+
await Promise.allSettled(
|
|
3485
|
+
poolCoinNames.map(async (poolCoinName) => {
|
|
3486
|
+
const stakeMarketCoinName = stakeMarketCoinNames.find(
|
|
3487
|
+
(marketCoinName2) => marketCoinName2 === query.utils.parseMarketCoinName(poolCoinName)
|
|
3488
|
+
);
|
|
3489
|
+
const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
|
|
3490
|
+
lendings[poolCoinName] = await getLending(
|
|
3491
|
+
query,
|
|
3492
|
+
poolCoinName,
|
|
3493
|
+
ownerAddress,
|
|
3494
|
+
indexer,
|
|
3495
|
+
marketPools?.[poolCoinName],
|
|
3496
|
+
stakeMarketCoinName ? spools[stakeMarketCoinName] : void 0,
|
|
3497
|
+
stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : [],
|
|
3498
|
+
coinAmounts?.[poolCoinName],
|
|
3499
|
+
marketCoinAmounts?.[marketCoinName],
|
|
3500
|
+
coinPrices?.[poolCoinName] ?? 0
|
|
3501
|
+
);
|
|
3502
|
+
})
|
|
3414
3503
|
);
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3504
|
+
return lendings;
|
|
3505
|
+
};
|
|
3506
|
+
var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice, sCoinAmount) => {
|
|
3507
|
+
const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
|
|
3508
|
+
coinPrice = coinPrice ?? (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
|
|
3509
|
+
marketPool = marketPool ?? await query.getMarketPool(poolCoinName, indexer, {
|
|
3510
|
+
coinPrice
|
|
3511
|
+
});
|
|
3512
|
+
if (!marketPool)
|
|
3513
|
+
throw new Error(`Failed to fetch marketPool for ${poolCoinName}`);
|
|
3514
|
+
spool = spool ?? SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(
|
|
3515
|
+
marketCoinName,
|
|
3516
|
+
indexer,
|
|
3418
3517
|
{
|
|
3419
|
-
|
|
3420
|
-
|
|
3518
|
+
marketPool,
|
|
3519
|
+
coinPrices: {
|
|
3520
|
+
[poolCoinName]: coinPrice
|
|
3521
|
+
}
|
|
3421
3522
|
}
|
|
3422
|
-
);
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3523
|
+
) : void 0;
|
|
3524
|
+
stakeAccounts = stakeAccounts || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getStakeAccounts(
|
|
3525
|
+
marketCoinName,
|
|
3526
|
+
ownerAddress
|
|
3527
|
+
) : [];
|
|
3528
|
+
coinAmount = coinAmount || await query.getCoinAmount(poolCoinName, ownerAddress);
|
|
3529
|
+
marketCoinAmount = marketCoinAmount || await query.getMarketCoinAmount(marketCoinName, ownerAddress);
|
|
3530
|
+
sCoinAmount = sCoinAmount || await query.getSCoinAmount(marketCoinName, ownerAddress);
|
|
3531
|
+
const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
3532
|
+
let stakedMarketAmount = (0, import_bignumber5.default)(0);
|
|
3533
|
+
let stakedMarketCoin = (0, import_bignumber5.default)(0);
|
|
3534
|
+
let stakedAmount = (0, import_bignumber5.default)(0);
|
|
3535
|
+
let stakedCoin = (0, import_bignumber5.default)(0);
|
|
3536
|
+
let stakedValue = (0, import_bignumber5.default)(0);
|
|
3537
|
+
let availableUnstakeAmount = (0, import_bignumber5.default)(0);
|
|
3538
|
+
let availableUnstakeCoin = (0, import_bignumber5.default)(0);
|
|
3539
|
+
let availableClaimAmount = (0, import_bignumber5.default)(0);
|
|
3540
|
+
let availableClaimCoin = (0, import_bignumber5.default)(0);
|
|
3541
|
+
if (spool) {
|
|
3542
|
+
for (const stakeAccount of stakeAccounts) {
|
|
3543
|
+
const accountStakedMarketCoinAmount = (0, import_bignumber5.default)(stakeAccount.staked);
|
|
3544
|
+
const accountStakedMarketCoin = accountStakedMarketCoinAmount.shiftedBy(
|
|
3545
|
+
-1 * spool.coinDecimal
|
|
3546
|
+
);
|
|
3547
|
+
const accountStakedAmount = accountStakedMarketCoinAmount.multipliedBy(
|
|
3548
|
+
marketPool?.conversionRate ?? 1
|
|
3549
|
+
);
|
|
3550
|
+
const accountStakedCoin = accountStakedAmount.shiftedBy(
|
|
3551
|
+
-1 * spool.coinDecimal
|
|
3552
|
+
);
|
|
3553
|
+
const accountStakedValue = accountStakedCoin.multipliedBy(
|
|
3554
|
+
spool.coinPrice
|
|
3555
|
+
);
|
|
3556
|
+
stakedMarketAmount = stakedMarketAmount.plus(
|
|
3557
|
+
accountStakedMarketCoinAmount
|
|
3558
|
+
);
|
|
3559
|
+
stakedMarketCoin = stakedMarketCoin.plus(accountStakedMarketCoin);
|
|
3560
|
+
stakedAmount = stakedAmount.plus(accountStakedAmount);
|
|
3561
|
+
stakedCoin = stakedCoin.plus(accountStakedCoin);
|
|
3562
|
+
stakedValue = stakedValue.plus(accountStakedValue);
|
|
3563
|
+
availableUnstakeAmount = availableUnstakeAmount.plus(
|
|
3564
|
+
accountStakedMarketCoinAmount
|
|
3565
|
+
);
|
|
3566
|
+
availableUnstakeCoin = availableUnstakeAmount.shiftedBy(
|
|
3567
|
+
-1 * spool.coinDecimal
|
|
3568
|
+
);
|
|
3569
|
+
const baseIndexRate = 1e9;
|
|
3570
|
+
const increasedPointRate = spool.currentPointIndex ? (0, import_bignumber5.default)(spool.currentPointIndex - stakeAccount.index).dividedBy(
|
|
3571
|
+
baseIndexRate
|
|
3572
|
+
) : 1;
|
|
3573
|
+
availableClaimAmount = availableClaimAmount.plus(
|
|
3574
|
+
accountStakedMarketCoinAmount.multipliedBy(increasedPointRate).plus(stakeAccount.points).multipliedBy(spool.exchangeRateNumerator).dividedBy(spool.exchangeRateDenominator)
|
|
3575
|
+
);
|
|
3576
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
3577
|
+
-1 * spool.rewardCoinDecimal
|
|
3433
3578
|
);
|
|
3434
|
-
const rewards = Number(rewardPoolFields.rewards);
|
|
3435
|
-
const claimedRewards = Number(rewardPoolFields.claimed_rewards);
|
|
3436
|
-
stakeRewardPool = {
|
|
3437
|
-
id,
|
|
3438
|
-
type: (0, import_utils5.normalizeStructTag)(type),
|
|
3439
|
-
stakePoolId,
|
|
3440
|
-
ratioNumerator,
|
|
3441
|
-
ratioDenominator,
|
|
3442
|
-
rewards,
|
|
3443
|
-
claimedRewards
|
|
3444
|
-
};
|
|
3445
3579
|
}
|
|
3446
3580
|
}
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
var import_bignumber3 = __toESM(require("bignumber.js"));
|
|
3453
|
-
var queryBorrowIncentivePools = async (address) => {
|
|
3454
|
-
const queryPkgId = address.get("borrowIncentive.query");
|
|
3455
|
-
const incentivePoolsId = address.get("borrowIncentive.incentivePools");
|
|
3456
|
-
const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
|
|
3457
|
-
const args = [incentivePoolsId];
|
|
3458
|
-
const queryResult = await address.cache.queryInspectTxn({
|
|
3459
|
-
queryTarget,
|
|
3460
|
-
args
|
|
3461
|
-
});
|
|
3462
|
-
const borrowIncentivePoolsQueryData = queryResult?.events[0].parsedJson;
|
|
3463
|
-
return borrowIncentivePoolsQueryData;
|
|
3464
|
-
};
|
|
3465
|
-
var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
|
|
3466
|
-
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
3467
|
-
], indexer = false, coinPrices) => {
|
|
3468
|
-
const borrowIncentivePools = {};
|
|
3469
|
-
coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
|
|
3470
|
-
if (indexer) {
|
|
3471
|
-
const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
|
|
3472
|
-
const updateBorrowIncentivePool = (pool) => {
|
|
3473
|
-
if (!borrowIncentiveCoinNames.includes(pool.coinName))
|
|
3474
|
-
return;
|
|
3475
|
-
pool.coinPrice = coinPrices[pool.coinName] ?? pool.coinPrice;
|
|
3476
|
-
borrowIncentivePools[pool.coinName] = pool;
|
|
3477
|
-
};
|
|
3478
|
-
Object.values(borrowIncentivePoolsIndexer).forEach(
|
|
3479
|
-
updateBorrowIncentivePool
|
|
3480
|
-
);
|
|
3481
|
-
return borrowIncentivePools;
|
|
3482
|
-
}
|
|
3483
|
-
const borrowIncentivePoolsQueryData = await queryBorrowIncentivePools(
|
|
3484
|
-
query.address
|
|
3581
|
+
const suppliedAmount = (0, import_bignumber5.default)(marketCoinAmount).plus((0, import_bignumber5.default)(sCoinAmount)).multipliedBy(marketPool?.conversionRate ?? 1);
|
|
3582
|
+
const suppliedCoin = suppliedAmount.shiftedBy(-1 * coinDecimal);
|
|
3583
|
+
const suppliedValue = suppliedCoin.multipliedBy(coinPrice ?? 0);
|
|
3584
|
+
const marketCoinPrice = (0, import_bignumber5.default)(coinPrice ?? 0).multipliedBy(
|
|
3585
|
+
marketPool?.conversionRate ?? 1
|
|
3485
3586
|
);
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(pool);
|
|
3489
|
-
const poolCoinType = (0, import_utils7.normalizeStructTag)(pool.pool_type.name);
|
|
3490
|
-
const poolCoinName = query.utils.parseCoinNameFromType(
|
|
3491
|
-
poolCoinType
|
|
3492
|
-
);
|
|
3493
|
-
const poolCoinPrice = coinPrices?.[poolCoinName] ?? 0;
|
|
3494
|
-
const poolCoinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
3495
|
-
if (!borrowIncentiveCoinNames.includes(poolCoinName)) {
|
|
3496
|
-
continue;
|
|
3497
|
-
}
|
|
3498
|
-
for (const [coinName, poolPoint] of Object.entries(
|
|
3499
|
-
parsedBorrowIncentivePoolData.poolPoints
|
|
3500
|
-
)) {
|
|
3501
|
-
const rewardCoinType = (0, import_utils7.normalizeStructTag)(poolPoint.pointType);
|
|
3502
|
-
const rewardCoinName = query.utils.parseCoinNameFromType(
|
|
3503
|
-
rewardCoinType
|
|
3504
|
-
);
|
|
3505
|
-
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
3506
|
-
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
3507
|
-
const symbol = query.utils.parseSymbol(rewardCoinName);
|
|
3508
|
-
const coinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
3509
|
-
const calculatedPoolPoint = calculateBorrowIncentivePoolPointData(
|
|
3510
|
-
// parsedBorrowIncentivePoolData,
|
|
3511
|
-
poolPoint,
|
|
3512
|
-
rewardCoinPrice,
|
|
3513
|
-
rewardCoinDecimal,
|
|
3514
|
-
poolCoinPrice,
|
|
3515
|
-
poolCoinDecimal
|
|
3516
|
-
);
|
|
3517
|
-
borrowIncentivePoolPoints[coinName] = {
|
|
3518
|
-
symbol,
|
|
3519
|
-
coinName: rewardCoinName,
|
|
3520
|
-
coinType: rewardCoinType,
|
|
3521
|
-
coinDecimal,
|
|
3522
|
-
coinPrice: rewardCoinPrice,
|
|
3523
|
-
points: poolPoint.points,
|
|
3524
|
-
distributedPoint: poolPoint.distributedPoint,
|
|
3525
|
-
weightedAmount: poolPoint.weightedAmount,
|
|
3526
|
-
...calculatedPoolPoint
|
|
3527
|
-
};
|
|
3528
|
-
}
|
|
3529
|
-
const stakedAmount = (0, import_bignumber3.default)(parsedBorrowIncentivePoolData.staked);
|
|
3530
|
-
const stakedCoin = stakedAmount.shiftedBy(-1 * poolCoinDecimal);
|
|
3531
|
-
const stakedValue = stakedCoin.multipliedBy(poolCoinPrice);
|
|
3532
|
-
borrowIncentivePools[poolCoinName] = {
|
|
3533
|
-
coinName: poolCoinName,
|
|
3534
|
-
symbol: query.utils.parseSymbol(poolCoinName),
|
|
3535
|
-
coinType: poolCoinType,
|
|
3536
|
-
coinDecimal: poolCoinDecimal,
|
|
3537
|
-
coinPrice: poolCoinPrice,
|
|
3538
|
-
stakedAmount: stakedAmount.toNumber(),
|
|
3539
|
-
stakedCoin: stakedCoin.toNumber(),
|
|
3540
|
-
stakedValue: stakedValue.toNumber(),
|
|
3541
|
-
points: borrowIncentivePoolPoints
|
|
3542
|
-
};
|
|
3543
|
-
}
|
|
3544
|
-
return borrowIncentivePools;
|
|
3545
|
-
};
|
|
3546
|
-
var queryBorrowIncentiveAccounts = async ({
|
|
3547
|
-
utils
|
|
3548
|
-
}, obligationId, borrowIncentiveCoinNames = [
|
|
3549
|
-
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
3550
|
-
]) => {
|
|
3551
|
-
const queryPkgId = utils.address.get("borrowIncentive.query");
|
|
3552
|
-
const incentiveAccountsId = utils.address.get(
|
|
3553
|
-
"borrowIncentive.incentiveAccounts"
|
|
3554
|
-
);
|
|
3555
|
-
const queryTarget = `${queryPkgId}::incentive_account_query::incentive_account_data`;
|
|
3556
|
-
const args = [incentiveAccountsId, obligationId];
|
|
3557
|
-
const queryResult = await utils.cache.queryInspectTxn({ queryTarget, args });
|
|
3558
|
-
const borrowIncentiveAccountsQueryData = queryResult?.events[0]?.parsedJson;
|
|
3559
|
-
const borrowIncentiveAccounts = Object.values(
|
|
3560
|
-
borrowIncentiveAccountsQueryData?.pool_records ?? []
|
|
3561
|
-
).reduce((accounts, accountData) => {
|
|
3562
|
-
const parsedBorrowIncentiveAccount = parseOriginBorrowIncentiveAccountData(accountData);
|
|
3563
|
-
const poolType = parsedBorrowIncentiveAccount.poolType;
|
|
3564
|
-
const coinName = utils.parseCoinNameFromType(poolType);
|
|
3565
|
-
if (borrowIncentiveCoinNames && borrowIncentiveCoinNames.includes(coinName)) {
|
|
3566
|
-
accounts[coinName] = parsedBorrowIncentiveAccount;
|
|
3567
|
-
}
|
|
3568
|
-
return accounts;
|
|
3569
|
-
}, {});
|
|
3570
|
-
return borrowIncentiveAccounts;
|
|
3571
|
-
};
|
|
3572
|
-
var getBindedObligationId = async ({
|
|
3573
|
-
address
|
|
3574
|
-
}, veScaKeyId) => {
|
|
3575
|
-
const borrowIncentiveObjectId = address.get("borrowIncentive.object");
|
|
3576
|
-
const incentivePoolsId = address.get("borrowIncentive.incentivePools");
|
|
3577
|
-
const veScaObjId = address.get("vesca.object");
|
|
3578
|
-
const incentivePoolsResponse = await address.cache.queryGetObject(
|
|
3579
|
-
incentivePoolsId,
|
|
3580
|
-
{
|
|
3581
|
-
showContent: true
|
|
3582
|
-
}
|
|
3583
|
-
);
|
|
3584
|
-
if (incentivePoolsResponse?.data?.content?.dataType !== "moveObject")
|
|
3585
|
-
return null;
|
|
3586
|
-
const incentivePoolFields = incentivePoolsResponse.data.content.fields;
|
|
3587
|
-
const veScaBindTableId = incentivePoolFields.ve_sca_bind.fields.id.id;
|
|
3588
|
-
const keyType = `${borrowIncentiveObjectId}::typed_id::TypedID<${veScaObjId}::ve_sca::VeScaKey>`;
|
|
3589
|
-
const veScaBindTableResponse = await address.cache.queryGetDynamicFieldObject(
|
|
3590
|
-
{
|
|
3591
|
-
parentId: veScaBindTableId,
|
|
3592
|
-
name: {
|
|
3593
|
-
type: keyType,
|
|
3594
|
-
value: veScaKeyId
|
|
3595
|
-
}
|
|
3596
|
-
}
|
|
3587
|
+
const unstakedMarketAmount = (0, import_bignumber5.default)(marketCoinAmount).plus(
|
|
3588
|
+
(0, import_bignumber5.default)(sCoinAmount)
|
|
3597
3589
|
);
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
const
|
|
3601
|
-
const
|
|
3602
|
-
|
|
3590
|
+
const unstakedMarketCoin = unstakedMarketAmount.shiftedBy(-1 * coinDecimal);
|
|
3591
|
+
const availableSupplyAmount = (0, import_bignumber5.default)(coinAmount);
|
|
3592
|
+
const availableSupplyCoin = availableSupplyAmount.shiftedBy(-1 * coinDecimal);
|
|
3593
|
+
const availableWithdrawAmount = minBigNumber(
|
|
3594
|
+
suppliedAmount,
|
|
3595
|
+
marketPool?.supplyAmount ?? Infinity
|
|
3596
|
+
).plus(stakedAmount);
|
|
3597
|
+
const availableWithdrawCoin = minBigNumber(
|
|
3598
|
+
suppliedCoin,
|
|
3599
|
+
marketPool?.supplyCoin ?? Infinity
|
|
3600
|
+
).plus(stakedCoin);
|
|
3601
|
+
const lending = {
|
|
3602
|
+
coinName: poolCoinName,
|
|
3603
|
+
symbol: query.utils.parseSymbol(poolCoinName),
|
|
3604
|
+
coinType: query.utils.parseCoinType(poolCoinName),
|
|
3605
|
+
marketCoinType: query.utils.parseMarketCoinType(poolCoinName),
|
|
3606
|
+
sCoinType: marketPool?.sCoinType ?? "",
|
|
3607
|
+
coinDecimal,
|
|
3608
|
+
coinPrice: coinPrice ?? 0,
|
|
3609
|
+
conversionRate: marketPool?.conversionRate ?? 1,
|
|
3610
|
+
marketCoinPrice: marketCoinPrice.toNumber(),
|
|
3611
|
+
supplyApr: marketPool?.supplyApr ?? 0,
|
|
3612
|
+
supplyApy: marketPool?.supplyApy ?? 0,
|
|
3613
|
+
rewardApr: spool?.rewardApr ?? 0,
|
|
3614
|
+
suppliedAmount: suppliedAmount.plus(stakedAmount).toNumber(),
|
|
3615
|
+
suppliedCoin: suppliedCoin.plus(stakedCoin).toNumber(),
|
|
3616
|
+
suppliedValue: suppliedValue.plus(stakedValue).toNumber(),
|
|
3617
|
+
stakedMarketAmount: stakedMarketAmount.toNumber(),
|
|
3618
|
+
stakedMarketCoin: stakedMarketCoin.toNumber(),
|
|
3619
|
+
stakedAmount: stakedAmount.toNumber(),
|
|
3620
|
+
stakedCoin: stakedCoin.toNumber(),
|
|
3621
|
+
stakedValue: stakedValue.toNumber(),
|
|
3622
|
+
unstakedMarketAmount: unstakedMarketAmount.toNumber(),
|
|
3623
|
+
unstakedMarketCoin: unstakedMarketCoin.toNumber(),
|
|
3624
|
+
unstakedAmount: suppliedAmount.toNumber(),
|
|
3625
|
+
unstakedCoin: suppliedCoin.toNumber(),
|
|
3626
|
+
unstakedValue: suppliedValue.toNumber(),
|
|
3627
|
+
availableSupplyAmount: availableSupplyAmount.toNumber(),
|
|
3628
|
+
availableSupplyCoin: availableSupplyCoin.toNumber(),
|
|
3629
|
+
availableWithdrawAmount: availableWithdrawAmount.toNumber(),
|
|
3630
|
+
availableWithdrawCoin: availableWithdrawCoin.toNumber(),
|
|
3631
|
+
availableStakeAmount: unstakedMarketAmount.toNumber(),
|
|
3632
|
+
availableStakeCoin: unstakedMarketCoin.toNumber(),
|
|
3633
|
+
availableUnstakeAmount: availableUnstakeAmount.toNumber(),
|
|
3634
|
+
availableUnstakeCoin: availableUnstakeCoin.toNumber(),
|
|
3635
|
+
availableClaimAmount: availableClaimAmount.toNumber(),
|
|
3636
|
+
availableClaimCoin: availableClaimCoin.toNumber(),
|
|
3637
|
+
isIsolated: marketPool ? marketPool.isIsolated : false
|
|
3638
|
+
};
|
|
3639
|
+
return lending;
|
|
3603
3640
|
};
|
|
3604
|
-
var
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
const
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3641
|
+
var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
|
|
3642
|
+
const coinPrices = await query.utils.getCoinPrices();
|
|
3643
|
+
const market = await query.queryMarket(indexer, { coinPrices });
|
|
3644
|
+
const [coinAmounts, obligations] = await Promise.all([
|
|
3645
|
+
query.getCoinAmounts(void 0, ownerAddress),
|
|
3646
|
+
query.getObligations(ownerAddress)
|
|
3647
|
+
]);
|
|
3648
|
+
const obligationAccounts = {};
|
|
3649
|
+
await Promise.allSettled(
|
|
3650
|
+
obligations.map(async (obligation) => {
|
|
3651
|
+
obligationAccounts[obligation.keyId] = await getObligationAccount(
|
|
3652
|
+
query,
|
|
3653
|
+
obligation.id,
|
|
3654
|
+
ownerAddress,
|
|
3655
|
+
indexer,
|
|
3656
|
+
market,
|
|
3657
|
+
coinPrices,
|
|
3658
|
+
coinAmounts
|
|
3659
|
+
);
|
|
3660
|
+
})
|
|
3615
3661
|
);
|
|
3616
|
-
|
|
3617
|
-
return null;
|
|
3618
|
-
const incentiveAccountsTableId = incentiveAccountsObject.data.content.fields.accounts.fields.id.id;
|
|
3619
|
-
const bindedIncentiveAcc = await address.cache.queryGetDynamicFieldObject({
|
|
3620
|
-
parentId: incentiveAccountsTableId,
|
|
3621
|
-
name: {
|
|
3622
|
-
type: `${borrowIncentiveObjectId}::typed_id::TypedID<${corePkg}::obligation::Obligation>`,
|
|
3623
|
-
value: obligationId
|
|
3624
|
-
}
|
|
3625
|
-
});
|
|
3626
|
-
if (bindedIncentiveAcc?.data?.content?.dataType !== "moveObject")
|
|
3627
|
-
return null;
|
|
3628
|
-
const bindedIncentiveAccFields = bindedIncentiveAcc.data.content.fields;
|
|
3629
|
-
return bindedIncentiveAccFields.value.fields.binded_ve_sca_key?.fields.id ?? null;
|
|
3662
|
+
return obligationAccounts;
|
|
3630
3663
|
};
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3664
|
+
var getObligationAccount = async (query, obligationId, ownerAddress, indexer = false, market, coinPrices, coinAmounts) => {
|
|
3665
|
+
const collateralAssetCoinNames = [
|
|
3666
|
+
...SUPPORT_COLLATERALS
|
|
3667
|
+
];
|
|
3668
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices(collateralAssetCoinNames);
|
|
3669
|
+
market = market ?? await query.queryMarket(indexer, { coinPrices });
|
|
3670
|
+
coinAmounts = coinAmounts || await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress);
|
|
3671
|
+
const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] = await Promise.all([
|
|
3672
|
+
query.queryObligation(obligationId),
|
|
3673
|
+
query.getBorrowIncentivePools(void 0, indexer, {
|
|
3674
|
+
coinPrices
|
|
3675
|
+
}),
|
|
3676
|
+
query.getBorrowIncentiveAccounts(obligationId)
|
|
3677
|
+
]);
|
|
3678
|
+
const collaterals = {};
|
|
3679
|
+
const debts = {};
|
|
3680
|
+
const borrowIncentives = {};
|
|
3681
|
+
let totalDepositedPools = 0;
|
|
3682
|
+
let totalDepositedValue = (0, import_bignumber5.default)(0);
|
|
3683
|
+
let totalBorrowCapacityValue = (0, import_bignumber5.default)(0);
|
|
3684
|
+
let totalRequiredCollateralValue = (0, import_bignumber5.default)(0);
|
|
3685
|
+
let totalBorrowedPools = 0;
|
|
3686
|
+
let totalRewardedPools = 0;
|
|
3687
|
+
let totalBorrowedValue = (0, import_bignumber5.default)(0);
|
|
3688
|
+
let totalBorrowedValueWithWeight = (0, import_bignumber5.default)(0);
|
|
3689
|
+
for (const assetCoinName of collateralAssetCoinNames) {
|
|
3690
|
+
const collateral = obligationQuery?.collaterals.find((collateral2) => {
|
|
3691
|
+
const collateralCoinName = query.utils.parseCoinNameFromType(
|
|
3692
|
+
collateral2.type.name
|
|
3648
3693
|
);
|
|
3649
|
-
|
|
3650
|
-
|
|
3694
|
+
return assetCoinName === collateralCoinName;
|
|
3695
|
+
});
|
|
3696
|
+
const marketCollateral = market.collaterals[assetCoinName];
|
|
3697
|
+
const coinDecimal = query.utils.getCoinDecimal(assetCoinName);
|
|
3698
|
+
const coinPrice = coinPrices?.[assetCoinName];
|
|
3699
|
+
const coinAmount = coinAmounts?.[assetCoinName] ?? 0;
|
|
3700
|
+
if (marketCollateral && coinPrice) {
|
|
3701
|
+
const depositedAmount = (0, import_bignumber5.default)(collateral?.amount ?? 0);
|
|
3702
|
+
const depositedCoin = depositedAmount.shiftedBy(-1 * coinDecimal);
|
|
3703
|
+
const depositedValue = depositedCoin.multipliedBy(coinPrice);
|
|
3704
|
+
const borrowCapacityValue = depositedValue.multipliedBy(
|
|
3705
|
+
marketCollateral.collateralFactor
|
|
3651
3706
|
);
|
|
3652
|
-
const
|
|
3653
|
-
|
|
3707
|
+
const requiredCollateralValue2 = depositedValue.multipliedBy(
|
|
3708
|
+
marketCollateral.liquidationFactor
|
|
3654
3709
|
);
|
|
3655
|
-
const
|
|
3656
|
-
|
|
3710
|
+
const poolSizeAmount = (0, import_bignumber5.default)(marketCollateral.maxDepositAmount).minus(
|
|
3711
|
+
marketCollateral.depositAmount
|
|
3657
3712
|
);
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
return 0;
|
|
3662
|
-
};
|
|
3663
|
-
var getPythPrices = async ({
|
|
3664
|
-
address
|
|
3665
|
-
}, assetCoinNames) => {
|
|
3666
|
-
const pythPriceFeedIds = assetCoinNames.reduce(
|
|
3667
|
-
(prev, assetCoinName) => {
|
|
3668
|
-
const pythPriceFeed = address.get(
|
|
3669
|
-
`core.coins.${assetCoinName}.oracle.pyth.feedObject`
|
|
3713
|
+
const availableDepositAmount = minBigNumber(
|
|
3714
|
+
(0, import_bignumber5.default)(coinAmount),
|
|
3715
|
+
poolSizeAmount
|
|
3670
3716
|
);
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
} else {
|
|
3674
|
-
prev[pythPriceFeed].push(assetCoinName);
|
|
3675
|
-
}
|
|
3676
|
-
return prev;
|
|
3677
|
-
},
|
|
3678
|
-
{}
|
|
3679
|
-
);
|
|
3680
|
-
const priceFeedObjects = await address.cache.queryGetObjects(
|
|
3681
|
-
Object.keys(pythPriceFeedIds),
|
|
3682
|
-
{ showContent: true }
|
|
3683
|
-
);
|
|
3684
|
-
const assetToPriceFeedMapping = priceFeedObjects.reduce(
|
|
3685
|
-
(prev, priceFeedObject) => {
|
|
3686
|
-
pythPriceFeedIds[priceFeedObject.objectId].forEach((assetCoinName) => {
|
|
3687
|
-
prev[assetCoinName] = priceFeedObject;
|
|
3688
|
-
});
|
|
3689
|
-
return prev;
|
|
3690
|
-
},
|
|
3691
|
-
{}
|
|
3692
|
-
);
|
|
3693
|
-
return (await Promise.all(
|
|
3694
|
-
Object.entries(assetToPriceFeedMapping).map(
|
|
3695
|
-
async ([assetCoinName, priceFeedObject]) => ({
|
|
3696
|
-
coinName: assetCoinName,
|
|
3697
|
-
price: await getPythPrice(
|
|
3698
|
-
{ address },
|
|
3699
|
-
assetCoinName,
|
|
3700
|
-
priceFeedObject
|
|
3701
|
-
)
|
|
3702
|
-
})
|
|
3703
|
-
)
|
|
3704
|
-
)).reduce(
|
|
3705
|
-
(prev, curr) => {
|
|
3706
|
-
prev[curr.coinName] = curr.price;
|
|
3707
|
-
return prev;
|
|
3708
|
-
},
|
|
3709
|
-
{}
|
|
3710
|
-
);
|
|
3711
|
-
};
|
|
3712
|
-
|
|
3713
|
-
// src/queries/portfolioQuery.ts
|
|
3714
|
-
var import_bignumber4 = __toESM(require("bignumber.js"));
|
|
3715
|
-
var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress, indexer = false) => {
|
|
3716
|
-
const marketCoinNames = poolCoinNames.map(
|
|
3717
|
-
(poolCoinName) => query.utils.parseMarketCoinName(poolCoinName)
|
|
3718
|
-
);
|
|
3719
|
-
const stakeMarketCoinNames = marketCoinNames.filter(
|
|
3720
|
-
(marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
|
|
3721
|
-
);
|
|
3722
|
-
const coinPrices = await query.utils.getCoinPrices(poolCoinNames);
|
|
3723
|
-
const marketPools = await query.getMarketPools(poolCoinNames, indexer, {
|
|
3724
|
-
coinPrices
|
|
3725
|
-
});
|
|
3726
|
-
const spools = await query.getSpools(stakeMarketCoinNames, indexer, {
|
|
3727
|
-
marketPools,
|
|
3728
|
-
coinPrices
|
|
3729
|
-
});
|
|
3730
|
-
const [coinAmounts, marketCoinAmounts, allStakeAccounts] = await Promise.all([
|
|
3731
|
-
query.getCoinAmounts(poolCoinNames, ownerAddress),
|
|
3732
|
-
query.getMarketCoinAmounts(marketCoinNames, ownerAddress),
|
|
3733
|
-
query.getAllStakeAccounts(ownerAddress)
|
|
3734
|
-
]);
|
|
3735
|
-
const lendings = {};
|
|
3736
|
-
await Promise.allSettled(
|
|
3737
|
-
poolCoinNames.map(async (poolCoinName) => {
|
|
3738
|
-
const stakeMarketCoinName = stakeMarketCoinNames.find(
|
|
3739
|
-
(marketCoinName2) => marketCoinName2 === query.utils.parseMarketCoinName(poolCoinName)
|
|
3717
|
+
const availableDepositCoin = availableDepositAmount.shiftedBy(
|
|
3718
|
+
-1 * coinDecimal
|
|
3740
3719
|
);
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
ownerAddress,
|
|
3746
|
-
indexer,
|
|
3747
|
-
marketPools?.[poolCoinName],
|
|
3748
|
-
stakeMarketCoinName ? spools[stakeMarketCoinName] : void 0,
|
|
3749
|
-
stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : [],
|
|
3750
|
-
coinAmounts?.[poolCoinName],
|
|
3751
|
-
marketCoinAmounts?.[marketCoinName],
|
|
3752
|
-
coinPrices?.[poolCoinName] ?? 0
|
|
3720
|
+
totalDepositedValue = totalDepositedValue.plus(depositedValue);
|
|
3721
|
+
totalBorrowCapacityValue = totalBorrowCapacityValue.plus(borrowCapacityValue);
|
|
3722
|
+
totalRequiredCollateralValue = totalRequiredCollateralValue.plus(
|
|
3723
|
+
requiredCollateralValue2
|
|
3753
3724
|
);
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
return lendings;
|
|
3757
|
-
};
|
|
3758
|
-
var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice, sCoinAmount) => {
|
|
3759
|
-
const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
|
|
3760
|
-
coinPrice = coinPrice ?? (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
|
|
3761
|
-
marketPool = marketPool ?? await query.getMarketPool(poolCoinName, indexer, {
|
|
3762
|
-
coinPrice
|
|
3763
|
-
});
|
|
3764
|
-
if (!marketPool)
|
|
3765
|
-
throw new Error(`Failed to fetch marketPool for ${poolCoinName}`);
|
|
3766
|
-
spool = spool ?? SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(
|
|
3767
|
-
marketCoinName,
|
|
3768
|
-
indexer,
|
|
3769
|
-
{
|
|
3770
|
-
marketPool,
|
|
3771
|
-
coinPrices: {
|
|
3772
|
-
[poolCoinName]: coinPrice
|
|
3725
|
+
if (depositedAmount.isGreaterThan(0)) {
|
|
3726
|
+
totalDepositedPools++;
|
|
3773
3727
|
}
|
|
3728
|
+
collaterals[assetCoinName] = {
|
|
3729
|
+
coinName: assetCoinName,
|
|
3730
|
+
coinType: query.utils.parseCoinType(assetCoinName),
|
|
3731
|
+
symbol: query.utils.parseSymbol(assetCoinName),
|
|
3732
|
+
coinDecimal,
|
|
3733
|
+
coinPrice,
|
|
3734
|
+
depositedAmount: depositedAmount.toNumber(),
|
|
3735
|
+
depositedCoin: depositedCoin.toNumber(),
|
|
3736
|
+
depositedValue: depositedValue.toNumber(),
|
|
3737
|
+
borrowCapacityValue: borrowCapacityValue.toNumber(),
|
|
3738
|
+
requiredCollateralValue: requiredCollateralValue2.toNumber(),
|
|
3739
|
+
availableDepositAmount: availableDepositAmount.toNumber(),
|
|
3740
|
+
availableDepositCoin: availableDepositCoin.toNumber(),
|
|
3741
|
+
availableWithdrawAmount: 0,
|
|
3742
|
+
availableWithdrawCoin: 0
|
|
3743
|
+
};
|
|
3774
3744
|
}
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
)
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
3784
|
-
let stakedMarketAmount = (0, import_bignumber4.default)(0);
|
|
3785
|
-
let stakedMarketCoin = (0, import_bignumber4.default)(0);
|
|
3786
|
-
let stakedAmount = (0, import_bignumber4.default)(0);
|
|
3787
|
-
let stakedCoin = (0, import_bignumber4.default)(0);
|
|
3788
|
-
let stakedValue = (0, import_bignumber4.default)(0);
|
|
3789
|
-
let availableUnstakeAmount = (0, import_bignumber4.default)(0);
|
|
3790
|
-
let availableUnstakeCoin = (0, import_bignumber4.default)(0);
|
|
3791
|
-
let availableClaimAmount = (0, import_bignumber4.default)(0);
|
|
3792
|
-
let availableClaimCoin = (0, import_bignumber4.default)(0);
|
|
3793
|
-
if (spool) {
|
|
3794
|
-
for (const stakeAccount of stakeAccounts) {
|
|
3795
|
-
const accountStakedMarketCoinAmount = (0, import_bignumber4.default)(stakeAccount.staked);
|
|
3796
|
-
const accountStakedMarketCoin = accountStakedMarketCoinAmount.shiftedBy(
|
|
3797
|
-
-1 * spool.coinDecimal
|
|
3798
|
-
);
|
|
3799
|
-
const accountStakedAmount = accountStakedMarketCoinAmount.multipliedBy(
|
|
3800
|
-
marketPool?.conversionRate ?? 1
|
|
3801
|
-
);
|
|
3802
|
-
const accountStakedCoin = accountStakedAmount.shiftedBy(
|
|
3803
|
-
-1 * spool.coinDecimal
|
|
3804
|
-
);
|
|
3805
|
-
const accountStakedValue = accountStakedCoin.multipliedBy(
|
|
3806
|
-
spool.coinPrice
|
|
3807
|
-
);
|
|
3808
|
-
stakedMarketAmount = stakedMarketAmount.plus(
|
|
3809
|
-
accountStakedMarketCoinAmount
|
|
3745
|
+
}
|
|
3746
|
+
const borrowAssetCoinNames = [
|
|
3747
|
+
.../* @__PURE__ */ new Set([...Object.values(market.pools).map((pool) => pool.coinName)])
|
|
3748
|
+
];
|
|
3749
|
+
for (const assetCoinName of borrowAssetCoinNames) {
|
|
3750
|
+
const debt = obligationQuery?.debts.find((debt2) => {
|
|
3751
|
+
const poolCoinName = query.utils.parseCoinNameFromType(
|
|
3752
|
+
debt2.type.name
|
|
3810
3753
|
);
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3754
|
+
return assetCoinName === poolCoinName;
|
|
3755
|
+
});
|
|
3756
|
+
const marketPool = market.pools[assetCoinName];
|
|
3757
|
+
const coinDecimal = query.utils.getCoinDecimal(assetCoinName);
|
|
3758
|
+
const coinPrice = coinPrices?.[assetCoinName];
|
|
3759
|
+
const coinAmount = coinAmounts?.[assetCoinName] ?? 0;
|
|
3760
|
+
if (marketPool && coinPrice) {
|
|
3761
|
+
const increasedRate = debt?.borrowIndex ? marketPool.borrowIndex / Number(debt.borrowIndex) - 1 : 0;
|
|
3762
|
+
const borrowedAmount = (0, import_bignumber5.default)(debt?.amount ?? 0).multipliedBy(
|
|
3763
|
+
increasedRate + 1
|
|
3817
3764
|
);
|
|
3818
|
-
|
|
3819
|
-
|
|
3765
|
+
const borrowedCoin = borrowedAmount.shiftedBy(-1 * coinDecimal);
|
|
3766
|
+
const requiredRepayAmount = borrowedAmount;
|
|
3767
|
+
const requiredRepayCoin = requiredRepayAmount.shiftedBy(-1 * coinDecimal);
|
|
3768
|
+
const availableRepayAmount = (0, import_bignumber5.default)(coinAmount);
|
|
3769
|
+
const availableRepayCoin = availableRepayAmount.shiftedBy(
|
|
3770
|
+
-1 * coinDecimal
|
|
3820
3771
|
);
|
|
3821
|
-
const
|
|
3822
|
-
const
|
|
3823
|
-
|
|
3824
|
-
) : 1;
|
|
3825
|
-
availableClaimAmount = availableClaimAmount.plus(
|
|
3826
|
-
accountStakedMarketCoinAmount.multipliedBy(increasedPointRate).plus(stakeAccount.points).multipliedBy(spool.exchangeRateNumerator).dividedBy(spool.exchangeRateDenominator)
|
|
3772
|
+
const borrowedValue = requiredRepayCoin.multipliedBy(coinPrice);
|
|
3773
|
+
const borrowedValueWithWeight = borrowedValue.multipliedBy(
|
|
3774
|
+
marketPool.borrowWeight
|
|
3827
3775
|
);
|
|
3828
|
-
|
|
3829
|
-
|
|
3776
|
+
totalBorrowedValue = totalBorrowedValue.plus(borrowedValue);
|
|
3777
|
+
totalBorrowedValueWithWeight = totalBorrowedValueWithWeight.plus(
|
|
3778
|
+
borrowedValueWithWeight
|
|
3830
3779
|
);
|
|
3780
|
+
if (borrowedAmount.isGreaterThan(0)) {
|
|
3781
|
+
totalBorrowedPools++;
|
|
3782
|
+
}
|
|
3783
|
+
debts[assetCoinName] = {
|
|
3784
|
+
coinName: assetCoinName,
|
|
3785
|
+
coinType: query.utils.parseCoinType(assetCoinName),
|
|
3786
|
+
symbol: query.utils.parseSymbol(assetCoinName),
|
|
3787
|
+
coinDecimal,
|
|
3788
|
+
coinPrice,
|
|
3789
|
+
borrowedAmount: borrowedAmount.toNumber(),
|
|
3790
|
+
borrowedCoin: borrowedCoin.toNumber(),
|
|
3791
|
+
borrowedValue: borrowedValue.toNumber(),
|
|
3792
|
+
borrowedValueWithWeight: borrowedValueWithWeight.toNumber(),
|
|
3793
|
+
borrowIndex: Number(debt?.borrowIndex ?? 0),
|
|
3794
|
+
requiredRepayAmount: requiredRepayAmount.toNumber(),
|
|
3795
|
+
requiredRepayCoin: requiredRepayCoin.toNumber(),
|
|
3796
|
+
availableBorrowAmount: 0,
|
|
3797
|
+
availableBorrowCoin: 0,
|
|
3798
|
+
availableRepayAmount: availableRepayAmount.toNumber(),
|
|
3799
|
+
availableRepayCoin: availableRepayCoin.toNumber()
|
|
3800
|
+
};
|
|
3831
3801
|
}
|
|
3832
3802
|
}
|
|
3833
|
-
const
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3803
|
+
for (const [poolCoinName, borrowIncentiveAccount] of Object.entries(
|
|
3804
|
+
borrowIncentiveAccounts
|
|
3805
|
+
)) {
|
|
3806
|
+
const coinName = poolCoinName;
|
|
3807
|
+
const borrowIncentivePool = borrowIncentivePools[coinName];
|
|
3808
|
+
if (borrowIncentivePool) {
|
|
3809
|
+
const rewards = [];
|
|
3810
|
+
for (const rewardCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
|
|
3811
|
+
const accountPoint = borrowIncentiveAccount.pointList[rewardCoinName];
|
|
3812
|
+
const poolPoint = borrowIncentivePool.points[rewardCoinName];
|
|
3813
|
+
if (accountPoint && poolPoint) {
|
|
3814
|
+
let availableClaimAmount = (0, import_bignumber5.default)(0);
|
|
3815
|
+
let availableClaimCoin = (0, import_bignumber5.default)(0);
|
|
3816
|
+
const accountBorrowedAmount = (0, import_bignumber5.default)(accountPoint.weightedAmount);
|
|
3817
|
+
const baseIndexRate = 1e9;
|
|
3818
|
+
const increasedPointRate = poolPoint.currentPointIndex ? Math.max(
|
|
3819
|
+
(0, import_bignumber5.default)(poolPoint.currentPointIndex - accountPoint.index).dividedBy(baseIndexRate).toNumber(),
|
|
3820
|
+
0
|
|
3821
|
+
) : 1;
|
|
3822
|
+
availableClaimAmount = availableClaimAmount.plus(
|
|
3823
|
+
accountBorrowedAmount.multipliedBy(increasedPointRate).plus(accountPoint.points)
|
|
3824
|
+
);
|
|
3825
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
3826
|
+
-1 * poolPoint.coinDecimal
|
|
3827
|
+
);
|
|
3828
|
+
const weightScale = (0, import_bignumber5.default)(1e12);
|
|
3829
|
+
const boostValue = (0, import_bignumber5.default)(accountPoint.weightedAmount).div(
|
|
3830
|
+
(0, import_bignumber5.default)(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
|
|
3831
|
+
).isFinite() ? (0, import_bignumber5.default)(accountPoint.weightedAmount).div(
|
|
3832
|
+
(0, import_bignumber5.default)(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
|
|
3833
|
+
).toNumber() : 1;
|
|
3834
|
+
if (availableClaimAmount.isGreaterThanOrEqualTo(0)) {
|
|
3835
|
+
rewards.push({
|
|
3836
|
+
coinName: poolPoint.coinName,
|
|
3837
|
+
coinType: poolPoint.coinType,
|
|
3838
|
+
symbol: poolPoint.symbol,
|
|
3839
|
+
coinDecimal: poolPoint.coinDecimal,
|
|
3840
|
+
coinPrice: poolPoint.coinPrice,
|
|
3841
|
+
availableClaimAmount: availableClaimAmount.toNumber(),
|
|
3842
|
+
availableClaimCoin: availableClaimCoin.toNumber(),
|
|
3843
|
+
boostValue
|
|
3844
|
+
});
|
|
3845
|
+
}
|
|
3846
|
+
}
|
|
3847
|
+
}
|
|
3848
|
+
if (Object.keys(borrowIncentivePool.points).some((coinName2) => {
|
|
3849
|
+
const rewardApr = borrowIncentivePool.points[coinName2]?.rewardApr;
|
|
3850
|
+
return rewardApr !== Infinity && typeof rewardApr == "number" && rewardApr > 0;
|
|
3851
|
+
}) && borrowIncentiveAccount.debtAmount > 0) {
|
|
3852
|
+
totalRewardedPools++;
|
|
3853
|
+
}
|
|
3854
|
+
borrowIncentives[coinName] = {
|
|
3855
|
+
coinName: borrowIncentivePool.coinName,
|
|
3856
|
+
coinType: borrowIncentivePool.coinType,
|
|
3857
|
+
symbol: borrowIncentivePool.symbol,
|
|
3858
|
+
coinDecimal: borrowIncentivePool.coinDecimal,
|
|
3859
|
+
coinPrice: borrowIncentivePool.coinPrice,
|
|
3860
|
+
rewards
|
|
3861
|
+
};
|
|
3862
|
+
}
|
|
3863
|
+
}
|
|
3864
|
+
let riskLevel = totalRequiredCollateralValue.isZero() ? (0, import_bignumber5.default)(0) : totalBorrowedValueWithWeight.dividedBy(totalRequiredCollateralValue);
|
|
3865
|
+
riskLevel = riskLevel.isLessThan(1) ? riskLevel : (0, import_bignumber5.default)(1);
|
|
3866
|
+
const accountBalanceValue = totalDepositedValue.minus(totalBorrowedValue).isGreaterThan(0) ? totalDepositedValue.minus(totalBorrowedValue) : (0, import_bignumber5.default)(0);
|
|
3867
|
+
const availableCollateralValue = totalBorrowCapacityValue.minus(totalBorrowedValueWithWeight).isGreaterThan(0) ? totalBorrowCapacityValue.minus(totalBorrowedValueWithWeight) : (0, import_bignumber5.default)(0);
|
|
3868
|
+
const requiredCollateralValue = totalBorrowedValueWithWeight.isGreaterThan(0) ? totalRequiredCollateralValue : (0, import_bignumber5.default)(0);
|
|
3869
|
+
const unhealthyCollateralValue = totalBorrowedValueWithWeight.minus(requiredCollateralValue).isGreaterThan(0) ? totalBorrowedValueWithWeight.minus(requiredCollateralValue) : (0, import_bignumber5.default)(0);
|
|
3870
|
+
const obligationAccount = {
|
|
3871
|
+
obligationId,
|
|
3872
|
+
// Deposited collateral value (collateral balance)
|
|
3873
|
+
totalDepositedValue: totalDepositedValue.toNumber(),
|
|
3874
|
+
// Borrowed debt value (liabilities balance)
|
|
3875
|
+
totalBorrowedValue: totalBorrowedValue.toNumber(),
|
|
3876
|
+
// The difference between the user’s actual deposit and loan (remaining balance)
|
|
3877
|
+
totalBalanceValue: accountBalanceValue.toNumber(),
|
|
3878
|
+
// Effective collateral value (the actual collateral value included in the calculation).
|
|
3879
|
+
totalBorrowCapacityValue: totalBorrowCapacityValue.toNumber(),
|
|
3880
|
+
// Available collateral value (the remaining collateral value that can be borrowed).
|
|
3881
|
+
totalAvailableCollateralValue: availableCollateralValue.toNumber(),
|
|
3882
|
+
// Available debt value (the actual borrowing value included in the calculation).
|
|
3883
|
+
totalBorrowedValueWithWeight: totalBorrowedValueWithWeight.toNumber(),
|
|
3884
|
+
// Required collateral value (avoid be liquidated).
|
|
3885
|
+
totalRequiredCollateralValue: requiredCollateralValue.toNumber(),
|
|
3886
|
+
// Unliquidated collateral value (pending liquidation).
|
|
3887
|
+
totalUnhealthyCollateralValue: unhealthyCollateralValue.toNumber(),
|
|
3888
|
+
totalRiskLevel: riskLevel.toNumber(),
|
|
3889
|
+
totalDepositedPools,
|
|
3890
|
+
totalBorrowedPools,
|
|
3891
|
+
totalRewardedPools,
|
|
3892
|
+
collaterals,
|
|
3893
|
+
debts,
|
|
3894
|
+
borrowIncentives
|
|
3890
3895
|
};
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3896
|
+
for (const [collateralCoinName, obligationCollateral] of Object.entries(
|
|
3897
|
+
obligationAccount.collaterals
|
|
3898
|
+
)) {
|
|
3899
|
+
const marketCollateral = market.collaterals[collateralCoinName];
|
|
3900
|
+
if (marketCollateral) {
|
|
3901
|
+
let estimatedAvailableWithdrawAmount = (0, import_bignumber5.default)(
|
|
3902
|
+
obligationAccount.totalAvailableCollateralValue
|
|
3903
|
+
).dividedBy(marketCollateral.collateralFactor).dividedBy(marketCollateral.coinPrice).shiftedBy(marketCollateral.coinDecimal);
|
|
3904
|
+
estimatedAvailableWithdrawAmount = obligationAccount.totalBorrowedValueWithWeight === 0 ? (
|
|
3905
|
+
// Note: when there is no debt record, there is no need to estimate and the deposited amount is directly used as available withdraw.
|
|
3906
|
+
(0, import_bignumber5.default)(obligationCollateral.depositedAmount)
|
|
3907
|
+
) : minBigNumber(
|
|
3908
|
+
estimatedAvailableWithdrawAmount.multipliedBy(
|
|
3909
|
+
estimatedFactor(
|
|
3910
|
+
(0, import_bignumber5.default)(obligationAccount.totalAvailableCollateralValue).dividedBy(marketCollateral.collateralFactor).toNumber(),
|
|
3911
|
+
3,
|
|
3912
|
+
"increase"
|
|
3913
|
+
)
|
|
3914
|
+
).toNumber(),
|
|
3915
|
+
obligationCollateral.depositedAmount,
|
|
3916
|
+
marketCollateral.depositAmount
|
|
3911
3917
|
);
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3918
|
+
obligationCollateral.availableWithdrawAmount = estimatedAvailableWithdrawAmount.toNumber();
|
|
3919
|
+
obligationCollateral.availableWithdrawCoin = estimatedAvailableWithdrawAmount.shiftedBy(-1 * obligationCollateral.coinDecimal).toNumber();
|
|
3920
|
+
}
|
|
3921
|
+
}
|
|
3922
|
+
for (const [poolCoinName, obligationDebt] of Object.entries(
|
|
3923
|
+
obligationAccount.debts
|
|
3924
|
+
)) {
|
|
3925
|
+
const marketPool = market.pools[poolCoinName];
|
|
3926
|
+
if (marketPool) {
|
|
3927
|
+
const estimatedRequiredRepayAmount = (0, import_bignumber5.default)(
|
|
3928
|
+
obligationDebt.requiredRepayAmount
|
|
3929
|
+
).multipliedBy(
|
|
3930
|
+
estimatedFactor(obligationDebt.borrowedValue, 3, "decrease")
|
|
3931
|
+
);
|
|
3932
|
+
let estimatedAvailableBorrowAmount = (0, import_bignumber5.default)(
|
|
3933
|
+
obligationAccount.totalAvailableCollateralValue
|
|
3934
|
+
).dividedBy(marketPool.borrowWeight).shiftedBy(marketPool.coinDecimal).dividedBy(marketPool.coinPrice);
|
|
3935
|
+
estimatedAvailableBorrowAmount = obligationAccount.totalAvailableCollateralValue !== 0 ? minBigNumber(
|
|
3936
|
+
estimatedAvailableBorrowAmount.multipliedBy(
|
|
3937
|
+
estimatedFactor(
|
|
3938
|
+
estimatedAvailableBorrowAmount.shiftedBy(-1 * marketPool.coinDecimal).multipliedBy(marketPool.coinPrice).toNumber(),
|
|
3939
|
+
3,
|
|
3940
|
+
"increase"
|
|
3941
|
+
)
|
|
3942
|
+
).toNumber(),
|
|
3943
|
+
marketPool.supplyAmount
|
|
3944
|
+
) : (0, import_bignumber5.default)(0);
|
|
3945
|
+
obligationDebt.availableBorrowAmount = estimatedAvailableBorrowAmount.toNumber();
|
|
3946
|
+
obligationDebt.availableBorrowCoin = estimatedAvailableBorrowAmount.shiftedBy(-1 * obligationDebt.coinDecimal).toNumber();
|
|
3947
|
+
obligationDebt.requiredRepayAmount = estimatedRequiredRepayAmount.toNumber();
|
|
3948
|
+
obligationDebt.requiredRepayCoin = estimatedRequiredRepayAmount.shiftedBy(-1 * obligationDebt.coinDecimal).toNumber();
|
|
3949
|
+
}
|
|
3950
|
+
}
|
|
3951
|
+
return obligationAccount;
|
|
3915
3952
|
};
|
|
3916
|
-
var
|
|
3917
|
-
const
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
const
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3953
|
+
var getTotalValueLocked = async (query, indexer = false) => {
|
|
3954
|
+
const market = await query.queryMarket(indexer);
|
|
3955
|
+
let supplyValue = (0, import_bignumber5.default)(0);
|
|
3956
|
+
let borrowValue = (0, import_bignumber5.default)(0);
|
|
3957
|
+
if (indexer) {
|
|
3958
|
+
const tvlIndexer = await query.indexer.getTotalValueLocked();
|
|
3959
|
+
const tvl2 = {
|
|
3960
|
+
supplyValue: tvlIndexer.supplyValue,
|
|
3961
|
+
supplyValueChangeRatio: tvlIndexer.supplyValueChangeRatio,
|
|
3962
|
+
borrowValue: tvlIndexer.borrowValue,
|
|
3963
|
+
borrowValueChangeRatio: tvlIndexer.borrowValueChangeRatio,
|
|
3964
|
+
totalValue: tvlIndexer.totalValue,
|
|
3965
|
+
totalValueChangeRatio: tvlIndexer.totalValueChangeRatio
|
|
3966
|
+
};
|
|
3967
|
+
return tvl2;
|
|
3968
|
+
}
|
|
3969
|
+
for (const pool of Object.values(market.pools)) {
|
|
3970
|
+
supplyValue = supplyValue.plus(
|
|
3971
|
+
(0, import_bignumber5.default)(pool.supplyCoin).multipliedBy(pool.coinPrice)
|
|
3972
|
+
);
|
|
3973
|
+
borrowValue = borrowValue.plus(
|
|
3974
|
+
(0, import_bignumber5.default)(pool.borrowCoin).multipliedBy(pool.coinPrice)
|
|
3975
|
+
);
|
|
3976
|
+
}
|
|
3977
|
+
for (const collateral of Object.values(market.collaterals)) {
|
|
3978
|
+
supplyValue = supplyValue.plus(
|
|
3979
|
+
(0, import_bignumber5.default)(collateral.depositCoin).multipliedBy(collateral.coinPrice)
|
|
3980
|
+
);
|
|
3981
|
+
}
|
|
3982
|
+
const tvl = {
|
|
3983
|
+
supplyValue: supplyValue.toNumber(),
|
|
3984
|
+
borrowValue: borrowValue.toNumber(),
|
|
3985
|
+
totalValue: supplyValue.minus(borrowValue).toNumber()
|
|
3986
|
+
};
|
|
3987
|
+
return tvl;
|
|
3988
|
+
};
|
|
3989
|
+
|
|
3990
|
+
// src/queries/priceQuery.ts
|
|
3991
|
+
var getPythPrice = async ({
|
|
3992
|
+
address
|
|
3993
|
+
}, assetCoinName, priceFeedObject) => {
|
|
3994
|
+
const pythFeedObjectId = address.get(
|
|
3995
|
+
`core.coins.${assetCoinName}.oracle.pyth.feedObject`
|
|
3996
|
+
);
|
|
3997
|
+
priceFeedObject = priceFeedObject || (await address.cache.queryGetObject(pythFeedObjectId, {
|
|
3998
|
+
showContent: true
|
|
3999
|
+
}))?.data;
|
|
4000
|
+
if (priceFeedObject) {
|
|
4001
|
+
const priceFeedPoolObject = priceFeedObject;
|
|
4002
|
+
if (priceFeedPoolObject.content && "fields" in priceFeedPoolObject.content) {
|
|
4003
|
+
const fields = priceFeedPoolObject.content.fields;
|
|
4004
|
+
const expoMagnitude = Number(
|
|
4005
|
+
fields.price_info.fields.price_feed.fields.price.fields.expo.fields.magnitude
|
|
3945
4006
|
);
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
const marketCollateral = market.collaterals[assetCoinName];
|
|
3949
|
-
const coinDecimal = query.utils.getCoinDecimal(assetCoinName);
|
|
3950
|
-
const coinPrice = coinPrices?.[assetCoinName];
|
|
3951
|
-
const coinAmount = coinAmounts?.[assetCoinName] ?? 0;
|
|
3952
|
-
if (marketCollateral && coinPrice) {
|
|
3953
|
-
const depositedAmount = (0, import_bignumber4.default)(collateral?.amount ?? 0);
|
|
3954
|
-
const depositedCoin = depositedAmount.shiftedBy(-1 * coinDecimal);
|
|
3955
|
-
const depositedValue = depositedCoin.multipliedBy(coinPrice);
|
|
3956
|
-
const borrowCapacityValue = depositedValue.multipliedBy(
|
|
3957
|
-
marketCollateral.collateralFactor
|
|
4007
|
+
const expoNegative = Number(
|
|
4008
|
+
fields.price_info.fields.price_feed.fields.price.fields.expo.fields.negative
|
|
3958
4009
|
);
|
|
3959
|
-
const
|
|
3960
|
-
|
|
4010
|
+
const priceMagnitude = Number(
|
|
4011
|
+
fields.price_info.fields.price_feed.fields.price.fields.price.fields.magnitude
|
|
3961
4012
|
);
|
|
3962
|
-
const
|
|
3963
|
-
|
|
4013
|
+
const priceNegative = Number(
|
|
4014
|
+
fields.price_info.fields.price_feed.fields.price.fields.price.fields.negative
|
|
3964
4015
|
);
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
4016
|
+
return priceMagnitude * 10 ** ((expoNegative ? -1 : 1) * expoMagnitude) * (priceNegative ? -1 : 1);
|
|
4017
|
+
}
|
|
4018
|
+
}
|
|
4019
|
+
return 0;
|
|
4020
|
+
};
|
|
4021
|
+
var getPythPrices = async ({
|
|
4022
|
+
address
|
|
4023
|
+
}, assetCoinNames) => {
|
|
4024
|
+
const pythPriceFeedIds = assetCoinNames.reduce(
|
|
4025
|
+
(prev, assetCoinName) => {
|
|
4026
|
+
const pythPriceFeed = address.get(
|
|
4027
|
+
`core.coins.${assetCoinName}.oracle.pyth.feedObject`
|
|
4028
|
+
);
|
|
4029
|
+
if (!prev[pythPriceFeed]) {
|
|
4030
|
+
prev[pythPriceFeed] = [assetCoinName];
|
|
4031
|
+
} else {
|
|
4032
|
+
prev[pythPriceFeed].push(assetCoinName);
|
|
4033
|
+
}
|
|
4034
|
+
return prev;
|
|
4035
|
+
},
|
|
4036
|
+
{}
|
|
4037
|
+
);
|
|
4038
|
+
const priceFeedObjects = await address.cache.queryGetObjects(
|
|
4039
|
+
Object.keys(pythPriceFeedIds),
|
|
4040
|
+
{ showContent: true }
|
|
4041
|
+
);
|
|
4042
|
+
const assetToPriceFeedMapping = priceFeedObjects.reduce(
|
|
4043
|
+
(prev, priceFeedObject) => {
|
|
4044
|
+
pythPriceFeedIds[priceFeedObject.objectId].forEach((assetCoinName) => {
|
|
4045
|
+
prev[assetCoinName] = priceFeedObject;
|
|
4046
|
+
});
|
|
4047
|
+
return prev;
|
|
4048
|
+
},
|
|
4049
|
+
{}
|
|
4050
|
+
);
|
|
4051
|
+
return (await Promise.all(
|
|
4052
|
+
Object.entries(assetToPriceFeedMapping).map(
|
|
4053
|
+
async ([assetCoinName, priceFeedObject]) => ({
|
|
4054
|
+
coinName: assetCoinName,
|
|
4055
|
+
price: await getPythPrice(
|
|
4056
|
+
{ address },
|
|
4057
|
+
assetCoinName,
|
|
4058
|
+
priceFeedObject
|
|
4059
|
+
)
|
|
4060
|
+
})
|
|
4061
|
+
)
|
|
4062
|
+
)).reduce(
|
|
4063
|
+
(prev, curr) => {
|
|
4064
|
+
prev[curr.coinName] = curr.price;
|
|
4065
|
+
return prev;
|
|
4066
|
+
},
|
|
4067
|
+
{}
|
|
4068
|
+
);
|
|
4069
|
+
};
|
|
4070
|
+
|
|
4071
|
+
// src/queries/referralQuery.ts
|
|
4072
|
+
var queryVeScaKeyIdFromReferralBindings = async (address, refereeAddress) => {
|
|
4073
|
+
const referralBindingTableId = address.get("referral.bindingTableId");
|
|
4074
|
+
const referralBindResponse = await address.cache.queryGetDynamicFieldObject({
|
|
4075
|
+
parentId: referralBindingTableId,
|
|
4076
|
+
name: {
|
|
4077
|
+
type: "address",
|
|
4078
|
+
value: refereeAddress
|
|
4079
|
+
}
|
|
4080
|
+
});
|
|
4081
|
+
if (referralBindResponse?.data?.content?.dataType !== "moveObject")
|
|
4082
|
+
return null;
|
|
4083
|
+
const fields = referralBindResponse.data.content.fields;
|
|
4084
|
+
return fields.value;
|
|
4085
|
+
};
|
|
4086
|
+
|
|
4087
|
+
// src/queries/sCoinQuery.ts
|
|
4088
|
+
var import_bcs = require("@mysten/sui/bcs");
|
|
4089
|
+
var import_assert = __toESM(require("assert"));
|
|
4090
|
+
var import_bignumber6 = __toESM(require("bignumber.js"));
|
|
4091
|
+
var getSCoinTotalSupply = async ({
|
|
4092
|
+
utils
|
|
4093
|
+
}, sCoinName) => {
|
|
4094
|
+
const sCoinPkgId = utils.address.get("scoin.id");
|
|
4095
|
+
const args = [utils.getSCoinTreasury(sCoinName)];
|
|
4096
|
+
const typeArgs = [
|
|
4097
|
+
utils.parseSCoinType(sCoinName),
|
|
4098
|
+
utils.parseUnderlyingSCoinType(sCoinName)
|
|
4099
|
+
];
|
|
4100
|
+
const queryTarget = `${sCoinPkgId}::s_coin_converter::total_supply`;
|
|
4101
|
+
const queryResults = await utils.cache.queryInspectTxn({
|
|
4102
|
+
queryTarget,
|
|
4103
|
+
args,
|
|
4104
|
+
typeArgs
|
|
4105
|
+
});
|
|
4106
|
+
const results = queryResults?.results;
|
|
4107
|
+
if (results && results[0]?.returnValues) {
|
|
4108
|
+
const value = Uint8Array.from(results[0].returnValues[0][0]);
|
|
4109
|
+
const type = results[0].returnValues[0][1];
|
|
4110
|
+
(0, import_assert.default)(type === "u64", "Result type is not u64");
|
|
4111
|
+
return (0, import_bignumber6.default)(import_bcs.bcs.u64().parse(value)).shiftedBy(utils.getCoinDecimal(utils.parseCoinName(sCoinName))).toNumber();
|
|
4112
|
+
}
|
|
4113
|
+
return 0;
|
|
4114
|
+
};
|
|
4115
|
+
var getSCoinAmounts = async ({
|
|
4116
|
+
utils
|
|
4117
|
+
}, sCoinNames = [...SUPPORT_SCOIN], ownerAddress) => {
|
|
4118
|
+
const owner = ownerAddress || utils.suiKit.currentAddress();
|
|
4119
|
+
const sCoins2 = {};
|
|
4120
|
+
await Promise.allSettled(
|
|
4121
|
+
sCoinNames.map(async (sCoinName) => {
|
|
4122
|
+
const sCoin = await getSCoinAmount({ utils }, sCoinName, owner);
|
|
4123
|
+
sCoins2[sCoinName] = sCoin;
|
|
4124
|
+
})
|
|
4125
|
+
);
|
|
4126
|
+
return sCoins2;
|
|
4127
|
+
};
|
|
4128
|
+
var getSCoinAmount = async ({
|
|
4129
|
+
utils
|
|
4130
|
+
}, sCoinName, ownerAddress) => {
|
|
4131
|
+
const owner = ownerAddress || utils.suiKit.currentAddress();
|
|
4132
|
+
const sCoinType = utils.parseSCoinType(sCoinName);
|
|
4133
|
+
const amount = await utils.cache.queryGetCoinBalance({
|
|
4134
|
+
owner,
|
|
4135
|
+
coinType: sCoinType
|
|
4136
|
+
});
|
|
4137
|
+
return (0, import_bignumber6.default)(amount).toNumber();
|
|
4138
|
+
};
|
|
4139
|
+
var isSupportStakeCoins = (value) => {
|
|
4140
|
+
return SUPPORT_SCOIN.includes(value);
|
|
4141
|
+
};
|
|
4142
|
+
var checkAssetParams = (fromSCoin, toSCoin) => {
|
|
4143
|
+
if (fromSCoin === toSCoin)
|
|
4144
|
+
throw new Error("fromAsset and toAsset must be different");
|
|
4145
|
+
if (!isSupportStakeCoins(fromSCoin))
|
|
4146
|
+
throw new Error("fromAsset is not supported");
|
|
4147
|
+
if (!isSupportStakeCoins(toSCoin)) {
|
|
4148
|
+
throw new Error("toAsset is not supported");
|
|
4149
|
+
}
|
|
4150
|
+
};
|
|
4151
|
+
var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) => {
|
|
4152
|
+
checkAssetParams(fromSCoin, toSCoin);
|
|
4153
|
+
const fromCoinName = query.utils.parseCoinName(fromSCoin);
|
|
4154
|
+
const toCoinName = query.utils.parseCoinName(toSCoin);
|
|
4155
|
+
const marketPools = await Promise.all([
|
|
4156
|
+
query.getMarketPool(fromCoinName, false),
|
|
4157
|
+
query.getMarketPool(toCoinName, false)
|
|
4158
|
+
]);
|
|
4159
|
+
if (marketPools.some((pool) => !pool))
|
|
4160
|
+
throw new Error("Failed to fetch the lendings data");
|
|
4161
|
+
if (marketPools.some((pool) => pool?.conversionRate === 0)) {
|
|
4162
|
+
throw new Error("Conversion rate cannot be zero");
|
|
4163
|
+
}
|
|
4164
|
+
const ScoinAToARate = marketPools[0].conversionRate;
|
|
4165
|
+
const BtoSCoinBRate = 1 / marketPools[1].conversionRate;
|
|
4166
|
+
const calcAtoBRate = async () => {
|
|
4167
|
+
const prices = await query.utils.getCoinPrices([fromCoinName, toCoinName]);
|
|
4168
|
+
if (!prices[fromCoinName] || !prices[toCoinName]) {
|
|
4169
|
+
throw new Error("Failed to fetch the coin prices");
|
|
4170
|
+
}
|
|
4171
|
+
if (prices[toCoinName] === 0) {
|
|
4172
|
+
throw new Error("Price of toCoin cannot be zero");
|
|
4173
|
+
}
|
|
4174
|
+
return prices[fromCoinName] / prices[toCoinName];
|
|
4175
|
+
};
|
|
4176
|
+
const AtoBRate = underlyingCoinPrice ?? await calcAtoBRate();
|
|
4177
|
+
return (0, import_bignumber6.default)(ScoinAToARate).multipliedBy(AtoBRate).multipliedBy(BtoSCoinBRate).toNumber();
|
|
4178
|
+
};
|
|
4179
|
+
|
|
4180
|
+
// src/queries/spoolQuery.ts
|
|
4181
|
+
var import_utils8 = require("@mysten/sui/utils");
|
|
4182
|
+
var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexer = false, marketPools, coinPrices) => {
|
|
4183
|
+
const stakeCoinNames = stakeMarketCoinNames.map(
|
|
4184
|
+
(stakeMarketCoinName) => query.utils.parseCoinName(stakeMarketCoinName)
|
|
4185
|
+
);
|
|
4186
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
|
|
4187
|
+
marketPools = marketPools ?? await query.getMarketPools(stakeCoinNames, indexer);
|
|
4188
|
+
if (!marketPools)
|
|
4189
|
+
throw new Error(`Fail to fetch marketPools for ${stakeCoinNames}`);
|
|
4190
|
+
const spools = {};
|
|
4191
|
+
if (indexer) {
|
|
4192
|
+
const spoolsIndexer = await query.indexer.getSpools();
|
|
4193
|
+
const updateSpools = (spool) => {
|
|
4194
|
+
if (!stakeMarketCoinNames.includes(spool.marketCoinName))
|
|
4195
|
+
return;
|
|
4196
|
+
const coinName = query.utils.parseCoinName(
|
|
4197
|
+
spool.marketCoinName
|
|
3968
4198
|
);
|
|
3969
|
-
const
|
|
3970
|
-
|
|
4199
|
+
const rewardCoinName = query.utils.getSpoolRewardCoinName(
|
|
4200
|
+
spool.marketCoinName
|
|
3971
4201
|
);
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
4202
|
+
const marketPool = marketPools[coinName];
|
|
4203
|
+
spool.coinPrice = coinPrices[coinName] ?? spool.coinPrice;
|
|
4204
|
+
spool.marketCoinPrice = coinPrices[coinName] ? (coinPrices[coinName] ?? 0) * (marketPool ? marketPool.conversionRate : 0) : spool.marketCoinPrice;
|
|
4205
|
+
spool.rewardCoinPrice = coinPrices[rewardCoinName] ?? spool.rewardCoinPrice;
|
|
4206
|
+
spools[spool.marketCoinName] = spool;
|
|
4207
|
+
};
|
|
4208
|
+
Object.values(spoolsIndexer).forEach(updateSpools);
|
|
4209
|
+
return spools;
|
|
4210
|
+
}
|
|
4211
|
+
for (const stakeMarketCoinName of stakeMarketCoinNames) {
|
|
4212
|
+
const stakeCoinName = query.utils.parseCoinName(stakeMarketCoinName);
|
|
4213
|
+
const spool = await getSpool(
|
|
4214
|
+
query,
|
|
4215
|
+
stakeMarketCoinName,
|
|
4216
|
+
indexer,
|
|
4217
|
+
marketPools[stakeCoinName],
|
|
4218
|
+
coinPrices
|
|
4219
|
+
);
|
|
4220
|
+
if (spool) {
|
|
4221
|
+
spools[stakeMarketCoinName] = spool;
|
|
4222
|
+
}
|
|
4223
|
+
}
|
|
4224
|
+
return spools;
|
|
4225
|
+
};
|
|
4226
|
+
var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPrices) => {
|
|
4227
|
+
const coinName = query.utils.parseCoinName(marketCoinName);
|
|
4228
|
+
marketPool = marketPool || await query.getMarketPool(coinName, indexer);
|
|
4229
|
+
if (!marketPool) {
|
|
4230
|
+
throw new Error(`Fail to fetch marketPool for ${coinName}`);
|
|
4231
|
+
}
|
|
4232
|
+
const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
|
|
4233
|
+
const rewardPoolId = query.address.get(
|
|
4234
|
+
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
4235
|
+
);
|
|
4236
|
+
let spool = void 0;
|
|
4237
|
+
coinPrices = coinPrices || await query.utils.getCoinPrices([coinName]);
|
|
4238
|
+
if (indexer) {
|
|
4239
|
+
const spoolIndexer = await query.indexer.getSpool(marketCoinName);
|
|
4240
|
+
const coinName2 = query.utils.parseCoinName(marketCoinName);
|
|
4241
|
+
const rewardCoinName2 = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
4242
|
+
spoolIndexer.coinPrice = coinPrices?.[coinName2] || spoolIndexer.coinPrice;
|
|
4243
|
+
spoolIndexer.marketCoinPrice = (coinPrices?.[coinName2] ?? 0) * (marketPool ? marketPool.conversionRate : 0) || spoolIndexer.marketCoinPrice;
|
|
4244
|
+
spoolIndexer.rewardCoinPrice = coinPrices?.[rewardCoinName2] || spoolIndexer.rewardCoinPrice;
|
|
4245
|
+
return spoolIndexer;
|
|
4246
|
+
}
|
|
4247
|
+
const spoolObjectResponse = await query.cache.queryGetObjects(
|
|
4248
|
+
[poolId, rewardPoolId],
|
|
4249
|
+
{
|
|
4250
|
+
showContent: true
|
|
4251
|
+
}
|
|
4252
|
+
);
|
|
4253
|
+
if (!(spoolObjectResponse[0] && spoolObjectResponse[1])) {
|
|
4254
|
+
throw new Error("Fail to fetch spoolObjectResponse!");
|
|
4255
|
+
}
|
|
4256
|
+
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
4257
|
+
coinPrices = coinPrices || await query.utils.getCoinPrices([coinName, rewardCoinName]);
|
|
4258
|
+
const spoolObject = spoolObjectResponse[0];
|
|
4259
|
+
const rewardPoolObject = spoolObjectResponse[1];
|
|
4260
|
+
if (spoolObject.content && "fields" in spoolObject.content) {
|
|
4261
|
+
const spoolFields = spoolObject.content.fields;
|
|
4262
|
+
const parsedSpoolData = parseOriginSpoolData({
|
|
4263
|
+
stakeType: spoolFields.stake_type,
|
|
4264
|
+
maxDistributedPoint: spoolFields.max_distributed_point,
|
|
4265
|
+
distributedPoint: spoolFields.distributed_point,
|
|
4266
|
+
distributedPointPerPeriod: spoolFields.distributed_point_per_period,
|
|
4267
|
+
pointDistributionTime: spoolFields.point_distribution_time,
|
|
4268
|
+
maxStake: spoolFields.max_stakes,
|
|
4269
|
+
stakes: spoolFields.stakes,
|
|
4270
|
+
index: spoolFields.index,
|
|
4271
|
+
createdAt: spoolFields.created_at,
|
|
4272
|
+
lastUpdate: spoolFields.last_update
|
|
4273
|
+
});
|
|
4274
|
+
const marketCoinPrice = (coinPrices?.[coinName] ?? 0) * marketPool.conversionRate;
|
|
4275
|
+
const marketCoinDecimal = query.utils.getCoinDecimal(marketCoinName);
|
|
4276
|
+
const calculatedSpoolData = calculateSpoolData(
|
|
4277
|
+
parsedSpoolData,
|
|
4278
|
+
marketCoinPrice,
|
|
4279
|
+
marketCoinDecimal
|
|
4280
|
+
);
|
|
4281
|
+
if (rewardPoolObject.content && "fields" in rewardPoolObject.content) {
|
|
4282
|
+
const rewardPoolFields = rewardPoolObject.content.fields;
|
|
4283
|
+
const parsedSpoolRewardPoolData = parseOriginSpoolRewardPoolData({
|
|
4284
|
+
claimed_rewards: rewardPoolFields.claimed_rewards,
|
|
4285
|
+
exchange_rate_numerator: rewardPoolFields.exchange_rate_numerator,
|
|
4286
|
+
exchange_rate_denominator: rewardPoolFields.exchange_rate_denominator,
|
|
4287
|
+
rewards: rewardPoolFields.rewards,
|
|
4288
|
+
spool_id: rewardPoolFields.spool_id
|
|
4289
|
+
});
|
|
4290
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
4291
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
4292
|
+
const calculatedRewardPoolData = calculateSpoolRewardPoolData(
|
|
4293
|
+
parsedSpoolData,
|
|
4294
|
+
parsedSpoolRewardPoolData,
|
|
4295
|
+
calculatedSpoolData,
|
|
4296
|
+
rewardCoinPrice,
|
|
4297
|
+
rewardCoinDecimal
|
|
3976
4298
|
);
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
coinDecimal,
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
4299
|
+
spool = {
|
|
4300
|
+
marketCoinName,
|
|
4301
|
+
symbol: query.utils.parseSymbol(marketCoinName),
|
|
4302
|
+
coinType: query.utils.parseCoinType(coinName),
|
|
4303
|
+
marketCoinType: query.utils.parseMarketCoinType(coinName),
|
|
4304
|
+
rewardCoinType: isMarketCoin(rewardCoinName) ? query.utils.parseMarketCoinType(rewardCoinName) : query.utils.parseCoinType(rewardCoinName),
|
|
4305
|
+
sCoinType: marketPool.sCoinType,
|
|
4306
|
+
coinDecimal: query.utils.getCoinDecimal(coinName),
|
|
4307
|
+
rewardCoinDecimal: query.utils.getCoinDecimal(rewardCoinName),
|
|
4308
|
+
coinPrice: coinPrices?.[coinName] ?? 0,
|
|
4309
|
+
marketCoinPrice,
|
|
4310
|
+
rewardCoinPrice,
|
|
4311
|
+
maxPoint: parsedSpoolData.maxPoint,
|
|
4312
|
+
distributedPoint: parsedSpoolData.distributedPoint,
|
|
4313
|
+
maxStake: parsedSpoolData.maxStake,
|
|
4314
|
+
...calculatedSpoolData,
|
|
4315
|
+
exchangeRateNumerator: parsedSpoolRewardPoolData.exchangeRateNumerator,
|
|
4316
|
+
exchangeRateDenominator: parsedSpoolRewardPoolData.exchangeRateDenominator,
|
|
4317
|
+
...calculatedRewardPoolData
|
|
3995
4318
|
};
|
|
3996
4319
|
}
|
|
3997
4320
|
}
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4321
|
+
return spool;
|
|
4322
|
+
};
|
|
4323
|
+
var getStakeAccounts = async ({
|
|
4324
|
+
utils
|
|
4325
|
+
}, ownerAddress) => {
|
|
4326
|
+
const owner = ownerAddress || utils.suiKit.currentAddress();
|
|
4327
|
+
const spoolObjectId = utils.address.get("spool.object");
|
|
4328
|
+
const stakeAccountType = `${spoolObjectId}::spool_account::SpoolAccount`;
|
|
4329
|
+
const stakeObjectsResponse = [];
|
|
4330
|
+
let hasNextPage = false;
|
|
4331
|
+
let nextCursor = null;
|
|
4332
|
+
do {
|
|
4333
|
+
const paginatedStakeObjectsResponse = await utils.cache.queryGetOwnedObjects({
|
|
4334
|
+
owner,
|
|
4335
|
+
filter: { StructType: stakeAccountType },
|
|
4336
|
+
options: {
|
|
4337
|
+
showContent: true,
|
|
4338
|
+
showType: true
|
|
4339
|
+
},
|
|
4340
|
+
cursor: nextCursor,
|
|
4341
|
+
limit: 10
|
|
4007
4342
|
});
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
);
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4343
|
+
if (!paginatedStakeObjectsResponse)
|
|
4344
|
+
continue;
|
|
4345
|
+
stakeObjectsResponse.push(...paginatedStakeObjectsResponse.data);
|
|
4346
|
+
if (paginatedStakeObjectsResponse.hasNextPage && paginatedStakeObjectsResponse.nextCursor) {
|
|
4347
|
+
hasNextPage = true;
|
|
4348
|
+
nextCursor = paginatedStakeObjectsResponse.nextCursor;
|
|
4349
|
+
} else {
|
|
4350
|
+
hasNextPage = false;
|
|
4351
|
+
}
|
|
4352
|
+
} while (hasNextPage);
|
|
4353
|
+
const stakeAccounts = SUPPORT_SPOOLS.reduce(
|
|
4354
|
+
(acc, stakeName) => {
|
|
4355
|
+
acc[stakeName] = [];
|
|
4356
|
+
return acc;
|
|
4357
|
+
},
|
|
4358
|
+
{}
|
|
4359
|
+
);
|
|
4360
|
+
const stakeMarketCoinTypes = Object.keys(stakeAccounts).reduce(
|
|
4361
|
+
(types, stakeMarketCoinName) => {
|
|
4362
|
+
const stakeCoinName = utils.parseCoinName(stakeMarketCoinName);
|
|
4363
|
+
const marketCoinType = utils.parseMarketCoinType(stakeCoinName);
|
|
4364
|
+
types[stakeMarketCoinName] = `${spoolObjectId}::spool_account::SpoolAccount<${marketCoinType}>`;
|
|
4365
|
+
return types;
|
|
4366
|
+
},
|
|
4367
|
+
{}
|
|
4368
|
+
);
|
|
4369
|
+
const reversedStakeMarketCoinTypes = Object.entries(stakeMarketCoinTypes).reduce(
|
|
4370
|
+
(reversedTypes, [key, value]) => {
|
|
4371
|
+
reversedTypes[value] = key;
|
|
4372
|
+
return reversedTypes;
|
|
4373
|
+
},
|
|
4374
|
+
{}
|
|
4375
|
+
);
|
|
4376
|
+
for (const stakeObject of stakeObjectsResponse.map((ref) => ref.data)) {
|
|
4377
|
+
const id = stakeObject?.objectId;
|
|
4378
|
+
const type = stakeObject?.type;
|
|
4379
|
+
if (id && stakeObject?.content && "fields" in stakeObject.content) {
|
|
4380
|
+
const fields = stakeObject.content.fields;
|
|
4381
|
+
const stakePoolId = String(fields.spool_id);
|
|
4382
|
+
const stakeType = String(fields.stake_type.fields.name);
|
|
4383
|
+
const staked = Number(fields.stakes);
|
|
4384
|
+
const index = Number(fields.index);
|
|
4385
|
+
const points = Number(fields.points);
|
|
4386
|
+
const totalPoints = Number(fields.total_points);
|
|
4387
|
+
const stakeMarketCoinTypeMap = {
|
|
4388
|
+
sweth: stakeAccounts.sweth,
|
|
4389
|
+
ssui: stakeAccounts.ssui,
|
|
4390
|
+
swusdc: stakeAccounts.swusdc,
|
|
4391
|
+
swusdt: stakeAccounts.swusdt,
|
|
4392
|
+
scetus: stakeAccounts.scetus,
|
|
4393
|
+
safsui: stakeAccounts.safsui,
|
|
4394
|
+
shasui: stakeAccounts.shasui,
|
|
4395
|
+
svsui: stakeAccounts.svsui,
|
|
4396
|
+
susdc: stakeAccounts.susdc
|
|
4052
4397
|
};
|
|
4398
|
+
const normalizedType = (0, import_utils8.normalizeStructTag)(type);
|
|
4399
|
+
const stakeAccountArray = stakeMarketCoinTypeMap[reversedStakeMarketCoinTypes[normalizedType]];
|
|
4400
|
+
if (stakeAccountArray) {
|
|
4401
|
+
stakeAccountArray.push({
|
|
4402
|
+
id,
|
|
4403
|
+
type: normalizedType,
|
|
4404
|
+
stakePoolId,
|
|
4405
|
+
stakeType: (0, import_utils8.normalizeStructTag)(stakeType),
|
|
4406
|
+
staked,
|
|
4407
|
+
index,
|
|
4408
|
+
points,
|
|
4409
|
+
totalPoints
|
|
4410
|
+
});
|
|
4411
|
+
}
|
|
4053
4412
|
}
|
|
4054
4413
|
}
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
boostValue
|
|
4096
|
-
});
|
|
4097
|
-
}
|
|
4098
|
-
}
|
|
4099
|
-
}
|
|
4100
|
-
if (Object.keys(borrowIncentivePool.points).some((coinName2) => {
|
|
4101
|
-
const rewardApr = borrowIncentivePool.points[coinName2]?.rewardApr;
|
|
4102
|
-
return rewardApr !== Infinity && typeof rewardApr == "number" && rewardApr > 0;
|
|
4103
|
-
}) && borrowIncentiveAccount.debtAmount > 0) {
|
|
4104
|
-
totalRewardedPools++;
|
|
4105
|
-
}
|
|
4106
|
-
borrowIncentives[coinName] = {
|
|
4107
|
-
coinName: borrowIncentivePool.coinName,
|
|
4108
|
-
coinType: borrowIncentivePool.coinType,
|
|
4109
|
-
symbol: borrowIncentivePool.symbol,
|
|
4110
|
-
coinDecimal: borrowIncentivePool.coinDecimal,
|
|
4111
|
-
coinPrice: borrowIncentivePool.coinPrice,
|
|
4112
|
-
rewards
|
|
4414
|
+
return stakeAccounts;
|
|
4415
|
+
};
|
|
4416
|
+
var getStakePool = async ({
|
|
4417
|
+
utils
|
|
4418
|
+
}, marketCoinName) => {
|
|
4419
|
+
const poolId = utils.address.get(`spool.pools.${marketCoinName}.id`);
|
|
4420
|
+
let stakePool = void 0;
|
|
4421
|
+
const stakePoolObjectResponse = await utils.cache.queryGetObject(poolId, {
|
|
4422
|
+
showContent: true,
|
|
4423
|
+
showType: true
|
|
4424
|
+
});
|
|
4425
|
+
if (stakePoolObjectResponse?.data) {
|
|
4426
|
+
const stakePoolObject = stakePoolObjectResponse.data;
|
|
4427
|
+
const id = stakePoolObject.objectId;
|
|
4428
|
+
const type = stakePoolObject.type;
|
|
4429
|
+
if (stakePoolObject.content && "fields" in stakePoolObject.content) {
|
|
4430
|
+
const fields = stakePoolObject.content.fields;
|
|
4431
|
+
const maxPoint = Number(fields.max_distributed_point);
|
|
4432
|
+
const distributedPoint = Number(fields.distributed_point);
|
|
4433
|
+
const pointPerPeriod = Number(fields.distributed_point_per_period);
|
|
4434
|
+
const period = Number(fields.point_distribution_time);
|
|
4435
|
+
const maxStake = Number(fields.max_stakes);
|
|
4436
|
+
const stakeType = String(fields.stake_type.fields.name);
|
|
4437
|
+
const totalStaked = Number(fields.stakes);
|
|
4438
|
+
const index = Number(fields.index);
|
|
4439
|
+
const createdAt = Number(fields.created_at);
|
|
4440
|
+
const lastUpdate = Number(fields.last_update);
|
|
4441
|
+
stakePool = {
|
|
4442
|
+
id,
|
|
4443
|
+
type: (0, import_utils8.normalizeStructTag)(type),
|
|
4444
|
+
maxPoint,
|
|
4445
|
+
distributedPoint,
|
|
4446
|
+
pointPerPeriod,
|
|
4447
|
+
period,
|
|
4448
|
+
maxStake,
|
|
4449
|
+
stakeType: (0, import_utils8.normalizeStructTag)(stakeType),
|
|
4450
|
+
totalStaked,
|
|
4451
|
+
index,
|
|
4452
|
+
createdAt,
|
|
4453
|
+
lastUpdate
|
|
4113
4454
|
};
|
|
4114
4455
|
}
|
|
4115
4456
|
}
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
const
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
// Effective collateral value (the actual collateral value included in the calculation).
|
|
4131
|
-
totalBorrowCapacityValue: totalBorrowCapacityValue.toNumber(),
|
|
4132
|
-
// Available collateral value (the remaining collateral value that can be borrowed).
|
|
4133
|
-
totalAvailableCollateralValue: availableCollateralValue.toNumber(),
|
|
4134
|
-
// Available debt value (the actual borrowing value included in the calculation).
|
|
4135
|
-
totalBorrowedValueWithWeight: totalBorrowedValueWithWeight.toNumber(),
|
|
4136
|
-
// Required collateral value (avoid be liquidated).
|
|
4137
|
-
totalRequiredCollateralValue: requiredCollateralValue.toNumber(),
|
|
4138
|
-
// Unliquidated collateral value (pending liquidation).
|
|
4139
|
-
totalUnhealthyCollateralValue: unhealthyCollateralValue.toNumber(),
|
|
4140
|
-
totalRiskLevel: riskLevel.toNumber(),
|
|
4141
|
-
totalDepositedPools,
|
|
4142
|
-
totalBorrowedPools,
|
|
4143
|
-
totalRewardedPools,
|
|
4144
|
-
collaterals,
|
|
4145
|
-
debts,
|
|
4146
|
-
borrowIncentives
|
|
4147
|
-
};
|
|
4148
|
-
for (const [collateralCoinName, obligationCollateral] of Object.entries(
|
|
4149
|
-
obligationAccount.collaterals
|
|
4150
|
-
)) {
|
|
4151
|
-
const marketCollateral = market.collaterals[collateralCoinName];
|
|
4152
|
-
if (marketCollateral) {
|
|
4153
|
-
let estimatedAvailableWithdrawAmount = (0, import_bignumber4.default)(
|
|
4154
|
-
obligationAccount.totalAvailableCollateralValue
|
|
4155
|
-
).dividedBy(marketCollateral.collateralFactor).dividedBy(marketCollateral.coinPrice).shiftedBy(marketCollateral.coinDecimal);
|
|
4156
|
-
estimatedAvailableWithdrawAmount = obligationAccount.totalBorrowedValueWithWeight === 0 ? (
|
|
4157
|
-
// Note: when there is no debt record, there is no need to estimate and the deposited amount is directly used as available withdraw.
|
|
4158
|
-
(0, import_bignumber4.default)(obligationCollateral.depositedAmount)
|
|
4159
|
-
) : minBigNumber(
|
|
4160
|
-
estimatedAvailableWithdrawAmount.multipliedBy(
|
|
4161
|
-
estimatedFactor(
|
|
4162
|
-
(0, import_bignumber4.default)(obligationAccount.totalAvailableCollateralValue).dividedBy(marketCollateral.collateralFactor).toNumber(),
|
|
4163
|
-
3,
|
|
4164
|
-
"increase"
|
|
4165
|
-
)
|
|
4166
|
-
).toNumber(),
|
|
4167
|
-
obligationCollateral.depositedAmount,
|
|
4168
|
-
marketCollateral.depositAmount
|
|
4169
|
-
);
|
|
4170
|
-
obligationCollateral.availableWithdrawAmount = estimatedAvailableWithdrawAmount.toNumber();
|
|
4171
|
-
obligationCollateral.availableWithdrawCoin = estimatedAvailableWithdrawAmount.shiftedBy(-1 * obligationCollateral.coinDecimal).toNumber();
|
|
4457
|
+
return stakePool;
|
|
4458
|
+
};
|
|
4459
|
+
var getStakeRewardPool = async ({
|
|
4460
|
+
utils
|
|
4461
|
+
}, marketCoinName) => {
|
|
4462
|
+
const poolId = utils.address.get(
|
|
4463
|
+
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
4464
|
+
);
|
|
4465
|
+
let stakeRewardPool = void 0;
|
|
4466
|
+
const stakeRewardPoolObjectResponse = await utils.cache.queryGetObject(
|
|
4467
|
+
poolId,
|
|
4468
|
+
{
|
|
4469
|
+
showContent: true,
|
|
4470
|
+
showType: true
|
|
4172
4471
|
}
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
const
|
|
4178
|
-
if (
|
|
4179
|
-
const
|
|
4180
|
-
|
|
4181
|
-
)
|
|
4182
|
-
|
|
4472
|
+
);
|
|
4473
|
+
if (stakeRewardPoolObjectResponse?.data) {
|
|
4474
|
+
const stakeRewardPoolObject = stakeRewardPoolObjectResponse.data;
|
|
4475
|
+
const id = stakeRewardPoolObject.objectId;
|
|
4476
|
+
const type = stakeRewardPoolObject.type;
|
|
4477
|
+
if (stakeRewardPoolObject.content && "fields" in stakeRewardPoolObject.content) {
|
|
4478
|
+
const rewardPoolFields = stakeRewardPoolObject.content.fields;
|
|
4479
|
+
const stakePoolId = String(rewardPoolFields.spool_id);
|
|
4480
|
+
const ratioNumerator = Number(rewardPoolFields.exchange_rate_numerator);
|
|
4481
|
+
const ratioDenominator = Number(
|
|
4482
|
+
rewardPoolFields.exchange_rate_denominator
|
|
4183
4483
|
);
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
marketPool.supplyAmount
|
|
4196
|
-
) : (0, import_bignumber4.default)(0);
|
|
4197
|
-
obligationDebt.availableBorrowAmount = estimatedAvailableBorrowAmount.toNumber();
|
|
4198
|
-
obligationDebt.availableBorrowCoin = estimatedAvailableBorrowAmount.shiftedBy(-1 * obligationDebt.coinDecimal).toNumber();
|
|
4199
|
-
obligationDebt.requiredRepayAmount = estimatedRequiredRepayAmount.toNumber();
|
|
4200
|
-
obligationDebt.requiredRepayCoin = estimatedRequiredRepayAmount.shiftedBy(-1 * obligationDebt.coinDecimal).toNumber();
|
|
4484
|
+
const rewards = Number(rewardPoolFields.rewards);
|
|
4485
|
+
const claimedRewards = Number(rewardPoolFields.claimed_rewards);
|
|
4486
|
+
stakeRewardPool = {
|
|
4487
|
+
id,
|
|
4488
|
+
type: (0, import_utils8.normalizeStructTag)(type),
|
|
4489
|
+
stakePoolId,
|
|
4490
|
+
ratioNumerator,
|
|
4491
|
+
ratioDenominator,
|
|
4492
|
+
rewards,
|
|
4493
|
+
claimedRewards
|
|
4494
|
+
};
|
|
4201
4495
|
}
|
|
4202
4496
|
}
|
|
4203
|
-
return
|
|
4204
|
-
};
|
|
4205
|
-
var getTotalValueLocked = async (query, indexer = false) => {
|
|
4206
|
-
const market = await query.queryMarket(indexer);
|
|
4207
|
-
let supplyValue = (0, import_bignumber4.default)(0);
|
|
4208
|
-
let borrowValue = (0, import_bignumber4.default)(0);
|
|
4209
|
-
if (indexer) {
|
|
4210
|
-
const tvlIndexer = await query.indexer.getTotalValueLocked();
|
|
4211
|
-
const tvl2 = {
|
|
4212
|
-
supplyValue: tvlIndexer.supplyValue,
|
|
4213
|
-
supplyValueChangeRatio: tvlIndexer.supplyValueChangeRatio,
|
|
4214
|
-
borrowValue: tvlIndexer.borrowValue,
|
|
4215
|
-
borrowValueChangeRatio: tvlIndexer.borrowValueChangeRatio,
|
|
4216
|
-
totalValue: tvlIndexer.totalValue,
|
|
4217
|
-
totalValueChangeRatio: tvlIndexer.totalValueChangeRatio
|
|
4218
|
-
};
|
|
4219
|
-
return tvl2;
|
|
4220
|
-
}
|
|
4221
|
-
for (const pool of Object.values(market.pools)) {
|
|
4222
|
-
supplyValue = supplyValue.plus(
|
|
4223
|
-
(0, import_bignumber4.default)(pool.supplyCoin).multipliedBy(pool.coinPrice)
|
|
4224
|
-
);
|
|
4225
|
-
borrowValue = borrowValue.plus(
|
|
4226
|
-
(0, import_bignumber4.default)(pool.borrowCoin).multipliedBy(pool.coinPrice)
|
|
4227
|
-
);
|
|
4228
|
-
}
|
|
4229
|
-
for (const collateral of Object.values(market.collaterals)) {
|
|
4230
|
-
supplyValue = supplyValue.plus(
|
|
4231
|
-
(0, import_bignumber4.default)(collateral.depositCoin).multipliedBy(collateral.coinPrice)
|
|
4232
|
-
);
|
|
4233
|
-
}
|
|
4234
|
-
const tvl = {
|
|
4235
|
-
supplyValue: supplyValue.toNumber(),
|
|
4236
|
-
borrowValue: borrowValue.toNumber(),
|
|
4237
|
-
totalValue: supplyValue.minus(borrowValue).toNumber()
|
|
4238
|
-
};
|
|
4239
|
-
return tvl;
|
|
4497
|
+
return stakeRewardPool;
|
|
4240
4498
|
};
|
|
4241
4499
|
|
|
4242
4500
|
// src/queries/vescaQuery.ts
|
|
4243
|
-
var
|
|
4501
|
+
var import_bignumber7 = __toESM(require("bignumber.js"));
|
|
4244
4502
|
var import_sui_kit3 = require("@scallop-io/sui-kit");
|
|
4245
|
-
var
|
|
4246
|
-
var
|
|
4247
|
-
var
|
|
4503
|
+
var import_bcs2 = require("@mysten/sui/bcs");
|
|
4504
|
+
var import_zod4 = require("zod");
|
|
4505
|
+
var import_assert2 = __toESM(require("assert"));
|
|
4248
4506
|
var getVescaKeys = async (utils, ownerAddress) => {
|
|
4249
4507
|
const owner = ownerAddress || utils.suiKit.currentAddress();
|
|
4250
4508
|
const veScaObjId = utils.address.get("vesca.object");
|
|
@@ -4292,10 +4550,10 @@ var getVeScas = async ({
|
|
|
4292
4550
|
}
|
|
4293
4551
|
return result;
|
|
4294
4552
|
};
|
|
4295
|
-
var SuiObjectRefZod =
|
|
4296
|
-
objectId:
|
|
4297
|
-
digest:
|
|
4298
|
-
version:
|
|
4553
|
+
var SuiObjectRefZod = import_zod4.z.object({
|
|
4554
|
+
objectId: import_zod4.z.string(),
|
|
4555
|
+
digest: import_zod4.z.string(),
|
|
4556
|
+
version: import_zod4.z.string()
|
|
4299
4557
|
});
|
|
4300
4558
|
var getVeSca = async (utils, veScaKey) => {
|
|
4301
4559
|
const tableId = utils.address.get(`vesca.tableId`);
|
|
@@ -4322,7 +4580,7 @@ var getVeSca = async (utils, veScaKey) => {
|
|
|
4322
4580
|
0
|
|
4323
4581
|
);
|
|
4324
4582
|
const lockedScaAmount = String(dynamicFields.locked_sca_amount);
|
|
4325
|
-
const lockedScaCoin = (0,
|
|
4583
|
+
const lockedScaCoin = (0, import_bignumber7.default)(dynamicFields.locked_sca_amount).shiftedBy(-9).toNumber();
|
|
4326
4584
|
const currentVeScaBalance = lockedScaCoin * (Math.floor(remainingLockPeriodInMilliseconds / 1e3) / MAX_LOCK_DURATION);
|
|
4327
4585
|
vesca = {
|
|
4328
4586
|
id: veScaDynamicFieldObject.objectId,
|
|
@@ -4332,7 +4590,7 @@ var getVeSca = async (utils, veScaKey) => {
|
|
|
4332
4590
|
lockedScaAmount,
|
|
4333
4591
|
lockedScaCoin,
|
|
4334
4592
|
currentVeScaBalance,
|
|
4335
|
-
unlockAt: (0,
|
|
4593
|
+
unlockAt: (0, import_bignumber7.default)(dynamicFields.unlock_at * 1e3).toNumber()
|
|
4336
4594
|
};
|
|
4337
4595
|
}
|
|
4338
4596
|
return vesca;
|
|
@@ -4381,8 +4639,8 @@ var getTotalVeScaTreasuryAmount = async (utils, veScaTreasury) => {
|
|
|
4381
4639
|
if (results && results[1]?.returnValues) {
|
|
4382
4640
|
const value = Uint8Array.from(results[1].returnValues[0][0]);
|
|
4383
4641
|
const type = results[1].returnValues[0][1];
|
|
4384
|
-
(0,
|
|
4385
|
-
return
|
|
4642
|
+
(0, import_assert2.default)(type === "u64", "Result type is not u64");
|
|
4643
|
+
return import_bcs2.bcs.u64().parse(value);
|
|
4386
4644
|
}
|
|
4387
4645
|
return "0";
|
|
4388
4646
|
};
|
|
@@ -4394,10 +4652,10 @@ var getVeScaTreasuryInfo = async (utils) => {
|
|
|
4394
4652
|
if (!veScaTreasury || veScaTreasury.data?.content?.dataType !== "moveObject")
|
|
4395
4653
|
return null;
|
|
4396
4654
|
const treasuryFields = veScaTreasury.data.content.fields;
|
|
4397
|
-
const totalLockedSca = (0,
|
|
4655
|
+
const totalLockedSca = (0, import_bignumber7.default)(
|
|
4398
4656
|
treasuryFields.unlock_schedule.fields.locked_sca_amount
|
|
4399
4657
|
).shiftedBy(-9).toNumber();
|
|
4400
|
-
const totalVeSca = (0,
|
|
4658
|
+
const totalVeSca = (0, import_bignumber7.default)(
|
|
4401
4659
|
await getTotalVeScaTreasuryAmount(utils, veScaTreasury.data) ?? 0
|
|
4402
4660
|
).shiftedBy(-9).toNumber();
|
|
4403
4661
|
const averageLockingPeriod = totalLockedSca > 0 ? totalVeSca / totalLockedSca * 4 : 0;
|
|
@@ -4410,94 +4668,8 @@ var getVeScaTreasuryInfo = async (utils) => {
|
|
|
4410
4668
|
};
|
|
4411
4669
|
};
|
|
4412
4670
|
|
|
4413
|
-
// src/queries/referralQuery.ts
|
|
4414
|
-
var queryVeScaKeyIdFromReferralBindings = async (address, refereeAddress) => {
|
|
4415
|
-
const referralBindingTableId = address.get("referral.bindingTableId");
|
|
4416
|
-
const referralBindResponse = await address.cache.queryGetDynamicFieldObject({
|
|
4417
|
-
parentId: referralBindingTableId,
|
|
4418
|
-
name: {
|
|
4419
|
-
type: "address",
|
|
4420
|
-
value: refereeAddress
|
|
4421
|
-
}
|
|
4422
|
-
});
|
|
4423
|
-
if (referralBindResponse?.data?.content?.dataType !== "moveObject")
|
|
4424
|
-
return null;
|
|
4425
|
-
const fields = referralBindResponse.data.content.fields;
|
|
4426
|
-
return fields.value;
|
|
4427
|
-
};
|
|
4428
|
-
|
|
4429
|
-
// src/queries/loyaltyProgramQuery.ts
|
|
4430
|
-
var import_bignumber6 = __toESM(require("bignumber.js"));
|
|
4431
|
-
var import_zod3 = require("zod");
|
|
4432
|
-
var rewardPoolFieldsZod = import_zod3.z.object({
|
|
4433
|
-
balance: import_zod3.z.string(),
|
|
4434
|
-
enable_claim: import_zod3.z.boolean()
|
|
4435
|
-
}).transform((value) => ({
|
|
4436
|
-
totalPoolReward: (0, import_bignumber6.default)(value.balance).shiftedBy(-9).toNumber(),
|
|
4437
|
-
isClaimEnabled: value.enable_claim
|
|
4438
|
-
}));
|
|
4439
|
-
var userRewardFieldsZod = import_zod3.z.object({
|
|
4440
|
-
value: import_zod3.z.string()
|
|
4441
|
-
}).transform((value) => (0, import_bignumber6.default)(value.value).shiftedBy(-9).toNumber());
|
|
4442
|
-
var getLoyaltyProgramInformations = async (query, veScaKey) => {
|
|
4443
|
-
const rewardPool = query.address.get("loyaltyProgram.rewardPool");
|
|
4444
|
-
const rewardPoolObject = await query.cache.queryGetObject(rewardPool, {
|
|
4445
|
-
showContent: true
|
|
4446
|
-
});
|
|
4447
|
-
if (rewardPoolObject?.data?.content?.dataType !== "moveObject")
|
|
4448
|
-
return null;
|
|
4449
|
-
const rewardPoolFields = rewardPoolObject.data.content.fields;
|
|
4450
|
-
const { isClaimEnabled, totalPoolReward } = rewardPoolFieldsZod.parse(
|
|
4451
|
-
rewardPoolFields
|
|
4452
|
-
);
|
|
4453
|
-
const result = {
|
|
4454
|
-
pendingReward: 0,
|
|
4455
|
-
totalPoolReward,
|
|
4456
|
-
isClaimEnabled
|
|
4457
|
-
};
|
|
4458
|
-
veScaKey = veScaKey ?? (await query.getVeScas())[0]?.keyObject;
|
|
4459
|
-
if (!veScaKey)
|
|
4460
|
-
return result;
|
|
4461
|
-
const userRewardTableId = query.address.get(
|
|
4462
|
-
"loyaltyProgram.userRewardTableId"
|
|
4463
|
-
);
|
|
4464
|
-
const userRewardObject = await query.cache.queryGetDynamicFieldObject({
|
|
4465
|
-
parentId: userRewardTableId,
|
|
4466
|
-
name: {
|
|
4467
|
-
type: "0x2::object::ID",
|
|
4468
|
-
value: typeof veScaKey === "string" ? veScaKey : veScaKey.objectId
|
|
4469
|
-
}
|
|
4470
|
-
});
|
|
4471
|
-
if (userRewardObject?.data?.content?.dataType !== "moveObject")
|
|
4472
|
-
return result;
|
|
4473
|
-
const userRewardFields = userRewardObject.data.content.fields;
|
|
4474
|
-
result.pendingReward = userRewardFieldsZod.parse(
|
|
4475
|
-
userRewardFields
|
|
4476
|
-
);
|
|
4477
|
-
return result;
|
|
4478
|
-
};
|
|
4479
|
-
|
|
4480
4671
|
// src/models/suiKit.ts
|
|
4481
4672
|
var import_sui_kit4 = require("@scallop-io/sui-kit");
|
|
4482
|
-
|
|
4483
|
-
// src/constants/rpc.ts
|
|
4484
|
-
var import_client = require("@mysten/sui/client");
|
|
4485
|
-
var RPC_PROVIDERS = [
|
|
4486
|
-
(0, import_client.getFullnodeUrl)("mainnet"),
|
|
4487
|
-
"https://sui-mainnet.public.blastapi.io",
|
|
4488
|
-
"https://sui-mainnet-ca-2.cosmostation.io",
|
|
4489
|
-
"https://sui-mainnet-eu-4.cosmostation.io",
|
|
4490
|
-
"https://sui-mainnet-endpoint.blockvision.org",
|
|
4491
|
-
"https://sui-rpc.publicnode.com",
|
|
4492
|
-
"https://sui-mainnet-rpc.allthatnode.com",
|
|
4493
|
-
"https://mainnet.suiet.app",
|
|
4494
|
-
"https://mainnet.sui.rpcpool.com",
|
|
4495
|
-
"https://sui1mainnet-rpc.chainode.tech",
|
|
4496
|
-
"https://fullnode.mainnet.apis.scallop.io",
|
|
4497
|
-
"https://sui-mainnet-us-2.cosmostation.io"
|
|
4498
|
-
];
|
|
4499
|
-
|
|
4500
|
-
// src/models/suiKit.ts
|
|
4501
4673
|
var newSuiKit = (params) => {
|
|
4502
4674
|
return new import_sui_kit4.SuiKit({
|
|
4503
4675
|
...params,
|
|
@@ -6754,183 +6926,8 @@ var ScallopIndexer = class {
|
|
|
6754
6926
|
}
|
|
6755
6927
|
};
|
|
6756
6928
|
|
|
6757
|
-
// src/queries/sCoinQuery.ts
|
|
6758
|
-
var import_bcs2 = require("@mysten/sui/bcs");
|
|
6759
|
-
var import_assert2 = __toESM(require("assert"));
|
|
6760
|
-
var import_bignumber7 = __toESM(require("bignumber.js"));
|
|
6761
|
-
var getSCoinTotalSupply = async ({
|
|
6762
|
-
utils
|
|
6763
|
-
}, sCoinName) => {
|
|
6764
|
-
const sCoinPkgId = utils.address.get("scoin.id");
|
|
6765
|
-
const args = [utils.getSCoinTreasury(sCoinName)];
|
|
6766
|
-
const typeArgs = [
|
|
6767
|
-
utils.parseSCoinType(sCoinName),
|
|
6768
|
-
utils.parseUnderlyingSCoinType(sCoinName)
|
|
6769
|
-
];
|
|
6770
|
-
const queryTarget = `${sCoinPkgId}::s_coin_converter::total_supply`;
|
|
6771
|
-
const queryResults = await utils.cache.queryInspectTxn({
|
|
6772
|
-
queryTarget,
|
|
6773
|
-
args,
|
|
6774
|
-
typeArgs
|
|
6775
|
-
});
|
|
6776
|
-
const results = queryResults?.results;
|
|
6777
|
-
if (results && results[0]?.returnValues) {
|
|
6778
|
-
const value = Uint8Array.from(results[0].returnValues[0][0]);
|
|
6779
|
-
const type = results[0].returnValues[0][1];
|
|
6780
|
-
(0, import_assert2.default)(type === "u64", "Result type is not u64");
|
|
6781
|
-
return (0, import_bignumber7.default)(import_bcs2.bcs.u64().parse(value)).shiftedBy(utils.getCoinDecimal(utils.parseCoinName(sCoinName))).toNumber();
|
|
6782
|
-
}
|
|
6783
|
-
return 0;
|
|
6784
|
-
};
|
|
6785
|
-
var getSCoinAmounts = async ({
|
|
6786
|
-
utils
|
|
6787
|
-
}, sCoinNames = [...SUPPORT_SCOIN], ownerAddress) => {
|
|
6788
|
-
const owner = ownerAddress || utils.suiKit.currentAddress();
|
|
6789
|
-
const sCoins2 = {};
|
|
6790
|
-
await Promise.allSettled(
|
|
6791
|
-
sCoinNames.map(async (sCoinName) => {
|
|
6792
|
-
const sCoin = await getSCoinAmount({ utils }, sCoinName, owner);
|
|
6793
|
-
sCoins2[sCoinName] = sCoin;
|
|
6794
|
-
})
|
|
6795
|
-
);
|
|
6796
|
-
return sCoins2;
|
|
6797
|
-
};
|
|
6798
|
-
var getSCoinAmount = async ({
|
|
6799
|
-
utils
|
|
6800
|
-
}, sCoinName, ownerAddress) => {
|
|
6801
|
-
const owner = ownerAddress || utils.suiKit.currentAddress();
|
|
6802
|
-
const sCoinType = utils.parseSCoinType(sCoinName);
|
|
6803
|
-
const amount = await utils.cache.queryGetCoinBalance({
|
|
6804
|
-
owner,
|
|
6805
|
-
coinType: sCoinType
|
|
6806
|
-
});
|
|
6807
|
-
return (0, import_bignumber7.default)(amount).toNumber();
|
|
6808
|
-
};
|
|
6809
|
-
var isSupportStakeCoins = (value) => {
|
|
6810
|
-
return SUPPORT_SCOIN.includes(value);
|
|
6811
|
-
};
|
|
6812
|
-
var checkAssetParams = (fromSCoin, toSCoin) => {
|
|
6813
|
-
if (fromSCoin === toSCoin)
|
|
6814
|
-
throw new Error("fromAsset and toAsset must be different");
|
|
6815
|
-
if (!isSupportStakeCoins(fromSCoin))
|
|
6816
|
-
throw new Error("fromAsset is not supported");
|
|
6817
|
-
if (!isSupportStakeCoins(toSCoin)) {
|
|
6818
|
-
throw new Error("toAsset is not supported");
|
|
6819
|
-
}
|
|
6820
|
-
};
|
|
6821
|
-
var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) => {
|
|
6822
|
-
checkAssetParams(fromSCoin, toSCoin);
|
|
6823
|
-
const fromCoinName = query.utils.parseCoinName(fromSCoin);
|
|
6824
|
-
const toCoinName = query.utils.parseCoinName(toSCoin);
|
|
6825
|
-
const marketPools = await Promise.all([
|
|
6826
|
-
query.getMarketPool(fromCoinName, false),
|
|
6827
|
-
query.getMarketPool(toCoinName, false)
|
|
6828
|
-
]);
|
|
6829
|
-
if (marketPools.some((pool) => !pool))
|
|
6830
|
-
throw new Error("Failed to fetch the lendings data");
|
|
6831
|
-
if (marketPools.some((pool) => pool?.conversionRate === 0)) {
|
|
6832
|
-
throw new Error("Conversion rate cannot be zero");
|
|
6833
|
-
}
|
|
6834
|
-
const ScoinAToARate = marketPools[0].conversionRate;
|
|
6835
|
-
const BtoSCoinBRate = 1 / marketPools[1].conversionRate;
|
|
6836
|
-
const calcAtoBRate = async () => {
|
|
6837
|
-
const prices = await query.utils.getCoinPrices([fromCoinName, toCoinName]);
|
|
6838
|
-
if (!prices[fromCoinName] || !prices[toCoinName]) {
|
|
6839
|
-
throw new Error("Failed to fetch the coin prices");
|
|
6840
|
-
}
|
|
6841
|
-
if (prices[toCoinName] === 0) {
|
|
6842
|
-
throw new Error("Price of toCoin cannot be zero");
|
|
6843
|
-
}
|
|
6844
|
-
return prices[fromCoinName] / prices[toCoinName];
|
|
6845
|
-
};
|
|
6846
|
-
const AtoBRate = underlyingCoinPrice ?? await calcAtoBRate();
|
|
6847
|
-
return (0, import_bignumber7.default)(ScoinAToARate).multipliedBy(AtoBRate).multipliedBy(BtoSCoinBRate).toNumber();
|
|
6848
|
-
};
|
|
6849
|
-
|
|
6850
6929
|
// src/models/scallopQuery.ts
|
|
6851
6930
|
var import_utils23 = require("@mysten/sui/utils");
|
|
6852
|
-
|
|
6853
|
-
// src/queries/isolatedAsset.ts
|
|
6854
|
-
var import_zod4 = require("zod");
|
|
6855
|
-
var isolatedAssetZod = import_zod4.z.object({
|
|
6856
|
-
dataType: import_zod4.z.string(),
|
|
6857
|
-
type: import_zod4.z.string(),
|
|
6858
|
-
hasPublicTransfer: import_zod4.z.boolean(),
|
|
6859
|
-
fields: import_zod4.z.object({
|
|
6860
|
-
id: import_zod4.z.object({
|
|
6861
|
-
id: import_zod4.z.string()
|
|
6862
|
-
}),
|
|
6863
|
-
name: import_zod4.z.object({
|
|
6864
|
-
type: import_zod4.z.string()
|
|
6865
|
-
}),
|
|
6866
|
-
value: import_zod4.z.boolean()
|
|
6867
|
-
})
|
|
6868
|
-
});
|
|
6869
|
-
var ISOLATED_ASSET_KEY = "0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::IsolatedAssetKey";
|
|
6870
|
-
var getIsolatedAssets = async (address) => {
|
|
6871
|
-
try {
|
|
6872
|
-
const marketObject = address.get("core.market");
|
|
6873
|
-
const isolatedAssets = [];
|
|
6874
|
-
if (!marketObject)
|
|
6875
|
-
return isolatedAssets;
|
|
6876
|
-
let hasNextPage = false;
|
|
6877
|
-
let nextCursor = null;
|
|
6878
|
-
const isIsolatedDynamicField = (dynamicField) => {
|
|
6879
|
-
return dynamicField.name.type === ISOLATED_ASSET_KEY;
|
|
6880
|
-
};
|
|
6881
|
-
do {
|
|
6882
|
-
const response = await address.cache.queryGetDynamicFields({
|
|
6883
|
-
parentId: marketObject,
|
|
6884
|
-
cursor: nextCursor,
|
|
6885
|
-
limit: 10
|
|
6886
|
-
});
|
|
6887
|
-
if (!response)
|
|
6888
|
-
break;
|
|
6889
|
-
const isolatedAssetCoinTypes = response.data.filter(isIsolatedDynamicField).map(({ name }) => `0x${name.value.type.name}`);
|
|
6890
|
-
isolatedAssets.push(...isolatedAssetCoinTypes);
|
|
6891
|
-
if (response && response.hasNextPage && response.nextCursor) {
|
|
6892
|
-
hasNextPage = true;
|
|
6893
|
-
nextCursor = response.nextCursor;
|
|
6894
|
-
} else {
|
|
6895
|
-
hasNextPage = false;
|
|
6896
|
-
}
|
|
6897
|
-
} while (hasNextPage);
|
|
6898
|
-
return isolatedAssets;
|
|
6899
|
-
} catch (e) {
|
|
6900
|
-
console.error(e);
|
|
6901
|
-
return [];
|
|
6902
|
-
}
|
|
6903
|
-
};
|
|
6904
|
-
var isIsolatedAsset = async (utils, coinName) => {
|
|
6905
|
-
try {
|
|
6906
|
-
const marketObject = utils.address.get("core.market");
|
|
6907
|
-
const cachedData = utils.address.cache.queryClient.getQueryData([
|
|
6908
|
-
"getDynamicFields",
|
|
6909
|
-
marketObject
|
|
6910
|
-
]);
|
|
6911
|
-
if (cachedData) {
|
|
6912
|
-
const coinType2 = utils.parseCoinType(coinName);
|
|
6913
|
-
return cachedData.includes(coinType2);
|
|
6914
|
-
}
|
|
6915
|
-
const coinType = utils.parseCoinType(coinName).slice(2);
|
|
6916
|
-
const object = await utils.cache.queryGetDynamicFieldObject({
|
|
6917
|
-
parentId: marketObject,
|
|
6918
|
-
name: {
|
|
6919
|
-
type: ISOLATED_ASSET_KEY,
|
|
6920
|
-
value: coinType
|
|
6921
|
-
}
|
|
6922
|
-
});
|
|
6923
|
-
const parsedData = isolatedAssetZod.safeParse(object?.data?.content);
|
|
6924
|
-
if (!parsedData.success)
|
|
6925
|
-
return false;
|
|
6926
|
-
return parsedData.data.fields.value;
|
|
6927
|
-
} catch (e) {
|
|
6928
|
-
console.error(e);
|
|
6929
|
-
return false;
|
|
6930
|
-
}
|
|
6931
|
-
};
|
|
6932
|
-
|
|
6933
|
-
// src/models/scallopQuery.ts
|
|
6934
6931
|
var ScallopQuery = class {
|
|
6935
6932
|
constructor(params, instance) {
|
|
6936
6933
|
this.params = params;
|
|
@@ -8447,6 +8444,7 @@ var Scallop = class {
|
|
|
8447
8444
|
PROTOCOL_OBJECT_ID,
|
|
8448
8445
|
PYTH_ENDPOINTS,
|
|
8449
8446
|
PYTH_FEED_IDS,
|
|
8447
|
+
RPC_PROVIDERS,
|
|
8450
8448
|
SCA_COIN_TYPE,
|
|
8451
8449
|
SDK_API_BASE_URL,
|
|
8452
8450
|
SUPPORT_BORROW_INCENTIVE_POOLS,
|