-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GMS-1103] Add erc20 contract client (#98)
* add erc20 client * upgrade to yarn * update index * udpate workflows * clean up * fix lint * add test publish --------- Co-authored-by: Allan Almeida <[email protected]>
- Loading branch information
1 parent
81dc875
commit 70fa817
Showing
13 changed files
with
9,919 additions
and
19,610 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ artifacts | |
cache | ||
coverage | ||
typechain | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
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"; | ||
|
||
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, 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, 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, overrides); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { ERC721 as ERC721Client } from "./erc721"; | ||
export { ERC721MintByID as ERC721MintByIDClient } from "./erc721-mint-by-id"; | ||
export { ERC20Client } from "./erc20"; | ||
export { ERC721Client } from "./erc721"; | ||
export { ERC721MintByIDClient } from "./erc721-mint-by-id"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
|
||
abstract contract ImmutableERC20 is ERC20 {} |
Oops, something went wrong.