From 62705c4c94d4740e76ce6657a772211decbce16f Mon Sep 17 00:00:00 2001 From: BC-A Date: Thu, 30 May 2024 17:50:30 +0800 Subject: [PATCH 1/3] feat: add update_global_exit_root_map function --- examples/zkevm/update_global_exit_root.js | 13 +++++++++ src/interfaces/zkevm_client_config.ts | 1 + src/zkevm/eigen_global_exit_root.ts | 33 +++++++++++++++++++++++ src/zkevm/index.ts | 17 +++++++++--- 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 examples/zkevm/update_global_exit_root.js create mode 100644 src/zkevm/eigen_global_exit_root.ts diff --git a/examples/zkevm/update_global_exit_root.js b/examples/zkevm/update_global_exit_root.js new file mode 100644 index 0000000..c2c2cda --- /dev/null +++ b/examples/zkevm/update_global_exit_root.js @@ -0,0 +1,13 @@ +const { getZkEvmClient, zkEvm, from } = require('../utils_zkevm'); + +const execute = async () => { + const client = await getZkEvmClient(); + let lastMainnetExitRoot = "0x696ab68e8fc171a30b26f661191a258f72a7a8a4794bb7d87647c32733909170" + await client.updateGlobalExitRootMap(lastMainnetExitRoot); +} +execute().then(() => { +}).catch(err => { + console.error("err", err); +}).finally(_ => { + process.exit(0); +}) \ No newline at end of file diff --git a/src/interfaces/zkevm_client_config.ts b/src/interfaces/zkevm_client_config.ts index fdd7a9b..3a3b107 100644 --- a/src/interfaces/zkevm_client_config.ts +++ b/src/interfaces/zkevm_client_config.ts @@ -4,4 +4,5 @@ export interface IZkEvmClientConfig extends IBaseClientConfig { parentBridge?: string; childBridge?: string; zkEVMWrapper?: string; + globalExitRootL2?: string; } diff --git a/src/zkevm/eigen_global_exit_root.ts b/src/zkevm/eigen_global_exit_root.ts new file mode 100644 index 0000000..682a9ca --- /dev/null +++ b/src/zkevm/eigen_global_exit_root.ts @@ -0,0 +1,33 @@ +import { BaseToken, Web3SideChainClient, Converter, promiseResolve } from "../utils"; +import { IZkEvmClientConfig, ITransactionOption } from "../interfaces"; +import { TYPE_AMOUNT } from "../types"; + +export class EigenGlobalExitRootL2 extends BaseToken { + + networkID_: number; + + constructor(client_: Web3SideChainClient, address: string) { + // EigenGlobalExitRootL2 contract is deployed on L2, isParent is false + super({ + address: address, + name: 'EigenGlobalExitRootL2', + bridgeType: 'zkevm', + isParent: false + }, client_); + } + + method(methodName: string, ...args) { + return this.getContract().then(contract => { + return contract.method(methodName, ...args); + }); + } + + updateGlobalExitRootMap(lastMainnetExitRoot: string){ + return this.method( + "updateGlobalExitRootMap", + lastMainnetExitRoot, + ).then(method => { + return this.processWrite(method); + }); + } +} diff --git a/src/zkevm/index.ts b/src/zkevm/index.ts index 89135ee..efd6d92 100644 --- a/src/zkevm/index.ts +++ b/src/zkevm/index.ts @@ -6,6 +6,7 @@ import { IZkEvmClientConfig, IZkEvmContracts } from "../interfaces"; import { config as urlConfig } from "../config"; import { service, NetworkService } from "../services"; import { ZkEVMWrapper } from "./zkevm_wrapper"; +import { EigenGlobalExitRootL2 } from "./eigen_global_exit_root"; export * from "./zkevm_bridge"; @@ -15,6 +16,7 @@ export * from "./zkevm_wrapper"; export class ZkEvmClient extends ZkEvmBridgeClient { zkEVMWrapper: ZkEVMWrapper; + globalExitRootL2: EigenGlobalExitRootL2; init(config: IZkEvmClientConfig) { const client = this.client; @@ -26,11 +28,11 @@ export class ZkEvmClient extends ZkEvmBridgeClient { { parentBridge: mainZkEvmContracts.PolygonZkEVMBridgeProxy, childBridge: zkEvmContracts.PolygonZkEVMBridge, - zkEVMWrapper: mainZkEvmContracts.ZkEVMWrapper + zkEVMWrapper: mainZkEvmContracts.ZkEVMWrapper, + globalExitRootL2: zkEvmContracts.PolygonZkEVMGlobalExitRootL2 } as IZkEvmClientConfig, config ); - this.rootChainBridge = new ZkEvmBridge( this.client, config.parentBridge, @@ -48,6 +50,11 @@ export class ZkEvmClient extends ZkEvmBridgeClient { config.zkEVMWrapper ); + this.globalExitRootL2 = new EigenGlobalExitRootL2( + this.client, + config.globalExitRootL2 + ); + this.bridgeUtil = new BridgeUtil( this.client ); @@ -97,7 +104,7 @@ export class ZkEvmClient extends ZkEvmBridgeClient { getBatchProof(blockNum: any, isParent?: boolean){ return this.client.getBatchProof(blockNum, isParent); } - + private getContracts_() { return { parentBridge: this.rootChainBridge, @@ -106,4 +113,8 @@ export class ZkEvmClient extends ZkEvmBridgeClient { zkEVMWrapper: this.zkEVMWrapper } as IZkEvmContracts; } + + updateGlobalExitRootMap(lastMainnetExitRoot: string){ + return this.globalExitRootL2.updateGlobalExitRootMap(lastMainnetExitRoot); + } } From 5f0480ae1eb325a2f8da9095e6f6001ce9ae223a Mon Sep 17 00:00:00 2001 From: BC-A Date: Fri, 31 May 2024 10:12:36 +0800 Subject: [PATCH 2/3] fix: fix bignumber --- examples/zkevm/erc20/deposit_ether.js | 4 ++-- src/utils/index.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/zkevm/erc20/deposit_ether.js b/examples/zkevm/erc20/deposit_ether.js index 05695c2..b19c478 100644 --- a/examples/zkevm/erc20/deposit_ether.js +++ b/examples/zkevm/erc20/deposit_ether.js @@ -1,10 +1,10 @@ const { getZkEvmClient, zkEvm, from } = require('../../utils_zkevm'); -const ether = require("ethers") const execute = async () => { const client = await getZkEvmClient(); const etherToken = client.erc20(zkEvm.parent.ether, true); - const result = await etherToken.deposit("20000000000000000", from); + //const amount = ethers.utils.parseEther("0.1") + const result = await etherToken.deposit("1000000000000000000", from); const txHash = await result.getTransactionHash(); console.log("txHash", txHash); diff --git a/src/utils/index.ts b/src/utils/index.ts index a8d1c62..dea0299 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,5 +1,6 @@ import { BaseWeb3Client, Converter, TYPE_AMOUNT } from ".."; import { EmptyBigNumber } from "../implementation"; +import { ZethBigNumber } from "../../zeth-web3/src/utils"; export * from "./use"; export * from "./event_bus"; @@ -22,6 +23,6 @@ export * from "./zkevm_bridge_client"; export const utils = { converter: Converter, Web3Client: BaseWeb3Client, - BN: EmptyBigNumber, + BN: ZethBigNumber, UnstoppableDomains: Object }; From d0af20340466fc47f769f8b85e56172f849c530c Mon Sep 17 00:00:00 2001 From: BC-A Date: Fri, 31 May 2024 12:44:31 +0800 Subject: [PATCH 3/3] fix: fix bridge name --- src/zkevm/bridge_util.ts | 2 +- src/zkevm/zkevm_bridge.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/zkevm/bridge_util.ts b/src/zkevm/bridge_util.ts index 2cb5a14..71c7b36 100644 --- a/src/zkevm/bridge_util.ts +++ b/src/zkevm/bridge_util.ts @@ -44,7 +44,7 @@ export class BridgeUtil { private decodedBridgeData_(data: string, isParent: boolean) { const client = isParent ? this.client_.parent : this.client_.child; - return this.client_.getABI("PolygonZkEVMBridge", "zkevm").then(abi => { + return this.client_.getABI("EigenBridge", "zkevm").then(abi => { const types = abi.filter(event => event.name === "BridgeEvent"); if (!types.length) { throw new Error("Data not decoded"); diff --git a/src/zkevm/zkevm_bridge.ts b/src/zkevm/zkevm_bridge.ts index 78068d1..8fbfe5c 100644 --- a/src/zkevm/zkevm_bridge.ts +++ b/src/zkevm/zkevm_bridge.ts @@ -9,7 +9,7 @@ export class ZkEvmBridge extends BaseToken { constructor(client_: Web3SideChainClient, address: string, isParent: boolean) { super({ address: address, - name: 'PolygonZkEVMBridge', + name: 'EigenBridge', bridgeType: 'zkevm', isParent: isParent }, client_);