import { JsonRpcSigner, ContractTransactionResponse, ContractTransactionReceipt, } from 'ethers' import { CONTRACT_CORECARD } from '../../../constants' import Erc721TokenContract from './erc721' import ABI from './MTCoreCardABI.json' export type MTCoreCardLevel = 0 | 1 | 2 | 3 | 4 export default class MTCoreCardContract extends Erc721TokenContract { constructor(provider: JsonRpcSigner) { super(CONTRACT_CORECARD, provider) this.ABI = ABI } async mint( level: MTCoreCardLevel, price: string, address?: string ): Promise { const useAddress = address ?? (await this.getCallerAddress()) const contract = this.getInstance() const tx: ContractTransactionResponse = await contract.mint( useAddress, level, { value: price, } ) const txwait = await tx.wait() if (!txwait) { throw new Error('Transaction failed') } return txwait } async getMintPrice(level: MTCoreCardLevel): Promise { const contract = this.getInstance() const bn = await contract.getMintPrice(level) return bn.toString() } async getAllMintPrice(): Promise<[string, string, string, string, string]> { const lv0 = await this.getMintPrice(0) const lv1 = await this.getMintPrice(1) const lv2 = await this.getMintPrice(2) const lv3 = await this.getMintPrice(3) const lv4 = await this.getMintPrice(4) return [lv0, lv1, lv2, lv3, lv4] } }