@scallop-io/sui-scallop-sdk 1.3.0-alpha.3 → 1.3.0-alpha.5
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/index.d.ts +1 -0
- package/dist/constants/queryKeys.d.ts +61 -0
- package/dist/index.js +221 -145
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +227 -153
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallop.d.ts +2 -1
- package/dist/models/scallopCache.d.ts +2 -3
- package/dist/models/scallopQuery.d.ts +8 -0
- package/dist/queries/isolatedAsset.d.ts +14 -0
- package/dist/types/query/core.d.ts +1 -0
- package/dist/types/query/portfolio.d.ts +1 -1
- package/package.json +2 -2
- package/src/constants/common.ts +2 -2
- package/src/constants/index.ts +1 -0
- package/src/constants/queryKeys.ts +111 -0
- package/src/models/scallop.ts +5 -2
- package/src/models/scallopAddress.ts +2 -1
- package/src/models/scallopCache.ts +31 -129
- package/src/models/scallopIndexer.ts +5 -4
- package/src/models/scallopQuery.ts +15 -0
- package/src/models/scallopUtils.ts +2 -1
- package/src/queries/coreQuery.ts +3 -0
- package/src/queries/isolatedAsset.ts +105 -0
- package/src/queries/portfolioQuery.ts +1 -0
- package/src/queries/supplyLimit.ts +2 -2
- package/src/queries/vescaQuery.ts +5 -4
- package/src/types/query/core.ts +1 -0
- package/src/types/query/portfolio.ts +1 -0
- package/src/utils/indexer.ts +2 -2
- package/src/utils/tokenBucket.ts +1 -1
- package/dist/test.d.ts +0 -1
- package/src/test.ts +0 -26
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { GetDynamicFieldObjectParams, GetDynamicFieldsParams, GetOwnedObjectsParams, SuiObjectData, SuiObjectDataOptions } from '@mysten/sui/client';
|
|
2
|
+
import type { SuiObjectArg } from '@scallop-io/sui-kit';
|
|
3
|
+
export declare const queryKeys: {
|
|
4
|
+
api: {
|
|
5
|
+
getAddresses: (addressesId?: string) => (string | {
|
|
6
|
+
addressesId: string | undefined;
|
|
7
|
+
})[];
|
|
8
|
+
getMarket: () => string[];
|
|
9
|
+
getSpools: () => string[];
|
|
10
|
+
getBorrowIncentivePool: () => string[];
|
|
11
|
+
getTotalValueLocked: () => string[];
|
|
12
|
+
};
|
|
13
|
+
rpc: {
|
|
14
|
+
getInspectTxn: (queryTarget?: string, args?: SuiObjectArg[], typeArgs?: any[]) => (string | {
|
|
15
|
+
queryTarget: string | undefined;
|
|
16
|
+
args: string;
|
|
17
|
+
typeArgs: string | undefined;
|
|
18
|
+
})[];
|
|
19
|
+
getObject: (objectId?: string, walletAddress?: string, options?: SuiObjectDataOptions) => (string | {
|
|
20
|
+
walletAddress: string | undefined;
|
|
21
|
+
options: SuiObjectDataOptions | undefined;
|
|
22
|
+
objectId: string | undefined;
|
|
23
|
+
})[];
|
|
24
|
+
getObjects: (objectIds?: string[], walletAddress?: string, options?: SuiObjectDataOptions) => (string | {
|
|
25
|
+
walletAddress: string | undefined;
|
|
26
|
+
options: SuiObjectDataOptions | undefined;
|
|
27
|
+
objectIds: string;
|
|
28
|
+
})[];
|
|
29
|
+
getOwnedObjects: (input: Partial<GetOwnedObjectsParams>) => (string | {
|
|
30
|
+
walletAddress: string | undefined;
|
|
31
|
+
cursor: string | undefined;
|
|
32
|
+
options: SuiObjectDataOptions | undefined;
|
|
33
|
+
filter: string;
|
|
34
|
+
limit: number | undefined;
|
|
35
|
+
})[];
|
|
36
|
+
getDynamicFields: (input: Partial<GetDynamicFieldsParams>) => (string | {
|
|
37
|
+
parentId: string | undefined;
|
|
38
|
+
cursor: string | undefined;
|
|
39
|
+
limit: number | undefined;
|
|
40
|
+
})[];
|
|
41
|
+
getDynamicFieldObject: (input: Partial<GetDynamicFieldObjectParams>) => (string | {
|
|
42
|
+
parentId: string | undefined;
|
|
43
|
+
name: {
|
|
44
|
+
type: string | undefined;
|
|
45
|
+
value: unknown;
|
|
46
|
+
};
|
|
47
|
+
})[];
|
|
48
|
+
getTotalVeScaTreasuryAmount: (refreshArgs?: any[], vescaAmountArgs?: (string | SuiObjectData)[]) => (string | {
|
|
49
|
+
refreshArgs: string;
|
|
50
|
+
vescaAmountArgs: string;
|
|
51
|
+
})[];
|
|
52
|
+
getAllCoinBalances: (owner?: string) => (string | {
|
|
53
|
+
owner: string | undefined;
|
|
54
|
+
})[];
|
|
55
|
+
};
|
|
56
|
+
pyth: {
|
|
57
|
+
getPythLatestPriceFeed: (pythPriceId?: string) => (string | {
|
|
58
|
+
pythPriceId: string | undefined;
|
|
59
|
+
})[];
|
|
60
|
+
};
|
|
61
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -69,6 +69,7 @@ __export(src_exports, {
|
|
|
69
69
|
coinDecimals: () => coinDecimals,
|
|
70
70
|
coinIds: () => coinIds,
|
|
71
71
|
marketCoins: () => marketCoins,
|
|
72
|
+
queryKeys: () => queryKeys,
|
|
72
73
|
sCoinIds: () => sCoinIds,
|
|
73
74
|
sCoins: () => sCoins,
|
|
74
75
|
spoolRewardCoins: () => spoolRewardCoins,
|
|
@@ -93,7 +94,7 @@ var SUPPORT_POOLS = [
|
|
|
93
94
|
"usdc",
|
|
94
95
|
// native USDC
|
|
95
96
|
"sbeth",
|
|
96
|
-
//
|
|
97
|
+
// sui bridge ETH
|
|
97
98
|
"weth",
|
|
98
99
|
"wbtc",
|
|
99
100
|
"wusdc",
|
|
@@ -111,7 +112,7 @@ var SUPPORT_COLLATERALS = [
|
|
|
111
112
|
"usdc",
|
|
112
113
|
// native USDC
|
|
113
114
|
"sbeth",
|
|
114
|
-
//
|
|
115
|
+
// sui bridge ETH
|
|
115
116
|
"weth",
|
|
116
117
|
"wbtc",
|
|
117
118
|
"wusdc",
|
|
@@ -364,6 +365,93 @@ var FlashLoanFeeObjectMap = {
|
|
|
364
365
|
wsol: "0xe84bdb35b790fc7bdd1645122ac6ac0fc904531d6772c9e25904fece322c5f34"
|
|
365
366
|
};
|
|
366
367
|
|
|
368
|
+
// src/constants/queryKeys.ts
|
|
369
|
+
var queryKeys = {
|
|
370
|
+
api: {
|
|
371
|
+
getAddresses: (addressesId) => [
|
|
372
|
+
"api",
|
|
373
|
+
"getAddresses",
|
|
374
|
+
{ addressesId }
|
|
375
|
+
],
|
|
376
|
+
getMarket: () => ["api", "getMarket"],
|
|
377
|
+
getSpools: () => ["api", "getSpools"],
|
|
378
|
+
getBorrowIncentivePool: () => ["api", "getBorrowIncentivePools"],
|
|
379
|
+
getTotalValueLocked: () => ["api", "getTotalValueLocked"]
|
|
380
|
+
},
|
|
381
|
+
rpc: {
|
|
382
|
+
getInspectTxn: (queryTarget, args, typeArgs) => [
|
|
383
|
+
"rpc",
|
|
384
|
+
"getInspectTxn",
|
|
385
|
+
{
|
|
386
|
+
queryTarget,
|
|
387
|
+
args: JSON.stringify(args),
|
|
388
|
+
typeArgs: !typeArgs ? void 0 : JSON.stringify(typeArgs)
|
|
389
|
+
}
|
|
390
|
+
],
|
|
391
|
+
getObject: (objectId, walletAddress, options) => ["rpc", "getObject", { walletAddress, options, objectId }],
|
|
392
|
+
getObjects: (objectIds, walletAddress, options) => [
|
|
393
|
+
"rpc",
|
|
394
|
+
"getObjects",
|
|
395
|
+
{
|
|
396
|
+
walletAddress,
|
|
397
|
+
options,
|
|
398
|
+
objectIds: JSON.stringify(objectIds ?? [])
|
|
399
|
+
}
|
|
400
|
+
],
|
|
401
|
+
getOwnedObjects: (input) => [
|
|
402
|
+
"rpc",
|
|
403
|
+
"getOwnedObjects",
|
|
404
|
+
{
|
|
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
|
+
}
|
|
411
|
+
],
|
|
412
|
+
getDynamicFields: (input) => [
|
|
413
|
+
"rpc",
|
|
414
|
+
"getDynamicFields",
|
|
415
|
+
{
|
|
416
|
+
parentId: input.parentId,
|
|
417
|
+
cursor: input.cursor ?? void 0,
|
|
418
|
+
limit: input.limit ?? void 0
|
|
419
|
+
}
|
|
420
|
+
],
|
|
421
|
+
getDynamicFieldObject: (input) => [
|
|
422
|
+
"rpc",
|
|
423
|
+
"getDynamicFieldObject",
|
|
424
|
+
{
|
|
425
|
+
parentId: input.parentId,
|
|
426
|
+
name: {
|
|
427
|
+
type: input?.name?.type,
|
|
428
|
+
value: input?.name?.value
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
],
|
|
432
|
+
getTotalVeScaTreasuryAmount: (refreshArgs, vescaAmountArgs) => [
|
|
433
|
+
"rpc",
|
|
434
|
+
"getTotalVeScaTreasuryAmount",
|
|
435
|
+
{
|
|
436
|
+
refreshArgs: JSON.stringify(refreshArgs),
|
|
437
|
+
vescaAmountArgs: JSON.stringify(vescaAmountArgs)
|
|
438
|
+
}
|
|
439
|
+
],
|
|
440
|
+
getAllCoinBalances: (owner) => [
|
|
441
|
+
"rpc",
|
|
442
|
+
"getAllCoinBalances",
|
|
443
|
+
{ owner }
|
|
444
|
+
]
|
|
445
|
+
},
|
|
446
|
+
pyth: {
|
|
447
|
+
getPythLatestPriceFeed: (pythPriceId) => [
|
|
448
|
+
"pyth",
|
|
449
|
+
"getPythPriceId",
|
|
450
|
+
{ pythPriceId }
|
|
451
|
+
]
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
|
|
367
455
|
// src/constants/vesca.ts
|
|
368
456
|
var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
|
|
369
457
|
var MAX_LOCK_ROUNDS = 1460;
|
|
@@ -996,7 +1084,7 @@ var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVA
|
|
|
996
1084
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
997
1085
|
return tryRequest();
|
|
998
1086
|
} else {
|
|
999
|
-
console.error("An error occurred:", error);
|
|
1087
|
+
console.error("An error occurred:", error.message);
|
|
1000
1088
|
return null;
|
|
1001
1089
|
}
|
|
1002
1090
|
}
|
|
@@ -1019,8 +1107,8 @@ async function callMethodWithIndexerFallback(method, context, ...args) {
|
|
|
1019
1107
|
if (indexer) {
|
|
1020
1108
|
try {
|
|
1021
1109
|
return await method.apply(context, args);
|
|
1022
|
-
} catch (
|
|
1023
|
-
console.warn(
|
|
1110
|
+
} catch (e) {
|
|
1111
|
+
console.warn(`Indexer requests failed: ${e}. Retrying without indexer..`);
|
|
1024
1112
|
return await method.apply(context, [...args.slice(0, -1), false]);
|
|
1025
1113
|
}
|
|
1026
1114
|
}
|
|
@@ -1034,8 +1122,8 @@ function withIndexerFallback(method) {
|
|
|
1034
1122
|
|
|
1035
1123
|
// src/models/scallopCache.ts
|
|
1036
1124
|
var ScallopCache = class {
|
|
1037
|
-
constructor(suiKit, walletAddress, cacheOptions, tokenBucket) {
|
|
1038
|
-
this.queryClient = new import_query_core.QueryClient(cacheOptions ?? DEFAULT_CACHE_OPTIONS);
|
|
1125
|
+
constructor(suiKit, walletAddress, cacheOptions, tokenBucket, queryClient) {
|
|
1126
|
+
this.queryClient = queryClient ?? new import_query_core.QueryClient(cacheOptions ?? DEFAULT_CACHE_OPTIONS);
|
|
1039
1127
|
this._suiKit = suiKit;
|
|
1040
1128
|
this.tokenBucket = tokenBucket ?? new TokenBucket(DEFAULT_TOKENS_PER_INTERVAL, DEFAULT_INTERVAL_IN_MS);
|
|
1041
1129
|
this.walletAddress = walletAddress ?? suiKit.currentAddress();
|
|
@@ -1063,41 +1151,6 @@ var ScallopCache = class {
|
|
|
1063
1151
|
refetchType
|
|
1064
1152
|
});
|
|
1065
1153
|
}
|
|
1066
|
-
async resolveArgs(txb, args) {
|
|
1067
|
-
return await Promise.all(
|
|
1068
|
-
args.map(async (arg) => {
|
|
1069
|
-
if (typeof arg === "string") {
|
|
1070
|
-
const objData = (await this.queryGetObject(arg, { showOwner: true }))?.data;
|
|
1071
|
-
if (!objData)
|
|
1072
|
-
return arg;
|
|
1073
|
-
const owner = objData?.owner;
|
|
1074
|
-
if (!owner)
|
|
1075
|
-
return arg;
|
|
1076
|
-
if ("Shared" in owner) {
|
|
1077
|
-
return txb.sharedObjectRef({
|
|
1078
|
-
objectId: objData.objectId,
|
|
1079
|
-
initialSharedVersion: owner.Shared.initial_shared_version,
|
|
1080
|
-
mutable: true
|
|
1081
|
-
});
|
|
1082
|
-
} else {
|
|
1083
|
-
return txb.objectRef({
|
|
1084
|
-
objectId: objData.objectId,
|
|
1085
|
-
version: objData.version,
|
|
1086
|
-
digest: objData.digest
|
|
1087
|
-
});
|
|
1088
|
-
}
|
|
1089
|
-
} else if ("objectId" in arg && "version" in arg && "digest" in arg) {
|
|
1090
|
-
return txb.objectRef({
|
|
1091
|
-
objectId: arg.objectId,
|
|
1092
|
-
version: arg.version,
|
|
1093
|
-
digest: arg.digest
|
|
1094
|
-
});
|
|
1095
|
-
} else {
|
|
1096
|
-
return arg;
|
|
1097
|
-
}
|
|
1098
|
-
})
|
|
1099
|
-
);
|
|
1100
|
-
}
|
|
1101
1154
|
/**
|
|
1102
1155
|
* @description Provides cache for inspectTxn of the SuiKit.
|
|
1103
1156
|
* @param QueryInspectTxnParams
|
|
@@ -1110,15 +1163,9 @@ var ScallopCache = class {
|
|
|
1110
1163
|
typeArgs
|
|
1111
1164
|
}) {
|
|
1112
1165
|
const txBlock = new import_sui_kit.SuiTxBlock();
|
|
1113
|
-
|
|
1114
|
-
txBlock.moveCall(queryTarget, resolvedArgs, typeArgs);
|
|
1166
|
+
txBlock.moveCall(queryTarget, args, typeArgs);
|
|
1115
1167
|
const query = await this.queryClient.fetchQuery({
|
|
1116
|
-
queryKey:
|
|
1117
|
-
"inspectTxn",
|
|
1118
|
-
queryTarget,
|
|
1119
|
-
JSON.stringify(args),
|
|
1120
|
-
JSON.stringify(typeArgs)
|
|
1121
|
-
],
|
|
1168
|
+
queryKey: queryKeys.rpc.getInspectTxn(queryTarget, args, typeArgs),
|
|
1122
1169
|
queryFn: async () => {
|
|
1123
1170
|
return await callWithRateLimit(
|
|
1124
1171
|
this.tokenBucket,
|
|
@@ -1135,12 +1182,8 @@ var ScallopCache = class {
|
|
|
1135
1182
|
* @returns Promise<SuiObjectResponse>
|
|
1136
1183
|
*/
|
|
1137
1184
|
async queryGetObject(objectId, options) {
|
|
1138
|
-
const queryKey = ["getObject", objectId, this.walletAddress];
|
|
1139
|
-
if (options) {
|
|
1140
|
-
queryKey.push(JSON.stringify(options));
|
|
1141
|
-
}
|
|
1142
1185
|
return this.queryClient.fetchQuery({
|
|
1143
|
-
queryKey,
|
|
1186
|
+
queryKey: queryKeys.rpc.getObject(objectId, this.walletAddress, options),
|
|
1144
1187
|
queryFn: async () => {
|
|
1145
1188
|
return await callWithRateLimit(
|
|
1146
1189
|
this.tokenBucket,
|
|
@@ -1162,16 +1205,12 @@ var ScallopCache = class {
|
|
|
1162
1205
|
}) {
|
|
1163
1206
|
if (objectIds.length === 0)
|
|
1164
1207
|
return [];
|
|
1165
|
-
const queryKey = [
|
|
1166
|
-
"getObjects",
|
|
1167
|
-
JSON.stringify(objectIds),
|
|
1168
|
-
this.walletAddress
|
|
1169
|
-
];
|
|
1170
|
-
if (options) {
|
|
1171
|
-
queryKey.push(JSON.stringify(options));
|
|
1172
|
-
}
|
|
1173
1208
|
return this.queryClient.fetchQuery({
|
|
1174
|
-
queryKey
|
|
1209
|
+
queryKey: queryKeys.rpc.getObjects(
|
|
1210
|
+
objectIds,
|
|
1211
|
+
this.walletAddress,
|
|
1212
|
+
options
|
|
1213
|
+
),
|
|
1175
1214
|
queryFn: async () => {
|
|
1176
1215
|
return await callWithRateLimit(
|
|
1177
1216
|
this.tokenBucket,
|
|
@@ -1186,21 +1225,8 @@ var ScallopCache = class {
|
|
|
1186
1225
|
* @returns Promise<PaginatedObjectsResponse>
|
|
1187
1226
|
*/
|
|
1188
1227
|
async queryGetOwnedObjects(input) {
|
|
1189
|
-
const queryKey = ["getOwnedObjects", input.owner];
|
|
1190
|
-
if (input.cursor) {
|
|
1191
|
-
queryKey.push(JSON.stringify(input.cursor));
|
|
1192
|
-
}
|
|
1193
|
-
if (input.options) {
|
|
1194
|
-
queryKey.push(JSON.stringify(input.options));
|
|
1195
|
-
}
|
|
1196
|
-
if (input.filter) {
|
|
1197
|
-
queryKey.push(JSON.stringify(input.filter));
|
|
1198
|
-
}
|
|
1199
|
-
if (input.limit) {
|
|
1200
|
-
queryKey.push(JSON.stringify(input.limit));
|
|
1201
|
-
}
|
|
1202
1228
|
return this.queryClient.fetchQuery({
|
|
1203
|
-
queryKey,
|
|
1229
|
+
queryKey: queryKeys.rpc.getOwnedObjects(input),
|
|
1204
1230
|
queryFn: async () => {
|
|
1205
1231
|
return await callWithRateLimit(
|
|
1206
1232
|
this.tokenBucket,
|
|
@@ -1210,15 +1236,8 @@ var ScallopCache = class {
|
|
|
1210
1236
|
});
|
|
1211
1237
|
}
|
|
1212
1238
|
async queryGetDynamicFields(input) {
|
|
1213
|
-
const queryKey = ["getDynamicFields", input.parentId];
|
|
1214
|
-
if (input.cursor) {
|
|
1215
|
-
queryKey.push(JSON.stringify(input.cursor));
|
|
1216
|
-
}
|
|
1217
|
-
if (input.limit) {
|
|
1218
|
-
queryKey.push(JSON.stringify(input.limit));
|
|
1219
|
-
}
|
|
1220
1239
|
return this.queryClient.fetchQuery({
|
|
1221
|
-
queryKey,
|
|
1240
|
+
queryKey: queryKeys.rpc.getDynamicFields(input),
|
|
1222
1241
|
queryFn: async () => {
|
|
1223
1242
|
return await callWithRateLimit(
|
|
1224
1243
|
this.tokenBucket,
|
|
@@ -1228,14 +1247,8 @@ var ScallopCache = class {
|
|
|
1228
1247
|
});
|
|
1229
1248
|
}
|
|
1230
1249
|
async queryGetDynamicFieldObject(input) {
|
|
1231
|
-
const queryKey = [
|
|
1232
|
-
"getDynamicFieldObject",
|
|
1233
|
-
input.parentId,
|
|
1234
|
-
input.name.type,
|
|
1235
|
-
input.name.value
|
|
1236
|
-
];
|
|
1237
1250
|
return this.queryClient.fetchQuery({
|
|
1238
|
-
queryKey,
|
|
1251
|
+
queryKey: queryKeys.rpc.getDynamicFieldObject(input),
|
|
1239
1252
|
queryFn: async () => {
|
|
1240
1253
|
return await callWithRateLimit(
|
|
1241
1254
|
this.tokenBucket,
|
|
@@ -1245,9 +1258,8 @@ var ScallopCache = class {
|
|
|
1245
1258
|
});
|
|
1246
1259
|
}
|
|
1247
1260
|
async queryGetAllCoinBalances(owner) {
|
|
1248
|
-
const queryKey = ["getAllCoinBalances", owner];
|
|
1249
1261
|
return this.queryClient.fetchQuery({
|
|
1250
|
-
queryKey,
|
|
1262
|
+
queryKey: queryKeys.rpc.getAllCoinBalances(owner),
|
|
1251
1263
|
queryFn: async () => {
|
|
1252
1264
|
const allBalances = await callWithRateLimit(
|
|
1253
1265
|
this.tokenBucket,
|
|
@@ -1264,17 +1276,6 @@ var ScallopCache = class {
|
|
|
1264
1276
|
},
|
|
1265
1277
|
{}
|
|
1266
1278
|
);
|
|
1267
|
-
for (const coinType in balances) {
|
|
1268
|
-
const coinBalanceQueryKey = [
|
|
1269
|
-
"getCoinBalance",
|
|
1270
|
-
(0, import_sui_kit.normalizeSuiAddress)(owner),
|
|
1271
|
-
(0, import_sui_kit.normalizeStructTag)(coinType)
|
|
1272
|
-
];
|
|
1273
|
-
this.queryClient.setQueryData(
|
|
1274
|
-
coinBalanceQueryKey,
|
|
1275
|
-
balances[coinType]
|
|
1276
|
-
);
|
|
1277
|
-
}
|
|
1278
1279
|
return balances;
|
|
1279
1280
|
}
|
|
1280
1281
|
});
|
|
@@ -1282,19 +1283,7 @@ var ScallopCache = class {
|
|
|
1282
1283
|
async queryGetCoinBalance(input) {
|
|
1283
1284
|
if (!input.coinType)
|
|
1284
1285
|
return "0";
|
|
1285
|
-
|
|
1286
|
-
"getCoinBalance",
|
|
1287
|
-
(0, import_sui_kit.normalizeSuiAddress)(input.owner),
|
|
1288
|
-
(0, import_sui_kit.normalizeStructTag)(input.coinType)
|
|
1289
|
-
];
|
|
1290
|
-
return this.queryClient.fetchQuery({
|
|
1291
|
-
queryKey,
|
|
1292
|
-
queryFn: async () => {
|
|
1293
|
-
if (!input.coinType)
|
|
1294
|
-
return "0";
|
|
1295
|
-
return (await this.queryGetAllCoinBalances(input.owner))[(0, import_sui_kit.normalizeStructTag)(input.coinType)] ?? "0";
|
|
1296
|
-
}
|
|
1297
|
-
});
|
|
1286
|
+
return (await this.queryGetAllCoinBalances(input.owner) || {})[(0, import_sui_kit.normalizeStructTag)(input.coinType)] ?? "0";
|
|
1298
1287
|
}
|
|
1299
1288
|
};
|
|
1300
1289
|
|
|
@@ -2228,7 +2217,7 @@ var ScallopAddress = class {
|
|
|
2228
2217
|
const addressesId = id || this._id || void 0;
|
|
2229
2218
|
if (addressesId !== void 0) {
|
|
2230
2219
|
const response = await this.cache.queryClient.fetchQuery({
|
|
2231
|
-
queryKey:
|
|
2220
|
+
queryKey: queryKeys.api.getAddresses(addressesId),
|
|
2232
2221
|
queryFn: async () => {
|
|
2233
2222
|
return await this._requestClient.get(`/addresses/${addressesId}`, {
|
|
2234
2223
|
headers: {
|
|
@@ -2382,7 +2371,7 @@ var supplyLimitZod = import_zod.z.object({
|
|
|
2382
2371
|
value: import_zod.z.string()
|
|
2383
2372
|
})
|
|
2384
2373
|
});
|
|
2385
|
-
var
|
|
2374
|
+
var SUPPLY_LIMIT_KEY = "0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::SupplyLimitKey";
|
|
2386
2375
|
var getSupplyLimit = async (utils, poolName) => {
|
|
2387
2376
|
const poolCoinType = utils.parseCoinType(poolName).slice(2);
|
|
2388
2377
|
const marketObject = utils.address.get("core.market");
|
|
@@ -2391,7 +2380,7 @@ var getSupplyLimit = async (utils, poolName) => {
|
|
|
2391
2380
|
const object = await utils.cache.queryGetDynamicFieldObject({
|
|
2392
2381
|
parentId: marketObject,
|
|
2393
2382
|
name: {
|
|
2394
|
-
type:
|
|
2383
|
+
type: SUPPLY_LIMIT_KEY,
|
|
2395
2384
|
value: poolCoinType
|
|
2396
2385
|
}
|
|
2397
2386
|
});
|
|
@@ -2401,6 +2390,76 @@ var getSupplyLimit = async (utils, poolName) => {
|
|
|
2401
2390
|
return parsedData.data.fields.value;
|
|
2402
2391
|
};
|
|
2403
2392
|
|
|
2393
|
+
// src/queries/isolatedAsset.ts
|
|
2394
|
+
var import_zod2 = require("zod");
|
|
2395
|
+
var isolatedAssetZod = import_zod2.z.object({
|
|
2396
|
+
dataType: import_zod2.z.string(),
|
|
2397
|
+
type: import_zod2.z.string(),
|
|
2398
|
+
hasPublicTransfer: import_zod2.z.boolean(),
|
|
2399
|
+
fields: import_zod2.z.object({
|
|
2400
|
+
id: import_zod2.z.object({
|
|
2401
|
+
id: import_zod2.z.string()
|
|
2402
|
+
}),
|
|
2403
|
+
name: import_zod2.z.object({
|
|
2404
|
+
type: import_zod2.z.string()
|
|
2405
|
+
}),
|
|
2406
|
+
value: import_zod2.z.boolean()
|
|
2407
|
+
})
|
|
2408
|
+
});
|
|
2409
|
+
var ISOLATED_ASSET_KEY = "0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::IsolatedAssetKey";
|
|
2410
|
+
var getIsolatedAssets = async (address) => {
|
|
2411
|
+
const marketObject = address.get("core.market");
|
|
2412
|
+
const isolatedAssets = [];
|
|
2413
|
+
if (!marketObject)
|
|
2414
|
+
return isolatedAssets;
|
|
2415
|
+
let hasNextPage = false;
|
|
2416
|
+
let nextCursor = null;
|
|
2417
|
+
const isIsolatedDynamicField = (dynamicField) => {
|
|
2418
|
+
return dynamicField.name.type === ISOLATED_ASSET_KEY;
|
|
2419
|
+
};
|
|
2420
|
+
do {
|
|
2421
|
+
const response = await address.cache.queryGetDynamicFields({
|
|
2422
|
+
parentId: marketObject,
|
|
2423
|
+
cursor: nextCursor,
|
|
2424
|
+
limit: 10
|
|
2425
|
+
});
|
|
2426
|
+
if (!response)
|
|
2427
|
+
break;
|
|
2428
|
+
const isolatedAssetCoinTypes = response.data.filter(isIsolatedDynamicField).map(({ name }) => `0x${name.value.type.name}`);
|
|
2429
|
+
isolatedAssets.push(...isolatedAssetCoinTypes);
|
|
2430
|
+
if (response && response.hasNextPage && response.nextCursor) {
|
|
2431
|
+
hasNextPage = true;
|
|
2432
|
+
nextCursor = response.nextCursor;
|
|
2433
|
+
} else {
|
|
2434
|
+
hasNextPage = false;
|
|
2435
|
+
}
|
|
2436
|
+
} while (hasNextPage);
|
|
2437
|
+
return isolatedAssets;
|
|
2438
|
+
};
|
|
2439
|
+
var isIsolatedAsset = async (utils, coinName) => {
|
|
2440
|
+
const marketObject = utils.address.get("core.market");
|
|
2441
|
+
const cachedData = utils.address.cache.queryClient.getQueryData([
|
|
2442
|
+
"getDynamicFields",
|
|
2443
|
+
marketObject
|
|
2444
|
+
]);
|
|
2445
|
+
if (cachedData) {
|
|
2446
|
+
const coinType2 = utils.parseCoinType(coinName);
|
|
2447
|
+
return cachedData.includes(coinType2);
|
|
2448
|
+
}
|
|
2449
|
+
const coinType = utils.parseCoinType(coinName).slice(2);
|
|
2450
|
+
const object = await utils.cache.queryGetDynamicFieldObject({
|
|
2451
|
+
parentId: marketObject,
|
|
2452
|
+
name: {
|
|
2453
|
+
type: ISOLATED_ASSET_KEY,
|
|
2454
|
+
value: coinType
|
|
2455
|
+
}
|
|
2456
|
+
});
|
|
2457
|
+
const parsedData = isolatedAssetZod.safeParse(object?.data?.content);
|
|
2458
|
+
if (!parsedData.success)
|
|
2459
|
+
return false;
|
|
2460
|
+
return parsedData.data.fields.value;
|
|
2461
|
+
};
|
|
2462
|
+
|
|
2404
2463
|
// src/queries/coreQuery.ts
|
|
2405
2464
|
var queryMarket = async (query, indexer = false) => {
|
|
2406
2465
|
const coinPrices = await query.utils.getCoinPrices();
|
|
@@ -2485,6 +2544,7 @@ var queryMarket = async (query, indexer = false) => {
|
|
|
2485
2544
|
borrowFee: parsedMarketPoolData.borrowFee,
|
|
2486
2545
|
marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
|
|
2487
2546
|
minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
|
|
2547
|
+
isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
|
|
2488
2548
|
maxSupplyCoin,
|
|
2489
2549
|
...calculatedMarketPoolData
|
|
2490
2550
|
};
|
|
@@ -2712,6 +2772,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2712
2772
|
marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
|
|
2713
2773
|
minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
|
|
2714
2774
|
maxSupplyCoin,
|
|
2775
|
+
isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
|
|
2715
2776
|
...calculatedMarketPoolData
|
|
2716
2777
|
};
|
|
2717
2778
|
}
|
|
@@ -3771,7 +3832,8 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
3771
3832
|
availableUnstakeAmount: availableUnstakeAmount.toNumber(),
|
|
3772
3833
|
availableUnstakeCoin: availableUnstakeCoin.toNumber(),
|
|
3773
3834
|
availableClaimAmount: availableClaimAmount.toNumber(),
|
|
3774
|
-
availableClaimCoin: availableClaimCoin.toNumber()
|
|
3835
|
+
availableClaimCoin: availableClaimCoin.toNumber(),
|
|
3836
|
+
isIsolated: marketPool ? marketPool.isIsolated : false
|
|
3775
3837
|
};
|
|
3776
3838
|
return lending;
|
|
3777
3839
|
};
|
|
@@ -4129,7 +4191,7 @@ var getTotalValueLocked = async (query, indexer = false) => {
|
|
|
4129
4191
|
var import_bignumber5 = __toESM(require("bignumber.js"));
|
|
4130
4192
|
var import_sui_kit3 = require("@scallop-io/sui-kit");
|
|
4131
4193
|
var import_bcs = require("@mysten/sui/bcs");
|
|
4132
|
-
var
|
|
4194
|
+
var import_zod3 = require("zod");
|
|
4133
4195
|
var import_assert = __toESM(require("assert"));
|
|
4134
4196
|
var getVescaKeys = async (utils, ownerAddress) => {
|
|
4135
4197
|
const owner = ownerAddress || utils.suiKit.currentAddress();
|
|
@@ -4178,10 +4240,10 @@ var getVeScas = async ({
|
|
|
4178
4240
|
}
|
|
4179
4241
|
return result;
|
|
4180
4242
|
};
|
|
4181
|
-
var SuiObjectRefZod =
|
|
4182
|
-
objectId:
|
|
4183
|
-
digest:
|
|
4184
|
-
version:
|
|
4243
|
+
var SuiObjectRefZod = import_zod3.z.object({
|
|
4244
|
+
objectId: import_zod3.z.string(),
|
|
4245
|
+
digest: import_zod3.z.string(),
|
|
4246
|
+
version: import_zod3.z.string()
|
|
4185
4247
|
});
|
|
4186
4248
|
var getVeSca = async (utils, veScaKey, ownerAddress) => {
|
|
4187
4249
|
const tableId = utils.address.get(`vesca.tableId`);
|
|
@@ -4256,10 +4318,10 @@ var getTotalVeScaTreasuryAmount = async (utils, veScaTreasury) => {
|
|
|
4256
4318
|
onlyTransactionKind: true
|
|
4257
4319
|
});
|
|
4258
4320
|
const res = await utils.cache.queryClient.fetchQuery({
|
|
4259
|
-
queryKey:
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4321
|
+
queryKey: queryKeys.rpc.getTotalVeScaTreasuryAmount(
|
|
4322
|
+
refreshArgs,
|
|
4323
|
+
veScaAmountArgs
|
|
4324
|
+
),
|
|
4263
4325
|
queryFn: async () => {
|
|
4264
4326
|
return await utils.suiKit.inspectTxn(txBytes);
|
|
4265
4327
|
}
|
|
@@ -4315,16 +4377,16 @@ var queryVeScaKeyIdFromReferralBindings = async (address, refereeAddress) => {
|
|
|
4315
4377
|
|
|
4316
4378
|
// src/queries/loyaltyProgramQuery.ts
|
|
4317
4379
|
var import_bignumber6 = __toESM(require("bignumber.js"));
|
|
4318
|
-
var
|
|
4319
|
-
var rewardPoolFieldsZod =
|
|
4320
|
-
balance:
|
|
4321
|
-
enable_claim:
|
|
4380
|
+
var import_zod4 = require("zod");
|
|
4381
|
+
var rewardPoolFieldsZod = import_zod4.z.object({
|
|
4382
|
+
balance: import_zod4.z.string(),
|
|
4383
|
+
enable_claim: import_zod4.z.boolean()
|
|
4322
4384
|
}).transform((value) => ({
|
|
4323
4385
|
totalPoolReward: (0, import_bignumber6.default)(value.balance).shiftedBy(-9).toNumber(),
|
|
4324
4386
|
isClaimEnabled: value.enable_claim
|
|
4325
4387
|
}));
|
|
4326
|
-
var userRewardFieldsZod =
|
|
4327
|
-
value:
|
|
4388
|
+
var userRewardFieldsZod = import_zod4.z.object({
|
|
4389
|
+
value: import_zod4.z.string()
|
|
4328
4390
|
}).transform((value) => (0, import_bignumber6.default)(value.value).shiftedBy(-9).toNumber());
|
|
4329
4391
|
var getLoyaltyProgramInformations = async (query, veScaKey) => {
|
|
4330
4392
|
const rewardPool = query.address.get("loyaltyProgram.rewardPool");
|
|
@@ -4743,7 +4805,7 @@ var ScallopUtils = class {
|
|
|
4743
4805
|
const pythConnection = new import_pyth_sui_js.SuiPriceServiceConnection(endpoint);
|
|
4744
4806
|
try {
|
|
4745
4807
|
const feed = await this.address.cache.queryClient.fetchQuery({
|
|
4746
|
-
queryKey:
|
|
4808
|
+
queryKey: queryKeys.pyth.getPythLatestPriceFeed(priceId),
|
|
4747
4809
|
queryFn: async () => {
|
|
4748
4810
|
return await pythConnection.getLatestPriceFeeds([priceId]);
|
|
4749
4811
|
}
|
|
@@ -6459,7 +6521,7 @@ var ScallopIndexer = class {
|
|
|
6459
6521
|
*/
|
|
6460
6522
|
async getMarket() {
|
|
6461
6523
|
const response = await this.cache.queryClient.fetchQuery({
|
|
6462
|
-
queryKey:
|
|
6524
|
+
queryKey: queryKeys.api.getMarket(),
|
|
6463
6525
|
queryFn: async () => {
|
|
6464
6526
|
return await this._requestClient.get(`/api/market/migrate`);
|
|
6465
6527
|
}
|
|
@@ -6522,7 +6584,7 @@ var ScallopIndexer = class {
|
|
|
6522
6584
|
*/
|
|
6523
6585
|
async getSpools() {
|
|
6524
6586
|
const response = await this.cache.queryClient.fetchQuery({
|
|
6525
|
-
queryKey:
|
|
6587
|
+
queryKey: queryKeys.api.getSpools(),
|
|
6526
6588
|
queryFn: async () => {
|
|
6527
6589
|
return await this._requestClient.get(`/api/spools/migrate`);
|
|
6528
6590
|
}
|
|
@@ -6551,7 +6613,7 @@ var ScallopIndexer = class {
|
|
|
6551
6613
|
*/
|
|
6552
6614
|
async getBorrowIncentivePools() {
|
|
6553
6615
|
const response = await this.cache.queryClient.fetchQuery({
|
|
6554
|
-
queryKey:
|
|
6616
|
+
queryKey: queryKeys.api.getBorrowIncentivePool(),
|
|
6555
6617
|
queryFn: async () => {
|
|
6556
6618
|
return await this._requestClient.get(`/api/borrowIncentivePools/migrate`);
|
|
6557
6619
|
}
|
|
@@ -6592,7 +6654,7 @@ var ScallopIndexer = class {
|
|
|
6592
6654
|
*/
|
|
6593
6655
|
async getTotalValueLocked() {
|
|
6594
6656
|
const response = await this.cache.queryClient.fetchQuery({
|
|
6595
|
-
queryKey:
|
|
6657
|
+
queryKey: queryKeys.api.getTotalValueLocked(),
|
|
6596
6658
|
queryFn: async () => {
|
|
6597
6659
|
return await this._requestClient.get(`/api/market/tvl`);
|
|
6598
6660
|
}
|
|
@@ -7217,6 +7279,18 @@ var ScallopQuery = class {
|
|
|
7217
7279
|
async getPoolSupplyLimit(poolName) {
|
|
7218
7280
|
return await getSupplyLimit(this.utils, poolName);
|
|
7219
7281
|
}
|
|
7282
|
+
/**
|
|
7283
|
+
* Get list of isolated assets
|
|
7284
|
+
*/
|
|
7285
|
+
async getIsolatedAssets() {
|
|
7286
|
+
return await getIsolatedAssets(this.address);
|
|
7287
|
+
}
|
|
7288
|
+
/**
|
|
7289
|
+
* Check if asset is an isolated asset
|
|
7290
|
+
*/
|
|
7291
|
+
async isIsolatedAsset(assetCoinName) {
|
|
7292
|
+
return isIsolatedAsset(this.utils, assetCoinName);
|
|
7293
|
+
}
|
|
7220
7294
|
};
|
|
7221
7295
|
|
|
7222
7296
|
// src/models/scallopBuilder.ts
|
|
@@ -8045,14 +8119,15 @@ var ScallopClient = class {
|
|
|
8045
8119
|
|
|
8046
8120
|
// src/models/scallop.ts
|
|
8047
8121
|
var Scallop = class {
|
|
8048
|
-
constructor(params, cacheOptions, tokenBucket) {
|
|
8122
|
+
constructor(params, cacheOptions, tokenBucket, queryClient) {
|
|
8049
8123
|
this.params = params;
|
|
8050
8124
|
this.suiKit = new import_sui_kit16.SuiKit(params);
|
|
8051
8125
|
this.cache = new ScallopCache(
|
|
8052
8126
|
this.suiKit,
|
|
8053
8127
|
params.walletAddress,
|
|
8054
8128
|
cacheOptions ?? DEFAULT_CACHE_OPTIONS,
|
|
8055
|
-
tokenBucket ?? new TokenBucket(DEFAULT_TOKENS_PER_INTERVAL, DEFAULT_INTERVAL_IN_MS)
|
|
8129
|
+
tokenBucket ?? new TokenBucket(DEFAULT_TOKENS_PER_INTERVAL, DEFAULT_INTERVAL_IN_MS),
|
|
8130
|
+
queryClient
|
|
8056
8131
|
);
|
|
8057
8132
|
this.address = new ScallopAddress(
|
|
8058
8133
|
{
|
|
@@ -8197,6 +8272,7 @@ var Scallop = class {
|
|
|
8197
8272
|
coinDecimals,
|
|
8198
8273
|
coinIds,
|
|
8199
8274
|
marketCoins,
|
|
8275
|
+
queryKeys,
|
|
8200
8276
|
sCoinIds,
|
|
8201
8277
|
sCoins,
|
|
8202
8278
|
spoolRewardCoins,
|