@scallop-io/sui-scallop-sdk 0.44.28 → 0.46.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.
Files changed (60) hide show
  1. package/dist/builders/borrowIncentiveBuilder.d.ts +1 -1
  2. package/dist/builders/referralBuilder.d.ts +12 -0
  3. package/dist/constants/cache.d.ts +8 -0
  4. package/dist/constants/common.d.ts +1 -1
  5. package/dist/index.js +890 -419
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +967 -493
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/models/index.d.ts +1 -0
  10. package/dist/models/scallop.d.ts +7 -1
  11. package/dist/models/scallopAddress.d.ts +4 -2
  12. package/dist/models/scallopBuilder.d.ts +2 -0
  13. package/dist/models/scallopCache.d.ts +75 -0
  14. package/dist/models/scallopClient.d.ts +2 -0
  15. package/dist/models/scallopIndexer.d.ts +5 -3
  16. package/dist/models/scallopQuery.d.ts +28 -28
  17. package/dist/models/scallopUtils.d.ts +1 -0
  18. package/dist/queries/coreQuery.d.ts +3 -29
  19. package/dist/queries/index.d.ts +1 -0
  20. package/dist/queries/priceQuery.d.ts +3 -1
  21. package/dist/queries/referralQuery.d.ts +7 -0
  22. package/dist/queries/vescaQuery.d.ts +6 -2
  23. package/dist/types/address.d.ts +15 -0
  24. package/dist/types/builder/core.d.ts +2 -0
  25. package/dist/types/builder/index.d.ts +2 -1
  26. package/dist/types/builder/referral.d.ts +30 -0
  27. package/dist/types/builder/vesca.d.ts +1 -0
  28. package/dist/types/model.d.ts +2 -0
  29. package/package.json +8 -6
  30. package/src/builders/borrowIncentiveBuilder.ts +12 -21
  31. package/src/builders/coreBuilder.ts +54 -0
  32. package/src/builders/index.ts +5 -2
  33. package/src/builders/referralBuilder.ts +178 -0
  34. package/src/builders/vescaBuilder.ts +8 -6
  35. package/src/constants/cache.ts +15 -0
  36. package/src/constants/common.ts +9 -2
  37. package/src/constants/vesca.ts +1 -3
  38. package/src/models/index.ts +1 -0
  39. package/src/models/scallop.ts +26 -7
  40. package/src/models/scallopAddress.ts +87 -38
  41. package/src/models/scallopBuilder.ts +14 -4
  42. package/src/models/scallopCache.ts +285 -0
  43. package/src/models/scallopClient.ts +15 -4
  44. package/src/models/scallopIndexer.ts +58 -84
  45. package/src/models/scallopQuery.ts +54 -5
  46. package/src/models/scallopUtils.ts +66 -37
  47. package/src/queries/borrowIncentiveQuery.ts +6 -12
  48. package/src/queries/coreQuery.ts +83 -260
  49. package/src/queries/index.ts +1 -0
  50. package/src/queries/priceQuery.ts +48 -9
  51. package/src/queries/referralQuery.ts +27 -0
  52. package/src/queries/spoolQuery.ts +20 -27
  53. package/src/queries/vescaQuery.ts +95 -17
  54. package/src/types/address.ts +15 -0
  55. package/src/types/builder/core.ts +14 -0
  56. package/src/types/builder/index.ts +2 -0
  57. package/src/types/builder/referral.ts +51 -0
  58. package/src/types/builder/vesca.ts +1 -0
  59. package/src/types/model.ts +2 -0
  60. package/src/types/query/borrowIncentive.ts +0 -107
@@ -1,4 +1,3 @@
1
- import axios, { AxiosInstance } from 'axios';
2
1
  import { API_BASE_URL } from '../constants';
3
2
  import type { NetworkType } from '@scallop-io/sui-kit';
