@scallop-io/sui-scallop-sdk 0.44.28 → 0.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -194,6 +194,197 @@ var MIN_TOP_UP_AMOUNT = 1e9;
194
194
  // src/models/scallop.ts
195
195
  import { SuiKit as SuiKit5 } from "@scallop-io/sui-kit";
196
196
 
197
+ // src/models/scallopCache.ts
198
+ import { QueryClient } from "@tanstack/query-core";
199
+ import { SuiTxBlock } from "@scallop-io/sui-kit";
200
+
201
+ // src/constants/cache.ts
202
+ var DEFAULT_CACHE_OPTIONS = {
203
+ defaultOptions: {
204
+ queries: {
205
+ staleTime: 3e3
206
+ }
207
+ }
208
+ };
209
+
210
+ // src/models/scallopCache.ts
211
+ var ScallopCache = class {
212
+ constructor(cacheOptions, suiKit) {
213
+ this.queryClient = new QueryClient(cacheOptions ?? DEFAULT_CACHE_OPTIONS);
214
+ this._suiKit = suiKit;
215
+ }
216
+ get suiKit() {
217
+ if (!this._suiKit) {
218
+ throw new Error("SuiKit instance is not initialized");
219
+ }
220
+ return this._suiKit;
221
+ }
222
+ /**
223
+ * @description Invalidate cache based on the refetchType parameter
224
+ * @param refetchType Determines the type of queries to be refetched. Defaults to `active`.
225
+ *
226
+ * - `active`: Only queries that match the refetch predicate and are actively being rendered via useQuery and related functions will be refetched in the background.
227
+ * - `inactive`: Only queries that match the refetch predicate and are NOT actively being rendered via useQuery and related functions will be refetched in the background.
228
+ * - `all`: All queries that match the refetch predicate will be refetched in the background.
229
+ * - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
230
+ */
231
+ invalidateAndRefetchAllCache(refetchType) {
232
+ return this.queryClient.invalidateQueries({
233
+ refetchType
234
+ });
235
+ }
236
+ /**
237
+ * @description Cache protocol config call for 60 seconds.
238
+ * @returns Promise<ProtocolConfig>
239
+ */
240
+ async getProtocolConfig() {
241
+ return await this.queryClient.fetchQuery({
242
+ queryKey: ["getProtocolConfig"],
243
+ queryFn: async () => {
244
+ return await this.suiKit.client().getProtocolConfig();
245
+ },
246
+ staleTime: 3e4
247
+ });
248
+ }
249
+ /**
250
+ * @description Provides cache for inspectTxn of the SuiKit.
251
+ * @param QueryInspectTxnParams
252
+ * @param txBlock
253
+ * @returns Promise<DevInspectResults>
254
+ */
255
+ async queryInspectTxn({
256
+ queryTarget,
257
+ args,
258
+ typeArgs
259
+ }) {
260
+ const txBlock = new SuiTxBlock();
261
+ const resolvedArgs = await Promise.all(
262
+ args.map(async (arg) => {
263
+ if (typeof arg === "string") {
264
+ return (await this.queryGetObject(arg, { showContent: true })).data;
265
+ }
266
+ return arg;
267
+ })
268
+ );
269
+ txBlock.moveCall(queryTarget, resolvedArgs, typeArgs);
270
+ const txBytes = await txBlock.txBlock.build({
271
+ client: this.suiKit.client(),
272
+ onlyTransactionKind: true,
273
+ protocolConfig: await this.getProtocolConfig()
274
+ });
275
+ const query = await this.queryClient.fetchQuery({
276
+ queryKey: typeArgs ? ["inspectTxn", queryTarget, JSON.stringify(args)] : [
277
+ "inspectTxn",
278
+ queryTarget,
279
+ JSON.stringify(args),
280
+ JSON.stringify(typeArgs)
281
+ ],
282
+ queryFn: async () => {
283
+ return await this.suiKit.inspectTxn(txBytes);
284
+ },
285
+ staleTime: 8e3
286
+ // make stale time longer for inspectTxn results
287
+ });
288
+ return query;
289
+ }
290
+ /**
291
+ * @description Provides cache for getObject of the SuiKit.
292
+ * @param objectId
293
+ * @param QueryObjectParams
294
+ * @returns Promise<SuiObjectResponse>
295
+ */
296
+ async queryGetObject(objectId, options) {
297
+ const queryKey = ["getObject", objectId, this.suiKit.currentAddress()];
298
+ if (options) {
299
+ queryKey.push(JSON.stringify(options));
300
+ }
301
+ return this.queryClient.fetchQuery({
302
+ queryKey,
303
+ queryFn: async () => {
304
+ return await this.suiKit.client().getObject({
305
+ id: objectId,
306
+ options
307
+ });
308
+ }
309
+ });
310
+ }
311
+ /**
312
+ * @description Provides cache for getObjects of the SuiKit.
313
+ * @param objectIds
314
+ * @returns Promise<SuiObjectData[]>
315
+ */
316
+ async queryGetObjects(objectIds, options) {
317
+ const queryKey = [
318
+ "getObjects",
319
+ JSON.stringify(objectIds),
320
+ this.suiKit.currentAddress()
321
+ ];
322
+ return this.queryClient.fetchQuery({
323
+ queryKey,
324
+ queryFn: async () => {
325
+ return await this.suiKit.getObjects(objectIds, options);
326
+ }
327
+ });
328
+ }
329
+ /**
330
+ * @description Provides cache for getOwnedObjects of the SuiKit.
331
+ * @param input
332
+ * @returns Promise<PaginatedObjectsResponse>
333
+ */
334
+ async queryGetOwnedObjects(input) {
335
+ const queryKey = ["getOwnedObjects", input.owner];
336
+ if (input.cursor) {
337
+ queryKey.push(JSON.stringify(input.cursor));
338
+ }
339
+ if (input.options) {
340
+ queryKey.push(JSON.stringify(input.options));
341
+ }
342
+ if (input.filter) {
343
+ queryKey.push(JSON.stringify(input.filter));
344
+ }
345
+ if (input.limit) {
346
+ queryKey.push(JSON.stringify(input.limit));
347
+ }
348
+ return this.queryClient.fetchQuery({
349
+ queryKey,
350
+ queryFn: async () => {
351
+ return await this.suiKit.client().getOwnedObjects(input);
352
+ }
353
+ });
354
+ }
355
+ async queryGetDynamicFields(input) {
356
+ const queryKey = ["getDynamicFields", input.parentId];
357
+ if (input.cursor) {
358
+ queryKey.push(JSON.stringify(input.cursor));
359
+ }
360
+ if (input.cursor) {
361
+ queryKey.push(JSON.stringify(input.cursor));
362
+ }
363
+ if (input.limit) {
364
+ queryKey.push(JSON.stringify(input.limit));
365
+ }
366
+ return this.queryClient.fetchQuery({
367
+ queryKey,
368
+ queryFn: async () => {
369
+ return await this.suiKit.client().getDynamicFields(input);
370
+ }
371
+ });
372
+ }
373
+ async queryGetDynamicFieldObject(input) {
374
+ const queryKey = [
375
+ "getDynamicFieldObject",
376
+ input.parentId,
377
+ input.name.value
378
+ ];
379
+ return this.queryClient.fetchQuery({
380
+ queryKey,
381
+ queryFn: async () => {
382
+ return await this.suiKit.client().getDynamicFieldObject(input);
383
+ }
384
+ });
385
+ }
386
+ };
387
+
197
388
  // src/models/scallopAddress.ts
