@scallop-io/sui-scallop-sdk 1.3.41 → 1.4.0
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/constants/tokenBucket.d.ts +1 -1
- package/dist/index.js +194 -186
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +194 -186
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopQuery.d.ts +34 -14
- package/package.json +1 -1
- package/src/constants/tokenBucket.ts +1 -1
- package/src/models/scallopQuery.ts +38 -31
- package/src/queries/coreQuery.ts +184 -189
- package/src/queries/portfolioQuery.ts +17 -16
- package/src/queries/sCoinQuery.ts +2 -2
- package/src/queries/spoolQuery.ts +2 -2
- package/src/utils/indexer.ts +9 -3
- package/src/utils/tokenBucket.ts +2 -2
package/dist/index.mjs
CHANGED
|
@@ -952,7 +952,7 @@ var TEST_ADDRESSES = {
|
|
|
952
952
|
|
|
953
953
|
// src/constants/tokenBucket.ts
|
|
954
954
|
var DEFAULT_TOKENS_PER_INTERVAL = 50;
|
|
955
|
-
var DEFAULT_INTERVAL_IN_MS =
|
|
955
|
+
var DEFAULT_INTERVAL_IN_MS = 100;
|
|
956
956
|
|
|
957
957
|
// src/constants/vesca.ts
|
|
958
958
|
var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
|
|
@@ -1556,7 +1556,7 @@ var TokenBucket = class {
|
|
|
1556
1556
|
return false;
|
|
1557
1557
|
}
|
|
1558
1558
|
};
|
|
1559
|
-
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries =
|
|
1559
|
+
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 15, backoffFactor = 2) => {
|
|
1560
1560
|
let retries = 0;
|
|
1561
1561
|
const tryRequest = async () => {
|
|
1562
1562
|
if (tokenBucket.removeTokens(1)) {
|
|
@@ -1592,13 +1592,19 @@ var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVA
|
|
|
1592
1592
|
|
|
1593
1593
|
// src/utils/indexer.ts
|
|
1594
1594
|
async function callMethodWithIndexerFallback(method, context, ...args) {
|
|
1595
|
-
const
|
|
1596
|
-
if (indexer) {
|
|
1595
|
+
const lastArgs = args[args.length - 1];
|
|
1596
|
+
if (typeof lastArgs === "object" && lastArgs.indexer) {
|
|
1597
1597
|
try {
|
|
1598
1598
|
return await method.apply(context, args);
|
|
1599
1599
|
} catch (e) {
|
|
1600
1600
|
console.warn(`Indexer requests failed: ${e}. Retrying without indexer..`);
|
|
1601
|
-
return await method.apply(context, [
|
|
1601
|
+
return await method.apply(context, [
|
|
1602
|
+
...args.slice(0, -1),
|
|
1603
|
+
{
|
|
1604
|
+
...lastArgs,
|
|
1605
|
+
indexer: false
|
|
1606
|
+
}
|
|
1607
|
+
]);
|
|
1602
1608
|
}
|
|
1603
1609
|
}
|
|
1604
1610
|
return await method.apply(context, args);
|
|
@@ -2971,150 +2977,146 @@ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer =
|
|
|
2971
2977
|
return marketPools;
|
|
2972
2978
|
};
|
|
2973
2979
|
var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, coinPrice) => {
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
+
coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
2981
|
+
if (indexer) {
|
|
2982
|
+
const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
|
|
2983
|
+
if (!marketPoolIndexer) {
|
|
2984
|
+
return void 0;
|
|
2985
|
+
}
|
|
2986
|
+
marketPoolIndexer.coinPrice = coinPrice ?? marketPoolIndexer.coinPrice;
|
|
2987
|
+
marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
2988
|
+
marketPoolIndexer.coinName
|
|
2989
|
+
);
|
|
2990
|
+
return marketPoolIndexer;
|
|
2991
|
+
}
|
|
2992
|
+
const marketId = query.address.get("core.market");
|
|
2993
|
+
marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
|
|
2994
|
+
showContent: true
|
|
2995
|
+
}))?.data;
|
|
2996
|
+
if (!(marketObject && marketObject.content?.dataType === "moveObject"))
|
|
2997
|
+
throw new Error(`Failed to fetch marketObject`);
|
|
2998
|
+
const fields = marketObject.content.fields;
|
|
2999
|
+
const coinType = query.utils.parseCoinType(poolCoinName);
|
|
3000
|
+
const balanceSheetParentId = fields.vault.fields.balance_sheets.fields.table.fields.id.id;
|
|
3001
|
+
const balanceSheetDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3002
|
+
parentId: balanceSheetParentId,
|
|
3003
|
+
name: {
|
|
3004
|
+
type: "0x1::type_name::TypeName",
|
|
3005
|
+
value: {
|
|
3006
|
+
name: coinType.substring(2)
|
|
2980
3007
|
}
|
|
2981
|
-
marketPoolIndexer.coinPrice = coinPrice ?? marketPoolIndexer.coinPrice;
|
|
2982
|
-
marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
2983
|
-
marketPoolIndexer.coinName
|
|
2984
|
-
);
|
|
2985
|
-
return marketPoolIndexer;
|
|
2986
3008
|
}
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
name: coinType.substring(2)
|
|
3002
|
-
}
|
|
3009
|
+
});
|
|
3010
|
+
const balanceSheetDynamicFieldObject = balanceSheetDynamicFieldObjectResponse?.data;
|
|
3011
|
+
if (!(balanceSheetDynamicFieldObject && balanceSheetDynamicFieldObject.content && "fields" in balanceSheetDynamicFieldObject.content))
|
|
3012
|
+
throw new Error(
|
|
3013
|
+
`Failed to fetch balanceSheetDynamicFieldObject for ${poolCoinName}: ${balanceSheetDynamicFieldObjectResponse?.error?.code.toString()}`
|
|
3014
|
+
);
|
|
3015
|
+
const balanceSheet = balanceSheetDynamicFieldObject.content.fields.value.fields;
|
|
3016
|
+
const borrowIndexParentId = fields.borrow_dynamics.fields.table.fields.id.id;
|
|
3017
|
+
const borrowIndexDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3018
|
+
parentId: borrowIndexParentId,
|
|
3019
|
+
name: {
|
|
3020
|
+
type: "0x1::type_name::TypeName",
|
|
3021
|
+
value: {
|
|
3022
|
+
name: coinType.substring(2)
|
|
3003
3023
|
}
|
|
3004
|
-
}
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3024
|
+
}
|
|
3025
|
+
});
|
|
3026
|
+
const borrowIndexDynamicFieldObject = borrowIndexDynamicFieldObjectResponse?.data;
|
|
3027
|
+
if (!(borrowIndexDynamicFieldObject && borrowIndexDynamicFieldObject.content && "fields" in borrowIndexDynamicFieldObject.content))
|
|
3028
|
+
throw new Error(
|
|
3029
|
+
`Failed to fetch borrowIndexDynamicFieldObject for ${poolCoinName}`
|
|
3030
|
+
);
|
|
3031
|
+
const borrowIndex = borrowIndexDynamicFieldObject.content.fields.value.fields;
|
|
3032
|
+
const interestModelParentId = fields.interest_models.fields.table.fields.id.id;
|
|
3033
|
+
const interestModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3034
|
+
parentId: interestModelParentId,
|
|
3035
|
+
name: {
|
|
3036
|
+
type: "0x1::type_name::TypeName",
|
|
3037
|
+
value: {
|
|
3038
|
+
name: coinType.substring(2)
|
|
3019
3039
|
}
|
|
3020
|
-
}
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3040
|
+
}
|
|
3041
|
+
});
|
|
3042
|
+
const interestModelDynamicFieldObject = interestModelDynamicFieldObjectResponse?.data;
|
|
3043
|
+
if (!(interestModelDynamicFieldObject && interestModelDynamicFieldObject.content && "fields" in interestModelDynamicFieldObject.content))
|
|
3044
|
+
throw new Error(
|
|
3045
|
+
`Failed to fetch interestModelDynamicFieldObject for ${poolCoinName}: ${interestModelDynamicFieldObject}`
|
|
3046
|
+
);
|
|
3047
|
+
const interestModel = interestModelDynamicFieldObject.content.fields.value.fields;
|
|
3048
|
+
const getBorrowFee = async () => {
|
|
3049
|
+
const borrowFeeDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3050
|
+
parentId: marketId,
|
|
3030
3051
|
name: {
|
|
3031
|
-
type:
|
|
3052
|
+
type: `${BORROW_FEE_PROTOCOL_ID}::market_dynamic_keys::BorrowFeeKey`,
|
|
3032
3053
|
value: {
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
}
|
|
3036
|
-
});
|
|
3037
|
-
const interestModelDynamicFieldObject = interestModelDynamicFieldObjectResponse?.data;
|
|
3038
|
-
if (!(interestModelDynamicFieldObject && interestModelDynamicFieldObject.content && "fields" in interestModelDynamicFieldObject.content))
|
|
3039
|
-
throw new Error(
|
|
3040
|
-
`Failed to fetch interestModelDynamicFieldObject for ${poolCoinName}: ${interestModelDynamicFieldObject}`
|
|
3041
|
-
);
|
|
3042
|
-
const interestModel = interestModelDynamicFieldObject.content.fields.value.fields;
|
|
3043
|
-
const getBorrowFee = async () => {
|
|
3044
|
-
const borrowFeeDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3045
|
-
parentId: marketId,
|
|
3046
|
-
name: {
|
|
3047
|
-
type: `${BORROW_FEE_PROTOCOL_ID}::market_dynamic_keys::BorrowFeeKey`,
|
|
3048
|
-
value: {
|
|
3049
|
-
type: {
|
|
3050
|
-
name: coinType.substring(2)
|
|
3051
|
-
}
|
|
3054
|
+
type: {
|
|
3055
|
+
name: coinType.substring(2)
|
|
3052
3056
|
}
|
|
3053
3057
|
}
|
|
3054
|
-
}
|
|
3055
|
-
const borrowFeeDynamicFieldObject = borrowFeeDynamicFieldObjectResponse?.data;
|
|
3056
|
-
if (!(borrowFeeDynamicFieldObject && borrowFeeDynamicFieldObject.content && "fields" in borrowFeeDynamicFieldObject.content))
|
|
3057
|
-
return { value: "0" };
|
|
3058
|
-
return borrowFeeDynamicFieldObject.content.fields.value.fields;
|
|
3059
|
-
};
|
|
3060
|
-
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
3061
|
-
type: interestModel.type.fields,
|
|
3062
|
-
maxBorrowRate: interestModel.max_borrow_rate.fields,
|
|
3063
|
-
interestRate: borrowIndex.interest_rate.fields,
|
|
3064
|
-
interestRateScale: borrowIndex.interest_rate_scale,
|
|
3065
|
-
borrowIndex: borrowIndex.borrow_index,
|
|
3066
|
-
lastUpdated: borrowIndex.last_updated,
|
|
3067
|
-
cash: balanceSheet.cash,
|
|
3068
|
-
debt: balanceSheet.debt,
|
|
3069
|
-
marketCoinSupply: balanceSheet.market_coin_supply,
|
|
3070
|
-
reserve: balanceSheet.revenue,
|
|
3071
|
-
reserveFactor: interestModel.revenue_factor.fields,
|
|
3072
|
-
borrowWeight: interestModel.borrow_weight.fields,
|
|
3073
|
-
borrowFeeRate: await getBorrowFee(),
|
|
3074
|
-
baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
|
|
3075
|
-
borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
|
|
3076
|
-
borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
|
|
3077
|
-
highKink: interestModel.high_kink.fields,
|
|
3078
|
-
midKink: interestModel.mid_kink.fields,
|
|
3079
|
-
minBorrowAmount: interestModel.min_borrow_amount
|
|
3058
|
+
}
|
|
3080
3059
|
});
|
|
3081
|
-
const
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3060
|
+
const borrowFeeDynamicFieldObject = borrowFeeDynamicFieldObjectResponse?.data;
|
|
3061
|
+
if (!(borrowFeeDynamicFieldObject && borrowFeeDynamicFieldObject.content && "fields" in borrowFeeDynamicFieldObject.content))
|
|
3062
|
+
return { value: "0" };
|
|
3063
|
+
return borrowFeeDynamicFieldObject.content.fields.value.fields;
|
|
3064
|
+
};
|
|
3065
|
+
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
3066
|
+
type: interestModel.type.fields,
|
|
3067
|
+
maxBorrowRate: interestModel.max_borrow_rate.fields,
|
|
3068
|
+
interestRate: borrowIndex.interest_rate.fields,
|
|
3069
|
+
interestRateScale: borrowIndex.interest_rate_scale,
|
|
3070
|
+
borrowIndex: borrowIndex.borrow_index,
|
|
3071
|
+
lastUpdated: borrowIndex.last_updated,
|
|
3072
|
+
cash: balanceSheet.cash,
|
|
3073
|
+
debt: balanceSheet.debt,
|
|
3074
|
+
marketCoinSupply: balanceSheet.market_coin_supply,
|
|
3075
|
+
reserve: balanceSheet.revenue,
|
|
3076
|
+
reserveFactor: interestModel.revenue_factor.fields,
|
|
3077
|
+
borrowWeight: interestModel.borrow_weight.fields,
|
|
3078
|
+
borrowFeeRate: await getBorrowFee(),
|
|
3079
|
+
baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
|
|
3080
|
+
borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
|
|
3081
|
+
borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
|
|
3082
|
+
highKink: interestModel.high_kink.fields,
|
|
3083
|
+
midKink: interestModel.mid_kink.fields,
|
|
3084
|
+
minBorrowAmount: interestModel.min_borrow_amount
|
|
3085
|
+
});
|
|
3086
|
+
const calculatedMarketPoolData = calculateMarketPoolData(
|
|
3087
|
+
query.utils,
|
|
3088
|
+
parsedMarketPoolData
|
|
3089
|
+
);
|
|
3090
|
+
const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
3091
|
+
const maxSupplyCoin = BigNumber3(
|
|
3092
|
+
await getSupplyLimit(query.utils, poolCoinName) ?? "0"
|
|
3093
|
+
).shiftedBy(-coinDecimal).toNumber();
|
|
3094
|
+
const maxBorrowCoin = BigNumber3(
|
|
3095
|
+
await getBorrowLimit(query.utils, poolCoinName) ?? "0"
|
|
3096
|
+
).shiftedBy(-coinDecimal).toNumber();
|
|
3097
|
+
return {
|
|
3098
|
+
coinName: poolCoinName,
|
|
3099
|
+
symbol: query.utils.parseSymbol(poolCoinName),
|
|
3100
|
+
coinType: query.utils.parseCoinType(poolCoinName),
|
|
3101
|
+
marketCoinType: query.utils.parseMarketCoinType(poolCoinName),
|
|
3102
|
+
sCoinType: query.utils.parseSCoinType(
|
|
3103
|
+
query.utils.parseMarketCoinName(poolCoinName)
|
|
3104
|
+
),
|
|
3105
|
+
coinWrappedType: query.utils.getCoinWrappedType(poolCoinName),
|
|
3106
|
+
coinDecimal,
|
|
3107
|
+
coinPrice: coinPrice ?? 0,
|
|
3108
|
+
highKink: parsedMarketPoolData.highKink,
|
|
3109
|
+
midKink: parsedMarketPoolData.midKink,
|
|
3110
|
+
reserveFactor: parsedMarketPoolData.reserveFactor,
|
|
3111
|
+
borrowWeight: parsedMarketPoolData.borrowWeight,
|
|
3112
|
+
borrowFee: parsedMarketPoolData.borrowFee,
|
|
3113
|
+
marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
|
|
3114
|
+
minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
|
|
3115
|
+
maxSupplyCoin,
|
|
3116
|
+
maxBorrowCoin,
|
|
3117
|
+
isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
|
|
3118
|
+
...calculatedMarketPoolData
|
|
3119
|
+
};
|
|
3118
3120
|
};
|
|
3119
3121
|
var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLATERALS], indexer = false) => {
|
|
3120
3122
|
const marketId = query.address.get("core.market");
|
|
@@ -3471,10 +3473,12 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
|
|
|
3471
3473
|
(marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
|
|
3472
3474
|
);
|
|
3473
3475
|
const coinPrices = await query.utils.getCoinPrices(poolCoinNames);
|
|
3474
|
-
const marketPools = await query.getMarketPools(poolCoinNames,
|
|
3476
|
+
const marketPools = await query.getMarketPools(poolCoinNames, {
|
|
3477
|
+
indexer,
|
|
3475
3478
|
coinPrices
|
|
3476
3479
|
});
|
|
3477
|
-
const spools = await query.getSpools(stakeMarketCoinNames,
|
|
3480
|
+
const spools = await query.getSpools(stakeMarketCoinNames, {
|
|
3481
|
+
indexer,
|
|
3478
3482
|
marketPools,
|
|
3479
3483
|
coinPrices
|
|
3480
3484
|
});
|
|
@@ -3509,21 +3513,19 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
|
|
|
3509
3513
|
var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice, sCoinAmount) => {
|
|
3510
3514
|
const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
|
|
3511
3515
|
coinPrice = coinPrice ?? (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
|
|
3512
|
-
marketPool = marketPool ?? await query.getMarketPool(poolCoinName,
|
|
3516
|
+
marketPool = marketPool ?? await query.getMarketPool(poolCoinName, {
|
|
3517
|
+
indexer,
|
|
3513
3518
|
coinPrice
|
|
3514
3519
|
});
|
|
3515
3520
|
if (!marketPool)
|
|
3516
3521
|
throw new Error(`Failed to fetch marketPool for ${poolCoinName}`);
|
|
3517
|
-
spool = spool ?? SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(
|
|
3518
|
-
marketCoinName,
|
|
3522
|
+
spool = spool ?? SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(marketCoinName, {
|
|
3519
3523
|
indexer,
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
[poolCoinName]: coinPrice
|
|
3524
|
-
}
|
|
3524
|
+
marketPool,
|
|
3525
|
+
coinPrices: {
|
|
3526
|
+
[poolCoinName]: coinPrice
|
|
3525
3527
|
}
|
|
3526
|
-
) : void 0;
|
|
3528
|
+
}) : void 0;
|
|
3527
3529
|
stakeAccounts = stakeAccounts || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getStakeAccounts(
|
|
3528
3530
|
marketCoinName,
|
|
3529
3531
|
ownerAddress
|
|
@@ -3643,7 +3645,7 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
3643
3645
|
};
|
|
3644
3646
|
var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
|
|
3645
3647
|
const coinPrices = await query.utils.getCoinPrices();
|
|
3646
|
-
const market = await query.queryMarket(indexer,
|
|
3648
|
+
const market = await query.queryMarket({ indexer, coinPrices });
|
|
3647
3649
|
const [coinAmounts, obligations] = await Promise.all([
|
|
3648
3650
|
query.getCoinAmounts(void 0, ownerAddress),
|
|
3649
3651
|
query.getObligations(ownerAddress)
|
|
@@ -3669,12 +3671,13 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3669
3671
|
...SUPPORT_COLLATERALS
|
|
3670
3672
|
];
|
|
3671
3673
|
coinPrices = coinPrices ?? await query.utils.getCoinPrices(collateralAssetCoinNames);
|
|
3672
|
-
market = market ?? await query.queryMarket(indexer,
|
|
3674
|
+
market = market ?? await query.queryMarket({ indexer, coinPrices });
|
|
3673
3675
|
coinAmounts = coinAmounts || await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress);
|
|
3674
3676
|
const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] = await Promise.all([
|
|
3675
3677
|
query.queryObligation(obligationId),
|
|
3676
|
-
query.getBorrowIncentivePools(void 0,
|
|
3677
|
-
coinPrices
|
|
3678
|
+
query.getBorrowIncentivePools(void 0, {
|
|
3679
|
+
coinPrices,
|
|
3680
|
+
indexer
|
|
3678
3681
|
}),
|
|
3679
3682
|
query.getBorrowIncentiveAccounts(obligationId)
|
|
3680
3683
|
]);
|
|
@@ -3954,7 +3957,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3954
3957
|
return obligationAccount;
|
|
3955
3958
|
};
|
|
3956
3959
|
var getTotalValueLocked = async (query, indexer = false) => {
|
|
3957
|
-
const market = await query.queryMarket(indexer);
|
|
3960
|
+
const market = await query.queryMarket({ indexer });
|
|
3958
3961
|
let supplyValue = BigNumber5(0);
|
|
3959
3962
|
let borrowValue = BigNumber5(0);
|
|
3960
3963
|
if (indexer) {
|
|
@@ -4158,8 +4161,8 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
|
|
|
4158
4161
|
const fromCoinName = query.utils.parseCoinName(fromSCoin);
|
|
4159
4162
|
const toCoinName = query.utils.parseCoinName(toSCoin);
|
|
4160
4163
|
const marketPools = await Promise.all([
|
|
4161
|
-
query.getMarketPool(fromCoinName
|
|
4162
|
-
query.getMarketPool(toCoinName
|
|
4164
|
+
query.getMarketPool(fromCoinName),
|
|
4165
|
+
query.getMarketPool(toCoinName)
|
|
4163
4166
|
]);
|
|
4164
4167
|
if (marketPools.some((pool) => !pool))
|
|
4165
4168
|
throw new Error("Failed to fetch the lendings data");
|
|
@@ -4189,7 +4192,7 @@ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexe
|
|
|
4189
4192
|
(stakeMarketCoinName) => query.utils.parseCoinName(stakeMarketCoinName)
|
|
4190
4193
|
);
|
|
4191
4194
|
coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
|
|
4192
|
-
marketPools = marketPools ?? await query.getMarketPools(stakeCoinNames, indexer);
|
|
4195
|
+
marketPools = marketPools ?? await query.getMarketPools(stakeCoinNames, { indexer });
|
|
4193
4196
|
if (!marketPools)
|
|
4194
4197
|
throw new Error(`Fail to fetch marketPools for ${stakeCoinNames}`);
|
|
4195
4198
|
const spools = {};
|
|
@@ -4230,7 +4233,7 @@ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexe
|
|
|
4230
4233
|
};
|
|
4231
4234
|
var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPrices) => {
|
|
4232
4235
|
const coinName = query.utils.parseCoinName(marketCoinName);
|
|
4233
|
-
marketPool = marketPool || await query.getMarketPool(coinName, indexer);
|
|
4236
|
+
marketPool = marketPool || await query.getMarketPool(coinName, { indexer });
|
|
4234
4237
|
if (!marketPool) {
|
|
4235
4238
|
throw new Error(`Failed to fetch marketPool for ${marketCoinName}`);
|
|
4236
4239
|
}
|
|
@@ -7025,8 +7028,8 @@ var ScallopQuery = class {
|
|
|
7025
7028
|
* @param indexer - Whether to use indexer.
|
|
7026
7029
|
* @return Market data.
|
|
7027
7030
|
*/
|
|
7028
|
-
async queryMarket(
|
|
7029
|
-
return await queryMarket(this, indexer, args?.coinPrices);
|
|
7031
|
+
async queryMarket(args) {
|
|
7032
|
+
return await queryMarket(this, args?.indexer, args?.coinPrices);
|
|
7030
7033
|
}
|
|
7031
7034
|
/**
|
|
7032
7035
|
* Get market pools.
|
|
@@ -7039,8 +7042,13 @@ var ScallopQuery = class {
|
|
|
7039
7042
|
* @param indexer - Whether to use indexer.
|
|
7040
7043
|
* @return Market pools data.
|
|
7041
7044
|
*/
|
|
7042
|
-
async getMarketPools(poolCoinNames,
|
|
7043
|
-
return await getMarketPools(
|
|
7045
|
+
async getMarketPools(poolCoinNames, args) {
|
|
7046
|
+
return await getMarketPools(
|
|
7047
|
+
this,
|
|
7048
|
+
poolCoinNames,
|
|
7049
|
+
args?.indexer,
|
|
7050
|
+
args?.coinPrices
|
|
7051
|
+
);
|
|
7044
7052
|
}
|
|
7045
7053
|
/**
|
|
7046
7054
|
* Get market pool
|
|
@@ -7049,11 +7057,11 @@ var ScallopQuery = class {
|
|
|
7049
7057
|
* @param indexer - Whether to use indexer.
|
|
7050
7058
|
* @return Market pool data.
|
|
7051
7059
|
*/
|
|
7052
|
-
async getMarketPool(poolCoinName,
|
|
7060
|
+
async getMarketPool(poolCoinName, args) {
|
|
7053
7061
|
return await getMarketPool(
|
|
7054
7062
|
this,
|
|
7055
7063
|
poolCoinName,
|
|
7056
|
-
indexer,
|
|
7064
|
+
args?.indexer,
|
|
7057
7065
|
args?.marketObject,
|
|
7058
7066
|
args?.coinPrice
|
|
7059
7067
|
);
|
|
@@ -7069,8 +7077,8 @@ var ScallopQuery = class {
|
|
|
7069
7077
|
* @param indexer - Whether to use indexer.
|
|
7070
7078
|
* @return Market collaterals data.
|
|
7071
7079
|
*/
|
|
7072
|
-
async getMarketCollaterals(collateralCoinNames,
|
|
7073
|
-
return await getMarketCollaterals(this, collateralCoinNames, indexer);
|
|
7080
|
+
async getMarketCollaterals(collateralCoinNames, args) {
|
|
7081
|
+
return await getMarketCollaterals(this, collateralCoinNames, args?.indexer);
|
|
7074
7082
|
}
|
|
7075
7083
|
/**
|
|
7076
7084
|
* Get market collateral
|
|
@@ -7079,8 +7087,8 @@ var ScallopQuery = class {
|
|
|
7079
7087
|
* @param indexer - Whether to use indexer.
|
|
7080
7088
|
* @return Market collateral data.
|
|
7081
7089
|
*/
|
|
7082
|
-
async getMarketCollateral(collateralCoinName,
|
|
7083
|
-
return await getMarketCollateral(this, collateralCoinName, indexer);
|
|
7090
|
+
async getMarketCollateral(collateralCoinName, args) {
|
|
7091
|
+
return await getMarketCollateral(this, collateralCoinName, args?.indexer);
|
|
7084
7092
|
}
|
|
7085
7093
|
/**
|
|
7086
7094
|
* Get obligations data.
|
|
@@ -7166,11 +7174,11 @@ var ScallopQuery = class {
|
|
|
7166
7174
|
* @param indexer - Whether to use indexer.
|
|
7167
7175
|
* @return Spools data.
|
|
7168
7176
|
*/
|
|
7169
|
-
async getSpools(stakeMarketCoinNames,
|
|
7177
|
+
async getSpools(stakeMarketCoinNames, args) {
|
|
7170
7178
|
return await getSpools(
|
|
7171
7179
|
this,
|
|
7172
7180
|
stakeMarketCoinNames,
|
|
7173
|
-
indexer,
|
|
7181
|
+
args?.indexer,
|
|
7174
7182
|
args?.marketPools,
|
|
7175
7183
|
args?.coinPrices
|
|
7176
7184
|
);
|
|
@@ -7182,11 +7190,11 @@ var ScallopQuery = class {
|
|
|
7182
7190
|
* @param indexer - Whether to use indexer.
|
|
7183
7191
|
* @return Spool data.
|
|
7184
7192
|
*/
|
|
7185
|
-
async getSpool(stakeMarketCoinName,
|
|
7193
|
+
async getSpool(stakeMarketCoinName, args) {
|
|
7186
7194
|
return await getSpool(
|
|
7187
7195
|
this,
|
|
7188
7196
|
stakeMarketCoinName,
|
|
7189
|
-
indexer,
|
|
7197
|
+
args?.indexer,
|
|
7190
7198
|
args?.marketPool,
|
|
7191
7199
|
args?.coinPrices
|
|
7192
7200
|
);
|
|
@@ -7289,11 +7297,11 @@ var ScallopQuery = class {
|
|
|
7289
7297
|
* @param indexer - Whether to use indexer.
|
|
7290
7298
|
* @return Borrow incentive pools data.
|
|
7291
7299
|
*/
|
|
7292
|
-
async getBorrowIncentivePools(coinNames,
|
|
7300
|
+
async getBorrowIncentivePools(coinNames, args) {
|
|
7293
7301
|
return await getBorrowIncentivePools(
|
|
7294
7302
|
this,
|
|
7295
7303
|
coinNames,
|
|
7296
|
-
indexer,
|
|
7304
|
+
args?.indexer,
|
|
7297
7305
|
args?.coinPrices
|
|
7298
7306
|
);
|
|
7299
7307
|
}
|
|
@@ -7315,8 +7323,8 @@ var ScallopQuery = class {
|
|
|
7315
7323
|
* @param indexer - Whether to use indexer.
|
|
7316
7324
|
* @return All lending and spool infomation.
|
|
7317
7325
|
*/
|
|
7318
|
-
async getLendings(poolCoinNames, ownerAddress = this.walletAddress,
|
|
7319
|
-
return await getLendings(this, poolCoinNames, ownerAddress, indexer);
|
|
7326
|
+
async getLendings(poolCoinNames, ownerAddress = this.walletAddress, args) {
|
|
7327
|
+
return await getLendings(this, poolCoinNames, ownerAddress, args?.indexer);
|
|
7320
7328
|
}
|
|
7321
7329
|
/**
|
|
7322
7330
|
* Get user lending and spool information for specific pool.
|
|
@@ -7326,8 +7334,8 @@ var ScallopQuery = class {
|
|
|
7326
7334
|
* @param indexer - Whether to use indexer.
|
|
7327
7335
|
* @return Lending pool data.
|
|
7328
7336
|
*/
|
|
7329
|
-
async getLending(poolCoinName, ownerAddress = this.walletAddress,
|
|
7330
|
-
return await getLending(this, poolCoinName, ownerAddress, indexer);
|
|
7337
|
+
async getLending(poolCoinName, ownerAddress = this.walletAddress, args) {
|
|
7338
|
+
return await getLending(this, poolCoinName, ownerAddress, args?.indexer);
|
|
7331
7339
|
}
|
|
7332
7340
|
/**
|
|
7333
7341
|
* Get user all obligation accounts information.
|
|
@@ -7339,8 +7347,8 @@ var ScallopQuery = class {
|
|
|
7339
7347
|
* @param indexer - Whether to use indexer.
|
|
7340
7348
|
* @return All obligation accounts information.
|
|
7341
7349
|
*/
|
|
7342
|
-
async getObligationAccounts(ownerAddress = this.walletAddress,
|
|
7343
|
-
return await getObligationAccounts(this, ownerAddress, indexer);
|
|
7350
|
+
async getObligationAccounts(ownerAddress = this.walletAddress, args) {
|
|
7351
|
+
return await getObligationAccounts(this, ownerAddress, args?.indexer);
|
|
7344
7352
|
}
|
|
7345
7353
|
/**
|
|
7346
7354
|
* Get obligation account information for specific id.
|
|
@@ -7353,12 +7361,12 @@ var ScallopQuery = class {
|
|
|
7353
7361
|
* @param indexer - Whether to use indexer.
|
|
7354
7362
|
* @return Borrowing and collateral information.
|
|
7355
7363
|
*/
|
|
7356
|
-
async getObligationAccount(obligationId, ownerAddress = this.walletAddress,
|
|
7364
|
+
async getObligationAccount(obligationId, ownerAddress = this.walletAddress, args) {
|
|
7357
7365
|
return await getObligationAccount(
|
|
7358
7366
|
this,
|
|
7359
7367
|
obligationId,
|
|
7360
7368
|
ownerAddress,
|
|
7361
|
-
indexer
|
|
7369
|
+
args?.indexer
|
|
7362
7370
|
);
|
|
7363
7371
|
}
|
|
7364
7372
|
/**
|
|
@@ -7370,8 +7378,8 @@ var ScallopQuery = class {
|
|
|
7370
7378
|
*
|
|
7371
7379
|
* @return Total value locked.
|
|
7372
7380
|
*/
|
|
7373
|
-
async getTvl(
|
|
7374
|
-
return await getTotalValueLocked(this, indexer);
|
|
7381
|
+
async getTvl(args) {
|
|
7382
|
+
return await getTotalValueLocked(this, args?.indexer);
|
|
7375
7383
|
}
|
|
7376
7384
|
/**
|
|
7377
7385
|
* Get veSca data.
|