Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add update root map #5

Merged
merged 3 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/zkevm/erc20/deposit_ether.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
13 changes: 13 additions & 0 deletions examples/zkevm/update_global_exit_root.js
Original file line number Diff line number Diff line change
@@ -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);
})
1 change: 1 addition & 0 deletions src/interfaces/zkevm_client_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface IZkEvmClientConfig extends IBaseClientConfig {
parentBridge?: string;
childBridge?: string;
zkEVMWrapper?: string;
globalExitRootL2?: string;
}
3 changes: 2 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -22,6 +23,6 @@ export * from "./zkevm_bridge_client";
export const utils = {
converter: Converter,
Web3Client: BaseWeb3Client,
BN: EmptyBigNumber,
BN: ZethBigNumber,
UnstoppableDomains: Object
};
2 changes: 1 addition & 1 deletion src/zkevm/bridge_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
33 changes: 33 additions & 0 deletions src/zkevm/eigen_global_exit_root.ts
Original file line number Diff line number Diff line change
@@ -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<IZkEvmClientConfig> {

networkID_: number;

constructor(client_: Web3SideChainClient<IZkEvmClientConfig>, 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);
});
}
}
17 changes: 14 additions & 3 deletions src/zkevm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -15,6 +16,7 @@ export * from "./zkevm_wrapper";
export class ZkEvmClient extends ZkEvmBridgeClient {

zkEVMWrapper: ZkEVMWrapper;
globalExitRootL2: EigenGlobalExitRootL2;

init(config: IZkEvmClientConfig) {
const client = this.client;
Expand All @@ -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,
Expand All @@ -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
);
Expand Down Expand Up @@ -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,
Expand All @@ -106,4 +113,8 @@ export class ZkEvmClient extends ZkEvmBridgeClient {
zkEVMWrapper: this.zkEVMWrapper
} as IZkEvmContracts;
}

updateGlobalExitRootMap(lastMainnetExitRoot: string){
return this.globalExitRootL2.updateGlobalExitRootMap(lastMainnetExitRoot);
}
}
2 changes: 1 addition & 1 deletion src/zkevm/zkevm_bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class ZkEvmBridge extends BaseToken<IZkEvmClientConfig> {
constructor(client_: Web3SideChainClient<IZkEvmClientConfig>, address: string, isParent: boolean) {
super({
address: address,
name: 'PolygonZkEVMBridge',
name: 'EigenBridge',
bridgeType: 'zkevm',
isParent: isParent
}, client_);
Expand Down
Loading