Skip to content

Commit

Permalink
Revert "remove clients"
Browse files Browse the repository at this point in the history
This reverts commit 7443666.

# Conflicts:
#	package.json
#	tsconfig.json
  • Loading branch information
allan-almeida-imtbl committed Apr 26, 2024
1 parent 61a2b23 commit 11ab358
Show file tree
Hide file tree
Showing 7 changed files with 1,298 additions and 0 deletions.
8 changes: 8 additions & 0 deletions clients/config/overrides.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CallOverrides } from "@ethersproject/contracts";

// https://docs.immutable.com/docs/zkEVM/architecture/gas-config
export const defaultGasOverrides: CallOverrides = {
maxPriorityFeePerGas: 10e9, // 10 Gwei
maxFeePerGas: 15e9,
gasLimit: 200000, // Expected when setting the above properties
};
82 changes: 82 additions & 0 deletions clients/erc20.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { Overrides } from "ethers";
import { Provider } from "@ethersproject/providers";
import { BigNumberish, BigNumber } from "@ethersproject/bignumber";
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;

constructor(contractAddress: string) {
const factory = new ERC20__factory();
this.contract = factory.attach(contractAddress);
}

/**
* @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);
}

/**
* @returns a promise that resolves with a BigNumber that represents the amount of tokens owned by account
*/
public async balanceOf(
provider: Provider,
account: PromiseOrValue<string>,
overrides: CallOverrides = {},
): Promise<BigNumber> {
return this.contract.connect(provider).balanceOf(account, overrides);
}

/**
* @returns a promise that resolves with a BigNumber that represents the remaining number of tokens that spender will be allowed to spend on behalf of owner through transferFrom
*/
public async allowance(
provider: Provider,
owner: PromiseOrValue<string>,
spender: PromiseOrValue<string>,
overrides: CallOverrides = {},
): Promise<BigNumber> {
return this.contract.connect(provider).allowance(owner, spender, overrides);
}

/**
* @returns a promise that resolves with a populated transaction
*/
public async populateTransfer(
to: PromiseOrValue<string>,
amount: PromiseOrValue<BigNumberish>,
overrides: Overrides & { from?: PromiseOrValue<string> } = {},
): Promise<PopulatedTransaction> {
return this.contract.populateTransaction.transfer(to, amount, { ...defaultGasOverrides, ...overrides });
}

/**
* @returns a promise that resolves with a populated transaction
*/
public async populateApprove(
spender: PromiseOrValue<string>,
amount: PromiseOrValue<BigNumberish>,
overrides: Overrides & { from?: PromiseOrValue<string> } = {},
): Promise<PopulatedTransaction> {
return this.contract.populateTransaction.approve(spender, amount, { ...defaultGasOverrides, ...overrides });
}

/**
* @returns a promise that resolves with a populated transaction
*/
public async populateTransferFrom(
from: PromiseOrValue<string>,
to: PromiseOrValue<string>,
amount: PromiseOrValue<BigNumberish>,
overrides: Overrides & { from?: PromiseOrValue<string> } = {},
): Promise<PopulatedTransaction> {
return this.contract.populateTransaction.transferFrom(from, to, amount, { ...defaultGasOverrides, ...overrides });
}
}
Loading

0 comments on commit 11ab358

Please sign in to comment.