@scallop-io/sui-scallop-sdk 1.3.1-alpha.2 → 1.3.2-alpha.1

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.
@@ -37,7 +37,7 @@ export declare class ScallopCache {
37
37
  * - `all`: All queries that match the refetch predicate will be refetched in the background.
38
38
  * - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
39
39
  */
40
- invalidateAndRefetchAllCache(refetchType: 'all' | 'active' | 'inactive' | 'none'): Promise<void>;
40
+ invalidateAllCache(): Promise<void>[];
41
41
  /**
42
42
  * @description Provides cache for inspectTxn of the SuiKit.
43
43
  * @param QueryInspectTxnParams
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "1.3.1-alpha.2",
3
+ "version": "1.3.2-alpha.1",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -1,12 +1,10 @@
1
- import { QueryClientConfig } from '@tanstack/query-core';
2
-
3
1
  /**
4
2
  * Default cache options for the QueryClient.
5
3
  * @type {QueryClientConfig}
6
4
  * @description Default cache options for the QueryClient
7
5
  * We set the default to 5s to prevent duplicate requests from being requested (e.g. query MarketObject, etc.)
8
6
  */
9
- export const DEFAULT_CACHE_OPTIONS: QueryClientConfig = {
7
+ export const DEFAULT_CACHE_OPTIONS = {
10
8
  defaultOptions: {
11
9
  queries: {
12
10
  staleTime: 5000,
@@ -52,31 +52,31 @@ export const queryKeys = {
52
52
  objectIds: JSON.stringify(objectIds ?? []),
53
53
  },
54
54
  ],
55
- getOwnedObjects: (input: Partial<GetOwnedObjectsParams>) => [
55
+ getOwnedObjects: (input?: Partial<GetOwnedObjectsParams>) => [
56
56
  'rpc',
57
57
  'getOwnedObjects',
58
58
  {
59
- walletAddress: input.owner,
60
- cursor: input.cursor ?? undefined,
61
- options: input.options ?? undefined,
62
- filter: JSON.stringify(input.filter ?? undefined),
63
- limit: input.limit ?? undefined,
59
+ walletAddress: input?.owner,
60
+ cursor: input?.cursor ?? undefined,
61
+ options: input?.options ?? undefined,
62
+ filter: JSON.stringify(input?.filter ?? undefined),
63
+ limit: input?.limit ?? undefined,
64
64
  },
65
65
  ],
66
- getDynamicFields: (input: Partial<GetDynamicFieldsParams>) => [
66
+ getDynamicFields: (input?: Partial<GetDynamicFieldsParams>) => [
67
67
  'rpc',
68
68
  'getDynamicFields',
69
69
  {
70
- parentId: input.parentId,
71
- cursor: input.cursor ?? undefined,
72
- limit: input.limit ?? undefined,
70
+ parentId: input?.parentId,
71
+ cursor: input?.cursor ?? undefined,
72
+ limit: input?.limit ?? undefined,
73
73
  },
74
74
  ],
75
- getDynamicFieldObject: (input: Partial<GetDynamicFieldObjectParams>) => [
75
+ getDynamicFieldObject: (input?: Partial<GetDynamicFieldObjectParams>) => [
76
76
  'rpc',
77
77
  'getDynamicFieldObject',
78
78
  {
79
- parentId: input.parentId,
79
+ parentId: input?.parentId,
80
80
  name: {
81
81
  type: input?.name?.type,
82
82
  value: input?.name?.value,
@@ -31,8 +31,6 @@ type QueryInspectTxnParams = {
31
31
  typeArgs?: any[];
32
32
  };
33
33
 
34
- const DEFAULT_GC_TIME = 5 * 1000; // 5 seconds
35
-
36
34
  /**
37
35
  * @description
38
36
  * It provides caching for moveCall, RPC Request, and API Request.
@@ -99,12 +97,12 @@ export class ScallopCache {
99
97
  * - `all`: All queries that match the refetch predicate will be refetched in the background.
100
98
  * - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
101
99
  */
102
- public invalidateAndRefetchAllCache(
103
- refetchType: 'all' | 'active' | 'inactive' | 'none'
104
- ) {
105
- return this.queryClient.invalidateQueries({
106
- refetchType,
107
- });
100
+ public invalidateAllCache() {
101
+ return Object.values(queryKeys.rpc).map((t) =>
102
+ this.queryClient.invalidateQueries({
103
+ queryKey: t(),
104
+ })
105
+ );
108
106
  }
109
107
 
110
108
  /**
@@ -129,7 +127,7 @@ export class ScallopCache {
129
127
  this.suiKit.inspectTxn(txBlock)
130
128
  );
131
129
  },
132
- gcTime: DEFAULT_GC_TIME,
130
+ ...DEFAULT_CACHE_OPTIONS.defaultOptions.queries,
133
131
  });
134
132
  return query;
135
133
  }
@@ -154,7 +152,7 @@ export class ScallopCache {
154
152
  })
155
153
  );
156
154
  },
157
- gcTime: DEFAULT_GC_TIME,
155
+ ...DEFAULT_CACHE_OPTIONS.defaultOptions.queries,
158
156
  });
159
157
  }
160
158
 
@@ -183,7 +181,7 @@ export class ScallopCache {
183
181
  this.suiKit.getObjects(objectIds, options)
184
182
  );
185
183
  },
186
- gcTime: DEFAULT_GC_TIME,
184
+ ...DEFAULT_CACHE_OPTIONS.defaultOptions.queries,
187
185
  });
188
186
  }
189
187
 
@@ -200,7 +198,7 @@ export class ScallopCache {
200
198
  this.client.getOwnedObjects(input)
201
199
  );
202
200
  },
203
- gcTime: DEFAULT_GC_TIME,
201
+ ...DEFAULT_CACHE_OPTIONS.defaultOptions.queries,
204
202
  });
205
203
  }
206
204
 
@@ -214,7 +212,7 @@ export class ScallopCache {
214
212
  this.client.getDynamicFields(input)
215
213
  );
216
214
  },
217
- gcTime: DEFAULT_GC_TIME,
215
+ ...DEFAULT_CACHE_OPTIONS.defaultOptions.queries,
218
216
  });
219
217
  }
220
218
 
@@ -228,7 +226,7 @@ export class ScallopCache {
228
226
  this.client.getDynamicFieldObject(input)
229
227
  );
230
228
  },
231
- gcTime: DEFAULT_GC_TIME,
229
+ ...DEFAULT_CACHE_OPTIONS.defaultOptions.queries,
232
230
  });
233
231
  }
234
232
 
@@ -29,42 +29,47 @@ const ISOLATED_ASSET_KEY =
29
29
  export const getIsolatedAssets = async (
30
30
  address: ScallopAddress
31
31
  ): Promise<string[]> => {
32
- const marketObject = address.get('core.market');
33
- const isolatedAssets: string[] = [];
34
- if (!marketObject) return isolatedAssets;
32
+ try {
33
+ const marketObject = address.get('core.market');
34
+ const isolatedAssets: string[] = [];
35
+ if (!marketObject) return isolatedAssets;
35
36
 
36
- let hasNextPage = false;
37
- let nextCursor: string | null | undefined = null;
37
+ let hasNextPage = false;
38
+ let nextCursor: string | null | undefined = null;
38
39
 
39
- const isIsolatedDynamicField = (
40
- dynamicField: DynamicFieldInfo
41
- ): dynamicField is DynamicFieldInfo & {
42
- name: DynamicFieldName & { value: { type: { name: string } } };
43
- } => {
44
- return dynamicField.name.type === ISOLATED_ASSET_KEY;
45
- };
40
+ const isIsolatedDynamicField = (
41
+ dynamicField: DynamicFieldInfo
42
+ ): dynamicField is DynamicFieldInfo & {
43
+ name: DynamicFieldName & { value: { type: { name: string } } };
44
+ } => {
45
+ return dynamicField.name.type === ISOLATED_ASSET_KEY;
46
+ };
46
47
 
47
- do {
48
- const response = await address.cache.queryGetDynamicFields({
49
- parentId: marketObject,
50
- cursor: nextCursor,
51
- limit: 10,
52
- });
53
- if (!response) break;
48
+ do {
49
+ const response = await address.cache.queryGetDynamicFields({
50
+ parentId: marketObject,
51
+ cursor: nextCursor,
52
+ limit: 10,
53
+ });
54
+ if (!response) break;
54
55
 
55
- const isolatedAssetCoinTypes = response.data
56
- .filter(isIsolatedDynamicField)
57
- .map(({ name }) => `0x${name.value.type.name}`);
58
- isolatedAssets.push(...isolatedAssetCoinTypes);
56
+ const isolatedAssetCoinTypes = response.data
57
+ .filter(isIsolatedDynamicField)
58
+ .map(({ name }) => `0x${name.value.type.name}`);
59
+ isolatedAssets.push(...isolatedAssetCoinTypes);
59
60
 
60
- if (response && response.hasNextPage && response.nextCursor) {
61
- hasNextPage = true;
62
- nextCursor = response.nextCursor;
63
- } else {
64
- hasNextPage = false;
65
- }
66
- } while (hasNextPage);
67
- return isolatedAssets;
61
+ if (response && response.hasNextPage && response.nextCursor) {
62
+ hasNextPage = true;
63
+ nextCursor = response.nextCursor;
64
+ } else {
65
+ hasNextPage = false;
66
+ }
67
+ } while (hasNextPage);
68
+ return isolatedAssets;
69
+ } catch (e) {
70
+ console.error(e);
71
+ return [];
72
+ }
68
73
  };
69
74
 
70
75
  /**
@@ -76,30 +81,35 @@ export const isIsolatedAsset = async (
76
81
  utils: ScallopUtils,
77
82
  coinName: SupportPoolCoins
78
83
  ): Promise<boolean> => {
79
- const marketObject = utils.address.get('core.market');
84
+ try {
85
+ const marketObject = utils.address.get('core.market');
80
86
 
81
- // check if the coin type is in the list
82
- const cachedData = utils.address.cache.queryClient.getQueryData<string[]>([
83
- 'getDynamicFields',
84
- marketObject,
85
- ]);
86
- if (cachedData) {
87
- const coinType = utils.parseCoinType(coinName);
88
- return cachedData.includes(coinType);
89
- }
87
+ // check if the coin type is in the list
88
+ const cachedData = utils.address.cache.queryClient.getQueryData<string[]>([
89
+ 'getDynamicFields',
90
+ marketObject,
91
+ ]);
92
+ if (cachedData) {
93
+ const coinType = utils.parseCoinType(coinName);
94
+ return cachedData.includes(coinType);
95
+ }
90
96
 
91
- // fetch dynamic field object
92
- const coinType = utils.parseCoinType(coinName).slice(2);
97
+ // fetch dynamic field object
98
+ const coinType = utils.parseCoinType(coinName).slice(2);
93
99
 
94
- const object = await utils.cache.queryGetDynamicFieldObject({
95
- parentId: marketObject,
96
- name: {
97
- type: ISOLATED_ASSET_KEY,
98
- value: coinType,
99
- },
100
- });
100
+ const object = await utils.cache.queryGetDynamicFieldObject({
101
+ parentId: marketObject,
102
+ name: {
103
+ type: ISOLATED_ASSET_KEY,
104
+ value: coinType,
105
+ },
106
+ });
101
107
 
102
- const parsedData = isolatedAssetZod.safeParse(object?.data?.content);
103
- if (!parsedData.success) return false;
104
- return parsedData.data.fields.value;
108
+ const parsedData = isolatedAssetZod.safeParse(object?.data?.content);
109
+ if (!parsedData.success) return false;
110
+ return parsedData.data.fields.value;
111
+ } catch (e) {
112
+ console.error(e);
113
+ return false;
114
+ }
105
115
  };