@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.
@@ -1,2 +1,2 @@
1
1
  export declare const DEFAULT_TOKENS_PER_INTERVAL = 50;
2
- export declare const DEFAULT_INTERVAL_IN_MS = 300;
2
+ export declare const DEFAULT_INTERVAL_IN_MS = 100;
package/dist/index.js CHANGED
@@ -1044,7 +1044,7 @@ var TEST_ADDRESSES = {
1044
1044
 
1045
1045
  // src/constants/tokenBucket.ts
1046
1046
  var DEFAULT_TOKENS_PER_INTERVAL = 50;
1047
- var DEFAULT_INTERVAL_IN_MS = 300;
1047
+ var DEFAULT_INTERVAL_IN_MS = 100;
1048
1048
 
1049
1049
  // src/constants/vesca.ts
1050
1050
  var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
@@ -1645,7 +1645,7 @@ var TokenBucket = class {
1645
1645
  return false;
1646
1646
  }
1647
1647
  };
1648
- var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 30, backoffFactor = 1.25) => {
1648
+ var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 15, backoffFactor = 2) => {
1649
1649
  let retries = 0;
1650
1650
  const tryRequest = async () => {
1651
1651
  if (tokenBucket.removeTokens(1)) {
@@ -1681,13 +1681,19 @@ var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVA
1681
1681
 
1682
1682
  // src/utils/indexer.ts
1683
1683
  async function callMethodWithIndexerFallback(method, context, ...args) {
1684
- const indexer = args[args.length - 1];
1685
- if (indexer) {
1684
+ const lastArgs = args[args.length - 1];
1685
+ if (typeof lastArgs === "object" && lastArgs.indexer) {
1686
1686
  try {
1687
1687
  return await method.apply(context, args);
1688
1688
  } catch (e) {
1689
1689
  console.warn(`Indexer requests failed: ${e}. Retrying without indexer..`);
1690
- return await method.apply(context, [...args.slice(0, -1), false]);
1690
+ return await method.apply(context, [
1691
+ ...args.slice(0, -1),
1692
+ {
1693
+ ...lastArgs,
1694
+ indexer: false
1695
+ }
1696
+ ]);
1691
1697
  }
1692
1698
  }
1693
1699
  return await method.apply(context, args);
@@ -3060,150 +3066,146 @@ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer =
3060
3066
  return marketPools;
3061
3067
  };
3062
3068
  var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, coinPrice) => {
3063
- try {
3064
- coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
3065
- if (indexer) {
3066
- const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
3067
- if (!marketPoolIndexer) {
3068
- return void 0;
3069
+ coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
3070
+ if (indexer) {
3071
+ const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
3072
+ if (!marketPoolIndexer) {
3073
+ return void 0;
3074
+ }
3075
+ marketPoolIndexer.coinPrice = coinPrice ?? marketPoolIndexer.coinPrice;
3076
+ marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
3077
+ marketPoolIndexer.coinName
3078
+ );
3079
+ return marketPoolIndexer;
3080
+ }
3081
+ const marketId = query.address.get("core.market");
3082
+ marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
3083
+ showContent: true
3084
+ }))?.data;
3085
+ if (!(marketObject && marketObject.content?.dataType === "moveObject"))
3086
+ throw new Error(`Failed to fetch marketObject`);
3087
+ const fields = marketObject.content.fields;
3088
+ const coinType = query.utils.parseCoinType(poolCoinName);
3089
+ const balanceSheetParentId = fields.vault.fields.balance_sheets.fields.table.fields.id.id;
3090
+ const balanceSheetDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
3091
+ parentId: balanceSheetParentId,
3092
+ name: {
3093
+ type: "0x1::type_name::TypeName",
3094
+ value: {
3095
+ name: coinType.substring(2)
3069
3096
  }
3070
- marketPoolIndexer.coinPrice = coinPrice ?? marketPoolIndexer.coinPrice;
3071
- marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
3072
- marketPoolIndexer.coinName
3073
- );
3074
- return marketPoolIndexer;
3075
3097
  }
3076
- const marketId = query.address.get("core.market");
3077
- marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
3078
- showContent: true
3079
- }))?.data;
3080
- if (!(marketObject && marketObject.content?.dataType === "moveObject"))
3081
- throw new Error(`Failed to fetch marketObject`);
3082
- const fields = marketObject.content.fields;
3083
- const coinType = query.utils.parseCoinType(poolCoinName);
3084
- const balanceSheetParentId = fields.vault.fields.balance_sheets.fields.table.fields.id.id;
3085
- const balanceSheetDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
3086
- parentId: balanceSheetParentId,
3087
- name: {
3088
- type: "0x1::type_name::TypeName",
3089
- value: {
3090
- name: coinType.substring(2)
3091
- }
3098
+ });
3099
+ const balanceSheetDynamicFieldObject = balanceSheetDynamicFieldObjectResponse?.data;
3100
+ if (!(balanceSheetDynamicFieldObject && balanceSheetDynamicFieldObject.content && "fields" in balanceSheetDynamicFieldObject.content))
3101
+ throw new Error(
3102
+ `Failed to fetch balanceSheetDynamicFieldObject for ${poolCoinName}: ${balanceSheetDynamicFieldObjectResponse?.error?.code.toString()}`
3103
+ );
3104
+ const balanceSheet = balanceSheetDynamicFieldObject.content.fields.value.fields;
3105
+ const borrowIndexParentId = fields.borrow_dynamics.fields.table.fields.id.id;
3106
+ const borrowIndexDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
3107
+ parentId: borrowIndexParentId,
3108
+ name: {
3109
+ type: "0x1::type_name::TypeName",
3110
+ value: {
3111
+ name: coinType.substring(2)
3092
3112
  }
3093
- });
3094
- const balanceSheetDynamicFieldObject = balanceSheetDynamicFieldObjectResponse?.data;
3095
- if (!(balanceSheetDynamicFieldObject && balanceSheetDynamicFieldObject.content && "fields" in balanceSheetDynamicFieldObject.content))
3096
- throw new Error(
3097
- `Failed to fetch balanceSheetDynamicFieldObject for ${poolCoinName}: ${balanceSheetDynamicFieldObjectResponse?.error?.code.toString()}`
3098
- );
3099
- const balanceSheet = balanceSheetDynamicFieldObject.content.fields.value.fields;
3100
- const borrowIndexParentId = fields.borrow_dynamics.fields.table.fields.id.id;
3101
- const borrowIndexDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
3102
- parentId: borrowIndexParentId,
3103
- name: {
3104
- type: "0x1::type_name::TypeName",
3105
- value: {
3106
- name: coinType.substring(2)
3107
- }
3113
+ }
3114
+ });
3115
+ const borrowIndexDynamicFieldObject = borrowIndexDynamicFieldObjectResponse?.data;
3116
+ if (!(borrowIndexDynamicFieldObject && borrowIndexDynamicFieldObject.content && "fields" in borrowIndexDynamicFieldObject.content))
3117
+ throw new Error(
3118
+ `Failed to fetch borrowIndexDynamicFieldObject for ${poolCoinName}`
3119
+ );
3120
+ const borrowIndex = borrowIndexDynamicFieldObject.content.fields.value.fields;
3121
+ const interestModelParentId = fields.interest_models.fields.table.fields.id.id;
3122
+ const interestModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
3123
+ parentId: interestModelParentId,
3124
+ name: {
3125
+ type: "0x1::type_name::TypeName",
3126
+ value: {
3127
+ name: coinType.substring(2)
3108
3128
  }
3109
- });
3110
- const borrowIndexDynamicFieldObject = borrowIndexDynamicFieldObjectResponse?.data;
3111
- if (!(borrowIndexDynamicFieldObject && borrowIndexDynamicFieldObject.content && "fields" in borrowIndexDynamicFieldObject.content))
3112
- throw new Error(
3113
- `Failed to fetch borrowIndexDynamicFieldObject for ${poolCoinName}`
3114
- );
3115
- const borrowIndex = borrowIndexDynamicFieldObject.content.fields.value.fields;
3116
- const interestModelParentId = fields.interest_models.fields.table.fields.id.id;
3117
- const interestModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
3118
- parentId: interestModelParentId,
3129
+ }
3130
+ });
3131
+ const interestModelDynamicFieldObject = interestModelDynamicFieldObjectResponse?.data;
3132
+ if (!(interestModelDynamicFieldObject && interestModelDynamicFieldObject.content && "fields" in interestModelDynamicFieldObject.content))
3133
+ throw new Error(
3134
+ `Failed to fetch interestModelDynamicFieldObject for ${poolCoinName}: ${interestModelDynamicFieldObject}`
3135
+ );
3136
+ const interestModel = interestModelDynamicFieldObject.content.fields.value.fields;
3137
+ const getBorrowFee = async () => {
3138
+ const borrowFeeDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
3139
+ parentId: marketId,
3119
3140
  name: {
3120
- type: "0x1::type_name::TypeName",
3141
+ type: `${BORROW_FEE_PROTOCOL_ID}::market_dynamic_keys::BorrowFeeKey`,
3121
3142
  value: {
3122
- name: coinType.substring(2)
3123
- }
3124
- }
3125
- });
3126
- const interestModelDynamicFieldObject = interestModelDynamicFieldObjectResponse?.data;
3127
- if (!(interestModelDynamicFieldObject && interestModelDynamicFieldObject.content && "fields" in interestModelDynamicFieldObject.content))
3128
- throw new Error(
3129
- `Failed to fetch interestModelDynamicFieldObject for ${poolCoinName}: ${interestModelDynamicFieldObject}`
3130
- );
3131
- const interestModel = interestModelDynamicFieldObject.content.fields.value.fields;
3132
- const getBorrowFee = async () => {
3133
- const borrowFeeDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
3134
- parentId: marketId,
3135
- name: {
3136
- type: `${BORROW_FEE_PROTOCOL_ID}::market_dynamic_keys::BorrowFeeKey`,
3137
- value: {
3138
- type: {
3139
- name: coinType.substring(2)
3140
- }
3143
+ type: {
3144
+ name: coinType.substring(2)
3141
3145
  }
3142
3146
  }
3143
- });
3144
- const borrowFeeDynamicFieldObject = borrowFeeDynamicFieldObjectResponse?.data;
3145
- if (!(borrowFeeDynamicFieldObject && borrowFeeDynamicFieldObject.content && "fields" in borrowFeeDynamicFieldObject.content))
3146
- return { value: "0" };
3147
- return borrowFeeDynamicFieldObject.content.fields.value.fields;
3148
- };
3149
- const parsedMarketPoolData = parseOriginMarketPoolData({
3150
- type: interestModel.type.fields,
3151
- maxBorrowRate: interestModel.max_borrow_rate.fields,
3152
- interestRate: borrowIndex.interest_rate.fields,
3153
- interestRateScale: borrowIndex.interest_rate_scale,
3154
- borrowIndex: borrowIndex.borrow_index,
3155
- lastUpdated: borrowIndex.last_updated,
3156
- cash: balanceSheet.cash,
3157
- debt: balanceSheet.debt,
3158
- marketCoinSupply: balanceSheet.market_coin_supply,
3159
- reserve: balanceSheet.revenue,
3160
- reserveFactor: interestModel.revenue_factor.fields,
3161
- borrowWeight: interestModel.borrow_weight.fields,
3162
- borrowFeeRate: await getBorrowFee(),
3163
- baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
3164
- borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
3165
- borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
3166
- highKink: interestModel.high_kink.fields,
3167
- midKink: interestModel.mid_kink.fields,
3168
- minBorrowAmount: interestModel.min_borrow_amount
3147
+ }
3169
3148
  });
