Skip to content

Commit 59f1a29

Browse files
committed
Add capital ratio snapshot without distribute to assignFunds
1 parent 3975a26 commit 59f1a29

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

contracts/contract/megapool/RocketMegapoolDelegate.sol

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ contract RocketMegapoolDelegate is RocketMegapoolDelegateBase, RocketMegapoolDel
320320
nodeBond += assignedNodeBond;
321321
userQueuedCapital -= assignedUserCapital;
322322
nodeQueuedBond -= assignedNodeBond;
323+
// Store capital ratio on first assignment
324+
if (lastDistributionTime == 0) {
325+
_calculateAndSaveCapitalRatio();
326+
}
323327
// Delete prestake signature for a small gas refund (no longer needed)
324328
delete prestakeSignatures[_validatorId];
325329
// Emit event
@@ -335,7 +339,7 @@ contract RocketMegapoolDelegate is RocketMegapoolDelegateBase, RocketMegapoolDel
335339
require(validator.inPrestake, "Validator must be pre-staked");
336340
// Store last requested value for later
337341
uint32 lastRequestedValue = validator.lastRequestedValue;
338-
// Snapshot capital ratio (sets lastDistributionTime on first validator)
342+
// Snapshot capital ratio
339343
_snapshotCapitalRatio();
340344
// Account for assigned value
341345
uint256 assignedUsed = lastRequestedValue * milliToWei - prestakeValue;
@@ -772,13 +776,18 @@ contract RocketMegapoolDelegate is RocketMegapoolDelegateBase, RocketMegapoolDel
772776
return RocketNodeDepositInterface(rocketStorage.getAddress(rocketNodeDepositKey));
773777
}
774778

775-
/// @dev Calculates the current capital ratio of this Megapool and notifies RocketNetworkRevenues to snapshot it
776-
/// Attempts to distribute rewards at current ratio before snapshotting
779+
/// @dev Attempts to distribute rewards at current ratio before snapshotting capital ratio
777780
function _snapshotCapitalRatio() internal {
778781
// Try to distribute rewards before updating capital ratio
779782
if (numExitingValidators == 0 && numLockedValidators == 0) {
780783
_distributeAmount(getPendingRewards());
781784
}
785+
// Snapshot capital ratio
786+
_calculateAndSaveCapitalRatio();
787+
}
788+
789+
/// @dev Calculates the current capital ratio of this Megapool and notifies RocketNetworkRevenues to snapshot it
790+
function _calculateAndSaveCapitalRatio() internal {
782791
// Calculate and send capital ratio to RocketNetworkRevenues for snapshotting
783792
RocketNetworkRevenuesInterface rocketNetworkRevenues = RocketNetworkRevenuesInterface(getContractAddress("rocketNetworkRevenues"));
784793
if (nodeBond + userCapital > 0) {

test/megapool/megapool-tests.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,15 +1276,6 @@ export default function() {
12761276
await setDAOProtocolBootstrapSetting(RocketDAOProtocolSettingsMegapool, 'megapool.time.before.dissolve', dissolvePeriod, { from: owner });
12771277
});
12781278

1279-
it(printTitle('node', 'receives any ETH that was already in the megapool prior to first validator stake'), async () => {
1280-
const preStakeRewards = '0.123'.ether;
1281-
await nodeDeposit(node);
1282-
await mockRewards(megapool, preStakeRewards);
1283-
await stakeMegapoolValidator(megapool, 0);
1284-
assertBN.equal(await megapool.getRefundValue(), preStakeRewards);
1285-
assertBN.equal(await megapool.getPendingRewards(), 0n);
1286-
});
1287-
12881279
it(printTitle('node', 'can deposit while assignments are disabled and be assigned once enabled again'), async () => {
12891280
const rocketDepositPool = await RocketDepositPool.deployed();
12901281
// Disable deposit assignments
@@ -1830,8 +1821,8 @@ export default function() {
18301821
// Exit remaining 2 validators
18311822
await exitValidator(megapool, 1, '32'.ether);
18321823
await exitValidator(megapool, 2, '32'.ether);
1833-
// Capital ratio should be 0
1834-
assertBN.equal(await rocketNetworkRevenues.getNodeAverageCapitalRatioSince(node.address, await megapool.getLastDistributionTime()), 0n);
1824+
// Capital ratio should remain 12.5%
1825+
assertBN.equal(await rocketNetworkRevenues.getNodeAverageCapitalRatioSince(node.address, await megapool.getLastDistributionTime()), '0.125'.ether);
18351826
// Create a new validator
18361827
await nodeDeposit(node);
18371828
await stakeMegapoolValidator(megapool, 3);

0 commit comments

Comments
 (0)