@scallop-io/sui-scallop-sdk 0.46.57 → 0.46.58

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.
@@ -1,2 +1,2 @@
1
- export declare const DEFAULT_TOKENS_PER_INTERVAL = 10;
2
- export declare const DEFAULT_INTERVAL_IN_MS = 1000;
1
+ export declare const DEFAULT_TOKENS_PER_INTERVAL = 50;
2
+ export declare const DEFAULT_INTERVAL_IN_MS = 300;
package/dist/index.js CHANGED
@@ -339,7 +339,7 @@ var import_sui_kit = require("@scallop-io/sui-kit");
339
339
  var DEFAULT_CACHE_OPTIONS = {
340
340
  defaultOptions: {
341
341
  queries: {
342
- staleTime: 1500
342
+ staleTime: 2e3
343
343
  }
344
344
  }
345
345
  };
@@ -888,8 +888,8 @@ var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
888
888
  };
889
889
 
890
890
  // src/constants/tokenBucket.ts
891
- var DEFAULT_TOKENS_PER_INTERVAL = 10;
892
- var DEFAULT_INTERVAL_IN_MS = 1e3;
891
+ var DEFAULT_TOKENS_PER_INTERVAL = 50;
892
+ var DEFAULT_INTERVAL_IN_MS = 300;
893
893
 
894
894
  // src/utils/tokenBucket.ts
895
895
  var TokenBucket = class {
@@ -917,14 +917,31 @@ var TokenBucket = class {
917
917
  return false;
918
918
  }
919
919
  };
