Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
valiafetisov committed Oct 21, 2022
1 parent 162de7c commit de8e0b4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 47 deletions.
56 changes: 12 additions & 44 deletions core/simulations/configs/vaultLiquidation.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,13 @@
import { warpTime, resetNetworkAndSetupWallet } from '../../helpers/hardhat/network';
import { addDaiToBalance, addMkrToBalance } from '../../helpers/hardhat/balance';
import { Simulation } from '../types';
import prompts from 'prompts';
import COLLATERALS from '../../src/constants/COLLATERALS';
import { collectStabilityFees, fetchVault, liquidateVault } from '../../src/vaults';
import { TEST_NETWORK } from '../../helpers/constants';
import createVaultWithCollateral, {
calculateMinCollateralAmountToOpenVault,
getLiquidatableCollateralTypes,
} from '../helpers/createVaultWithCollateral';

const UNSUPPORTED_COLLATERAL_TYPES = [
'CRVV1ETHSTETH-A', // collateral handled differently
'UNIV2DAIUSDC-A', // Liquidation limit too high (fails with "Dog/liquidation-limit-hit")
'WSTETH-B', // does not accumulate stability fee rate at all.
];

export const getLiquidatableCollateralTypes = () => {
return Object.keys(COLLATERALS).filter(collateralType => !UNSUPPORTED_COLLATERAL_TYPES.includes(collateralType));
};

const getCollateralType = async () => {
const { collateralType } = await prompts([
{
type: 'select',
name: 'collateralType',
message: 'Select the collateral symbol to add to the VAT.',
choices: getLiquidatableCollateralTypes()
.sort()
.map(collateral => ({
title: collateral,
value: collateral,
})),
},
]);
return collateralType;
};

const getBaseContext = async () => {
const collateralType = await getCollateralType();
const decimals = COLLATERALS[collateralType].decimals;
const collateralOwned = await calculateMinCollateralAmountToOpenVault(collateralType);

console.info(`Collateral in the VAT initially: ${collateralOwned.toFixed()}`);
return {
collateralType,
decimals,
collateralOwned,
};
};
import promptToSelectOneOption from '../helpers/promptToSelectOneOption';

const simulation: Simulation = {
title: 'Simulate liquidation Auctions',
Expand All @@ -56,13 +16,21 @@ const simulation: Simulation = {
title: 'Reset blockchain fork',
entry: async () => {
await resetNetworkAndSetupWallet();
return getBaseContext();
const collateralType = await promptToSelectOneOption(
'Select the collateral symbol to add to the VAT.',
getLiquidatableCollateralTypes()
);
return {
collateralType,
};
},
},
{
title: 'Create the vault',
entry: async context => {
const latestVaultId = await createVaultWithCollateral(context.collateralType, context.collateralOwned);
const collateralOwned = await calculateMinCollateralAmountToOpenVault(context.collateralType);
console.info(`Minimum collateral amount to open vault: ${collateralOwned.toFixed()}`);
const latestVaultId = await createVaultWithCollateral(context.collateralType, collateralOwned);
return { ...context, latestVaultId };
},
},
Expand Down
18 changes: 16 additions & 2 deletions core/simulations/helpers/createVaultWithCollateral.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ethers } from 'ethers';
import BigNumber from '../../src/bignumber';
import { setCollateralInVat } from '../../helpers/hardhat/balance';
import { getCollateralConfigByType } from '../../src/constants/COLLATERALS';
import BigNumber from '../../src/bignumber';
import { changeVaultContents, fetchVault, openVault, fetchVaultCollateralParameters } from '../../src/vaults';
import { HARDHAT_PUBLIC_KEY, TEST_NETWORK } from '../../helpers/constants';
import {
Expand All @@ -17,9 +18,22 @@ import {
} from '../../src/wallet';
import { MAX } from '../../src/constants/UNITS';
import { CollateralConfig, CollateralType } from '../../src/types';
import { ethers } from 'ethers';
import { roundDownToFirstSignificantDecimal, roundUpToFirstSignificantDecimal } from '../../helpers/hex';
import { determineBalanceSlot, setCollateralInWallet } from '../../helpers/hardhat/erc20';
import { getAllCollateralTypes } from '../../src/constants/COLLATERALS';

const UNSUPPORTED_COLLATERAL_TYPES = [
'CRVV1ETHSTETH-A', // Collateral handled differently
'UNIV2DAIUSDC-A', // Liquidation limit too high (fails with "Dog/liquidation-limit-hit")
'WSTETH-B', // Does not accumulate stability fee rate at all
'RETH-A', // [temporary] this collateral is not yet deployed, tested via different flow
];

export const getLiquidatableCollateralTypes = () => {
return Object.keys(getAllCollateralTypes()).filter(
collateralType => !UNSUPPORTED_COLLATERAL_TYPES.includes(collateralType)
);
};

const setAndCheckCollateralInVat = async (collateralType: CollateralType, collateralOwned: BigNumber) => {
console.info(`Setting ${collateralType} balance in VAT...`);
Expand Down
2 changes: 1 addition & 1 deletion core/test/vault-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import { fetchAuctionByCollateralTypeAndAuctionIndex } from '../src/fetch';
import { fetchVATbalanceDAI } from '../src/wallet';
import createVaultWithCollateral, {
calculateMinCollateralAmountToOpenVault,
getLiquidatableCollateralTypes,
} from '../simulations/helpers/createVaultWithCollateral';
import { getLiquidatableCollateralTypes } from '../simulations/configs/vaultLiquidation';
import { MAX } from '../src/constants/UNITS';
chai.use(deepEqualInAnyOrder);

Expand Down

0 comments on commit de8e0b4

Please sign in to comment.