@scallop-io/sui-scallop-sdk 1.3.1 → 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.
package/dist/index.mjs CHANGED
@@ -320,27 +320,27 @@ var queryKeys = {
320
320
  "rpc",
321
321
  "getOwnedObjects",
322
322
  {
323
- walletAddress: input.owner,
324
- cursor: input.cursor ?? void 0,
325
- options: input.options ?? void 0,
326
- filter: JSON.stringify(input.filter ?? void 0),
327
- limit: input.limit ?? void 0
323
+ walletAddress: input?.owner,
324
+ cursor: input?.cursor ?? void 0,
325
+ options: input?.options ?? void 0,
326
+ filter: JSON.stringify(input?.filter ?? void 0),
327
+ limit: input?.limit ?? void 0
328
328
  }
329
329
  ],
330
330
  getDynamicFields: (input) => [
331
331
  "rpc",
332
332
  "getDynamicFields",
333
333
  {
334
- parentId: input.parentId,
335
- cursor: input.cursor ?? void 0,
336
- limit: input.limit ?? void 0
334
+ parentId: input?.parentId,
335
+ cursor: input?.cursor ?? void 0,
336
+ limit: input?.limit ?? void 0
337
337
  }
338
338
  ],
339
339
  getDynamicFieldObject: (input) => [
340
340
  "rpc",
341
341
  "getDynamicFieldObject",
342
342
  {
343
- parentId: input.parentId,
343
+ parentId: input?.parentId,
344
344
  name: {
345
345
  type: input?.name?.type,
346
346
  value: input?.name?.value
@@ -1043,7 +1043,6 @@ function withIndexerFallback(method) {
1043
1043
  }
1044
1044
 
1045
1045
  // src/models/scallopCache.ts
1046
- var DEFAULT_GC_TIME = 5 * 1e3;
1047
1046
  var ScallopCache = class {
1048
1047
  constructor(suiKit, walletAddress, cacheOptions, tokenBucket, queryClient) {
1049
1048
  this.queryClient = queryClient ?? new QueryClient(cacheOptions ?? DEFAULT_CACHE_OPTIONS);
@@ -1069,10 +1068,12 @@ var ScallopCache = class {
1069
1068
  * - `all`: All queries that match the refetch predicate will be refetched in the background.
1070
1069
  * - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
1071
1070
  */
1072
- invalidateAndRefetchAllCache(refetchType) {
1073
- return this.queryClient.invalidateQueries({
1074
- refetchType
1075
- });
1071
+ invalidateAllCache() {
1072
+ return Object.values(queryKeys.rpc).map(
1073
+ (t) => this.queryClient.invalidateQueries({
1074
+ queryKey: t()
1075
+ })
1076
+ );
1076
1077
  }
1077
1078
  /**
1078
1079
  * @description Provides cache for inspectTxn of the SuiKit.
@@ -1095,7 +1096,7 @@ var ScallopCache = class {
1095
1096
  () => this.suiKit.inspectTxn(txBlock)
1096
1097
  );
1097
1098
  },
1098
- gcTime: DEFAULT_GC_TIME
1099
+ ...DEFAULT_CACHE_OPTIONS.defaultOptions.queries
1099
1100
  });
1100
1101
  return query;
1101
1102
  }
@@ -1117,7 +1118,7 @@ var ScallopCache = class {
1117
1118
  })
1118
1119
  );
1119
1120
  },
1120
- gcTime: DEFAULT_GC_TIME
1121
+ ...DEFAULT_CACHE_OPTIONS.defaultOptions.queries
1121
1122
  });
1122
1123
  }
1123
1124
  /**
@@ -1142,7 +1143,7 @@ var ScallopCache = class {
1142
1143
  () => this.suiKit.getObjects(objectIds, options)
1143
1144
  );
1144
1145
  },
1145
- gcTime: DEFAULT_GC_TIME
1146
+ ...DEFAULT_CACHE_OPTIONS.defaultOptions.queries
1146
1147
  });
1147
1148
  }
1148
1149
  /**
@@ -1159,7 +1160,7 @@ var ScallopCache = class {
1159
1160
  () => this.client.getOwnedObjects(input)
1160
1161
  );
1161
1162
  },
1162
- gcTime: DEFAULT_GC_TIME
1163
+ ...DEFAULT_CACHE_OPTIONS.defaultOptions.queries
1163
1164
  });
1164
1165
  }
1165
1166
  async queryGetDynamicFields(input) {
@@ -1171,7 +1172,7 @@ var ScallopCache = class {
1171
1172
  () => this.client.getDynamicFields(input)
1172
1173
  );
1173
1174
  },
1174
- gcTime: DEFAULT_GC_TIME
1175
+ ...DEFAULT_CACHE_OPTIONS.defaultOptions.queries
1175
1176
  });
1176
1177
  }
1177
1178
  async queryGetDynamicFieldObject(input) {
@@ -1183,7 +1184,7 @@ var ScallopCache = class {
1183
1184
  () => this.client.getDynamicFieldObject(input)
1184
1185
  );
1185
1186
  },
1186
- gcTime: DEFAULT_GC_TIME
1187
+ ...DEFAULT_CACHE_OPTIONS.defaultOptions.queries
1187
1188
  });
1188
1189
  }
1189
1190
  async queryGetAllCoinBalances(owner) {
@@ -2337,56 +2338,66 @@ var isolatedAssetZod = zod2.object({
2337
2338
  });
2338
2339
  var ISOLATED_ASSET_KEY = "0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::IsolatedAssetKey";
2339
2340
  var getIsolatedAssets = async (address) => {
2340
- const marketObject = address.get("core.market");
2341
- const isolatedAssets = [];
2342
- if (!marketObject)
2341
+ try {
2342
+ const marketObject = address.get("core.market");
2343
+ const isolatedAssets = [];
2344
+ if (!marketObject)
2345
+ return isolatedAssets;
2346
+ let hasNextPage = false;
2347
+ let nextCursor = null;
2348
+ const isIsolatedDynamicField = (dynamicField) => {
2349
+ return dynamicField.name.type === ISOLATED_ASSET_KEY;
2350
+ };
2351
+ do {
2352
+ const response = await address.cache.queryGetDynamicFields({
2353
+ parentId: marketObject,
2354
+ cursor: nextCursor,
2355
+ limit: 10
2356
+ });
2357
+ if (!response)
2358
+ break;
2359
+ const isolatedAssetCoinTypes = response.data.filter(isIsolatedDynamicField).map(({ name }) => `0x${name.value.type.name}`);
2360
+ isolatedAssets.push(...isolatedAssetCoinTypes);
2361
+ if (response && response.hasNextPage && response.nextCursor) {
2362
+ hasNextPage = true;
2363
+ nextCursor = response.nextCursor;
2364
+ } else {
2365
+ hasNextPage = false;
2366
+ }
2367
+ } while (hasNextPage);
2343
2368
  return isolatedAssets;
2344
- let hasNextPage = false;
2345
- let nextCursor = null;
2346
- const isIsolatedDynamicField = (dynamicField) => {
2347
- return dynamicField.name.type === ISOLATED_ASSET_KEY;
2348
- };
2349
- do {
2350
- const response = await address.cache.queryGetDynamicFields({
2351
- parentId: marketObject,
2352
- cursor: nextCursor,
2353
- limit: 10
2354
- });
2355
- if (!response)
2356
- break;
2357
- const isolatedAssetCoinTypes = response.data.filter(isIsolatedDynamicField).map(({ name }) => `0x${name.value.type.name}`);
2358
- isolatedAssets.push(...isolatedAssetCoinTypes);
2359
- if (response && response.hasNextPage && response.nextCursor) {
2360
- hasNextPage = true;
2361
- nextCursor = response.nextCursor;
2362
- } else {
2363
- hasNextPage = false;
2364
- }
2365
- } while (hasNextPage);
2366
- return isolatedAssets;
2369
+ } catch (e) {
2370
+ console.error(e);
2371
+ return [];
2372
+ }
2367
2373
  };
2368
2374
  var isIsolatedAsset = async (utils, coinName) => {
2369
- const marketObject = utils.address.get("core.market");
2370
- const cachedData = utils.address.cache.queryClient.getQueryData([
2371
- "getDynamicFields",
2372
- marketObject
2373
- ]);
2374
- if (cachedData) {
2375
- const coinType2 = utils.parseCoinType(coinName);
2376
- return cachedData.includes(coinType2);
2377
- }
2378
- const coinType = utils.parseCoinType(coinName).slice(2);
2379
- const object = await utils.cache.queryGetDynamicFieldObject({
2380
- parentId: marketObject,
2381
- name: {
2382
- type: ISOLATED_ASSET_KEY,
2383
- value: coinType
2384
- }
2385
- });
2386
- const parsedData = isolatedAssetZod.safeParse(object?.data?.content);
2387
- if (!parsedData.success)
2375
+ try {
2376
+ const marketObject = utils.address.get("core.market");
2377
+ const cachedData = utils.address.cache.queryClient.getQueryData([
2378
+ "getDynamicFields",
2379
+ marketObject
2380
+ ]);
2381
+ if (cachedData) {
2382
+ const coinType2 = utils.parseCoinType(coinName);
2383
+ return cachedData.includes(coinType2);
2384
+ }
2385
+ const coinType = utils.parseCoinType(coinName).slice(2);
2386
+ const object = await utils.cache.queryGetDynamicFieldObject({
2387
+ parentId: marketObject,
2388
+ name: {
2389
+ type: ISOLATED_ASSET_KEY,
2390
+ value: coinType
2391
+ }
2392
+ });
2393
+ const parsedData = isolatedAssetZod.safeParse(object?.data?.content);
2394
+ if (!parsedData.success)
2395
+ return false;
2396
+ return parsedData.data.fields.value;
2397
+ } catch (e) {
2398
+ console.error(e);
2388
2399
  return false;
2389
- return parsedData.data.fields.value;
2400
+ }
2390
2401
  };
2391
2402
 
2392
2403
  // src/queries/coreQuery.ts