@zebec-network/zebec-stake-sdk 1.0.4 → 1.0.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/README.md CHANGED
@@ -1 +1,19 @@
1
1
  # ZBCN Stake Sdk
2
+
3
+ ## Installation
4
+
5
+ ```
6
+ yarn add @zebec-network/zebec-stake-sdk
7
+ ```
8
+
9
+ ```
10
+ npm install @zebec-network/zebec-stake-sdk
11
+ ```
12
+
13
+ ## Development
14
+
15
+ To build the package
16
+
17
+ ```
18
+ yarn build
19
+ ```
package/dist/service.d.ts CHANGED
@@ -71,9 +71,18 @@ export declare class StakeService {
71
71
  getLockupInfo(lockupAddress: Address): Promise<LockupInfo | null>;
72
72
  getStakeInfo(stakeAddress: Address, lockupAddress: Address): Promise<StakeInfo | null>;
73
73
  getUserNonceInfo(userNonceAddress: Address): Promise<UserNonceInfo | null>;
74
- getAllStakesInfo(userAdress: Address, lockupAddress: Address): Promise<(StakeInfo & {
74
+ getAllStakesInfo(userAdress: Address, lockupAddress: Address): Promise<{
75
+ address: string;
76
+ nonce: bigint;
77
+ createdTime: number;
78
+ stakedAmount: string;
79
+ rewardAmount: string;
80
+ stakeClaimed: boolean;
81
+ lockPeriod: number;
82
+ staker: string;
83
+ lockup: string;
75
84
  hash: string;
76
- })[]>;
85
+ }[]>;
77
86
  getTotalStakeCount(lockupAddress: Address): Promise<number>;
78
87
  }
79
88
  export type InitLockupInstructionData = {
package/dist/service.js CHANGED
@@ -14,6 +14,7 @@ const artifacts_1 = require("./artifacts");
14
14
  const constants_1 = require("./constants");
15
15
  const pda_1 = require("./pda");
16
16
  const providers_1 = require("./providers");
17
+ const utils_1 = require("./utils");
17
18
  /**
18
19
  * StakeServiceBuilder is a builder class for creating a StakeService instance.
19
20
  * It allows you to set the network, provider, and program to use.
@@ -357,8 +358,10 @@ class StakeService {
357
358
  };
358
359
  return info;
359
360
  });
361
+ // Your mapping with exponential backoff applied to the API call.
360
362
  const promises = stakeAccountsInfo.map(async (stakeInfo) => {
361
- const signatures = await this.provider.connection.getSignaturesForAddress((0, anchor_1.translateAddress)(stakeInfo.address), {}, "finalized");
363
+ // Wrap the asynchronous call with our exponential backoff helper.
364
+ const signatures = await (0, utils_1.callWithExponentialBackoff)(async () => this.provider.connection.getSignaturesForAddress((0, anchor_1.translateAddress)(stakeInfo.address), {}, "finalized"));
362
365
  const stakeSignatures = signatures.filter((s) => {
363
366
  return !s.err && (s.blockTime ?? 0) === stakeInfo.createdTime;
364
367
  });
@@ -0,0 +1 @@
1
+ export declare function callWithExponentialBackoff<T>(fn: () => T, attemptsLeft?: number, delay?: number): Promise<T>;
package/dist/utils.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.callWithExponentialBackoff = callWithExponentialBackoff;
4
+ // Set your backoff parameters
5
+ const MAX_ATTEMPTS = 5;
6
+ const INITIAL_DELAY = 100; // in milliseconds
7
+ const BACKOFF_FACTOR = 2;
8
+ // Helper function that wraps an async operation with exponential backoff.
9
+ async function callWithExponentialBackoff(fn, attemptsLeft = MAX_ATTEMPTS, delay = INITIAL_DELAY) {
10
+ try {
11
+ return await fn();
12
+ }
13
+ catch (error) {
14
+ if (attemptsLeft === 1) {
15
+ // If no attempts remain, rethrow the error.
16
+ throw error;
17
+ }
18
+ console.warn(`Error encountered: ${error instanceof Error ? error.message : "Unknown error"}. Retrying in ${delay} ms... (${attemptsLeft - 1} attempts left)`);
19
+ // Wait for the delay period.
20
+ await new Promise((resolve) => setTimeout(resolve, delay));
21
+ // Try again with one fewer attempt and an exponentially increased delay.
22
+ return callWithExponentialBackoff(fn, attemptsLeft - 1, delay * BACKOFF_FACTOR);
23
+ }
24
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zebec-network/zebec-stake-sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "An SDK for zebec network stake solana program",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -21,7 +21,7 @@
21
21
  "clean": "rimraf ./dist",
22
22
  "format": "prettier --write .",
23
23
  "start": "ts-node src/index.ts",
24
- "test": "ts-mocha -p ./tsconfig.json -t 1000000"
24
+ "test": "ts-mocha -p ./tsconfig.json -t 1000000000"
25
25
  },
26
26
  "dependencies": {
27
27
  "@coral-xyz/anchor": "^0.31.1",