import { DebtToken__factory , LoanFactory2 , FixedTermLoan__factory , TestLegacyLoanToken2__factory , TestLoanFactory , TestTrueLender , TrueFiPool2 , } from 'contracts' ; import { BigNumberish , Wallet } from 'ethers' ; export const createLoan = async function ( factory , creator , pool , amount , duration , apy ) { const fakeFTLA = creator ; const originalFTLA_address = await factory . ftlAgency ( ) ; await factory . setFixedTermLoanAgency ( fakeFTLA . address ) ; const loanTx = await factory . connect ( fakeFTLA ) . createLoanToken ( pool . address , creator . address , amount , duration , apy ) ; await factory . setFixedTermLoanAgency ( originalFTLA_address ) ; const loanAddress = ( await loanTx . wait ( ) ) . events [ 1 ] . args . loanToken ; return new FixedTermLoan__factory ( creator ) . attach ( loanAddress ) ; } ; export const createDebtToken = async ( loanFactory , creditAgency , owner , pool , borrower , debt ) => { await loanFactory . setCreditAgency ( creditAgency . address ) ; const tx = await loanFactory . connect ( creditAgency ) . createDebtToken ( pool . address , borrower . address , debt ) ; const creationEvent = ( await tx . wait ( ) ) . events [ 1 ] ; return DebtToken__factory . connect ( creationEvent . args . debtToken , owner ) ; } ; export const createLegacyLoan = async ( loanFactory , pool , lender , owner , borrower , amount , term , apy ) => { const tx = await loanFactory . createLegacyLoanToken ( pool . address , borrower . address , amount , term , apy ) ; const receipt = await tx . wait ( ) ; const loan = TestLegacyLoanToken2__factory . connect ( receipt . events [ 0 ] . args [ 0 ] , owner ) ; await loan . setLender ( lender . address ) ; return loan ; } ;