@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.js CHANGED
@@ -53,6 +53,7 @@ __export(src_exports, {
53
53
  Scallop: () => Scallop,
54
54
  ScallopAddress: () => ScallopAddress,
55
55
  ScallopBuilder: () => ScallopBuilder,
56
+ ScallopCache: () => ScallopCache,
56
57
  ScallopClient: () => ScallopClient,
57
58
  ScallopIndexer: () => ScallopIndexer,
58
59
  ScallopQuery: () => ScallopQuery,
@@ -264,7 +265,198 @@ var MIN_INITIAL_LOCK_AMOUNT = 1e10;
264
265
  var MIN_TOP_UP_AMOUNT = 1e9;
265
266
 
266
267
  // src/models/scallop.ts
267
- var import_sui_kit11 = require("@scallop-io/sui-kit");
268
+ var import_sui_kit10 = require("@scallop-io/sui-kit");
269
+
270
+ // src/models/scallopCache.ts
271
+ var import_query_core = require("@tanstack/query-core");
272
+ var import_sui_kit = require("@scallop-io/sui-kit");
273
+
274
+ // src/constants/cache.ts
275
+ var DEFAULT_CACHE_OPTIONS = {
276
+ defaultOptions: {
277
+ queries: {
278
+ staleTime: 3e3
279
+ }
280
+ }
281
+ };
282
+
283
+ // src/models/scallopCache.ts
284
+ var ScallopCache = class {
285
+ constructor(cacheOptions, suiKit) {
286
+ this.queryClient = new import_query_core.QueryClient(cacheOptions ?? DEFAULT_CACHE_OPTIONS);
287
+ this._suiKit = suiKit;
288
+ }
289
+ get suiKit() {
290
+ if (!this._suiKit) {
291
+ throw new Error("SuiKit instance is not initialized");
292
+ }
293
+ return this._suiKit;
294
+ }
295
+ /**
296
+ * @description Invalidate cache based on the refetchType parameter
297
+ * @param refetchType Determines the type of queries to be refetched. Defaults to `active`.
298
+ *
299
+ * - `active`: Only queries that match the refetch predicate and are actively being rendered via useQuery and related functions will be refetched in the background.
300
+ * - `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.
301
+ * - `all`: All queries that match the refetch predicate will be refetched in the background.
302
+ * - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
303
+ */
304
+ invalidateAndRefetchAllCache(refetchType) {
305
+ return this.queryClient.invalidateQueries({
306
+ refetchType
307
+ });
308
+ }
309
+ /**
310
+ * @description Cache protocol config call for 60 seconds.
311
+ * @returns Promise<ProtocolConfig>
312
+ */
313
+ async getProtocolConfig() {
314
+ return await this.queryClient.fetchQuery({
315
+ queryKey: ["getProtocolConfig"],
316
+ queryFn: async () => {
317
+ return await this.suiKit.client().getProtocolConfig();
318
+ },
319
+ staleTime: 3e4
320
+ });
321
+ }
322
+ /**
323
+ * @description Provides cache for inspectTxn of the SuiKit.
324
+ * @param QueryInspectTxnParams
325
+ * @param txBlock
326
+ * @returns Promise<DevInspectResults>
327
+ */
328
+ async queryInspectTxn({
329
+ queryTarget,
330
+ args,
331
+ typeArgs
332
+ }) {
333
+ const txBlock = new import_sui_kit.SuiTxBlock();
334
+ const resolvedArgs = await Promise.all(
335
+ args.map(async (arg) => {
336
+ if (typeof arg === "string") {
337
+ return (await this.queryGetObject(arg, { showContent: true })).data;
338
+ }
339
+ return arg;
340
+ })
341
+ );
342
+ txBlock.moveCall(queryTarget, resolvedArgs, typeArgs);
343
+ const txBytes = await txBlock.txBlock.build({
344
+ client: this.suiKit.client(),
345
+ onlyTransactionKind: true,
346
+ protocolConfig: await this.getProtocolConfig()
347
+ });
348
+ const query = await this.queryClient.fetchQuery({
349
+ queryKey: typeArgs ? ["inspectTxn", queryTarget, JSON.stringify(args)] : [
350
+ "inspectTxn",
351
+ queryTarget,
352
+ JSON.stringify(args),
353
+ JSON.stringify(typeArgs)
354
+ ],
355
+ queryFn: async () => {
356
+ return await this.suiKit.inspectTxn(txBytes);
357
+ },
358
+ staleTime: 8e3
359
+ // make stale time longer for inspectTxn results
360
+ });
361
+ return query;
362
+ }
363
+ /**
364
+ * @description Provides cache for getObject of the SuiKit.
365
+ * @param objectId
366
+ * @param QueryObjectParams
367
+ * @returns Promise<SuiObjectResponse>
368
+ */
369
+ async queryGetObject(objectId, options) {
370
+ const queryKey = ["getObject", objectId, this.suiKit.currentAddress()];
371
+ if (options) {
372
+ queryKey.push(JSON.stringify(options));
373
+ }
374
+ return this.queryClient.fetchQuery({
375
+ queryKey,
376
+ queryFn: async () => {
377
+ return await this.suiKit.client().getObject({
378
+ id: objectId,
379
+ options
380
+ });
381
+ }
382
+ });
383
+ }
384
+ /**
385
+ * @description Provides cache for getObjects of the SuiKit.
386
+ * @param objectIds
387
+ * @returns Promise<SuiObjectData[]>
388
+ */
389
+ async queryGetObjects(objectIds, options) {
390
+ const queryKey = [
391
+ "getObjects",
392
+ JSON.stringify(objectIds),
393
+ this.suiKit.currentAddress()
394
+ ];
395
+ return this.queryClient.fetchQuery({
396
+ queryKey,
397
+ queryFn: async () => {
398
+ return await this.suiKit.getObjects(objectIds, options);
399
+ }
400
+ });
401
+ }
402
+ /**
403
+ * @description Provides cache for getOwnedObjects of the SuiKit.
404
+ * @param input
405
+ * @returns Promise<PaginatedObjectsResponse>
406
+ */
407
+ async queryGetOwnedObjects(input) {
408
+ const queryKey = ["getOwnedObjects", input.owner];
409
+ if (input.cursor) {
410
+ queryKey.push(JSON.stringify(input.cursor));
411
+ }
412
+ if (input.options) {
413
+ queryKey.push(JSON.stringify(input.options));
414
+ }
415
+ if (input.filter) {
416
+ queryKey.push(JSON.stringify(input.filter));
417
+ }
418
+ if (input.limit) {
419
+ queryKey.push(JSON.stringify(input.limit));
420
+ }
421
+ return this.queryClient.fetchQuery({
422
+ queryKey,
423
+ queryFn: async () => {
424
+ return await this.suiKit.client().getOwnedObjects(input);
425
+ }
426
+ });
427
+ }
428
+ async queryGetDynamicFields(input) {
429
+ const queryKey = ["getDynamicFields", input.parentId];
430
+ if (input.cursor) {
431
+ queryKey.push(JSON.stringify(input.cursor));
432
+ }
433
+ if (input.cursor) {
434
+ queryKey.push(JSON.stringify(input.cursor));
435
+ }
436
+ if (input.limit) {
437
+ queryKey.push(JSON.stringify(input.limit));
438
+ }
439
+ return this.queryClient.fetchQuery({
440
+ queryKey,
441
+ queryFn: async () => {
442
+ return await this.suiKit.client().getDynamicFields(input);
443
+ }
444
+ });
445
+ }
446
+ async queryGetDynamicFieldObject(input) {
447
+ const queryKey = [
448
+ "getDynamicFieldObject",
449
+ input.parentId,
450
+ input.name.value
451
+ ];
452
+ return this.queryClient.fetchQuery({
453
+ queryKey,
454
+ queryFn: async () => {
455
+ return await this.suiKit.client().getDynamicFieldObject(input);
456
+ }
457
+ });
458
+ }
459
+ };
268
460
 
269
461
  // src/models/scallopAddress.ts
270
462
  var import_axios = __toESM(require("axios"));
@@ -518,13 +710,9 @@ var EMPTY_ADDRESSES = {
518
710
  }
519
711
  };
520
712
  var ScallopAddress = class {
521
- constructor(params) {
713
+ constructor(params, cache) {
522
714
  const { id, auth, network } = params;
523
- if (auth)
524
- this._auth = auth;
525
- this._id = id;
526
- this._network = network || "mainnet";
527
- this._addressesMap = /* @__PURE__ */ new Map();
715
+ this._cache = cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS);
528
716
  this._requestClient = import_axios.default.create({
529
717
  baseURL: API_BASE_URL,
530
718
  headers: {
@@ -533,6 +721,11 @@ var ScallopAddress = class {
533
721
  },
534
722
  timeout: 3e4
535
723
  });
724
+ if (auth)
725
+ this._auth = auth;
726
+ this._id = id;
727
+ this._network = network || "mainnet";
728
+ this._addressesMap = /* @__PURE__ */ new Map();
536
729
  }
537
730
  /**
538
731
  * Get addresses API id.
@@ -656,7 +849,7 @@ var ScallopAddress = class {
656
849
  this._addressesMap.clear();
657
850
  this.setAddresses(targetAddresses, targetNetwork);
658
851
  const response = await this._requestClient.post(
659
- `${API_BASE_URL}/addresses`,
852
+ `/addresses`,
660
853
  JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
661
854
  {
662
855
  headers: {
@@ -693,14 +886,16 @@ var ScallopAddress = class {
693
886
  async read(id) {
694
887
  const addressesId = id || this._id || void 0;
695
888
  if (addressesId !== void 0) {
696
- const response = await this._requestClient.get(
697
- `${API_BASE_URL}/addresses/${addressesId}`,
698
- {
699
- headers: {
700
- "Content-Type": "application/json"
701
- }
889
+ const response = await this._cache.queryClient.fetchQuery({
890
+ queryKey: ["api-getAddresses", addressesId],
891
+ queryFn: async () => {
892
+ return await this._requestClient.get(`/addresses/${addressesId}`, {
893
+ headers: {
894
+ "Content-Type": "application/json"
895
+ }
896
+ });
702
897
  }
703
- );
898
+ });
704
899
  if (response.status === 200) {
705
900
  for (const [network, addresses] of Object.entries(
706
901
  response.data
@@ -754,7 +949,7 @@ var ScallopAddress = class {
754
949
  }
755
950
  this.setAddresses(targetAddresses, targetNetwork);
756
951
  const response = await this._requestClient.put(
757
- `${API_BASE_URL}/addresses/${targetId}`,
952
+ `/addresses/${targetId}`,
758
953
  JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
759
954
  {
760
955
  headers: {
@@ -796,7 +991,7 @@ var ScallopAddress = class {
796
991
  throw Error("Require specific addresses id to be deleted.");
797
992
  if (apiKey !== void 0) {
798
993
  const response = await this._requestClient.delete(
799
- `${API_BASE_URL}/addresses/${targetId}`,
994
+ `/addresses/${targetId}`,
800
995
  {
801
996
  headers: {
802
997
  "Content-Type": "application/json",
@@ -819,19 +1014,18 @@ var ScallopAddress = class {
819
1014
 
820
1015
  // src/models/scallopClient.ts
821
1016
  var import_utils20 = require("@mysten/sui.js/utils");
822
- var import_sui_kit10 = require("@scallop-io/sui-kit");
1017
+ var import_sui_kit9 = require("@scallop-io/sui-kit");
823
1018
 
824
1019
  // src/models/scallopUtils.ts
825
1020
  var import_utils9 = require("@mysten/sui.js/utils");
826
- var import_sui_kit4 = require("@scallop-io/sui-kit");
1021
+ var import_sui_kit3 = require("@scallop-io/sui-kit");
827
1022
  var import_pyth_sui_js = require("@pythnetwork/pyth-sui-js");
828
1023
 
829
1024
  // src/models/scallopQuery.ts
830
- var import_sui_kit3 = require("@scallop-io/sui-kit");
1025
+ var import_sui_kit2 = require("@scallop-io/sui-kit");
831
1026
 
832
1027
  // src/queries/coreQuery.ts
833
1028
  var import_utils2 = require("@mysten/sui.js/utils");
834
- var import_sui_kit = require("@scallop-io/sui-kit");
835
1029
  var import_bignumber2 = __toESM(require("bignumber.js"));
836
1030
 
837
1031
  // src/utils/builder.ts
@@ -1383,10 +1577,12 @@ var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
1383
1577
  var queryMarket = async (query, indexer = false) => {
1384
1578
  const packageId = query.address.get("core.packages.query.id");
1385
1579
  const marketId = query.address.get("core.market");
1386
- const txBlock = new import_sui_kit.SuiTxBlock();
1387
1580
  const queryTarget = `${packageId}::market_query::market_data`;
1388
- txBlock.moveCall(queryTarget, [marketId]);
1389
- const queryResult = await query.suiKit.inspectTxn(txBlock);
1581
+ const args = [marketId];
1582
+ const queryResult = await query.cache.queryInspectTxn(
1583
+ { queryTarget, args }
1584
+ // txBlock
1585
+ );
1390
1586
  const marketData = queryResult.events[0].parsedJson;
1391
1587
  const coinPrices = await query.utils.getCoinPrices();
1392
1588
  const pools = {};
@@ -1504,11 +1700,8 @@ var queryMarket = async (query, indexer = false) => {
1504
1700
  var getMarketPools = async (query, poolCoinNames, indexer = false) => {
1505
1701
  poolCoinNames = poolCoinNames || [...SUPPORT_POOLS];
1506
1702
  const marketId = query.address.get("core.market");
1507
- const marketObjectResponse = await query.suiKit.client().getObject({
1508
- id: marketId,
1509
- options: {
1510
- showContent: true
1511
- }
1703
+ const marketObjectResponse = await query.cache.queryGetObject(marketId, {
1704
+ showContent: true
1512
1705
  });
1513
1706
  const coinPrices = await query.utils.getCoinPrices(poolCoinNames ?? []);
1514
1707
  const marketPools = {};
@@ -1541,11 +1734,8 @@ var getMarketPools = async (query, poolCoinNames, indexer = false) => {
1541
1734
  };
1542
1735
  var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, coinPrice) => {
1543
1736
  const marketId = query.address.get("core.market");
1544
- marketObject = marketObject || (await query.suiKit.client().getObject({
1545
- id: marketId,
1546
- options: {
1547
- showContent: true
1548
- }
1737
+ marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
1738
+ showContent: true
1549
1739
  })).data;
1550
1740
  coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
1551
1741
  let marketPool;
@@ -1566,7 +1756,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
1566
1756
  const fields = marketObject.content.fields;
1567
1757
  const coinType = query.utils.parseCoinType(poolCoinName);
1568
1758
  const balanceSheetParentId = fields.vault.fields.balance_sheets.fields.table.fields.id.id;
1569
- const balanceSheetDynamicFieldObjectResponse = await query.suiKit.client().getDynamicFieldObject({
1759
+ const balanceSheetDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
1570
1760
  parentId: balanceSheetParentId,
1571
1761
  name: {
1572
1762
  type: "0x1::type_name::TypeName",
@@ -1581,7 +1771,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
1581
1771
  balanceSheet = dynamicFields.value.fields;
1582
1772
  }
1583
1773
  const borrowIndexParentId = fields.borrow_dynamics.fields.table.fields.id.id;
1584
- const borrowIndexDynamicFieldObjectResponse = await query.suiKit.client().getDynamicFieldObject({
1774
+ const borrowIndexDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
1585
1775
  parentId: borrowIndexParentId,
1586
1776
  name: {
1587
1777
  type: "0x1::type_name::TypeName",
@@ -1596,7 +1786,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
1596
1786
  borrowIndex = dynamicFields.value.fields;
1597
1787
  }
1598
1788
  const interestModelParentId = fields.interest_models.fields.table.fields.id.id;
1599
- const interestModelDynamicFieldObjectResponse = await query.suiKit.client().getDynamicFieldObject({
1789
+ const interestModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
1600
1790
  parentId: interestModelParentId,
1601
1791
  name: {
1602
1792
  type: "0x1::type_name::TypeName",
@@ -1610,7 +1800,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
1610
1800
  const dynamicFields = interestModelDynamicFieldObject.content.fields;
1611
1801
  interestModel = dynamicFields.value.fields;
1612
1802
  }
1613
- const borrowFeeDynamicFieldObjectResponse = await query.suiKit.client().getDynamicFieldObject({
1803
+ const borrowFeeDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
1614
1804
  parentId: marketId,
1615
1805
  name: {
1616
1806
  type: `${BORROW_FEE_PROTOCOL_ID}::market_dynamic_keys::BorrowFeeKey`,
@@ -1677,11 +1867,8 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
1677
1867
  var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) => {
1678
1868
  collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
1679
1869
  const marketId = query.address.get("core.market");
1680
- const marketObjectResponse = await query.suiKit.client().getObject({
1681
- id: marketId,
1682
- options: {
1683
- showContent: true
1684
- }
1870
+ const marketObjectResponse = await query.cache.queryGetObject(marketId, {
1871
+ showContent: true
1685
1872
  });
1686
1873
  const coinPrices = await query.utils.getCoinPrices(collateralCoinNames ?? []);
1687
1874
  const marketCollaterals = {};
@@ -1714,11 +1901,8 @@ var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) =
1714
1901
  };
1715
1902
  var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
1716
1903
  const marketId = query.address.get("core.market");
1717
- marketObject = marketObject || (await query.suiKit.client().getObject({
1718
- id: marketId,
1719
- options: {
1720
- showContent: true
1721
- }
1904
+ marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
1905
+ showContent: true
1722
1906
  })).data;
1723
1907
  coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
1724
1908
  let marketCollateral;
@@ -1737,7 +1921,7 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
1737
1921
  const fields = marketObject.content.fields;
1738
1922
  const coinType = query.utils.parseCoinType(collateralCoinName);
1739
1923
  const riskModelParentId = fields.risk_models.fields.table.fields.id.id;
1740
- const riskModelDynamicFieldObjectResponse = await query.suiKit.client().getDynamicFieldObject({
1924
+ const riskModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
1741
1925
  parentId: riskModelParentId,
1742
1926
  name: {
1743
1927
  type: "0x1::type_name::TypeName",
@@ -1752,7 +1936,7 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
1752
1936
  riskModel = dynamicFields.value.fields;
1753
1937
  }
1754
1938
  const collateralStatParentId = fields.collateral_stats.fields.table.fields.id.id;
1755
- const collateralStatDynamicFieldObjectResponse = await query.suiKit.client().getDynamicFieldObject({
1939
+ const collateralStatDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
1756
1940
  parentId: collateralStatParentId,
1757
1941
  name: {
1758
1942
  type: "0x1::type_name::TypeName",
@@ -1808,7 +1992,7 @@ var getObligations = async (query, ownerAddress) => {
1808
1992
  let hasNextPage = false;
1809
1993
  let nextCursor = null;
1810
1994
  do {
1811
- const paginatedKeyObjectsResponse = await query.suiKit.client().getOwnedObjects({
1995
+ const paginatedKeyObjectsResponse = await query.cache.queryGetOwnedObjects({
1812
1996
  owner,
1813
1997
  filter: {
1814
1998
  StructType: `${protocolObjectId}::obligation::ObligationKey`
@@ -1824,7 +2008,7 @@ var getObligations = async (query, ownerAddress) => {
1824
2008
  }
1825
2009
  } while (hasNextPage);
1826
2010
  const keyObjectIds = keyObjectsResponse.map((ref) => ref?.data?.objectId).filter((id) => id !== void 0);
1827
- const keyObjects = await query.suiKit.getObjects(keyObjectIds);
2011
+ const keyObjects = await query.cache.queryGetObjects(keyObjectIds);
1828
2012
  const obligations = [];
1829
2013
  for (const keyObject of keyObjects) {
1830
2014
  const keyId = keyObject.objectId;
@@ -1838,12 +2022,10 @@ var getObligations = async (query, ownerAddress) => {
1838
2022
  return obligations;
1839
2023
  };
1840
2024
  var getObligationLocked = async (query, obligationId) => {
1841
- const obligationObjectResponse = await query.suiKit.client().getObject({
1842
- id: obligationId,
1843
- options: {
1844
- showContent: true
1845
- }
1846
- });
2025
+ const obligationObjectResponse = await query.cache.queryGetObject(
2026
+ obligationId,
2027
+ { showContent: true }
2028
+ );
1847
2029
  let obligationLocked = false;
1848
2030
  if (obligationObjectResponse.data && obligationObjectResponse?.data?.content?.dataType === "moveObject" && "lock_key" in obligationObjectResponse.data.content.fields) {
1849
2031
  obligationLocked = Boolean(
@@ -1855,9 +2037,11 @@ var getObligationLocked = async (query, obligationId) => {
1855
2037
  var queryObligation = async (query, obligationId) => {
1856
2038
  const packageId = query.address.get("core.packages.query.id");
1857
2039
  const queryTarget = `${packageId}::obligation_query::obligation_data`;
1858
- const txBlock = new import_sui_kit.SuiTxBlock();
1859
- txBlock.moveCall(queryTarget, [obligationId]);
1860
- const queryResult = await query.suiKit.inspectTxn(txBlock);
2040
+ const args = [obligationId];
2041
+ const queryResult = await query.cache.queryInspectTxn(
2042
+ { queryTarget, args }
2043
+ // txBlock
2044
+ );
1861
2045
  return queryResult.events[0].parsedJson;
1862
2046
  };
1863
2047
  var getCoinAmounts = async (query, assetCoinNames, ownerAddress) => {
@@ -1867,20 +2051,22 @@ var getCoinAmounts = async (query, assetCoinNames, ownerAddress) => {
1867
2051
  let hasNextPage = false;
1868
2052
  let nextCursor = null;
1869
2053
  do {
1870
- const paginatedCoinObjectsResponse = await query.suiKit.client().getOwnedObjects({
1871
- owner,
1872
- filter: {
1873
- MatchAny: assetCoinNames.map((assetCoinName) => {
1874
- const coinType = query.utils.parseCoinType(assetCoinName);
1875
- return { StructType: `0x2::coin::Coin<${coinType}>` };
1876
- })
1877
- },
1878
- options: {
1879
- showType: true,
1880
- showContent: true
1881
- },
1882
- cursor: nextCursor
1883
- });
2054
+ const paginatedCoinObjectsResponse = await query.cache.queryGetOwnedObjects(
2055
+ {
2056
+ owner,
2057
+ filter: {
2058
+ MatchAny: assetCoinNames.map((assetCoinName) => {
2059
+ const coinType = query.utils.parseCoinType(assetCoinName);
2060
+ return { StructType: `0x2::coin::Coin<${coinType}>` };
2061
+ })
2062
+ },
2063
+ options: {
2064
+ showType: true,
2065
+ showContent: true
2066
+ },
2067
+ cursor: nextCursor
2068
+ }
2069
+ );
1884
2070
  coinObjectsResponse.push(...paginatedCoinObjectsResponse.data);
1885
2071
  if (paginatedCoinObjectsResponse.hasNextPage && paginatedCoinObjectsResponse.nextCursor) {
1886
2072
  hasNextPage = true;
@@ -1914,14 +2100,16 @@ var getCoinAmount = async (query, assetCoinName, ownerAddress) => {
1914
2100
  let hasNextPage = false;
1915
2101
  let nextCursor = null;
1916
2102
  do {
1917
- const paginatedCoinObjectsResponse = await query.suiKit.client().getOwnedObjects({
1918
- owner,
1919
- filter: { StructType: `0x2::coin::Coin<${coinType}>` },
1920
- options: {
1921
- showContent: true
1922
- },
1923
- cursor: nextCursor
1924
- });
2103
+ const paginatedCoinObjectsResponse = await query.cache.queryGetOwnedObjects(
2104
+ {
2105
+ owner,
2106
+ filter: { StructType: `0x2::coin::Coin<${coinType}>` },
2107
+ options: {
2108
+ showContent: true
2109
+ },
2110
+ cursor: nextCursor
2111
+ }
2112
+ );
1925
2113
  coinObjectsResponse.push(...paginatedCoinObjectsResponse.data);
1926
2114
  if (paginatedCoinObjectsResponse.hasNextPage && paginatedCoinObjectsResponse.nextCursor) {
1927
2115
  hasNextPage = true;
@@ -1953,7 +2141,7 @@ var getMarketCoinAmounts = async (query, marketCoinNames, ownerAddress) => {
1953
2141
  let hasNextPage = false;
1954
2142
  let nextCursor = null;
1955
2143
  do {
1956
- const paginatedMarketCoinObjectsResponse = await query.suiKit.client().getOwnedObjects({
2144
+ const paginatedMarketCoinObjectsResponse = await query.cache.queryGetOwnedObjects({
1957
2145
  owner,
1958
2146
  filter: {
1959
2147
  MatchAny: marketCoinNames.map((marketCoinName) => {
@@ -2002,7 +2190,7 @@ var getMarketCoinAmount = async (query, marketCoinName, ownerAddress) => {
2002
2190
  let hasNextPage = false;
2003
2191
  let nextCursor = null;
2004
2192
  do {
2005
- const paginatedMarketCoinObjectsResponse = await query.suiKit.client().getOwnedObjects({
2193
+ const paginatedMarketCoinObjectsResponse = await query.cache.queryGetOwnedObjects({
2006
2194
  owner,
2007
2195
  filter: { StructType: `0x2::coin::Coin<${marketCoinType}>` },
2008
2196
  options: {
@@ -2182,7 +2370,7 @@ var getStakeAccounts = async (query, ownerAddress) => {
2182
2370
  let hasNextPage = false;
2183
2371
  let nextCursor = null;
2184
2372
  do {
2185
- const paginatedStakeObjectsResponse = await query.suiKit.client().getOwnedObjects({
2373
+ const paginatedStakeObjectsResponse = await query.cache.queryGetOwnedObjects({
2186
2374
  owner,
2187
2375
  filter: { StructType: stakeAccountType },
2188
2376
  options: {
@@ -2220,7 +2408,7 @@ var getStakeAccounts = async (query, ownerAddress) => {
2220
2408
  {}
2221
2409
  );
2222
2410
  const stakeObjectIds = stakeObjectsResponse.map((ref) => ref?.data?.objectId).filter((id) => id !== void 0);
2223
- const stakeObjects = await query.suiKit.getObjects(stakeObjectIds);
2411
+ const stakeObjects = await query.cache.queryGetObjects(stakeObjectIds);
2224
2412
  for (const stakeObject of stakeObjects) {
2225
2413
  const id = stakeObject.objectId;
2226
2414
  const type = stakeObject.type;
@@ -2328,12 +2516,9 @@ var getStakeAccounts = async (query, ownerAddress) => {
2328
2516
  var getStakePool = async (query, marketCoinName) => {
2329
2517
  const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
2330
2518
  let stakePool = void 0;
2331
- const stakePoolObjectResponse = await query.suiKit.client().getObject({
2332
- id: poolId,
2333
- options: {
2334
- showContent: true,
2335
- showType: true
2336
- }
2519
+ const stakePoolObjectResponse = await query.cache.queryGetObject(poolId, {
2520
+ showContent: true,
2521
+ showType: true
2337
2522
  });
2338
2523
  if (stakePoolObjectResponse.data) {
2339
2524
  const stakePoolObject = stakePoolObjectResponse.data;
@@ -2374,13 +2559,13 @@ var getStakeRewardPool = async (query, marketCoinName) => {
2374
2559
  `spool.pools.${marketCoinName}.rewardPoolId`
2375
2560
  );
2376
2561
  let stakeRewardPool = void 0;
2377
- const stakeRewardPoolObjectResponse = await query.suiKit.client().getObject({
2378
- id: poolId,
2379
- options: {
2562
+ const stakeRewardPoolObjectResponse = await query.cache.queryGetObject(
2563
+ poolId,
2564
+ {
2380
2565
  showContent: true,
2381
2566
  showType: true
2382
2567
  }
2383
- });
2568
+ );
2384
2569
  if (stakeRewardPoolObjectResponse.data) {
2385
2570
  const stakeRewardPoolObject = stakeRewardPoolObjectResponse.data;
2386
2571
  const id = stakeRewardPoolObject.objectId;
@@ -2410,17 +2595,15 @@ var getStakeRewardPool = async (query, marketCoinName) => {
2410
2595
 
2411
2596
  // src/queries/borrowIncentiveQuery.ts
2412
2597
  var import_utils6 = require("@mysten/sui.js/utils");
2413
- var import_sui_kit2 = require("@scallop-io/sui-kit");
2414
2598
  var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer = false) => {
2415
2599
  borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
2416
2600
  ...SUPPORT_BORROW_INCENTIVE_POOLS
2417
2601
  ];
2418
2602
  const queryPkgId = query.address.get("borrowIncentive.query");
2419
2603
  const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
2420
- const txBlock = new import_sui_kit2.SuiTxBlock();
2421
2604
  const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
2422
- txBlock.moveCall(queryTarget, [incentivePoolsId]);
2423
- const queryResult = await query.suiKit.inspectTxn(txBlock);
2605
+ const args = [incentivePoolsId];
2606
+ const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
2424
2607
  const borrowIncentivePoolsQueryData = queryResult.events[0].parsedJson;
2425
2608
  const borrowIncentivePools = {};
2426
2609
  if (indexer) {
@@ -2497,9 +2680,8 @@ var queryBorrowIncentiveAccounts = async (query, obligationId, borrowIncentiveCo
2497
2680
  "borrowIncentive.incentiveAccounts"
2498
2681
  );
2499
2682
  const queryTarget = `${queryPkgId}::incentive_account_query::incentive_account_data`;
2500
- const txBlock = new import_sui_kit2.SuiTxBlock();
2501
- txBlock.moveCall(queryTarget, [incentiveAccountsId, obligationId]);
2502
- const queryResult = await query.suiKit.inspectTxn(txBlock);
2683
+ const args = [incentiveAccountsId, obligationId];
2684
+ const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
2503
2685
  const borrowIncentiveAccountsQueryData = queryResult.events[0].parsedJson;
2504
2686
  const borrowIncentiveAccounts = Object.values(
2505
2687
  borrowIncentiveAccountsQueryData.pool_records
@@ -2577,12 +2759,10 @@ var getPythPrice = async (query, assetCoinName) => {
2577
2759
  const pythFeedObjectId = query.address.get(
2578
2760
  `core.coins.${assetCoinName}.oracle.pyth.feedObject`
2579
2761
  );
2580
- const priceFeedObjectResponse = await query.suiKit.client().getObject({
2581
- id: pythFeedObjectId,
2582
- options: {
2583
- showContent: true
2584
- }
2585
- });
2762
+ const priceFeedObjectResponse = await query.cache.queryGetObject(
2763
+ pythFeedObjectId,
2764
+ { showContent: true }
2765
+ );
2586
2766
  if (priceFeedObjectResponse.data) {
2587
2767
  const priceFeedPoolObject = priceFeedObjectResponse.data;
2588
2768
  if (priceFeedPoolObject.content && "fields" in priceFeedPoolObject.content) {
@@ -3146,7 +3326,7 @@ var getVeSca = async (query, veScaKeyId, ownerAddress) => {
3146
3326
  const tableId = IS_VE_SCA_TEST ? "0xc607241e4a679fe376d1170b2fbe07b64917bfe69100d4825241cda20039d4bd" : query.address.get(`vesca.tableId`);
3147
3327
  veScaKeyId = veScaKeyId || (await getVescaKeys(query, ownerAddress))[0].objectId;
3148
3328
  let vesca = void 0;
3149
- const veScaDynamicFieldObjectResponse = await query.suiKit.client().getDynamicFieldObject({
3329
+ const veScaDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
3150
3330
  parentId: tableId,
3151
3331
  name: {
3152
3332
  type: "0x2::object::ID",
@@ -3178,7 +3358,9 @@ var getVeSca = async (query, veScaKeyId, ownerAddress) => {
3178
3358
  // src/models/scallopIndexer.ts
3179
3359
  var import_axios2 = __toESM(require("axios"));
3180
3360
  var ScallopIndexer = class {
3181
- constructor() {
3361
+ constructor(params, instance) {
3362
+ this.params = params;
3363
+ this._cache = instance?.cache ?? new ScallopCache();
3182
3364
  this._requestClient = import_axios2.default.create({
3183
3365
  baseURL: SDK_API_BASE_URL,
3184
3366
  headers: {
@@ -3194,7 +3376,12 @@ var ScallopIndexer = class {
3194
3376
  * @return Market data.
3195
3377
  */
3196
3378
  async getMarket() {
3197
- const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market`);
3379
+ const response = await this._cache.queryClient.fetchQuery({
3380
+ queryKey: ["market"],
3381
+ queryFn: async () => {
3382
+ return await this._requestClient.get(`/api/market`);
3383
+ }
3384
+ });
3198
3385
  if (response.status === 200) {
3199
3386
  return {
3200
3387
  pools: response.data.pools.reduce((marketPools, marketPool) => {
@@ -3219,15 +3406,8 @@ var ScallopIndexer = class {
3219
3406
  * @return Market pools data.
3220
3407
  */
3221
3408
  async getMarketPools() {
3222
- const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/pools`);
3223
- if (response.status === 200) {
3224
- return response.data.pools.reduce((marketPools, marketPool) => {
3225
- marketPools[marketPool.coinName] = marketPool;
3226
- return marketPools;
3227
- }, {});
3228
- } else {
3229
- throw Error("Failed to getMarketPools.");
3230
- }
3409
+ const response = (await this.getMarket()).pools;
3410
+ return response;
3231
3411
  }
3232
3412
  /**
3233
3413
  * Get market pool index data.
@@ -3235,12 +3415,7 @@ var ScallopIndexer = class {
3235
3415
  * @return Market pool data.
3236
3416
  */
3237
3417
  async getMarketPool(poolCoinName) {
3238
- const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/pool/${poolCoinName}`);
3239
- if (response.status === 200) {
3240
- return response.data.pool;
3241
- } else {
3242
- throw Error("Failed to getMarketPool.");
3243
- }
3418
+ return (await this.getMarketPools())[poolCoinName];
3244
3419
  }
3245
3420
  /**
3246
3421
  * Get market collaterals index data.
@@ -3248,18 +3423,7 @@ var ScallopIndexer = class {
3248
3423
  * @return Market collaterals data.
3249
3424
  */
3250
3425
  async getMarketCollaterals() {
3251
- const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/collaterals`);
3252
- if (response.status === 200) {
3253
- return response.data.collaterals.reduce(
3254
- (marketCollaterals, marketCollateral) => {
3255
- marketCollaterals[marketCollateral.coinName] = marketCollateral;
3256
- return marketCollaterals;
3257
- },
3258
- {}
3259
- );
3260
- } else {
3261
- throw Error("Failed to getMarketCollaterals.");
3262
- }
3426
+ return (await this.getMarket()).collaterals;
3263
3427
  }
3264
3428
  /**
3265
3429
  * Get market collateral index data.
@@ -3267,12 +3431,7 @@ var ScallopIndexer = class {
3267
3431
  * @return Market collateral data.
3268
3432
  */
3269
3433
  async getMarketCollateral(collateralCoinName) {
3270
- const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/collateral/${collateralCoinName}`);
3271
- if (response.status === 200) {
3272
- return response.data.collateral;
3273
- } else {
3274
- throw Error("Failed to getMarketCollateral.");
3275
- }
3434
+ return (await this.getMarketCollaterals())[collateralCoinName];
3276
3435
  }
3277
3436
  /**
3278
3437
  * Get spools index data.
@@ -3280,7 +3439,12 @@ var ScallopIndexer = class {
3280
3439
  * @return Spools data.
3281
3440
  */
3282
3441
  async getSpools() {
3283
- const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/spools`);
3442
+ const response = await this._cache.queryClient.fetchQuery({
3443
+ queryKey: ["spools"],
3444
+ queryFn: async () => {
3445
+ return await this._requestClient.get(`/api/spools`);
3446
+ }
3447
+ });
3284
3448
  if (response.status === 200) {
3285
3449
  return response.data.spools.reduce((spools, spool) => {
3286
3450
  spools[spool.marketCoinName] = spool;
@@ -3296,12 +3460,7 @@ var ScallopIndexer = class {
3296
3460
  * @return Spool data.
3297
3461
  */
3298
3462
  async getSpool(marketCoinName) {
3299
- const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/spool/${marketCoinName}`);
3300
- if (response.status === 200) {
3301
- return response.data.spool;
3302
- } else {
3303
- throw Error("Failed to getSpool.");
3304
- }
3463
+ return (await this.getSpools())[marketCoinName];
3305
3464
  }
3306
3465
  /**
3307
3466
  * Get borrow incentive pools index data.
@@ -3309,7 +3468,12 @@ var ScallopIndexer = class {
3309
3468
  * @return Borrow incentive pools data.
3310
3469
  */
3311
3470
  async getBorrowIncentivePools() {
3312
- const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/borrowIncentivePools`);
3471
+ const response = await this._cache.queryClient.fetchQuery({
3472
+ queryKey: ["borrowIncentivePools"],
3473
+ queryFn: async () => {
3474
+ return await this._requestClient.get(`/api/borrowIncentivePools`);
3475
+ }
3476
+ });
3313
3477
  if (response.status === 200) {
3314
3478
  return response.data.borrowIncentivePools.reduce(
3315
3479
  (borrowIncentivePools, borrowIncentivePool) => {
@@ -3328,14 +3492,7 @@ var ScallopIndexer = class {
3328
3492
  * @return Borrow incentive pool data.
3329
3493
  */
3330
3494
  async getBorrowIncentivePool(borrowIncentiveCoinName) {
3331
- const response = await this._requestClient.get(
3332
- `${SDK_API_BASE_URL}/api/borrowIncentivePool/${borrowIncentiveCoinName}`
3333
- );
3334
- if (response.status === 200) {
3335
- return response.data.borrowIncentivePool;
3336
- } else {
3337
- throw Error("Failed to getSpool.");
3338
- }
3495
+ return (await this.getBorrowIncentivePools())[borrowIncentiveCoinName];
3339
3496
  }
3340
3497
  /**
3341
3498
  * Get total value locked index data.
@@ -3343,7 +3500,12 @@ var ScallopIndexer = class {
3343
3500
  * @return Total value locked.
3344
3501
  */
3345
3502
  async getTotalValueLocked() {
3346
- const response = await this._requestClient.get(`${SDK_API_BASE_URL}/api/market/tvl`);
3503
+ const response = await this._cache.queryClient.fetchQuery({
3504
+ queryKey: ["totalValueLocked"],
3505
+ queryFn: async () => {
3506
+ return await this._requestClient.get(`/api/market/tvl`);
3507
+ }
3508
+ });
3347
3509
  if (response.status === 200) {
3348
3510
  return response.data;
3349
3511
  } else {
@@ -3356,17 +3518,22 @@ var ScallopIndexer = class {
3356
3518
  var ScallopQuery = class {
3357
3519
  constructor(params, instance) {
3358
3520
  this.params = params;
3359
- this.suiKit = instance?.suiKit ?? new import_sui_kit3.SuiKit(params);
3360
- this.address = instance?.address ?? new ScallopAddress({
3361
- id: params?.addressesId || ADDRESSES_ID,
3362
- network: params?.networkType
3363
- });
3521
+ this.suiKit = instance?.suiKit ?? new import_sui_kit2.SuiKit(params);
3522
+ this.cache = instance?.cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS, this.suiKit);
3523
+ this.address = instance?.address ?? new ScallopAddress(
3524
+ {
3525
+ id: params?.addressesId || ADDRESSES_ID,
3526
+ network: params?.networkType
3527
+ },
3528
+ this.cache
3529
+ );
3364
3530
  this.utils = instance?.utils ?? new ScallopUtils(this.params, {
3365
3531
  suiKit: this.suiKit,
3366
3532
  address: this.address,
3533
+ cache: this.cache,
3367
3534
  query: this
3368
3535
  });
3369
- this.indexer = new ScallopIndexer();
3536
+ this.indexer = new ScallopIndexer(this.params, { cache: this.cache });
3370
3537
  }
3371
3538
  /**
3372
3539
  * Request the scallop API to initialize data.
@@ -3751,14 +3918,19 @@ var ScallopUtils = class {
3751
3918
  return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
3752
3919
  };
3753
3920
  this.params = params;
3754
- this._suiKit = instance?.suiKit ?? new import_sui_kit4.SuiKit(params);
3755
- this._address = instance?.address ?? new ScallopAddress({
3756
- id: params?.addressesId || ADDRESSES_ID,
3757
- network: params?.networkType
3758
- });
3921
+ this._suiKit = instance?.suiKit ?? new import_sui_kit3.SuiKit(params);
3922
+ this._cache = instance?.cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS, this._suiKit);
3923
+ this._address = instance?.address ?? new ScallopAddress(
3924
+ {
3925
+ id: params?.addressesId || ADDRESSES_ID,
3926
+ network: params?.networkType
3927
+ },
3928
+ this._cache
3929
+ );
3759
3930
  this._query = instance?.query ?? new ScallopQuery(params, {
3760
3931
  suiKit: this._suiKit,
3761
- address: this._address
3932
+ address: this._address,
3933
+ cache: this._cache
3762
3934
  });
3763
3935
  this.isTestnet = params.networkType ? params.networkType === "testnet" : false;
3764
3936
  }
@@ -3975,33 +4147,52 @@ var ScallopUtils = class {
3975
4147
  }
3976
4148
  if (lackPricesCoinNames.length > 0) {
3977
4149
  const endpoints = this.params.pythEndpoints ?? PYTH_ENDPOINTS[this.isTestnet ? "testnet" : "mainnet"];
3978
- try {
3979
- for (const endpoint of endpoints) {
3980
- try {
3981
- const pythConnection = new import_pyth_sui_js.SuiPriceServiceConnection(endpoint);
3982
- const priceIds = lackPricesCoinNames.map(
3983
- (coinName) => this._address.get(`core.coins.${coinName}.oracle.pyth.feed`)
4150
+ const failedRequests = new Set(
4151
+ lackPricesCoinNames
4152
+ );
4153
+ for (const endpoint of endpoints) {
4154
+ let hasFailRequest = false;
4155
+ const pythConnection = new import_pyth_sui_js.SuiPriceServiceConnection(endpoint);
4156
+ const priceIds = Array.from(failedRequests.values()).reduce(
4157
+ (acc, coinName) => {
4158
+ const priceId = this._address.get(
4159
+ `core.coins.${coinName}.oracle.pyth.feed`
3984
4160
  );
3985
- const priceFeeds = await pythConnection.getLatestPriceFeeds(priceIds) || [];
3986
- for (const [index, feed] of priceFeeds.entries()) {
3987
- const data = parseDataFromPythPriceFeed(feed, this._address);
3988
- const coinName = lackPricesCoinNames[index];
4161
+ acc[coinName] = priceId;
4162
+ return acc;
4163
+ },
4164
+ {}
4165
+ );
4166
+ for (const [coinName, priceId] of Object.entries(priceIds)) {
4167
+ try {
4168
+ const feed = await this._cache.queryClient.fetchQuery({
4169
+ queryKey: [priceId],
4170
+ queryFn: async () => {
4171
+ return await pythConnection.getLatestPriceFeeds([priceId]);
4172
+ }
4173
+ // staleTime: 15000,
4174
+ });
4175
+ if (feed) {
4176
+ const data = parseDataFromPythPriceFeed(feed[0], this._address);
3989
4177
  this._priceMap.set(coinName, {
3990
4178
  price: data.price,
3991
4179
  publishTime: data.publishTime
3992
4180
  });
3993
4181
  coinPrices[coinName] = data.price;
3994
4182
  }
3995
- break;
4183
+ failedRequests.delete(coinName);
3996
4184
  } catch (e) {
3997
4185
  console.warn(
3998
- `Failed to update price feeds with endpoint ${endpoint}: ${e}`
4186
+ `Failed to get price ${coinName} feeds with endpoint ${endpoint}: ${e}`
3999
4187
  );
4188
+ hasFailRequest = true;
4000
4189
  }
4001
- throw new Error("Failed to update price feeds with all endpoins");
4002
4190
  }
4003
- } catch (_e) {
4004
- for (const coinName of lackPricesCoinNames) {
4191
+ if (!hasFailRequest)
4192
+ break;
4193
+ }
4194
+ if (failedRequests.size > 0) {
4195
+ for (const coinName of failedRequests.values()) {
4005
4196
  const price = await this._query.getPriceFromPyth(coinName);
4006
4197
  this._priceMap.set(coinName, {
4007
4198
  price,
@@ -4069,12 +4260,12 @@ var ScallopUtils = class {
4069
4260
 
4070
4261
  // src/models/scallopBuilder.ts
4071
4262
  var import_utils19 = require("@mysten/sui.js/utils");
4072
- var import_sui_kit9 = require("@scallop-io/sui-kit");
4263
+ var import_sui_kit8 = require("@scallop-io/sui-kit");
4073
4264
 
4074
4265
  // src/builders/coreBuilder.ts
4075
4266
  var import_transactions = require("@mysten/sui.js/transactions");
4076
4267
  var import_utils12 = require("@mysten/sui.js/utils");
4077
- var import_sui_kit5 = require("@scallop-io/sui-kit");
4268
+ var import_sui_kit4 = require("@scallop-io/sui-kit");
4078
4269
 
4079
4270
  // src/builders/oracle.ts
4080
4271
  var import_utils11 = require("@mysten/sui.js/utils");
@@ -4506,7 +4697,7 @@ var generateCoreQuickMethod = ({
4506
4697
  };
4507
4698
  };
4508
4699
  var newCoreTxBlock = (builder, initTxBlock) => {
4509
- const txBlock = initTxBlock instanceof import_transactions.TransactionBlock ? new import_sui_kit5.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit5.SuiTxBlock();
4700
+ const txBlock = initTxBlock instanceof import_transactions.TransactionBlock ? new import_sui_kit4.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit4.SuiTxBlock();
4510
4701
  const normalMethod = generateCoreNormalMethod({
4511
4702
  builder,
4512
4703
  txBlock
@@ -4536,7 +4727,7 @@ var newCoreTxBlock = (builder, initTxBlock) => {
4536
4727
  // src/builders/spoolBuilder.ts
4537
4728
  var import_transactions2 = require("@mysten/sui.js/transactions");
4538
4729
  var import_utils14 = require("@mysten/sui.js/utils");
4539
- var import_sui_kit6 = require("@scallop-io/sui-kit");
4730
+ var import_sui_kit5 = require("@scallop-io/sui-kit");
4540
4731
  var requireStakeAccountIds = async (...params) => {
4541
4732
  const [builder, txBlock, stakeMarketCoinName, stakeAccountId] = params;
4542
4733
  if (params.length === 4 && stakeAccountId)
@@ -4694,7 +4885,7 @@ var generateSpoolQuickMethod = ({
4694
4885
  };
4695
4886
  };
4696
4887
  var newSpoolTxBlock = (builder, initTxBlock) => {
4697
- const txBlock = initTxBlock instanceof import_transactions2.TransactionBlock ? new import_sui_kit6.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit6.SuiTxBlock();
4888
+ const txBlock = initTxBlock instanceof import_transactions2.TransactionBlock ? new import_sui_kit5.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit5.SuiTxBlock();
4698
4889
  const normalMethod = generateSpoolNormalMethod({
4699
4890
  builder,
4700
4891
  txBlock
@@ -4724,10 +4915,10 @@ var newSpoolTxBlock = (builder, initTxBlock) => {
4724
4915
  // src/builders/borrowIncentiveBuilder.ts
4725
4916
  var import_transactions3 = require("@mysten/sui.js/transactions");
4726
4917
  var import_utils17 = require("@mysten/sui.js/utils");
4727
- var import_sui_kit8 = require("@scallop-io/sui-kit");
4918
+ var import_sui_kit7 = require("@scallop-io/sui-kit");
4728
4919
 
4729
4920
  // src/builders/vescaBuilder.ts
4730
- var import_sui_kit7 = require("@scallop-io/sui-kit");
4921
+ var import_sui_kit6 = require("@scallop-io/sui-kit");
4731
4922
  var requireVeSca = async (...params) => {
4732
4923
  const [builder, txBlock, veScaKey] = params;
4733
4924
  if (params.length === 3 && veScaKey && typeof veScaKey === "string") {
@@ -4767,7 +4958,7 @@ var generateNormalVeScaMethod = ({
4767
4958
  veScaIds.treasury,
4768
4959
  scaCoin,
4769
4960
  unlockAtInSecondTimestamp,
4770
- import_sui_kit7.SUI_CLOCK_OBJECT_ID
4961
+ import_sui_kit6.SUI_CLOCK_OBJECT_ID
4771
4962
  ],
4772
4963
  []
4773
4964
  );
@@ -4781,7 +4972,7 @@ var generateNormalVeScaMethod = ({
4781
4972
  veScaIds.table,
4782
4973
  veScaIds.treasury,
4783
4974
  newUnlockAtInSecondTimestamp,
4784
- import_sui_kit7.SUI_CLOCK_OBJECT_ID
4975
+ import_sui_kit6.SUI_CLOCK_OBJECT_ID
4785
4976
  ],
4786
4977
  []
4787
4978
  );
@@ -4795,7 +4986,7 @@ var generateNormalVeScaMethod = ({
4795
4986
  veScaIds.table,
4796
4987
  veScaIds.treasury,
4797
4988
  scaCoin,
4798
- import_sui_kit7.SUI_CLOCK_OBJECT_ID
4989
+ import_sui_kit6.SUI_CLOCK_OBJECT_ID
4799
4990
  ],
4800
4991
  []
4801
4992
  );
@@ -4810,7 +5001,7 @@ var generateNormalVeScaMethod = ({
4810
5001
  veScaIds.treasury,
4811
5002
  scaCoin,
4812
5003
  newUnlockAtInSecondTimestamp,
4813
- import_sui_kit7.SUI_CLOCK_OBJECT_ID
5004
+ import_sui_kit6.SUI_CLOCK_OBJECT_ID
4814
5005
  ],
4815
5006
  []
4816
5007
  );
@@ -4823,7 +5014,7 @@ var generateNormalVeScaMethod = ({
4823
5014
  veScaKey,
4824
5015
  veScaIds.table,
4825
5016
  veScaIds.treasury,
4826
- import_sui_kit7.SUI_CLOCK_OBJECT_ID
5017
+ import_sui_kit6.SUI_CLOCK_OBJECT_ID
4827
5018
  ],
4828
5019
  []
4829
5020
  );
@@ -4969,7 +5160,7 @@ var generateQuickVeScaMethod = ({
4969
5160
  };
4970
5161
  };
4971
5162
  var newVeScaTxBlock = (builder, initTxBlock) => {
4972
- const txBlock = initTxBlock instanceof import_sui_kit7.TransactionBlock ? new import_sui_kit7.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit7.SuiTxBlock();
5163
+ const txBlock = initTxBlock instanceof import_sui_kit6.TransactionBlock ? new import_sui_kit6.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit6.SuiTxBlock();
4973
5164
  const normalMethod = generateNormalVeScaMethod({
4974
5165
  builder,
4975
5166
  txBlock
@@ -5084,7 +5275,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
5084
5275
  );
5085
5276
  },
5086
5277
  claimBorrowIncentive: (obligationId, obligationKey, coinName, rewardCoinName) => {
5087
- const rewardCoinNames = borrowIncentiveRewardCoins[coinName];
5278
+ const rewardCoinNames = builder.utils.getBorrowIncentiveRewardCoinName(coinName);
5088
5279
  if (rewardCoinNames.includes(rewardCoinName) === false) {
5089
5280
  throw new Error(`Invalid reward coin name ${rewardCoinName}`);
5090
5281
  }
@@ -5211,7 +5402,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
5211
5402
  };
5212
5403
  };
5213
5404
  var newBorrowIncentiveTxBlock = (builder, initTxBlock) => {
5214
- const txBlock = initTxBlock instanceof import_transactions3.TransactionBlock ? new import_sui_kit8.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit8.SuiTxBlock();
5405
+ const txBlock = initTxBlock instanceof import_transactions3.TransactionBlock ? new import_sui_kit7.SuiTxBlock(initTxBlock) : initTxBlock ? initTxBlock : new import_sui_kit7.SuiTxBlock();
5215
5406
  const normalMethod = generateBorrowIncentiveNormalMethod({
5216
5407
  builder,
5217
5408
  txBlock
@@ -5265,19 +5456,25 @@ var newScallopTxBlock = (builder, initTxBlock) => {
5265
5456
  var ScallopBuilder = class {
5266
5457
  constructor(params, instance) {
5267
5458
  this.params = params;
5268
- this.suiKit = instance?.suiKit ?? new import_sui_kit9.SuiKit(params);
5269
- this.address = instance?.address ?? new ScallopAddress({
5270
- id: params?.addressesId || ADDRESSES_ID,
5271
- network: params?.networkType
5272
- });
5459
+ this.suiKit = instance?.suiKit ?? new import_sui_kit8.SuiKit(params);
5460
+ this.cache = instance?.cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS, this.suiKit);
5461
+ this.address = instance?.address ?? new ScallopAddress(
5462
+ {
5463
+ id: params?.addressesId || ADDRESSES_ID,
5464
+ network: params?.networkType
5465
+ },
5466
+ this.cache
5467
+ );
5273
5468
  this.query = instance?.query ?? new ScallopQuery(params, {
5274
5469
  suiKit: this.suiKit,
5275
- address: this.address
5470
+ address: this.address,
5471
+ cache: this.cache
5276
5472
  });
5277
5473
  this.utils = instance?.utils ?? new ScallopUtils(this.params, {
5278
5474
  suiKit: this.suiKit,
5279
5475
  address: this.address,
5280
- query: this.query
5476
+ query: this.query,
5477
+ cache: this.cache
5281
5478
  });
5282
5479
  this.walletAddress = (0, import_utils19.normalizeSuiAddress)(
5283
5480
  params?.walletAddress || this.suiKit.currentAddress()
@@ -5358,25 +5555,32 @@ var ScallopBuilder = class {
5358
5555
  var ScallopClient = class {
5359
5556
  constructor(params, instance) {
5360
5557
  this.params = params;
5361
- this.suiKit = instance?.suiKit ?? new import_sui_kit10.SuiKit(params);
5362
- this.address = instance?.address ?? new ScallopAddress({
5363
- id: params?.addressesId || ADDRESSES_ID,
5364
- network: params?.networkType
5365
- });
5558
+ this.suiKit = instance?.suiKit ?? new import_sui_kit9.SuiKit(params);
5559
+ this.cache = instance?.cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS, this.suiKit);
5560
+ this.address = instance?.address ?? new ScallopAddress(
5561
+ {
5562
+ id: params?.addressesId || ADDRESSES_ID,
5563
+ network: params?.networkType
5564
+ },
5565
+ this.cache
5566
+ );
5366
5567
  this.query = instance?.query ?? new ScallopQuery(params, {
5367
5568
  suiKit: this.suiKit,
5368
- address: this.address
5569
+ address: this.address,
5570
+ cache: this.cache
5369
5571
  });
5370
5572
  this.utils = instance?.utils ?? new ScallopUtils(params, {
5371
5573
  suiKit: this.suiKit,
5372
5574
  address: this.address,
5373
- query: this.query
5575
+ query: this.query,
5576
+ cache: this.cache
5374
5577
  });
5375
5578
  this.builder = instance?.builder ?? new ScallopBuilder(params, {
5376
5579
  suiKit: this.suiKit,
5377
5580
  address: this.address,
5378
5581
  query: this.query,
5379
- utils: this.utils
5582
+ utils: this.utils,
5583
+ cache: this.cache
5380
5584
  });
5381
5585
  this.walletAddress = (0, import_utils20.normalizeSuiAddress)(
5382
5586
  params?.walletAddress || this.suiKit.currentAddress()
@@ -5882,13 +6086,20 @@ var ScallopClient = class {
5882
6086
 
5883
6087
  // src/models/scallop.ts
5884
6088
  var Scallop = class {
5885
- constructor(params) {
6089
+ constructor(params, cacheOptions) {
5886
6090
  this.params = params;
5887
- this.suiKit = new import_sui_kit11.SuiKit(params);
5888
- this._address = new ScallopAddress({
5889
- id: params?.addressesId || ADDRESSES_ID,
5890
- network: params?.networkType
5891
- });
6091
+ this.suiKit = new import_sui_kit10.SuiKit(params);
6092
+ this.cache = new ScallopCache(
6093
+ cacheOptions ?? DEFAULT_CACHE_OPTIONS,
6094
+ this.suiKit
6095
+ );
6096
+ this._address = new ScallopAddress(
6097
+ {
6098
+ id: params?.addressesId || ADDRESSES_ID,
6099
+ network: params?.networkType
6100
+ },
6101
+ this.cache
6102
+ );
5892
6103
  }
5893
6104
  /**
5894
6105
  * Get a scallop address instance that already has read addresses.
@@ -5910,7 +6121,8 @@ var Scallop = class {
5910
6121
  await this._address.read();
5911
6122
  const scallopBuilder = new ScallopBuilder(this.params, {
5912
6123
  suiKit: this.suiKit,
5913
- address: this._address
6124
+ address: this._address,
6125
+ cache: this.cache
5914
6126
  });
5915
6127
  return scallopBuilder;
5916
6128
  }
@@ -5925,7 +6137,7 @@ var Scallop = class {
5925
6137
  await this._address.read();
5926
6138
  const scallopClient = new ScallopClient(
5927
6139
  { ...this.params, walletAddress },
5928
- { suiKit: this.suiKit, address: this._address }
6140
+ { suiKit: this.suiKit, address: this._address, cache: this.cache }
5929
6141
  );
5930
6142
  return scallopClient;
5931
6143
  }
@@ -5939,7 +6151,8 @@ var Scallop = class {
5939
6151
  await this._address.read();
5940
6152
  const scallopQuery = new ScallopQuery(this.params, {
5941
6153
  suiKit: this.suiKit,
5942
- address: this._address
6154
+ address: this._address,
6155
+ cache: this.cache
5943
6156
  });
5944
6157
  return scallopQuery;
5945
6158
  }
@@ -5949,7 +6162,9 @@ var Scallop = class {
5949
6162
  * @return Scallop Indexer.
5950
6163
  */
5951
6164
  async createScallopIndexer() {
5952
- const scallopIndexer = new ScallopIndexer();
6165
+ const scallopIndexer = new ScallopIndexer(this.params, {
6166
+ cache: this.cache
6167
+ });
5953
6168
  return scallopIndexer;
5954
6169
  }
5955
6170
  /**
@@ -5962,7 +6177,8 @@ var Scallop = class {
5962
6177
  await this._address.read();
5963
6178
  const scallopUtils = new ScallopUtils(this.params, {
5964
6179
  suiKit: this.suiKit,
5965
- address: this._address
6180
+ address: this._address,
6181
+ cache: this.cache
5966
6182
  });
5967
6183
  return scallopUtils;
5968
6184
  }
@@ -5992,6 +6208,7 @@ var Scallop = class {
5992
6208
  Scallop,
5993
6209
  ScallopAddress,
5994
6210
  ScallopBuilder,
6211
+ ScallopCache,
5995
6212
  ScallopClient,
5996
6213
  ScallopIndexer,
5997
6214
  ScallopQuery,