198
389
  import axios from "axios";
199
390
  var EMPTY_ADDRESSES = {
@@ -446,13 +637,9 @@ var EMPTY_ADDRESSES = {
446
637
  }
447
638
  };
448
639
  var ScallopAddress = class {
449
- constructor(params) {
640
+ constructor(params, cache) {
450
641
  const { id, auth, network } = params;
451
- if (auth)
452
- this._auth = auth;
453
- this._id = id;
454
- this._network = network || "mainnet";
455
- this._addressesMap = /* @__PURE__ */ new Map();
642
+ this._cache = cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS);
456
643
  this._requestClient = axios.create({
457
644
  baseURL: API_BASE_URL,
458
645
  headers: {
@@ -461,6 +648,11 @@ var ScallopAddress = class {
461
648
  },
462
649
  timeout: 3e4
463
650
  });
651
+ if (auth)
652
+ this._auth = auth;
653
+ this._id = id;
654
+ this._network = network || "mainnet";
655
+ this._addressesMap = /* @__PURE__ */ new Map();
464
656
  }
465
657
  /**
466
658
  * Get addresses API id.
@@ -584,7 +776,7 @@ var ScallopAddress = class {
584
776
  this._addressesMap.clear();
585
777
  this.setAddresses(targetAddresses, targetNetwork);
586
778
  const response = await this._requestClient.post(
587
- `${API_BASE_URL}/addresses`,
779
+ `/addresses`,
588
780
  JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
589
781
  {
590
782
  headers: {
@@ -621,14 +813,16 @@ var ScallopAddress = class {
621
813
  async read(id) {
622
814
  const addressesId = id || this._id || void 0;
623
815
  if (addressesId !== void 0) {
624
- const response = await this._requestClient.get(
625
- `${API_BASE_URL}/addresses/${addressesId}`,
626
- {
627
- headers: {
628
- "Content-Type": "application/json"
629
- }
816
+ const response = await this._cache.queryClient.fetchQuery({
817
+ queryKey: ["api-getAddresses", addressesId],
818
+ queryFn: async () => {
819
+ return await this._requestClient.get(`/addresses/${addressesId}`, {
820
+ headers: {
821
+ "Content-Type": "application/json"
822
+ }
823
+ });
630
824
  }
631
- );
825
+ });
632
826
  if (response.status === 200) {
633
827
  for (const [network, addresses] of Object.entries(
634
828
  response.data
@@ -682,7 +876,7 @@ var ScallopAddress = class {
682
876
  }
683
877
  this.setAddresses(targetAddresses, targetNetwork);
684
878
  const response = await this._requestClient.put(
685
- `${API_BASE_URL}/addresses/${targetId}`,
879
+ `/addresses/${targetId}`,
686
880
  JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
687
881
  {
688
882
  headers: {
@@ -724,7 +918,7 @@ var ScallopAddress = class {
724
918
  throw Error("Require specific addresses id to be deleted.");
725
919
  if (apiKey !== void 0) {
726
920
  const response = await this._requestClient.delete(
727
- `${API_BASE_URL}/addresses/${targetId}`,
921
+ `/addresses/${targetId}`,
728
922
  {
729
923
  headers: {
730
924
  "Content-Type": "application/json",
@@ -759,7 +953,6 @@ import { SuiKit } from "@scallop-io/sui-kit";
759
953
 
760
954
  // src/queries/coreQuery.ts
761
955
  import { normalizeStructTag as normalizeStructTag2 } from "@mysten/sui.js/utils";
762
- import { SuiTxBlock as SuiKitTxBlock } from "@scallop-io/sui-kit";
763
956
  import BigNumber2 from "bignumber.js";
764
957
 
765
958
  // src/utils/builder.ts
@@ -1311,10 +1504,12 @@ var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
1311
1504
  var queryMarket = async (query, indexer = false) => {
1312
1505
  const packageId = query.address.get("core.packages.query.id");
1313
1506
  const marketId = query.address.get("core.market");
1314
- const txBlock = new SuiKitTxBlock();
1315
1507
  const queryTarget = `${packageId}::market_query::market_data`;
1316
- txBlock.moveCall(queryTarget, [marketId]);
1317
- const queryResult = await query.suiKit.inspectTxn(txBlock);
1508
+ const args = [marketId];
1509
+ const queryResult = await query.cache.queryInspectTxn(
1510
+ { queryTarget, args }
1511
+ // txBlock
1512
+ );
1318
1513
  const marketData = queryResult.events[0].parsedJson;
1319
1514
  const coinPrices = await query.utils.getCoinPrices();
1320
1515
  const pools = {};
@@ -1432,11 +1627,8 @@ var queryMarket = async (query, indexer = false) => {
1432
1627
  var getMarketPools = async (query, poolCoinNames, indexer = false) => {
1433
1628
  poolCoinNames = poolCoinNames || [...SUPPORT_POOLS];
1434
1629
  const marketId = query.address.get("core.market");
1435
- const marketObjectResponse = await query.suiKit.client().getObject({
1436
- id: marketId,
1437
- options: {
1438
- showContent: true
1439
- }
1630
+ const marketObjectResponse = await query.cache.queryGetObject(marketId, {
1631
+ showContent: true
1440
1632
  });
1441
1633
  const coinPrices = await query.utils.getCoinPrices(poolCoinNames ?? []);
1442
1634
  const marketPools = {};
@@ -1469,11 +1661,8 @@ var getMarketPools = async (query, poolCoinNames, indexer = false) => {
1469
1661
  };
1470
1662
  var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, coinPrice) => {
1471
1663
  const marketId = query.address.get("core.market");
1472
- marketObject = marketObject || (await query.suiKit.client().getObject({
1473
- id: marketId,
1474
- options: {
1475
- showContent: true
1476
- }
1664
+ marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
1665
+ showContent: true
1477
1666
  })).data;
1478
1667
  coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
1479
1668
  let marketPool;
@@ -1494,7 +1683,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
1494
1683
  const fields = marketObject.content.fields;
1495
1684
  const coinType = query.utils.parseCoinType(poolCoinName);
1496
1685
  const balanceSheetParentId = fields.vault.fields.balance_sheets.fields.table.fields.id.id;
1497
- const balanceSheetDynamicFieldObjectResponse = await query.suiKit.client().getDynamicFieldObject({
1686
+ const balanceSheetDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
1498
1687
  parentId: balanceSheetParentId,
1499
1688
  name: {
1500
1689
  type: "0x1::type_name::TypeName",
@@ -1509,7 +1698,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
1509
1698
  balanceSheet = dynamicFields.value.fields;
1510
1699
  }
1511
1700
  const borrowIndexParentId = fields.borrow_dynamics.fields.table.fields.id.id;
1512
- const borrowIndexDynamicFieldObjectResponse = await query.suiKit.client().getDynamicFieldObject({
1701
+ const borrowIndexDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
1513
1702
  parentId: borrowIndexParentId,
1514
1703
  name: {
1515
1704
  type: "0x1::type_name::TypeName",
@@ -1524,7 +1713,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
1524
1713
  borrowIndex = dynamicFields.value.fields;
1525
1714
  }
1526
1715
  const interestModelParentId = fields.interest_models.fields.table.fields.id.id;
1527
- const interestModelDynamicFieldObjectResponse = await query.suiKit.client().getDynamicFieldObject({
1716
+ const interestModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
1528
1717
  parentId: interestModelParentId,
1529
1718
  name: {
1530
1719
  type: "0x1::type_name::TypeName",
@@ -1538,7 +1727,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
1538
1727
  const dynamicFields = interestModelDynamicFieldObject.content.fields;
1539
1728
  interestModel = dynamicFields.value.fields;
1540
1729
  }
1541
- const borrowFeeDynamicFieldObjectResponse = await query.suiKit.client().getDynamicFieldObject({
1730
+ const borrowFeeDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
1542
1731
  parentId: marketId,
1543
1732
  name: {
1544
1733
  type: `${BORROW_FEE_PROTOCOL_ID}::market_dynamic_keys::BorrowFeeKey`,
@@ -1605,11 +1794,8 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
1605
1794
  var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) => {
1606
1795
  collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
1607
1796
  const marketId = query.address.get("core.market");
1608
- const marketObjectResponse = await query.suiKit.client().getObject({
1609
- id: marketId,
1610
- options: {
1611
- showContent: true
1612
- }
1797
+ const marketObjectResponse = await query.cache.queryGetObject(marketId, {
1798
+ showContent: true
1613
1799
  });
1614
1800
  const coinPrices = await query.utils.getCoinPrices(collateralCoinNames ?? []);
1615
1801
  const marketCollaterals = {};
@@ -1642,11 +1828,8 @@ var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) =
1642
1828
  };
1643
1829
  var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
1644
1830
  const marketId = query.address.get("core.market");
1645
- marketObject = marketObject || (await query.suiKit.client().getObject({
1646
- id: marketId,
1647
- options: {
1648
- showContent: true
1649
- }
1831
+ marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
1832
+ showContent: true
1650
1833
  })).data;
1651
1834
  coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
1652
1835
  let marketCollateral;
@@ -1665,7 +1848,7 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
1665
1848
  const fields = marketObject.content.fields;
1666
1849
  const coinType = query.utils.parseCoinType(collateralCoinName);
1667
1850
  const riskModelParentId = fields.risk_models.fields.table.fields.id.id;
1668
- const riskModelDynamicFieldObjectResponse = await query.suiKit.client().getDynamicFieldObject({
1851
+ const riskModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
1669
1852
  parentId: riskModelParentId,
1670
1853
  name: {
1671
1854
  type: "0x1::type_name::TypeName",
@@ -1680,7 +1863,7 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
1680
1863
  riskModel = dynamicFields.value.fields;
1681
1864
  }
1682
1865
  const collateralStatParentId = fields.collateral_stats.fields.table.fields.id.id;
1683
- const collateralStatDynamicFieldObjectResponse = await query.suiKit.client().getDynamicFieldObject({
1866
+ const collateralStatDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
1684
1867
  parentId: collateralStatParentId,
1685
1868
  name: {
1686
1869
  type: "0x1::type_name::TypeName",
@@ -1736,7 +1919,7 @@ var getObligations = async (query, ownerAddress) => {
1736
1919
  let hasNextPage = false;
1737
1920
  let nextCursor = null;
1738
1921
  do {
1739
- const paginatedKeyObjectsResponse = await query.suiKit.client().getOwnedObjects({
1922
+ const paginatedKeyObjectsResponse = await query.cache.queryGetOwnedObjects({
1740
1923
  owner,
1741
1924
  filter: {
1742
1925
  StructType: `${protocolObjectId}::obligation::ObligationKey`
@@ -1752,7 +1935,7 @@ var getObligations = async (query, ownerAddress) => {
1752
1935
  }
1753
1936
  } while (hasNextPage);
1754
1937
  const keyObjectIds = keyObjectsResponse.map((ref) => ref?.data?.objectId).filter((id) => id !== void 0);
1755
- const keyObjects = await query.suiKit.getObjects(keyObjectIds);
1938
+ const keyObjects = await query.cache.queryGetObjects(keyObjectIds);
1756
1939
  const obligations = [];
1757
1940
  for (const keyObject of keyObjects) {
1758
1941
  const keyId = keyObject.objectId;
@@ -1766,12 +1949,10 @@ var getObligations = async (query, ownerAddress) => {
1766
1949
  return obligations;
1767
1950
  };
1768
1951
  var getObligationLocked = async (query, obligationId) => {
1769
- const obligationObjectResponse = await query.suiKit.client().getObject({
1770
- id: obligationId,
1771
- options: {
1772
- showContent: true
1773
- }
1774
- });
1952
+ const obligationObjectResponse = await query.cache.queryGetObject(
1953
+ obligationId,
1954
+ { showContent: true }
1955
+ );
1775
1956
  let obligationLocked = false;
1776
1957
  if (obligationObjectResponse.data && obligationObjectResponse?.data?.content?.dataType === "moveObject" && "lock_key" in obligationObjectResponse.data.content.fields) {
1777
1958
  obligationLocked = Boolean(
@@ -1783,9 +1964,11 @@ var getObligationLocked = async (query, obligationId) => {
1783
1964
  var queryObligation = async (query, obligationId) => {
1784
1965
  const packageId = query.address.get("core.packages.query.id");
1785
1966
  const queryTarget = `${packageId}::obligation_query::obligation_data`;
1786
- const txBlock = new SuiKitTxBlock();
1787
- txBlock.moveCall(queryTarget, [obligationId]);
1788
- const queryResult = await query.suiKit.inspectTxn(txBlock);
1967
+ const args = [obligationId];
1968
+ const queryResult = await query.cache.queryInspectTxn(
1969
+ { queryTarget, args }
1970
+ // txBlock
1971
+ );
1789
1972
  return queryResult.events[0].parsedJson;
1790
1973
  };
1791
1974
  var getCoinAmounts = async (query, assetCoinNames, ownerAddress) => {
@@ -1795,20 +1978,22 @@ var getCoinAmounts = async (query, assetCoinNames, ownerAddress) => {
1795
1978
  let hasNextPage = false;
1796
1979
  let nextCursor = null;
1797
1980
  do {
1798
- const paginatedCoinObjectsResponse = await query.suiKit.client().getOwnedObjects({
1799
- owner,
1800
- filter: {
1801
- MatchAny: assetCoinNames.map((assetCoinName) => {
1802
- const coinType = query.utils.parseCoinType(assetCoinName);
1803
- return { StructType: `0x2::coin::Coin<${coinType}>` };
1804
- })
1805
- },
1806
- options: {
1807
- showType: true,
1808
- showContent: true
1809
- },
1810
- cursor: nextCursor
1811
- });
1981
+ const paginatedCoinObjectsResponse = await query.cache.queryGetOwnedObjects(
1982
+ {
1983
+ owner,
1984
+ filter: {
1985
+ MatchAny: assetCoinNames.map((assetCoinName) => {
1986
+ const coinType = query.utils.parseCoinType(assetCoinName);
1987
+ return { StructType: `0x2::coin::Coin<${coinType}>` };
1988
+ })
1989
+ },
1990
+ options: {
1991
+ showType: true,
1992
+ showContent: true
1993
+ },
1994
+ cursor: nextCursor
1995
+ }
1996
+ );
1812
1997
  coinObjectsResponse.push(...paginatedCoinObjectsResponse.data);
1813
1998
  if (paginatedCoinObjectsResponse.hasNextPage && paginatedCoinObjectsResponse.nextCursor) {
1814
1999
  hasNextPage = true;
@@ -1842,14 +2027,16 @@ var getCoinAmount = async (query, assetCoinName, ownerAddress) => {
1842
2027
  let hasNextPage = false;
1843
2028
  let nextCursor = null;
1844
2029
  do {
1845
- const paginatedCoinObjectsResponse = await query.suiKit.client().getOwnedObjects({
1846
- owner,
1847
- filter: { StructType: `0x2::coin::Coin<${coinType}>` },
1848
- options: {
1849
- showContent: true
1850
- },
1851
- cursor: nextCursor
1852
- });
2030
+ const paginatedCoinObjectsResponse = await query.cache.queryGetOwnedObjects(
2031
+ {
2032
+ owner,
2033
+ filter: { StructType: `0x2::coin::Coin<${coinType}>` },
2034
+ options: {
2035
+ showContent: true
2036
+ },
2037
+ cursor: nextCursor
2038
+ }
2039
+ );
1853
2040
  coinObjectsResponse.push(...paginatedCoinObjectsResponse.data);
1854
2041
  if (paginatedCoinObjectsResponse.hasNextPage && paginatedCoinObjectsResponse.nextCursor) {
1855
2042
  hasNextPage = true;
@@ -1881,7 +2068,7 @@ var getMarketCoinAmounts = async (query, marketCoinNames, ownerAddress) => {
1881
2068
  let hasNextPage = false;
1882
2069
  let nextCursor = null;
1883
2070
  do {
1884
- const paginatedMarketCoinObjectsResponse = await query.suiKit.client().getOwnedObjects({
2071
+ const paginatedMarketCoinObjectsResponse = await query.cache.queryGetOwnedObjects({
1885
2072
  owner,
1886
2073
  filter: {
1887
2074
  MatchAny: marketCoinNames.map((marketCoinName) => {
@@ -1930,7 +2117,7 @@ var getMarketCoinAmount = async (query, marketCoinName, ownerAddress) => {
1930
2117
  let hasNextPage = false;
1931
2118
  let nextCursor = null;
1932
2119
  do {
1933
- const paginatedMarketCoinObjectsResponse = await query.suiKit.client().getOwnedObjects({
2120
+ const paginatedMarketCoinObjectsResponse = await query.cache.queryGetOwnedObjects({
1934
2121
  owner,
1935
2122
  filter: { StructType: `0x2::coin::Coin<${marketCoinType}>` },
1936
2123
  options: {
@@ -2110,7 +2297,7 @@ var getStakeAccounts = async (query, ownerAddress) => {
2110
2297
  let hasNextPage = false;
2111
2298
  let nextCursor = null;
2112
2299
  do {
2113
- const paginatedStakeObjectsResponse = await query.suiKit.client().getOwnedObjects({
2300
+ const paginatedStakeObjectsResponse = await query.cache.queryGetOwnedObjects({
2114
2301
  owner,
2115
2302
  filter: { StructType: stakeAccountType },
2116
2303
  options: {
@@ -2148,7 +2335,7 @@ var getStakeAccounts = async (query, ownerAddress) => {
2148
2335
  {}
2149
2336
  );
2150
2337
  const stakeObjectIds = stakeObjectsResponse.map((ref) => ref?.data?.objectId).filter((id) => id !== void 0);
2151
- const stakeObjects = await query.suiKit.getObjects(stakeObjectIds);
2338
+ const stakeObjects = await query.cache.queryGetObjects(stakeObjectIds);
2152
2339
  for (const stakeObject of stakeObjects) {
2153
2340
  const id = stakeObject.objectId;
2154
2341
  const type = stakeObject.type;
@@ -2256,12 +2443,9 @@ var getStakeAccounts = async (query, ownerAddress) => {
2256
2443
  var getStakePool = async (query, marketCoinName) => {
2257
2444
  const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
2258
2445
  let stakePool = void 0;
2259
- const stakePoolObjectResponse = await query.suiKit.client().getObject({
2260
- id: poolId,
2261
- options: {
2262
- showContent: true,
2263
- showType: true
2264
- }
2446
+ const stakePoolObjectResponse = await query.cache.queryGetObject(poolId, {
2447
+ showContent: true,
2448
+ showType: true
2265
2449
  });
2266
2450
  if (stakePoolObjectResponse.data) {
2267
2451
  const stakePoolObject = stakePoolObjectResponse.data;
@@ -2302,13 +2486,13 @@ var getStakeRewardPool = async (query, marketCoinName) => {
2302
2486
  `spool.pools.${marketCoinName}.rewardPoolId`
2303
2487
  );
2304
2488
  let stakeRewardPool = void 0;
2305
- const stakeRewardPoolObjectResponse = await query.suiKit.client().getObject({
2306
- id: poolId,
2307
- options: {
2489
+ const stakeRewardPoolObjectResponse = await query.cache.queryGetObject(
2490
+ poolId,
2491
+ {
2308
2492
  showContent: true,
2309
2493
  showType: true
2310
2494
  }
2311
- });
2495
+ );
2312
2496
  if (stakeRewardPoolObjectResponse.data) {
2313
2497
  const stakeRewardPoolObject = stakeRewardPoolObjectResponse.data;
2314
2498
  const id = stakeRewardPoolObject.objectId;
@@ -2338,17 +2522,15 @@ var getStakeRewardPool = async (query, marketCoinName) => {
2338
2522
 
2339
2523
  // src/queries/borrowIncentiveQuery.ts
2340
2524
  import { normalizeStructTag as normalizeStructTag4 } from "@mysten/sui.js/utils";
2341
- import { SuiTxBlock as SuiKitTxBlock2 } from "@scallop-io/sui-kit";
2342
2525
  var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer = false) => {
2343
2526
  borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
2344
2527
  ...SUPPORT_BORROW_INCENTIVE_POOLS
2345
2528
  ];
2346
2529
  const queryPkgId = query.address.get("borrowIncentive.query");
2347
2530
  const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
2348
- const txBlock = new SuiKitTxBlock2();
2349
2531
  const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
2350
- txBlock.moveCall(queryTarget, [incentivePoolsId]);
2351
- const queryResult = await query.suiKit.inspectTxn(txBlock);
2532
+ const args = [incentivePoolsId];
2533
+ const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
2352
2534
  const borrowIncentivePoolsQueryData = queryResult.events[0].parsedJson;
2353
2535
  const borrowIncentivePools = {};
2354
2536
  if (indexer) {
@@ -2425,9 +2607,8 @@ var queryBorrowIncentiveAccounts = async (query, obligationId, borrowIncentiveCo
2425
2607
  "borrowIncentive.incentiveAccounts"
2426
2608
  );
2427
2609
  const queryTarget = `${queryPkgId}::incentive_account_query::incentive_account_data`;
2428
- const txBlock = new SuiKitTxBlock2();
2429
- txBlock.moveCall(queryTarget, [incentiveAccountsId, obligationId]);
2430
- const queryResult = await query.suiKit.inspectTxn(txBlock);
2610
+ const args = [incentiveAccountsId, obligationId];
2611
+ const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
2431
2612
  const borrowIncentiveAccountsQueryData = queryResult.events[0].parsedJson;
2432
2613
  const borrowIncentiveAccounts = Object.values(
2433
2614
  borrowIncentiveAccountsQueryData.pool_records
@@ -2505,12 +2686,10 @@ var getPythPrice = async (query, assetCoinName) => {
2505
2686
  const pythFeedObjectId = query.address.get(
2506
2687
  `core.coins.${assetCoinName}.oracle.pyth.feedObject`
2507
2688
  );
2508
- const priceFeedObjectResponse = await query.suiKit.client().getObject({
2509
- id: pythFeedObjectId,
2510
- options: {
2511
- showContent: true
2512
- }
2513
- });
2689
+ const priceFeedObjectResponse = await query.cache.queryGetObject(
2690
+ pythFeedObjectId,
2691
+ { showContent: true }
2692
+ );
2514
2693
  if (priceFeedObjectResponse.data) {
2515
2694
  const priceFeedPoolObject = priceFeedObjectResponse.data;
2516
2695
  if (priceFeedPoolObject.content && "fields" in priceFeedPoolObject.content) {
@@ -3074,7 +3253,7 @@ var getVeSca = async (query, veScaKeyId, ownerAddress) => {
3074
3253
  const tableId = IS_VE_SCA_TEST ? "0xc607241e4a679fe376d1170b2fbe07b64917bfe69100d4825241cda20039d4bd" : query.address.get(`vesca.tableId`);
3075
3254
  veScaKeyId = veScaKeyId || (await getVescaKeys(query, ownerAddress))[0].objectId;
3076
3255
  let vesca = void 0;
3077
- const veScaDynamicFieldObjectResponse = await query.suiKit.client().getDynamicFieldObject({
3256
+ const veScaDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
3078
3257
  parentId: tableId,
3079
3258
  name: {
3080
3259
  type: "0x2::object::ID",
@@ -3106,7 +3285,9 @@ var getVeSca = async (query, veScaKeyId, ownerAddress) => {
3106
3285
  // src/models/scallopIndexer.ts
3107
3286
  import axios2 from "axios";
3108
3287
  var ScallopIndexer = class {
3109
- constructor() {
3288
+ constructor(params, instance) {
3289
+ this.params = params;
3290
+ this._cache = instance?.cache ?? new ScallopCache();
3110
3291
  this._requestClient = axios2.create({
3111
3292
  baseURL: SDK_API_BASE_URL,
3112
3293
  headers: {
@@ -3122,7 +3303,12 @@ var ScallopIndexer = class {
3122
3303
  * @return Market data.
3123
3304
  */
3124
3305
  async getMarket() {
3125
- const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market`);
3306
+ const response = await this._cache.queryClient.fetchQuery({
3307
+ queryKey: ["market"],
3308
+ queryFn: async () => {
3309
+ return await this._requestClient.get(`/api/market`);
3310
+ }
3311
+ });
3126
3312
  if (response.status === 200) {
3127
3313
  return {
3128
3314
  pools: response.data.pools.reduce((marketPools, marketPool) => {
@@ -3147,15 +3333,8 @@ var ScallopIndexer = class {
3147
3333
  * @return Market pools data.
3148
3334
  */
3149
3335
  async getMarketPools() {
3150
- const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/pools`);
3151
- if (response.status === 200) {
3152
- return response.data.pools.reduce((marketPools, marketPool) => {
3153
- marketPools[marketPool.coinName] = marketPool;
3154
- return marketPools;
3155
- }, {});
3156
- } else {
3157
- throw Error("Failed to getMarketPools.");
3158
- }
3336
+ const response = (await this.getMarket()).pools;
3337
+ return response;
3159
3338
  }
3160
3339
  /**
3161
3340
  * Get market pool index data.
@@ -3163,12 +3342,7 @@ var ScallopIndexer = class {
3163
3342
  * @return Market pool data.
3164
3343
  */
3165
3344
  async getMarketPool(poolCoinName) {
3166
- const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/pool/${poolCoinName}`);
3167
- if (response.status === 200) {
3168
- return response.data.pool;
3169
- } else {
3170
- throw Error("Failed to getMarketPool.");
3171
- }
3345
+ return (await this.getMarketPools())[poolCoinName];
3172
3346
  }
3173
3347
  /**
3174
3348
  * Get market collaterals index data.
@@ -3176,18 +3350,7 @@ var ScallopIndexer = class {
3176
3350
  * @return Market collaterals data.
3177
3351
  */
3178
3352
  async getMarketCollaterals() {
3179
- const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/collaterals`);
3180
- if (response.status === 200) {
3181
- return response.data.collaterals.reduce(
3182
- (marketCollaterals, marketCollateral) => {
3183
- marketCollaterals[marketCollateral.coinName] = marketCollateral;
3184
- return marketCollaterals;
3185
- },
3186
- {}
3187
- );
3188
- } else {
3189
- throw Error("Failed to getMarketCollaterals.");
3190
- }
3353
+ return (await this.getMarket()).collaterals;
3191
3354
  }
