import BigNumberJs from 'bignumber.js'; import { providers } from 'ethers'; import BaseService from '../commons/BaseService'; import { eEthereumTxType, EthereumTransactionTypeExtended, tEthereumAddress, transactionType, } from '../commons/types'; import { isEthAddress } from '../commons/validators/paramValidators'; import { ParaSpaceAidrop } from './typechain/ParaSpaceAidrop'; import { ParaSpaceAidrop__factory } from './typechain/ParaSpaceAidrop__factory'; export type AirdropStatus = { amount: BigNumberJs; claimed: boolean; }; export class ParaspaceApeAirdrop extends BaseService { instance: ParaSpaceAidrop; constructor(provider: providers.Provider, address: string) { super(provider, ParaSpaceAidrop__factory); this.instance = this.getContractInstance(address); } public async userStatus( @isEthAddress('user') user: tEthereumAddress, ): Promise { const { amount, claimed } = await this.instance.userStatus(user); return { amount: new BigNumberJs(amount.toString()), claimed }; } public claimAirdrop( @isEthAddress('user') user: tEthereumAddress, ): EthereumTransactionTypeExtended[] { const txs: EthereumTransactionTypeExtended[] = []; const txCallback: () => Promise = this.generateTxCallback({ rawTxMethod: async () => this.instance.populateTransaction.claimAidrop(), from: user, }); txs.push({ tx: txCallback, txType: eEthereumTxType.OTHERS, gas: this.generateTxPriceEstimation([], txCallback), }); return txs; } }