@scallop-io/sui-scallop-sdk 0.46.57 → 0.46.58-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/tokenBucket.d.ts +2 -2
- package/dist/index.js +69 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -25
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopCache.d.ts +2 -1
- package/dist/models/scallopUtils.d.ts +2 -1
- package/dist/utils/tokenBucket.d.ts +1 -1
- package/package.json +1 -1
- package/src/constants/cache.ts +1 -1
- package/src/constants/tokenBucket.ts +2 -2
- package/src/models/scallop.ts +1 -0
- package/src/models/scallopAddress.ts +1 -0
- package/src/models/scallopBuilder.ts +5 -1
- package/src/models/scallopCache.ts +8 -3
- package/src/models/scallopClient.ts +5 -1
- package/src/models/scallopIndexer.ts +1 -1
- package/src/models/scallopQuery.ts +10 -5
- package/src/models/scallopUtils.ts +9 -2
- package/src/queries/coreQuery.ts +1 -0
- package/src/queries/spoolQuery.ts +5 -2
- package/src/queries/vescaQuery.ts +1 -0
- package/src/utils/tokenBucket.ts +29 -5
package/dist/index.mjs
CHANGED
|
@@ -265,7 +265,7 @@ import {
|
|
|
265
265
|
var DEFAULT_CACHE_OPTIONS = {
|
|
266
266
|
defaultOptions: {
|
|
267
267
|
queries: {
|
|
268
|
-
staleTime:
|
|
268
|
+
staleTime: 2e3
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
};
|
|
@@ -814,8 +814,8 @@ var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
|
|
|
814
814
|
};
|
|
815
815
|
|
|
816
816
|
// src/constants/tokenBucket.ts
|
|
817
|
-
var DEFAULT_TOKENS_PER_INTERVAL =
|
|
818
|
-
var DEFAULT_INTERVAL_IN_MS =
|
|
817
|
+
var DEFAULT_TOKENS_PER_INTERVAL = 50;
|
|
818
|
+
var DEFAULT_INTERVAL_IN_MS = 300;
|
|
819
819
|
|
|
820
820
|
// src/utils/tokenBucket.ts
|
|
821
821
|
var TokenBucket = class {
|
|
@@ -843,14 +843,31 @@ var TokenBucket = class {
|
|
|
843
843
|
return false;
|
|
844
844
|
}
|
|
845
845
|
};
|
|
846
|
-
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries =
|
|
846
|
+
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 15, backoffFactor = 1.25) => {
|
|
847
847
|
let retries = 0;
|
|
848
848
|
const tryRequest = async () => {
|
|
849
849
|
if (tokenBucket.removeTokens(1)) {
|
|
850
|
-
|
|
850
|
+
try {
|
|
851
|
+
const result = await fn();
|
|
852
|
+
if (result && result.status === 429) {
|
|
853
|
+
throw new Error("Unexpected status code: 429");
|
|
854
|
+
}
|
|
855
|
+
return result;
|
|
856
|
+
} catch (error) {
|
|
857
|
+
if (error.message === "Unexpected status code: 429" && retries < maxRetries) {
|
|
858
|
+
retries++;
|
|
859
|
+
const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
|
|
860
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
861
|
+
return tryRequest();
|
|
862
|
+
} else {
|
|
863
|
+
console.error("An error occurred:", error);
|
|
864
|
+
return null;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
851
867
|
} else if (retries < maxRetries) {
|
|
852
868
|
retries++;
|
|
853
|
-
|
|
869
|
+
const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
|
|
870
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
854
871
|
return tryRequest();
|
|
855
872
|
} else {
|
|
856
873
|
console.error("Maximum retries reached");
|
|
@@ -862,10 +879,11 @@ var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVA
|
|
|
862
879
|
|
|
863
880
|
// src/models/scallopCache.ts
|
|
864
881
|
var ScallopCache = class {
|
|
865
|
-
constructor(suiKit, cacheOptions, tokenBucket) {
|
|
882
|
+
constructor(suiKit, walletAddress, cacheOptions, tokenBucket) {
|
|
866
883
|
this.queryClient = new QueryClient(cacheOptions ?? DEFAULT_CACHE_OPTIONS);
|
|
867
884
|
this._suiKit = suiKit;
|
|
868
885
|
this.tokenBucket = tokenBucket ?? new TokenBucket(DEFAULT_TOKENS_PER_INTERVAL, DEFAULT_INTERVAL_IN_MS);
|
|
886
|
+
this.walletAddress = walletAddress ?? suiKit.currentAddress();
|
|
869
887
|
}
|
|
870
888
|
get suiKit() {
|
|
871
889
|
if (!this._suiKit) {
|
|
@@ -955,7 +973,7 @@ var ScallopCache = class {
|
|
|
955
973
|
* @returns Promise<SuiObjectResponse>
|
|
956
974
|
*/
|
|
957
975
|
async queryGetObject(objectId, options) {
|
|
958
|
-
const queryKey = ["getObject", objectId, this.
|
|
976
|
+
const queryKey = ["getObject", objectId, this.walletAddress];
|
|
959
977
|
if (options) {
|
|
960
978
|
queryKey.push(JSON.stringify(options));
|
|
961
979
|
}
|
|
@@ -977,13 +995,15 @@ var ScallopCache = class {
|
|
|
977
995
|
* @param objectIds
|
|
978
996
|
* @returns Promise<SuiObjectData[]>
|
|
979
997
|
*/
|
|
980
|
-
async queryGetObjects(objectIds, options
|
|
998
|
+
async queryGetObjects(objectIds, options = {
|
|
999
|
+
showContent: true
|
|
1000
|
+
}) {
|
|
981
1001
|
if (objectIds.length === 0)
|
|
982
1002
|
return [];
|
|
983
1003
|
const queryKey = [
|
|
984
1004
|
"getObjects",
|
|
985
1005
|
JSON.stringify(objectIds),
|
|
986
|
-
this.
|
|
1006
|
+
this.walletAddress
|
|
987
1007
|
];
|
|
988
1008
|
if (options) {
|
|
989
1009
|
queryKey.push(JSON.stringify(options));
|
|
@@ -1856,6 +1876,7 @@ var ScallopAddress = class {
|
|
|
1856
1876
|
const { id, auth, network } = params;
|
|
1857
1877
|
this.cache = instance?.cache ?? new ScallopCache(
|
|
1858
1878
|
instance?.suiKit ?? new SuiKit({}),
|
|
1879
|
+
void 0,
|
|
1859
1880
|
DEFAULT_CACHE_OPTIONS
|
|
1860
1881
|
);
|
|
1861
1882
|
this._requestClient = axios.create({
|
|
@@ -2617,7 +2638,8 @@ var getObligations = async ({
|
|
|
2617
2638
|
filter: {
|
|
2618
2639
|
StructType: `${protocolObjectId}::obligation::ObligationKey`
|
|
2619
2640
|
},
|
|
2620
|
-
cursor: nextCursor
|
|
2641
|
+
cursor: nextCursor,
|
|
2642
|
+
limit: 10
|
|
2621
2643
|
});
|
|
2622
2644
|
if (!paginatedKeyObjectsResponse)
|
|
2623
2645
|
break;
|
|
@@ -2931,10 +2953,10 @@ var getStakeAccounts = async ({
|
|
|
2931
2953
|
owner,
|
|
2932
2954
|
filter: { StructType: stakeAccountType },
|
|
2933
2955
|
options: {
|
|
2934
|
-
showContent: true
|
|
2935
|
-
showType: true
|
|
2956
|
+
showContent: true
|
|
2936
2957
|
},
|
|
2937
|
-
cursor: nextCursor
|
|
2958
|
+
cursor: nextCursor,
|
|
2959
|
+
limit: 10
|
|
2938
2960
|
});
|
|
2939
2961
|
if (!paginatedStakeObjectsResponse)
|
|
2940
2962
|
continue;
|
|
@@ -2967,7 +2989,10 @@ var getStakeAccounts = async ({
|
|
|
2967
2989
|
{}
|
|
2968
2990
|
);
|
|
2969
2991
|
const stakeObjectIds = stakeObjectsResponse.map((ref) => ref?.data?.objectId).filter((id) => id !== void 0);
|
|
2970
|
-
const stakeObjects = await utils.cache.queryGetObjects(stakeObjectIds
|
|
2992
|
+
const stakeObjects = await utils.cache.queryGetObjects(stakeObjectIds, {
|
|
2993
|
+
showContent: true,
|
|
2994
|
+
showType: true
|
|
2995
|
+
});
|
|
2971
2996
|
for (const stakeObject of stakeObjects) {
|
|
2972
2997
|
const id = stakeObject.objectId;
|
|
2973
2998
|
const type = stakeObject.type;
|
|
@@ -3953,7 +3978,8 @@ var getVescaKeys = async (utils, ownerAddress) => {
|
|
|
3953
3978
|
filter: {
|
|
3954
3979
|
StructType: veScaKeyType
|
|
3955
3980
|
},
|
|
3956
|
-
cursor: nextCursor
|
|
3981
|
+
cursor: nextCursor,
|
|
3982
|
+
limit: 10
|
|
3957
3983
|
});
|
|
3958
3984
|
if (!paginatedKeyObjectsResponse)
|
|
3959
3985
|
continue;
|
|
@@ -4200,12 +4226,17 @@ var ScallopUtils = class {
|
|
|
4200
4226
|
...params
|
|
4201
4227
|
};
|
|
4202
4228
|
this.suiKit = instance?.suiKit ?? instance?.address?.cache._suiKit ?? new SuiKit2(params);
|
|
4229
|
+
this.walletAddress = params.walletAddress ?? this.suiKit.currentAddress();
|
|
4203
4230
|
if (instance?.address) {
|
|
4204
4231
|
this.address = instance.address;
|
|
4205
4232
|
this.cache = this.address.cache;
|
|
4206
4233
|
this.suiKit = this.address.cache._suiKit;
|
|
4207
4234
|
} else {
|
|
4208
|
-
this.cache = new ScallopCache(
|
|
4235
|
+
this.cache = new ScallopCache(
|
|
4236
|
+
this.suiKit,
|
|
4237
|
+
this.walletAddress,
|
|
4238
|
+
DEFAULT_CACHE_OPTIONS
|
|
4239
|
+
);
|
|
4209
4240
|
this.address = instance?.address ?? new ScallopAddress(
|
|
4210
4241
|
{
|
|
4211
4242
|
id: params?.addressesId || ADDRESSES_ID,
|
|
@@ -4418,7 +4449,7 @@ var ScallopUtils = class {
|
|
|
4418
4449
|
* @param coinType
|
|
4419
4450
|
* @param sender
|
|
4420
4451
|
*/
|
|
4421
|
-
async mergeSimilarCoins(txBlock, dest, coinType, sender) {
|
|
4452
|
+
async mergeSimilarCoins(txBlock, dest, coinType, sender = this.walletAddress) {
|
|
4422
4453
|
try {
|
|
4423
4454
|
const existingCoins = await this.selectCoins(
|
|
4424
4455
|
Number.MAX_SAFE_INTEGER,
|
|
@@ -6235,7 +6266,7 @@ import { SuiKit as SuiKit3 } from "@scallop-io/sui-kit";
|
|
|
6235
6266
|
var ScallopIndexer = class {
|
|
6236
6267
|
constructor(params, instance) {
|
|
6237
6268
|
this.params = params;
|
|
6238
|
-
this.cache = instance?.cache ?? new ScallopCache(new SuiKit3({}), DEFAULT_CACHE_OPTIONS);
|
|
6269
|
+
this.cache = instance?.cache ?? new ScallopCache(new SuiKit3({}), void 0, DEFAULT_CACHE_OPTIONS);
|
|
6239
6270
|
this._requestClient = axios2.create({
|
|
6240
6271
|
baseURL: SDK_API_BASE_URL,
|
|
6241
6272
|
headers: {
|
|
@@ -6498,12 +6529,19 @@ var ScallopQuery = class {
|
|
|
6498
6529
|
constructor(params, instance) {
|
|
6499
6530
|
this.params = params;
|
|
6500
6531
|
this.suiKit = instance?.suiKit ?? instance?.utils?.suiKit ?? new SuiKit4(params);
|
|
6532
|
+
this.walletAddress = normalizeSuiAddress2(
|
|
6533
|
+
params.walletAddress || this.suiKit.currentAddress()
|
|
6534
|
+
);
|
|
6501
6535
|
if (instance?.utils) {
|
|
6502
6536
|
this.utils = instance.utils;
|
|
6503
6537
|
this.address = instance.utils.address;
|
|
6504
6538
|
this.cache = this.address.cache;
|
|
6505
6539
|
} else {
|
|
6506
|
-
this.cache = new ScallopCache(
|
|
6540
|
+
this.cache = new ScallopCache(
|
|
6541
|
+
this.suiKit,
|
|
6542
|
+
this.walletAddress,
|
|
6543
|
+
DEFAULT_CACHE_OPTIONS
|
|
6544
|
+
);
|
|
6507
6545
|
this.address = new ScallopAddress(
|
|
6508
6546
|
{
|
|
6509
6547
|
id: params?.addressesId || ADDRESSES_ID,
|
|
@@ -6518,9 +6556,6 @@ var ScallopQuery = class {
|
|
|
6518
6556
|
});
|
|
6519
6557
|
}
|
|
6520
6558
|
this.indexer = instance?.indexer ?? new ScallopIndexer(this.params, { cache: this.cache });
|
|
6521
|
-
this.walletAddress = normalizeSuiAddress2(
|
|
6522
|
-
params.walletAddress || this.suiKit.currentAddress()
|
|
6523
|
-
);
|
|
6524
6559
|
}
|
|
6525
6560
|
/**
|
|
6526
6561
|
* Request the scallop API to initialize data.
|
|
@@ -6976,7 +7011,11 @@ var ScallopBuilder = class {
|
|
|
6976
7011
|
this.address = this.utils.address;
|
|
6977
7012
|
this.cache = this.address.cache;
|
|
6978
7013
|
} else {
|
|
6979
|
-
this.cache = new ScallopCache(
|
|
7014
|
+
this.cache = new ScallopCache(
|
|
7015
|
+
this.suiKit,
|
|
7016
|
+
this.walletAddress,
|
|
7017
|
+
DEFAULT_CACHE_OPTIONS
|
|
7018
|
+
);
|
|
6980
7019
|
this.address = new ScallopAddress(
|
|
6981
7020
|
{
|
|
6982
7021
|
id: params?.addressesId || ADDRESSES_ID,
|
|
@@ -7119,7 +7158,11 @@ var ScallopClient = class {
|
|
|
7119
7158
|
this.address = this.utils.address;
|
|
7120
7159
|
this.cache = this.address.cache;
|
|
7121
7160
|
} else {
|
|
7122
|
-
this.cache = new ScallopCache(
|
|
7161
|
+
this.cache = new ScallopCache(
|
|
7162
|
+
this.suiKit,
|
|
7163
|
+
this.walletAddress,
|
|
7164
|
+
DEFAULT_CACHE_OPTIONS
|
|
7165
|
+
);
|
|
7123
7166
|
this.address = new ScallopAddress(
|
|
7124
7167
|
{
|
|
7125
7168
|
id: params?.addressesId || ADDRESSES_ID,
|
|
@@ -7775,6 +7818,7 @@ var Scallop = class {
|
|
|
7775
7818
|
this.suiKit = new SuiKit7(params);
|
|
7776
7819
|
this.cache = new ScallopCache(
|
|
7777
7820
|
this.suiKit,
|
|
7821
|
+
params.walletAddress,
|
|
7778
7822
|
cacheOptions ?? DEFAULT_CACHE_OPTIONS,
|
|
7779
7823
|
tokenBucket ?? new TokenBucket(DEFAULT_TOKENS_PER_INTERVAL, DEFAULT_INTERVAL_IN_MS)
|
|
7780
7824
|
);
|