@@ -9,9 +9,11 @@ import createVaultWithCollateral, {
9
9
} from '../helpers/createVaultWithCollateral' ;
10
10
import promptToSelectOneOption from '../helpers/promptToSelectOneOption' ;
11
11
import promptToGetBlockNumber from '../helpers/promptToGetBlockNumber' ;
12
+ import getProvider from '../../src/provider' ;
12
13
13
- import { fetchMaximumAuctionDurationInSeconds } from '../../src/fetch' ;
14
+ import fetchAuctionsByCollateralType , { fetchMaximumAuctionDurationInSeconds } from '../../src/fetch' ;
14
15
import { getAllCollateralTypes } from '../../src/constants/COLLATERALS' ;
16
+ import { setCollateralDebtCeilingToGlobal } from '../../helpers/hardhat/contractParametrization' ;
15
17
16
18
const TWO_YEARS_IN_MINUTES = 60 * 24 * 30 * 12 * 2 ;
17
19
@@ -23,8 +25,10 @@ const simulation: Simulation = {
23
25
entry : async ( ) => {
24
26
const number = await promptToGetBlockNumber ( ) ;
25
27
await resetNetworkAndSetupWallet ( number ) ;
28
+ await addDaiToBalance ( ) ;
29
+ await addMkrToBalance ( ) ;
26
30
const collateralType = await promptToSelectOneOption (
27
- 'Select the collateral symbol to add to the VAT. ' ,
31
+ 'Select the collateral type ' ,
28
32
getAllCollateralTypes ( )
29
33
) ;
30
34
return {
@@ -33,34 +37,29 @@ const simulation: Simulation = {
33
37
} ,
34
38
} ,
35
39
{
36
- title : 'Create the vault' ,
40
+ title : 'Create underwater vault' ,
37
41
entry : async context => {
38
42
await adjustLimitsAndRates ( context . collateralType ) ;
39
43
const collateralOwned = await calculateMinCollateralAmountToOpenVault ( context . collateralType ) ;
40
44
console . info ( `Minimum collateral amount to open vault: ${ collateralOwned . toFixed ( ) } ` ) ;
41
- const latestVaultId = await createVaultWithCollateral ( context . collateralType , collateralOwned ) ;
45
+ await setCollateralDebtCeilingToGlobal ( context . collateralType ) ;
46
+ const latestVaultId = await createVaultWithCollateral (
47
+ context . collateralType ,
48
+ collateralOwned . multipliedBy ( 1 )
49
+ ) ;
42
50
console . info ( `Created Vault id: ${ latestVaultId } ` ) ;
43
- return { ...context , latestVaultId } ;
44
- } ,
45
- } ,
46
- {
47
- title : 'Skip time' ,
48
- entry : async context => {
51
+
52
+ console . info ( `Skipping ${ TWO_YEARS_IN_MINUTES } minutes...` ) ;
49
53
await warpTime ( TWO_YEARS_IN_MINUTES , 60 ) ;
50
- return context ;
51
- } ,
52
- } ,
53
- {
54
- title : 'Collect stability fees' ,
55
- entry : async context => {
56
- const collateralType = context . collateralType ;
57
- const latestVaultId = context . latestVaultId ;
54
+
55
+ console . info ( `Collecting stability fees...` ) ;
58
56
const vaultBefore = await fetchVault ( TEST_NETWORK , latestVaultId ) ;
59
- console . info ( `stability fees before ${ vaultBefore . stabilityFeeRate } ` ) ;
60
- await collectStabilityFees ( TEST_NETWORK , collateralType ) ;
57
+ console . info ( `Stability fee before ${ vaultBefore . stabilityFeeRate } ` ) ;
58
+ await collectStabilityFees ( TEST_NETWORK , context . collateralType ) ;
61
59
const vaultAfter = await fetchVault ( TEST_NETWORK , latestVaultId ) ;
62
- console . info ( `stability fees after ${ vaultAfter . stabilityFeeRate } ` ) ;
63
- return context ;
60
+ console . info ( `Stability fee after ${ vaultAfter . stabilityFeeRate } ` ) ;
61
+
62
+ return { ...context , latestVaultId } ;
64
63
} ,
65
64
} ,
66
65
{
@@ -79,20 +78,26 @@ const simulation: Simulation = {
79
78
TEST_NETWORK ,
80
79
context . collateralType
81
80
) ;
82
- const warpSeconds = Math . floor ( auctionLifetime / 2 ) ;
83
- if ( ! warpSeconds ) {
84
- throw new Error ( 'Auction lifetime is too short to warp time.' ) ;
85
- }
86
- console . info ( `Skipping time: ${ warpSeconds } seconds` ) ;
81
+ const INITIAL_WARP_PARTS = 1 / 13 ;
82
+ const warpSeconds = Math . floor ( auctionLifetime * INITIAL_WARP_PARTS ) ;
83
+ console . info ( `Initial warp of ${ INITIAL_WARP_PARTS } of an auction time: ${ warpSeconds } seconds` ) ;
87
84
await warpTime ( warpSeconds , 1 ) ;
88
- return context ;
89
- } ,
90
- } ,
91
- {
92
- title : 'Add DAI and MKR to the wallet' ,
93
- entry : async ( ) => {
94
- await addDaiToBalance ( ) ;
95
- await addMkrToBalance ( ) ;
85
+ const provider = await getProvider ( TEST_NETWORK ) ;
86
+ const STEP_SECONDS = 30 ;
87
+ while ( true ) {
88
+ const initialAuctions = await fetchAuctionsByCollateralType ( TEST_NETWORK , context . collateralType ) ;
89
+ if ( ! initialAuctions [ 0 ] || ! initialAuctions [ 0 ] . isActive ) {
90
+ console . info ( 'No active auctions are found, exiting the "evm_mine" loop' ) ;
91
+ break ;
92
+ }
93
+ console . info ( `Gradually skipping time, one block every ${ STEP_SECONDS } seconds` ) ;
94
+ try {
95
+ await provider . send ( 'evm_mine' , [ ] ) ;
96
+ await new Promise ( resolve => setTimeout ( resolve , STEP_SECONDS * 1000 ) ) ;
97
+ } catch ( error ) {
98
+ console . error ( 'evm_mine failed with' , error ) ;
99
+ }
100
+ }
96
101
} ,
97
102
} ,
98
103
] ,
0 commit comments