diff --git a/.changeset/sixty-humans-learn.md b/.changeset/shy-falcons-return.md similarity index 100% rename from .changeset/sixty-humans-learn.md rename to .changeset/shy-falcons-return.md diff --git a/package-lock.json b/package-lock.json index ec97fab..1f32eeb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17941,13 +17941,13 @@ }, "packages/chains/ethereum": { "name": "@rosen-chains/ethereum", - "version": "0.1.4", + "version": "0.1.5", "license": "GPL-3.0", "dependencies": { "@rosen-bridge/abstract-logger": "^1.0.0", "@rosen-bridge/tokens": "^1.2.1", "@rosen-chains/abstract-chain": "^9.0.1", - "@rosen-chains/evm": "^4.0.0" + "@rosen-chains/evm": "^4.0.1" }, "devDependencies": { "@types/node": "^20.11.9", @@ -18239,7 +18239,7 @@ }, "packages/chains/evm": { "name": "@rosen-chains/evm", - "version": "4.0.0", + "version": "4.0.1", "license": "GPL-3.0", "dependencies": { "@rosen-bridge/abstract-logger": "^1.0.0", @@ -23379,13 +23379,13 @@ }, "packages/networks/evm-rpc": { "name": "@rosen-chains/evm-rpc", - "version": "2.1.1", + "version": "2.1.2", "license": "GPL-3.0", "dependencies": { "@rosen-bridge/abstract-logger": "^1.0.0", "@rosen-bridge/evm-address-tx-extractor": "^1.0.3", "@rosen-chains/abstract-chain": "^9.0.1", - "@rosen-chains/evm": "^4.0.0", + "@rosen-chains/evm": "^4.0.1", "typeorm": "^0.3.20" }, "devDependencies": { diff --git a/packages/chains/ethereum/CHANGELOG.md b/packages/chains/ethereum/CHANGELOG.md index fbc3871..2a2ce77 100644 --- a/packages/chains/ethereum/CHANGELOG.md +++ b/packages/chains/ethereum/CHANGELOG.md @@ -1,5 +1,12 @@ # @rosen-chains/ethereum +## 0.1.5 + +### Patch Changes + +- Updated dependencies + - @rosen-chains/evm@4.0.1 + ## 0.1.4 ### Patch Changes diff --git a/packages/chains/ethereum/package.json b/packages/chains/ethereum/package.json index 9aa6619..c3db2f7 100644 --- a/packages/chains/ethereum/package.json +++ b/packages/chains/ethereum/package.json @@ -1,6 +1,6 @@ { "name": "@rosen-chains/ethereum", - "version": "0.1.4", + "version": "0.1.5", "description": "this project contains ethereum chain for Rosen-bridge", "repository": "https://github.com/rosen-bridge/rosen-chains", "license": "GPL-3.0", @@ -31,6 +31,6 @@ "@rosen-bridge/abstract-logger": "^1.0.0", "@rosen-bridge/tokens": "^1.2.1", "@rosen-chains/abstract-chain": "^9.0.1", - "@rosen-chains/evm": "^4.0.0" + "@rosen-chains/evm": "^4.0.1" } } diff --git a/packages/chains/evm/CHANGELOG.md b/packages/chains/evm/CHANGELOG.md index f578ee7..954f1a1 100644 --- a/packages/chains/evm/CHANGELOG.md +++ b/packages/chains/evm/CHANGELOG.md @@ -1,5 +1,11 @@ # @rosen-chains/evm +## 4.0.1 + +### Patch Changes + +- catch errors while checking tx before submission + ## 4.0.0 ### Major Changes diff --git a/packages/chains/evm/lib/EvmChain.ts b/packages/chains/evm/lib/EvmChain.ts index b7bbc7b..f318621 100644 --- a/packages/chains/evm/lib/EvmChain.ts +++ b/packages/chains/evm/lib/EvmChain.ts @@ -568,33 +568,43 @@ abstract class EvmChain extends AbstractChain { return; } - // check type - if (tx.type !== 2) { - this.logger.warn( - `Cannot submit transaction [${transaction.txId}]: Transaction is not of type 2` - ); - return; - } + try { + // check type + if (tx.type !== 2) { + this.logger.warn( + `Cannot submit transaction [${transaction.txId}]: Transaction is not of type 2` + ); + return; + } - // check fees - const gasRequired = await this.network.getGasRequired(tx); - if (gasRequired > tx.gasLimit) { - this.logger.warn( - `Cannot submit transaction [${transaction.txId}]: Transaction gas limit [${tx.maxFeePerGas}] is less than the required gas [${gasRequired}]` - ); - return; - } + // check fees + const gasRequired = await this.network.getGasRequired(tx); + if (gasRequired > tx.gasLimit) { + this.logger.warn( + `Cannot submit transaction [${transaction.txId}]: Transaction gas limit [${tx.maxFeePerGas}] is less than the required gas [${gasRequired}]` + ); + return; + } - // check lock still has enough assets - const txAssets = await this.getTransactionAssets(transaction); - if (!(await this.hasLockAddressEnoughAssets(txAssets.inputAssets))) { + // check lock still has enough assets + const txAssets = await this.getTransactionAssets(transaction); + if (!(await this.hasLockAddressEnoughAssets(txAssets.inputAssets))) { + this.logger.warn( + `Cannot submit transaction [${ + transaction.txId + }]: Locked assets cannot cover transaction assets: ${JSONBigInt.stringify( + txAssets.inputAssets + )}` + ); + return; + } + } catch (e) { this.logger.warn( - `Cannot submit transaction [${ - transaction.txId - }]: Locked assets cannot cover transaction assets: ${JSONBigInt.stringify( - txAssets.inputAssets - )}` + `An error occurred while checking transaction [${transaction.txId}] for submission: ${e}` ); + if (e instanceof Error && e.stack) { + this.logger.warn(e.stack); + } return; } diff --git a/packages/chains/evm/package.json b/packages/chains/evm/package.json index 78411e7..aff27f3 100644 --- a/packages/chains/evm/package.json +++ b/packages/chains/evm/package.json @@ -1,6 +1,6 @@ { "name": "@rosen-chains/evm", - "version": "4.0.0", + "version": "4.0.1", "description": "this project contains evm chains for Rosen-bridge", "repository": "https://github.com/rosen-bridge/rosen-chains", "license": "GPL-3.0", diff --git a/packages/chains/evm/tests/EvmChain.spec.ts b/packages/chains/evm/tests/EvmChain.spec.ts index 84607e5..6b03b82 100644 --- a/packages/chains/evm/tests/EvmChain.spec.ts +++ b/packages/chains/evm/tests/EvmChain.spec.ts @@ -1564,6 +1564,46 @@ describe('EvmChain', () => { await evmChain.submitTransaction(paymentTx); expect(submitTransactionSpy).not.toHaveBeenCalled(); }); + + /** + * @target EvmChain.submitTransaction should not submit the transaction + * when checking failed due to error + * @dependencies + * @scenario + * - mock invalid PaymentTransaction + * - mock getGasRequired to throw error + * - run test + * - check function is not called + * @expected + * - it should not call the function + */ + it('should not submit the transaction when checking failed due to error', async () => { + // mock getGasRequired + vi.spyOn(network, 'getGasRequired').mockImplementation(() => { + throw Error(`test Error`); + }); + + // mock PaymentTransaction + const tx = Transaction.from(TestData.transaction1Json); + tx.gasLimit = 55000n; + tx.maxFeePerGas = 21n; + tx.maxPriorityFeePerGas = 6n; + tx.value = 2n; + + const eventId = 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'; + const txType = TransactionType.payment; + const paymentTx = new PaymentTransaction( + evmChain.CHAIN, + tx.unsignedHash, + eventId, + Serializer.serialize(tx), + txType + ); + const submitTransactionSpy = vi.spyOn(network, 'submitTransaction'); + submitTransactionSpy.mockImplementation(async () => undefined); + await evmChain.submitTransaction(paymentTx); + expect(submitTransactionSpy).not.toHaveBeenCalled(); + }); }); describe('verifyTransactionExtraConditions', () => { diff --git a/packages/networks/evm-rpc/CHANGELOG.md b/packages/networks/evm-rpc/CHANGELOG.md index 894b6d4..6e4c139 100644 --- a/packages/networks/evm-rpc/CHANGELOG.md +++ b/packages/networks/evm-rpc/CHANGELOG.md @@ -1,5 +1,13 @@ # @rosen-chains/evm-rpc +## 2.1.2 + +### Patch Changes + +- improve log in `getGasRequired` function +- Updated dependencies + - @rosen-chains/evm@4.0.1 + ## 2.1.1 ### Patch Changes diff --git a/packages/networks/evm-rpc/lib/EvmRpcNetwork.ts b/packages/networks/evm-rpc/lib/EvmRpcNetwork.ts index c3c68c1..76ec805 100644 --- a/packages/networks/evm-rpc/lib/EvmRpcNetwork.ts +++ b/packages/networks/evm-rpc/lib/EvmRpcNetwork.ts @@ -311,6 +311,12 @@ class EvmRpcNetwork extends AbstractEvmNetwork { return gas; } catch (e: unknown) { const baseError = `Failed to get required Gas from ${this.chain} RPC: `; + if (isCallException(e)) + this.logger.debug( + `Gas estimation failed on chain [${ + this.chain + }] due to CALL_EXCEPTION: ${JsonBigInt.stringify(e)}` + ); throw new UnexpectedApiError(baseError + `${e}`); } }; diff --git a/packages/networks/evm-rpc/package.json b/packages/networks/evm-rpc/package.json index b764184..90cba23 100644 --- a/packages/networks/evm-rpc/package.json +++ b/packages/networks/evm-rpc/package.json @@ -1,6 +1,6 @@ { "name": "@rosen-chains/evm-rpc", - "version": "2.1.1", + "version": "2.1.2", "description": "A package to be used as network api provider for @rosen-chains/evm package", "repository": "https://github.com/rosen-bridge/rosen-chains", "license": "GPL-3.0", @@ -36,7 +36,7 @@ "@rosen-bridge/abstract-logger": "^1.0.0", "@rosen-bridge/evm-address-tx-extractor": "^1.0.3", "@rosen-chains/abstract-chain": "^9.0.1", - "@rosen-chains/evm": "^4.0.0", + "@rosen-chains/evm": "^4.0.1", "typeorm": "^0.3.20" } }