@scallop-io/sui-scallop-sdk 0.44.7 → 0.44.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -34,6 +34,7 @@ __export(src_exports, {
34
34
  API_BASE_URL: () => API_BASE_URL,
35
35
  BORROW_FEE_PROTOCOL_ID: () => BORROW_FEE_PROTOCOL_ID,
36
36
  PROTOCOL_OBJECT_ID: () => PROTOCOL_OBJECT_ID,
37
+ SDK_API_BASE_URL: () => SDK_API_BASE_URL,
37
38
  SUPPORT_BORROW_INCENTIVE_POOLS: () => SUPPORT_BORROW_INCENTIVE_POOLS,
38
39
  SUPPORT_BORROW_INCENTIVE_REWARDS: () => SUPPORT_BORROW_INCENTIVE_REWARDS,
39
40
  SUPPORT_COLLATERALS: () => SUPPORT_COLLATERALS,
@@ -46,6 +47,7 @@ __export(src_exports, {
46
47
  ScallopAddress: () => ScallopAddress,
47
48
  ScallopBuilder: () => ScallopBuilder,
48
49
  ScallopClient: () => ScallopClient,
50
+ ScallopIndexer: () => ScallopIndexer,
49
51
  ScallopQuery: () => ScallopQuery,
50
52
  ScallopUtils: () => ScallopUtils,
51
53
  assetCoins: () => assetCoins,
@@ -62,6 +64,7 @@ module.exports = __toCommonJS(src_exports);
62
64
 
63
65
  // src/constants/common.ts
64
66
  var API_BASE_URL = "https://sui.api.scallop.io";
67
+ var SDK_API_BASE_URL = "https://sdk.api.scallop.io";
65
68
  var ADDRESSES_ID = "6462a088a7ace142bb6d7e9b";
66
69
  var PROTOCOL_OBJECT_ID = "0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf";
67
70
  var BORROW_FEE_PROTOCOL_ID = "0xc38f849e81cfe46d4e4320f508ea7dda42934a329d5a6571bb4c3cb6ea63f5da";
@@ -1170,7 +1173,7 @@ var parseDataFromPythPriceFeed = (feed, address) => {
1170
1173
  };
1171
1174
 
1172
1175
  // src/queries/coreQuery.ts
1173
- var queryMarket = async (query) => {
1176
+ var queryMarket = async (query, indexer = false) => {
1174
1177
  const packageId = query.address.get("core.packages.query.id");
1175
1178
  const marketId = query.address.get("core.market");
1176
1179
  const txBlock = new import_sui_kit.SuiTxBlock();
@@ -1178,12 +1181,30 @@ var queryMarket = async (query) => {
1178
1181
  txBlock.moveCall(queryTarget, [marketId]);
1179
1182
  const queryResult = await query.suiKit.inspectTxn(txBlock);
1180
1183
  const marketData = queryResult.events[0].parsedJson;
1184
+ const coinPrices = await query.utils.getCoinPrices();
1181
1185
  const pools = {};
1182
1186
  const collaterals = {};
1187
+ if (indexer) {
1188
+ const marketIndexer = await query.indexer.getMarket();
1189
+ for (const pool of Object.values(marketIndexer.pools)) {
1190
+ pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
1191
+ pool.coinWrappedType = query.utils.getCoinWrappedType(pool.coinName);
1192
+ }
1193
+ for (const collateral of Object.values(marketIndexer.collaterals)) {
1194
+ collateral.coinPrice = coinPrices[collateral.coinName] || collateral.coinPrice;
1195
+ collateral.coinWrappedType = query.utils.getCoinWrappedType(
1196
+ collateral.coinName
1197
+ );
1198
+ }
1199
+ return {
1200
+ pools: marketIndexer.pools,
1201
+ collaterals: marketIndexer.collaterals
1202
+ };
1203
+ }
1183
1204
  for (const pool of marketData.pools) {
1184
1205
  const coinType = (0, import_utils2.normalizeStructTag)(pool.type.name);
1185
1206
  const poolCoinName = query.utils.parseCoinNameFromType(coinType);
1186
- const coinPrice = (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName] ?? 0;
1207
+ const coinPrice = coinPrices[poolCoinName] ?? 0;
1187
1208
  if (!SUPPORT_POOLS.includes(poolCoinName)) {
1188
1209
  continue;
1189
1210
  }
@@ -1233,7 +1254,7 @@ var queryMarket = async (query) => {
1233
1254
  for (const collateral of marketData.collaterals) {
1234
1255
  const coinType = (0, import_utils2.normalizeStructTag)(collateral.type.name);
1235
1256
  const collateralCoinName = query.utils.parseCoinNameFromType(coinType);
1236
- const coinPrice = (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName] ?? 0;
1257
+ const coinPrice = coinPrices[collateralCoinName] ?? 0;
1237
1258
  if (!SUPPORT_COLLATERALS.includes(collateralCoinName)) {
1238
1259
  continue;
1239
1260
  }
@@ -1273,7 +1294,7 @@ var queryMarket = async (query) => {
1273
1294
  data: marketData
1274
1295
  };
1275
1296
  };
1276
- var getMarketPools = async (query, poolCoinNames) => {
1297
+ var getMarketPools = async (query, poolCoinNames, indexer = false) => {
1277
1298
  poolCoinNames = poolCoinNames || [...SUPPORT_POOLS];
1278
1299
  const marketId = query.address.get("core.market");
1279
1300
  const marketObjectResponse = await query.suiKit.client().getObject({
@@ -1284,10 +1305,24 @@ var getMarketPools = async (query, poolCoinNames) => {
1284
1305
  });
1285
1306
  const coinPrices = await query.utils.getCoinPrices(poolCoinNames ?? []);
1286
1307
  const marketPools = {};
1308
+ if (indexer) {
1309
+ const marketPoolsIndexer = await query.indexer.getMarketPools();
1310
+ for (const marketPool of Object.values(marketPoolsIndexer)) {
1311
+ if (!poolCoinNames.includes(marketPool.coinName))
1312
+ continue;
1313
+ marketPool.coinPrice = coinPrices[marketPool.coinName] || marketPool.coinPrice;
1314
+ marketPool.coinWrappedType = query.utils.getCoinWrappedType(
1315
+ marketPool.coinName
1316
+ );
1317
+ marketPools[marketPool.coinName] = marketPool;
1318
+ }
1319
+ return marketPools;
1320
+ }
1287
1321
  for (const poolCoinName of poolCoinNames) {
1288
1322
  const marketPool = await getMarketPool(
1289
1323
  query,
1290
1324
  poolCoinName,
1325
+ indexer,
1291
1326
  marketObjectResponse.data,
1292
1327
  coinPrices?.[poolCoinName]
1293
1328
  );
@@ -1297,7 +1332,7 @@ var getMarketPools = async (query, poolCoinNames) => {
1297
1332
  }
1298
1333
  return marketPools;
1299
1334
  };
1300
- var getMarketPool = async (query, poolCoinName, marketObject, coinPrice) => {
1335
+ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, coinPrice) => {
1301
1336
  const marketId = query.address.get("core.market");
1302
1337
  marketObject = marketObject || (await query.suiKit.client().getObject({
1303
1338
  id: marketId,
@@ -1305,11 +1340,20 @@ var getMarketPool = async (query, poolCoinName, marketObject, coinPrice) => {
1305
1340
  showContent: true
1306
1341
  }
1307
1342
  })).data;
1343
+ coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
1308
1344
  let marketPool;
1309
1345
  let balanceSheet;
1310
1346
  let borrowIndex;
1311
1347
  let interestModel;
1312
1348
  let borrowFeeRate;
1349
+ if (indexer) {
1350
+ const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
1351
+ marketPoolIndexer.coinPrice = coinPrice || marketPoolIndexer.coinPrice;
1352
+ marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
1353
+ marketPoolIndexer.coinName
1354
+ );
1355
+ return marketPoolIndexer;
1356
+ }
1313
1357
  if (marketObject) {
1314
1358
  if (marketObject.content && "fields" in marketObject.content) {
1315
1359
  const fields = marketObject.content.fields;
@@ -1403,7 +1447,6 @@ var getMarketPool = async (query, poolCoinName, marketObject, coinPrice) => {
1403
1447
  query.utils,
1404
1448
  parsedMarketPoolData
1405
1449
  );
1406
- coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
1407
1450
  marketPool = {
1408
1451
  coinName: poolCoinName,
1409
1452
  symbol: query.utils.parseSymbol(poolCoinName),
@@ -1424,7 +1467,7 @@ var getMarketPool = async (query, poolCoinName, marketObject, coinPrice) => {
1424
1467
  }
1425
1468
  return marketPool;
1426
1469
  };
1427
- var getMarketCollaterals = async (query, collateralCoinNames) => {
1470
+ var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) => {
1428
1471
  collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
1429
1472
  const marketId = query.address.get("core.market");
1430
1473
  const marketObjectResponse = await query.suiKit.client().getObject({
@@ -1435,10 +1478,24 @@ var getMarketCollaterals = async (query, collateralCoinNames) => {
1435
1478
  });
1436
1479
  const coinPrices = await query.utils.getCoinPrices(collateralCoinNames ?? []);
1437
1480
  const marketCollaterals = {};
1481
+ if (indexer) {
1482
+ const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
1483
+ for (const marketCollateral of Object.values(marketCollateralsIndexer)) {
1484
+ if (!collateralCoinNames.includes(marketCollateral.coinName))
1485
+ continue;
1486
+ marketCollateral.coinPrice = coinPrices[marketCollateral.coinName] || marketCollateral.coinPrice;
1487
+ marketCollateral.coinWrappedType = query.utils.getCoinWrappedType(
1488
+ marketCollateral.coinName
1489
+ );
1490
+ marketCollaterals[marketCollateral.coinName] = marketCollateral;
1491
+ }
1492
+ return marketCollaterals;
1493
+ }
1438
1494
  for (const collateralCoinName of collateralCoinNames) {
1439
1495
  const marketCollateral = await getMarketCollateral(
1440
1496
  query,
1441
1497
  collateralCoinName,
1498
+ indexer,
1442
1499
  marketObjectResponse.data,
1443
1500
  coinPrices?.[collateralCoinName]
1444
1501
  );
@@ -1448,7 +1505,7 @@ var getMarketCollaterals = async (query, collateralCoinNames) => {
1448
1505
  }
1449
1506
  return marketCollaterals;
1450
1507
  };
1451
- var getMarketCollateral = async (query, collateralCoinName, marketObject, coinPrice) => {
1508
+ var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
1452
1509
  const marketId = query.address.get("core.market");
1453
1510
  marketObject = marketObject || (await query.suiKit.client().getObject({
1454
1511
  id: marketId,
@@ -1456,9 +1513,18 @@ var getMarketCollateral = async (query, collateralCoinName, marketObject, coinPr
1456
1513
  showContent: true
1457
1514
  }
1458
1515
  })).data;
1516
+ coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
1459
1517
  let marketCollateral;
1460
1518
  let riskModel;
1461
1519
  let collateralStat;
1520
+ if (indexer) {
1521
+ const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
1522
+ marketCollateralIndexer.coinPrice = coinPrice || marketCollateralIndexer.coinPrice;
1523
+ marketCollateralIndexer.coinWrappedType = query.utils.getCoinWrappedType(
1524
+ marketCollateralIndexer.coinName
1525
+ );
1526
+ return marketCollateralIndexer;
1527
+ }
1462
1528
  if (marketObject) {
1463
1529
  if (marketObject.content && "fields" in marketObject.content) {
1464
1530
  const fields = marketObject.content.fields;
@@ -1510,7 +1576,6 @@ var getMarketCollateral = async (query, collateralCoinName, marketObject, coinPr
1510
1576
  query.utils,
1511
1577
  parsedMarketCollateralData
1512
1578
  );
1513
- coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
1514
1579
  marketCollateral = {
1515
1580
  coinName: collateralCoinName,
1516
1581
  symbol: query.utils.parseSymbol(collateralCoinName),
@@ -1753,19 +1818,47 @@ var getMarketCoinAmount = async (query, marketCoinName, ownerAddress) => {
1753
1818
 
1754
1819
  // src/queries/spoolQuery.ts
1755
1820
  var import_utils4 = require("@mysten/sui.js/utils");
1756
- var getSpools = async (query, stakeMarketCoinNames) => {
1821
+ var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
1757
1822
  stakeMarketCoinNames = stakeMarketCoinNames || [...SUPPORT_SPOOLS];
1758
1823
  const stakeCoinNames = stakeMarketCoinNames.map(
1759
1824
  (stakeMarketCoinName) => query.utils.parseCoinName(stakeMarketCoinName)
1760
1825
  );
1761
- const marketPool = await query.getMarketPools(stakeCoinNames);
1826
+ const rewardCoinNames = stakeMarketCoinNames.map((stakeMarketCoinName) => {
1827
+ const rewardCoinName = query.utils.getSpoolRewardCoinName(stakeMarketCoinName);
1828
+ return rewardCoinName;
1829
+ });
1830
+ const coinPrices = await query.utils.getCoinPrices(
1831
+ [.../* @__PURE__ */ new Set([...stakeCoinNames, ...rewardCoinNames])]
1832
+ );
1833
+ const marketPools = await query.getMarketPools(stakeCoinNames, indexer);
1762
1834
  const spools = {};
1835
+ if (indexer) {
1836
+ const spoolsIndexer = await query.indexer.getSpools();
1837
+ for (const spool of Object.values(spoolsIndexer)) {
1838
+ if (!stakeMarketCoinNames.includes(spool.marketCoinName))
1839
+ continue;
1840
+ const coinName = query.utils.parseCoinName(
1841
+ spool.marketCoinName
1842
+ );
1843
+ const rewardCoinName = query.utils.getSpoolRewardCoinName(
1844
+ spool.marketCoinName
1845
+ );
1846
+ const marketPool = marketPools[coinName];
1847
+ spool.coinPrice = coinPrices[coinName] || spool.coinPrice;
1848
+ spool.marketCoinPrice = (coinPrices[coinName] ?? 0) * (marketPool ? marketPool.conversionRate : 0) || spool.marketCoinPrice;
1849
+ spool.rewardCoinPrice = coinPrices[rewardCoinName] || spool.rewardCoinPrice;
1850
+ spools[spool.marketCoinName] = spool;
1851
+ }
1852
+ return spools;
1853
+ }
1763
1854
  for (const stakeMarketCoinName of stakeMarketCoinNames) {
1764
1855
  const stakeCoinName = query.utils.parseCoinName(stakeMarketCoinName);
1765
1856
  const spool = await getSpool(
1766
1857
  query,
1767
1858
  stakeMarketCoinName,
1768
- marketPool[stakeCoinName]
1859
+ indexer,
1860
+ marketPools[stakeCoinName],
1861
+ coinPrices
1769
1862
  );
1770
1863
  if (spool) {
1771
1864
  spools[stakeMarketCoinName] = spool;
@@ -1773,15 +1866,24 @@ var getSpools = async (query, stakeMarketCoinNames) => {
1773
1866
  }
1774
1867
  return spools;
1775
1868
  };
1776
- var getSpool = async (query, marketCoinName, marketPool) => {
1869
+ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPrices) => {
1777
1870
  const coinName = query.utils.parseCoinName(marketCoinName);
1778
- marketPool = marketPool || await query.getMarketPool(coinName);
1871
+ marketPool = marketPool || await query.getMarketPool(coinName, indexer);
1779
1872
  const spoolPkgId = query.address.get(`spool.id`);
1780
1873
  const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
1781
1874
  const rewardPoolId = query.address.get(
1782
1875
  `spool.pools.${marketCoinName}.rewardPoolId`
1783
1876
  );
1784
1877
  let spool = void 0;
1878
+ if (indexer) {
1879
+ const spoolIndexer = await query.indexer.getSpool(marketCoinName);
1880
+ const coinName2 = query.utils.parseCoinName(marketCoinName);
1881
+ const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
1882
+ spoolIndexer.coinPrice = coinPrices?.[coinName2] || spoolIndexer.coinPrice;
1883
+ spoolIndexer.marketCoinPrice = (coinPrices?.[coinName2] ?? 0) * (marketPool ? marketPool.conversionRate : 0) || spoolIndexer.marketCoinPrice;
1884
+ spoolIndexer.rewardCoinPrice = coinPrices?.[rewardCoinName] || spoolIndexer.rewardCoinPrice;
1885
+ return spoolIndexer;
1886
+ }
1785
1887
  const spoolObjectResponse = await query.suiKit.client().multiGetObjects({
1786
1888
  ids: [poolId, rewardPoolId],
1787
1889
  options: {
@@ -1797,10 +1899,7 @@ var getSpool = async (query, marketCoinName, marketPool) => {
1797
1899
  });
1798
1900
  if (marketPool && spoolObjectResponse[0].data && spoolObjectResponse[1].data) {
1799
1901
  const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
1800
- const coinPrices = await query.utils.getCoinPrices([
1801
- coinName,
1802
- rewardCoinName
1803
- ]);
1902
+ coinPrices = coinPrices || await query.utils.getCoinPrices([coinName, rewardCoinName]);
1804
1903
  const spoolObject = spoolObjectResponse[0].data;
1805
1904
  const rewardPoolObject = spoolObjectResponse[1].data;
1806
1905
  const rewardFeeObject = spoolRewardFeeDynamicFieldsResponse.data;
@@ -2058,7 +2157,7 @@ var getStakeRewardPool = async (query, marketCoinName) => {
2058
2157
  // src/queries/borrowIncentiveQuery.ts
2059
2158
  var import_utils6 = require("@mysten/sui.js/utils");
2060
2159
  var import_sui_kit2 = require("@scallop-io/sui-kit");
2061
- var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames) => {
2160
+ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer = false) => {
2062
2161
  borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
2063
2162
  ...SUPPORT_BORROW_INCENTIVE_POOLS
2064
2163
  ];
@@ -2073,18 +2172,31 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames) => {
2073
2172
  borrowIncentivePoolsQueryData.reward_pool
2074
2173
  );
2075
2174
  const rewardCoinType = parsedBorrowIncentiveRewardPoolData.rewardType;
2175
+ const rewardCoinName = query.utils.parseCoinNameFromType(rewardCoinType);
2176
+ const coinPrices = await query.utils.getCoinPrices(
2177
+ [.../* @__PURE__ */ new Set([...borrowIncentiveCoinNames, rewardCoinName])]
2178
+ );
2076
2179
  const borrowIncentivePools = {};
2180
+ if (indexer) {
2181
+ const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
2182
+ for (const borrowIncentivePool of Object.values(
2183
+ borrowIncentivePoolsIndexer
2184
+ )) {
2185
+ if (!borrowIncentiveCoinNames.includes(borrowIncentivePool.coinName))
2186
+ continue;
2187
+ borrowIncentivePool.coinPrice = coinPrices[borrowIncentivePool.coinName] || borrowIncentivePool.coinPrice;
2188
+ borrowIncentivePool.rewardCoinPrice = coinPrices[rewardCoinName] || borrowIncentivePool.rewardCoinPrice;
2189
+ borrowIncentivePools[borrowIncentivePool.coinName] = borrowIncentivePool;
2190
+ }
2191
+ return borrowIncentivePools;
2192
+ }
2077
2193
  for (const pool of borrowIncentivePoolsQueryData.incentive_pools) {
2078
2194
  const coinType = (0, import_utils6.normalizeStructTag)(pool.pool_type.name);
2079
2195
  const coinName = query.utils.parseCoinNameFromType(coinType);
2080
- const rewardCoinName = query.utils.parseCoinNameFromType(rewardCoinType);
2196
+ const rewardCoinName2 = query.utils.parseCoinNameFromType(rewardCoinType);
2081
2197
  if (!borrowIncentiveCoinNames.includes(coinName)) {
2082
2198
  continue;
2083
2199
  }
2084
- const coinPrices = await query.utils.getCoinPrices([
2085
- coinName,
2086
- rewardCoinName
2087
- ]);
2088
2200
  const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(pool);
2089
2201
  const coinPrice = coinPrices?.[coinName] ?? 0;
2090
2202
  const coinDecimal = query.utils.getCoinDecimal(coinName);
@@ -2093,8 +2205,8 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames) => {
2093
2205
  coinPrice,
2094
2206
  coinDecimal
2095
2207
  );
2096
- const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
2097
- const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
2208
+ const rewardCoinPrice = coinPrices?.[rewardCoinName2] ?? 0;
2209
+ const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName2);
2098
2210
  const calculatedBorrowIncentiveRewardPoolData = calculateBorrowIncentiveRewardPoolData(
2099
2211
  parsedBorrowIncentivePoolData,
2100
2212
  parsedBorrowIncentiveRewardPoolData,
@@ -2190,7 +2302,7 @@ var getPythPrice = async (query, assetCoinName) => {
2190
2302
 
2191
2303
  // src/queries/portfolioQuery.ts
2192
2304
  var import_bignumber3 = __toESM(require("bignumber.js"));
2193
- var getLendings = async (query, poolCoinNames, ownerAddress) => {
2305
+ var getLendings = async (query, poolCoinNames, ownerAddress, indexer = false) => {
2194
2306
  poolCoinNames = poolCoinNames || [...SUPPORT_POOLS];
2195
2307
  const marketCoinNames = poolCoinNames.map(
2196
2308
  (poolCoinName) => query.utils.parseMarketCoinName(poolCoinName)
@@ -2198,8 +2310,8 @@ var getLendings = async (query, poolCoinNames, ownerAddress) => {
2198
2310
  const stakeMarketCoinNames = marketCoinNames.filter(
2199
2311
  (marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
2200
2312
  );
2201
- const marketPools = await query.getMarketPools(poolCoinNames);
2202
- const spools = await query.getSpools(stakeMarketCoinNames);
2313
+ const marketPools = await query.getMarketPools(poolCoinNames, indexer);
2314
+ const spools = await query.getSpools(stakeMarketCoinNames, indexer);
2203
2315
  const coinAmounts = await query.getCoinAmounts(poolCoinNames, ownerAddress);
2204
2316
  const marketCoinAmounts = await query.getMarketCoinAmounts(
2205
2317
  marketCoinNames,
@@ -2217,6 +2329,7 @@ var getLendings = async (query, poolCoinNames, ownerAddress) => {
2217
2329
  query,
2218
2330
  poolCoinName,
2219
2331
  ownerAddress,
2332
+ indexer,
2220
2333
  marketPools?.[poolCoinName],
2221
2334
  stakeMarketCoinName ? spools[stakeMarketCoinName] : void 0,
2222
2335
  stakeMarketCoinName ? allStakeAccounts[stakeMarketCoinName] : void 0,
@@ -2227,10 +2340,10 @@ var getLendings = async (query, poolCoinNames, ownerAddress) => {
2227
2340
  }
2228
2341
  return lendings;
2229
2342
  };
2230
- var getLending = async (query, poolCoinName, ownerAddress, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice) => {
2343
+ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice) => {
2231
2344
  const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
2232
- marketPool = marketPool || await query.getMarketPool(poolCoinName);
2233
- spool = spool || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(marketCoinName) : void 0;
2345
+ marketPool = marketPool || await query.getMarketPool(poolCoinName, indexer);
2346
+ spool = spool || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(marketCoinName, indexer) : void 0;
2234
2347
  stakeAccounts = stakeAccounts || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getStakeAccounts(
2235
2348
  marketCoinName,
2236
2349
  ownerAddress
@@ -2277,7 +2390,7 @@ var getLending = async (query, poolCoinName, ownerAddress, marketPool, spool, st
2277
2390
  -1 * spool.coinDecimal
2278
2391
  );
2279
2392
  const baseIndexRate = 1e9;
2280
- const increasedPointRate = spool?.currentPointIndex ? (0, import_bignumber3.default)(spool.currentPointIndex - stakeAccount.index).dividedBy(
2393
+ const increasedPointRate = spool.currentPointIndex ? (0, import_bignumber3.default)(spool.currentPointIndex - stakeAccount.index).dividedBy(
2281
2394
  baseIndexRate
2282
2395
  ) : 1;
2283
2396
  availableClaimAmount = availableClaimAmount.plus(
@@ -2341,8 +2454,8 @@ var getLending = async (query, poolCoinName, ownerAddress, marketPool, spool, st
2341
2454
  };
2342
2455
  return lending;
2343
2456
  };
2344
- var getObligationAccounts = async (query, ownerAddress) => {
2345
- const market = await query.queryMarket();
2457
+ var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
2458
+ const market = await query.queryMarket(indexer);
2346
2459
  const coinPrices = await query.utils.getCoinPrices();
2347
2460
  const coinAmounts = await query.getCoinAmounts(void 0, ownerAddress);
2348
2461
  const obligations = await query.getObligations(ownerAddress);
@@ -2352,6 +2465,7 @@ var getObligationAccounts = async (query, ownerAddress) => {
2352
2465
  query,
2353
2466
  obligation.id,
2354
2467
  ownerAddress,
2468
+ indexer,
2355
2469
  market,
2356
2470
  coinPrices,
2357
2471
  coinAmounts
@@ -2359,8 +2473,8 @@ var getObligationAccounts = async (query, ownerAddress) => {
2359
2473
  }
2360
2474
  return obligationAccounts;
2361
2475
  };
2362
- var getObligationAccount = async (query, obligationId, ownerAddress, market, coinPrices, coinAmounts) => {
2363
- market = market || await query.queryMarket();
2476
+ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = false, market, coinPrices, coinAmounts) => {
2477
+ market = market || await query.queryMarket(indexer);
2364
2478
  const assetCoinNames = [
2365
2479
  .../* @__PURE__ */ new Set([
2366
2480
  ...Object.values(market.pools).map((pool) => pool.coinName),
@@ -2370,7 +2484,10 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
2370
2484
  ])
2371
2485
  ];
2372
2486
  const obligationQuery = await query.queryObligation(obligationId);
2373
- const borrowIncentivePools = await query.getBorrowIncentivePools();
2487
+ const borrowIncentivePools = await query.getBorrowIncentivePools(
2488
+ void 0,
2489
+ indexer
2490
+ );
2374
2491
  const borrowIncentiveAccounts = await query.getBorrowIncentiveAccounts(obligationId);
2375
2492
  coinPrices = coinPrices || await query.utils.getCoinPrices(assetCoinNames);
2376
2493
  coinAmounts = coinAmounts || await query.getCoinAmounts(assetCoinNames, ownerAddress);
@@ -2405,7 +2522,13 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
2405
2522
  const requiredCollateralValue2 = depositedValue.multipliedBy(
2406
2523
  marketCollateral.liquidationFactor
2407
2524
  );
2408
- const availableDepositAmount = (0, import_bignumber3.default)(coinAmount);
2525
+ const poolSizeAmount = (0, import_bignumber3.default)(marketCollateral.maxDepositAmount).minus(
2526
+ marketCollateral.depositAmount
2527
+ );
2528
+ const availableDepositAmount = minBigNumber(
2529
+ (0, import_bignumber3.default)(coinAmount),
2530
+ poolSizeAmount
2531
+ );
2409
2532
  const availableDepositCoin = availableDepositAmount.shiftedBy(
2410
2533
  -1 * coinDecimal
2411
2534
  );
@@ -2612,10 +2735,18 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
2612
2735
  }
2613
2736
  return obligationAccount;
2614
2737
  };
2615
- var getTotalValueLocked = async (query) => {
2616
- const market = await query.queryMarket();
2738
+ var getTotalValueLocked = async (query, indexer = false) => {
2739
+ const market = await query.queryMarket(indexer);
2617
2740
  let supplyValue = (0, import_bignumber3.default)(0);
2618
2741
  let borrowValue = (0, import_bignumber3.default)(0);
2742
+ if (indexer) {
2743
+ const tvl2 = await query.indexer.getTotalValueLocked();
2744
+ return {
2745
+ supplyValue: tvl2.supplyValue,
2746
+ borrowValue: tvl2.borrowValue,
2747
+ totalValue: tvl2.totalValue
2748
+ };
2749
+ }
2619
2750
  for (const pool of Object.values(market.pools)) {
2620
2751
  supplyValue = supplyValue.plus(
2621
2752
  (0, import_bignumber3.default)(pool.supplyCoin).multipliedBy(pool.coinPrice)
@@ -2637,6 +2768,183 @@ var getTotalValueLocked = async (query) => {
2637
2768
  return tvl;
2638
2769
  };
2639
2770
 
2771
+ // src/models/scallopIndexer.ts
2772
+ var import_axios2 = __toESM(require("axios"));
2773
+ var ScallopIndexer = class {
2774
+ constructor() {
2775
+ this._requestClient = import_axios2.default.create({
2776
+ baseURL: SDK_API_BASE_URL,
2777
+ headers: {
2778
+ "Content-Type": "application/json",
2779
+ Accept: "application/json"
2780
+ },
2781
+ timeout: 3e4
2782
+ });
2783
+ }
2784
+ /**
2785
+ * Get market index data.
2786
+ *
2787
+ * @return Market data.
2788
+ */
2789
+ async getMarket() {
2790
+ const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market`);
2791
+ if (response.status === 200) {
2792
+ return {
2793
+ pools: response.data.pools.reduce((marketPools, marketPool) => {
2794
+ marketPools[marketPool.coinName] = marketPool;
2795
+ return marketPools;
2796
+ }, {}),
2797
+ collaterals: response.data.collaterals.reduce(
2798
+ (marketCollaterals, marketCollateral) => {
2799
+ marketCollaterals[marketCollateral.coinName] = marketCollateral;
2800
+ return marketCollaterals;
2801
+ },
2802
+ {}
2803
+ )
2804
+ };
2805
+ } else {
2806
+ throw Error("Failed to getMarket.");
2807
+ }
2808
+ }
2809
+ /**
2810
+ * Get market pools index data.
2811
+ *
2812
+ * @return Market pools data.
2813
+ */
2814
+ async getMarketPools() {
2815
+ const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/pools`);
2816
+ if (response.status === 200) {
2817
+ return response.data.pools.reduce((marketPools, marketPool) => {
2818
+ marketPools[marketPool.coinName] = marketPool;
2819
+ return marketPools;
2820
+ }, {});
2821
+ } else {
2822
+ throw Error("Failed to getMarketPools.");
2823
+ }
2824
+ }
2825
+ /**
2826
+ * Get market pool index data.
2827
+ *
2828
+ * @return Market pool data.
2829
+ */
2830
+ async getMarketPool(poolCoinName) {
2831
+ const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/pool/${poolCoinName}`);
2832
+ if (response.status === 200) {
2833
+ return response.data.pool;
2834
+ } else {
2835
+ throw Error("Failed to getMarketPool.");
2836
+ }
2837
+ }
2838
+ /**
2839
+ * Get market collaterals index data.
2840
+ *
2841
+ * @return Market collaterals data.
2842
+ */
2843
+ async getMarketCollaterals() {
2844
+ const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/collaterals`);
2845
+ if (response.status === 200) {
2846
+ return response.data.collaterals.reduce(
2847
+ (marketCollaterals, marketCollateral) => {
2848
+ marketCollaterals[marketCollateral.coinName] = marketCollateral;
2849
+ return marketCollaterals;
2850
+ },
2851
+ {}
2852
+ );
2853
+ } else {
2854
+ throw Error("Failed to getMarketCollaterals.");
2855
+ }
2856
+ }
2857
+ /**
2858
+ * Get market collateral index data.
2859
+ *
2860
+ * @return Market collateral data.
2861
+ */
2862
+ async getMarketCollateral(collateralCoinName) {
2863
+ const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/collateral/${collateralCoinName}`);
2864
+ if (response.status === 200) {
2865
+ return response.data.collateral;
2866
+ } else {
2867
+ throw Error("Failed to getMarketCollateral.");
2868
+ }
2869
+ }
2870
+ /**
2871
+ * Get spools index data.
2872
+ *
2873
+ * @return Spools data.
2874
+ */
2875
+ async getSpools() {
2876
+ const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/spools`);
2877
+ if (response.status === 200) {
2878
+ return response.data.spools.reduce((spools, spool) => {
2879
+ spools[spool.marketCoinName] = spool;
2880
+ return spools;
2881
+ }, {});
2882
+ } else {
2883
+ throw Error("Failed to getSpools.");
2884
+ }
2885
+ }
2886
+ /**
2887
+ * Get spool index data.
2888
+ *
2889
+ * @return Spool data.
2890
+ */
2891
+ async getSpool(marketCoinName) {
2892
+ const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/spool/${marketCoinName}`);
2893
+ if (response.status === 200) {
2894
+ return response.data.spool;
2895
+ } else {
2896
+ throw Error("Failed to getSpool.");
2897
+ }
2898
+ }
2899
+ /**
2900
+ * Get borrow incentive pools index data.
2901
+ *
2902
+ * @return Borrow incentive pools data.
2903
+ */
2904
+ async getBorrowIncentivePools() {
2905
+ const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/borrowIncentivePools`);
2906
+ if (response.status === 200) {
2907
+ return response.data.borrowIncentivePools.reduce(
2908
+ (borrowIncentivePools, borrowIncentivePool) => {
2909
+ borrowIncentivePools[borrowIncentivePool.coinName] = borrowIncentivePool;
2910
+ return borrowIncentivePools;
2911
+ },
2912
+ {}
2913
+ );
2914
+ } else {
2915
+ throw Error("Failed to getBorrowIncentivePools.");
2916
+ }
2917
+ }
2918
+ /**
2919
+ * Get borrow incentive pool index data.
2920
+ *
2921
+ * @return Borrow incentive pool data.
2922
+ */
2923
+ async getBorrowIncentivePool(borrowIncentiveCoinName) {
2924
+ const response = await this._requestClient.get(
2925
+ `${SDK_API_BASE_URL}/api/borrowIncentivePool/${borrowIncentiveCoinName}`
2926
+ );
2927
+ if (response.status === 200) {
2928
+ return response.data.borrowIncentivePool;
2929
+ } else {
2930
+ throw Error("Failed to getSpool.");
2931
+ }
2932
+ }
2933
+ /**
2934
+ * Get total value locked index data.
2935
+ *
2936
+ * @return Total value locked.
2937
+ */
2938
+ async getTotalValueLocked() {
2939
+ const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/tvl`);
2940
+ if (response.status === 200) {
2941
+ return response.data;
2942
+ } else {
2943
+ throw Error("Failed to getTotalValueLocked.");
2944
+ }
2945
+ }
2946
+ };
2947
+
2640
2948
  // src/models/scallopQuery.ts
2641
2949
  var ScallopQuery = class {
2642
2950
  constructor(params, instance) {
@@ -2651,6 +2959,7 @@ var ScallopQuery = class {
2651
2959
  address: this.address,
2652
2960
  query: this
2653
2961
  });
2962
+ this.indexer = new ScallopIndexer();
2654
2963
  }
2655
2964
  /**
2656
2965
  * Request the scallop API to initialize data.
@@ -2666,11 +2975,11 @@ var ScallopQuery = class {
2666
2975
  /* ==================== Core Query Methods ==================== */
2667
2976
  /**
2668
2977
  * Query market data.
2669
- *
2978
+ * @param indexer - Whether to use indexer.
2670
2979
  * @return Market data.
2671
2980
  */
2672
- async queryMarket() {
2673
- return await queryMarket(this);
2981
+ async queryMarket(indexer = false) {
2982
+ return await queryMarket(this, indexer);
2674
2983
  }
2675
2984
  /**
2676
2985
  * Get market pools.
@@ -2680,19 +2989,21 @@ var ScallopQuery = class {
2680
2989
  * the `queryMarket` method to reduce time consumption.
2681
2990
  *
2682
2991
  * @param poolCoinNames - Specific an array of support pool coin name.
2992
+ * @param indexer - Whether to use indexer.
2683
2993
  * @return Market pools data.
2684
2994
  */
2685
- async getMarketPools(poolCoinNames) {
2686
- return await getMarketPools(this, poolCoinNames);
2995
+ async getMarketPools(poolCoinNames, indexer = false) {
2996
+ return await getMarketPools(this, poolCoinNames, indexer);
2687
2997
  }
2688
2998
  /**
2689
2999
  * Get market pool
2690
3000
  *
2691
3001
  * @param poolCoinName - Specific support pool coin name.
3002
+ * @param indexer - Whether to use indexer.
2692
3003
  * @return Market pool data.
2693
3004
  */
2694
- async getMarketPool(poolCoinName) {
2695
- return await getMarketPool(this, poolCoinName);
3005
+ async getMarketPool(poolCoinName, indexer = false) {
3006
+ return await getMarketPool(this, poolCoinName, indexer);
2696
3007
  }
2697
3008
  /**
2698
3009
  * Get market collaterals.
@@ -2702,19 +3013,21 @@ var ScallopQuery = class {
2702
3013
  * the `queryMarket` method to reduce time consumption.
2703
3014
  *
2704
3015
  * @param collateralCoinNames - Specific an array of support collateral coin name.
3016
+ * @param indexer - Whether to use indexer.
2705
3017
  * @return Market collaterals data.
2706
3018
  */
2707
- async getMarketCollaterals(collateralCoinNames) {
2708
- return await getMarketCollaterals(this, collateralCoinNames);
3019
+ async getMarketCollaterals(collateralCoinNames, indexer = false) {
3020
+ return await getMarketCollaterals(this, collateralCoinNames, indexer);
2709
3021
  }
2710
3022
  /**
2711
3023
  * Get market collateral
2712
3024
  *
2713
3025
  * @param collateralCoinName - Specific support collateral coin name.
3026
+ * @param indexer - Whether to use indexer.
2714
3027
  * @return Market collateral data.
2715
3028
  */
2716
- async getMarketCollateral(collateralCoinName) {
2717
- return await getMarketCollateral(this, collateralCoinName);
3029
+ async getMarketCollateral(collateralCoinName, indexer = false) {
3030
+ return await getMarketCollateral(this, collateralCoinName, indexer);
2718
3031
  }
2719
3032
  /**
2720
3033
  * Get obligations data.
@@ -2788,19 +3101,21 @@ var ScallopQuery = class {
2788
3101
  * Get spools data.
2789
3102
  *
2790
3103
  * @param stakeMarketCoinNames - Specific an array of support stake market coin name.
3104
+ * @param indexer - Whether to use indexer.
2791
3105
  * @return Spools data.
2792
3106
  */
2793
- async getSpools(stakeMarketCoinNames) {
2794
- return await getSpools(this, stakeMarketCoinNames);
3107
+ async getSpools(stakeMarketCoinNames, indexer = false) {
3108
+ return await getSpools(this, stakeMarketCoinNames, indexer);
2795
3109
  }
2796
3110
  /**
2797
3111
  * Get spool data.
2798
3112
  *
2799
3113
  * @param stakeMarketCoinName - Specific support stake market coin name.
3114
+ * @param indexer - Whether to use indexer.
2800
3115
  * @return Spool data.
2801
3116
  */
2802
- async getSpool(stakeMarketCoinName) {
2803
- return await getSpool(this, stakeMarketCoinName);
3117
+ async getSpool(stakeMarketCoinName, indexer = false) {
3118
+ return await getSpool(this, stakeMarketCoinName, indexer);
2804
3119
  }
2805
3120
  /**
2806
3121
  * Get stake accounts data for all stake pools (spools).
@@ -2897,10 +3212,11 @@ var ScallopQuery = class {
2897
3212
  * Get borrow incentive pools data.
2898
3213
  *
2899
3214
  * @param coinNames - Specific an array of support borrow incentive coin name.
3215
+ * @param indexer - Whether to use indexer.
2900
3216
  * @return Borrow incentive pools data.
2901
3217
  */
2902
- async getBorrowIncentivePools(coinNames) {
2903
- return await queryBorrowIncentivePools(this, coinNames);
3218
+ async getBorrowIncentivePools(coinNames, indexer = false) {
3219
+ return await queryBorrowIncentivePools(this, coinNames, indexer);
2904
3220
  }
2905
3221
  /**
2906
3222
  * Get borrow incentive accounts data.
@@ -2917,20 +3233,22 @@ var ScallopQuery = class {
2917
3233
  *
2918
3234
  * @param poolCoinNames - Specific an array of support pool coin name.
2919
3235
  * @param ownerAddress - The owner address.
3236
+ * @param indexer - Whether to use indexer.
2920
3237
  * @return All lending and spool infomation.
2921
3238
  */
2922
- async getLendings(poolCoinNames, ownerAddress) {
2923
- return await getLendings(this, poolCoinNames, ownerAddress);
3239
+ async getLendings(poolCoinNames, ownerAddress, indexer = false) {
3240
+ return await getLendings(this, poolCoinNames, ownerAddress, indexer);
2924
3241
  }
2925
3242
  /**
2926
3243
  * Get user lending and spool information for specific pool.
2927
3244
  *
2928
3245
  * @param poolCoinName - Specific support pool coin name.
2929
3246
  * @param ownerAddress - The owner address.
3247
+ * @param indexer - Whether to use indexer.
2930
3248
  * @return Lending pool data.
2931
3249
  */
2932
- async getLending(poolCoinName, ownerAddress) {
2933
- return await getLending(this, poolCoinName, ownerAddress);
3250
+ async getLending(poolCoinName, ownerAddress, indexer = false) {
3251
+ return await getLending(this, poolCoinName, ownerAddress, indexer);
2934
3252
  }
2935
3253
  /**
2936
3254
  * Get user all obligation accounts information.
@@ -2939,10 +3257,11 @@ var ScallopQuery = class {
2939
3257
  * All collateral and borrowing information in all obligation accounts owned by the user.
2940
3258
  *
2941
3259
  * @param ownerAddress - The owner address.
3260
+ * @param indexer - Whether to use indexer.
2942
3261
  * @return All obligation accounts information.
2943
3262
  */
2944
- async getObligationAccounts(ownerAddress) {
2945
- return await getObligationAccounts(this, ownerAddress);
3263
+ async getObligationAccounts(ownerAddress, indexer = false) {
3264
+ return await getObligationAccounts(this, ownerAddress, indexer);
2946
3265
  }
2947
3266
  /**
2948
3267
  * Get obligation account information for specific id.
@@ -2952,21 +3271,28 @@ var ScallopQuery = class {
2952
3271
  *
2953
3272
  * @param obligationId - The obligation id.
2954
3273
  * @param ownerAddress - The owner address.
3274
+ * @param indexer - Whether to use indexer.
2955
3275
  * @return Borrowing and collateral information.
2956
3276
  */
2957
- async getObligationAccount(obligationId, ownerAddress) {
2958
- return await getObligationAccount(this, obligationId, ownerAddress);
3277
+ async getObligationAccount(obligationId, ownerAddress, indexer = false) {
3278
+ return await getObligationAccount(
3279
+ this,
3280
+ obligationId,
3281
+ ownerAddress,
3282
+ indexer
3283
+ );
2959
3284
  }
2960
3285
  /**
2961
3286
  * Get total value locked.
2962
3287
  *
3288
+ * @param indexer - Whether to use indexer.
2963
3289
  * @description
2964
3290
  * Include total supplied value and total borrowed value.
2965
3291
  *
2966
3292
  * @return Total value locked.
2967
3293
  */
2968
- async getTvl() {
2969
- return await getTotalValueLocked(this);
3294
+ async getTvl(indexer = false) {
3295
+ return await getTotalValueLocked(this, indexer);
2970
3296
  }
2971
3297
  };
2972
3298
 
@@ -4783,6 +5109,15 @@ var Scallop = class {
4783
5109
  });
4784
5110
  return scallopQuery;
4785
5111
  }
5112
+ /**
5113
+ * Create a scallop indexer instance.
5114
+ *
5115
+ * @return Scallop Indexer.
5116
+ */
5117
+ async createScallopIndexer() {
5118
+ const scallopIndexer = new ScallopIndexer();
5119
+ return scallopIndexer;
5120
+ }
4786
5121
  /**
4787
5122
  * Create a scallop utils instance.
4788
5123
  *
@@ -4804,6 +5139,7 @@ var Scallop = class {
4804
5139
  API_BASE_URL,
4805
5140
  BORROW_FEE_PROTOCOL_ID,
4806
5141
  PROTOCOL_OBJECT_ID,
5142
+ SDK_API_BASE_URL,
4807
5143
  SUPPORT_BORROW_INCENTIVE_POOLS,
4808
5144
  SUPPORT_BORROW_INCENTIVE_REWARDS,
4809
5145
  SUPPORT_COLLATERALS,
@@ -4816,6 +5152,7 @@ var Scallop = class {
4816
5152
  ScallopAddress,
4817
5153
  ScallopBuilder,
4818
5154
  ScallopClient,
5155
+ ScallopIndexer,
4819
5156
  ScallopQuery,
4820
5157
  ScallopUtils,
4821
5158
  assetCoins,