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

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://sui-scallop-sdk-api.vercel.app";
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);
@@ -2612,10 +2729,18 @@ var getObligationAccount = async (query, obligationId, ownerAddress, market, coi
2612
2729
  }
2613
2730
  return obligationAccount;
2614
2731
  };
2615
- var getTotalValueLocked = async (query) => {
2616
- const market = await query.queryMarket();
2732
+ var getTotalValueLocked = async (query, indexer = false) => {
2733
+ const market = await query.queryMarket(indexer);
2617
2734
  let supplyValue = (0, import_bignumber3.default)(0);
2618
2735
  let borrowValue = (0, import_bignumber3.default)(0);
2736
+ if (indexer) {
2737
+ const tvl2 = await query.indexer.getTotalValueLocked();
2738
+ return {
2739
+ supplyValue: tvl2.supplyValue,
2740
+ borrowValue: tvl2.borrowValue,
2741
+ totalValue: tvl2.totalValue
2742
+ };
2743
+ }
2619
2744
  for (const pool of Object.values(market.pools)) {
2620
2745
  supplyValue = supplyValue.plus(
2621
2746
  (0, import_bignumber3.default)(pool.supplyCoin).multipliedBy(pool.coinPrice)
@@ -2637,6 +2762,183 @@ var getTotalValueLocked = async (query) => {
2637
2762
  return tvl;
2638
2763
  };
2639
2764
 
2765
+ // src/models/scallopIndexer.ts
2766
+ var import_axios2 = __toESM(require("axios"));
2767
+ var ScallopIndexer = class {
2768
+ constructor() {
2769
+ this._requestClient = import_axios2.default.create({
2770
+ baseURL: SDK_API_BASE_URL,
2771
+ headers: {
2772
+ "Content-Type": "application/json",
2773
+ Accept: "application/json"
2774
+ },
2775
+ timeout: 3e4
2776
+ });
2777
+ }
2778
+ /**
2779
+ * Get market index data.
2780
+ *
2781
+ * @return Market data.
2782
+ */
2783
+ async getMarket() {
2784
+ const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market`);
2785
+ if (response.status === 200) {
2786
+ return {
2787
+ pools: response.data.pools.reduce((marketPools, marketPool) => {
2788
+ marketPools[marketPool.coinName] = marketPool;
2789
+ return marketPools;
2790
+ }, {}),
2791
+ collaterals: response.data.collaterals.reduce(
2792
+ (marketCollaterals, marketCollateral) => {
2793
+ marketCollaterals[marketCollateral.coinName] = marketCollateral;
2794
+ return marketCollaterals;
2795
+ },
2796
+ {}
2797
+ )
2798
+ };
2799
+ } else {
2800
+ throw Error("Failed to getMarket.");
2801
+ }
2802
+ }
2803
+ /**
2804
+ * Get market pools index data.
2805
+ *
2806
+ * @return Market pools data.
2807
+ */
2808
+ async getMarketPools() {
2809
+ const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/pools`);
2810
+ if (response.status === 200) {
2811
+ return response.data.pools.reduce((marketPools, marketPool) => {
2812
+ marketPools[marketPool.coinName] = marketPool;
2813
+ return marketPools;
2814
+ }, {});
2815
+ } else {
2816
+ throw Error("Failed to getMarketPools.");
2817
+ }
2818
+ }
2819
+ /**
2820
+ * Get market pool index data.
2821
+ *
2822
+ * @return Market pool data.
2823
+ */
2824
+ async getMarketPool(poolCoinName) {
2825
+ const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/pool/${poolCoinName}`);
2826
+ if (response.status === 200) {
2827
+ return response.data.pool;
2828
+ } else {
2829
+ throw Error("Failed to getMarketPool.");
2830
+ }
2831
+ }
2832
+ /**
2833
+ * Get market collaterals index data.
2834
+ *
2835
+ * @return Market collaterals data.
2836
+ */
2837
+ async getMarketCollaterals() {
2838
+ const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/collaterals`);
2839
+ if (response.status === 200) {
2840
+ return response.data.collaterals.reduce(
2841
+ (marketCollaterals, marketCollateral) => {
2842
+ marketCollaterals[marketCollateral.coinName] = marketCollateral;
2843
+ return marketCollaterals;
2844
+ },
2845
+ {}
2846
+ );
2847
+ } else {
2848
+ throw Error("Failed to getMarketCollaterals.");
2849
+ }
2850
+ }
2851
+ /**
2852
+ * Get market collateral index data.
2853
+ *
2854
+ * @return Market collateral data.
2855
+ */
2856
+ async getMarketCollateral(collateralCoinName) {
2857
+ const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/collateral/${collateralCoinName}`);
2858
+ if (response.status === 200) {
2859
+ return response.data.collateral;
2860
+ } else {
2861
+ throw Error("Failed to getMarketCollateral.");
2862
+ }
2863
+ }
2864
+ /**
2865
+ * Get spools index data.
2866
+ *
2867
+ * @return Spools data.
2868
+ */
2869
+ async getSpools() {
2870
+ const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/spools`);
2871
+ if (response.status === 200) {
2872
+ return response.data.spools.reduce((spools, spool) => {
2873
+ spools[spool.marketCoinName] = spool;
2874
+ return spools;
2875
+ }, {});
2876
+ } else {
2877
+ throw Error("Failed to getSpools.");
2878
+ }
2879
+ }
2880
+ /**
2881
+ * Get spool index data.
2882
+ *
2883
+ * @return Spool data.
2884
+ */
2885
+ async getSpool(marketCoinName) {
2886
+ const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/spool/${marketCoinName}`);
2887
+ if (response.status === 200) {
2888
+ return response.data.spool;
2889
+ } else {
2890
+ throw Error("Failed to getSpool.");
2891
+ }
2892
+ }
2893
+ /**
2894
+ * Get borrow incentive pools index data.
2895
+ *
2896
+ * @return Borrow incentive pools data.
2897
+ */
2898
+ async getBorrowIncentivePools() {
2899
+ const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/borrowIncentivePools`);
2900
+ if (response.status === 200) {
2901
+ return response.data.borrowIncentivePools.reduce(
2902
+ (borrowIncentivePools, borrowIncentivePool) => {
2903
+ borrowIncentivePools[borrowIncentivePool.coinName] = borrowIncentivePool;
2904
+ return borrowIncentivePools;
2905
+ },
2906
+ {}
2907
+ );
2908
+ } else {
2909
+ throw Error("Failed to getBorrowIncentivePools.");
2910
+ }
2911
+ }
2912
+ /**
2913
+ * Get borrow incentive pool index data.
2914
+ *
2915
+ * @return Borrow incentive pool data.
2916
+ */
2917
+ async getBorrowIncentivePool(borrowIncentiveCoinName) {
2918
+ const response = await this._requestClient.get(
2919
+ `${SDK_API_BASE_URL}/api/borrowIncentivePool/${borrowIncentiveCoinName}`
2920
+ );
2921
+ if (response.status === 200) {
2922
+ return response.data.borrowIncentivePool;
2923
+ } else {
2924
+ throw Error("Failed to getSpool.");
2925
+ }
2926
+ }
2927
+ /**
2928
+ * Get total value locked index data.
2929
+ *
2930
+ * @return Total value locked.
2931
+ */
2932
+ async getTotalValueLocked() {
2933
+ const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/tvl`);
2934
+ if (response.status === 200) {
2935
+ return response.data;
2936
+ } else {
2937
+ throw Error("Failed to getTotalValueLocked.");
2938
+ }
2939
+ }
2940
+ };
2941
+
2640
2942
  // src/models/scallopQuery.ts
2641
2943
  var ScallopQuery = class {
2642
2944
  constructor(params, instance) {
@@ -2651,6 +2953,7 @@ var ScallopQuery = class {
2651
2953
  address: this.address,
2652
2954
  query: this
2653
2955
  });
2956
+ this.indexer = new ScallopIndexer();
2654
2957
  }
2655
2958
  /**
2656
2959
  * Request the scallop API to initialize data.
@@ -2666,11 +2969,11 @@ var ScallopQuery = class {
2666
2969
  /* ==================== Core Query Methods ==================== */
2667
2970
  /**
2668
2971
  * Query market data.
2669
- *
2972
+ * @param indexer - Whether to use indexer.
2670
2973
  * @return Market data.
2671
2974
  */
2672
- async queryMarket() {
2673
- return await queryMarket(this);
2975
+ async queryMarket(indexer = false) {
2976
+ return await queryMarket(this, indexer);
2674
2977
  }
2675
2978
  /**
2676
2979
  * Get market pools.
@@ -2680,19 +2983,21 @@ var ScallopQuery = class {
2680
2983
  * the `queryMarket` method to reduce time consumption.
2681
2984
  *
2682
2985
  * @param poolCoinNames - Specific an array of support pool coin name.
2986
+ * @param indexer - Whether to use indexer.
2683
2987
  * @return Market pools data.
2684
2988
  */
2685
- async getMarketPools(poolCoinNames) {
2686
- return await getMarketPools(this, poolCoinNames);
2989
+ async getMarketPools(poolCoinNames, indexer = false) {
2990
+ return await getMarketPools(this, poolCoinNames, indexer);
2687
2991
  }
2688
2992
  /**
2689
2993
  * Get market pool
2690
2994
  *
2691
2995
  * @param poolCoinName - Specific support pool coin name.
2996
+ * @param indexer - Whether to use indexer.
2692
2997
  * @return Market pool data.
2693
2998
  */
2694
- async getMarketPool(poolCoinName) {
2695
- return await getMarketPool(this, poolCoinName);
2999
+ async getMarketPool(poolCoinName, indexer = false) {
3000
+ return await getMarketPool(this, poolCoinName, indexer);
2696
3001
  }
2697
3002
  /**
2698
3003
  * Get market collaterals.
@@ -2702,19 +3007,21 @@ var ScallopQuery = class {
2702
3007
  * the `queryMarket` method to reduce time consumption.
2703
3008
  *
2704
3009
  * @param collateralCoinNames - Specific an array of support collateral coin name.
3010
+ * @param indexer - Whether to use indexer.
2705
3011
  * @return Market collaterals data.
2706
3012
  */
2707
- async getMarketCollaterals(collateralCoinNames) {
2708
- return await getMarketCollaterals(this, collateralCoinNames);
3013
+ async getMarketCollaterals(collateralCoinNames, indexer = false) {
3014
+ return await getMarketCollaterals(this, collateralCoinNames, indexer);
2709
3015
  }
2710
3016
  /**
2711
3017
  * Get market collateral
2712
3018
  *
2713
3019
  * @param collateralCoinName - Specific support collateral coin name.
3020
+ * @param indexer - Whether to use indexer.
2714
3021
  * @return Market collateral data.
2715
3022
  */
2716
- async getMarketCollateral(collateralCoinName) {
2717
- return await getMarketCollateral(this, collateralCoinName);
3023
+ async getMarketCollateral(collateralCoinName, indexer = false) {
3024
+ return await getMarketCollateral(this, collateralCoinName, indexer);
2718
3025
  }
2719
3026
  /**
2720
3027
  * Get obligations data.
@@ -2788,19 +3095,21 @@ var ScallopQuery = class {
2788
3095
  * Get spools data.
2789
3096
  *
2790
3097
  * @param stakeMarketCoinNames - Specific an array of support stake market coin name.
3098
+ * @param indexer - Whether to use indexer.
2791
3099
  * @return Spools data.
2792
3100
  */
2793
- async getSpools(stakeMarketCoinNames) {
2794
- return await getSpools(this, stakeMarketCoinNames);
3101
+ async getSpools(stakeMarketCoinNames, indexer = false) {
3102
+ return await getSpools(this, stakeMarketCoinNames, indexer);
2795
3103
  }
2796
3104
  /**
2797
3105
  * Get spool data.
2798
3106
  *
2799
3107
  * @param stakeMarketCoinName - Specific support stake market coin name.
3108
+ * @param indexer - Whether to use indexer.
2800
3109
  * @return Spool data.
2801
3110
  */
2802
- async getSpool(stakeMarketCoinName) {
2803
- return await getSpool(this, stakeMarketCoinName);
3111
+ async getSpool(stakeMarketCoinName, indexer = false) {
3112
+ return await getSpool(this, stakeMarketCoinName, indexer);
2804
3113
  }
2805
3114
  /**
2806
3115
  * Get stake accounts data for all stake pools (spools).
@@ -2897,10 +3206,11 @@ var ScallopQuery = class {
2897
3206
  * Get borrow incentive pools data.
2898
3207
  *
2899
3208
  * @param coinNames - Specific an array of support borrow incentive coin name.
3209
+ * @param indexer - Whether to use indexer.
2900
3210
  * @return Borrow incentive pools data.
2901
3211
  */
2902
- async getBorrowIncentivePools(coinNames) {
2903
- return await queryBorrowIncentivePools(this, coinNames);
3212
+ async getBorrowIncentivePools(coinNames, indexer = false) {
3213
+ return await queryBorrowIncentivePools(this, coinNames, indexer);
2904
3214
  }
2905
3215
  /**
2906
3216
  * Get borrow incentive accounts data.
@@ -2917,20 +3227,22 @@ var ScallopQuery = class {
2917
3227
  *
2918
3228
  * @param poolCoinNames - Specific an array of support pool coin name.
2919
3229
  * @param ownerAddress - The owner address.
3230
+ * @param indexer - Whether to use indexer.
2920
3231
  * @return All lending and spool infomation.
2921
3232
  */
2922
- async getLendings(poolCoinNames, ownerAddress) {
2923
- return await getLendings(this, poolCoinNames, ownerAddress);
3233
+ async getLendings(poolCoinNames, ownerAddress, indexer = false) {
3234
+ return await getLendings(this, poolCoinNames, ownerAddress, indexer);
2924
3235
  }
2925
3236
  /**
2926
3237
  * Get user lending and spool information for specific pool.
2927
3238
  *
2928
3239
  * @param poolCoinName - Specific support pool coin name.
2929
3240
  * @param ownerAddress - The owner address.
3241
+ * @param indexer - Whether to use indexer.
2930
3242
  * @return Lending pool data.
2931
3243
  */
2932
- async getLending(poolCoinName, ownerAddress) {
2933
- return await getLending(this, poolCoinName, ownerAddress);
3244
+ async getLending(poolCoinName, ownerAddress, indexer = false) {
3245
+ return await getLending(this, poolCoinName, ownerAddress, indexer);
2934
3246
  }
2935
3247
  /**
2936
3248
  * Get user all obligation accounts information.
@@ -2939,10 +3251,11 @@ var ScallopQuery = class {
2939
3251
  * All collateral and borrowing information in all obligation accounts owned by the user.
2940
3252
  *
2941
3253
  * @param ownerAddress - The owner address.
3254
+ * @param indexer - Whether to use indexer.
2942
3255
  * @return All obligation accounts information.
2943
3256
  */
2944
- async getObligationAccounts(ownerAddress) {
2945
- return await getObligationAccounts(this, ownerAddress);
3257
+ async getObligationAccounts(ownerAddress, indexer = false) {
3258
+ return await getObligationAccounts(this, ownerAddress, indexer);
2946
3259
  }
2947
3260
  /**
2948
3261
  * Get obligation account information for specific id.
@@ -2952,21 +3265,28 @@ var ScallopQuery = class {
2952
3265
  *
2953
3266
  * @param obligationId - The obligation id.
2954
3267
  * @param ownerAddress - The owner address.
3268
+ * @param indexer - Whether to use indexer.
2955
3269
  * @return Borrowing and collateral information.
2956
3270
  */
2957
- async getObligationAccount(obligationId, ownerAddress) {
2958
- return await getObligationAccount(this, obligationId, ownerAddress);
3271
+ async getObligationAccount(obligationId, ownerAddress, indexer = false) {
3272
+ return await getObligationAccount(
3273
+ this,
3274
+ obligationId,
3275
+ ownerAddress,
3276
+ indexer
3277
+ );
2959
3278
  }
2960
3279
  /**
2961
3280
  * Get total value locked.
2962
3281
  *
3282
+ * @param indexer - Whether to use indexer.
2963
3283
  * @description
2964
3284
  * Include total supplied value and total borrowed value.
2965
3285
  *
2966
3286
  * @return Total value locked.
2967
3287
  */
2968
- async getTvl() {
2969
- return await getTotalValueLocked(this);
3288
+ async getTvl(indexer = false) {
3289
+ return await getTotalValueLocked(this, indexer);
2970
3290
  }
2971
3291
  };
2972
3292
 
@@ -4783,6 +5103,15 @@ var Scallop = class {
4783
5103
  });
4784
5104
  return scallopQuery;
4785
5105
  }
5106
+ /**
5107
+ * Create a scallop indexer instance.
5108
+ *
5109
+ * @return Scallop Indexer.
5110
+ */
5111
+ async createScallopIndexer() {
5112
+ const scallopIndexer = new ScallopIndexer();
5113
+ return scallopIndexer;
5114
+ }
4786
5115
  /**
4787
5116
  * Create a scallop utils instance.
4788
5117
  *
@@ -4804,6 +5133,7 @@ var Scallop = class {
4804
5133
  API_BASE_URL,
4805
5134
  BORROW_FEE_PROTOCOL_ID,
4806
5135
  PROTOCOL_OBJECT_ID,
5136
+ SDK_API_BASE_URL,
4807
5137
  SUPPORT_BORROW_INCENTIVE_POOLS,
4808
5138
  SUPPORT_BORROW_INCENTIVE_REWARDS,
4809
5139
  SUPPORT_COLLATERALS,
@@ -4816,6 +5146,7 @@ var Scallop = class {
4816
5146
  ScallopAddress,
4817
5147
  ScallopBuilder,
4818
5148
  ScallopClient,
5149
+ ScallopIndexer,
4819
5150
  ScallopQuery,
4820
5151
  ScallopUtils,
4821
5152
  assetCoins,