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

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,13 @@ 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
+ async invalidateAllCache() {
1072
+ return Object.values(queryKeys.rpc).map(
1073
+ (t) => this.queryClient.invalidateQueries({
1074
+ queryKey: t(),
1075
+ type: "all"
1076
+ })
1077
+ );
1076
1078
  }
1077
1079
  /**
1078
1080
  * @description Provides cache for inspectTxn of the SuiKit.
@@ -1094,8 +1096,7 @@ var ScallopCache = class {
1094
1096
  this.tokenBucket,
1095
1097
  () => this.suiKit.inspectTxn(txBlock)
1096
1098
  );
1097
- },
1098
- gcTime: DEFAULT_GC_TIME
1099
+ }
1099
1100
  });
1100
1101
  return query;
1101
1102
  }
@@ -1116,8 +1117,7 @@ var ScallopCache = class {
1116
1117
  options
1117
1118
  })
1118
1119
  );
1119
- },
1120
- gcTime: DEFAULT_GC_TIME
1120
+ }
1121
1121
  });
1122
1122
  }
1123
1123
  /**
@@ -1141,8 +1141,7 @@ var ScallopCache = class {
1141
1141
  this.tokenBucket,
1142
1142
  () => this.suiKit.getObjects(objectIds, options)
1143
1143
  );
1144
- },
1145
- gcTime: DEFAULT_GC_TIME
1144
+ }
1146
1145
  });
1147
1146
  }
1148
1147
  /**
@@ -1158,8 +1157,7 @@ var ScallopCache = class {
1158
1157
  this.tokenBucket,
1159
1158
  () => this.client.getOwnedObjects(input)
1160
1159
  );
1161
- },
1162
- gcTime: DEFAULT_GC_TIME
1160
+ }
1163
1161
  });
1164
1162
  }
1165
1163
  async queryGetDynamicFields(input) {
@@ -1170,8 +1168,7 @@ var ScallopCache = class {
1170
1168
  this.tokenBucket,
1171
1169
  () => this.client.getDynamicFields(input)
1172
1170
  );
1173
- },
1174
- gcTime: DEFAULT_GC_TIME
1171
+ }
1175
1172
  });
1176
1173
  }
1177
1174
  async queryGetDynamicFieldObject(input) {
@@ -1182,8 +1179,7 @@ var ScallopCache = class {
1182
1179
  this.tokenBucket,
1183
1180
  () => this.client.getDynamicFieldObject(input)
1184
1181
  );
1185
- },
1186
- gcTime: DEFAULT_GC_TIME
1182
+ }
1187
1183
  });
1188
1184
  }
1189
1185
  async queryGetAllCoinBalances(owner) {
@@ -2337,56 +2333,66 @@ var isolatedAssetZod = zod2.object({
2337
2333
  });
2338
2334
  var ISOLATED_ASSET_KEY = "0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::IsolatedAssetKey";
2339
2335
  var getIsolatedAssets = async (address) => {
2340
- const marketObject = address.get("core.market");
2341
- const isolatedAssets = [];
2342
- if (!marketObject)
2336
+ try {
2337
+ const marketObject = address.get("core.market");
2338
+ const isolatedAssets = [];
2339
+ if (!marketObject)
2340
+ return isolatedAssets;
2341
+ let hasNextPage = false;
2342
+ let nextCursor = null;
2343
+ const isIsolatedDynamicField = (dynamicField) => {
2344
+ return dynamicField.name.type === ISOLATED_ASSET_KEY;
2345
+ };
2346
+ do {
2347
+ const response = await address.cache.queryGetDynamicFields({
2348
+ parentId: marketObject,
2349
+ cursor: nextCursor,
2350
+ limit: 10
2351
+ });
2352
+ if (!response)
2353
+ break;
2354
+ const isolatedAssetCoinTypes = response.data.filter(isIsolatedDynamicField).map(({ name }) => `0x${name.value.type.name}`);
2355
+ isolatedAssets.push(...isolatedAssetCoinTypes);
2356
+ if (response && response.hasNextPage && response.nextCursor) {
2357
+ hasNextPage = true;
2358
+ nextCursor = response.nextCursor;
2359
+ } else {
2360
+ hasNextPage = false;
2361
+ }
2362
+ } while (hasNextPage);
2343
2363
  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;
2364
+ } catch (e) {
2365
+ console.error(e);
2366
+ return [];
2367
+ }
2367
2368
  };
2368
2369
  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)
2370
+ try {
2371
+ const marketObject = utils.address.get("core.market");
2372
+ const cachedData = utils.address.cache.queryClient.getQueryData([
2373
+ "getDynamicFields",
2374
+ marketObject
2375
+ ]);
2376
+ if (cachedData) {
2377
+ const coinType2 = utils.parseCoinType(coinName);
2378
+ return cachedData.includes(coinType2);
2379
+ }
2380
+ const coinType = utils.parseCoinType(coinName).slice(2);
2381
+ const object = await utils.cache.queryGetDynamicFieldObject({
2382
+ parentId: marketObject,
2383
+ name: {
2384
+ type: ISOLATED_ASSET_KEY,
2385
+ value: coinType
2386
+ }
2387
+ });
2388
+ const parsedData = isolatedAssetZod.safeParse(object?.data?.content);
2389
+ if (!parsedData.success)
2390
+ return false;
2391
+ return parsedData.data.fields.value;
2392
+ } catch (e) {
2393
+ console.error(e);
2388
2394
  return false;
2389
- return parsedData.data.fields.value;
2395
+ }
2390
2396
  };
2391
2397
 
2392
2398
  // src/queries/coreQuery.ts
@@ -3163,7 +3169,8 @@ var getStakeAccounts = async ({
3163
3169
  owner,
3164
3170
  filter: { StructType: stakeAccountType },
3165
3171
  options: {
3166
- showContent: true
3172
+ showContent: true,
3173
+ showType: true
3167
3174
  },
3168
3175
  cursor: nextCursor,
3169
3176
  limit: 10
@@ -3201,15 +3208,10 @@ var getStakeAccounts = async ({
3201
3208
  },
3202
3209
  {}
3203
3210
  );
3204
- const stakeObjectIds = stakeObjectsResponse.map((ref) => ref?.data?.objectId).filter((id) => id !== void 0);
3205
- const stakeObjects = await utils.cache.queryGetObjects(stakeObjectIds, {
3206
- showContent: true,
3207
- showType: true
3208
- });
3209
- for (const stakeObject of stakeObjects) {
3210
- const id = stakeObject.objectId;
3211
- const type = stakeObject.type;
3212
- if (stakeObject.content && "fields" in stakeObject.content) {
3211
+ for (const stakeObject of stakeObjectsResponse.map((ref) => ref.data)) {
3212
+ const id = stakeObject?.objectId;
3213
+ const type = stakeObject?.type;
3214
+ if (id && stakeObject?.content && "fields" in stakeObject.content) {
3213
3215
  const fields = stakeObject.content.fields;
3214
3216
  const stakePoolId = String(fields.spool_id);
3215
3217
  const stakeType = String(fields.stake_type.fields.name);
@@ -4706,6 +4708,11 @@ var ScallopUtils = class {
4706
4708
  existPricesCoinNames.push(assetCoinName);
4707
4709
  } else {
4708
4710
  lackPricesCoinNames.push(assetCoinName);
4711
+ this.cache.queryClient.invalidateQueries({
4712
+ queryKey: queryKeys.oracle.getPythLatestPriceFeed(
4713
+ this.address.get(`core.coins.${assetCoinName}.oracle.pyth.feed`)
4714
+ )
4715
+ });
4709
4716
  }
4710
4717
  });
4711
4718
  if (existPricesCoinNames.length > 0) {
@@ -4733,7 +4740,7 @@ var ScallopUtils = class {
4733
4740
  Object.entries(priceIds).map(async ([coinName, priceId]) => {
4734
4741
  const pythConnection = new SuiPriceServiceConnection(endpoint);
4735
4742
  try {
4736
- const feed = await this.address.cache.queryClient.fetchQuery({
4743
+ const feed = await this.cache.queryClient.fetchQuery({
4737
4744
  queryKey: queryKeys.oracle.getPythLatestPriceFeed(priceId),
4738
4745
  queryFn: async () => {
4739
4746
  return await pythConnection.getLatestPriceFeeds([priceId]);