diff --git a/package.json b/package.json index d55c6d2..a9b62b4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zkbob-client-js", - "version": "5.5.0", + "version": "5.5.1", "description": "zkBob integration library", "repository": "git@github.com:zkBob/libzkbob-client-js.git", "author": "Dmitry Vdovin ", @@ -37,8 +37,7 @@ "tronweb": "^5.3.0", "wasm-feature-detect": "^1.2.11", "web3": "1.8.0", - "web3-utils": "1.8.0", - "promise-retry": "^2.0.1" + "web3-utils": "1.8.0" }, "devDependencies": { "@types/ethereum-protocol": "^1.0.1", diff --git a/src/client-provider.ts b/src/client-provider.ts index 73226d9..5a39642 100644 --- a/src/client-provider.ts +++ b/src/client-provider.ts @@ -379,14 +379,14 @@ export class ZkBobProvider { // Convert native pool amount to the base units public async shieldedAmountToWei(amountShielded: bigint): Promise { - const denominator = await this.denominator(); - return denominator > 0 ? amountShielded * denominator : amountShielded / (-denominator); + const denominator = BigInt(await this.denominator()); + return denominator > 0 ? BigInt(amountShielded) * denominator : BigInt(amountShielded) / (-denominator); } // Convert base units to the native pool amount public async weiToShieldedAmount(amountWei: bigint): Promise { - const denominator = await this.denominator(); - return denominator > 0 ? amountWei / denominator : amountWei * (-denominator); + const denominator = BigInt(await this.denominator()); + return denominator > 0 ? BigInt(amountWei) / denominator : BigInt(amountWei) * (-denominator); } // Round up the fee if needed with fixed fee decimal places (after point) diff --git a/src/networks/rpcman.ts b/src/networks/rpcman.ts index 565844a..57e1537 100644 --- a/src/networks/rpcman.ts +++ b/src/networks/rpcman.ts @@ -1,5 +1,4 @@ import { InternalError } from "../errors"; -import promiseRetry from 'promise-retry'; const RPC_ISSUES_THRESHOLD = 20; // number of errors needed to switch RPC @@ -26,23 +25,27 @@ export class MultiRpcManager { } // Performs RPC interaction within several attempts. The errors will registered automatically - protected commonRpcRetry(closure: () => any, errorPattern: string, retriesCnt: number): Promise { - return promiseRetry( - async (retry, attempt) => { - try { - return await closure(); - } catch (e) { - console.error(`${errorPattern ?? 'Error occured'} [attempt #${attempt}]: ${e.message}`); - this.registerRpcIssue(); - retry(e) - } - }, - { - retries: retriesCnt, - minTimeout: 500, - maxTimeout: 500, + protected async commonRpcRetry(closure: () => any, errorPattern: string, retriesCnt: number): Promise { + let cnt = 0; + const attemptMinDelayMs = 500; + let lastErr; + do { + const startTs = Date.now(); + try { + return await closure(); + } catch (e) { + lastErr = e; + console.error(`${errorPattern ?? 'Error occured'} [attempt #${cnt + 1}]: ${e.message}`); + this.registerRpcIssue(); + + const delay = Date.now() - startTs; + if (delay < attemptMinDelayMs) { + await new Promise(f => setTimeout(f, attemptMinDelayMs - delay)); + } } - ); + } while (++cnt < retriesCnt); + + throw new InternalError(`MultRpcManager: ${lastErr.message}`) } // ----------------------=========< RPC switching >=========----------------------