import { MockTrueCurrency , TrueFiPool2 , FixedTermLoanAgency , } from 'contracts' ; import { BigNumber , Wallet } from 'ethers' ; import { DAY } from './constants' ; export const setUtilization = async ( tusd , borrower1 , borrower2 , ftlAgency , owner , pool , utilization ) => { if ( utilization === 0 ) { return ; } await ftlAgency . allowBorrower ( borrower1 . address ) ; const poolValue = await pool . poolValue ( ) ; const utilizationAmount = poolValue . mul ( utilization ) . div ( 100 ) ; if ( utilization <= 15 ) { await ftlAgency . connect ( borrower1 ) . borrow ( pool . address , utilizationAmount , DAY , 2000 ) ; return ; } if ( utilization <= 30 ) { await ftlAgency . connect ( borrower1 ) . borrow ( pool . address , poolValue . mul ( 15 ) . div ( 100 ) , DAY , 2000 ) ; } else { await tusd . mint ( owner . address , poolValue . mul ( 9 ) ) ; await tusd . connect ( owner ) . approve ( pool . address , poolValue . mul ( 9 ) ) ; await pool . connect ( owner ) . join ( poolValue . mul ( 9 ) ) ; await ftlAgency . connect ( borrower1 ) . borrow ( pool . address , utilizationAmount , DAY , 2000 ) ; await pool . connect ( owner ) . liquidExit ( poolValue . mul ( 89 ) . div ( 10 ) ) ; } await ftlAgency . allowBorrower ( borrower2 . address ) ; let loanAmount = ( await pool . liquidValue ( ) ) . sub ( BigNumber . from ( ( 100 - utilization ) * 100 ) . mul ( await pool . poolValue ( ) ) . div ( 10000 ) ) ; const liquidityLeft = await pool . liquidValue ( ) ; if ( loanAmount . gt ( liquidityLeft ) ) { loanAmount = liquidityLeft ; } await ftlAgency . connect ( borrower2 ) . borrow ( pool . address , loanAmount , DAY , 50000 ) ; } ;