@zebec-network/zebec-stake-sdk 1.0.11 → 1.0.13
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/service.js +36 -31
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +8 -0
- package/package.json +2 -2
package/dist/service.js
CHANGED
|
@@ -340,37 +340,42 @@ class StakeService {
|
|
|
340
340
|
const currentNonce = userNonceAccount.nonce.toNumber();
|
|
341
341
|
const nonces = Array.from({ length: currentNonce }, (_, i) => BigInt(i));
|
|
342
342
|
const stakeAddresses = nonces.map((nonce) => (0, pda_1.deriveStakeAddress)(userAdress, lockupAddress, nonce, this.programId));
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const
|
|
350
|
-
address: stakeAddresses[i]
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
343
|
+
const stakeAddressesChunks = (0, utils_1.chunkArray)(stakeAddresses, 100);
|
|
344
|
+
let stakeWithHash2D = [];
|
|
345
|
+
for (const stakeAddresses of stakeAddressesChunks) {
|
|
346
|
+
const accountInfos = await this.connection.getMultipleAccountsInfo(stakeAddresses, {
|
|
347
|
+
commitment: this.connection.commitment,
|
|
348
|
+
});
|
|
349
|
+
const stakeAccountsInfo = accountInfos.map((value, i) => {
|
|
350
|
+
(0, assert_1.default)(value, "Account does not exists for stake address: " + stakeAddresses[i] + " at nonce: " + nonces[i]);
|
|
351
|
+
const stakeAccount = this.program.coder.accounts.decode(this.program.idl.accounts[2].name, value.data);
|
|
352
|
+
const info = {
|
|
353
|
+
address: stakeAddresses[i].toString(),
|
|
354
|
+
nonce: BigInt(stakeAccount.nonce.toString()),
|
|
355
|
+
createdTime: stakeAccount.createdTime.toNumber(),
|
|
356
|
+
stakedAmount: (0, bignumber_js_1.BigNumber)(stakeAccount.stakedAmount.toString()).div(UNITS_PER_STAKE_TOKEN).toFixed(),
|
|
357
|
+
rewardAmount: (0, bignumber_js_1.BigNumber)(stakeAccount.rewardAmount.toString()).div(UNITS_PER_REWARD_TOKEN).toFixed(),
|
|
358
|
+
stakeClaimed: stakeAccount.stakeClaimed,
|
|
359
|
+
lockPeriod: stakeAccount.lockPeriod.toNumber(),
|
|
360
|
+
lockup: stakeAccount.lockup.toString(),
|
|
361
|
+
staker: stakeAccount.staker.toString(),
|
|
362
|
+
};
|
|
363
|
+
return info;
|
|
364
|
+
});
|
|
365
|
+
let stakesWithHash = new Array(stakeAccountsInfo.length);
|
|
366
|
+
const { maxConcurrent = 3, minDelayMs = 400 } = options;
|
|
367
|
+
const queue = new rateLimitQueue_1.RateLimitedQueue(maxConcurrent, minDelayMs); // Max 3 concurrent, 300ms between requests
|
|
368
|
+
const promises = stakeAccountsInfo.map((stakeInfo, index) => queue.add(async () => {
|
|
369
|
+
const signature = await this.getStakeSignatureForStake(stakeInfo);
|
|
370
|
+
stakesWithHash[index] = {
|
|
371
|
+
hash: signature ? signature : "",
|
|
372
|
+
...stakeInfo,
|
|
373
|
+
};
|
|
374
|
+
}));
|
|
375
|
+
await Promise.all(promises);
|
|
376
|
+
stakeWithHash2D.push(stakesWithHash);
|
|
377
|
+
}
|
|
378
|
+
return stakeWithHash2D.flat();
|
|
374
379
|
}
|
|
375
380
|
async getAllStakesCount(lockupAddress) {
|
|
376
381
|
const dataSize = this.program.account.userStakeData.size;
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.callWithEnhancedBackoff = callWithEnhancedBackoff;
|
|
4
|
+
exports.chunkArray = chunkArray;
|
|
4
5
|
const core_utils_1 = require("@zebec-network/core-utils");
|
|
5
6
|
// Set your backoff parameters
|
|
6
7
|
const MAX_RETRIES = 5;
|
|
@@ -29,3 +30,10 @@ async function callWithEnhancedBackoff(fn, maxRetries = MAX_RETRIES, backoffFact
|
|
|
29
30
|
}
|
|
30
31
|
throw new Error("Max retries exceeded");
|
|
31
32
|
}
|
|
33
|
+
function chunkArray(arr, size) {
|
|
34
|
+
const result = [];
|
|
35
|
+
for (let i = 0; i < arr.length; i += size) {
|
|
36
|
+
result.push(arr.slice(i, i + size));
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zebec-network/zebec-stake-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "An SDK for zebec network stake solana program",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@coral-xyz/anchor": "^0.31.1",
|
|
29
29
|
"@solana/web3.js": "1.98.2",
|
|
30
30
|
"@zebec-network/core-utils": "^1.0.4",
|
|
31
|
-
"@zebec-network/solana-common": "
|
|
31
|
+
"@zebec-network/solana-common": "1.5.1",
|
|
32
32
|
"bignumber.js": "^9.3.0",
|
|
33
33
|
"buffer": "^6.0.3",
|
|
34
34
|
"dotenv": "^16.5.0"
|