From 79d12f62ddf1c081debb4ffa0dec87510a4ca1d8 Mon Sep 17 00:00:00 2001 From: Aniket Sharma Date: Fri, 29 Aug 2025 16:08:05 +0530 Subject: [PATCH 1/2] feat: add optional gas price and nonce in EVM adapter --- src/chain-adapters/EVM/EVM.ts | 24 +++++++++++++----------- src/chain-adapters/EVM/types.ts | 5 ++++- src/chain-adapters/EVM/utils.ts | 16 ++++++++++++---- yarn.lock | 19 +------------------ 4 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/chain-adapters/EVM/EVM.ts b/src/chain-adapters/EVM/EVM.ts index e3717d0..2e41fac 100644 --- a/src/chain-adapters/EVM/EVM.ts +++ b/src/chain-adapters/EVM/EVM.ts @@ -18,7 +18,7 @@ import { concat, pad, isAddress, - SignedAuthorization, + type SignedAuthorization, } from 'viem' import { hashAuthorization } from 'viem/experimental' @@ -69,9 +69,11 @@ export class EVM extends ChainAdapter { const fees = await fetchEVMFeeProperties(this.client, transaction) - const nonce = await this.client.getTransactionCount({ - address: transaction.from, - }) + const nonce = + transaction.nonce ?? + (await this.client.getTransactionCount({ + address: transaction.from, + })) const { from, ...rest } = transaction @@ -87,12 +89,14 @@ export class EVM extends ChainAdapter { - const gasPrice = await this.client.getGasPrice() - const nonce = await this.client.getTransactionCount({ - address: transaction.from, - }) + const gasPrice = transaction.gasPrice ?? (await this.client.getGasPrice()) + const nonce = + transaction.nonce ?? + (await this.client.getTransactionCount({ + address: transaction.from, + })) - const { from, ...rest } = transaction; + const { from, ...rest } = transaction return { ...rest, @@ -105,8 +109,6 @@ export class EVM extends ChainAdapter { + extends Omit { from: Address + nonce?: number } // Legacy transaction request coming from your dApp (includes 'from' address) @@ -23,6 +24,8 @@ export interface EVMTransactionRequestLegacy { to: `0x${string}` value?: bigint gas?: bigint + gasPrice?: bigint + nonce?: number } // Legacy unsigned transaction to be signed diff --git a/src/chain-adapters/EVM/utils.ts b/src/chain-adapters/EVM/utils.ts index 644bf2f..abbd1b9 100644 --- a/src/chain-adapters/EVM/utils.ts +++ b/src/chain-adapters/EVM/utils.ts @@ -10,10 +10,18 @@ export async function fetchEVMFeeProperties( client: PublicClient, transaction: TransactionRequest ): Promise { - const [gas, feeData] = await Promise.all([ - client.estimateGas(transaction), - client.estimateFeesPerGas(), - ]) + const gasPromise = transaction.gas + ? Promise.resolve(transaction.gas) + : client.estimateGas(transaction) + const feeDataPromise = + transaction.maxFeePerGas && transaction.maxPriorityFeePerGas + ? Promise.resolve({ + maxFeePerGas: transaction.maxFeePerGas, + maxPriorityFeePerGas: transaction.maxPriorityFeePerGas, + }) + : client.estimateFeesPerGas() + + const [gas, feeData] = await Promise.all([gasPromise, feeDataPromise]) const maxFeePerGas = feeData.maxFeePerGas ?? BigInt(10_000_000_000) // 10 gwei const maxPriorityFeePerGas = diff --git a/yarn.lock b/yarn.lock index 650b2a5..36d4240 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7215,16 +7215,6 @@ fs.realpath@^1.0.0: resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== -fsevents@^2.3.2, fsevents@~2.3.2, fsevents@~2.3.3: - version "2.3.3" - resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz" - integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== - -fsevents@2.3.2: - version "2.3.2" - resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz" - integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== - function-bind@^1.1.2: version "1.1.2" resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz" @@ -7451,14 +7441,7 @@ global-prefix@^3.0.0: kind-of "^6.0.2" which "^1.3.1" -globals@^13.19.0: - version "13.24.0" - resolved "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz" - integrity sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ== - dependencies: - type-fest "^0.20.2" - -globals@^13.24.0: +globals@^13.19.0, globals@^13.24.0: version "13.24.0" resolved "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz" integrity sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ== From 500c0f83e4e47d942658462562f34c3b67dbb7b8 Mon Sep 17 00:00:00 2001 From: Aniket Sharma Date: Wed, 17 Sep 2025 03:29:43 +0530 Subject: [PATCH 2/2] fix: yarn lock --- yarn.lock | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index 36d4240..650b2a5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7215,6 +7215,16 @@ fs.realpath@^1.0.0: resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== +fsevents@^2.3.2, fsevents@~2.3.2, fsevents@~2.3.3: + version "2.3.3" + resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz" + integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== + +fsevents@2.3.2: + version "2.3.2" + resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz" + integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== + function-bind@^1.1.2: version "1.1.2" resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz" @@ -7441,7 +7451,14 @@ global-prefix@^3.0.0: kind-of "^6.0.2" which "^1.3.1" -globals@^13.19.0, globals@^13.24.0: +globals@^13.19.0: + version "13.24.0" + resolved "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz" + integrity sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ== + dependencies: + type-fest "^0.20.2" + +globals@^13.24.0: version "13.24.0" resolved "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz" integrity sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==