import { providers } from 'ethers'; import BaseService from '../commons/BaseService'; import { eEthereumTxType, EthereumTransactionTypeExtended, tEthereumAddress, transactionType, } from '../commons/types'; import { FlashClaimValidator } from '../commons/validators/methodValidators'; import { isEthAddress } from '../commons/validators/paramValidators'; import { AirdropFlashClaimReceiver } from './typechain/AirdropFlashClaimReceiver'; import { AirdropFlashClaimReceiver__factory } from './typechain/AirdropFlashClaimReceiver__factory'; import { IUserFlashclaimRegistry } from './typechain/IUserFlashclaimRegistry'; import { IUserFlashclaimRegistryFactory } from './typechain/IUserFlashclaimRegistryFactory'; export interface IUserFlashClaimServiceInterface { createReceiver: (user: tEthereumAddress) => EthereumTransactionTypeExtended[]; getUserReceivers: (user: tEthereumAddress) => Promise; } export class UserFlashClaimService extends BaseService implements IUserFlashClaimServiceInterface { readonly registryAddress: string; constructor(provider: providers.Provider, registryAddress?: string) { super(provider, IUserFlashclaimRegistryFactory); this.registryAddress = registryAddress ?? ''; this.createReceiver = this.createReceiver.bind(this); this.getUserReceivers = this.getUserReceivers.bind(this); } @FlashClaimValidator public createReceiver( @isEthAddress('user') user: tEthereumAddress, ): EthereumTransactionTypeExtended[] { const txs: EthereumTransactionTypeExtended[] = []; const registryContract: IUserFlashclaimRegistry = this.getContractInstance( this.registryAddress, ); const txCallback: () => Promise = this.generateTxCallback({ rawTxMethod: async () => registryContract.populateTransaction.createReceiver(), from: user, }); txs.push({ tx: txCallback, txType: eEthereumTxType.FLASHCLAIM_REGISTRY, gas: this.generateTxPriceEstimation([], txCallback), }); return txs; } @FlashClaimValidator public async getUserReceivers( @isEthAddress('user') user: tEthereumAddress, ): Promise { const registryContract: IUserFlashclaimRegistry = this.getContractInstance( this.registryAddress, ); return registryContract.getUserReceivers(user); } } export class AirdropFlashClaimReceiverService extends BaseService { readonly contractAddress: string; constructor(provider: providers.Provider, address: string) { super(provider, AirdropFlashClaimReceiver__factory); this.contractAddress = address; } public async batchTransferERC721({ user, token, to, tokenIds, }: { user: string; token: string; to: string; tokenIds: number[]; }) { const instance = this.getContractInstance(this.contractAddress); const txCallback: () => Promise = this.generateTxCallback({ rawTxMethod: async () => instance.populateTransaction.batchTransferERC721(token, to, tokenIds), from: user, }); return { tx: txCallback, txType: eEthereumTxType.OTHERS, gas: this.generateTxPriceEstimation([], txCallback), }; } }