add eip1559 support
MODIFY
src/constant.ts
src/constant.ts
@@ -7,9 +7,6 @@ export const setWeb3Client = (web3Client) => {
Web3Client = web3Client;
}
-export const EXTRA_GAS_FOR_PROXY_CALL = 1000000
-
-
export const BIG_ONE = new BN(1)
export const BIG_TWO = new BN(2)
export const CHECKPOINT_INTERVAL = new BN(10000)

MODIFY
src/helpers/abi_helper.ts
src/helpers/abi_helper.ts
@@ -34,7 +34,7 @@ export class ABIManager {
});
}
- getAddress(path: string) {
+ getConfig(path: string) {
return resolve(
cache[this.networkName][this.version].address,
path

MODIFY
src/interfaces/transaction_config.ts
src/interfaces/transaction_config.ts
@@ -11,4 +11,6 @@ export interface ITransactionConfig {
chainId?: number;
chain?: string;
hardfork?: string;
+ maxFeePerGas?: number | string;
+ maxPriorityFeePerGas?: number | string;
}
\ No newline at end of file

MODIFY
src/utils/base_token.ts
src/utils/base_token.ts
@@ -2,7 +2,6 @@ import { Web3SideChainClient } from "./web3_side_chain_client";
import { ITransactionConfig, ITransactionOption, IContractInitParam, IPOSClientConfig, IBaseClientConfig } from "../interfaces";
import { BaseContractMethod, BaseContract, BaseWeb3Client } from "../abstracts";
import { Converter, merge } from "../utils";
-import { EXTRA_GAS_FOR_PROXY_CALL } from "../constant";
import { ContractWriteResult } from "../helpers";
import { promiseResolve } from "./promise_resolve";
import { ERROR_TYPE } from "../enums";
@@ -178,6 +177,12 @@ export class BaseToken<T_CLIENT_CONFIG> {
client.estimateGas(config);
};
if (isWrite) {
+ const { maxFeePerGas, maxPriorityFeePerGas } = txConfig;
+ const isEIP1559Supported = this.client.isEIP1559Supported(isParent);
+ if (!isParent && isEIP1559Supported && (maxFeePerGas || maxPriorityFeePerGas)) {
+ throw new Error(`Child chain doesn't support eip-1559`);
+ }
+
const [gasLimit, gasPrice, nonce, chainId] = await Promise.all([
!(txConfig.gasLimit)
? estimateGas({ from: txConfig.from, value: txConfig.value })
@@ -187,10 +192,17 @@ export class BaseToken<T_CLIENT_CONFIG> {
!txConfig.chainId ? client.getChainId() : txConfig.chainId,
]);
this.client.logger.log("options filled");
- txConfig.gasLimit = isParent ? Number(gasLimit) + EXTRA_GAS_FOR_PROXY_CALL : gasLimit;
- txConfig.gasPrice = gasPrice;
+ txConfig.gasLimit = Number(gasLimit);
txConfig.nonce = nonce;
txConfig.chainId = chainId;
+ if (isEIP1559Supported) {
+ txConfig.maxFeePerGas = maxFeePerGas;
+ txConfig.maxPriorityFeePerGas = maxPriorityFeePerGas;
+ }
+ else {
+ txConfig.gasPrice = Number(gasPrice);
+ }
+
}
return txConfig;
}

MODIFY
src/utils/bridge_client.ts
src/utils/bridge_client.ts
@@ -32,7 +32,7 @@ export class BridgeClient<T> {
"genesis",
).then(abi => {
const contract = client.child.getContract(
- client.abiManager.getAddress("Matic.GenesisContracts.StateReceiver"),
+ client.abiManager.getConfig("Matic.GenesisContracts.StateReceiver"),
abi
);
return Promise.all([

MODIFY
src/utils/web3_side_chain_client.ts
src/utils/web3_side_chain_client.ts
@@ -45,12 +45,21 @@ export class Web3SideChainClient<T_CONFIG> {
return this.abiManager.getABI(name, type);
}
+ getConfig(path: string) {
+ return this.abiManager.getConfig(path);
+ }
+
get mainPlasmaContracts() {
- return this.abiManager.getAddress("Main.Contracts");
+ return this.getConfig("Main.Contracts");
}
get mainPOSContracts() {
- return this.abiManager.getAddress("Main.POSContracts");
+ return this.getConfig("Main.POSContracts");
+ }
+
+ isEIP1559Supported(isParent: boolean): boolean {
+ return isParent ? this.getConfig("Main.SupportsEIP1559") :
+ this.getConfig("Matic.SupportsEIP1559");
}

MODIFY
test/specs/erc20.spec.ts
test/specs/erc20.spec.ts
@@ -50,14 +50,21 @@ describe('ERC20', () => {
// })
if (process.env.NODE_ENV === 'test_all') {
- // it('transfer', async () => {
- // const result = await erc20Child.transfer(to, '10');
- // const txHash = await result.getTransactionHash();
- // expect(txHash).to.be.an('string');
+ it('transfer', async () => {
+ const oldBalance = await erc20Child.getBalance(to);
+ console.log('oldBalance', oldBalance);
- // const txReceipt = await result.getReceipt();
- // expect(txReceipt).to.be.an('object');
- // });
+ const result = await erc20Child.transfer(to, '10');
+ const txHash = await result.getTransactionHash();
+ expect(txHash).to.be.an('string');
+ console.log('txHash', txHash);
+ const txReceipt = await result.getReceipt();
+ expect(txReceipt).to.be.an('object');
+
+ // const newBalance = await erc20Child.getBalance(to);
+ // console.log('newBalance', newBalance);
+
+ });
// it('approve', async () => {
// const result = await erc20Parent.approve('10');
@@ -70,14 +77,14 @@ describe('ERC20', () => {
// expect(txReceipt.type).equal('0x0');
// });
- it('deposit', async () => {
- const result = await erc20Parent.deposit('10', from);
+ // it('deposit', async () => {
+ // const result = await erc20Parent.deposit('10', from);
- const txHash = await result.getTransactionHash();
- expect(txHash).to.be.an('string');
+ // const txHash = await result.getTransactionHash();
+ // expect(txHash).to.be.an('string');
- const txReceipt = await result.getReceipt();
- expect(txReceipt).to.be.an('object');
- });
+ // const txReceipt = await result.getReceipt();
+ // expect(txReceipt).to.be.an('object');
+ // });
}
});
\ No newline at end of file

MODIFY
test/specs/index.ts
test/specs/index.ts
@@ -8,5 +8,5 @@ console.log('process.env.NODE_ENV', process.env.NODE_ENV);
import './map_promise.spec'
import './erc20.spec'
-import './erc721.spec'
+// import './erc721.spec'
// import './pos_bridge'

add eip1559 support