From 49d3367876b3d960a56dbadd6031b931ba530ece Mon Sep 17 00:00:00 2001 From: HFazelinia Date: Wed, 14 Aug 2024 20:24:25 -0600 Subject: [PATCH 1/2] fix bugs in EVM packages --- .changeset/chilly-donkeys-deny.md | 5 ++++ .changeset/cuddly-poems-count.md | 5 ++++ .changeset/eleven-mice-deliver.md | 5 ++++ .changeset/lucky-eels-watch.md | 5 ++++ packages/chains/ethereum/lib/EthereumChain.ts | 29 ++++++++++++++++++- packages/chains/ethereum/package.json | 1 + packages/chains/evm/lib/EvmChain.ts | 21 +++++--------- packages/chains/evm/tests/EvmChain.spec.ts | 27 +++++++++++++++-- packages/chains/evm/tests/TestChain.ts | 11 +++++-- .../networks/evm-rpc/lib/EvmRpcNetwork.ts | 2 +- 10 files changed, 91 insertions(+), 20 deletions(-) create mode 100644 .changeset/chilly-donkeys-deny.md create mode 100644 .changeset/cuddly-poems-count.md create mode 100644 .changeset/eleven-mice-deliver.md create mode 100644 .changeset/lucky-eels-watch.md diff --git a/.changeset/chilly-donkeys-deny.md b/.changeset/chilly-donkeys-deny.md new file mode 100644 index 00000000..61c51c6e --- /dev/null +++ b/.changeset/chilly-donkeys-deny.md @@ -0,0 +1,5 @@ +--- +'@rosen-chains/evm': major +--- + +add chain name and native token id to constructor to fix extractor intialization diff --git a/.changeset/cuddly-poems-count.md b/.changeset/cuddly-poems-count.md new file mode 100644 index 00000000..577edb8f --- /dev/null +++ b/.changeset/cuddly-poems-count.md @@ -0,0 +1,5 @@ +--- +'@rosen-chains/ethereum': patch +--- + +fix extractor initialization diff --git a/.changeset/eleven-mice-deliver.md b/.changeset/eleven-mice-deliver.md new file mode 100644 index 00000000..f62d64f5 --- /dev/null +++ b/.changeset/eleven-mice-deliver.md @@ -0,0 +1,5 @@ +--- +'@rosen-chains/evm': patch +--- + +fix tx serialization for rosen-extractor diff --git a/.changeset/lucky-eels-watch.md b/.changeset/lucky-eels-watch.md new file mode 100644 index 00000000..cb8d810e --- /dev/null +++ b/.changeset/lucky-eels-watch.md @@ -0,0 +1,5 @@ +--- +'@rosen-chains/evm-rpc': patch +--- + +fix transaction submission diff --git a/packages/chains/ethereum/lib/EthereumChain.ts b/packages/chains/ethereum/lib/EthereumChain.ts index 1c5c97d2..e996ef2b 100644 --- a/packages/chains/ethereum/lib/EthereumChain.ts +++ b/packages/chains/ethereum/lib/EthereumChain.ts @@ -1,10 +1,37 @@ -import { EvmChain } from '@rosen-chains/evm'; +import { + AbstractEvmNetwork, + EvmChain, + EvmConfigs, + TssSignFunction, +} from '@rosen-chains/evm'; +import { RosenTokens } from '@rosen-bridge/tokens'; +import { AbstractLogger } from '@rosen-bridge/abstract-logger'; import { ETH, ETHEREUM_CHAIN } from './constants'; class EthereumChain extends EvmChain { CHAIN = ETHEREUM_CHAIN; NATIVE_TOKEN_ID = ETH; CHAIN_ID = 1n; + + constructor( + network: AbstractEvmNetwork, + configs: EvmConfigs, + tokens: RosenTokens, + supportedTokens: Array, + signFunction: TssSignFunction, + logger?: AbstractLogger + ) { + super( + network, + configs, + tokens, + supportedTokens, + signFunction, + ETHEREUM_CHAIN, + ETH, + logger + ); + } } export default EthereumChain; diff --git a/packages/chains/ethereum/package.json b/packages/chains/ethereum/package.json index 7c1fc107..b4e07848 100644 --- a/packages/chains/ethereum/package.json +++ b/packages/chains/ethereum/package.json @@ -32,6 +32,7 @@ "@rosen-chains/evm": "^2.0.1" }, "dependencies": { + "@rosen-bridge/abstract-logger": "^1.0.0", "@rosen-bridge/tokens": "^1.2.1" } } diff --git a/packages/chains/evm/lib/EvmChain.ts b/packages/chains/evm/lib/EvmChain.ts index c1961e81..342dcb69 100644 --- a/packages/chains/evm/lib/EvmChain.ts +++ b/packages/chains/evm/lib/EvmChain.ts @@ -43,29 +43,21 @@ abstract class EvmChain extends AbstractChain { tokens: RosenTokens, supportedTokens: Array, signFunction: TssSignFunction, + CHAIN: string, + NATIVE_TOKEN_ID: string, logger?: AbstractLogger ) { super(network, configs, tokens, logger); this.supportedTokens = supportedTokens; this.signFunction = signFunction; - this.initExtractor(tokens, logger); - } - - /** - * initializes rosen extractor - * @param tokens - * @param nativeToken - * @param logger - */ - protected initExtractor = (tokens: RosenTokens, logger?: any) => { this.extractor = new EvmRosenExtractor( this.configs.addresses.lock, tokens, - this.CHAIN, - this.NATIVE_TOKEN_ID, + CHAIN, + NATIVE_TOKEN_ID, logger ); - }; + } /** * generates single or multiple unsigned PaymentTransactions for a payment order @@ -773,7 +765,8 @@ abstract class EvmChain extends AbstractChain { /** * serializes the transaction of this chain into string */ - protected serializeTx = (tx: Transaction): string => tx.toJSON(); + protected serializeTx = (tx: Transaction): string => + tx.serialized.substring(2); /** * gets the address balance for native token and all supported tokens diff --git a/packages/chains/evm/tests/EvmChain.spec.ts b/packages/chains/evm/tests/EvmChain.spec.ts index 649d7427..41f031c9 100644 --- a/packages/chains/evm/tests/EvmChain.spec.ts +++ b/packages/chains/evm/tests/EvmChain.spec.ts @@ -1,6 +1,4 @@ import { expect, vi } from 'vitest'; -import TestEvmNetwork from './network/TestEvmNetwork'; -import * as TestData from './testData'; import { AssetNotSupportedError, MaxParallelTxError, @@ -10,17 +8,42 @@ import { TransactionFormatError, TransactionType, } from '@rosen-chains/abstract-chain'; +import TestEvmNetwork from './network/TestEvmNetwork'; +import * as TestData from './testData'; import * as testUtils from './TestUtils'; import Serializer from '../lib/Serializer'; import { Transaction, TransactionLike } from 'ethers'; import { mockGetAddressBalanceForNativeToken } from './TestUtils'; import { EvmTxStatus } from '../lib'; +import TestChain from './TestChain'; describe('EvmChain', () => { const network = new TestEvmNetwork(); const evmChain = testUtils.generateChainObject(network); + describe(`constructor`, () => { + /** + * @target EvmChain.constructor should initialize rosen-extractor successfully + * @dependencies + * @scenario + * - initialize EvmChain + * - check CHAIN variable in rosen-extractor + * @expected + * - CHAIN variable should be the same as the one defined EvmChain + */ + it('should initialize rosen-extractor successfully', async () => { + const chain = new TestChain( + network, + testUtils.configs, + TestData.testTokenMap, + TestData.supportedTokens, + testUtils.mockedSignFn + ); + expect(chain.extractor?.chain).toEqual(chain.CHAIN); + }); + }); + describe('generateMultipleTransactions', () => { /** * @target EvmChain.generateMultipleTransactions should generate payment transactions diff --git a/packages/chains/evm/tests/TestChain.ts b/packages/chains/evm/tests/TestChain.ts index 49af7d2e..414d368c 100644 --- a/packages/chains/evm/tests/TestChain.ts +++ b/packages/chains/evm/tests/TestChain.ts @@ -1,6 +1,5 @@ import { RosenTokens } from '@rosen-bridge/tokens'; import { AbstractEvmNetwork, EvmChain, TssSignFunction } from '../lib'; -import { EvmRosenExtractor } from '@rosen-bridge/rosen-extractor'; class TestChain extends EvmChain { CHAIN = 'test'; @@ -14,7 +13,15 @@ class TestChain extends EvmChain { supportedTokens: Array, signFunction: TssSignFunction ) { - super(network, configs, tokens, supportedTokens, signFunction); + super( + network, + configs, + tokens, + supportedTokens, + signFunction, + 'test', + 'test-native-token' + ); } } diff --git a/packages/networks/evm-rpc/lib/EvmRpcNetwork.ts b/packages/networks/evm-rpc/lib/EvmRpcNetwork.ts index 5cb31562..cdaa8a1d 100644 --- a/packages/networks/evm-rpc/lib/EvmRpcNetwork.ts +++ b/packages/networks/evm-rpc/lib/EvmRpcNetwork.ts @@ -191,7 +191,7 @@ class EvmRpcNetwork extends AbstractEvmNetwork { * @param transaction the transaction */ submitTransaction = async (transaction: Transaction): Promise => { - await this.provider.broadcastTransaction(transaction.toJSON()); + await this.provider.broadcastTransaction(transaction.serialized); }; /** From 63b0c2210ca455c24c21ae3f21243c9b397e25a7 Mon Sep 17 00:00:00 2001 From: HFazelinia Date: Wed, 14 Aug 2024 20:39:11 -0600 Subject: [PATCH 2/2] update package-lock --- package-lock.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package-lock.json b/package-lock.json index ceef7bb9..14129738 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17935,6 +17935,7 @@ "version": "0.1.2", "license": "GPL-3.0", "dependencies": { + "@rosen-bridge/abstract-logger": "^1.0.0", "@rosen-bridge/tokens": "^1.2.1" }, "devDependencies": {