From b54e44e96348df0d68b6e33d694b510be77e824e Mon Sep 17 00:00:00 2001 From: Yuchen Lin Date: Thu, 13 Oct 2022 02:16:24 -0700 Subject: [PATCH 1/6] Set tfTOKEN.deficitValue() to zero without affecting SAFU --- contracts/truefi2/SAFU.sol | 14 +++++++++++--- test/truefi2/SAFU.test.ts | 23 +++++++++++++++++++---- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/contracts/truefi2/SAFU.sol b/contracts/truefi2/SAFU.sol index 5ae26c035..052313d39 100644 --- a/contracts/truefi2/SAFU.sol +++ b/contracts/truefi2/SAFU.sol @@ -36,7 +36,7 @@ contract SAFU is ISAFU, UpgradeableClaimable { I1Inch3 public _1Inch; mapping(ILoanToken2 => IDeficiencyToken) public override deficiencyToken; - mapping(address => uint256) public override poolDeficit; + mapping(address => uint256) public internalPoolDeficit; // ======= STORAGE DECLARATION END ============ @@ -80,6 +80,14 @@ contract SAFU is ISAFU, UpgradeableClaimable { _1Inch = __1Inch; } + /** + * @dev Dummy view so that tfTOKEN.deficitValue() discounts deficiency tokens to zero value. + * Does not affect SAFU internal deficiency token tracking. + */ + function poolDeficit(address) external override view returns (uint256) { + return 0; + } + /** * @dev Liquidates a defaulted Loan, withdraws a portion of tru from staking pool * then tries to cover the loan with own funds, to compensate TrueFiPool @@ -104,7 +112,7 @@ contract SAFU is ISAFU, UpgradeableClaimable { deficit = owedToPool.sub(safuTokenBalance); toTransfer = safuTokenBalance; deficiencyToken[loan] = new DeficiencyToken(loan, deficit); - poolDeficit[address(loan.pool())] = poolDeficit[address(loan.pool())].add(deficit); + internalPoolDeficit[address(loan.pool())] = internalPoolDeficit[address(loan.pool())].add(deficit); } token.safeTransfer(address(pool), toTransfer); emit Liquidated(loan, toTransfer, deficiencyToken[loan], deficit); @@ -145,7 +153,7 @@ contract SAFU is ISAFU, UpgradeableClaimable { require(address(dToken) != address(0), "SAFU: No deficiency token found for loan"); require(dToken.balanceOf(poolAddress) > 0, "SAFU: Pool does not have deficiency tokens to be reclaimed"); - poolDeficit[poolAddress] = poolDeficit[poolAddress].sub(amount); + internalPoolDeficit[poolAddress] = internalPoolDeficit[poolAddress].sub(amount); dToken.burnFrom(msg.sender, amount); loan.token().safeTransfer(poolAddress, amount); diff --git a/test/truefi2/SAFU.test.ts b/test/truefi2/SAFU.test.ts index c12b39a2a..d82e6d759 100644 --- a/test/truefi2/SAFU.test.ts +++ b/test/truefi2/SAFU.test.ts @@ -142,7 +142,12 @@ describe('SAFU', () => { expect(await safu.deficiencyToken(loan.address)).to.eq(AddressZero) }) - it('increases pool deficit', async () => { + it('increases internal pool deficit', async () => { + await safu.liquidate(loan.address) + expect(await safu.internalPoolDeficit(pool.address)).to.eq(0) + }) + + it('does not move pool deficit from zero', async () => { await safu.liquidate(loan.address) expect(await safu.poolDeficit(pool.address)).to.eq(0) }) @@ -175,9 +180,14 @@ describe('SAFU', () => { expect(await safu.deficiencyToken(loan.address)).to.eq(deficiencyToken) }) - it('increases pool deficit', async () => { + it('increases internal pool deficit', async () => { + await safu.liquidate(loan.address) + expect(await safu.internalPoolDeficit(pool.address)).to.eq(defaultAmount.div(2)) + }) + + it('does not move pool deficit from zero', async () => { await safu.liquidate(loan.address) - expect(await safu.poolDeficit(pool.address)).to.eq(defaultAmount.div(2)) + expect(await safu.poolDeficit(pool.address)).to.eq(0) }) it('emits event', async () => { @@ -298,7 +308,12 @@ describe('SAFU', () => { expect(await dToken.totalSupply()).to.eq(0) }) - it('decreases pool deficit', async () => { + it('decreases internal pool deficit', async () => { + await pool.reclaimDeficit(loan.address) + expect(await safu.internalPoolDeficit(pool.address)).to.eq(0) + }) + + it('does not move pool deficit from zero', async () => { await pool.reclaimDeficit(loan.address) expect(await safu.poolDeficit(pool.address)).to.eq(0) }) From 43f2f54a3255ac618b2f79cb282b7075d57f77d1 Mon Sep 17 00:00:00 2001 From: Yuchen Lin Date: Thu, 13 Oct 2022 03:17:29 -0700 Subject: [PATCH 2/6] Do not let SAFU immediately repay debt on liquidation --- contracts/truefi2/SAFU.sol | 27 ++++++++--------------- test/truefi2/SAFU.test.ts | 44 ++++++++++++++++++++------------------ 2 files changed, 32 insertions(+), 39 deletions(-) diff --git a/contracts/truefi2/SAFU.sol b/contracts/truefi2/SAFU.sol index 052313d39..81d0ec0bc 100644 --- a/contracts/truefi2/SAFU.sol +++ b/contracts/truefi2/SAFU.sol @@ -51,7 +51,7 @@ contract SAFU is ISAFU, UpgradeableClaimable { /** * @dev Emitted when a loan gets liquidated * @param loan Loan that has been liquidated - * @param repaid Amount repaid to the pool + * @param repaid DEPRECATED Amount repaid to the pool * @param deficiencyToken Deficiency token representing a deficit that is owed to the pool by SAFU * @param deficit Deficit amount that SAFU still owes the pool */ @@ -89,9 +89,8 @@ contract SAFU is ISAFU, UpgradeableClaimable { } /** - * @dev Liquidates a defaulted Loan, withdraws a portion of tru from staking pool - * then tries to cover the loan with own funds, to compensate TrueFiPool - * If SAFU does not have enough funds, deficit is saved to be redeemed later + * @dev Liquidates a defaulted Loan and withdraws a portion of tru from staking pool + * to compensate TrueFiPool. Deficit is saved to be redeemed later * @param loan Loan to be liquidated */ function liquidate(ILoanToken2 loan) external { @@ -99,23 +98,15 @@ contract SAFU is ISAFU, UpgradeableClaimable { require(loan.status() == ILoanToken2.Status.Defaulted, "SAFU: Loan is not defaulted"); ITrueFiPool2 pool = ITrueFiPool2(loan.pool()); - IERC20 token = IERC20(pool.token()); liquidator.liquidate(loan); pool.liquidate(loan); - uint256 owedToPool = loan.debt().mul(tokenBalance(loan)).div(loan.totalSupply()); - uint256 safuTokenBalance = tokenBalance(token); - - uint256 deficit = 0; - uint256 toTransfer = owedToPool; - if (owedToPool > safuTokenBalance) { - deficit = owedToPool.sub(safuTokenBalance); - toTransfer = safuTokenBalance; - deficiencyToken[loan] = new DeficiencyToken(loan, deficit); - internalPoolDeficit[address(loan.pool())] = internalPoolDeficit[address(loan.pool())].add(deficit); - } - token.safeTransfer(address(pool), toTransfer); - emit Liquidated(loan, toTransfer, deficiencyToken[loan], deficit); + + uint256 deficit = loan.debt().mul(tokenBalance(loan)).div(loan.totalSupply()); + deficiencyToken[loan] = new DeficiencyToken(loan, deficit); + internalPoolDeficit[address(pool)] = internalPoolDeficit[address(pool)].add(deficit); + + emit Liquidated(loan, 0, deficiencyToken[loan], deficit); } /** diff --git a/test/truefi2/SAFU.test.ts b/test/truefi2/SAFU.test.ts index d82e6d759..4cda2d3b8 100644 --- a/test/truefi2/SAFU.test.ts +++ b/test/truefi2/SAFU.test.ts @@ -116,7 +116,7 @@ describe('SAFU', () => { }) }) - describe('Handles debt repay', () => { + describe('Does not repay debt', () => { beforeEach(async () => { await timeTravel(DAY * 400) await loan.enterDefault() @@ -127,24 +127,25 @@ describe('SAFU', () => { await token.mint(safu.address, defaultAmount) }) - it('takes funds from safu', async () => { + it('does not take funds from safu', async () => { await expect(() => safu.liquidate(loan.address)) - .to.changeTokenBalance(token, safu, defaultAmount.mul(-1)) + .to.changeTokenBalance(token, safu, 0) }) - it('transfers funds to the pool', async () => { + it('does not transfer funds to the pool', async () => { await expect(() => safu.liquidate(loan.address)) - .to.changeTokenBalance(token, pool, defaultAmount) + .to.changeTokenBalance(token, pool, 0) }) it('sets deficiencyToken', async () => { - await safu.liquidate(loan.address) - expect(await safu.deficiencyToken(loan.address)).to.eq(AddressZero) + const tx = await safu.liquidate(loan.address) + const deficiencyToken = (await tx.wait()).events[7].args.deficiencyToken + expect(await safu.deficiencyToken(loan.address)).to.eq(deficiencyToken) }) it('increases internal pool deficit', async () => { await safu.liquidate(loan.address) - expect(await safu.internalPoolDeficit(pool.address)).to.eq(0) + expect(await safu.internalPoolDeficit(pool.address)).to.eq(defaultAmount) }) it('does not move pool deficit from zero', async () => { @@ -153,9 +154,10 @@ describe('SAFU', () => { }) it('emits event', async () => { - await expect(safu.liquidate(loan.address)) + const tx = await safu.liquidate(loan.address) + await expect(tx) .to.emit(safu, 'Liquidated') - .withArgs(loan.address, defaultAmount, AddressZero, 0) + .withArgs(loan.address, 0, await safu.deficiencyToken(loan.address), defaultAmount) }) }) @@ -164,25 +166,25 @@ describe('SAFU', () => { await token.mint(safu.address, defaultAmount.div(2)) }) - it('takes funds from safu', async () => { + it('does not take funds from safu', async () => { await expect(() => safu.liquidate(loan.address)) - .to.changeTokenBalance(token, safu, defaultAmount.div(2).mul(-1)) + .to.changeTokenBalance(token, safu, 0) }) - it('transfers funds to the pool', async () => { + it('does not transfer funds to the pool', async () => { await expect(() => safu.liquidate(loan.address)) - .to.changeTokenBalance(token, pool, defaultAmount.div(2)) + .to.changeTokenBalance(token, pool, 0) }) it('sets deficiencyToken', async () => { const tx = await safu.liquidate(loan.address) - const deficiencyToken = (await tx.wait()).events[8].args.deficiencyToken + const deficiencyToken = (await tx.wait()).events[7].args.deficiencyToken expect(await safu.deficiencyToken(loan.address)).to.eq(deficiencyToken) }) it('increases internal pool deficit', async () => { await safu.liquidate(loan.address) - expect(await safu.internalPoolDeficit(pool.address)).to.eq(defaultAmount.div(2)) + expect(await safu.internalPoolDeficit(pool.address)).to.eq(defaultAmount) }) it('does not move pool deficit from zero', async () => { @@ -194,7 +196,7 @@ describe('SAFU', () => { const tx = await safu.liquidate(loan.address) await expect(tx) .to.emit(safu, 'Liquidated') - .withArgs(loan.address, defaultAmount.div(2), await safu.deficiencyToken(loan.address), defaultAmount.div(2)) + .withArgs(loan.address, 0, await safu.deficiencyToken(loan.address), defaultAmount) }) }) }) @@ -303,7 +305,7 @@ describe('SAFU', () => { it('burns deficiency tokens', async () => { const dToken = new DeficiencyToken__factory(owner).attach(await safu.deficiencyToken(loan.address)) - expect(await dToken.totalSupply()).to.eq(defaultAmount.div(2)) + expect(await dToken.totalSupply()).to.eq(defaultAmount) await pool.reclaimDeficit(loan.address) expect(await dToken.totalSupply()).to.eq(0) }) @@ -319,11 +321,11 @@ describe('SAFU', () => { }) it('transfers deficit to the pool', async () => { - await expect(() => pool.reclaimDeficit(loan.address)).changeTokenBalance(token, pool, defaultAmount.div(2)) + await expect(() => pool.reclaimDeficit(loan.address)).changeTokenBalance(token, pool, defaultAmount) }) it('transfers deficit from the safu', async () => { - await expect(() => pool.reclaimDeficit(loan.address)).changeTokenBalance(token, safu, defaultAmount.div(2).mul(-1)) + await expect(() => pool.reclaimDeficit(loan.address)).changeTokenBalance(token, safu, defaultAmount.mul(-1)) }) it('safu keeps excessive funds', async () => { @@ -334,7 +336,7 @@ describe('SAFU', () => { it('emits event', async () => { await expect(pool.reclaimDeficit(loan.address)) .to.emit(safu, 'Reclaimed') - .withArgs(loan.address, defaultAmount.div(2)) + .withArgs(loan.address, defaultAmount) }) }) }) From ef161de091f9604c97ee209ece6a8fe0f94d7197 Mon Sep 17 00:00:00 2001 From: Yuchen Lin Date: Thu, 13 Oct 2022 10:16:22 -0700 Subject: [PATCH 3/6] Add integration tests for SAFU hotfix --- test/integration/safuHotfix20221013.ts | 118 +++++++++++++++++++++++++ test/integration/suite20221013.ts | 76 ++++++++++++++++ 2 files changed, 194 insertions(+) create mode 100644 test/integration/safuHotfix20221013.ts create mode 100644 test/integration/suite20221013.ts diff --git a/test/integration/safuHotfix20221013.ts b/test/integration/safuHotfix20221013.ts new file mode 100644 index 000000000..09d6415b0 --- /dev/null +++ b/test/integration/safuHotfix20221013.ts @@ -0,0 +1,118 @@ +import { forkChain } from './suite20221013' +import { setupDeploy } from 'scripts/utils' +import { Erc20, Erc20__factory, LoanToken2, LoanToken2__factory, OwnedUpgradeabilityProxy__factory, Safu, Safu__factory, TrueFiPool2, TrueFiPool2__factory } from 'contracts' +import { expect, use } from 'chai' +import { solidity } from 'ethereum-waffle' +import { parseEth } from 'utils' +import { JsonRpcSigner } from '@ethersproject/providers' + +use(solidity) + +describe('SAFU hotfix 2022-10-13', () => { + const SAFU_OWNER = '0x16cEa306506c387713C70b9C1205fd5aC997E78E' + const SAFU_ADDRESS = '0x1eA63189eB1F4c109B10Cf6567f328C826AA6151' + const TFBUSD_ADDRESS = '0x1Ed460D149D48FA7d91703bf4890F97220C09437' + const LOAN_ADDRESS = '0x4A66a867f52DF4Ed1D8580A1C383B2dD036a3C47' + const ETH_HOLDER = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' + const BUSD_HOLDER = '0xF977814e90dA44bFA03b6295A0616a897441aceC' + const BUSD_ADDRESS = '0x4Fabb145d64652a948d72533023f6E7A623C7C53' + const BLOCK_NUMBER = 15734123 // 2022-10-12 + + let safuOwner: JsonRpcSigner + let safu: Safu + let tfBUSD: TrueFiPool2 + let loan: LoanToken2 + let busd: Erc20 + + beforeEach(async () => { + const provider = forkChain([SAFU_OWNER, ETH_HOLDER, BUSD_HOLDER], BLOCK_NUMBER - 1) + + safuOwner = provider.getSigner(SAFU_OWNER) + safu = Safu__factory.connect(SAFU_ADDRESS, safuOwner) + loan = LoanToken2__factory.connect(LOAN_ADDRESS, safuOwner) + tfBUSD = TrueFiPool2__factory.connect(TFBUSD_ADDRESS, safuOwner) + + const ethHolder = provider.getSigner(ETH_HOLDER) + await ethHolder.sendTransaction({ value: parseEth(100), to: SAFU_OWNER }) + + const busdHolder = provider.getSigner(BUSD_HOLDER) + busd = Erc20__factory.connect(BUSD_ADDRESS, busdHolder) + }) + + describe('before SAFU upgrade', () => { + it('tfBUSD pool value includes 100% of deficiency token value', async () => { + await safu.liquidate(loan.address) + + const poolValue = await tfBUSD.poolValue() + const totalSupply = await tfBUSD.totalSupply() + const deficitValue = await tfBUSD.deficitValue() + const liquidValue = await tfBUSD.liquidValue() + const loansValue = await tfBUSD.loansValue() + + expect(totalSupply).to.be.lt(poolValue) + expect(deficitValue).to.equal(await loan.debt()) + expect(poolValue).to.equal(liquidValue.add(loansValue).add(deficitValue)) + }) + + it('SAFU transfers BUSD tokens to pool during liquidation', async () => { + await busd.transfer(safu.address, parseEth(1_000_000_000)) + + const liquidValueBefore = await tfBUSD.liquidValue() + + await safu.liquidate(loan.address) + + const poolValue = await tfBUSD.poolValue() + const totalSupply = await tfBUSD.totalSupply() + const deficitValue = await tfBUSD.deficitValue() + const liquidValue = await tfBUSD.liquidValue() + const loansValue = await tfBUSD.loansValue() + + expect(totalSupply).to.be.lt(poolValue) + expect(deficitValue).to.equal(0) + expect(poolValue).to.equal(liquidValue.add(loansValue)) + expect(liquidValue).to.equal(liquidValueBefore.add(await loan.debt())) + }) + }) + + describe('after SAFU upgrade', () => { + beforeEach(async () => { + const deployContract = setupDeploy(safuOwner) + const newSAFU = await deployContract(Safu__factory) + const safuProxy = OwnedUpgradeabilityProxy__factory.connect(SAFU_ADDRESS, safuOwner) + await safuProxy.upgradeTo(newSAFU.address) + }) + + it('tfBUSD pool value includes 0% of deficiency token value', async () => { + await safu.liquidate(loan.address) + + const poolValue = await tfBUSD.poolValue() + const totalSupply = await tfBUSD.totalSupply() + const deficitValue = await tfBUSD.deficitValue() + const liquidValue = await tfBUSD.liquidValue() + const loansValue = await tfBUSD.loansValue() + + expect(totalSupply).to.be.gt(poolValue) + expect(deficitValue).to.equal(0) + expect(poolValue).to.equal(liquidValue.add(loansValue)) + }) + + it('SAFU does not transfer BUSD tokens to pool during liquidation', async () => { + await busd.transfer(safu.address, parseEth(1_000_000_000)) + + const liquidValueBefore = await tfBUSD.liquidValue() + + await safu.liquidate(loan.address) + + const poolValue = await tfBUSD.poolValue() + const totalSupply = await tfBUSD.totalSupply() + const deficitValue = await tfBUSD.deficitValue() + const liquidValue = await tfBUSD.liquidValue() + const loansValue = await tfBUSD.loansValue() + + expect(totalSupply).to.be.gt(poolValue) + expect(deficitValue).to.equal(0) + expect(poolValue).to.equal(liquidValue.add(loansValue)) + expect(liquidValue).to.equal(liquidValueBefore) + }) + }) +}) diff --git a/test/integration/suite20221013.ts b/test/integration/suite20221013.ts new file mode 100644 index 000000000..115532570 --- /dev/null +++ b/test/integration/suite20221013.ts @@ -0,0 +1,76 @@ +/* eslint-disable no-redeclare */ +import { BigNumberish, Contract, providers } from 'ethers' +import { ContractFactoryConstructor, deployContract } from 'scripts/utils/deployContract' +import ganache from 'ganache-core' +import { OwnedUpgradeabilityProxy__factory } from 'contracts' +import { expect } from 'chai' +import { parseEth } from 'utils' + +export const CONTRACTS_OWNER = '0x16cEa306506c387713C70b9C1205fd5aC997E78E' +export const ETHER_HOLDER = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' + +function _forkChain (rpc: string, unlockedAccounts: string[] = [], blockNumber?: BigNumberish, +) { + return new providers.Web3Provider(ganache.provider({ + fork: blockNumber ? `${rpc}@${blockNumber.toString()}` : rpc, + unlocked_accounts: unlockedAccounts, + })) +} + +export function forkChain (unlockedAccounts: string[] = [], blockNumber?: BigNumberish) { + const infura_key = process.env.INFURA_PROJECT_ID + const infura_secret = process.env.INFURA_PROJECT_SECRET + + const rpc = infura_key ? `https://:${infura_secret}@mainnet.infura.io/v3/${infura_key}` : 'https://eth-mainnet.alchemyapi.io/v2/Vc3xNXIWdxEbDOToa69DhWeyhgFVBDWl' + return _forkChain(rpc, unlockedAccounts, blockNumber) +} + +type Getter = keyof T['callStatic'] | ((contract: T) => any) + +const execGetter = (contract: T) => async (getter: Getter) => { + if (typeof getter === 'function') { + return getter(contract) + } + return contract[getter]() +} + +export const TEST_STATE_BLOCK_NUMBER = 12010725 + +export function upgradeSuite(blockNumber: number, Factory: ContractFactoryConstructor, currentAddress: string, + getters: Getter[], contractsOwner?: string): Promise +export function upgradeSuite(Factory: ContractFactoryConstructor, currentAddress: string, + getters: Getter[], contractsOwner?: string): Promise +export function upgradeSuite (...args: any[]): any { + if (typeof args[0] === 'number') { + const [bn, factory, address, getters, owner] = args + return _upgradeSuite(factory, address, getters, owner, bn) + } + const [factory, address, getters, owner] = args + return _upgradeSuite(factory, address, getters, owner) +} + +async function _upgradeSuite ( + Factory: ContractFactoryConstructor, + currentAddress: string, + getters: Getter[], + contractsOwner: string = CONTRACTS_OWNER, + blockNumber?: number | undefined, +) { + const provider = forkChain([contractsOwner, ETHER_HOLDER], blockNumber) + const owner = provider.getSigner(contractsOwner) + const holder = provider.getSigner(ETHER_HOLDER) + await holder.sendTransaction({ value: parseEth(100), to: contractsOwner }) + const newContract = await deployContract(owner, Factory) + const existingContract = new Factory(owner).attach(currentAddress) + const oldValues = await Promise.all(getters.map(execGetter(existingContract))) + const proxy = new OwnedUpgradeabilityProxy__factory(owner).attach(currentAddress) + await (await proxy.upgradeTo(newContract.address)).wait() + const newValues = await Promise.all(getters.map(execGetter(existingContract))) + for (let i = 0; i < oldValues.length; i++) { + expect(oldValues[i], `Possible corrupted storage: +Getter: ${getters[i]} +Current: ${oldValues[i].toString()} +Post upgrade: ${newValues[i].toString()} \n`).to.deep.equal(newValues[i]) + } + return existingContract +} From f15ae525dae3293b59ac64ee96312bf4a22852e3 Mon Sep 17 00:00:00 2001 From: Yuchen Lin Date: Thu, 13 Oct 2022 11:01:53 -0700 Subject: [PATCH 4/6] TMP comment out all but SAFU deploy --- deploy/truefi2.ts | 216 +++++++++++++++++++++++----------------------- 1 file changed, 108 insertions(+), 108 deletions(-) diff --git a/deploy/truefi2.ts b/deploy/truefi2.ts index 3a746a75c..243ecde3f 100644 --- a/deploy/truefi2.ts +++ b/deploy/truefi2.ts @@ -53,117 +53,117 @@ const deployParams = { } deploy({}, (_, config) => { - const proxy = createProxy(OwnedUpgradeabilityProxy) - const timeProxy = createProxy(TimeOwnedUpgradeabilityProxy) - const isMainnet = config.network === 'mainnet' - const NETWORK = isMainnet ? 'mainnet' : 'testnet' + // const proxy = createProxy(OwnedUpgradeabilityProxy) + // const timeProxy = createProxy(TimeOwnedUpgradeabilityProxy) + // const isMainnet = config.network === 'mainnet' + // const NETWORK = isMainnet ? 'mainnet' : 'testnet' - // Existing contracts - const trustToken = isMainnet - ? timeProxy(contract(TrustToken), () => {}) - : timeProxy(contract(TestTrustToken), () => {}) - const stkTruToken = proxy(contract(StkTruToken), () => {}) - const trueFiPool = isMainnet - ? proxy(contract(TrueFiPool), () => {}) - : proxy(contract(TestTrueFiPool), () => {}) - const usdc = isMainnet - ? deployParams['mainnet'].USDC - : contract(TestUSDCToken) - const usdt = isMainnet - ? deployParams['mainnet'].USDT - : contract(TestUSDTToken) - const trueRatingAgencyV2 = proxy(contract(TrueRatingAgencyV2), () => {}) + // // Existing contracts + // const trustToken = isMainnet + // ? timeProxy(contract(TrustToken), () => {}) + // : timeProxy(contract(TestTrustToken), () => {}) + // const stkTruToken = proxy(contract(StkTruToken), () => {}) + // const trueFiPool = isMainnet + // ? proxy(contract(TrueFiPool), () => {}) + // : proxy(contract(TestTrueFiPool), () => {}) + // const usdc = isMainnet + // ? deployParams['mainnet'].USDC + // : contract(TestUSDCToken) + // const usdt = isMainnet + // ? deployParams['mainnet'].USDT + // : contract(TestUSDTToken) + // const trueRatingAgencyV2 = proxy(contract(TrueRatingAgencyV2), () => {}) - // New contract impls - const trueLender2_impl = contract(TrueLender2) - const poolFactory_impl = contract(PoolFactory) - const liquidator2_impl = contract(Liquidator2) - const loanFactory2_impl = contract(LoanFactory2) + // // New contract impls + // const trueLender2_impl = contract(TrueLender2) + // const poolFactory_impl = contract(PoolFactory) + // const liquidator2_impl = contract(Liquidator2) + // const loanFactory2_impl = contract(LoanFactory2) const safu_impl = contract(SAFU) - const usdc_TrueFiPool2_LinearTrueDistributor_impl = contract('usdc_TrueFiPool2_LinearTrueDistributor', LinearTrueDistributor) - const usdc_TrueFiPool2_TrueFarm_impl = contract('usdc_TrueFiPool2_TrueFarm', TrueFarm) - const usdt_TrueFiPool2_LinearTrueDistributor_impl = contract('usdt_TrueFiPool2_LinearTrueDistributor', LinearTrueDistributor) - const usdt_TrueFiPool2_TrueFarm_impl = contract('usdt_TrueFiPool2_TrueFarm', TrueFarm) - const trueFiCreditOracle_impl = contract(TrueFiCreditOracle) - const borrowingMutex_impl = contract(BorrowingMutex) + // const usdc_TrueFiPool2_LinearTrueDistributor_impl = contract('usdc_TrueFiPool2_LinearTrueDistributor', LinearTrueDistributor) + // const usdc_TrueFiPool2_TrueFarm_impl = contract('usdc_TrueFiPool2_TrueFarm', TrueFarm) + // const usdt_TrueFiPool2_LinearTrueDistributor_impl = contract('usdt_TrueFiPool2_LinearTrueDistributor', LinearTrueDistributor) + // const usdt_TrueFiPool2_TrueFarm_impl = contract('usdt_TrueFiPool2_TrueFarm', TrueFarm) + // const trueFiCreditOracle_impl = contract(TrueFiCreditOracle) + // const borrowingMutex_impl = contract(BorrowingMutex) - // New contract proxies - const trueLender2 = proxy(trueLender2_impl, () => {}) - const poolFactory = proxy(poolFactory_impl, () => {}) - const liquidator2 = proxy(liquidator2_impl, () => {}) - const loanFactory2 = proxy(loanFactory2_impl, () => {}) - const usdc_TrueFiPool2_LinearTrueDistributor = proxy(usdc_TrueFiPool2_LinearTrueDistributor_impl, () => {}) - const usdc_TrueFiPool2_TrueFarm = proxy(usdc_TrueFiPool2_TrueFarm_impl, () => {}) - const usdt_TrueFiPool2_LinearTrueDistributor = proxy(usdt_TrueFiPool2_LinearTrueDistributor_impl, () => {}) - const usdt_TrueFiPool2_TrueFarm = proxy(usdt_TrueFiPool2_TrueFarm_impl, () => {}) - const trueFiCreditOracle = proxy(trueFiCreditOracle_impl, () => {}) - const safu = proxy(safu_impl, () => {}) - const borrowingMutex = proxy(borrowingMutex_impl, () => {}) - // New bare contracts - const trueFiPool2 = contract(TrueFiPool2) - const implementationReference = contract(ImplementationReference, [trueFiPool2]) - const chainlinkTruTusdOracle = contract(ChainlinkTruTusdOracle) - const chainlinkTruUsdcOracle = contract(ChainlinkTruUsdcOracle) - const chainlinkTruUsdtOracle = contract(ChainlinkTruUsdtOracle) - const oneInch = isMainnet ? ONE_INCH_EXCHANGE : contract(Mock1InchV3) + // // New contract proxies + // const trueLender2 = proxy(trueLender2_impl, () => {}) + // const poolFactory = proxy(poolFactory_impl, () => {}) + // const liquidator2 = proxy(liquidator2_impl, () => {}) + // const loanFactory2 = proxy(loanFactory2_impl, () => {}) + // const usdc_TrueFiPool2_LinearTrueDistributor = proxy(usdc_TrueFiPool2_LinearTrueDistributor_impl, () => {}) + // const usdc_TrueFiPool2_TrueFarm = proxy(usdc_TrueFiPool2_TrueFarm_impl, () => {}) + // const usdt_TrueFiPool2_LinearTrueDistributor = proxy(usdt_TrueFiPool2_LinearTrueDistributor_impl, () => {}) + // const usdt_TrueFiPool2_TrueFarm = proxy(usdt_TrueFiPool2_TrueFarm_impl, () => {}) + // const trueFiCreditOracle = proxy(trueFiCreditOracle_impl, () => {}) + // const safu = proxy(safu_impl, () => {}) + // const borrowingMutex = proxy(borrowingMutex_impl, () => {}) + // // New bare contracts + // const trueFiPool2 = contract(TrueFiPool2) + // const implementationReference = contract(ImplementationReference, [trueFiPool2]) + // const chainlinkTruTusdOracle = contract(ChainlinkTruTusdOracle) + // const chainlinkTruUsdcOracle = contract(ChainlinkTruUsdcOracle) + // const chainlinkTruUsdtOracle = contract(ChainlinkTruUsdtOracle) + // const oneInch = isMainnet ? ONE_INCH_EXCHANGE : contract(Mock1InchV3) - // Contract initialization - runIf(safu.isInitialized().not(), () => { - safu.initialize(loanFactory2, liquidator2, oneInch) - }) - runIf(poolFactory.isInitialized().not(), () => { - poolFactory.initialize(implementationReference, trueLender2, safu) - }) - runIf(trueLender2.isInitialized().not(), () => { - trueLender2.initialize(stkTruToken, poolFactory, trueRatingAgencyV2, oneInch, trueFiCreditOracle, borrowingMutex) - }) - runIf(trueLender2.votingPeriod().equals(deployParams[NETWORK].WITHDRAW_PERIOD).not(), () => { - trueLender2.setVotingPeriod(deployParams[NETWORK].WITHDRAW_PERIOD) - }) - runIf(loanFactory2.isInitialized().not(), () => { - loanFactory2.initialize(poolFactory, trueLender2, liquidator2, AddressZero, trueFiCreditOracle, borrowingMutex) - }) - runIf(liquidator2.isInitialized().not(), () => { - liquidator2.initialize(stkTruToken, trustToken, loanFactory2, AddressZero) - }) - runIf(poolFactory.pool(usdc).equals(AddressZero), () => { - poolFactory.allowToken(usdc, true) - poolFactory.createPool(usdc) - }) - const usdc_TrueFiPool2 = poolFactory.pool(usdc) - runIf(trueLender2.feePool().equals(AddressZero), () => { - trueLender2.setFeePool(usdc_TrueFiPool2) - }) - runIf(usdc_TrueFiPool2_LinearTrueDistributor.isInitialized().not(), () => { - usdc_TrueFiPool2_LinearTrueDistributor.initialize(deployParams[NETWORK].DISTRIBUTION_START, deployParams[NETWORK].DISTRIBUTION_DURATION, deployParams[NETWORK].STAKE_DISTRIBUTION_AMOUNT, trustToken) - }) - runIf(usdc_TrueFiPool2_LinearTrueDistributor.farm().equals(usdc_TrueFiPool2_TrueFarm).not(), () => { - usdc_TrueFiPool2_LinearTrueDistributor.setFarm(usdc_TrueFiPool2_TrueFarm) - }) - runIf(usdc_TrueFiPool2_TrueFarm.isInitialized().not(), () => { - usdc_TrueFiPool2_TrueFarm.initialize(usdc_TrueFiPool2, usdc_TrueFiPool2_LinearTrueDistributor, 'TrueFi tfUSDC Farm') - }) - runIf(poolFactory.pool(usdt).equals(AddressZero), () => { - poolFactory.allowToken(usdt, true) - poolFactory.createPool(usdt) - }) - const usdt_TrueFiPool2 = poolFactory.pool(usdt) - runIf(usdt_TrueFiPool2_LinearTrueDistributor.isInitialized().not(), () => { - usdt_TrueFiPool2_LinearTrueDistributor.initialize(deployParams[NETWORK].DISTRIBUTION_START, deployParams[NETWORK].DISTRIBUTION_DURATION, deployParams[NETWORK].STAKE_DISTRIBUTION_AMOUNT, trustToken) - }) - runIf(usdt_TrueFiPool2_LinearTrueDistributor.farm().equals(usdt_TrueFiPool2_TrueFarm).not(), () => { - usdt_TrueFiPool2_LinearTrueDistributor.setFarm(usdt_TrueFiPool2_TrueFarm) - }) - runIf(usdt_TrueFiPool2_TrueFarm.isInitialized().not(), () => { - usdt_TrueFiPool2_TrueFarm.initialize(usdt_TrueFiPool2, usdt_TrueFiPool2_LinearTrueDistributor, 'TrueFi tfUSDT Farm') - }) - runIf(trueFiCreditOracle.isInitialized().not(), () => { - trueFiCreditOracle.initialize() - }) - if (!isMainnet) { - trueLender2.setFee(deployParams['testnet'].LOAN_INTEREST_FEE) - } - runIf(poolFactory.isPool(trueFiPool).not(), () => { - poolFactory.addLegacyPool(trueFiPool) - }) + // // Contract initialization + // runIf(safu.isInitialized().not(), () => { + // safu.initialize(loanFactory2, liquidator2, oneInch) + // }) + // runIf(poolFactory.isInitialized().not(), () => { + // poolFactory.initialize(implementationReference, trueLender2, safu) + // }) + // runIf(trueLender2.isInitialized().not(), () => { + // trueLender2.initialize(stkTruToken, poolFactory, trueRatingAgencyV2, oneInch, trueFiCreditOracle, borrowingMutex) + // }) + // runIf(trueLender2.votingPeriod().equals(deployParams[NETWORK].WITHDRAW_PERIOD).not(), () => { + // trueLender2.setVotingPeriod(deployParams[NETWORK].WITHDRAW_PERIOD) + // }) + // runIf(loanFactory2.isInitialized().not(), () => { + // loanFactory2.initialize(poolFactory, trueLender2, liquidator2, AddressZero, trueFiCreditOracle, borrowingMutex) + // }) + // runIf(liquidator2.isInitialized().not(), () => { + // liquidator2.initialize(stkTruToken, trustToken, loanFactory2, AddressZero) + // }) + // runIf(poolFactory.pool(usdc).equals(AddressZero), () => { + // poolFactory.allowToken(usdc, true) + // poolFactory.createPool(usdc) + // }) + // const usdc_TrueFiPool2 = poolFactory.pool(usdc) + // runIf(trueLender2.feePool().equals(AddressZero), () => { + // trueLender2.setFeePool(usdc_TrueFiPool2) + // }) + // runIf(usdc_TrueFiPool2_LinearTrueDistributor.isInitialized().not(), () => { + // usdc_TrueFiPool2_LinearTrueDistributor.initialize(deployParams[NETWORK].DISTRIBUTION_START, deployParams[NETWORK].DISTRIBUTION_DURATION, deployParams[NETWORK].STAKE_DISTRIBUTION_AMOUNT, trustToken) + // }) + // runIf(usdc_TrueFiPool2_LinearTrueDistributor.farm().equals(usdc_TrueFiPool2_TrueFarm).not(), () => { + // usdc_TrueFiPool2_LinearTrueDistributor.setFarm(usdc_TrueFiPool2_TrueFarm) + // }) + // runIf(usdc_TrueFiPool2_TrueFarm.isInitialized().not(), () => { + // usdc_TrueFiPool2_TrueFarm.initialize(usdc_TrueFiPool2, usdc_TrueFiPool2_LinearTrueDistributor, 'TrueFi tfUSDC Farm') + // }) + // runIf(poolFactory.pool(usdt).equals(AddressZero), () => { + // poolFactory.allowToken(usdt, true) + // poolFactory.createPool(usdt) + // }) + // const usdt_TrueFiPool2 = poolFactory.pool(usdt) + // runIf(usdt_TrueFiPool2_LinearTrueDistributor.isInitialized().not(), () => { + // usdt_TrueFiPool2_LinearTrueDistributor.initialize(deployParams[NETWORK].DISTRIBUTION_START, deployParams[NETWORK].DISTRIBUTION_DURATION, deployParams[NETWORK].STAKE_DISTRIBUTION_AMOUNT, trustToken) + // }) + // runIf(usdt_TrueFiPool2_LinearTrueDistributor.farm().equals(usdt_TrueFiPool2_TrueFarm).not(), () => { + // usdt_TrueFiPool2_LinearTrueDistributor.setFarm(usdt_TrueFiPool2_TrueFarm) + // }) + // runIf(usdt_TrueFiPool2_TrueFarm.isInitialized().not(), () => { + // usdt_TrueFiPool2_TrueFarm.initialize(usdt_TrueFiPool2, usdt_TrueFiPool2_LinearTrueDistributor, 'TrueFi tfUSDT Farm') + // }) + // runIf(trueFiCreditOracle.isInitialized().not(), () => { + // trueFiCreditOracle.initialize() + // }) + // if (!isMainnet) { + // trueLender2.setFee(deployParams['testnet'].LOAN_INTEREST_FEE) + // } + // runIf(poolFactory.isPool(trueFiPool).not(), () => { + // poolFactory.addLegacyPool(trueFiPool) + // }) }) From 0605be0f47e9b509dc14e0aa272652944162f920 Mon Sep 17 00:00:00 2001 From: Yuchen Lin Date: Thu, 13 Oct 2022 11:06:46 -0700 Subject: [PATCH 5/6] Deploy SAFU hotfix to mainnet --- deployments.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deployments.json b/deployments.json index a23da6b68..155096d30 100644 --- a/deployments.json +++ b/deployments.json @@ -557,8 +557,8 @@ "address": "0xCB829B1Aa77B8B57D320AF05a780757c8c2B88C1" }, "sAFU": { - "txHash": "0x069ca631faace9d865bf47ad09df5326633eb4d1d34aafafd0df3bcd7c37cd14", - "address": "0xC83E731e0cab21ce5B0Bbbe3252bAefD0e11fc03" + "txHash": "0x5856ef56a67575ed46d74f86e7c5c6a4eb344a516ddfdc83fac445b324ac96ac", + "address": "0xc7B4BB7c8e3620A6c4F9E96524ccB8a81D52A1b1" }, "sAFU_proxy": { "txHash": "0xaa5bbaa6ca71899793cea116bfa42e4b06791c7ab85523e83bf911a4b9e12c42", From 49f472adc6379780742a3af6c17f5792fe7f247d Mon Sep 17 00:00:00 2001 From: Yuchen Lin Date: Thu, 13 Oct 2022 11:06:53 -0700 Subject: [PATCH 6/6] Revert "TMP comment out all but SAFU deploy" This reverts commit f15ae525dae3293b59ac64ee96312bf4a22852e3. --- deploy/truefi2.ts | 216 +++++++++++++++++++++++----------------------- 1 file changed, 108 insertions(+), 108 deletions(-) diff --git a/deploy/truefi2.ts b/deploy/truefi2.ts index 243ecde3f..3a746a75c 100644 --- a/deploy/truefi2.ts +++ b/deploy/truefi2.ts @@ -53,117 +53,117 @@ const deployParams = { } deploy({}, (_, config) => { - // const proxy = createProxy(OwnedUpgradeabilityProxy) - // const timeProxy = createProxy(TimeOwnedUpgradeabilityProxy) - // const isMainnet = config.network === 'mainnet' - // const NETWORK = isMainnet ? 'mainnet' : 'testnet' + const proxy = createProxy(OwnedUpgradeabilityProxy) + const timeProxy = createProxy(TimeOwnedUpgradeabilityProxy) + const isMainnet = config.network === 'mainnet' + const NETWORK = isMainnet ? 'mainnet' : 'testnet' - // // Existing contracts - // const trustToken = isMainnet - // ? timeProxy(contract(TrustToken), () => {}) - // : timeProxy(contract(TestTrustToken), () => {}) - // const stkTruToken = proxy(contract(StkTruToken), () => {}) - // const trueFiPool = isMainnet - // ? proxy(contract(TrueFiPool), () => {}) - // : proxy(contract(TestTrueFiPool), () => {}) - // const usdc = isMainnet - // ? deployParams['mainnet'].USDC - // : contract(TestUSDCToken) - // const usdt = isMainnet - // ? deployParams['mainnet'].USDT - // : contract(TestUSDTToken) - // const trueRatingAgencyV2 = proxy(contract(TrueRatingAgencyV2), () => {}) + // Existing contracts + const trustToken = isMainnet + ? timeProxy(contract(TrustToken), () => {}) + : timeProxy(contract(TestTrustToken), () => {}) + const stkTruToken = proxy(contract(StkTruToken), () => {}) + const trueFiPool = isMainnet + ? proxy(contract(TrueFiPool), () => {}) + : proxy(contract(TestTrueFiPool), () => {}) + const usdc = isMainnet + ? deployParams['mainnet'].USDC + : contract(TestUSDCToken) + const usdt = isMainnet + ? deployParams['mainnet'].USDT + : contract(TestUSDTToken) + const trueRatingAgencyV2 = proxy(contract(TrueRatingAgencyV2), () => {}) - // // New contract impls - // const trueLender2_impl = contract(TrueLender2) - // const poolFactory_impl = contract(PoolFactory) - // const liquidator2_impl = contract(Liquidator2) - // const loanFactory2_impl = contract(LoanFactory2) + // New contract impls + const trueLender2_impl = contract(TrueLender2) + const poolFactory_impl = contract(PoolFactory) + const liquidator2_impl = contract(Liquidator2) + const loanFactory2_impl = contract(LoanFactory2) const safu_impl = contract(SAFU) - // const usdc_TrueFiPool2_LinearTrueDistributor_impl = contract('usdc_TrueFiPool2_LinearTrueDistributor', LinearTrueDistributor) - // const usdc_TrueFiPool2_TrueFarm_impl = contract('usdc_TrueFiPool2_TrueFarm', TrueFarm) - // const usdt_TrueFiPool2_LinearTrueDistributor_impl = contract('usdt_TrueFiPool2_LinearTrueDistributor', LinearTrueDistributor) - // const usdt_TrueFiPool2_TrueFarm_impl = contract('usdt_TrueFiPool2_TrueFarm', TrueFarm) - // const trueFiCreditOracle_impl = contract(TrueFiCreditOracle) - // const borrowingMutex_impl = contract(BorrowingMutex) + const usdc_TrueFiPool2_LinearTrueDistributor_impl = contract('usdc_TrueFiPool2_LinearTrueDistributor', LinearTrueDistributor) + const usdc_TrueFiPool2_TrueFarm_impl = contract('usdc_TrueFiPool2_TrueFarm', TrueFarm) + const usdt_TrueFiPool2_LinearTrueDistributor_impl = contract('usdt_TrueFiPool2_LinearTrueDistributor', LinearTrueDistributor) + const usdt_TrueFiPool2_TrueFarm_impl = contract('usdt_TrueFiPool2_TrueFarm', TrueFarm) + const trueFiCreditOracle_impl = contract(TrueFiCreditOracle) + const borrowingMutex_impl = contract(BorrowingMutex) - // // New contract proxies - // const trueLender2 = proxy(trueLender2_impl, () => {}) - // const poolFactory = proxy(poolFactory_impl, () => {}) - // const liquidator2 = proxy(liquidator2_impl, () => {}) - // const loanFactory2 = proxy(loanFactory2_impl, () => {}) - // const usdc_TrueFiPool2_LinearTrueDistributor = proxy(usdc_TrueFiPool2_LinearTrueDistributor_impl, () => {}) - // const usdc_TrueFiPool2_TrueFarm = proxy(usdc_TrueFiPool2_TrueFarm_impl, () => {}) - // const usdt_TrueFiPool2_LinearTrueDistributor = proxy(usdt_TrueFiPool2_LinearTrueDistributor_impl, () => {}) - // const usdt_TrueFiPool2_TrueFarm = proxy(usdt_TrueFiPool2_TrueFarm_impl, () => {}) - // const trueFiCreditOracle = proxy(trueFiCreditOracle_impl, () => {}) - // const safu = proxy(safu_impl, () => {}) - // const borrowingMutex = proxy(borrowingMutex_impl, () => {}) - // // New bare contracts - // const trueFiPool2 = contract(TrueFiPool2) - // const implementationReference = contract(ImplementationReference, [trueFiPool2]) - // const chainlinkTruTusdOracle = contract(ChainlinkTruTusdOracle) - // const chainlinkTruUsdcOracle = contract(ChainlinkTruUsdcOracle) - // const chainlinkTruUsdtOracle = contract(ChainlinkTruUsdtOracle) - // const oneInch = isMainnet ? ONE_INCH_EXCHANGE : contract(Mock1InchV3) + // New contract proxies + const trueLender2 = proxy(trueLender2_impl, () => {}) + const poolFactory = proxy(poolFactory_impl, () => {}) + const liquidator2 = proxy(liquidator2_impl, () => {}) + const loanFactory2 = proxy(loanFactory2_impl, () => {}) + const usdc_TrueFiPool2_LinearTrueDistributor = proxy(usdc_TrueFiPool2_LinearTrueDistributor_impl, () => {}) + const usdc_TrueFiPool2_TrueFarm = proxy(usdc_TrueFiPool2_TrueFarm_impl, () => {}) + const usdt_TrueFiPool2_LinearTrueDistributor = proxy(usdt_TrueFiPool2_LinearTrueDistributor_impl, () => {}) + const usdt_TrueFiPool2_TrueFarm = proxy(usdt_TrueFiPool2_TrueFarm_impl, () => {}) + const trueFiCreditOracle = proxy(trueFiCreditOracle_impl, () => {}) + const safu = proxy(safu_impl, () => {}) + const borrowingMutex = proxy(borrowingMutex_impl, () => {}) + // New bare contracts + const trueFiPool2 = contract(TrueFiPool2) + const implementationReference = contract(ImplementationReference, [trueFiPool2]) + const chainlinkTruTusdOracle = contract(ChainlinkTruTusdOracle) + const chainlinkTruUsdcOracle = contract(ChainlinkTruUsdcOracle) + const chainlinkTruUsdtOracle = contract(ChainlinkTruUsdtOracle) + const oneInch = isMainnet ? ONE_INCH_EXCHANGE : contract(Mock1InchV3) - // // Contract initialization - // runIf(safu.isInitialized().not(), () => { - // safu.initialize(loanFactory2, liquidator2, oneInch) - // }) - // runIf(poolFactory.isInitialized().not(), () => { - // poolFactory.initialize(implementationReference, trueLender2, safu) - // }) - // runIf(trueLender2.isInitialized().not(), () => { - // trueLender2.initialize(stkTruToken, poolFactory, trueRatingAgencyV2, oneInch, trueFiCreditOracle, borrowingMutex) - // }) - // runIf(trueLender2.votingPeriod().equals(deployParams[NETWORK].WITHDRAW_PERIOD).not(), () => { - // trueLender2.setVotingPeriod(deployParams[NETWORK].WITHDRAW_PERIOD) - // }) - // runIf(loanFactory2.isInitialized().not(), () => { - // loanFactory2.initialize(poolFactory, trueLender2, liquidator2, AddressZero, trueFiCreditOracle, borrowingMutex) - // }) - // runIf(liquidator2.isInitialized().not(), () => { - // liquidator2.initialize(stkTruToken, trustToken, loanFactory2, AddressZero) - // }) - // runIf(poolFactory.pool(usdc).equals(AddressZero), () => { - // poolFactory.allowToken(usdc, true) - // poolFactory.createPool(usdc) - // }) - // const usdc_TrueFiPool2 = poolFactory.pool(usdc) - // runIf(trueLender2.feePool().equals(AddressZero), () => { - // trueLender2.setFeePool(usdc_TrueFiPool2) - // }) - // runIf(usdc_TrueFiPool2_LinearTrueDistributor.isInitialized().not(), () => { - // usdc_TrueFiPool2_LinearTrueDistributor.initialize(deployParams[NETWORK].DISTRIBUTION_START, deployParams[NETWORK].DISTRIBUTION_DURATION, deployParams[NETWORK].STAKE_DISTRIBUTION_AMOUNT, trustToken) - // }) - // runIf(usdc_TrueFiPool2_LinearTrueDistributor.farm().equals(usdc_TrueFiPool2_TrueFarm).not(), () => { - // usdc_TrueFiPool2_LinearTrueDistributor.setFarm(usdc_TrueFiPool2_TrueFarm) - // }) - // runIf(usdc_TrueFiPool2_TrueFarm.isInitialized().not(), () => { - // usdc_TrueFiPool2_TrueFarm.initialize(usdc_TrueFiPool2, usdc_TrueFiPool2_LinearTrueDistributor, 'TrueFi tfUSDC Farm') - // }) - // runIf(poolFactory.pool(usdt).equals(AddressZero), () => { - // poolFactory.allowToken(usdt, true) - // poolFactory.createPool(usdt) - // }) - // const usdt_TrueFiPool2 = poolFactory.pool(usdt) - // runIf(usdt_TrueFiPool2_LinearTrueDistributor.isInitialized().not(), () => { - // usdt_TrueFiPool2_LinearTrueDistributor.initialize(deployParams[NETWORK].DISTRIBUTION_START, deployParams[NETWORK].DISTRIBUTION_DURATION, deployParams[NETWORK].STAKE_DISTRIBUTION_AMOUNT, trustToken) - // }) - // runIf(usdt_TrueFiPool2_LinearTrueDistributor.farm().equals(usdt_TrueFiPool2_TrueFarm).not(), () => { - // usdt_TrueFiPool2_LinearTrueDistributor.setFarm(usdt_TrueFiPool2_TrueFarm) - // }) - // runIf(usdt_TrueFiPool2_TrueFarm.isInitialized().not(), () => { - // usdt_TrueFiPool2_TrueFarm.initialize(usdt_TrueFiPool2, usdt_TrueFiPool2_LinearTrueDistributor, 'TrueFi tfUSDT Farm') - // }) - // runIf(trueFiCreditOracle.isInitialized().not(), () => { - // trueFiCreditOracle.initialize() - // }) - // if (!isMainnet) { - // trueLender2.setFee(deployParams['testnet'].LOAN_INTEREST_FEE) - // } - // runIf(poolFactory.isPool(trueFiPool).not(), () => { - // poolFactory.addLegacyPool(trueFiPool) - // }) + // Contract initialization + runIf(safu.isInitialized().not(), () => { + safu.initialize(loanFactory2, liquidator2, oneInch) + }) + runIf(poolFactory.isInitialized().not(), () => { + poolFactory.initialize(implementationReference, trueLender2, safu) + }) + runIf(trueLender2.isInitialized().not(), () => { + trueLender2.initialize(stkTruToken, poolFactory, trueRatingAgencyV2, oneInch, trueFiCreditOracle, borrowingMutex) + }) + runIf(trueLender2.votingPeriod().equals(deployParams[NETWORK].WITHDRAW_PERIOD).not(), () => { + trueLender2.setVotingPeriod(deployParams[NETWORK].WITHDRAW_PERIOD) + }) + runIf(loanFactory2.isInitialized().not(), () => { + loanFactory2.initialize(poolFactory, trueLender2, liquidator2, AddressZero, trueFiCreditOracle, borrowingMutex) + }) + runIf(liquidator2.isInitialized().not(), () => { + liquidator2.initialize(stkTruToken, trustToken, loanFactory2, AddressZero) + }) + runIf(poolFactory.pool(usdc).equals(AddressZero), () => { + poolFactory.allowToken(usdc, true) + poolFactory.createPool(usdc) + }) + const usdc_TrueFiPool2 = poolFactory.pool(usdc) + runIf(trueLender2.feePool().equals(AddressZero), () => { + trueLender2.setFeePool(usdc_TrueFiPool2) + }) + runIf(usdc_TrueFiPool2_LinearTrueDistributor.isInitialized().not(), () => { + usdc_TrueFiPool2_LinearTrueDistributor.initialize(deployParams[NETWORK].DISTRIBUTION_START, deployParams[NETWORK].DISTRIBUTION_DURATION, deployParams[NETWORK].STAKE_DISTRIBUTION_AMOUNT, trustToken) + }) + runIf(usdc_TrueFiPool2_LinearTrueDistributor.farm().equals(usdc_TrueFiPool2_TrueFarm).not(), () => { + usdc_TrueFiPool2_LinearTrueDistributor.setFarm(usdc_TrueFiPool2_TrueFarm) + }) + runIf(usdc_TrueFiPool2_TrueFarm.isInitialized().not(), () => { + usdc_TrueFiPool2_TrueFarm.initialize(usdc_TrueFiPool2, usdc_TrueFiPool2_LinearTrueDistributor, 'TrueFi tfUSDC Farm') + }) + runIf(poolFactory.pool(usdt).equals(AddressZero), () => { + poolFactory.allowToken(usdt, true) + poolFactory.createPool(usdt) + }) + const usdt_TrueFiPool2 = poolFactory.pool(usdt) + runIf(usdt_TrueFiPool2_LinearTrueDistributor.isInitialized().not(), () => { + usdt_TrueFiPool2_LinearTrueDistributor.initialize(deployParams[NETWORK].DISTRIBUTION_START, deployParams[NETWORK].DISTRIBUTION_DURATION, deployParams[NETWORK].STAKE_DISTRIBUTION_AMOUNT, trustToken) + }) + runIf(usdt_TrueFiPool2_LinearTrueDistributor.farm().equals(usdt_TrueFiPool2_TrueFarm).not(), () => { + usdt_TrueFiPool2_LinearTrueDistributor.setFarm(usdt_TrueFiPool2_TrueFarm) + }) + runIf(usdt_TrueFiPool2_TrueFarm.isInitialized().not(), () => { + usdt_TrueFiPool2_TrueFarm.initialize(usdt_TrueFiPool2, usdt_TrueFiPool2_LinearTrueDistributor, 'TrueFi tfUSDT Farm') + }) + runIf(trueFiCreditOracle.isInitialized().not(), () => { + trueFiCreditOracle.initialize() + }) + if (!isMainnet) { + trueLender2.setFee(deployParams['testnet'].LOAN_INTEREST_FEE) + } + runIf(poolFactory.isPool(trueFiPool).not(), () => { + poolFactory.addLegacyPool(trueFiPool) + }) })