mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Created AccessList contract.
This commit is contained in:
parent
1f4e4336dd
commit
87a7a0134b
119
src/contracts/AccessList.ts
Normal file
119
src/contracts/AccessList.ts
Normal file
@ -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<string>} Token URI
|
||||||
|
*/
|
||||||
|
public async getTokenUri(accessListAddress: string): Promise<string> {
|
||||||
|
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<ReceiptOrEstimate>} transactionId
|
||||||
|
*/
|
||||||
|
public async mint<G extends boolean = false>(
|
||||||
|
accessListAddress: string,
|
||||||
|
user: string,
|
||||||
|
tokenUri: string,
|
||||||
|
estimateGas?: G
|
||||||
|
): Promise<ReceiptOrEstimate<G>> {
|
||||||
|
const accessListContract = this.getContract(accessListAddress)
|
||||||
|
const estGas = await accessListContract.estimateGas.mint(user, tokenUri)
|
||||||
|
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
|
||||||
|
|
||||||
|
const trxReceipt = await sendTx(
|
||||||
|
estGas,
|
||||||
|
this.signer,
|
||||||
|
this.config?.gasFeeMultiplier,
|
||||||
|
accessListContract.mint,
|
||||||
|
user,
|
||||||
|
tokenUri
|
||||||
|
)
|
||||||
|
return <ReceiptOrEstimate<G>>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<ReceiptOrEstimate>} transactionId
|
||||||
|
*/
|
||||||
|
public async batchMint<G extends boolean = false>(
|
||||||
|
accessListAddress: string,
|
||||||
|
users: Array<string>,
|
||||||
|
tokenUris: Array<string>,
|
||||||
|
estimateGas?: G
|
||||||
|
): Promise<ReceiptOrEstimate<G>> {
|
||||||
|
const accessListContract = this.getContract(accessListAddress)
|
||||||
|
const estGas = await accessListContract.estimateGas.batchMint(users, tokenUris)
|
||||||
|
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
|
||||||
|
|
||||||
|
const trxReceipt = await sendTx(
|
||||||
|
estGas,
|
||||||
|
this.signer,
|
||||||
|
this.config?.gasFeeMultiplier,
|
||||||
|
accessListContract.batchMint,
|
||||||
|
users,
|
||||||
|
tokenUris
|
||||||
|
)
|
||||||
|
return <ReceiptOrEstimate<G>>trxReceipt
|
||||||
|
}
|
||||||
|
|
||||||
|
public async burn<G extends boolean = false>(
|
||||||
|
accessListAddress: string,
|
||||||
|
tokenId: number,
|
||||||
|
estimateGas?: G
|
||||||
|
): Promise<ReceiptOrEstimate<G>> {
|
||||||
|
const accessListContract = this.getContract(accessListAddress)
|
||||||
|
const estGas = await accessListContract.estimateGas.burn(tokenId)
|
||||||
|
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
|
||||||
|
|
||||||
|
const trxReceipt = await sendTx(
|
||||||
|
estGas,
|
||||||
|
this.signer,
|
||||||
|
this.config?.gasFeeMultiplier,
|
||||||
|
accessListContract.burn,
|
||||||
|
tokenId
|
||||||
|
)
|
||||||
|
return <ReceiptOrEstimate<G>>trxReceipt
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user