Skip to content

Commit

Permalink
fix: reset price after oracle test
Browse files Browse the repository at this point in the history
  • Loading branch information
panukettu committed Feb 1, 2024
1 parent 6a977da commit a05be1a
Show file tree
Hide file tree
Showing 8 changed files with 7,016 additions and 205 deletions.
2 changes: 1 addition & 1 deletion docs/test-report/mochawesome.html

Large diffs are not rendered by default.

7,163 changes: 6,985 additions & 178 deletions docs/test-report/mochawesome.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/test/minter/01-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ describe('Minter - Configuration', function () {
expect(newValues2.closeFee).to.equal(update2.openFee)
expect(newValues2.swapInFeeSCDP).to.equal(update2.swapInFeeSCDP)
expect(newValues2.maxDebtMinter).to.equal(update2.maxDebtMinter)

await f.KrAsset.setPrice(10)
})
})
})
2 changes: 1 addition & 1 deletion src/test/scdp/00-scdp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const initialDepositValue = depositAmount.ebn(8)
const depositAmount18Dec = depositAmount.ebn()
const depositAmount8Dec = depositAmount.ebn(8)

describe.only('SCDP', async function () {
describe('SCDP', async function () {
let f: SCDPFixture
this.slow(5000)

Expand Down
1 change: 1 addition & 0 deletions src/utils/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ export const liquidationsFixture = hre.deployments.createFixture<LiquidationFixt
amount: initialDeposits,
asset: DefaultCollateral,
})

await depositCollateral({
user: hre.users.liquidator,
amount: toBig(100000000),
Expand Down
35 changes: 18 additions & 17 deletions src/utils/test/helpers/krassets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,16 @@ export const leverageKrAsset = async (
collateralToUse: TestAsset<any, 'mock'>,
amount: BigNumber,
) => {
const [krAssetValueBig, mcrBig, collateralValue, collateralToUseInfo, krAssetInfo] = await Promise.all([
hre.Diamond.getValue(krAsset.address, amount),
optimized.getMinCollateralRatioMinter(),
hre.Diamond.getValue(collateralToUse.address, toBig(1)),
hre.Diamond.getAsset(collateralToUse.address),
hre.Diamond.getAsset(krAsset.address),
])
const [krAssetValueBig, mcrBig, collateralValue, collateralToUseInfo, krAssetInfo, updateData, prices] =
await Promise.all([
hre.Diamond.getValue(krAsset.address, amount),
optimized.getMinCollateralRatioMinter(),
hre.Diamond.getValue(collateralToUse.address, toBig(1)),
hre.Diamond.getAsset(collateralToUse.address),
hre.Diamond.getAsset(krAsset.address),
hre.updateData(),
collateralToUse.getPrice(),
])

await krAsset.contract.setVariable('_allowances', {
[user.address]: {
Expand All @@ -150,7 +153,7 @@ export const leverageKrAsset = async (
const collateralValueRequired = krAssetValueBig.percentMul(mcrBig)

const price = collateralValue.num(8)
const collateralAmount = collateralValueRequired.wadDiv((await collateralToUse.getPrice()).pyth)
const collateralAmount = collateralValueRequired.wadDiv(prices.pyth)

await collateralToUse.setBalance(user, collateralAmount, hre.Diamond.address)

Expand Down Expand Up @@ -178,13 +181,11 @@ export const leverageKrAsset = async (
await Promise.all(addPromises)
const UserKresko = hre.Diamond.connect(user)
await UserKresko.depositCollateral(user.address, collateralToUse.address, collateralAmount)
await Promise.all([
UserKresko.mintKreskoAsset(
{ account: user.address, krAsset: krAsset.address, amount, receiver: user.address },
await hre.updateData(),
),
UserKresko.depositCollateral(user.address, krAsset.address, amount),
])
await UserKresko.mintKreskoAsset(
{ account: user.address, krAsset: krAsset.address, amount, receiver: user.address },
updateData,
)
await UserKresko.depositCollateral(user.address, krAsset.address, amount)

// Deposit krAsset and withdraw other collateral to bare minimum of within healthy range

Expand All @@ -206,11 +207,11 @@ export const leverageKrAsset = async (
collateralIndex: optimized.getAccountDepositIndex(user.address, collateralToUse.address),
receiver: user.address,
},
await hre.updateData(),
updateData,
)

// "burn" collateral not needed
collateralToUse.setBalance(user, toBig(0))
await collateralToUse.setBalance(user, toBig(0))
// await collateralToUse.contract.connect(user).transfer(hre.ethers.constants.AddressZero, amountToWithdraw);
}
}
13 changes: 7 additions & 6 deletions src/utils/test/helpers/liquidations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import optimized from '@utils/test/helpers/optimizations'
import { fromBig, toBig } from '@utils/values'
import { depositCollateral, depositMockCollateral } from './collaterals'
import { mintKrAsset } from './krassets'
export const getLiqAmount = async (user: SignerWithAddress, krAsset: any, collateral: any, log = false) => {
export const getLiqAmount = async (user: SignerWithAddress, krAsset: TestKrAsset, collateral: any, log = false) => {
const [maxLiquidatableValue, krAssetPrice] = await Promise.all([
hre.Diamond.getMaxLiqValue(user.address, krAsset.address, collateral.address),
krAsset.getPrice(),
Expand All @@ -26,23 +26,24 @@ export const getLiqAmount = async (user: SignerWithAddress, krAsset: any, collat
valueUnder: fromBig(accountMinimumCollateralValue.sub(accountCollateralValue), 8),
kreskoAssetDebt,
maxValue: maxLiquidatableValue,
maxAmount: maxLiquidatableValue.repayValue.wadDiv(krAssetPrice),
maxAmount: maxLiquidatableValue.repayValue.wadDiv(krAssetPrice.pyth),
})
}

return maxLiquidatableValue.repayValue.wadDiv(krAssetPrice)
return maxLiquidatableValue.repayValue.wadDiv(krAssetPrice.pyth)
}

export const liquidate = async (
user: SignerWithAddress,
krAsset: TestKrAsset,
collateral: any,
collateral: TestExtAsset | TestKrAsset,
allowSeizeUnderflow = false,
) => {
const [depositsBefore, debtBefore, liqAmount] = await Promise.all([
const [depositsBefore, debtBefore, liqAmount, updateData] = await Promise.all([
hre.Diamond.getAccountCollateralAmount(user.address, collateral.address),
hre.Diamond.getAccountDebtAmount(user.address, krAsset.address),
getLiqAmount(user, krAsset, collateral),
hre.updateData(),
])

if (liqAmount.eq(0)) {
Expand Down Expand Up @@ -88,7 +89,7 @@ export const liquidate = async (
seizeAssetAddr: collateral.address,
repayAssetIndex: optimized.getAccountMintIndex(user.address, krAsset.address),
seizeAssetIndex: optimized.getAccountDepositIndex(user.address, collateral.address),
prices: await hre.updateData(),
prices: updateData,
})

const [depositsAfter, debtAfter, decimals] = await Promise.all([
Expand Down
3 changes: 1 addition & 2 deletions src/utils/test/helpers/oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ export const updatePrices = async (hre: any, fakeOracle: FakeContract<MockOracle
fakeOracle.latestRoundData.returns([1, priceBn, now, now, 1])

const mockPyth = await hre.getContractOrFork('MockPyth')
const updateData = await getUpdateData(hre)
await mockPyth.updatePriceFeeds(updateData)
await mockPyth.updatePriceFeeds(await getUpdateData(hre))
}

export const getUpdateData = async (hre: any) => {
Expand Down

0 comments on commit a05be1a

Please sign in to comment.