11import { executeUpgrade } from '../_helpers/upgrade' ;
2- import { RocketNetworkVoting , RocketNodeStaking } from '../../test/_utils/artifacts' ;
2+ import { RocketDAOProtocolSettingsNode , RocketNetworkVoting , RocketNodeStaking } from '../../test/_utils/artifacts' ;
33import { assertBN } from '../../test/_helpers/bn' ;
4- import { getMinipoolMinimumRPLStake , stakeMinipool } from '../../test/_helpers/minipool' ;
4+ import { stakeMinipool } from '../../test/_helpers/minipool' ;
55import { createMinipool } from '../_helpers/minipool' ;
66import { userDeposit } from '../../test/_helpers/deposit' ;
77import { nodeDeposit } from '../../test/_helpers/megapool' ;
88import { BigSqrt } from '../../test/_helpers/bigmath' ;
9+ import { submitPrices } from '../../test/network/scenario-submit-prices' ;
10+ import { setNodeTrusted } from '../../test/_helpers/node' ;
11+ import { shouldRevert } from '../../test/_utils/testing' ;
12+ import { setDAOProtocolBootstrapSetting } from '../../test/dao/scenario-dao-protocol-bootstrap' ;
913
1014const { beforeEach, describe, before, it } = require ( 'mocha' ) ;
1115const { globalSnapShot } = require ( '../../test/_utils/snapshotting' ) ;
@@ -30,6 +34,9 @@ export default function() {
3034 let owner ,
3135 node ,
3236 nodeWithdrawalAddress ,
37+ trustedNode1 ,
38+ trustedNode2 ,
39+ trustedNode3 ,
3340 random ;
3441
3542 let upgradeContract ;
@@ -41,6 +48,9 @@ export default function() {
4148 owner ,
4249 node ,
4350 nodeWithdrawalAddress ,
51+ trustedNode1 ,
52+ trustedNode2 ,
53+ trustedNode3 ,
4454 random ,
4555 ] = await ethers . getSigners ( ) ;
4656
@@ -134,5 +144,61 @@ export default function() {
134144 */
135145 assertBN . equal ( votingPower , BigSqrt ( '3000' . ether * '1' . ether ) ) ;
136146 } ) ;
147+
148+ it ( printTitle ( 'node' , 'can unstake legacy staked RPL down to 15% of borrowed ETH' ) , async ( ) => {
149+ // Register node
150+ await registerNode ( { from : node } ) ;
151+ // Register trusted nodes
152+ await registerNode ( { from : trustedNode1 } ) ;
153+ await registerNode ( { from : trustedNode2 } ) ;
154+ await registerNode ( { from : trustedNode3 } ) ;
155+ await setNodeTrusted ( trustedNode1 , 'saas_1' , 'node@home.com' , owner ) ;
156+ await setNodeTrusted ( trustedNode2 , 'saas_2' , 'node@home.com' , owner ) ;
157+ await setNodeTrusted ( trustedNode3 , 'saas_3' , 'node@home.com' , owner ) ;
158+ // Set RPL price to 0.1 ETH
159+ let block = await ethers . provider . getBlockNumber ( ) ;
160+ let slotTimestamp = '1600000000' ;
161+ let rplPrice = '0.1' . ether ;
162+ await submitPrices ( block , slotTimestamp , rplPrice , { from : trustedNode1 } ) ;
163+ await submitPrices ( block , slotTimestamp , rplPrice , { from : trustedNode2 } ) ;
164+ await submitPrices ( block , slotTimestamp , rplPrice , { from : trustedNode3 } ) ;
165+ // Mint 1000 RPL and stake
166+ await mintRPL ( owner , node , '1000' . ether ) ;
167+ await stakeRPL ( node , '1000' . ether ) ;
168+ // Create a 8 ETH minipool
169+ const minipool = ( await createMinipool ( { from : node , value : '8' . ether } ) ) . connect ( node ) ;
170+ // Perform a user deposit with enough to assign the minipool
171+ await userDeposit ( { from : random , value : '24' . ether } ) ;
172+ // Confirm prelaunch status
173+ const status = await minipool . getStatus ( ) ;
174+ assertBN . equal ( status , 1n )
175+ // Execute upgrade
176+ await executeUpgrade ( owner , upgradeContract , rocketStorageAddress ) ;
177+ // Set minimum stake setting to 15%
178+ await setDAOProtocolBootstrapSetting ( RocketDAOProtocolSettingsNode , "node.minimum.legacy.staked.rpl" , '0.15' . ether , { from : owner } ) ;
179+ // Check minimum stake
180+ /**
181+ * With 1x 8 ETH minipool, borrowed ETH is 24 ETH
182+ * At 0.1 ETH per RPL, the minimum should be 15% of 240 RPL
183+ * Minimum is therefore 36 RPL
184+ */
185+ const rocketNodeStaking = await RocketNodeStaking . deployed ( ) ;
186+ const minimumStake = await rocketNodeStaking . getNodeMinimumLegacyRPLStake ( node . address ) ;
187+ assertBN . equal ( minimumStake , '36' . ether ) ;
188+ // Should not be able to unstake below 36 RPL (1000 - 36 = 964)
189+ await shouldRevert (
190+ unstakeLegacyRpl ( '965' . ether , { from : node } ) ,
191+ 'Was able to unstake below 15% minimum' ,
192+ 'Insufficient legacy staked RPL'
193+ ) ;
194+ // Should be able to unstake to 36 RPL
195+ await unstakeLegacyRpl ( '964' . ether , { from : node } ) ;
196+ // Should not be able to unstake any more
197+ await shouldRevert (
198+ unstakeLegacyRpl ( 1n , { from : node } ) ,
199+ 'Was able to unstake below 15% minimum' ,
200+ 'Insufficient legacy staked RPL'
201+ ) ;
202+ } ) ;
137203 } ) ;
138204}
0 commit comments