import { providers } from 'ethers'; import BaseService from '../commons/BaseService'; import { eEthereumTxType, EthereumTransactionTypeExtended, LendingPoolMarketConfig, tEthereumAddress, transactionType, } from '../commons/types'; import { FaucetValidator } from '../commons/validators/methodValidators'; import { isEthAddress } from '../commons/validators/paramValidators'; import { MockTokenFaucet } from './typechain/MockTokenFaucet'; import { MockTokenFaucet__factory } from './typechain/MockTokenFaucet__factory'; export type FaucetParamsType = { userAddress: tEthereumAddress; }; export interface FaucetInterface { mint: (args: FaucetParamsType) => EthereumTransactionTypeExtended[]; } export class FaucetService extends BaseService implements FaucetInterface { readonly faucetAddress: string; readonly faucetConfig: LendingPoolMarketConfig | undefined; constructor(provider: providers.Provider, faucetAddress?: string) { super(provider, MockTokenFaucet__factory); this.faucetAddress = faucetAddress ?? ''; } @FaucetValidator public mint( @isEthAddress('userAddress') { userAddress }: FaucetParamsType, ): EthereumTransactionTypeExtended[] { const faucetContract = this.getContractInstance(this.faucetAddress); const txCallback: () => Promise = this.generateTxCallback({ rawTxMethod: async () => faucetContract.populateTransaction.mint(userAddress), from: userAddress, }); return [ { tx: txCallback, txType: eEthereumTxType.FAUCET_MINT, gas: this.generateTxPriceEstimation([], txCallback), }, ]; } }