@scallop-io/sui-scallop-sdk 1.3.0-alpha.4 → 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/index.mjs CHANGED
@@ -283,6 +283,93 @@ var FlashLoanFeeObjectMap = {
283
283
  wsol: "0xe84bdb35b790fc7bdd1645122ac6ac0fc904531d6772c9e25904fece322c5f34"
284
284
  };
285
285
 
286
+ // src/constants/queryKeys.ts
287
+ var queryKeys = {
288
+ api: {
289
+ getAddresses: (addressesId) => [
290
+ "api",
291
+ "getAddresses",
292
+ { addressesId }
293
+ ],
294
+ getMarket: () => ["api", "getMarket"],
295
+ getSpools: () => ["api", "getSpools"],
296
+ getBorrowIncentivePool: () => ["api", "getBorrowIncentivePools"],
297
+ getTotalValueLocked: () => ["api", "getTotalValueLocked"]
298
+ },
299
+ rpc: {
300
+ getInspectTxn: (queryTarget, args, typeArgs) => [
301
+ "rpc",
302
+ "getInspectTxn",
303
+ {
304
+ queryTarget,
305
+ args: JSON.stringify(args),
306
+ typeArgs: !typeArgs ? void 0 : JSON.stringify(typeArgs)
307
+ }
308
+ ],
309
+ getObject: (objectId, walletAddress, options) => ["rpc", "getObject", { walletAddress, options, objectId }],
310
+ getObjects: (objectIds, walletAddress, options) => [
311
+ "rpc",
312
+ "getObjects",
313
+ {
314
+ walletAddress,
315
+ options,
316
+ objectIds: JSON.stringify(objectIds ?? [])
317
+ }
318
+ ],
319
+ getOwnedObjects: (input) => [
320
+ "rpc",
321
+ "getOwnedObjects",
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
328
+ }
329
+ ],
330
+ getDynamicFields: (input) => [
331
+ "rpc",
332
+ "getDynamicFields",
333
+ {
334
+ parentId: input.parentId,
335
+ cursor: input.cursor ?? void 0,
336
+ limit: input.limit ?? void 0
337
+ }
338
+ ],
339
+ getDynamicFieldObject: (input) => [
340
+ "rpc",
341
+ "getDynamicFieldObject",
342
+ {
343
+ parentId: input.parentId,
344
+ name: {
345
+ type: input?.name?.type,
346
+ value: input?.name?.value
347
+ }
348
+ }
349
+ ],
350
+ getTotalVeScaTreasuryAmount: (refreshArgs, vescaAmountArgs) => [
351
+ "rpc",
352
+ "getTotalVeScaTreasuryAmount",
353
+ {
354
+ refreshArgs: JSON.stringify(refreshArgs),
355
+ vescaAmountArgs: JSON.stringify(vescaAmountArgs)
356
+ }
357
+ ],
358
+ getAllCoinBalances: (owner) => [
359
+ "rpc",
360
+ "getAllCoinBalances",
361
+ { owner }
362
+ ]
363
+ },
364
+ pyth: {
365
+ getPythLatestPriceFeed: (pythPriceId) => [
366
+ "pyth",
367
+ "getPythPriceId",
368
+ { pythPriceId }
369
+ ]
370
+ }
371
+ };
372
+
286
373
  // src/constants/vesca.ts
287
374
  var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
288
375
  var MAX_LOCK_ROUNDS = 1460;
@@ -300,8 +387,7 @@ import { SuiKit } from "@scallop-io/sui-kit";
300
387
  import { QueryClient } from "@tanstack/query-core";
301
388
  import {
302
389
  SuiTxBlock,
303
- normalizeStructTag as normalizeStructTag2,
304
- normalizeSuiAddress
390
+ normalizeStructTag as normalizeStructTag2
305
391
  } from "@scallop-io/sui-kit";
306
392
 
307
393
  // src/constants/cache.ts