3170
- const calculatedMarketPoolData = calculateMarketPoolData(
3171
- query.utils,
3172
- parsedMarketPoolData
3173
- );
3174
- const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
3175
- const maxSupplyCoin = (0, import_bignumber3.default)(
3176
- await getSupplyLimit(query.utils, poolCoinName) ?? "0"
3177
- ).shiftedBy(-coinDecimal).toNumber();
3178
- const maxBorrowCoin = (0, import_bignumber3.default)(
3179
- await getBorrowLimit(query.utils, poolCoinName) ?? "0"
3180
- ).shiftedBy(-coinDecimal).toNumber();
3181
- return {
3182
- coinName: poolCoinName,
3183
- symbol: query.utils.parseSymbol(poolCoinName),
3184
- coinType: query.utils.parseCoinType(poolCoinName),
3185
- marketCoinType: query.utils.parseMarketCoinType(poolCoinName),
3186
- sCoinType: query.utils.parseSCoinType(
3187
- query.utils.parseMarketCoinName(poolCoinName)
3188
- ),
3189
- coinWrappedType: query.utils.getCoinWrappedType(poolCoinName),
3190
- coinDecimal,
3191
- coinPrice: coinPrice ?? 0,
3192
- highKink: parsedMarketPoolData.highKink,
3193
- midKink: parsedMarketPoolData.midKink,
3194
- reserveFactor: parsedMarketPoolData.reserveFactor,
3195
- borrowWeight: parsedMarketPoolData.borrowWeight,
3196
- borrowFee: parsedMarketPoolData.borrowFee,
3197
- marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
3198
- minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
3199
- maxSupplyCoin,
3200
- maxBorrowCoin,
3201
- isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
3202
- ...calculatedMarketPoolData
3203
- };
3204
- } catch (e) {
3205
- console.error(e.message);
3206
- }
3149
+ const borrowFeeDynamicFieldObject = borrowFeeDynamicFieldObjectResponse?.data;
3150
+ if (!(borrowFeeDynamicFieldObject && borrowFeeDynamicFieldObject.content && "fields" in borrowFeeDynamicFieldObject.content))
3151
+ return { value: "0" };
3152
+ return borrowFeeDynamicFieldObject.content.fields.value.fields;
3153
+ };
3154
+ const parsedMarketPoolData = parseOriginMarketPoolData({
3155
+ type: interestModel.type.fields,
3156
+ maxBorrowRate: interestModel.max_borrow_rate.fields,
3157
+ interestRate: borrowIndex.interest_rate.fields,
3158
+ interestRateScale: borrowIndex.interest_rate_scale,
3159
+ borrowIndex: borrowIndex.borrow_index,
3160
+ lastUpdated: borrowIndex.last_updated,
3161
+ cash: balanceSheet.cash,
3162
+ debt: balanceSheet.debt,
3163
+ marketCoinSupply: balanceSheet.market_coin_supply,
3164
+ reserve: balanceSheet.revenue,
3165
+ reserveFactor: interestModel.revenue_factor.fields,
3166
+ borrowWeight: interestModel.borrow_weight.fields,
3167
+ borrowFeeRate: await getBorrowFee(),
3168
+ baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
3169
+ borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
3170
+ borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
3171
+ highKink: interestModel.high_kink.fields,
3172
+ midKink: interestModel.mid_kink.fields,
3173
+ minBorrowAmount: interestModel.min_borrow_amount
3174
+ });
3175
+ const calculatedMarketPoolData = calculateMarketPoolData(
3176
+ query.utils,
3177
+ parsedMarketPoolData
3178
+ );
3179
+ const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
3180
+ const maxSupplyCoin = (0, import_bignumber3.default)(
3181
+ await getSupplyLimit(query.utils, poolCoinName) ?? "0"
3182
+ ).shiftedBy(-coinDecimal).toNumber();
3183
+ const maxBorrowCoin = (0, import_bignumber3.default)(
3184
+ await getBorrowLimit(query.utils, poolCoinName) ?? "0"
3185
+ ).shiftedBy(-coinDecimal).toNumber();
3186
+ return {
3187
+ coinName: poolCoinName,
3188
+ symbol: query.utils.parseSymbol(poolCoinName),
3189
+ coinType: query.utils.parseCoinType(poolCoinName),
3190
+ marketCoinType: query.utils.parseMarketCoinType(poolCoinName),
3191
+ sCoinType: query.utils.parseSCoinType(
3192
+ query.utils.parseMarketCoinName(poolCoinName)
3193
+ ),
3194
+ coinWrappedType: query.utils.getCoinWrappedType(poolCoinName),
3195
+ coinDecimal,
3196
+ coinPrice: coinPrice ?? 0,
3197
+ highKink: parsedMarketPoolData.highKink,
3198
+ midKink: parsedMarketPoolData.midKink,
3199
+ reserveFactor: parsedMarketPoolData.reserveFactor,
3200
+ borrowWeight: parsedMarketPoolData.borrowWeight,
3201
+ borrowFee: parsedMarketPoolData.borrowFee,
3202
+ marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
3203
+ minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
3204
+ maxSupplyCoin,
3205
+ maxBorrowCoin,
3206
+ isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
3207
+ ...calculatedMarketPoolData
3208
+ };
3207
3209
  };
