chg: new static structure variables
MODIFY
src/abstracts/base_web3_client.ts
src/abstracts/base_web3_client.ts
@@ -25,7 +25,8 @@ export abstract class BaseWeb3Client {
abstract getBlock(blockHashOrBlockNumber): Promise<IBlock>;
abstract getBlockWithTransaction(blockHashOrBlockNumber): Promise<IBlockWithTransaction>;
abstract hexToNumber(value: any): number;
-
+ abstract hexToNumberString(value: any): string;
+ abstract getBalance(address: string): string;
getRootHash?(startBlock: number, endBlock: number) {
return this.sendRPCRequest({
@@ -49,17 +50,6 @@ export abstract class BaseWeb3Client {
});
}
- getBalance?(address: string) {
- return this.sendRPCRequest({
- jsonrpc: '2.0',
- method: 'eth_getBalance',
- params: [address, "latest"],
- id: new Date().getTime()
- }).then(payload => {
- return this.hexToNumber(payload.result);
- });
- }
-
getAccounts?() {
return this.sendRPCRequest({
jsonrpc: '2.0',

MODIFY
src/hermez/bridge.ts
src/hermez/bridge.ts
@@ -10,7 +10,7 @@ export class Bridge extends BaseToken<IHermezClientConfig> {
super({
address: address,
name: 'Bridge',
- bridgeType: 'hermez',
+ bridgeType: 'zkevm',
isParent: isParent
}, client_);
}

MODIFY
src/hermez/bridge_util.ts
src/hermez/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("Bridge", "hermez").then(abi => {
+ return this.client_.getABI("Bridge", "zkevm").then(abi => {
const types = abi.filter(event => event.name === "BridgeEvent");
if (!types.length) {
throw new Error("Data not decoded");

MODIFY
src/hermez/erc20.ts
src/hermez/erc20.ts
import { isHexString } from 'ethereumjs-util';
import { ITransactionOption } from "../interfaces";
-import { Converter, Web3SideChainClient } from "../utils";
+import { Converter, Web3SideChainClient, promiseAny } from "../utils";
import { HermezToken } from "./hermez_token";
import { TYPE_AMOUNT } from "../types";
import { BaseContractMethod } from "../abstracts";
@@ -18,8 +18,8 @@ export class ERC20 extends HermezToken {
super({
isParent,
address: tokenAddress,
- name: 'ChildERC20',
- bridgeType: 'pos'
+ name: 'ERC20',
+ bridgeType: 'zkevm'
}, client, getContracts);
}
@@ -347,7 +347,7 @@ export class ERC20 extends HermezToken {
case EIP_2612_PERMIT_TYPEHASH: {
const DOMAIN_TYPEHASH = contract.method("DOMAIN_TYPEHASH");
const EIP712DOMAIN_HASH = contract.method("EIP712DOMAIN_HASH");
- return Promise.any([this.processRead<string>(DOMAIN_TYPEHASH), this.processRead<string>(EIP712DOMAIN_HASH)]).then(
+ return promiseAny([this.processRead<string>(DOMAIN_TYPEHASH), this.processRead<string>(EIP712DOMAIN_HASH)]).then(
(domainTypehash) => {
switch (domainTypehash) {
case EIP_2612_DOMAIN_TYPEHASH: {

MODIFY
src/hermez/index.ts
src/hermez/index.ts
@@ -14,12 +14,12 @@ export class HermezClient extends HermezBridgeClient<IHermezClientConfig> {
const client = this.client;
return client.init(config).then(_ => {
- const mainHermezContracts = client.mainHermezContracts;
+ const mainHermezContracts = client.mainContracts;
const hermezContracts = client.hermezContracts;
client.config = config = Object.assign(
{
parentBridge: mainHermezContracts.BridgeProxy,
- childBridge: hermezContracts.BridgeProxy,
+ childBridge: hermezContracts.Bridge,
} as IHermezClientConfig,
config
);

MODIFY
src/pos/index.ts
src/pos/index.ts
@@ -25,7 +25,7 @@ export class POSClient extends BridgeClient<IPOSClientConfig> {
{
rootChainManager: mainPOSContracts.RootChainManagerProxy,
- rootChain: client.mainPlasmaContracts.RootChainProxy
+ rootChain: client.mainContracts.RootChainProxy
} as IPOSClientConfig,
config
);

MODIFY
src/utils/base_token.ts
src/utils/base_token.ts
import { Web3SideChainClient } from "./web3_side_chain_client";
-import { ITransactionRequestConfig, ITransactionOption, IContractInitParam, IPOSClientConfig, IBaseClientConfig, ITransactionWriteResult } from "../interfaces";
-import { BaseContractMethod, BaseContract, BaseWeb3Client } from "../abstracts";
+import { ITransactionRequestConfig, ITransactionOption, IContractInitParam, IBaseClientConfig, ITransactionWriteResult } from "../interfaces";
+import { BaseContractMethod, BaseContract } from "../abstracts";
import { Converter, merge } from "../utils";
import { promiseResolve } from "./promise_resolve";
import { ERROR_TYPE } from "../enums";

MODIFY
src/utils/promise_resolve.ts
src/utils/promise_resolve.ts
export const promiseResolve = <T>(value?) => {
return Promise.resolve<T>(value);
};
+
+export const promiseAny = (promisesArray) => {
+ const promiseErrors = new Array(promisesArray.length);
+ let counter = 0;
+
+ //return a new promise
+ return new Promise((resolve, reject) => {
+ promisesArray.forEach((promise) => {
+ Promise.resolve(promise)
+ .then(resolve) // resolve, when any of the input promise resolves
+ .catch((error) => {
+ promiseErrors[counter] = error;
+ counter = counter + 1;
+ if (counter === promisesArray.length) {
+ // all promises rejected, reject outer promise
+ reject(promiseErrors);
+ }
+ }); // reject, when any of the input promise rejects
+ });
+ });
+};

MODIFY
src/utils/web3_side_chain_client.ts
src/utils/web3_side_chain_client.ts
@@ -63,7 +63,7 @@ export class Web3SideChainClient<T_CONFIG> {
return this.abiManager.getConfig(path);
}
- get mainPlasmaContracts() {
+ get mainContracts() {
return this.getConfig("Main.Contracts");
}

MODIFY
test/debug.js
test/debug.js
@@ -157,7 +157,7 @@ const executeHermez = async () => {
await client.init({
log: true,
network: 'testnet',
- version: 'mumbai',
+ version: 'litchi',
parent: {
provider: new HDWalletProvider(privateKey, rpc.hermez.parent),
defaultConfig: {
@@ -198,11 +198,11 @@ const executeHermez = async () => {
// return console.log('result', result);
// // getTokenWrappedAddress
- // var result = await client.childChainBridge.getTokenWrappedAddress("0", '0x4701Aa9471d7bfAc765D87dcb1Ea6BB23AD32733');
+ // var result = await client.childChainBridge.getTokenWrappedAddress("0", goerliERC20);
// return console.log('result', result);
// // wrappedTokenToTokenInfo
- // var result = await client.childChainBridge.wrappedTokenToTokenInfo("0x270969e59d170fB576cBB5E254493e9bfB13684f");
+ // var result = await client.childChainBridge.wrappedTokenToTokenInfo(litchiERC20);
// return console.log('result', result);
// // getBalance on goerli
@@ -222,31 +222,23 @@ const executeHermez = async () => {
// return console.log('result', result);
// // approve
- // var tx = await goerliERC20Token.approve("10", {returnTransaction: false});
- // return console.log("hash", await tx.getTransactionHash());
+ // var tx = await goerliERC20Token.approve("10", {returnTransaction: true});
+ // return console.log("hash", tx);
// // deposit Ether
// var tx = await goerliEtherToken.deposit("220000000000", from, {returnTransaction: true});
// return console.log("hash", tx);
// // claim Ether
- // var tx = await litchiEtherToken.depositClaim("0xd2019abfdb978346cfc886525752b3d8a5798b8c474a46a8d18ed9b293bd5862", {returnTransaction: false});
- // return console.log("hash", await tx.getTransactionHash());
+ // var tx = await litchiEtherToken.depositClaim("0xd2019abfdb978346cfc886525752b3d8a5798b8c474a46a8d18ed9b293bd5862", {returnTransaction: true});
+ // return console.log("hash", tx);
// // deposit ERC20
// var tx = await goerliERC20Token.deposit("10", from, {returnTransaction: true});
// return console.log("hash", tx);
// // deposit claim ERC20
- // var tx = await litchiERC20Token.depositClaim("0x080b05623d70c2858cb1fc64fd76cd04bde52a0a344d3cb896d33833ef221b12", {returnTransaction: false});
- // return console.log("hash", await tx.getTransactionHash());
-
- // // withdraw Ether
- // var tx = await litchiEtherToken.withdraw("1", from, {returnTransaction: true});
- // return console.log("hash", tx);
-
- // // withdraw ERC20
- // var tx = await litchiERC20Token.withdraw("1", from, {returnTransaction: true});
+ // var tx = await litchiERC20Token.depositClaim("0x080b05623d70c2858cb1fc64fd76cd04bde52a0a344d3cb896d33833ef221b12", {returnTransaction: true});
// return console.log("hash", tx);
// // Get Permit Data
@@ -257,11 +249,18 @@ const executeHermez = async () => {
// var tx = await goerliERC20Token.depositWithPermit("10", from, {returnTransaction: true});
// return console.log("hash", tx);
+ // // withdraw Ether
+ // var tx = await litchiEtherToken.withdraw("1", from, {returnTransaction: true});
+ // return console.log("hash", tx);
+
+ // // withdraw ERC20
+ // var tx = await litchiERC20Token.withdraw("1", from, {returnTransaction: true});
+ // return console.log("hash", tx);
+
// // withdraw exit ERC20
// var tx = await goerliERC20Token.withdrawExit("0x2df7caedb9a28b3110a43d5380c19d8f7d3a177aad4c8c11a07cbc46ce377654", {returnTransaction: true});
// return console.log("hash", tx);
-
// console.log("hash", await tx.getTransactionHash());
// console.log("receipt", await tx.getReceipt());
}

MODIFY
test/specs/hermez/erc20.spec.ts
test/specs/hermez/erc20.spec.ts
@@ -12,7 +12,7 @@ describe('ERC20', () => {
let etherChild = hermezClient.erc20(ether.child);
let etherParent = hermezClient.erc20(ether.parent, true);
- const abiManager = new ABIManager("testnet", "mumbai");
+ const abiManager = new ABIManager("testnet", "litchi");
before(() => {
return Promise.all([
abiManager.init()
@@ -185,7 +185,7 @@ describe('ERC20', () => {
returnTransaction: true
});
- const bridge = await abiManager.getConfig("Main.zkEVMContracts.BridgeProxy")
+ const bridge = await abiManager.getConfig("Main.Contracts.BridgeProxy")
expect(result['to'].toLowerCase()).equal(bridge.toLowerCase());
expect(Number(result['value'])).eq(10);
expect(result).to.have.property('data');
@@ -196,7 +196,7 @@ describe('ERC20', () => {
returnTransaction: true
});
- const bridge = await abiManager.getConfig("Main.zkEVMContracts.BridgeProxy")
+ const bridge = await abiManager.getConfig("Main.Contracts.BridgeProxy")
expect(result['to'].toLowerCase()).equal(bridge.toLowerCase());
expect(result).to.have.property('data');
});
@@ -206,7 +206,7 @@ describe('ERC20', () => {
returnTransaction: true
});
- const bridge = await abiManager.getConfig("Main.zkEVMContracts.BridgeProxy")
+ const bridge = await abiManager.getConfig("Main.Contracts.BridgeProxy")
expect(result['to'].toLowerCase()).equal(bridge.toLowerCase());
expect(result).to.have.property('data');
});
@@ -216,7 +216,7 @@ describe('ERC20', () => {
returnTransaction: true
});
- const bridge = await abiManager.getConfig("zkEVM.Contracts.BridgeProxy")
+ const bridge = await abiManager.getConfig("zkEVM.Contracts.Bridge")
expect(result['to'].toLowerCase()).equal(bridge.toLowerCase());
expect(result).to.have.property('data');
});
@@ -227,7 +227,7 @@ describe('ERC20', () => {
returnTransaction: true
});
- const bridge = await abiManager.getConfig("zkEVM.Contracts.BridgeProxy")
+ const bridge = await abiManager.getConfig("zkEVM.Contracts.Bridge")
expect(result['to'].toLowerCase()).equal(bridge.toLowerCase());
expect(result).to.have.property('data');
});
@@ -237,7 +237,7 @@ describe('ERC20', () => {
returnTransaction: true
});
- const bridge = await abiManager.getConfig("zkEVM.Contracts.BridgeProxy")
+ const bridge = await abiManager.getConfig("zkEVM.Contracts.Bridge")
expect(result['to'].toLowerCase()).equal(bridge.toLowerCase());
expect(Number(result['value'])).eq(1);
expect(result).to.have.property('data');
@@ -251,7 +251,7 @@ describe('ERC20', () => {
expect(result['data']).equal(
exitData
);
- const bridge = await abiManager.getConfig("Main.zkEVMContracts.BridgeProxy")
+ const bridge = await abiManager.getConfig("Main.Contracts.BridgeProxy")
expect(result['to'].toLowerCase()).equal(bridge.toLowerCase());
expect(result).to.have.property('data');
});

ADD
test/specs/hermez/hermez_client.spec.ts
+import { from, hermezClient, hermezClientForTo, privateKey, RPC, to, toPrivateKey } from "./client";
+import { expect } from 'chai'
+import { ABIManager } from '@maticnetwork/maticjs'
+import { providers, Wallet } from "ethers";
+
+
+describe('Hermez Client', () => {
+
+ const abiManager = new ABIManager("testnet", "litchi");
+ const parentPrivder = new providers.JsonRpcProvider(RPC.parent);
+ const childProvider = new providers.JsonRpcProvider(RPC.child);
+
+ before(() => {
+ return Promise.all([
+ hermezClient.init({
+ // log: true,
+ network: 'testnet',
+ version: 'litchi',
+ parent: {
+ provider: new Wallet(privateKey, parentPrivder),
+ defaultConfig: {
+ from
+ }
+ },
+ child: {
+ provider: new Wallet(privateKey, childProvider),
+ defaultConfig: {
+ from
+ }
+ }
+ }),
+ hermezClientForTo.init({
+ // log: true,
+ network: 'testnet',
+ version: 'litchi',
+ parent: {
+ provider: new Wallet(toPrivateKey, parentPrivder),
+ defaultConfig: {
+ from: to
+ }
+ },
+ child: {
+ provider: new Wallet(toPrivateKey, childProvider),
+ defaultConfig: {
+ from: to
+ }
+ }
+ }),
+ abiManager.init()
+ ]);
+ });
+});
\ No newline at end of file

ADD
test/specs/hermez/index.ts
+import { use } from "@maticnetwork/maticjs";
+import { Web3ClientPlugin } from "@maticnetwork/maticjs-ethers";
+
+use(Web3ClientPlugin);
+
+console.log('process.env.NODE_ENV', process.env.NODE_ENV);
+
+import './hermez_client.spec'
+import './erc20.spec'
\ No newline at end of file

MODIFY
test/specs/index.ts
test/specs/index.ts
@@ -5,13 +5,5 @@ use(Web3ClientPlugin);
console.log('process.env.NODE_ENV', process.env.NODE_ENV);
-import './map_promise.spec'
-
-// HERMEZ
-import './hermez/erc20.spec'
-
-// PoS
-// import './pos/pos_client.spec'
-// import './pos/erc20.spec'
-// import './pos/erc721.spec'
-// import './pos/erc1155.spec'
+import './pos'
+import './hermez'

ADD
test/specs/pos/index.ts
+import { use } from "@maticnetwork/maticjs";
+import { Web3ClientPlugin } from "@maticnetwork/maticjs-ethers";
+
+use(Web3ClientPlugin);
+
+console.log('process.env.NODE_ENV', process.env.NODE_ENV);
+
+import './pos_client.spec'
+import './erc20.spec'
+import './erc721.spec'
+import './erc1155.spec'
\ No newline at end of file

chg: new static structure variables