920
- var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 5) => {
920
+ var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 15, backoffFactor = 1.25) => {
921
921
  let retries = 0;
922
922
  const tryRequest = async () => {
923
923
  if (tokenBucket.removeTokens(1)) {
924
- return await fn();
924
+ try {
925
+ const result = await fn();
926
+ if (result && result.status === 429) {
927
+ throw new Error("Unexpected status code: 429");
928
+ }
929
+ return result;
930
+ } catch (error) {
931
+ if (error.message === "Unexpected status code: 429" && retries < maxRetries) {
932
+ retries++;
933
+ const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
934
+ await new Promise((resolve) => setTimeout(resolve, delay));
935
+ return tryRequest();
936
+ } else {
937
+ console.error("An error occurred:", error);
938
+ return null;
939
+ }
940
+ }
925
941
  } else if (retries < maxRetries) {
926
942
  retries++;
927
- await new Promise((resolve) => setTimeout(resolve, retryDelayInMs));
943
+ const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
944
+ await new Promise((resolve) => setTimeout(resolve, delay));
928
945
  return tryRequest();
929
946
  } else {
930
947
  console.error("Maximum retries reached");
@@ -936,10 +953,11 @@ var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVA
936
953
 
937
954
  // src/models/scallopCache.ts
938
955
  var ScallopCache = class {
939
- constructor(suiKit, cacheOptions, tokenBucket) {
956
+ constructor(suiKit, walletAddress, cacheOptions, tokenBucket) {
940
957
  this.queryClient = new import_query_core.QueryClient(cacheOptions ?? DEFAULT_CACHE_OPTIONS);
941
958
  this._suiKit = suiKit;
942
959
  this.tokenBucket = tokenBucket ?? new TokenBucket(DEFAULT_TOKENS_PER_INTERVAL, DEFAULT_INTERVAL_IN_MS);
960
+ this.walletAddress = walletAddress ?? suiKit.currentAddress();
943
961
  }
944
962
  get suiKit() {
945
963
  if (!this._suiKit) {
@@ -1029,7 +1047,7 @@ var ScallopCache = class {
1029
1047
  * @returns Promise<SuiObjectResponse>
1030
1048
  */
1031
1049
  async queryGetObject(objectId, options) {
1032
- const queryKey = ["getObject", objectId, this.suiKit.currentAddress()];
1050
+ const queryKey = ["getObject", objectId, this.walletAddress];
1033
1051
  if (options) {
1034
1052
  queryKey.push(JSON.stringify(options));
1035
1053
  }
@@ -1051,13 +1069,15 @@ var ScallopCache = class {
1051
1069
  * @param objectIds
1052
1070
  * @returns Promise<SuiObjectData[]>
1053
1071
  */
1054
- async queryGetObjects(objectIds, options) {
1072
+ async queryGetObjects(objectIds, options = {
1073
+ showContent: true
1074
+ }) {
1055
1075
  if (objectIds.length === 0)
1056
1076
  return [];
1057
1077
  const queryKey = [
1058
1078
  "getObjects",
1059
1079
  JSON.stringify(objectIds),
1060
- this.suiKit.currentAddress()
1080
+ this.walletAddress
1061
1081
  ];
1062
1082
  if (options) {
1063
1083
  queryKey.push(JSON.stringify(options));
@@ -1930,6 +1950,7 @@ var ScallopAddress = class {
1930
1950
  const { id, auth, network } = params;
1931
1951
  this.cache = instance?.cache ?? new ScallopCache(
1932
1952
  instance?.suiKit ?? new import_sui_kit2.SuiKit({}),
1953
+ void 0,
1933
1954
  DEFAULT_CACHE_OPTIONS
1934
1955
  );
1935
1956
  this._requestClient = import_axios.default.create({
@@ -2691,7 +2712,8 @@ var getObligations = async ({
2691
2712
  filter: {
2692
2713
  StructType: `${protocolObjectId}::obligation::ObligationKey`
2693
2714
  },
2694
- cursor: nextCursor
2715
+ cursor: nextCursor,
2716
+ limit: 10
2695
2717
  });
2696
2718
  if (!paginatedKeyObjectsResponse)
2697
2719
  break;
@@ -3005,10 +3027,10 @@ var getStakeAccounts = async ({
3005
3027
  owner,
3006
3028
  filter: { StructType: stakeAccountType },
3007
3029
  options: {
3008
- showContent: true,
3009
- showType: true
3030
+ showContent: true
3010
3031
  },
3011
- cursor: nextCursor
3032
+ cursor: nextCursor,
3033
+ limit: 10
3012
3034
  });
3013
3035
  if (!paginatedStakeObjectsResponse)
3014
3036
  continue;
@@ -3041,7 +3063,10 @@ var getStakeAccounts = async ({
3041
3063
  {}
3042
3064
  );
3043
3065
  const stakeObjectIds = stakeObjectsResponse.map((ref) => ref?.data?.objectId).filter((id) => id !== void 0);
3044
- const stakeObjects = await utils.cache.queryGetObjects(stakeObjectIds);
3066
+ const stakeObjects = await utils.cache.queryGetObjects(stakeObjectIds, {
3067
+ showContent: true,
3068
+ showType: true
3069
+ });
3045
3070
  for (const stakeObject of stakeObjects) {
3046
3071
  const id = stakeObject.objectId;
3047
3072
  const type = stakeObject.type;
@@ -4027,7 +4052,8 @@ var getVescaKeys = async (utils, ownerAddress) => {
4027
4052
  filter: {
4028
4053
  StructType: veScaKeyType
4029
4054
  },
4030
- cursor: nextCursor
4055
+ cursor: nextCursor,
4056
+ limit: 10
4031
4057
  });
4032
4058
  if (!paginatedKeyObjectsResponse)
4033
4059
  continue;
@@ -4274,12 +4300,17 @@ var ScallopUtils = class {
4274
4300
  ...params
4275
4301
  };
4276
4302
  this.suiKit = instance?.suiKit ?? instance?.address?.cache._suiKit ?? new import_sui_kit4.SuiKit(params);
4303
+ this.walletAddress = params.walletAddress ?? this.suiKit.currentAddress();
4277
4304
  if (instance?.address) {
4278
4305
  this.address = instance.address;
4279
4306
  this.cache = this.address.cache;
4280
4307
  this.suiKit = this.address.cache._suiKit;
4281
4308
  } else {
4282
- this.cache = new ScallopCache(this.suiKit, DEFAULT_CACHE_OPTIONS);
4309
+ this.cache = new ScallopCache(
4310
+ this.suiKit,
4311
+ this.walletAddress,
4312
+ DEFAULT_CACHE_OPTIONS
4313
+ );
4283
4314
  this.address = instance?.address ?? new ScallopAddress(
4284
4315
  {
4285
4316
  id: params?.addressesId || ADDRESSES_ID,
@@ -4492,7 +4523,7 @@ var ScallopUtils = class {
4492
4523
  * @param coinType
4493
4524
  * @param sender
4494
4525
  */
4495
- async mergeSimilarCoins(txBlock, dest, coinType, sender) {
4526
+ async mergeSimilarCoins(txBlock, dest, coinType, sender = this.walletAddress) {
4496
4527
  try {
4497
4528
  const existingCoins = await this.selectCoins(
4498
4529
  Number.MAX_SAFE_INTEGER,
@@ -6295,7 +6326,7 @@ var import_sui_kit12 = require("@scallop-io/sui-kit");
6295
6326
  var ScallopIndexer = class {
6296
6327
  constructor(params, instance) {
6297
6328
  this.params = params;
6298
- this.cache = instance?.cache ?? new ScallopCache(new import_sui_kit12.SuiKit({}), DEFAULT_CACHE_OPTIONS);
6329
+ this.cache = instance?.cache ?? new ScallopCache(new import_sui_kit12.SuiKit({}), void 0, DEFAULT_CACHE_OPTIONS);
6299
6330
  this._requestClient = import_axios2.default.create({
6300
6331
  baseURL: SDK_API_BASE_URL,
6301
6332
  headers: {
@@ -6558,12 +6589,19 @@ var ScallopQuery = class {
6558
6589
  constructor(params, instance) {
6559
6590
  this.params = params;
6560
6591
  this.suiKit = instance?.suiKit ?? instance?.utils?.suiKit ?? new import_sui_kit13.SuiKit(params);
6592
+ this.walletAddress = (0, import_utils23.normalizeSuiAddress)(
6593
+ params.walletAddress || this.suiKit.currentAddress()
6594
+ );
6561
6595
  if (instance?.utils) {
6562
6596
  this.utils = instance.utils;
6563
6597
  this.address = instance.utils.address;
6564
6598
  this.cache = this.address.cache;
6565
6599
  } else {
6566
- this.cache = new ScallopCache(this.suiKit, DEFAULT_CACHE_OPTIONS);
6600
+ this.cache = new ScallopCache(
6601
+ this.suiKit,
6602
+ this.walletAddress,
6603
+ DEFAULT_CACHE_OPTIONS
6604
+ );
6567
6605
  this.address = new ScallopAddress(
6568
6606
  {
6569
6607
  id: params?.addressesId || ADDRESSES_ID,
@@ -6578,9 +6616,6 @@ var ScallopQuery = class {
6578
6616
  });
6579
6617
  }
6580
6618
  this.indexer = instance?.indexer ?? new ScallopIndexer(this.params, { cache: this.cache });
6581
- this.walletAddress = (0, import_utils23.normalizeSuiAddress)(
6582
- params.walletAddress || this.suiKit.currentAddress()
6583
- );
6584
6619
  }
6585
6620
  /**
6586
6621
  * Request the scallop API to initialize data.
@@ -7036,7 +7071,11 @@ var ScallopBuilder = class {
7036
7071
  this.address = this.utils.address;
7037
7072
  this.cache = this.address.cache;
7038
7073
  } else {
7039
- this.cache = new ScallopCache(this.suiKit, DEFAULT_CACHE_OPTIONS);
7074
+ this.cache = new ScallopCache(
7075
+ this.suiKit,
7076
+ this.walletAddress,
7077
+ DEFAULT_CACHE_OPTIONS
7078
+ );
7040
7079
  this.address = new ScallopAddress(
7041
7080
  {
7042
7081
  id: params?.addressesId || ADDRESSES_ID,
@@ -7179,7 +7218,11 @@ var ScallopClient = class {
7179
7218
  this.address = this.utils.address;
7180
7219
  this.cache = this.address.cache;
7181
7220
  } else {
7182
- this.cache = new ScallopCache(this.suiKit, DEFAULT_CACHE_OPTIONS);
7221
+ this.cache = new ScallopCache(
7222
+ this.suiKit,
7223
+ this.walletAddress,
7224
+ DEFAULT_CACHE_OPTIONS
7225
+ );
7183
7226
  this.address = new ScallopAddress(
7184
7227
  {
7185
7228
  id: params?.addressesId || ADDRESSES_ID,
@@ -7696,7 +7739,7 @@ var ScallopClient = class {
7696
7739
  * Function to migrate all market coin in user wallet into sCoin
7697
7740
  * @returns Transaction response
7698
7741
  */
7699
- async migrateAllMarketCoin(sign = true) {
7742
+ async migrateAllMarketCoin(includeStakePool = true, sign = true) {
7700
7743
  const txBlock = this.builder.createTxBlock();
7701
7744
  txBlock.setSender(this.walletAddress);
7702
7745
  const toTransfer = [];
@@ -7732,16 +7775,18 @@ var ScallopClient = class {
7732
7775
  );
7733
7776
  sCoins2.push(sCoin);
7734
7777
  }
7735
- if (SUPPORT_SPOOLS.includes(sCoinName)) {
7736
- try {
7737
- const sCoin = await txBlock.unstakeQuick(
7738
- Number.MAX_SAFE_INTEGER,
7739
- sCoinName
7740
- );
7741
- if (sCoin) {
7742
- sCoins2.push(sCoin);
7778
+ if (includeStakePool) {
7779
+ if (SUPPORT_SPOOLS.includes(sCoinName)) {
7780
+ try {
7781
+ const sCoin = await txBlock.unstakeQuick(
7782
+ Number.MAX_SAFE_INTEGER,
7783
+ sCoinName
7784
+ );
7785
+ if (sCoin) {
7786
+ sCoins2.push(sCoin);
7787
+ }
7788
+ } catch (e) {
7743
7789
  }
7744
- } catch (e) {
7745
7790
  }
7746
7791
  }
7747
7792
  if (sCoins2.length > 0) {
@@ -7835,6 +7880,7 @@ var Scallop = class {
7835
7880
  this.suiKit = new import_sui_kit16.SuiKit(params);
7836
7881
  this.cache = new ScallopCache(
7837
7882
  this.suiKit,
7883
+ params.walletAddress,
7838
7884
  cacheOptions ?? DEFAULT_CACHE_OPTIONS,
7839
7885
  tokenBucket ?? new TokenBucket(DEFAULT_TOKENS_PER_INTERVAL, DEFAULT_INTERVAL_IN_MS)
7840
7886
  );