@@ -942,8 +1028,8 @@ async function callMethodWithIndexerFallback(method, context, ...args) {
942
1028
  if (indexer) {
943
1029
  try {
944
1030
  return await method.apply(context, args);
945
- } catch (_e) {
946
- console.warn("Indexer requests failed. Retrying without indexer..");
1031
+ } catch (e) {
1032
+ console.warn(`Indexer requests failed: ${e}. Retrying without indexer..`);
947
1033
  return await method.apply(context, [...args.slice(0, -1), false]);
948
1034
  }
949
1035
  }
@@ -957,8 +1043,8 @@ function withIndexerFallback(method) {
957
1043
 
958
1044
  // src/models/scallopCache.ts
959
1045
  var ScallopCache = class {
960
- constructor(suiKit, walletAddress, cacheOptions, tokenBucket) {
961
- this.queryClient = new QueryClient(cacheOptions ?? DEFAULT_CACHE_OPTIONS);
1046
+ constructor(suiKit, walletAddress, cacheOptions, tokenBucket, queryClient) {
1047
+ this.queryClient = queryClient ?? new QueryClient(cacheOptions ?? DEFAULT_CACHE_OPTIONS);
962
1048
  this._suiKit = suiKit;
963
1049
  this.tokenBucket = tokenBucket ?? new TokenBucket(DEFAULT_TOKENS_PER_INTERVAL, DEFAULT_INTERVAL_IN_MS);
964
1050
  this.walletAddress = walletAddress ?? suiKit.currentAddress();
@@ -986,41 +1072,6 @@ var ScallopCache = class {
986
1072
  refetchType
987
1073
  });
988
1074
  }
989
- async resolveArgs(txb, args) {
990
- return await Promise.all(
991
- args.map(async (arg) => {
992
- if (typeof arg === "string") {
993
- const objData = (await this.queryGetObject(arg, { showOwner: true }))?.data;
994
- if (!objData)
995
- return arg;
996
- const owner = objData?.owner;
997
- if (!owner)
998
- return arg;
999
- if ("Shared" in owner) {
1000
- return txb.sharedObjectRef({
1001
- objectId: objData.objectId,
1002
- initialSharedVersion: owner.Shared.initial_shared_version,
1003
- mutable: true
1004
- });
1005
- } else {
1006
- return txb.objectRef({
1007
- objectId: objData.objectId,
1008
- version: objData.version,
1009
- digest: objData.digest
1010
- });
1011
- }
1012
- } else if ("objectId" in arg && "version" in arg && "digest" in arg) {
1013
- return txb.objectRef({
1014
- objectId: arg.objectId,
1015
- version: arg.version,
1016
- digest: arg.digest
1017
- });
1018
- } else {
1019
- return arg;
1020
- }
1021
- })
1022
- );
1023
- }
1024
1075
  /**
1025
1076
  * @description Provides cache for inspectTxn of the SuiKit.
1026
1077
  * @param QueryInspectTxnParams
@@ -1033,15 +1084,9 @@ var ScallopCache = class {
1033
1084
  typeArgs
1034
1085
  }) {
1035
1086
  const txBlock = new SuiTxBlock();
1036
- const resolvedArgs = await this.resolveArgs(txBlock, args);
1037
- txBlock.moveCall(queryTarget, resolvedArgs, typeArgs);
1087
+ txBlock.moveCall(queryTarget, args, typeArgs);
1038
1088
  const query = await this.queryClient.fetchQuery({
1039
- queryKey: typeArgs ? ["inspectTxn", queryTarget, JSON.stringify(args)] : [
1040
- "inspectTxn",
1041
- queryTarget,
1042
- JSON.stringify(args),
1043
- JSON.stringify(typeArgs)
1044
- ],
1089
+ queryKey: queryKeys.rpc.getInspectTxn(queryTarget, args, typeArgs),
1045
1090
  queryFn: async () => {
1046
1091
  return await callWithRateLimit(
1047
1092
  this.tokenBucket,
@@ -1058,12 +1103,8 @@ var ScallopCache = class {
1058
1103
  * @returns Promise<SuiObjectResponse>
1059
1104
  */
1060
1105
  async queryGetObject(objectId, options) {
1061
- const queryKey = ["getObject", objectId, this.walletAddress];
1062
- if (options) {
1063
- queryKey.push(JSON.stringify(options));
1064
- }
1065
1106
  return this.queryClient.fetchQuery({
1066
- queryKey,
1107
+ queryKey: queryKeys.rpc.getObject(objectId, this.walletAddress, options),
1067
1108
  queryFn: async () => {
1068
1109
  return await callWithRateLimit(
1069
1110
  this.tokenBucket,
@@ -1085,16 +1126,12 @@ var ScallopCache = class {
1085
1126
  }) {
1086
1127
  if (objectIds.length === 0)
1087
1128
  return [];
1088
- const queryKey = [
1089
- "getObjects",
1090
- JSON.stringify(objectIds),
1091
- this.walletAddress
1092
- ];
1093
- if (options) {
1094
- queryKey.push(JSON.stringify(options));
1095
- }
1096
1129
  return this.queryClient.fetchQuery({
1097
- queryKey,
1130
+ queryKey: queryKeys.rpc.getObjects(
1131
+ objectIds,
1132
+ this.walletAddress,
1133
+ options
1134
+ ),
1098
1135
  queryFn: async () => {
1099
1136
  return await callWithRateLimit(
1100
1137
  this.tokenBucket,
@@ -1109,21 +1146,8 @@ var ScallopCache = class {
1109
1146
  * @returns Promise<PaginatedObjectsResponse>
1110
1147
  */
1111
1148
  async queryGetOwnedObjects(input) {
1112
- const queryKey = ["getOwnedObjects", input.owner];
1113
- if (input.cursor) {
1114
- queryKey.push(JSON.stringify(input.cursor));
1115
- }
1116
- if (input.options) {
1117
- queryKey.push(JSON.stringify(input.options));
1118
- }
1119
- if (input.filter) {
1120
- queryKey.push(JSON.stringify(input.filter));
1121
- }
1122
- if (input.limit) {
1123
- queryKey.push(JSON.stringify(input.limit));
1124
- }
1125
1149
  return this.queryClient.fetchQuery({
1126
- queryKey,
1150
+ queryKey: queryKeys.rpc.getOwnedObjects(input),
1127
1151
  queryFn: async () => {
1128
1152
  return await callWithRateLimit(
1129
1153
  this.tokenBucket,
@@ -1133,15 +1157,8 @@ var ScallopCache = class {
1133
1157
  });
1134
1158
  }
1135
1159
  async queryGetDynamicFields(input) {
1136
- const queryKey = ["getDynamicFields", input.parentId];
1137
- if (input.cursor) {
1138
- queryKey.push(JSON.stringify(input.cursor));
1139
- }
1140
- if (input.limit) {
1141
- queryKey.push(JSON.stringify(input.limit));
1142
- }
1143
1160
  return this.queryClient.fetchQuery({
1144
- queryKey,
1161
+ queryKey: queryKeys.rpc.getDynamicFields(input),
1145
1162
  queryFn: async () => {
1146
1163
  return await callWithRateLimit(
1147
1164
  this.tokenBucket,
@@ -1151,14 +1168,8 @@ var ScallopCache = class {
1151
1168
  });
1152
1169
  }
1153
1170
  async queryGetDynamicFieldObject(input) {
1154
- const queryKey = [
1155
- "getDynamicFieldObject",
1156
- input.parentId,
1157
- input.name.type,
1158
- input.name.value
1159
- ];
1160
1171
  return this.queryClient.fetchQuery({
1161
- queryKey,
1172
+ queryKey: queryKeys.rpc.getDynamicFieldObject(input),
1162
1173
  queryFn: async () => {
1163
1174
  return await callWithRateLimit(
1164
1175
  this.tokenBucket,
@@ -1168,9 +1179,8 @@ var ScallopCache = class {
1168
1179
  });
1169
1180
  }
1170
1181
  async queryGetAllCoinBalances(owner) {
1171
- const queryKey = ["getAllCoinBalances", owner];
1172
1182
  return this.queryClient.fetchQuery({
1173
- queryKey,
1183
+ queryKey: queryKeys.rpc.getAllCoinBalances(owner),
1174
1184
  queryFn: async () => {
1175
1185
  const allBalances = await callWithRateLimit(
1176
1186
  this.tokenBucket,
@@ -1187,17 +1197,6 @@ var ScallopCache = class {
1187
1197
  },
1188
1198
  {}
1189
1199
  );
1190
- for (const coinType in balances) {
1191
- const coinBalanceQueryKey = [
1192
- "getCoinBalance",
1193
- normalizeSuiAddress(owner),
1194
- normalizeStructTag2(coinType)
1195
- ];
1196
- this.queryClient.setQueryData(
1197
- coinBalanceQueryKey,
1198
- balances[coinType]
1199
- );
1200
- }
1201
1200
  return balances;
1202
1201
  }
1203
1202
  });
@@ -1205,19 +1204,7 @@ var ScallopCache = class {
1205
1204
  async queryGetCoinBalance(input) {
1206
1205
  if (!input.coinType)
1207
1206
  return "0";
1208
- const queryKey = [
1209
- "getCoinBalance",
1210
- normalizeSuiAddress(input.owner),
1211
- normalizeStructTag2(input.coinType)
1212
- ];
1213
- return this.queryClient.fetchQuery({
1214
- queryKey,
1215
- queryFn: async () => {
1216
- if (!input.coinType)
1217
- return "0";
1218
- return (await this.queryGetAllCoinBalances(input.owner))[normalizeStructTag2(input.coinType)] ?? "0";
1219
- }
1220
- });
1207
+ return (await this.queryGetAllCoinBalances(input.owner) || {})[normalizeStructTag2(input.coinType)] ?? "0";
1221
1208
  }
1222
1209
  };
1223
1210
 
@@ -2151,7 +2138,7 @@ var ScallopAddress = class {
2151
2138
  const addressesId = id || this._id || void 0;
2152
2139
  if (addressesId !== void 0) {
2153
2140
  const response = await this.cache.queryClient.fetchQuery({
2154
- queryKey: ["api-getAddresses", addressesId],
2141
+ queryKey: queryKeys.api.getAddresses(addressesId),
2155
2142
  queryFn: async () => {
2156
2143
  return await this._requestClient.get(`/addresses/${addressesId}`, {
2157
2144
  headers: {
@@ -2277,7 +2264,7 @@ var ScallopAddress = class {
2277
2264
  };
2278
2265
 
2279
2266
  // src/models/scallopClient.ts
2280
- import { normalizeSuiAddress as normalizeSuiAddress4 } from "@mysten/sui/utils";
2267
+ import { normalizeSuiAddress as normalizeSuiAddress3 } from "@mysten/sui/utils";
2281
2268
  import { SuiKit as SuiKit6 } from "@scallop-io/sui-kit";
2282
2269
 
2283
2270
  // src/models/scallopUtils.ts
@@ -4252,10 +4239,10 @@ var getTotalVeScaTreasuryAmount = async (utils, veScaTreasury) => {
4252
4239
  onlyTransactionKind: true
4253
4240
  });
4254
4241
  const res = await utils.cache.queryClient.fetchQuery({
4255
- queryKey: [
4256
- "getTotalVeScaTreasuryAmount",
4257
- JSON.stringify([...refreshArgs, ...veScaAmountArgs])
4258
- ],
4242
+ queryKey: queryKeys.rpc.getTotalVeScaTreasuryAmount(
4243
+ refreshArgs,
4244
+ veScaAmountArgs
4245
+ ),
4259
4246
  queryFn: async () => {
4260
4247
  return await utils.suiKit.inspectTxn(txBytes);
4261
4248
  }
@@ -4739,7 +4726,7 @@ var ScallopUtils = class {
4739
4726
  const pythConnection = new SuiPriceServiceConnection(endpoint);
4740
4727
  try {
4741
4728
  const feed = await this.address.cache.queryClient.fetchQuery({
4742
- queryKey: [priceId],
4729
+ queryKey: queryKeys.pyth.getPythLatestPriceFeed(priceId),
4743
4730
  queryFn: async () => {
4744
4731
  return await pythConnection.getLatestPriceFeeds([priceId]);
4745
4732
  }
@@ -4833,7 +4820,7 @@ var ScallopUtils = class {
4833
4820
  };
4834
4821
 
4835
4822
  // src/models/scallopBuilder.ts
4836
- import { normalizeSuiAddress as normalizeSuiAddress3 } from "@mysten/sui/utils";
4823
+ import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui/utils";
4837
4824
  import { SuiKit as SuiKit5 } from "@scallop-io/sui-kit";
4838
4825
 
4839
4826
  // src/builders/coreBuilder.ts
@@ -6466,7 +6453,7 @@ var ScallopIndexer = class {
6466
6453
  */
6467
6454
  async getMarket() {
6468
6455
  const response = await this.cache.queryClient.fetchQuery({
6469
- queryKey: ["market"],
6456
+ queryKey: queryKeys.api.getMarket(),
6470
6457
  queryFn: async () => {
6471
6458
  return await this._requestClient.get(`/api/market/migrate`);
6472
6459
  }
@@ -6529,7 +6516,7 @@ var ScallopIndexer = class {
6529
6516
  */
6530
6517
  async getSpools() {
6531
6518
  const response = await this.cache.queryClient.fetchQuery({
6532
- queryKey: ["spools"],
6519
+ queryKey: queryKeys.api.getSpools(),
6533
6520
  queryFn: async () => {
6534
6521
  return await this._requestClient.get(`/api/spools/migrate`);
6535
6522
  }
@@ -6558,7 +6545,7 @@ var ScallopIndexer = class {
6558
6545
  */
6559
6546
  async getBorrowIncentivePools() {
6560
6547
  const response = await this.cache.queryClient.fetchQuery({
6561
- queryKey: ["borrowIncentivePools"],
6548
+ queryKey: queryKeys.api.getBorrowIncentivePool(),
6562
6549
  queryFn: async () => {
6563
6550
  return await this._requestClient.get(`/api/borrowIncentivePools/migrate`);
6564
6551
  }
@@ -6599,7 +6586,7 @@ var ScallopIndexer = class {
6599
6586
  */
6600
6587
  async getTotalValueLocked() {
6601
6588
  const response = await this.cache.queryClient.fetchQuery({
6602
- queryKey: ["totalValueLocked"],
6589
+ queryKey: queryKeys.api.getTotalValueLocked(),
6603
6590
  queryFn: async () => {
6604
6591
  return await this._requestClient.get(`/api/market/tvl`);
6605
6592
  }
@@ -6706,12 +6693,12 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
6706
6693
  };
6707
6694
 
6708
6695
  // src/models/scallopQuery.ts
6709
- import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui/utils";
6696
+ import { normalizeSuiAddress } from "@mysten/sui/utils";
6710
6697
  var ScallopQuery = class {
6711
6698
  constructor(params, instance) {
6712
6699
  this.params = params;
6713
6700
  this.suiKit = instance?.suiKit ?? instance?.utils?.suiKit ?? new SuiKit4(params);
6714
- this.walletAddress = normalizeSuiAddress2(
6701
+ this.walletAddress = normalizeSuiAddress(
6715
6702
  params.walletAddress || this.suiKit.currentAddress()
6716
6703
  );
6717
6704
  if (instance?.utils) {
@@ -7244,7 +7231,7 @@ var ScallopBuilder = class {
7244
7231
  constructor(params, instance) {
7245
7232
  this.suiKit = instance?.suiKit ?? new SuiKit5(params);
7246
7233
  this.params = params;
7247
- this.walletAddress = normalizeSuiAddress3(
7234
+ this.walletAddress = normalizeSuiAddress2(
7248
7235
  params?.walletAddress || this.suiKit.currentAddress()
7249
7236
  );
7250
7237
  if (instance?.query) {
@@ -7394,7 +7381,7 @@ var ScallopClient = class {
7394
7381
  constructor(params, instance) {
7395
7382
  this.params = params;
7396
7383
  this.suiKit = instance?.suiKit ?? instance?.builder?.suiKit ?? new SuiKit6(params);
7397
- this.walletAddress = normalizeSuiAddress4(
7384
+ this.walletAddress = normalizeSuiAddress3(
7398
7385
  params?.walletAddress || this.suiKit.currentAddress()
7399
7386
  );
7400
7387
  if (instance?.builder) {
@@ -8064,14 +8051,15 @@ var ScallopClient = class {
8064
8051
 
8065
8052
  // src/models/scallop.ts
8066
8053
  var Scallop = class {
8067
- constructor(params, cacheOptions, tokenBucket) {
8054
+ constructor(params, cacheOptions, tokenBucket, queryClient) {
8068
8055
  this.params = params;
8069
8056
  this.suiKit = new SuiKit7(params);
8070
8057
  this.cache = new ScallopCache(
8071
8058
  this.suiKit,
8072
8059
  params.walletAddress,
8073
8060
  cacheOptions ?? DEFAULT_CACHE_OPTIONS,
8074
- tokenBucket ?? new TokenBucket(DEFAULT_TOKENS_PER_INTERVAL, DEFAULT_INTERVAL_IN_MS)
8061
+ tokenBucket ?? new TokenBucket(DEFAULT_TOKENS_PER_INTERVAL, DEFAULT_INTERVAL_IN_MS),
8062
+ queryClient
8075
8063
  );
8076
8064
  this.address = new ScallopAddress(
8077
8065
  {
@@ -8215,6 +8203,7 @@ export {
8215
8203
  coinDecimals,
8216
8204
  coinIds,
8217
8205
  marketCoins,
8206
+ queryKeys,
8218
8207
  sCoinIds,
8219
8208
  sCoins,
8220
8209
  spoolRewardCoins,