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 { SmartContractWithAddress } from './SmartContractWithAddress' export class AccessListContract extends SmartContractWithAddress { public abiEnterprise: AbiItem[] getDefaultAbi() { return AccessList.abi as AbiItem[] } /** * Instantiate AccessList class * @param {string} address The contract address. * @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( address: string, signer: Signer, network?: string | number, config?: Config, abi?: AbiItem[] ) { super(address, signer, network, config, abi) this.abi = abi || this.getDefaultAbi() } /** * Get Token Uri * @return {Promise} Token URI */ public async getTokenUri(tokenId: number): Promise { return await this.contract.tokenURI(tokenId) } /** * Get Owner * @return {Promise} Owner */ public async getOwner(): Promise { return await this.contract.owner() } /** * Get Id * @return {Promise} Id */ public async getId(): Promise { return await this.contract.getId() } /** * Get Name of Access list * @return {Promise} Name */ public async getName(): Promise { return await this.contract.name() } /** * Get Symbol of Access list * @return {Promise} Symbol */ public async getSymbol(): Promise { return await this.contract.symbol() } /** * Get Address Balance for access list token * @param {String} address user adress * @return {Promise} balance Number of datatokens. Will be converted from wei */ public async balance(address: string): Promise { const balance = await this.contract.balanceOf(address) return await this.unitsToAmount(null, balance, 18) } /** * Add address to access list * @param {String} user Minter address * @param {String} tokenUri tokenURI * @param {Boolean} estimateGas if True, return gas estimate * @return {Promise} returns the transaction receipt or the estimateGas value */ public async mint( user: string, tokenUri: string, estimateGas?: G ): Promise> { const estGas = await this.contract.estimateGas.mint(user, tokenUri) if (estimateGas) return >estGas const trxReceipt = await sendTx( estGas, this.getSignerAccordingSdk(), this.config?.gasFeeMultiplier, this.contract.mint, user, tokenUri ) return >trxReceipt } /** * Batch add addresses to the access list * @param {String} users Minter addresses * @param {String} tokenUris tokenURI * @param {Boolean} estimateGas if True, return gas estimate * @return {Promise} returns the transaction receipt or the estimateGas value */ public async batchMint( users: Array, tokenUris: Array, estimateGas?: G ): Promise> { const estGas = await this.contract.estimateGas.batchMint(users, tokenUris) if (estimateGas) return >estGas const trxReceipt = await sendTx( estGas, this.getSignerAccordingSdk(), this.config?.gasFeeMultiplier, this.contract.batchMint, users, tokenUris ) return >trxReceipt } /** * Delete address from access list * @param {Number} tokenId token ID * @param {Boolean} estimateGas if True, return gas estimate * @return {Promise} returns the transaction receipt or the estimateGas value */ public async burn( tokenId: number, estimateGas?: G ): Promise> { const estGas = await this.contract.estimateGas.burn(tokenId) if (estimateGas) return >estGas const trxReceipt = await sendTx( estGas, this.getSignerAccordingSdk(), this.config?.gasFeeMultiplier, this.contract.burn, tokenId ) return >trxReceipt } /** * Transfer Ownership of an access list, called by owner of access list * @param {Number} newOwner new owner of the access list * @param {Boolean} estimateGas if True, return gas estimate * @return {Promise} returns the transaction receipt or the estimateGas value */ public async transferOwnership( newOwner: string, estimateGas?: G ): Promise> { const estGas = await this.contract.estimateGas.transferOwnership(newOwner) if (estimateGas) return >estGas const trxReceipt = await sendTx( estGas, this.getSignerAccordingSdk(), this.config?.gasFeeMultiplier, this.contract.transferOwnership, newOwner ) return >trxReceipt } /** * Renounce Ownership of an access list, called by owner of access list * @param {Boolean} estimateGas if True, return gas estimate * @return {Promise} returns the transaction receipt or the estimateGas value */ public async renounceOwnership( estimateGas?: G ): Promise> { const estGas = await this.contract.estimateGas.renounceOwnership() if (estimateGas) return >estGas const trxReceipt = await sendTx( estGas, this.getSignerAccordingSdk(), this.config?.gasFeeMultiplier, this.contract.renounceOwnership ) return >trxReceipt } }