diff --git a/src/contracts/AccessList.ts b/src/contracts/AccessList.ts new file mode 100644 index 00000000..6950e4ef --- /dev/null +++ b/src/contracts/AccessList.ts @@ -0,0 +1,119 @@ +import { Signer } from 'ethers' +import AccessList from '@oceanprotocol/contracts/artifacts/contracts/accesslists/AccessList.sol/AccessList.json' +import { sendTx } from '../utils' +import { AbiItem, ReceiptOrEstimate } from '../@types' +import { Config } from '../config' +import { SmartContract } from './SmartContract' + +export class AccessList extends SmartContract { + public abiEnterprise: AbiItem[] + + getDefaultAbi() { + return AccessList.abi as AbiItem[] + } + + /** + * Instantiate AccessList class + * @param {Signer} signer The signer object. + * @param {string | number} [network] Network id or name + * @param {Config} [config] The configuration object. + * @param {AbiItem[]} [abi] ABI array of the smart contract + * @param {AbiItem[]} abiEnterprise Enterprise ABI array of the smart contract + */ + constructor( + signer: Signer, + network?: string | number, + config?: Config, + abi?: AbiItem[], + abiEnterprise?: AbiItem[] + ) { + super(signer, network, config, abi) + this.abiEnterprise = abiEnterprise || (AccessList.abi as AbiItem[]) + } + + /** + * Get Token Uri + * @return {Promise} Token URI + */ + public async getTokenUri(accessListAddress: string): Promise { + const accessListContract = this.getContract(accessListAddress) + return await accessListContract.tokenURI() + } + + /** + * Mint ERC721 contract + * @param {String} accessListAddress AccessList contract address + * @param {String} user Minter address + * @param {String} tokenUri tokenURI + * @param {Boolean} estimateGas if True, return gas estimate + * @return {Promise} transactionId + */ + public async mint( + accessListAddress: string, + user: string, + tokenUri: string, + estimateGas?: G + ): Promise> { + const accessListContract = this.getContract(accessListAddress) + const estGas = await accessListContract.estimateGas.mint(user, tokenUri) + if (estimateGas) return >estGas + + const trxReceipt = await sendTx( + estGas, + this.signer, + this.config?.gasFeeMultiplier, + accessListContract.mint, + user, + tokenUri + ) + return >trxReceipt + } + + /** + * Batch Mint ERC721 contract + * @param {String} accessListAddress AccessList contract address + * @param {String} users Minter addresses + * @param {String} tokenUris tokenURI + * @param {Boolean} estimateGas if True, return gas estimate + * @return {Promise} transactionId + */ + public async batchMint( + accessListAddress: string, + users: Array, + tokenUris: Array, + estimateGas?: G + ): Promise> { + const accessListContract = this.getContract(accessListAddress) + const estGas = await accessListContract.estimateGas.batchMint(users, tokenUris) + if (estimateGas) return >estGas + + const trxReceipt = await sendTx( + estGas, + this.signer, + this.config?.gasFeeMultiplier, + accessListContract.batchMint, + users, + tokenUris + ) + return >trxReceipt + } + + public async burn( + accessListAddress: string, + tokenId: number, + estimateGas?: G + ): Promise> { + const accessListContract = this.getContract(accessListAddress) + const estGas = await accessListContract.estimateGas.burn(tokenId) + if (estimateGas) return >estGas + + const trxReceipt = await sendTx( + estGas, + this.signer, + this.config?.gasFeeMultiplier, + accessListContract.burn, + tokenId + ) + return >trxReceipt + } +}