Skip to content

Commit

Permalink
[GMS-1265] Add default gas overrides (#140)
Browse files Browse the repository at this point in the history
* add default gas overrides

* remove

* udpate gas config

---------

Co-authored-by: Allan Almeida <[email protected]>
  • Loading branch information
allan-almeida and allan-almeida-imtbl authored Dec 6, 2023
1 parent 720ed7d commit 85019e1
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 120 deletions.
7 changes: 7 additions & 0 deletions clients/config/overrides.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { CallOverrides } from "@ethersproject/contracts";

// https://docs.immutable.com/docs/zkEVM/architecture/gas-config
export const defaultGasOverrides: CallOverrides = {
maxPriorityFeePerGas: 10e9, // 10 Gwei
maxFeePerGas: 15e9,
};
13 changes: 7 additions & 6 deletions clients/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CallOverrides, PopulatedTransaction } from "@ethersproject/contracts";
import { ERC20 } from "../typechain-types/@openzeppelin/contracts/token/ERC20";
import { ERC20__factory } from "../typechain-types/factories/@openzeppelin/contracts/token/ERC20/ERC20__factory";
import { PromiseOrValue } from "../typechain-types/common";
import { defaultGasOverrides } from "./config/overrides";

export class ERC20Client {
private readonly contract: ERC20;
Expand All @@ -19,7 +20,7 @@ export class ERC20Client {
* @returns a promise that resolves with a BigNumber that represents the amount of tokens in existence
*/
public async totalSupply(provider: Provider, overrides: CallOverrides = {}): Promise<BigNumber> {
return this.contract.connect(provider).totalSupply(overrides);
return this.contract.connect(provider).totalSupply({ ...defaultGasOverrides, ...overrides });
}

/**
Expand All @@ -30,7 +31,7 @@ export class ERC20Client {
account: PromiseOrValue<string>,
overrides: CallOverrides = {}
): Promise<BigNumber> {
return this.contract.connect(provider).balanceOf(account, overrides);
return this.contract.connect(provider).balanceOf(account, { ...defaultGasOverrides, ...overrides });
}

/**
Expand All @@ -42,7 +43,7 @@ export class ERC20Client {
spender: PromiseOrValue<string>,
overrides: CallOverrides = {}
): Promise<BigNumber> {
return this.contract.connect(provider).allowance(owner, spender, overrides);
return this.contract.connect(provider).allowance(owner, spender, { ...defaultGasOverrides, ...overrides });
}

/**
Expand All @@ -53,7 +54,7 @@ export class ERC20Client {
amount: PromiseOrValue<BigNumberish>,
overrides: Overrides & { from?: PromiseOrValue<string> } = {}
): Promise<PopulatedTransaction> {
return this.contract.populateTransaction.transfer(to, amount, overrides);
return this.contract.populateTransaction.transfer(to, amount, { ...defaultGasOverrides, ...overrides });
}

/**
Expand All @@ -64,7 +65,7 @@ export class ERC20Client {
amount: PromiseOrValue<BigNumberish>,
overrides: Overrides & { from?: PromiseOrValue<string> } = {}
): Promise<PopulatedTransaction> {
return this.contract.populateTransaction.approve(spender, amount, overrides);
return this.contract.populateTransaction.approve(spender, amount, { ...defaultGasOverrides, ...overrides });
}

/**
Expand All @@ -76,6 +77,6 @@ export class ERC20Client {
amount: PromiseOrValue<BigNumberish>,
overrides: Overrides & { from?: PromiseOrValue<string> } = {}
): Promise<PopulatedTransaction> {
return this.contract.populateTransaction.transferFrom(from, to, amount, overrides);
return this.contract.populateTransaction.transferFrom(from, to, amount, { ...defaultGasOverrides, ...overrides });
}
}
Loading

0 comments on commit 85019e1

Please sign in to comment.