@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.
- package/dist/constants/cache.d.ts +8 -2
- package/dist/constants/queryKeys.d.ts +3 -3
- package/dist/index.js +77 -66
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -66
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopCache.d.ts +1 -1
- package/package.json +1 -1
- package/src/constants/cache.ts +1 -3
- package/src/constants/queryKeys.ts +12 -12
- package/src/models/scallopCache.ts +12 -14
- package/src/queries/isolatedAsset.ts +63 -53
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import { QueryClientConfig } from '@tanstack/query-core';
|
|
2
1
|
/**
|
|
3
2
|
* Default cache options for the QueryClient.
|
|
4
3
|
* @type {QueryClientConfig}
|
|
5
4
|
* @description Default cache options for the QueryClient
|
|
6
5
|
* We set the default to 5s to prevent duplicate requests from being requested (e.g. query MarketObject, etc.)
|
|
7
6
|
*/
|
|
8
|
-
export declare const DEFAULT_CACHE_OPTIONS:
|
|
7
|
+
export declare const DEFAULT_CACHE_OPTIONS: {
|
|
8
|
+
defaultOptions: {
|
|
9
|
+
queries: {
|
|
10
|
+
staleTime: number;
|
|
11
|
+
gcTime: number;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
};
|
|
@@ -26,19 +26,19 @@ export declare const queryKeys: {
|
|
|
26
26
|
options: SuiObjectDataOptions | undefined;
|
|
27
27
|
objectIds: string;
|
|
28
28
|
})[];
|
|
29
|
-
getOwnedObjects: (input
|
|
29
|
+
getOwnedObjects: (input?: Partial<GetOwnedObjectsParams>) => (string | {
|
|
30
30
|
walletAddress: string | undefined;
|
|
31
31
|
cursor: string | undefined;
|
|
32
32
|
options: SuiObjectDataOptions | undefined;
|
|
33
33
|
filter: string;
|
|
34
34
|
limit: number | undefined;
|
|
35
35
|
})[];
|
|
36
|
-
getDynamicFields: (input
|
|
36
|
+
getDynamicFields: (input?: Partial<GetDynamicFieldsParams>) => (string | {
|
|
37
37
|
parentId: string | undefined;
|
|
38
38
|
cursor: string | undefined;
|
|
39
39
|
limit: number | undefined;
|
|
40
40
|
})[];
|
|
41
|
-
getDynamicFieldObject: (input
|
|
41
|
+
getDynamicFieldObject: (input?: Partial<GetDynamicFieldObjectParams>) => (string | {
|
|
42
42
|
parentId: string | undefined;
|
|
43
43
|
name: {
|
|
44
44
|
type: string | undefined;
|
package/dist/index.js
CHANGED
|
@@ -402,27 +402,27 @@ var queryKeys = {
|
|
|
402
402
|
"rpc",
|
|
403
403
|
"getOwnedObjects",
|
|
404
404
|
{
|
|
405
|
-
walletAddress: input
|
|
406
|
-
cursor: input
|
|
407
|
-
options: input
|
|
408
|
-
filter: JSON.stringify(input
|
|
409
|
-
limit: input
|
|
405
|
+
walletAddress: input?.owner,
|
|
406
|
+
cursor: input?.cursor ?? void 0,
|
|
407
|
+
options: input?.options ?? void 0,
|
|
408
|
+
filter: JSON.stringify(input?.filter ?? void 0),
|
|
409
|
+
limit: input?.limit ?? void 0
|
|
410
410
|
}
|
|
411
411
|
],
|
|
412
412
|
getDynamicFields: (input) => [
|
|
413
413
|
"rpc",
|
|
414
414
|
"getDynamicFields",
|
|
415
415
|
{
|
|
416
|
-
parentId: input
|
|
417
|
-
cursor: input
|
|
418
|
-
limit: input
|
|
416
|
+
parentId: input?.parentId,
|
|
417
|
+
cursor: input?.cursor ?? void 0,
|
|
418
|
+
limit: input?.limit ?? void 0
|
|
419
419
|
}
|
|
420
420
|
],
|
|
421
421
|
getDynamicFieldObject: (input) => [
|
|
422
422
|
"rpc",
|
|
423
423
|
"getDynamicFieldObject",
|
|
424
424
|
{
|
|
425
|
-
parentId: input
|
|
425
|
+
parentId: input?.parentId,
|
|
426
426
|
name: {
|
|
427
427
|
type: input?.name?.type,
|
|
428
428
|
value: input?.name?.value
|
|
@@ -1122,7 +1122,6 @@ function withIndexerFallback(method) {
|
|
|
1122
1122
|
}
|
|
1123
1123
|
|
|
1124
1124
|
// src/models/scallopCache.ts
|
|
1125
|
-
var DEFAULT_GC_TIME = 5 * 1e3;
|
|
1126
1125
|
var ScallopCache = class {
|
|
1127
1126
|
constructor(suiKit, walletAddress, cacheOptions, tokenBucket, queryClient) {
|
|
1128
1127
|
this.queryClient = queryClient ?? new import_query_core.QueryClient(cacheOptions ?? DEFAULT_CACHE_OPTIONS);
|
|
@@ -1148,10 +1147,12 @@ var ScallopCache = class {
|
|
|
1148
1147
|
* - `all`: All queries that match the refetch predicate will be refetched in the background.
|
|
1149
1148
|
* - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
|
|
1150
1149
|
*/
|
|
1151
|
-
|
|
1152
|
-
return
|
|
1153
|
-
|
|
1154
|
-
|
|
1150
|
+
invalidateAllCache() {
|
|
1151
|
+
return Object.values(queryKeys.rpc).map(
|
|
1152
|
+
(t) => this.queryClient.invalidateQueries({
|
|
1153
|
+
queryKey: t()
|
|
1154
|
+
})
|
|
1155
|
+
);
|
|
1155
1156
|
}
|
|
1156
1157
|
/**
|
|
1157
1158
|
* @description Provides cache for inspectTxn of the SuiKit.
|
|
@@ -1174,7 +1175,7 @@ var ScallopCache = class {
|
|
|
1174
1175
|
() => this.suiKit.inspectTxn(txBlock)
|
|
1175
1176
|
);
|
|
1176
1177
|
},
|
|
1177
|
-
|
|
1178
|
+
...DEFAULT_CACHE_OPTIONS.defaultOptions.queries
|
|
1178
1179
|
});
|
|
1179
1180
|
return query;
|
|
1180
1181
|
}
|
|
@@ -1196,7 +1197,7 @@ var ScallopCache = class {
|
|
|
1196
1197
|
})
|
|
1197
1198
|
);
|
|
1198
1199
|
},
|
|
1199
|
-
|
|
1200
|
+
...DEFAULT_CACHE_OPTIONS.defaultOptions.queries
|
|
1200
1201
|
});
|
|
1201
1202
|
}
|
|
1202
1203
|
/**
|
|
@@ -1221,7 +1222,7 @@ var ScallopCache = class {
|
|
|
1221
1222
|
() => this.suiKit.getObjects(objectIds, options)
|
|
1222
1223
|
);
|
|
1223
1224
|
},
|
|
1224
|
-
|
|
1225
|
+
...DEFAULT_CACHE_OPTIONS.defaultOptions.queries
|
|
1225
1226
|
});
|
|
1226
1227
|
}
|
|
1227
1228
|
/**
|
|
@@ -1238,7 +1239,7 @@ var ScallopCache = class {
|
|
|
1238
1239
|
() => this.client.getOwnedObjects(input)
|
|
1239
1240
|
);
|
|
1240
1241
|
},
|
|
1241
|
-
|
|
1242
|
+
...DEFAULT_CACHE_OPTIONS.defaultOptions.queries
|
|
1242
1243
|
});
|
|
1243
1244
|
}
|
|
1244
1245
|
async queryGetDynamicFields(input) {
|
|
@@ -1250,7 +1251,7 @@ var ScallopCache = class {
|
|
|
1250
1251
|
() => this.client.getDynamicFields(input)
|
|
1251
1252
|
);
|
|
1252
1253
|
},
|
|
1253
|
-
|
|
1254
|
+
...DEFAULT_CACHE_OPTIONS.defaultOptions.queries
|
|
1254
1255
|
});
|
|
1255
1256
|
}
|
|
1256
1257
|
async queryGetDynamicFieldObject(input) {
|
|
@@ -1262,7 +1263,7 @@ var ScallopCache = class {
|
|
|
1262
1263
|
() => this.client.getDynamicFieldObject(input)
|
|
1263
1264
|
);
|
|
1264
1265
|
},
|
|
1265
|
-
|
|
1266
|
+
...DEFAULT_CACHE_OPTIONS.defaultOptions.queries
|
|
1266
1267
|
});
|
|
1267
1268
|
}
|
|
1268
1269
|
async queryGetAllCoinBalances(owner) {
|
|
@@ -2416,56 +2417,66 @@ var isolatedAssetZod = import_zod2.z.object({
|
|
|
2416
2417
|
});
|
|
2417
2418
|
var ISOLATED_ASSET_KEY = "0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::IsolatedAssetKey";
|
|
2418
2419
|
var getIsolatedAssets = async (address) => {
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2420
|
+
try {
|
|
2421
|
+
const marketObject = address.get("core.market");
|
|
2422
|
+
const isolatedAssets = [];
|
|
2423
|
+
if (!marketObject)
|
|
2424
|
+
return isolatedAssets;
|
|
2425
|
+
let hasNextPage = false;
|
|
2426
|
+
let nextCursor = null;
|
|
2427
|
+
const isIsolatedDynamicField = (dynamicField) => {
|
|
2428
|
+
return dynamicField.name.type === ISOLATED_ASSET_KEY;
|
|
2429
|
+
};
|
|
2430
|
+
do {
|
|
2431
|
+
const response = await address.cache.queryGetDynamicFields({
|
|
2432
|
+
parentId: marketObject,
|
|
2433
|
+
cursor: nextCursor,
|
|
2434
|
+
limit: 10
|
|
2435
|
+
});
|
|
2436
|
+
if (!response)
|
|
2437
|
+
break;
|
|
2438
|
+
const isolatedAssetCoinTypes = response.data.filter(isIsolatedDynamicField).map(({ name }) => `0x${name.value.type.name}`);
|
|
2439
|
+
isolatedAssets.push(...isolatedAssetCoinTypes);
|
|
2440
|
+
if (response && response.hasNextPage && response.nextCursor) {
|
|
2441
|
+
hasNextPage = true;
|
|
2442
|
+
nextCursor = response.nextCursor;
|
|
2443
|
+
} else {
|
|
2444
|
+
hasNextPage = false;
|
|
2445
|
+
}
|
|
2446
|
+
} while (hasNextPage);
|
|
2422
2447
|
return isolatedAssets;
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
};
|
|
2428
|
-
do {
|
|
2429
|
-
const response = await address.cache.queryGetDynamicFields({
|
|
2430
|
-
parentId: marketObject,
|
|
2431
|
-
cursor: nextCursor,
|
|
2432
|
-
limit: 10
|
|
2433
|
-
});
|
|
2434
|
-
if (!response)
|
|
2435
|
-
break;
|
|
2436
|
-
const isolatedAssetCoinTypes = response.data.filter(isIsolatedDynamicField).map(({ name }) => `0x${name.value.type.name}`);
|
|
2437
|
-
isolatedAssets.push(...isolatedAssetCoinTypes);
|
|
2438
|
-
if (response && response.hasNextPage && response.nextCursor) {
|
|
2439
|
-
hasNextPage = true;
|
|
2440
|
-
nextCursor = response.nextCursor;
|
|
2441
|
-
} else {
|
|
2442
|
-
hasNextPage = false;
|
|
2443
|
-
}
|
|
2444
|
-
} while (hasNextPage);
|
|
2445
|
-
return isolatedAssets;
|
|
2448
|
+
} catch (e) {
|
|
2449
|
+
console.error(e);
|
|
2450
|
+
return [];
|
|
2451
|
+
}
|
|
2446
2452
|
};
|
|
2447
2453
|
var isIsolatedAsset = async (utils, coinName) => {
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2454
|
+
try {
|
|
2455
|
+
const marketObject = utils.address.get("core.market");
|
|
2456
|
+
const cachedData = utils.address.cache.queryClient.getQueryData([
|
|
2457
|
+
"getDynamicFields",
|
|
2458
|
+
marketObject
|
|
2459
|
+
]);
|
|
2460
|
+
if (cachedData) {
|
|
2461
|
+
const coinType2 = utils.parseCoinType(coinName);
|
|
2462
|
+
return cachedData.includes(coinType2);
|
|
2463
|
+
}
|
|
2464
|
+
const coinType = utils.parseCoinType(coinName).slice(2);
|
|
2465
|
+
const object = await utils.cache.queryGetDynamicFieldObject({
|
|
2466
|
+
parentId: marketObject,
|
|
2467
|
+
name: {
|
|
2468
|
+
type: ISOLATED_ASSET_KEY,
|
|
2469
|
+
value: coinType
|
|
2470
|
+
}
|
|
2471
|
+
});
|
|
2472
|
+
const parsedData = isolatedAssetZod.safeParse(object?.data?.content);
|
|
2473
|
+
if (!parsedData.success)
|
|
2474
|
+
return false;
|
|
2475
|
+
return parsedData.data.fields.value;
|
|
2476
|
+
} catch (e) {
|
|
2477
|
+
console.error(e);
|
|
2467
2478
|
return false;
|
|
2468
|
-
|
|
2479
|
+
}
|
|
2469
2480
|
};
|
|
2470
2481
|
|
|
2471
2482
|
// src/queries/coreQuery.ts
|