3192
3355
  /**
3193
3356
  * Get market collateral index data.
@@ -3195,12 +3358,7 @@ var ScallopIndexer = class {
3195
3358
  * @return Market collateral data.
3196
3359
  */
3197
3360
  async getMarketCollateral(collateralCoinName) {
3198
- const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/collateral/${collateralCoinName}`);
3199
- if (response.status === 200) {
3200
- return response.data.collateral;
3201
- } else {
3202
- throw Error("Failed to getMarketCollateral.");
3203
- }
3361
+ return (await this.getMarketCollaterals())[collateralCoinName];
3204
3362
  }
3205
3363
  /**
3206
3364
  * Get spools index data.
@@ -3208,7 +3366,12 @@ var ScallopIndexer = class {
3208
3366
  * @return Spools data.
3209
3367
  */
3210
3368
  async getSpools() {
3211
- const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/spools`);
3369
+ const response = await this._cache.queryClient.fetchQuery({
3370
+ queryKey: ["spools"],
3371
+ queryFn: async () => {
3372
+ return await this._requestClient.get(`/api/spools`);
3373
+ }
3374
+ });
3212
3375
  if (response.status === 200) {
3213
3376
  return response.data.spools.reduce((spools, spool) => {
3214
3377
  spools[spool.marketCoinName] = spool;
@@ -3224,12 +3387,7 @@ var ScallopIndexer = class {
3224
3387
  * @return Spool data.
3225
3388
  */
3226
3389
  async getSpool(marketCoinName) {
3227
- const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/spool/${marketCoinName}`);
3228
- if (response.status === 200) {
3229
- return response.data.spool;
3230
- } else {
3231
- throw Error("Failed to getSpool.");
3232
- }
3390
+ return (await this.getSpools())[marketCoinName];
3233
3391
  }
3234
3392
  /**
3235
3393
  * Get borrow incentive pools index data.
@@ -3237,7 +3395,12 @@ var ScallopIndexer = class {
3237
3395
  * @return Borrow incentive pools data.
3238
3396
  */
3239
3397
  async getBorrowIncentivePools() {
3240
- const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/borrowIncentivePools`);
3398
+ const response = await this._cache.queryClient.fetchQuery({
3399
+ queryKey: ["borrowIncentivePools"],
3400
+ queryFn: async () => {
3401
+ return await this._requestClient.get(`/api/borrowIncentivePools`);
3402
+ }
3403
+ });
3241
3404
  if (response.status === 200) {
3242
3405
  return response.data.borrowIncentivePools.reduce(
3243
3406
  (borrowIncentivePools, borrowIncentivePool) => {
@@ -3256,14 +3419,7 @@ var ScallopIndexer = class {
3256
3419
  * @return Borrow incentive pool data.
3257
3420
  */
3258
3421
  async getBorrowIncentivePool(borrowIncentiveCoinName) {
3259
- const response = await this._requestClient.get(
3260
- `${SDK_API_BASE_URL}/api/borrowIncentivePool/${borrowIncentiveCoinName}`
3261
- );
3262
- if (response.status === 200) {
3263
- return response.data.borrowIncentivePool;
3264
- } else {
3265
- throw Error("Failed to getSpool.");
3266
- }
3422
+ return (await this.getBorrowIncentivePools())[borrowIncentiveCoinName];
3267
3423
  }
3268
3424
  /**
3269
3425
  * Get total value locked index data.
@@ -3271,7 +3427,12 @@ var ScallopIndexer = class {
3271
3427
  * @return Total value locked.
3272
3428
  */
3273
3429
  async getTotalValueLocked() {
3274
- const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/tvl`);
3430
+ const response = await this._cache.queryClient.fetchQuery({
3431
+ queryKey: ["totalValueLocked"],
3432
+ queryFn: async () => {
3433
+ return await this._requestClient.get(`/api/market/tvl`);
3434
+ }
3435
+ });
3275
3436
  if (response.status === 200) {
3276
3437
  return response.data;
3277
3438
  } else {
@@ -3285,16 +3446,21 @@ var ScallopQuery = class {
3285
3446
  constructor(params, instance) {
3286
3447
  this.params = params;
3287
3448
  this.suiKit = instance?.suiKit ?? new SuiKit(params);
3288
- this.address = instance?.address ?? new ScallopAddress({
3289
- id: params?.addressesId || ADDRESSES_ID,
3290
- network: params?.networkType
3291
- });
3449
+ this.cache = instance?.cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS, this.suiKit);
3450
+ this.address = instance?.address ?? new ScallopAddress(
3451
+ {
3452
+ id: params?.addressesId || ADDRESSES_ID,
3453
+ network: params?.networkType
3454
+ },
3455
+ this.cache
3456
+ );
3292
3457
  this.utils = instance?.utils ?? new ScallopUtils(this.params, {
3293
3458
  suiKit: this.suiKit,
3294
3459
  address: this.address,
3460
+ cache: this.cache,
3295
3461
  query: this
3296
3462
  });
3297
- this.indexer = new ScallopIndexer();
3463
+ this.indexer = new ScallopIndexer(this.params, { cache: this.cache });
3298
3464
  }
3299
3465
  /**
3300
3466
  * Request the scallop API to initialize data.
@@ -3680,13 +3846,18 @@ var ScallopUtils = class {
3680
3846
  };
3681
3847
  this.params = params;
3682
3848
  this._suiKit = instance?.suiKit ?? new SuiKit2(params);
3683
- this._address = instance?.address ?? new ScallopAddress({
3684
- id: params?.addressesId || ADDRESSES_ID,
3685
- network: params?.networkType
3686
- });
3849
+ this._cache = instance?.cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS, this._suiKit);
3850
+ this._address = instance?.address ?? new ScallopAddress(
3851
+ {
3852
+ id: params?.addressesId || ADDRESSES_ID,
3853
+ network: params?.networkType
3854
+ },
3855
+ this._cache
3856
+ );
3687
3857
  this._query = instance?.query ?? new ScallopQuery(params, {
3688
3858
  suiKit: this._suiKit,
3689
- address: this._address
3859
+ address: this._address,
3860
+ cache: this._cache
3690
3861
  });
3691
3862
  this.isTestnet = params.networkType ? params.networkType === "testnet" : false;
3692
3863
  }
@@ -3903,33 +4074,52 @@ var ScallopUtils = class {
3903
4074
  }
3904
4075
  if (lackPricesCoinNames.length > 0) {
3905
4076
  const endpoints = this.params.pythEndpoints ?? PYTH_ENDPOINTS[this.isTestnet ? "testnet" : "mainnet"];
3906
- try {
3907
- for (const endpoint of endpoints) {
3908
- try {
3909
- const pythConnection = new SuiPriceServiceConnection(endpoint);
3910
- const priceIds = lackPricesCoinNames.map(
3911
- (coinName) => this._address.get(`core.coins.${coinName}.oracle.pyth.feed`)
4077
+ const failedRequests = new Set(
4078
+ lackPricesCoinNames
4079
+ );
4080
+ for (const endpoint of endpoints) {
4081
+ let hasFailRequest = false;
4082
+ const pythConnection = new SuiPriceServiceConnection(endpoint);
4083
+ const priceIds = Array.from(failedRequests.values()).reduce(
4084
+ (acc, coinName) => {
4085
+ const priceId = this._address.get(
4086
+ `core.coins.${coinName}.oracle.pyth.feed`
3912
4087
  );
3913
- const priceFeeds = await pythConnection.getLatestPriceFeeds(priceIds) || [];
3914
- for (const [index, feed] of priceFeeds.entries()) {
3915
- const data = parseDataFromPythPriceFeed(feed, this._address);
3916
- const coinName = lackPricesCoinNames[index];
4088
+ acc[coinName] = priceId;
4089
+ return acc;
4090
+ },
4091
+ {}
4092
+ );
4093
+ for (const [coinName, priceId] of Object.entries(priceIds)) {
4094
+ try {
4095
+ const feed = await this._cache.queryClient.fetchQuery({
4096
+ queryKey: [priceId],
4097
+ queryFn: async () => {
4098
+ return await pythConnection.getLatestPriceFeeds([priceId]);
4099
+ }
4100
+ // staleTime: 15000,
4101
+ });
4102
+ if (feed) {
4103
+ const data = parseDataFromPythPriceFeed(feed[0], this._address);
3917
4104
  this._priceMap.set(coinName, {
3918
4105
  price: data.price,
3919
4106
  publishTime: data.publishTime
3920
4107
  });
3921
4108
  coinPrices[coinName] = data.price;
3922
4109
  }
3923
- break;
4110
+ failedRequests.delete(coinName);
3924
4111
  } catch (e) {
3925
4112
  console.warn(
3926
- `Failed to update price feeds with endpoint ${endpoint}: ${e}`
4113
+ `Failed to get price ${coinName} feeds with endpoint ${endpoint}: ${e}`
3927
4114
  );
4115
+ hasFailRequest = true;
3928
4116
  }
3929
- throw new Error("Failed to update price feeds with all endpoins");
3930
4117
  }
3931
- } catch (_e) {
3932
- for (const coinName of lackPricesCoinNames) {
4118
+ if (!hasFailRequest)
4119
+ break;
4120
+ }
4121
+ if (failedRequests.size > 0) {
4122
+ for (const coinName of failedRequests.values()) {
3933
4123
  const price = await this._query.getPriceFromPyth(coinName);
3934
4124
  this._priceMap.set(coinName, {
3935
4125
  price,
@@ -4002,7 +4192,7 @@ import { SuiKit as SuiKit3 } from "@scallop-io/sui-kit";
4002
4192
  // src/builders/coreBuilder.ts
4003
4193
  import { TransactionBlock } from "@mysten/sui.js/transactions";
4004
4194
  import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID2 } from "@mysten/sui.js/utils";
4005
- import { SuiTxBlock as SuiKitTxBlock3 } from "@scallop-io/sui-kit";
4195
+ import { SuiTxBlock as SuiKitTxBlock } from "@scallop-io/sui-kit";
4006
4196
 
4007
4197
  // src/builders/oracle.ts
4008
4198
  import { SUI_CLOCK_OBJECT_ID } from "@mysten/sui.js/utils";
@@ -4437,7 +4627,7 @@ var generateCoreQuickMethod = ({
4437
4627
  };
4438
4628
  };
4439
4629
  var newCoreTxBlock = (builder, initTxBlock) => {
4440
- const txBlock = initTxBlock instanceof TransactionBlock ? new SuiKitTxBlock3(initTxBlock) : initTxBlock ? initTxBlock : new SuiKitTxBlock3();
4630
+ const txBlock = initTxBlock instanceof TransactionBlock ? new SuiKitTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new SuiKitTxBlock();
4441
4631
  const normalMethod = generateCoreNormalMethod({
4442
4632
  builder,
4443
4633
  txBlock
@@ -4467,7 +4657,7 @@ var newCoreTxBlock = (builder, initTxBlock) => {
4467
4657
  // src/builders/spoolBuilder.ts
4468
4658
  import { TransactionBlock as TransactionBlock2 } from "@mysten/sui.js/transactions";
4469
4659
  import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID3 } from "@mysten/sui.js/utils";
4470
- import { SuiTxBlock as SuiKitTxBlock4 } from "@scallop-io/sui-kit";
4660
+ import { SuiTxBlock as SuiKitTxBlock2 } from "@scallop-io/sui-kit";
4471
4661
  var requireStakeAccountIds = async (...params) => {
4472
4662
  const [builder, txBlock, stakeMarketCoinName, stakeAccountId] = params;
4473
4663
  if (params.length === 4 && stakeAccountId)
@@ -4625,7 +4815,7 @@ var generateSpoolQuickMethod = ({
4625
4815
  };
4626
4816
  };
4627
4817
  var newSpoolTxBlock = (builder, initTxBlock) => {
4628
- const txBlock = initTxBlock instanceof TransactionBlock2 ? new SuiKitTxBlock4(initTxBlock) : initTxBlock ? initTxBlock : new SuiKitTxBlock4();
4818
+ const txBlock = initTxBlock instanceof TransactionBlock2 ? new SuiKitTxBlock2(initTxBlock) : initTxBlock ? initTxBlock : new SuiKitTxBlock2();
4629
4819
  const normalMethod = generateSpoolNormalMethod({
4630
4820
  builder,
4631
4821
  txBlock
@@ -4655,13 +4845,13 @@ var newSpoolTxBlock = (builder, initTxBlock) => {
4655
4845
  // src/builders/borrowIncentiveBuilder.ts
4656
4846
  import { TransactionBlock as TransactionBlock4 } from "@mysten/sui.js/transactions";
4657
4847
  import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID5 } from "@mysten/sui.js/utils";
4658
- import { SuiTxBlock as SuiKitTxBlock6 } from "@scallop-io/sui-kit";
4848
+ import { SuiTxBlock as SuiKitTxBlock4 } from "@scallop-io/sui-kit";
4659
4849
 
4660
4850
  // src/builders/vescaBuilder.ts
4661
4851
  import {
4662
4852
  SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID4,
4663
4853
  TransactionBlock as TransactionBlock3,
4664
- SuiTxBlock as SuiKitTxBlock5
4854
+ SuiTxBlock as SuiKitTxBlock3
4665
4855
  } from "@scallop-io/sui-kit";
4666
4856
  var requireVeSca = async (...params) => {
4667
4857
  const [builder, txBlock, veScaKey] = params;
@@ -4904,7 +5094,7 @@ var generateQuickVeScaMethod = ({
4904
5094
  };
4905
5095
  };
4906
5096
  var newVeScaTxBlock = (builder, initTxBlock) => {
4907
- const txBlock = initTxBlock instanceof TransactionBlock3 ? new SuiKitTxBlock5(initTxBlock) : initTxBlock ? initTxBlock : new SuiKitTxBlock5();
5097
+ const txBlock = initTxBlock instanceof TransactionBlock3 ? new SuiKitTxBlock3(initTxBlock) : initTxBlock ? initTxBlock : new SuiKitTxBlock3();
4908
5098
  const normalMethod = generateNormalVeScaMethod({
4909
5099
  builder,
4910
5100
  txBlock
@@ -5019,7 +5209,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
5019
5209
  );
5020
5210
  },
5021
5211
  claimBorrowIncentive: (obligationId, obligationKey, coinName, rewardCoinName) => {
5022
- const rewardCoinNames = borrowIncentiveRewardCoins[coinName];
5212
+ const rewardCoinNames = builder.utils.getBorrowIncentiveRewardCoinName(coinName);
5023
5213
  if (rewardCoinNames.includes(rewardCoinName) === false) {
5024
5214
  throw new Error(`Invalid reward coin name ${rewardCoinName}`);
5025
5215
  }
@@ -5146,7 +5336,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
5146
5336
  };
5147
5337
  };
5148
5338
  var newBorrowIncentiveTxBlock = (builder, initTxBlock) => {
5149
- const txBlock = initTxBlock instanceof TransactionBlock4 ? new SuiKitTxBlock6(initTxBlock) : initTxBlock ? initTxBlock : new SuiKitTxBlock6();
5339
+ const txBlock = initTxBlock instanceof TransactionBlock4 ? new SuiKitTxBlock4(initTxBlock) : initTxBlock ? initTxBlock : new SuiKitTxBlock4();
5150
5340
  const normalMethod = generateBorrowIncentiveNormalMethod({
5151
5341
  builder,
5152
5342
  txBlock
@@ -5201,18 +5391,24 @@ var ScallopBuilder = class {
5201
5391
  constructor(params, instance) {
5202
5392
  this.params = params;
5203
5393
  this.suiKit = instance?.suiKit ?? new SuiKit3(params);
5204
- this.address = instance?.address ?? new ScallopAddress({
5205
- id: params?.addressesId || ADDRESSES_ID,
5206
- network: params?.networkType
5207
- });
5394
+ this.cache = instance?.cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS, this.suiKit);
5395
+ this.address = instance?.address ?? new ScallopAddress(
5396
+ {
5397
+ id: params?.addressesId || ADDRESSES_ID,
5398
+ network: params?.networkType
5399
+ },
5400
+ this.cache
5401
+ );
5208
5402
  this.query = instance?.query ?? new ScallopQuery(params, {
5209
5403
  suiKit: this.suiKit,
5210
- address: this.address
5404
+ address: this.address,
5405
+ cache: this.cache
5211
5406
  });
5212
5407
  this.utils = instance?.utils ?? new ScallopUtils(this.params, {
5213
5408
  suiKit: this.suiKit,
5214
5409
  address: this.address,
5215
- query: this.query
5410
+ query: this.query,
5411
+ cache: this.cache
5216
5412
  });
5217
5413
  this.walletAddress = normalizeSuiAddress(
5218
5414
  params?.walletAddress || this.suiKit.currentAddress()
@@ -5294,24 +5490,31 @@ var ScallopClient = class {
5294
5490
  constructor(params, instance) {
5295
5491
  this.params = params;
5296
5492
  this.suiKit = instance?.suiKit ?? new SuiKit4(params);
5297
- this.address = instance?.address ?? new ScallopAddress({
5298
- id: params?.addressesId || ADDRESSES_ID,
5299
- network: params?.networkType
5300
- });
5493
+ this.cache = instance?.cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS, this.suiKit);
5494
+ this.address = instance?.address ?? new ScallopAddress(
5495
+ {
5496
+ id: params?.addressesId || ADDRESSES_ID,
5497
+ network: params?.networkType
5498
+ },
5499
+ this.cache
5500
+ );
5301
5501
  this.query = instance?.query ?? new ScallopQuery(params, {
5302
5502
  suiKit: this.suiKit,
5303
- address: this.address
5503
+ address: this.address,
5504
+ cache: this.cache
5304
5505
  });
5305
5506
  this.utils = instance?.utils ?? new ScallopUtils(params, {
5306
5507
  suiKit: this.suiKit,
5307
5508
  address: this.address,
5308
- query: this.query
5509
+ query: this.query,
5510
+ cache: this.cache
5309
5511
  });
5310
5512
  this.builder = instance?.builder ?? new ScallopBuilder(params, {
5311
5513
  suiKit: this.suiKit,
5312
5514
  address: this.address,
5313
5515
  query: this.query,
5314
- utils: this.utils
5516
+ utils: this.utils,
5517
+ cache: this.cache
5315
5518
  });
5316
5519
  this.walletAddress = normalizeSuiAddress2(
5317
5520
  params?.walletAddress || this.suiKit.currentAddress()
@@ -5817,13 +6020,20 @@ var ScallopClient = class {
5817
6020
 
5818
6021
  // src/models/scallop.ts
5819
6022
  var Scallop = class {
5820
- constructor(params) {
6023
+ constructor(params, cacheOptions) {
5821
6024
  this.params = params;
5822
6025
  this.suiKit = new SuiKit5(params);
5823
- this._address = new ScallopAddress({
5824
- id: params?.addressesId || ADDRESSES_ID,
5825
- network: params?.networkType
5826
- });
6026
+ this.cache = new ScallopCache(
6027
+ cacheOptions ?? DEFAULT_CACHE_OPTIONS,
6028
+ this.suiKit
6029
+ );
6030
+ this._address = new ScallopAddress(
6031
+ {
6032
+ id: params?.addressesId || ADDRESSES_ID,
6033
+ network: params?.networkType
6034
+ },
6035
+ this.cache
6036
+ );
5827
6037
  }
5828
6038
  /**
5829
6039
  * Get a scallop address instance that already has read addresses.
@@ -5845,7 +6055,8 @@ var Scallop = class {
5845
6055
  await this._address.read();
5846
6056
  const scallopBuilder = new ScallopBuilder(this.params, {
5847
6057
  suiKit: this.suiKit,
5848
- address: this._address
6058
+ address: this._address,
6059
+ cache: this.cache
5849
6060
  });
5850
6061
  return scallopBuilder;
5851
6062
  }
@@ -5860,7 +6071,7 @@ var Scallop = class {
5860
6071
  await this._address.read();
5861
6072
  const scallopClient = new ScallopClient(
5862
6073
  { ...this.params, walletAddress },
5863
- { suiKit: this.suiKit, address: this._address }
6074
+ { suiKit: this.suiKit, address: this._address, cache: this.cache }
5864
6075
  );
5865
6076
  return scallopClient;
5866
6077
  }
@@ -5874,7 +6085,8 @@ var Scallop = class {
5874
6085
  await this._address.read();
5875
6086
  const scallopQuery = new ScallopQuery(this.params, {
5876
6087
  suiKit: this.suiKit,
5877
- address: this._address
6088
+ address: this._address,
6089
+ cache: this.cache
5878
6090
  });
5879
6091
  return scallopQuery;
5880
6092
  }
@@ -5884,7 +6096,9 @@ var Scallop = class {
5884
6096
  * @return Scallop Indexer.
5885
6097
  */
5886
6098
  async createScallopIndexer() {
5887
- const scallopIndexer = new ScallopIndexer();
6099
+ const scallopIndexer = new ScallopIndexer(this.params, {
6100
+ cache: this.cache
6101
+ });
5888
6102
  return scallopIndexer;
5889
6103
  }
5890
6104
  /**
@@ -5897,7 +6111,8 @@ var Scallop = class {
5897
6111
  await this._address.read();
5898
6112
  const scallopUtils = new ScallopUtils(this.params, {
5899
6113
  suiKit: this.suiKit,
5900
- address: this._address
6114
+ address: this._address,
6115
+ cache: this.cache
5901
6116
  });
5902
6117
  return scallopUtils;
5903
6118
  }
@@ -5926,6 +6141,7 @@ export {
5926
6141
  Scallop,
5927
6142
  ScallopAddress,
5928
6143
  ScallopBuilder,
6144
+ ScallopCache,
5929
6145
  ScallopClient,
5930
6146
  ScallopIndexer,
5931
6147
  ScallopQuery,