diff --git a/clients/config/overrides.ts b/clients/config/overrides.ts new file mode 100644 index 00000000..88f44b0e --- /dev/null +++ b/clients/config/overrides.ts @@ -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 +}; diff --git a/clients/erc20.ts b/clients/erc20.ts new file mode 100644 index 00000000..82ed985b --- /dev/null +++ b/clients/erc20.ts @@ -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 { + 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, + overrides: CallOverrides = {}, + ): Promise { + 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, + spender: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return this.contract.connect(provider).allowance(owner, spender, overrides); + } + + /** + * @returns a promise that resolves with a populated transaction + */ + public async populateTransfer( + to: PromiseOrValue, + amount: PromiseOrValue, + overrides: Overrides & { from?: PromiseOrValue } = {}, + ): Promise { + return this.contract.populateTransaction.transfer(to, amount, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a promise that resolves with a populated transaction + */ + public async populateApprove( + spender: PromiseOrValue, + amount: PromiseOrValue, + overrides: Overrides & { from?: PromiseOrValue } = {}, + ): Promise { + return this.contract.populateTransaction.approve(spender, amount, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a promise that resolves with a populated transaction + */ + public async populateTransferFrom( + from: PromiseOrValue, + to: PromiseOrValue, + amount: PromiseOrValue, + overrides: Overrides & { from?: PromiseOrValue } = {}, + ): Promise { + return this.contract.populateTransaction.transferFrom(from, to, amount, { ...defaultGasOverrides, ...overrides }); + } +} diff --git a/clients/erc721-mint-by-id.ts b/clients/erc721-mint-by-id.ts new file mode 100644 index 00000000..0b8c7c84 --- /dev/null +++ b/clients/erc721-mint-by-id.ts @@ -0,0 +1,545 @@ +import type { BigNumber, BigNumberish, BytesLike, CallOverrides, Overrides, PopulatedTransaction } from "ethers"; +import type { Provider } from "@ethersproject/providers"; + +import { ImmutableERC721MintByID__factory } from "../typechain-types/factories/contracts/token/erc721/preset/ImmutableERC721MintByID__factory"; +import { + ImmutableERC721Base, + ImmutableERC721MintByID, +} from "../typechain-types/contracts/token/erc721/preset/ImmutableERC721MintByID"; +import { PromiseOrValue } from "../typechain-types/common"; +import { defaultGasOverrides } from "./config/overrides"; + +// Struct for specifying token IDs to mint to an address. +export type IDMint = ImmutableERC721Base.IDMintStruct; + +// Struct for transferring multiple tokens between two addresses. +export type TransferRequest = ImmutableERC721Base.TransferRequestStruct; + +// Struct for safe burning multiple tokens from a single address. +export type IDBurn = ImmutableERC721Base.IDBurnStruct; + +export class ERC721MintByIDClient { + private readonly contract: ImmutableERC721MintByID; + + constructor(contractAddress: string) { + const factory = new ImmutableERC721MintByID__factory(); + this.contract = factory.attach(contractAddress); + } + + /** + * Read functions + */ + + /** + * @returns the DEFAULT_ADMIN_ROLE as a string. + */ + public async DEFAULT_ADMIN_ROLE(provider: Provider, overrides: CallOverrides = {}): Promise { + return await this.contract.connect(provider).DEFAULT_ADMIN_ROLE(overrides); + } + + /** + * @returns the MINTER_ROLE as a string. + */ + public async MINTER_ROLE(provider: Provider, overrides: CallOverrides = {}): Promise { + return await this.contract.connect(provider).MINTER_ROLE(overrides); + } + + /** + * @returns the balance of an address as a BigNumber. + */ + public async balanceOf( + provider: Provider, + owner: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.connect(provider).balanceOf(owner, overrides); + } + + /** + * @returns the baseURI as a string. + */ + public async baseURI(provider: Provider, overrides: CallOverrides = {}): Promise { + return await this.contract.connect(provider).baseURI(overrides); + } + + /** + * @returns the contractURI as a string. + */ + public async contractURI(provider: Provider, overrides: CallOverrides = {}): Promise { + return await this.contract.connect(provider).contractURI(overrides); + } + + /** + * @returns admin addresses as an array of strings. + */ + public async getAdmins(provider: Provider, overrides: CallOverrides = {}): Promise { + return await this.contract.connect(provider).getAdmins(overrides); + } + + /** + * @returns the approved address for a token ID, or zero if no address set. + */ + public async getApproved( + provider: Provider, + tokenId: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.connect(provider).getApproved(tokenId, overrides); + } + + /** + * @returns the role admin address. + */ + public async getRoleAdmin( + provider: Provider, + role: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.connect(provider).getRoleAdmin(role, overrides); + } + + /** + * @returns the role member address at a particular index. + */ + public async getRoleMember( + provider: Provider, + role: PromiseOrValue, + index: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.connect(provider).getRoleMember(role, index, overrides); + } + + /** + * @returns the role member count as a BigNumber. + */ + public async getRoleMemberCount( + provider: Provider, + role: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.connect(provider).getRoleMemberCount(role, overrides); + } + + /** + * @returns a boolean for whether an account has a particular role. + */ + public async hasRole( + provider: Provider, + role: PromiseOrValue, + account: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.connect(provider).hasRole(role, account, overrides); + } + + /** + * @returns a booolean that tells whether an operator is approved by a given owner. + */ + public async isApprovedForAll( + provider: Provider, + owner: PromiseOrValue, + operator: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.connect(provider).isApprovedForAll(owner, operator, overrides); + } + + /** + * @returns the name of the contract as a string. + */ + public async name(provider: Provider, overrides: CallOverrides = {}): Promise { + return await this.contract.connect(provider).name(overrides); + } + + /** + * @returns the owner address of a particular tokenId. + */ + public async ownerOf( + provider: Provider, + tokenId: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.connect(provider).ownerOf(tokenId, overrides); + } + + /** + * Returns the current nonce of a given token ID. + * @param tokenId The ID of the token for which to retrieve the nonce. + * @return Current nonce of the given token. + */ + public async nonces( + provider: Provider, + tokenId: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.connect(provider).nonces(tokenId, overrides); + } + + /** + * @returns the operator allowlist as a string. + */ + public async operatorAllowlist(provider: Provider, overrides: CallOverrides = {}): Promise { + return await this.contract.connect(provider).operatorAllowlist(overrides); + } + + /** + * @returns the royalty information for a particular tokenId. + */ + public async royaltyInfo( + provider: Provider, + _tokenId: PromiseOrValue, + _salePrice: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise<[string, BigNumber]> { + return await this.contract.connect(provider).royaltyInfo(_tokenId, _salePrice, overrides); + } + + /** + * @returns the symbol of the contract as a string. + */ + public async symbol(provider: Provider, overrides: CallOverrides = {}): Promise { + return await this.contract.connect(provider).symbol(overrides); + } + + /** + * @returns the Uniform Resource Identifier (URI) for tokenId token. + */ + public async tokenURI( + provider: Provider, + tokenId: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.connect(provider).tokenURI(tokenId, overrides); + } + + /** + * @returns returns the total amount of tokens stored by the contract. + */ + public async totalSupply(provider: Provider, overrides: CallOverrides = {}): Promise { + return await this.contract.connect(provider).totalSupply(overrides); + } + + /** + * Write functions + */ + + /** + * @returns a populated transaction for the approve contract function + */ + public async populateApprove( + to: PromiseOrValue, + tokenId: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.approve(to, tokenId, { ...defaultGasOverrides, ...overrides }); + } + + /** + * Function to approve by way of owner signature + * @param spender the address to approve + * @param tokenId the index of the NFT to approve the spender on + * @param deadline a timestamp expiry for the permit + * @param sig a traditional or EIP-2098 signature + */ + public async populatePermit( + spender: PromiseOrValue, + tokenId: PromiseOrValue, + deadline: PromiseOrValue, + sig: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.populateTransaction.permit(spender, tokenId, deadline, sig, { + ...defaultGasOverrides, + ...overrides, + }); + } + + /** + * @returns a populated transaction for the burn contract function + */ + public async populateBurn( + tokenId: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.burn(tokenId, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the batch burn contract function + */ + public async populateBurnBatch( + tokenIds: PromiseOrValue[], + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.burnBatch(tokenIds, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the grantMinterRole contract function + */ + public async populateGrantMinterRole( + user: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.grantMinterRole(user, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the grantRole contract function + */ + public async populateGrantRole( + role: PromiseOrValue, + account: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.grantRole(role, account, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the mint contract function + */ + public async populateMint( + to: PromiseOrValue, + tokenId: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.mint(to, tokenId, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the batch mint contract function + */ + public async populateSafeMintBatch( + mints: IDMint[], + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.safeMintBatch(mints, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the safe burn contract function + */ + public async populateSafeBurn( + owner: PromiseOrValue, + tokenId: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.safeBurn(owner, tokenId, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the safe burn batch contract function + */ + public async populateSafeBurnBatch( + burns: IDBurn[], + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.safeBurnBatch(burns, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the renounceRole contract function + */ + public async populateRenounceRole( + role: PromiseOrValue, + account: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.renounceRole(role, account, { + ...defaultGasOverrides, + ...overrides, + }); + } + + /** + * @returns a populated transaction for the revokeMinterRole contract function + */ + public async populateRevokeMinterRole( + user: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.revokeMinterRole(user, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the revokeRole contract function + */ + public async populateRevokeRole( + role: PromiseOrValue, + account: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.revokeRole(role, account, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the batch save transfer from function + */ + public async populateSafeTransferFromBatch( + transfers: TransferRequest, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.safeTransferFromBatch(transfers, { + ...defaultGasOverrides, + ...overrides, + }); + } + + /** + * @returns a populated transaction for the safeTransferFrom(address,address,uint256) contract function + */ + public async "populateSafeTransferFrom(address,address,uint256)"( + from: PromiseOrValue, + to: PromiseOrValue, + tokenId: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction["safeTransferFrom(address,address,uint256)"](from, to, tokenId, { + ...defaultGasOverrides, + ...overrides, + }); + } + + /** + * @returns a populated transaction for the safeTransferFrom(address,address,uint256,bytes) contract function + */ + public async "populateSafeTransferFrom(address,address,uint256,bytes)"( + from: PromiseOrValue, + to: PromiseOrValue, + tokenId: PromiseOrValue, + data: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction["safeTransferFrom(address,address,uint256,bytes)"]( + from, + to, + tokenId, + data, + { ...defaultGasOverrides, ...overrides }, + ); + } + + /** + * @returns a populated transaction for the setApprovalForAll contract function + */ + public async populateSetApprovalForAll( + operator: PromiseOrValue, + approved: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.setApprovalForAll(operator, approved, { + ...defaultGasOverrides, + ...overrides, + }); + } + + /** + * @returns a populated transaction for the setBaseURI contract function + */ + public async populateSetBaseURI( + baseURI_: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.setBaseURI(baseURI_, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the setContractURI contract function + */ + public async populateSetContractURI( + _contractURI: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.setContractURI(_contractURI, { + ...defaultGasOverrides, + ...overrides, + }); + } + + /** + * @returns a populated transaction for the setDefaultRoyaltyReceiver contract function + */ + public async populateSetDefaultRoyaltyReceiver( + receiver: PromiseOrValue, + feeNumerator: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.setDefaultRoyaltyReceiver(receiver, feeNumerator, { + ...defaultGasOverrides, + ...overrides, + }); + } + + /** + * @returns a populated transaction for the setNFTRoyaltyReceiver contract function + */ + public async populateSetNFTRoyaltyReceiver( + tokenId: PromiseOrValue, + receiver: PromiseOrValue, + feeNumerator: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.setNFTRoyaltyReceiver(tokenId, receiver, feeNumerator, { + ...defaultGasOverrides, + ...overrides, + }); + } + + /** + * @returns a populated transaction for the setNFTRoyaltyReceiverBatch contract function + */ + public async populateSetNFTRoyaltyReceiverBatch( + tokenIds: PromiseOrValue[], + receiver: PromiseOrValue, + feeNumerator: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.setNFTRoyaltyReceiverBatch(tokenIds, receiver, feeNumerator, { + ...defaultGasOverrides, + ...overrides, + }); + } +} diff --git a/clients/erc721.ts b/clients/erc721.ts new file mode 100644 index 00000000..c7a0f24f --- /dev/null +++ b/clients/erc721.ts @@ -0,0 +1,658 @@ +import type { BigNumber, BigNumberish, BytesLike, CallOverrides, Overrides, PopulatedTransaction } from "ethers"; +import type { Provider } from "@ethersproject/providers"; + +import { ImmutableERC721__factory } from "../typechain-types/factories/contracts/token/erc721/preset/ImmutableERC721__factory"; +import { ImmutableERC721, ERC721Hybrid } from "../typechain-types/contracts/token/erc721/preset/ImmutableERC721"; +import { PromiseOrValue } from "../typechain-types/common"; +import { defaultGasOverrides } from "./config/overrides"; + +// Struct for specifying token IDs to mint to an address, by quantity. +export type Mint = ERC721Hybrid.MintStruct; + +// Struct for specifying token IDs to mint to an address. +export type IDMint = ERC721Hybrid.IDMintStruct; + +// Struct for transferring multiple tokens between two addresses. +export type TransferRequest = ERC721Hybrid.TransferRequestStruct; + +// Struct for burning multiple tokens from the same address +export type IDBurn = ERC721Hybrid.IDBurnStruct; + +export class ERC721Client { + private readonly contract: ImmutableERC721; + + constructor(contractAddress: string) { + const factory = new ImmutableERC721__factory(); + this.contract = factory.attach(contractAddress); + } + + /** + * Read functions + */ + + /** + * @returns the DEFAULT_ADMIN_ROLE as a string. + */ + public async DEFAULT_ADMIN_ROLE(provider: Provider, overrides: CallOverrides = {}): Promise { + return await this.contract.connect(provider).DEFAULT_ADMIN_ROLE(overrides); + } + + /** + * Returns the domain separator used in the encoding of the signature for permits, as defined by EIP-712 + * @return the bytes32 domain separator + */ + public async DOMAIN_SEPARATOR(provider: Provider, overrides: CallOverrides = {}): Promise { + return await this.contract.connect(provider).DOMAIN_SEPARATOR(overrides); + } + + /** + * @returns the MINTER_ROLE as a string. + */ + public async MINTER_ROLE(provider: Provider, overrides: CallOverrides = {}): Promise { + return await this.contract.connect(provider).MINTER_ROLE(overrides); + } + + /** + * @returns the balance of an address as a BigNumber. + */ + public async balanceOf( + provider: Provider, + owner: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.connect(provider).balanceOf(owner, overrides); + } + + /** + * @returns the baseURI as a string. + */ + public async baseURI(provider: Provider, overrides: CallOverrides = {}): Promise { + return await this.contract.connect(provider).baseURI(overrides); + } + + /** + * @returns the contractURI as a string. + */ + public async contractURI(provider: Provider, overrides: CallOverrides = {}): Promise { + return await this.contract.connect(provider).contractURI(overrides); + } + + /** + * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712 + * signature. + */ + public async eip712Domain( + provider: Provider, + overrides: CallOverrides = {}, + ): Promise< + [string, string, string, BigNumber, string, string, BigNumber[]] & { + fields: string; + name: string; + version: string; + chainId: BigNumber; + verifyingContract: string; + salt: string; + extensions: BigNumber[]; + } + > { + return await this.contract.connect(provider).eip712Domain(overrides); + } + + /** + * @returns admin addresses as an array of strings. + */ + public async getAdmins(provider: Provider, overrides: CallOverrides = {}): Promise { + return await this.contract.connect(provider).getAdmins(overrides); + } + + /** + * @returns the approved address for a token ID, or zero if no address set. + */ + public async getApproved( + provider: Provider, + tokenId: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.connect(provider).getApproved(tokenId, overrides); + } + + /** + * @returns the role admin address. + */ + public async getRoleAdmin( + provider: Provider, + role: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.connect(provider).getRoleAdmin(role, overrides); + } + + /** + * @returns the role member address at a particular index. + */ + public async getRoleMember( + provider: Provider, + role: PromiseOrValue, + index: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.connect(provider).getRoleMember(role, index, overrides); + } + + /** + * @returns the role member count as a BigNumber. + */ + public async getRoleMemberCount( + provider: Provider, + role: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.connect(provider).getRoleMemberCount(role, overrides); + } + + /** + * @returns a boolean for whether an account has a particular role. + */ + public async hasRole( + provider: Provider, + role: PromiseOrValue, + account: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.connect(provider).hasRole(role, account, overrides); + } + + /** + * @returns a booolean that tells whether an operator is approved by a given owner. + */ + public async isApprovedForAll( + provider: Provider, + owner: PromiseOrValue, + operator: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.connect(provider).isApprovedForAll(owner, operator, overrides); + } + + /** + * @returns the name of the contract as a string. + */ + public async name(provider: Provider, overrides: CallOverrides = {}): Promise { + return await this.contract.connect(provider).name(overrides); + } + + /** + * @returns the owner address of a particular tokenId. + */ + public async ownerOf( + provider: Provider, + tokenId: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.connect(provider).ownerOf(tokenId, overrides); + } + + /** + * Returns the current nonce of a given token ID. + * @param tokenId The ID of the token for which to retrieve the nonce. + * @return Current nonce of the given token. + */ + public async nonces( + provider: Provider, + tokenId: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.connect(provider).nonces(tokenId, overrides); + } + + /** + * @returns the operator allowlist as a string. + */ + public async operatorAllowlist(provider: Provider, overrides: CallOverrides = {}): Promise { + return await this.contract.connect(provider).operatorAllowlist(overrides); + } + + /** + * @returns the royalty information for a particular tokenId. + */ + public async royaltyInfo( + provider: Provider, + _tokenId: PromiseOrValue, + _salePrice: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise<[string, BigNumber]> { + return await this.contract.connect(provider).royaltyInfo(_tokenId, _salePrice, overrides); + } + + /** + * @returns the symbol of the contract as a string. + */ + public async symbol(provider: Provider, overrides: CallOverrides = {}): Promise { + return await this.contract.connect(provider).symbol(overrides); + } + + /** + * @returns the Uniform Resource Identifier (URI) for tokenId token. + */ + public async tokenURI( + provider: Provider, + tokenId: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.connect(provider).tokenURI(tokenId, overrides); + } + + /** + * @returns returns the total amount of tokens stored by the contract. + */ + public async totalSupply(provider: Provider, overrides: CallOverrides = {}): Promise { + return await this.contract.connect(provider).totalSupply(overrides); + } + + /** + * Write functions + */ + + /** + * @returns a populated transaction for the approve contract function + */ + public async populateApprove( + to: PromiseOrValue, + tokenId: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.approve(to, tokenId, { ...defaultGasOverrides, ...overrides }); + } + + /** + * Function to approve by way of owner signature + * @param spender the address to approve + * @param tokenId the index of the NFT to approve the spender on + * @param deadline a timestamp expiry for the permit + * @param sig a traditional or EIP-2098 signature + */ + public async populatePermit( + spender: PromiseOrValue, + tokenId: PromiseOrValue, + deadline: PromiseOrValue, + sig: PromiseOrValue, + overrides: CallOverrides = {}, + ): Promise { + return await this.contract.populateTransaction.permit(spender, tokenId, deadline, sig, { + ...defaultGasOverrides, + ...overrides, + }); + } + + /** + * @returns a populated transaction for the burn contract function + */ + public async populateBurn( + tokenId: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.burn(tokenId, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the batch burn contract function + */ + public async populateBurnBatch( + tokenIds: PromiseOrValue[], + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.burnBatch(tokenIds, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the safe burn contract function + */ + public async populateSafeBurn( + owner: PromiseOrValue, + tokenId: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.safeBurn(owner, tokenId, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the safe burn batch contract function + */ + public async populateSafeBurnBatch( + burns: IDBurn[], + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.safeBurnBatch(burns, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the grantMinterRole contract function + */ + public async populateGrantMinterRole( + user: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.grantMinterRole(user, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the grantRole contract function + */ + public async populateGrantRole( + role: PromiseOrValue, + account: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.grantRole(role, account, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the mint by ID contract function + */ + public async populateMint( + to: PromiseOrValue, + tokenId: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.mint(to, tokenId, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the safe mint by ID contract function + */ + public async populateSafeMint( + to: PromiseOrValue, + tokenId: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.safeMint(to, tokenId, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the mint by quantity contract function + */ + public async populateMintByQuantity( + to: PromiseOrValue, + quantity: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.mintByQuantity(to, quantity, { + ...defaultGasOverrides, + ...overrides, + }); + } + + /** + * @returns a populated transaction for the safe mint by quantity contract function + */ + public async populateSafeMintByQuantity( + to: PromiseOrValue, + quantity: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.safeMintByQuantity(to, quantity, { + ...defaultGasOverrides, + ...overrides, + }); + } + + /** + * @returns a populated transaction for the batch mint by quantity contract function + */ + public async populateMintBatchByQuantity( + mints: Mint[], + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.mintBatchByQuantity(mints, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the batch safe mint by quantity contract function + */ + public async populateSafeMintBatchByQuantity( + mints: Mint[], + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.safeMintBatchByQuantity(mints, { + ...defaultGasOverrides, + ...overrides, + }); + } + + /** + * @returns a populated transaction for the batch mint by ID to multiple recipients contract function + */ + public async populateMintBatch( + mints: IDMint[], + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.mintBatch(mints, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the batch safe mint by ID to multiple recipients contract function + */ + public async populateSafeMintBatch( + mints: IDMint[], + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.safeMintBatch(mints, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the renounceRole contract function + */ + public async populateRenounceRole( + role: PromiseOrValue, + account: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.renounceRole(role, account, { + ...defaultGasOverrides, + ...overrides, + }); + } + + /** + * @returns a populated transaction for the revokeMinterRole contract function + */ + public async populateRevokeMinterRole( + user: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.revokeMinterRole(user, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the revokeRole contract function + */ + public async populateRevokeRole( + role: PromiseOrValue, + account: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.revokeRole(role, account, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the batch save transfer from function + */ + public async populateSafeTransferFromBatch( + transfers: TransferRequest, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.safeTransferFromBatch(transfers, { + ...defaultGasOverrides, + ...overrides, + }); + } + + /** + * @returns a populated transaction for the safeTransferFrom(address,address,uint256) contract function + */ + public async "populateSafeTransferFrom(address,address,uint256)"( + from: PromiseOrValue, + to: PromiseOrValue, + tokenId: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction["safeTransferFrom(address,address,uint256)"](from, to, tokenId, { + ...defaultGasOverrides, + ...overrides, + }); + } + + /** + * @returns a populated transaction for the safeTransferFrom(address,address,uint256,bytes) contract function + */ + public async "populateSafeTransferFrom(address,address,uint256,bytes)"( + from: PromiseOrValue, + to: PromiseOrValue, + tokenId: PromiseOrValue, + data: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction["safeTransferFrom(address,address,uint256,bytes)"]( + from, + to, + tokenId, + data, + { ...defaultGasOverrides, ...overrides }, + ); + } + + /** + * @returns a populated transaction for the setApprovalForAll contract function + */ + public async populateSetApprovalForAll( + operator: PromiseOrValue, + approved: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.setApprovalForAll(operator, approved, { + ...defaultGasOverrides, + ...overrides, + }); + } + + /** + * @returns a populated transaction for the setBaseURI contract function + */ + public async populateSetBaseURI( + baseURI_: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.setBaseURI(baseURI_, { ...defaultGasOverrides, ...overrides }); + } + + /** + * @returns a populated transaction for the setContractURI contract function + */ + public async populateSetContractURI( + _contractURI: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.setContractURI(_contractURI, { + ...defaultGasOverrides, + ...overrides, + }); + } + + /** + * @returns a populated transaction for the setDefaultRoyaltyReceiver contract function + */ + public async populateSetDefaultRoyaltyReceiver( + receiver: PromiseOrValue, + feeNumerator: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.setDefaultRoyaltyReceiver(receiver, feeNumerator, { + ...defaultGasOverrides, + ...overrides, + }); + } + + /** + * @returns a populated transaction for the setNFTRoyaltyReceiver contract function + */ + public async populateSetNFTRoyaltyReceiver( + tokenId: PromiseOrValue, + receiver: PromiseOrValue, + feeNumerator: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.setNFTRoyaltyReceiver(tokenId, receiver, feeNumerator, { + ...defaultGasOverrides, + ...overrides, + }); + } + + /** + * @returns a populated transaction for the setNFTRoyaltyReceiverBatch contract function + */ + public async populateSetNFTRoyaltyReceiverBatch( + tokenIds: PromiseOrValue[], + receiver: PromiseOrValue, + feeNumerator: PromiseOrValue, + overrides: Overrides & { + from?: PromiseOrValue; + } = {}, + ): Promise { + return await this.contract.populateTransaction.setNFTRoyaltyReceiverBatch(tokenIds, receiver, feeNumerator, { + ...defaultGasOverrides, + ...overrides, + }); + } +} diff --git a/clients/index.ts b/clients/index.ts new file mode 100644 index 00000000..e434df2e --- /dev/null +++ b/clients/index.ts @@ -0,0 +1,3 @@ +export { ERC20Client } from "./erc20"; +export { ERC721Client } from "./erc721"; +export { ERC721MintByIDClient } from "./erc721-mint-by-id"; diff --git a/index.ts b/index.ts new file mode 100644 index 00000000..b8fd0ad6 --- /dev/null +++ b/index.ts @@ -0,0 +1 @@ +export * from "./clients"; diff --git a/package.json b/package.json index e96039d8..17c13d1d 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "test": "hardhat test", "prettier:solidity": "./node_modules/.bin/prettier --write --plugin=prettier-plugin-solidity contracts/**/*.sol", "lint": "eslint . --ext .ts,.tsx --fix && solhint --config ./.solhint.json contracts/**/*.sol", + "eslint": "eslint clients --ext .ts,.tsx", "solhint": "solhint --config ./.solhint.json", "clean": "hardhat clean", "coverage": "hardhat coverage"