import { providers } from 'ethers'; import BaseService from '../commons/BaseService'; import { eEthereumTxType, EthereumTransactionTypeExtended, tEthereumAddress, transactionType, } from '../commons/types'; import { isEthAddress, isValidTokenIdArray, } from '../commons/validators/paramValidators'; import { Moonbirds } from './typechain/Moonbirds'; import { Moonbirds__factory } from './typechain/Moonbirds__factory'; export interface MoonBirdsSafeTransferWhileNestingParams { from: string; to: string; tokenIds: number[]; } export interface MoonBirdsInterface { safeTransferWhileNesting: ( args: MoonBirdsSafeTransferWhileNestingParams, ) => EthereumTransactionTypeExtended[]; } export class MoonBirdsService extends BaseService implements MoonBirdsInterface { readonly moonBirdsAddress: string; constructor( provider: providers.Provider, moonBirdsAddress: tEthereumAddress, ) { super(provider, Moonbirds__factory); this.moonBirdsAddress = moonBirdsAddress; this.safeTransferWhileNesting = this.safeTransferWhileNesting.bind(this); } public safeTransferWhileNesting( @isEthAddress('from') @isEthAddress('to') @isValidTokenIdArray('tokenIds') { from, to, tokenIds }: MoonBirdsSafeTransferWhileNestingParams, ): EthereumTransactionTypeExtended[] { const moonBirdsContract = this.getContractInstance(this.moonBirdsAddress); return tokenIds.map(tokenId => { const tx: () => Promise = this.generateTxCallback({ rawTxMethod: async () => moonBirdsContract.populateTransaction.safeTransferWhileNesting( from, to, tokenId, ), from, }); return { tx, txType: eEthereumTxType.MOONBIRD_SAFE_TRANSFER_WHILE_NESTING, gas: this.generateTxPriceEstimation([], tx), }; }); } }