@@ -88,7 +88,6 @@ export async function nodeDeposit(node, bondAmount = '4'.ether, useExpressTicket
8888
8989 const queueIndex = await rocketDepositPool . getQueueIndex ( ) ;
9090 const expressQueueRate = await rocketDAOProtocolSettingsDeposit . getExpressQueueRate ( ) ;
91- const nextAssignmentIsExpress = queueIndex % ( expressQueueRate + 1n ) !== 0n ;
9291
9392 async function getData ( ) {
9493 let data = await Promise . all ( [
@@ -142,6 +141,9 @@ export async function nodeDeposit(node, bondAmount = '4'.ether, useExpressTicket
142141
143142 const data1 = await getData ( ) ;
144143
144+ const expressQueueLengthAfterDeposit = useExpressTicket ? data1 . expressQueueLength + 1n : data1 . expressQueueLength ;
145+ const nextAssignmentIsExpress = ( queueIndex % ( expressQueueRate + 1n ) !== expressQueueRate ) && expressQueueLengthAfterDeposit !== 0n ;
146+
145147 const assignmentsEnabled = await rocketDAOProtocolSettingsDeposit . getAssignDepositsEnabled ( ) ;
146148 const depositPoolCapacity = await rocketDepositPool . getBalance ( ) ;
147149 const amountRequired = '32' . ether - bondAmount ;
@@ -155,6 +157,8 @@ export async function nodeDeposit(node, bondAmount = '4'.ether, useExpressTicket
155157 await tx . wait ( ) ;
156158 }
157159
160+ const megapool = await getMegapoolForNode ( node ) ;
161+
158162 const data2 = await getData ( ) ;
159163
160164 if ( ! data1 . deployed ) {
@@ -187,31 +191,47 @@ export async function nodeDeposit(node, bondAmount = '4'.ether, useExpressTicket
187191
188192 const minipoolInQueue = data1 . minipoolQueueLength > 0n ;
189193
190- const expectSelfAssignment =
191- ! minipoolInQueue &&
194+ const expectAssignment = ! minipoolInQueue &&
192195 assignmentsEnabled &&
193- depositPoolCapacity >= amountRequired &&
196+ depositPoolCapacity >= amountRequired ;
197+
198+ let expectSelfAssignment =
199+ expectAssignment &&
194200 (
195- nextAssignmentIsExpress && data1 . expressQueueLength === 0n ||
196- ! nextAssignmentIsExpress && data1 . standardQueueLength === 0n
201+ ( useExpressTicket && data1 . expressQueueLength === 0n && nextAssignmentIsExpress ) ||
202+ ( ! useExpressTicket && data1 . standardQueueLength === 0n )
197203 ) ;
198204
205+ const queueTop = await rocketDepositPool . getQueueTop ( ) ;
206+ let expectMegapoolAssignment = expectSelfAssignment || ( expectAssignment && ( queueTop [ 0 ] === megapool . target ) ) ;
207+
199208 if ( useExpressTicket ) {
200209 assertBN . equal ( numExpressTicketsDelta , - 1n , 'Did not consume express ticket' ) ;
201- if ( ! expectSelfAssignment ) {
202- assertBN . equal ( expressQueueLengthDelta , 1n , 'Express queue did not grow by 1' ) ;
203- assertBN . equal ( standardQueueLengthDelta , 0n , 'Standard queue grew' ) ;
210+ if ( expectAssignment ) {
211+ if ( nextAssignmentIsExpress ) {
212+ assertBN . equal ( expressQueueLengthDelta , 0n , 'Express queue changed' ) ;
213+ assertBN . equal ( standardQueueLengthDelta , 0n , 'Standard queue changed' ) ;
214+ } else {
215+ assertBN . equal ( expressQueueLengthDelta , 1n , 'Express queue did not grow by 1' ) ;
216+ assertBN . equal ( standardQueueLengthDelta , - 1n , 'Standard queue did not shrink by 1' ) ;
217+ }
204218 }
205219 } else {
206220 assertBN . equal ( numExpressTicketsDelta , 0n , 'Express ticket count incorrect' ) ;
207- if ( ! expectSelfAssignment ) {
208- assertBN . equal ( expressQueueLengthDelta , 0n , 'Express queue grew' ) ;
209- assertBN . equal ( standardQueueLengthDelta , 1n , 'Standard queue did not grow by 1' ) ;
221+ if ( expectAssignment ) {
222+ if ( nextAssignmentIsExpress ) {
223+ console . log ( data1 ) ;
224+ console . log ( data2 ) ;
225+ assertBN . equal ( expressQueueLengthDelta , - 1n , 'Express queue did not shrink by 1' ) ;
226+ assertBN . equal ( standardQueueLengthDelta , 1n , 'Standard queue did not grow by 1' ) ;
227+ } else {
228+ assertBN . equal ( expressQueueLengthDelta , 0n , 'Express queue changed' ) ;
229+ assertBN . equal ( standardQueueLengthDelta , 0n , 'Standard queue changed' ) ;
230+ }
210231 }
211232 }
212233
213234 // Confirm state of new validator
214- const megapool = await getMegapoolForNode ( node ) ;
215235 const validatorInfo = await getValidatorInfo ( megapool , data1 . numValidators ) ;
216236
217237 assertBN . equal ( nodeBondDelta + nodeQueuedBondDelta , bondAmount , 'Incorrect node capital' ) ;
@@ -226,25 +246,29 @@ export async function nodeDeposit(node, bondAmount = '4'.ether, useExpressTicket
226246 assertBN . equal ( assignedValueDelta , 0n , 'Incorrect assigned value' ) ;
227247 assertBN . equal ( userQueuedCapitalDelta , launchValue - bondAmount ) ;
228248 assertBN . equal ( nodeQueuedBondDelta , bondAmount ) ;
229- }
230- else if ( expectSelfAssignment )
231- {
249+ } else if ( expectSelfAssignment ) {
232250 assert . equal ( validatorInfo . inQueue , false , 'Incorrect validator status' ) ;
233251 assert . equal ( validatorInfo . inPrestake , true , 'Incorrect validator status' ) ;
234252 assertBN . equal ( assignedValueDelta , '31' . ether , 'Incorrect assigned value' ) ;
235253 assertBN . equal ( nodeBalanceDelta , 0n , 'Incorrect node balance value' ) ;
236254 // If validator is assigned immediately, then there should be no change in queued capital balances
237255 assertBN . equal ( nodeQueuedBondDelta , 0n ) ;
238256 assertBN . equal ( userQueuedCapitalDelta , 0n ) ;
239- }
240- else
241- {
257+ } else {
242258 assert . equal ( validatorInfo . inQueue , true , 'Incorrect validator status' ) ;
243259 assert . equal ( validatorInfo . inPrestake , false , 'Incorrect validator status' ) ;
244- assertBN . equal ( assignedValueDelta , 0n , 'Incorrect assigned value' ) ;
245- assertBN . equal ( nodeBalanceDelta , expectedNodeBalanceChange , 'Incorrect node balance value' ) ;
246- assertBN . equal ( userQueuedCapitalDelta , launchValue - bondAmount ) ;
247- assertBN . equal ( nodeQueuedBondDelta , bondAmount ) ;
260+
261+ if ( expectMegapoolAssignment ) {
262+ assertBN . equal ( assignedValueDelta , '31' . ether , 'Incorrect assigned value' ) ;
263+ assertBN . equal ( nodeBalanceDelta , 0n , 'Incorrect node balance value' ) ;
264+ assertBN . equal ( userQueuedCapitalDelta , 0n ) ;
265+ assertBN . equal ( nodeQueuedBondDelta , 0n ) ;
266+ } else {
267+ assertBN . equal ( assignedValueDelta , 0n , 'Incorrect assigned value' ) ;
268+ assertBN . equal ( nodeBalanceDelta , expectedNodeBalanceChange , 'Incorrect node balance value' ) ;
269+ assertBN . equal ( userQueuedCapitalDelta , launchValue - bondAmount ) ;
270+ assertBN . equal ( nodeQueuedBondDelta , bondAmount ) ;
271+ }
248272 }
249273
250274 assertBN . equal ( validatorInfo . lastRequestedValue , '32' . ether / milliToWei , 'Incorrect validator lastRequestedValue' ) ;
@@ -468,6 +492,23 @@ export async function getMegapoolForNode(node) {
468492 return new ethers . Contract ( megapoolAddress , combinedAbi , node ) ;
469493}
470494
495+ export async function getMegapoolForNodeAddress ( nodeAddress ) {
496+ const rocketMegapoolFactory = await RocketMegapoolFactory . deployed ( ) ;
497+ const megapoolAddress = await rocketMegapoolFactory . getExpectedAddress ( nodeAddress ) ;
498+
499+ if ( ! await rocketMegapoolFactory . getMegapoolDeployed ( nodeAddress ) ) {
500+ return null
501+ }
502+
503+ const delegateAbi = artifacts . require ( 'RocketMegapoolDelegate' ) . abi ;
504+ const proxyAbi = artifacts . require ( 'RocketMegapoolProxy' ) . abi ;
505+
506+ const combinedAbi = [ ...delegateAbi , ...proxyAbi ] . filter ( fragment => fragment . type !== 'constructor' ) ;
507+
508+ const [ signer ] = await ethers . getSigners ( ) ;
509+ return new ethers . Contract ( megapoolAddress , combinedAbi , signer ) ;
510+ }
511+
471512export async function findInQueue ( megapoolAddress , validatorId , queueKey , indexOffset = 0n , positionOffset = 0n ) {
472513 const maxSliceLength = 100n ; // Number of entries to scan per call
473514
0 commit comments