4
3
  import type {
@@ -6,6 +5,9 @@ import type {
6
5
  AddressesInterface,
7
6
  AddressStringPath,
8
7
  } from '../types';
8
+ import { ScallopCache } from './scallopCache';
9
+ import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
10
+ import axios, { AxiosInstance } from 'axios';
9
11
 
10
12
  const EMPTY_ADDRESSES: AddressesInterface = {
11
13
  core: {
@@ -17,6 +19,45 @@ const EMPTY_ADDRESSES: AddressesInterface = {
17
19
  coinDecimalsRegistry: '',
18
20
  obligationAccessStore: '',
19
21
  coins: {
22
+ cetus: {
23
+ id: '',
24
+ metaData: '',
25
+ treasury: '',
26
+ oracle: {
27
+ supra: '',
28
+ switchboard: '',
29
+ pyth: {
30
+ feed: '',
31
+ feedObject: '',
32
+ },
33
+ },
34
+ },
35
+ apt: {
36
+ id: '',
37
+ metaData: '',
38
+ treasury: '',
39
+ oracle: {
40
+ supra: '',
41
+ switchboard: '',
42
+ pyth: {
43
+ feed: '',
44
+ feedObject: '',
45
+ },
46
+ },
47
+ },
48
+ sol: {
49
+ id: '',
50
+ metaData: '',
51
+ treasury: '',
52
+ oracle: {
53
+ supra: '',
54
+ switchboard: '',
55
+ pyth: {
56
+ feed: '',
57
+ feedObject: '',
58
+ },
59
+ },
60
+ },
20
61
  btc: {
21
62
  id: '',
22
63
  metaData: '',
@@ -138,15 +179,8 @@ const EMPTY_ADDRESSES: AddressesInterface = {
138
179
  oracles: {
139
180
  xOracle: '',
140
181
  xOracleCap: '',
141
- supra: {
142
- registry: '',
143
- registryCap: '',
144
- holder: '',
145
- },
146
- switchboard: {
147
- registry: '',
148
- registryCap: '',
149
- },
182
+ supra: { registry: '', registryCap: '', holder: '' },
183
+ switchboard: { registry: '', registryCap: '' },
150
184
  pyth: {
151
185
  registry: '',
152
186
  registryCap: '',
@@ -176,27 +210,25 @@ const EMPTY_ADDRESSES: AddressesInterface = {
176
210
  id: '',
177
211
  upgradeCap: '',
178
212
  },
179
- query: {
213
+ protocolWhitelist: {
180
214
  id: '',
181
215
  upgradeCap: '',
182
216
  },
183
- pyth: {
217
+ query: {
184
218
  id: '',
185
219
  upgradeCap: '',
186
220
  },
187
- switchboard: {
221
+ supra: { id: '', upgradeCap: '' },
222
+ pyth: {
188
223
  id: '',
189
224
  upgradeCap: '',
190
225
  },
226
+ switchboard: { id: '', upgradeCap: '' },
191
227
  xOracle: {
192
228
  id: '',
193
229
  upgradeCap: '',
194
230
  },
195
- // Deploy for faucet on testnet.
196
- testCoin: {
197
- id: '',
198
- upgradeCap: '',
199
- },
231
+ testCoin: { id: '', upgradeCap: '' },
200
232
  },
201
233
  },
202
234
  spool: {
@@ -237,26 +269,40 @@ const EMPTY_ADDRESSES: AddressesInterface = {
237
269
  rewardPoolId: '',
238
270
  },
239
271
  },
272
+ config: '',
240
273
  },
241
274
  borrowIncentive: {
242
275
  id: '',
243
276
  adminCap: '',
244
277
  object: '',
245
278
  query: '',
246
- config: '',
247
279
  incentivePools: '',
248
280
  incentiveAccounts: '',
281
+ config: '',
249
282
  },
250
283
  vesca: {
251
284
  id: '',
285
+ object: '',
252
286
  adminCap: '',
253
287
  tableId: '',
254
288
  table: '',
255
289
  treasury: '',
256
290
  config: '',
257
291
  },
292
+ referral: {
293
+ id: '',
294
+ version: '',
295
+ object: '',
296
+ adminCap: '',
297
+ referralBindings: '',
298
+ bindingTableId: '',
299
+ referralRevenuePool: '',
300
+ revenueTableId: '',
301
+ referralTiers: '',
302
+ tiersTableId: '',
303
+ authorizedWitnessList: '',
304
+ },
258
305
  };
259
-
260
306
  /**
261
307
  * @description
262
308
  * It provides methods for managing addresses.
@@ -270,20 +316,17 @@ const EMPTY_ADDRESSES: AddressesInterface = {
270
316
  */
271
317
  export class ScallopAddress {
272
318
  private readonly _auth?: string;
319
+ private readonly _requestClient: AxiosInstance;
273
320
 
274
- private _requestClient: AxiosInstance;
275
321
  private _id?: string;
276
322
  private _network: NetworkType;
277
323
  private _currentAddresses?: AddressesInterface;
278
324
  private _addressesMap: Map<NetworkType, AddressesInterface>;
325
+ private _cache: ScallopCache;
279
326
 
280
- public constructor(params: ScallopAddressParams) {
327
+ public constructor(params: ScallopAddressParams, cache?: ScallopCache) {
281
328
  const { id, auth, network } = params;
282
-
283
- if (auth) this._auth = auth;
284
- this._id = id;
285
- this._network = network || 'mainnet';
286
- this._addressesMap = new Map();
329
+ this._cache = cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS);
287
330
  this._requestClient = axios.create({
288
331
  baseURL: API_BASE_URL,
289
332
  headers: {
@@ -292,6 +335,10 @@ export class ScallopAddress {
292
335
  },
293
336
  timeout: 30000,
294
337
  });
338
+ if (auth) this._auth = auth;
339
+ this._id = id;
340
+ this._network = network || 'mainnet';
341
+ this._addressesMap = new Map();
295
342
  }
296
343
 
297
344
  /**
@@ -437,7 +484,7 @@ export class ScallopAddress {
437
484
  this._addressesMap.clear();
438
485
  this.setAddresses(targetAddresses, targetNetwork);
439
486
  const response = await this._requestClient.post(
440
- `${API_BASE_URL}/addresses`,
487
+ `/addresses`,
441
488
  JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
442
489
  {
443
490
  headers: {
@@ -475,14 +522,16 @@ export class ScallopAddress {
475
522
  public async read(id?: string) {
476
523
  const addressesId = id || this._id || undefined;
477
524
  if (addressesId !== undefined) {
478
- const response = await this._requestClient.get(
479
- `${API_BASE_URL}/addresses/${addressesId}`,
480
- {
481
- headers: {
482
- 'Content-Type': 'application/json',
483
- },
484
- }
485
- );
525
+ const response = await this._cache.queryClient.fetchQuery({
526
+ queryKey: ['api-getAddresses', addressesId],
527
+ queryFn: async () => {
528
+ return await this._requestClient.get(`/addresses/${addressesId}`, {
529
+ headers: {
530
+ 'Content-Type': 'application/json',
531
+ },
532
+ });
533
+ },
534
+ });
486
535
 
487
536
  if (response.status === 200) {
488
537
  for (const [network, addresses] of Object.entries<AddressesInterface>(
@@ -548,7 +597,7 @@ export class ScallopAddress {
548
597
  }
549
598
  this.setAddresses(targetAddresses, targetNetwork);
550
599
  const response = await this._requestClient.put(
551
- `${API_BASE_URL}/addresses/${targetId}`,
600
+ `/addresses/${targetId}`,
552
601
  JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
553
602
  {
554
603
  headers: {
@@ -592,7 +641,7 @@ export class ScallopAddress {
592
641
  throw Error('Require specific addresses id to be deleted.');
593
642
  if (apiKey !== undefined) {
594
643
  const response = await this._requestClient.delete(
595
- `${API_BASE_URL}/addresses/${targetId}`,
644
+ `/addresses/${targetId}`,
596
645
  {
597
646
  headers: {
598
647
  'Content-Type': 'application/json',
@@ -15,6 +15,8 @@ import type {
15
15
  SupportMarketCoins,
16
16
  SupportAssetCoins,
17
17
  } from '../types';
18
+ import { ScallopCache } from './scallopCache';
19
+ import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
18
20
 
19
21
  /**
20
22
  * @description
@@ -36,6 +38,7 @@ export class ScallopBuilder {
36
38
  public query: ScallopQuery;
37
39
  public utils: ScallopUtils;
38
40
  public walletAddress: string;
41
+ public cache: ScallopCache;
39
42
 
40
43
  public constructor(
41
44
  params: ScallopBuilderParams,
@@ -43,17 +46,23 @@ export class ScallopBuilder {
43
46
  ) {
44
47
  this.params = params;
45
48
  this.suiKit = instance?.suiKit ?? new SuiKit(params);
49
+ this.cache =
50
+ instance?.cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS, this.suiKit);
46
51
  this.address =
47
52
  instance?.address ??
48
- new ScallopAddress({
49
- id: params?.addressesId || ADDRESSES_ID,
50
- network: params?.networkType,
51
- });
53
+ new ScallopAddress(
54
+ {
55
+ id: params?.addressesId || ADDRESSES_ID,
56
+ network: params?.networkType,
57
+ },
58
+ this.cache
59
+ );
52
60
  this.query =
53
61
  instance?.query ??
54
62
  new ScallopQuery(params, {
55
63
  suiKit: this.suiKit,
56
64
  address: this.address,
65
+ cache: this.cache,
57
66
  });
58
67
  this.utils =
59
68
  instance?.utils ??
@@ -61,6 +70,7 @@ export class ScallopBuilder {
61
70
  suiKit: this.suiKit,
62
71
  address: this.address,
63
72
  query: this.query,
73
+ cache: this.cache,
64
74
  });
65
75
  this.walletAddress = normalizeSuiAddress(
66
76
  params?.walletAddress || this.suiKit.currentAddress()
@@ -0,0 +1,285 @@
1
+ import { QueryClient, QueryClientConfig } from '@tanstack/query-core';
2
+ import { SuiTxArg, SuiTxBlock, normalizeStructTag } from '@scallop-io/sui-kit';
3
+ import { SuiKit } from '@scallop-io/sui-kit';
4
+ import type {
5
+ SuiObjectResponse,
6
+ SuiObjectDataOptions,
7
+ SuiObjectData,
8
+ PaginatedObjectsResponse,
9
+ GetOwnedObjectsParams,
10
+ DevInspectResults,
11
+ GetDynamicFieldsParams,
12
+ DynamicFieldPage,
13
+ GetDynamicFieldObjectParams,
14
+ GetBalanceParams,
15
+ } from '@mysten/sui.js/client';
16
+ import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
17
+
18
+ type QueryInspectTxnParams = {
19
+ queryTarget: string;
20
+ args: SuiTxArg[];
21
+ typeArgs?: any[];
22
+ };
23
+
24
+ /**
25
+ * @description
26
+ * It provides caching for moveCall, RPC Request, and API Request.
27
+ *
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const scallopCache = new scallopCache(<parameters>);
32
+ * scallopCache.<indexer functions>();
33
+ * await scallopCache.<indexer async functions>();
34
+ * ```
35
+ */
36
+
37
+ export class ScallopCache {
38
+ public readonly queryClient: QueryClient;
39
+ public readonly _suiKit?: SuiKit;
40
+
41
+ public constructor(cacheOptions?: QueryClientConfig, suiKit?: SuiKit) {
42
+ this.queryClient = new QueryClient(cacheOptions ?? DEFAULT_CACHE_OPTIONS);
43
+ this._suiKit = suiKit;
44
+ }
45
+
46
+ private get suiKit(): SuiKit {
47
+ if (!this._suiKit) {
48
+ throw new Error('SuiKit instance is not initialized');
49
+ }
50
+ return this._suiKit;
51
+ }
52
+
53
+ /**
54
+ * @description Invalidate cache based on the refetchType parameter
55
+ * @param refetchType Determines the type of queries to be refetched. Defaults to `active`.
56
+ *
57
+ * - `active`: Only queries that match the refetch predicate and are actively being rendered via useQuery and related functions will be refetched in the background.
58
+ * - `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.
59
+ * - `all`: All queries that match the refetch predicate will be refetched in the background.
60
+ * - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
61
+ */
62
+ public invalidateAndRefetchAllCache(
63
+ refetchType: 'all' | 'active' | 'inactive' | 'none'
64
+ ) {
65
+ return this.queryClient.invalidateQueries({
66
+ refetchType,
67
+ });
68
+ }
69
+
70
+ /**
71
+ * @description Cache protocol config call for 60 seconds.
72
+ * @returns Promise<ProtocolConfig>
73
+ */
74
+ public async getProtocolConfig() {
75
+ return await this.queryClient.fetchQuery({
76
+ queryKey: ['getProtocolConfig'],
77
+ queryFn: async () => {
78
+ return await this.suiKit.client().getProtocolConfig();
79
+ },
80
+ staleTime: 30000,
81
+ });
82
+ }
83
+
84
+ /**
85
+ * @description Provides cache for inspectTxn of the SuiKit.
86
+ * @param QueryInspectTxnParams
87
+ * @param txBlock
88
+ * @returns Promise<DevInspectResults>
89
+ */
90
+ public async queryInspectTxn({
91
+ queryTarget,
92
+ args,
93
+ typeArgs,
94
+ }: QueryInspectTxnParams): Promise<DevInspectResults> {
95
+ const txBlock = new SuiTxBlock();
96
+
97
+ // resolve all the object args to prevent duplicate getNormalizedMoveFunction calls
98
+ const resolvedArgs = await Promise.all(
99
+ args.map(async (arg) => {
100
+ if (typeof arg === 'string') {
101
+ return (await this.queryGetObject(arg, { showContent: true })).data;
102
+ }
103
+ return arg;
104
+ })
105
+ );
106
+ txBlock.moveCall(queryTarget, resolvedArgs, typeArgs);
107
+
108
+ // build the txBlock to prevent duplicate getProtocolConfig calls
109
+ const txBytes = await txBlock.txBlock.build({
110
+ client: this.suiKit.client(),
111
+ onlyTransactionKind: true,
112
+ protocolConfig: await this.getProtocolConfig(),
113
+ });
114
+
115
+ const query = await this.queryClient.fetchQuery({
116
+ queryKey: typeArgs
117
+ ? ['inspectTxn', queryTarget, JSON.stringify(args)]
118
+ : [
119
+ 'inspectTxn',
120
+ queryTarget,
121
+ JSON.stringify(args),
122
+ JSON.stringify(typeArgs),
123
+ ],
124
+ queryFn: async () => {
125
+ return await this.suiKit.inspectTxn(txBytes);
126
+ },
127
+ staleTime: 8000, // make stale time longer for inspectTxn results
128
+ });
129
+ return query;
130
+ }
131
+
132
+ /**
133
+ * @description Provides cache for getObject of the SuiKit.
134
+ * @param objectId
135
+ * @param QueryObjectParams
136
+ * @returns Promise<SuiObjectResponse>
137
+ */
138
+ public async queryGetObject(
139
+ objectId: string,
140
+ options?: SuiObjectDataOptions
141
+ ): Promise<SuiObjectResponse> {
142
+ const queryKey = ['getObject', objectId, this.suiKit.currentAddress()];
143
+ if (options) {
144
+ queryKey.push(JSON.stringify(options));
145
+ }
146
+ return this.queryClient.fetchQuery({
147
+ queryKey,
148
+ queryFn: async () => {
149
+ return await this.suiKit.client().getObject({
150
+ id: objectId,
151
+ options,
152
+ });
153
+ },
154
+ });
155
+ }
156
+
157
+ /**
158
+ * @description Provides cache for getObjects of the SuiKit.
159
+ * @param objectIds
160
+ * @returns Promise<SuiObjectData[]>
161
+ */
162
+ public async queryGetObjects(
163
+ objectIds: string[],
164
+ options?: SuiObjectDataOptions
165
+ ): Promise<SuiObjectData[]> {
166
+ const queryKey = [
167
+ 'getObjects',
168
+ JSON.stringify(objectIds),
169
+ this.suiKit.currentAddress(),
170
+ ];
171
+ return this.queryClient.fetchQuery({
172
+ queryKey,
173
+ queryFn: async () => {
174
+ return await this.suiKit.getObjects(objectIds, options);
175
+ },
176
+ });
177
+ }
178
+
179
+ /**
180
+ * @description Provides cache for getOwnedObjects of the SuiKit.
181
+ * @param input
182
+ * @returns Promise<PaginatedObjectsResponse>
183
+ */
184
+ public async queryGetOwnedObjects(
185
+ input: GetOwnedObjectsParams
186
+ ): Promise<PaginatedObjectsResponse> {
187
+ const queryKey = ['getOwnedObjects', input.owner];
188
+ if (input.cursor) {
189
+ queryKey.push(JSON.stringify(input.cursor));
190
+ }
191
+ if (input.options) {
192
+ queryKey.push(JSON.stringify(input.options));
193
+ }
194
+ if (input.filter) {
195
+ queryKey.push(JSON.stringify(input.filter));
196
+ }
197
+ if (input.limit) {
198
+ queryKey.push(JSON.stringify(input.limit));
199
+ }
200
+
201
+ return this.queryClient.fetchQuery({
202
+ queryKey,
203
+ queryFn: async () => {
204
+ return await this.suiKit.client().getOwnedObjects(input);
205
+ },
206
+ });
207
+ }
208
+
209
+ public async queryGetDynamicFields(
210
+ input: GetDynamicFieldsParams
211
+ ): Promise<DynamicFieldPage> {
212
+ const queryKey = ['getDynamicFields', input.parentId];
213
+ if (input.cursor) {
214
+ queryKey.push(JSON.stringify(input.cursor));
215
+ }
216
+ if (input.cursor) {
217
+ queryKey.push(JSON.stringify(input.cursor));
218
+ }
219
+ if (input.limit) {
220
+ queryKey.push(JSON.stringify(input.limit));
221
+ }
222
+
223
+ return this.queryClient.fetchQuery({
224
+ queryKey,
225
+ queryFn: async () => {
226
+ return await this.suiKit.client().getDynamicFields(input);
227
+ },
228
+ });
229
+ }
230
+
231
+ public async queryGetDynamicFieldObject(
232
+ input: GetDynamicFieldObjectParams
233
+ ): Promise<SuiObjectResponse> {
234
+ const queryKey = [
235
+ 'getDynamicFieldObject',
236
+ input.parentId,
237
+ input.name.value,
238
+ ];
239
+ return this.queryClient.fetchQuery({
240
+ queryKey,
241
+ queryFn: async () => {
242
+ return await this.suiKit.client().getDynamicFieldObject(input);
243
+ },
244
+ });
245
+ }
246
+
247
+ public async queryGetAllCoinBalances(
248
+ owner: string
249
+ ): Promise<{ [k: string]: string }> {
250
+ const queryKey = ['getAllCoinBalances', owner];
251
+ return this.queryClient.fetchQuery({
252
+ queryKey,
253
+ queryFn: async () => {
254
+ const allBalances = await this.suiKit
255
+ .client()
256
+ .getAllBalances({ owner });
257
+ return allBalances.reduce(
258
+ (acc, coinBalance) => {
259
+ if (coinBalance.totalBalance !== '0') {
260
+ acc[normalizeStructTag(coinBalance.coinType)] =
261
+ coinBalance.totalBalance;
262
+ }
263
+ return acc;
264
+ },
265
+ {} as { [k: string]: string }
266
+ );
267
+ },
268
+ });
269
+ }
270
+
271
+ public async queryGetCoinBalance(input: GetBalanceParams): Promise<string> {
272
+ const queryKey = ['getCoinBalance', input.owner, input.coinType];
273
+ return this.queryClient.fetchQuery({
274
+ queryKey,
275
+ queryFn: async () => {
276
+ if (!input.coinType) return '0';
277
+ return (
278
+ (await this.queryGetAllCoinBalances(input.owner))[
279
+ normalizeStructTag(input.coinType)
280
+ ] ?? '0'
281
+ );
282
+ },
283
+ });
284
+ }
285
+ }
@@ -24,6 +24,8 @@ import type {
24
24
  SupportBorrowIncentiveCoins,
25
25
  ScallopTxBlock,
26
26
  } from '../types';
27
+ import { ScallopCache } from './scallopCache';
28
+ import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
27
29
 
28
30
  /**
29
31
  * @description
@@ -45,6 +47,7 @@ export class ScallopClient {
45
47
  public builder: ScallopBuilder;
46
48
  public query: ScallopQuery;
47
49
  public utils: ScallopUtils;
50
+ public cache: ScallopCache;
48
51
  public walletAddress: string;
49
52
 
50
53
  public constructor(
@@ -53,17 +56,23 @@ export class ScallopClient {
53
56
  ) {
54
57
  this.params = params;
55
58
  this.suiKit = instance?.suiKit ?? new SuiKit(params);
59
+ this.cache =
60
+ instance?.cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS, this.suiKit);
56
61
  this.address =
57
62
  instance?.address ??
58
- new ScallopAddress({
59
- id: params?.addressesId || ADDRESSES_ID,
60
- network: params?.networkType,
61
- });
63
+ new ScallopAddress(
64
+ {
65
+ id: params?.addressesId || ADDRESSES_ID,
66
+ network: params?.networkType,
67
+ },
68
+ this.cache
69
+ );
62
70
  this.query =
63
71
  instance?.query ??
64
72
  new ScallopQuery(params, {
65
73
  suiKit: this.suiKit,
66
74
  address: this.address,
75
+ cache: this.cache,
67
76
  });
68
77
  this.utils =
69
78
  instance?.utils ??
@@ -71,6 +80,7 @@ export class ScallopClient {
71
80
  suiKit: this.suiKit,
72
81
  address: this.address,
73
82
  query: this.query,
83
+ cache: this.cache,
74
84
  });
75
85
  this.builder =
76
86
  instance?.builder ??
@@ -79,6 +89,7 @@ export class ScallopClient {
79
89
  address: this.address,
80
90
  query: this.query,
81
91
  utils: this.utils,
92
+ cache: this.cache,
82
93
  });
83
94
  this.walletAddress = normalizeSuiAddress(
84
95
  params?.walletAddress || this.suiKit.currentAddress()