mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
* Created AccessList contract. * Created new Datatoken4 template. * set file object fc. * integrated datatoken 4 contract. * install new version of ocean contracts. * added sapphire sdk + remove private functions. * tweaks of template4. * wrap signer on access list contract. * Added minimum gas fees for sapphire networks. Send function. * Convert to contract functions. Remove abiEnterprise. * Upgraded contracts v2.2.0. * Integrated Access List factory. Created tests. * Rename file. * Add script for testing sapphire functionality. * Remove sapphire sdk from accesslist contract. * Added new functions to access list contract. * Remove script. * Remove script. * Increase timeout to the tests. * Added js script. Modified gitignore. * Install tsx, added oasis testnet into config helpers. * Modified provider signature. * fix lint. * Fix type module. * commented ordering other assets different than URL. * Added check for file object for template index. * fix deploy erc20 template 4 test. * Calculate index function. Fix review. * Change to this.signer. * Uncommented orders. * Upgrade Github actions. * Condition for calculation of template index. * Specify ABI in the tests. * Test w soulbound contracts. * Fixed wallet address for test. * Add deny list check. * Store access list address within the constructor. Added tests. * add debug log. * Create new datatoken for consumer. * distinguish coverage reports. * Fix coverage download report. * cleanup. added tests. * fix tests. * Remove unused imports. * Increase timeout. * Added test with encrypted tx. * comment the test file. * Add test back + add ABI. * added debug log. * increase timeout. * Comment tests with external services. * fix graphql URL. * Insert arweave. * Insert ipfs. * cleanup. mention ipfs issue. * Fixes. Added getFilesObject back. * fix review. * replace srv id w srv index. * Fix doc. * Remove wrap call from constructor. * Modify README. * Added check for tx. * fix check. * remove duplicate test.
203 lines
6.0 KiB
TypeScript
203 lines
6.0 KiB
TypeScript
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<string>} Token URI
|
|
*/
|
|
public async getTokenUri(tokenId: number): Promise<string> {
|
|
return await this.contract.tokenURI(tokenId)
|
|
}
|
|
|
|
/**
|
|
* Get Owner
|
|
* @return {Promise<string>} Owner
|
|
*/
|
|
public async getOwner(): Promise<string> {
|
|
return await this.contract.owner()
|
|
}
|
|
|
|
/**
|
|
* Get Id
|
|
* @return {Promise<string>} Id
|
|
*/
|
|
public async getId(): Promise<number> {
|
|
return await this.contract.getId()
|
|
}
|
|
|
|
/**
|
|
* Get Name of Access list
|
|
* @return {Promise<string>} Name
|
|
*/
|
|
public async getName(): Promise<string> {
|
|
return await this.contract.name()
|
|
}
|
|
|
|
/**
|
|
* Get Symbol of Access list
|
|
* @return {Promise<string>} Symbol
|
|
*/
|
|
public async getSymbol(): Promise<string> {
|
|
return await this.contract.symbol()
|
|
}
|
|
|
|
/**
|
|
* Get Address Balance for access list token
|
|
* @param {String} address user adress
|
|
* @return {Promise<String>} balance Number of datatokens. Will be converted from wei
|
|
*/
|
|
public async balance(address: string): Promise<string> {
|
|
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<ReceiptOrEstimate>} returns the transaction receipt or the estimateGas value
|
|
*/
|
|
public async mint<G extends boolean = false>(
|
|
user: string,
|
|
tokenUri: string,
|
|
estimateGas?: G
|
|
): Promise<ReceiptOrEstimate<G>> {
|
|
const estGas = await this.contract.estimateGas.mint(user, tokenUri)
|
|
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
|
|
|
|
const trxReceipt = await sendTx(
|
|
estGas,
|
|
this.signer,
|
|
this.config?.gasFeeMultiplier,
|
|
this.contract.mint,
|
|
user,
|
|
tokenUri
|
|
)
|
|
return <ReceiptOrEstimate<G>>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<ReceiptOrEstimate>} returns the transaction receipt or the estimateGas value
|
|
*/
|
|
public async batchMint<G extends boolean = false>(
|
|
users: Array<string>,
|
|
tokenUris: Array<string>,
|
|
estimateGas?: G
|
|
): Promise<ReceiptOrEstimate<G>> {
|
|
const estGas = await this.contract.estimateGas.batchMint(users, tokenUris)
|
|
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
|
|
|
|
const trxReceipt = await sendTx(
|
|
estGas,
|
|
this.signer,
|
|
this.config?.gasFeeMultiplier,
|
|
this.contract.batchMint,
|
|
users,
|
|
tokenUris
|
|
)
|
|
return <ReceiptOrEstimate<G>>trxReceipt
|
|
}
|
|
|
|
/**
|
|
* Delete address from access list
|
|
* @param {Number} tokenId token ID
|
|
* @param {Boolean} estimateGas if True, return gas estimate
|
|
* @return {Promise<ReceiptOrEstimate>} returns the transaction receipt or the estimateGas value
|
|
*/
|
|
public async burn<G extends boolean = false>(
|
|
tokenId: number,
|
|
estimateGas?: G
|
|
): Promise<ReceiptOrEstimate<G>> {
|
|
const estGas = await this.contract.estimateGas.burn(tokenId)
|
|
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
|
|
|
|
const trxReceipt = await sendTx(
|
|
estGas,
|
|
this.signer,
|
|
this.config?.gasFeeMultiplier,
|
|
this.contract.burn,
|
|
tokenId
|
|
)
|
|
return <ReceiptOrEstimate<G>>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<ReceiptOrEstimate>} returns the transaction receipt or the estimateGas value
|
|
*/
|
|
public async transferOwnership<G extends boolean = false>(
|
|
newOwner: string,
|
|
estimateGas?: G
|
|
): Promise<ReceiptOrEstimate<G>> {
|
|
const estGas = await this.contract.estimateGas.transferOwnership(newOwner)
|
|
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
|
|
|
|
const trxReceipt = await sendTx(
|
|
estGas,
|
|
this.signer,
|
|
this.config?.gasFeeMultiplier,
|
|
this.contract.transferOwnership,
|
|
newOwner
|
|
)
|
|
return <ReceiptOrEstimate<G>>trxReceipt
|
|
}
|
|
|
|
/**
|
|
* Renounce Ownership of an access list, called by owner of access list
|
|
* @param {Boolean} estimateGas if True, return gas estimate
|
|
* @return {Promise<ReceiptOrEstimate>} returns the transaction receipt or the estimateGas value
|
|
*/
|
|
public async renounceOwnership<G extends boolean = false>(
|
|
estimateGas?: G
|
|
): Promise<ReceiptOrEstimate<G>> {
|
|
const estGas = await this.contract.estimateGas.renounceOwnership()
|
|
if (estimateGas) return <ReceiptOrEstimate<G>>estGas
|
|
|
|
const trxReceipt = await sendTx(
|
|
estGas,
|
|
this.signer,
|
|
this.config?.gasFeeMultiplier,
|
|
this.contract.renounceOwnership
|
|
)
|
|
return <ReceiptOrEstimate<G>>trxReceipt
|
|
}
|
|
}
|