3208
3210
  var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLATERALS], indexer = false) => {
3209
3211
  const marketId = query.address.get("core.market");
@@ -3560,10 +3562,12 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
3560
3562
  (marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
3561
3563
  );
3562
3564
  const coinPrices = await query.utils.getCoinPrices(poolCoinNames);
3563
- const marketPools = await query.getMarketPools(poolCoinNames, indexer, {
3565
+ const marketPools = await query.getMarketPools(poolCoinNames, {
3566
+ indexer,
3564
3567
  coinPrices
3565
3568
  });
3566
- const spools = await query.getSpools(stakeMarketCoinNames, indexer, {
3569
+ const spools = await query.getSpools(stakeMarketCoinNames, {
3570
+ indexer,
3567
3571
  marketPools,
3568
3572
  coinPrices
3569
3573
  });
@@ -3598,21 +3602,19 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
3598
3602
  var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice, sCoinAmount) => {
3599
3603
  const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
3600
3604
  coinPrice = coinPrice ?? (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
3601
- marketPool = marketPool ?? await query.getMarketPool(poolCoinName, indexer, {
3605
+ marketPool = marketPool ?? await query.getMarketPool(poolCoinName, {
3606
+ indexer,
3602
3607
  coinPrice
3603
3608
  });
3604
3609
  if (!marketPool)
3605
3610
  throw new Error(`Failed to fetch marketPool for ${poolCoinName}`);
3606
- spool = spool ?? SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(
3607
- marketCoinName,
3611
+ spool = spool ?? SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(marketCoinName, {
3608
3612
  indexer,
3609
- {
3610
- marketPool,
3611
- coinPrices: {
3612
- [poolCoinName]: coinPrice
3613
- }
3613
+ marketPool,
3614
+ coinPrices: {
3615
+ [poolCoinName]: coinPrice
3614
3616
  }
3615
- ) : void 0;
3617
+ }) : void 0;
3616
3618
  stakeAccounts = stakeAccounts || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getStakeAccounts(
3617
3619
  marketCoinName,
3618
3620
  ownerAddress
@@ -3732,7 +3734,7 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
3732
3734
  };
3733
3735
  var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
3734
3736
  const coinPrices = await query.utils.getCoinPrices();
3735
- const market = await query.queryMarket(indexer, { coinPrices });
3737
+ const market = await query.queryMarket({ indexer, coinPrices });
3736
3738
  const [coinAmounts, obligations] = await Promise.all([
3737
3739
  query.getCoinAmounts(void 0, ownerAddress),
3738
3740
  query.getObligations(ownerAddress)
@@ -3758,12 +3760,13 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
3758
3760
  ...SUPPORT_COLLATERALS
3759
3761
  ];
3760
3762
  coinPrices = coinPrices ?? await query.utils.getCoinPrices(collateralAssetCoinNames);
3761
- market = market ?? await query.queryMarket(indexer, { coinPrices });
3763
+ market = market ?? await query.queryMarket({ indexer, coinPrices });
3762
3764
  coinAmounts = coinAmounts || await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress);
3763
3765
  const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] = await Promise.all([
3764
3766
  query.queryObligation(obligationId),
3765
- query.getBorrowIncentivePools(void 0, indexer, {
3766
- coinPrices
3767
+ query.getBorrowIncentivePools(void 0, {
3768
+ coinPrices,
3769
+ indexer
3767
3770
  }),
3768
3771
  query.getBorrowIncentiveAccounts(obligationId)
3769
3772
  ]);
@@ -4043,7 +4046,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
4043
4046
  return obligationAccount;
4044
4047
  };
4045
4048
  var getTotalValueLocked = async (query, indexer = false) => {
4046
- const market = await query.queryMarket(indexer);
4049
+ const market = await query.queryMarket({ indexer });
4047
4050
  let supplyValue = (0, import_bignumber5.default)(0);
4048
4051
  let borrowValue = (0, import_bignumber5.default)(0);
4049
4052
  if (indexer) {
@@ -4247,8 +4250,8 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
4247
4250
  const fromCoinName = query.utils.parseCoinName(fromSCoin);
4248
4251
  const toCoinName = query.utils.parseCoinName(toSCoin);
4249
4252
  const marketPools = await Promise.all([
4250
- query.getMarketPool(fromCoinName, false),
4251
- query.getMarketPool(toCoinName, false)
4253
+ query.getMarketPool(fromCoinName),
4254
+ query.getMarketPool(toCoinName)
4252
4255
  ]);
4253
4256
  if (marketPools.some((pool) => !pool))
4254
4257
  throw new Error("Failed to fetch the lendings data");
@@ -4278,7 +4281,7 @@ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexe
4278
4281
  (stakeMarketCoinName) => query.utils.parseCoinName(stakeMarketCoinName)
4279
4282
  );
4280
4283
  coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
4281
- marketPools = marketPools ?? await query.getMarketPools(stakeCoinNames, indexer);
4284
+ marketPools = marketPools ?? await query.getMarketPools(stakeCoinNames, { indexer });
4282
4285
  if (!marketPools)
4283
4286
  throw new Error(`Fail to fetch marketPools for ${stakeCoinNames}`);
4284
4287
  const spools = {};
@@ -4319,7 +4322,7 @@ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexe
4319
4322
  };
4320
4323
  var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPrices) => {
4321
4324
  const coinName = query.utils.parseCoinName(marketCoinName);
4322
- marketPool = marketPool || await query.getMarketPool(coinName, indexer);
4325
+ marketPool = marketPool || await query.getMarketPool(coinName, { indexer });
4323
4326
  if (!marketPool) {
4324
4327
  throw new Error(`Failed to fetch marketPool for ${marketCoinName}`);
4325
4328
  }
@@ -7103,8 +7106,8 @@ var ScallopQuery = class {
7103
7106
  * @param indexer - Whether to use indexer.
7104
7107
  * @return Market data.
7105
7108
  */
7106
- async queryMarket(indexer = false, args) {
7107
- return await queryMarket(this, indexer, args?.coinPrices);
7109
+ async queryMarket(args) {
7110
+ return await queryMarket(this, args?.indexer, args?.coinPrices);
7108
7111
  }
7109
7112
  /**
7110
7113
  * Get market pools.
@@ -7117,8 +7120,13 @@ var ScallopQuery = class {
7117
7120
  * @param indexer - Whether to use indexer.
7118
7121
  * @return Market pools data.
7119
7122
  */
7120
- async getMarketPools(poolCoinNames, indexer = false, args) {
7121
- return await getMarketPools(this, poolCoinNames, indexer, args?.coinPrices);
7123
+ async getMarketPools(poolCoinNames, args) {
7124
+ return await getMarketPools(
7125
+ this,
7126
+ poolCoinNames,
7127
+ args?.indexer,
7128
+ args?.coinPrices
7129
+ );
7122
7130
  }
7123
7131
  /**
7124
7132
  * Get market pool
@@ -7127,11 +7135,11 @@ var ScallopQuery = class {
7127
7135
  * @param indexer - Whether to use indexer.
7128
7136
  * @return Market pool data.
7129
7137
  */
7130
- async getMarketPool(poolCoinName, indexer = false, args) {
7138
+ async getMarketPool(poolCoinName, args) {
7131
7139
  return await getMarketPool(
7132
7140
  this,
7133
7141
  poolCoinName,
7134
- indexer,
7142
+ args?.indexer,
7135
7143
  args?.marketObject,
7136
7144
  args?.coinPrice
7137
7145
  );
@@ -7147,8 +7155,8 @@ var ScallopQuery = class {
7147
7155
  * @param indexer - Whether to use indexer.
7148
7156
  * @return Market collaterals data.
7149
7157
  */
7150
- async getMarketCollaterals(collateralCoinNames, indexer = false) {
7151
- return await getMarketCollaterals(this, collateralCoinNames, indexer);
7158
+ async getMarketCollaterals(collateralCoinNames, args) {
7159
+ return await getMarketCollaterals(this, collateralCoinNames, args?.indexer);
7152
7160
  }
7153
7161
  /**
7154
7162
  * Get market collateral
@@ -7157,8 +7165,8 @@ var ScallopQuery = class {
7157
7165
  * @param indexer - Whether to use indexer.
7158
7166
  * @return Market collateral data.
7159
7167
  */
7160
- async getMarketCollateral(collateralCoinName, indexer = false) {
7161
- return await getMarketCollateral(this, collateralCoinName, indexer);
7168
+ async getMarketCollateral(collateralCoinName, args) {
7169
+ return await getMarketCollateral(this, collateralCoinName, args?.indexer);
7162
7170
  }
7163
7171
  /**
7164
7172
  * Get obligations data.
@@ -7244,11 +7252,11 @@ var ScallopQuery = class {
7244
7252
  * @param indexer - Whether to use indexer.
7245
7253
  * @return Spools data.
7246
7254
  */
7247
- async getSpools(stakeMarketCoinNames, indexer = false, args) {
7255
+ async getSpools(stakeMarketCoinNames, args) {
7248
7256
  return await getSpools(
7249
7257
  this,
7250
7258
  stakeMarketCoinNames,
7251
- indexer,
7259
+ args?.indexer,
7252
7260
  args?.marketPools,
7253
7261
  args?.coinPrices
7254
7262
  );
@@ -7260,11 +7268,11 @@ var ScallopQuery = class {
7260
7268
  * @param indexer - Whether to use indexer.
7261
7269
  * @return Spool data.
7262
7270
  */
7263
- async getSpool(stakeMarketCoinName, indexer = false, args) {
7271
+ async getSpool(stakeMarketCoinName, args) {
7264
7272
  return await getSpool(
7265
7273
  this,
7266
7274
  stakeMarketCoinName,
7267
- indexer,
7275
+ args?.indexer,
7268
7276
  args?.marketPool,
7269
7277
  args?.coinPrices
7270
7278
  );
@@ -7367,11 +7375,11 @@ var ScallopQuery = class {
7367
7375
  * @param indexer - Whether to use indexer.
7368
7376
  * @return Borrow incentive pools data.
7369
7377
  */
7370
- async getBorrowIncentivePools(coinNames, indexer = false, args) {
7378
+ async getBorrowIncentivePools(coinNames, args) {
7371
7379
  return await getBorrowIncentivePools(
7372
7380
  this,
7373
7381
  coinNames,
7374
- indexer,
7382
+ args?.indexer,
7375
7383
  args?.coinPrices
7376
7384
  );
7377
7385
  }
@@ -7393,8 +7401,8 @@ var ScallopQuery = class {
7393
7401
  * @param indexer - Whether to use indexer.
7394
7402
  * @return All lending and spool infomation.
7395
7403
  */
7396
- async getLendings(poolCoinNames, ownerAddress = this.walletAddress, indexer = false) {
7397
- return await getLendings(this, poolCoinNames, ownerAddress, indexer);
7404
+ async getLendings(poolCoinNames, ownerAddress = this.walletAddress, args) {
7405
+ return await getLendings(this, poolCoinNames, ownerAddress, args?.indexer);
7398
7406
  }
7399
7407
  /**
7400
7408
  * Get user lending and spool information for specific pool.
@@ -7404,8 +7412,8 @@ var ScallopQuery = class {
7404
7412
  * @param indexer - Whether to use indexer.
7405
7413
  * @return Lending pool data.
7406
7414
  */
7407
- async getLending(poolCoinName, ownerAddress = this.walletAddress, indexer = false) {
7408
- return await getLending(this, poolCoinName, ownerAddress, indexer);
7415
+ async getLending(poolCoinName, ownerAddress = this.walletAddress, args) {
7416
+ return await getLending(this, poolCoinName, ownerAddress, args?.indexer);
7409
7417
  }
7410
7418
  /**
7411
7419
  * Get user all obligation accounts information.
@@ -7417,8 +7425,8 @@ var ScallopQuery = class {
7417
7425
  * @param indexer - Whether to use indexer.
7418
7426
  * @return All obligation accounts information.
7419
7427
  */
7420
- async getObligationAccounts(ownerAddress = this.walletAddress, indexer = false) {
7421
- return await getObligationAccounts(this, ownerAddress, indexer);
7428
+ async getObligationAccounts(ownerAddress = this.walletAddress, args) {
7429
+ return await getObligationAccounts(this, ownerAddress, args?.indexer);
7422
7430
  }
7423
7431
  /**
7424
7432
  * Get obligation account information for specific id.
@@ -7431,12 +7439,12 @@ var ScallopQuery = class {
7431
7439
  * @param indexer - Whether to use indexer.
7432
7440
  * @return Borrowing and collateral information.
7433
7441
  */
7434
- async getObligationAccount(obligationId, ownerAddress = this.walletAddress, indexer = false) {
7442
+ async getObligationAccount(obligationId, ownerAddress = this.walletAddress, args) {
7435
7443
  return await getObligationAccount(
7436
7444
  this,
7437
7445
  obligationId,
7438
7446
  ownerAddress,
7439
- indexer
7447
+ args?.indexer
7440
7448
  );
7441
7449
  }
7442
7450
  /**
@@ -7448,8 +7456,8 @@ var ScallopQuery = class {
7448
7456
  *
7449
7457
  * @return Total value locked.
7450
7458
  */
7451
- async getTvl(indexer = false) {
7452
- return await getTotalValueLocked(this, indexer);
7459
+ async getTvl(args) {
7460
+ return await getTotalValueLocked(this, args?.indexer);
7453
7461
  }
7454
7462
  /**
7455
7463
  * Get veSca data.