Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧠 Add integration test for tfUSDC reclaim price drop #1177

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions test/integration/trueLender2ReclaimPriceDrop.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { CONTRACTS_OWNER, forkChain } from './suite'
import { TrueFiPool2, TrueFiPool2__factory, TrueLender2Deprecated, TrueLender2Deprecated__factory } from 'contracts'
import { expect, use } from 'chai'
import { solidity } from 'ethereum-waffle'
import { parseEth } from 'utils'

use(solidity)

describe('TrueLender2.reclaim', () => {
const TFUSDC_ADDRESS = '0xA991356d261fbaF194463aF6DF8f0464F8f1c742'
const TRUELENDER2_ADDRESS = '0xa606dd423dF7dFb65Efe14ab66f5fDEBf62FF583'
const LOAN_ADDRESS = '0x8768f87B31c9B97c35F21b4149eD70E678957B9D'
const ETH_HOLDER = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
const BLOCK_NUMBER = 14650636 // 2022/04/25
const PRECISION = 0.0000001

let trueLender2: TrueLender2Deprecated
let tfUSDC: TrueFiPool2

const tfUSDCPrice = async () => {
return (await tfUSDC.poolValue()).toNumber() / (await tfUSDC.totalSupply()).toNumber()
}

beforeEach(async () => {
const provider = forkChain([CONTRACTS_OWNER, ETH_HOLDER], BLOCK_NUMBER - 1)

const contractsOwner = provider.getSigner(CONTRACTS_OWNER)
trueLender2 = TrueLender2Deprecated__factory.connect(TRUELENDER2_ADDRESS, contractsOwner)
tfUSDC = TrueFiPool2__factory.connect(TFUSDC_ADDRESS, contractsOwner)

const ethHolder = provider.getSigner(ETH_HOLDER)
await ethHolder.sendTransaction({ value: parseEth(100), to: CONTRACTS_OWNER })
})

it('with nonzero fee causes price drop', async () => {
expect(await trueLender2.fee()).to.be.gt(0)

const oldPrice = await tfUSDCPrice()
await trueLender2.reclaim(LOAN_ADDRESS, '0x')

expect(await tfUSDCPrice()).to.not.be.closeTo(oldPrice, PRECISION)
expect(await tfUSDCPrice()).to.be.lt(oldPrice)
})

it('with zero fee does not affect price', async () => {
await trueLender2.setFee(0)

const oldPrice = await tfUSDCPrice()
await trueLender2.reclaim(LOAN_ADDRESS, '0x')

expect(await tfUSDCPrice()).to.be.closeTo(oldPrice, PRECISION)
})
})