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,68 @@ 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+ // Submit different prices
163+ await submitPrices ( block , slotTimestamp , rplPrice , {
164+ from : trustedNode1 ,
165+ } ) ;
166+ await submitPrices ( block , slotTimestamp , rplPrice , {
167+ from : trustedNode2 ,
168+ } ) ;
169+ await submitPrices ( block , slotTimestamp , rplPrice , {
170+ from : trustedNode3 ,
171+ } ) ;
172+ // Mint 1000 RPL and stake
173+ await mintRPL ( owner , node , '1000' . ether ) ;
174+ await stakeRPL ( node , '1000' . ether ) ;
175+ // Create a 8 ETH minipool
176+ const minipool = ( await createMinipool ( { from : node , value : '8' . ether } ) ) . connect ( node ) ;
177+ // Perform a user deposit with enough to assign the minipool
178+ await userDeposit ( { from : random , value : '24' . ether } ) ;
179+ // Confirm prelaunch status
180+ const status = await minipool . getStatus ( ) ;
181+ assertBN . equal ( status , 1n )
182+ // Execute upgrade
183+ await executeUpgrade ( owner , upgradeContract , rocketStorageAddress ) ;
184+ // Set minimum stake setting to 15%
185+ await setDAOProtocolBootstrapSetting ( RocketDAOProtocolSettingsNode , "node.minimum.legacy.staked.rpl" , '0.15' . ether , { from : owner } ) ;
186+ // Check minimum stake
187+ /**
188+ * With 1x 8 ETH minipool, borrowed ETH is 24 ETH
189+ * At 0.1 ETH per RPL, the minimum should be 15% of 240 RPL
190+ * Minimum is therefore 36 RPL
191+ */
192+ const rocketNodeStaking = await RocketNodeStaking . deployed ( ) ;
193+ const minimumStake = await rocketNodeStaking . getNodeMinimumLegacyRPLStake ( node . address ) ;
194+ assertBN . equal ( minimumStake , '36' . ether ) ;
195+ // Should not be able to unstake below 36 RPL (1000 - 36 = 964)
196+ await shouldRevert (
197+ unstakeLegacyRpl ( '965' . ether , { from : node } ) ,
198+ 'Was able to unstake below 15% minimum' ,
199+ 'Insufficient legacy staked RPL'
200+ ) ;
201+ // Should be able to unstake to 36 RPL
202+ await unstakeLegacyRpl ( '964' . ether , { from : node } ) ;
203+ // Should not be able to unstake any more
204+ await shouldRevert (
205+ unstakeLegacyRpl ( 1n , { from : node } ) ,
206+ 'Was able to unstake below 15% minimum' ,
207+ 'Insufficient legacy staked RPL'
208+ ) ;
209+ } ) ;
137210 } ) ;
138211}
0 commit comments