-
Notifications
You must be signed in to change notification settings - Fork 466
Conversation
2e0af0f
to
eb9b9b3
Compare
/** | ||
* _.zip() that clips to the shortest array. | ||
*/ | ||
export function shortZip<T1, T2>(a: T1[], b: T2[]): Array<[T1, T2]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is better than _.zip()
because the return type isn't some weird Array<[T1 | undefined, T2 | undefined]>
, which makes _.zip()
pretty inconvenient to use in TS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not finished with my review but wanted to get something in ASAP. I will continue later today!
MixinStakeStorage, | ||
MixinStakingPoolMakers, | ||
MixinStakeBalances, | ||
MixinCumulativeRewards, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you got a hold of Greg's linearization script
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we can give imports another pass after all big features are merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Come to the dark side, Amir. These aren't the imports you're looking for.
contracts/staking/contracts/src/staking_pools/MixinCumulativeRewards.sol
Outdated
Show resolved
Hide resolved
contracts/staking/contracts/src/staking_pools/MixinCumulativeRewards.sol
Show resolved
Hide resolved
contracts/staking/contracts/src/staking_pools/MixinCumulativeRewards.sol
Show resolved
Hide resolved
contracts/staking/contracts/src/staking_pools/MixinStakingPoolRewards.sol
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome job overall! Not done reading the tests, but here are some comments in the meantime
contracts/staking/contracts/src/interfaces/IStakingPoolRewardVault.sol
Outdated
Show resolved
Hide resolved
contracts/staking/contracts/src/staking_pools/MixinCumulativeRewards.sol
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm partway through my review. I think the overall approach looks good, and I like that there's relatively little logic outside of finalization had to change +1.
internal | ||
/// @dev Returns the total balance of this contract, including WETH. | ||
/// @return totalBalance Total balance. | ||
function getTotalBalance() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add that this is the fee balance? This will add context to the greater staking API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As in, add it to idk, aren't they two different things? The contract balance could include subsidies, remaining rewards, etc.totalFeesCollected
?
Edit: misread
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I guess they are. Basically, just a name to disambiguate between this balance and the stake balances. Maybe getTotalPayableBalance
or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could just remove this function. All it's doing is suming ETH and WETH balance, and we could use the space.
|
||
/// @dev Exposes some internal functions from various contracts to avoid | ||
/// cyclical dependencies. | ||
contract MixinAbstract { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I don't have full context, but I feel like this could be solved more cleanly by reorganizing the mixins.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idk how to fix the cyclical deps without introducing something like this or an interface, and we don't use the interface convention for mixins in this package so I went with this. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kk I'll look into it a bit more during the final pass. If not then could be good to make this an interface since it's declarations only.
contracts/staking/contracts/src/staking_pools/MixinStakingPoolRewards.sol
Outdated
Show resolved
Hide resolved
contracts/staking/contracts/src/staking_pools/MixinStakingPoolRewards.sol
Outdated
Show resolved
Hide resolved
contracts/staking/contracts/src/staking_pools/MixinStakingPoolRewards.sol
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a review for the remaining Solidity!
contracts/staking/contracts/src/staking_pools/MixinStakingPoolRewards.sol
Show resolved
Hide resolved
contracts/staking/contracts/src/staking_pools/MixinStakingPoolRewards.sol
Outdated
Show resolved
Hide resolved
contracts/staking/contracts/src/staking_pools/MixinStakingPoolRewards.sol
Outdated
Show resolved
Hide resolved
contracts/staking/contracts/src/staking_pools/MixinStakingPoolRewards.sol
Outdated
Show resolved
Hide resolved
contracts/staking/contracts/src/staking_pools/MixinStakingPoolRewards.sol
Outdated
Show resolved
Hide resolved
contracts/staking/contracts/src/staking_pools/MixinStakingPoolRewards.sol
Outdated
Show resolved
Hide resolved
contracts/staking/contracts/src/staking_pools/MixinStakingPoolRewards.sol
Outdated
Show resolved
Hide resolved
contracts/staking/contracts/src/staking_pools/MixinStakingPoolRewards.sol
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only looked over changes to base-contract
and order-utils
. Those look good to me :)
5be0eb0
to
dde306a
Compare
…ult to `_rewards_test`.
…s in `getTopicsForIndexedArgs()`.
…actorings. `@0x/contracts-staking`: Add finalization-related protocol fees unit tests.
`@0x/contracts-staking`: Convert all rewards to WETH. `@0x/contracts-staking`: Style changes. `@0x/contracts-staking`: Address misc. review comments. `@0x/contracts-staking`: Make `LibFractions` scaling a separate step.
b180d75
to
eac4520
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to go. I did not leave any comments on any code related to the EthVault
or StakingPoolRewardsVault
because of #2186 . Please do not make any further changes to these contracts, since they will be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work on this one! I had a couple of nits, but it looks good to go.
`@0x/contracts-utils`: Use `safeDiv()` in `LibFractions.normalize()`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking really solid! I left four comments; three of which we can address in the final pass. Although one regarding reward intervals should be addressed before we merge.
|
||
// Emit an event so keepers know what pools to pass into | ||
// `finalize()`. | ||
emit StakingPoolActivated(currentEpoch_, poolId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like there's more information we may want to communicate in this function. What would you think of emitting a single event that communicates: the epoch, pool id, whether payments was in ETH or WETH, and whether or not the fee was attributed to the pool?
internal | ||
/// @dev Returns the total balance of this contract, including WETH. | ||
/// @return totalBalance Total balance. | ||
function getTotalBalance() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I guess they are. Basically, just a name to disambiguate between this balance and the stake balances. Maybe getTotalPayableBalance
or something?
|
||
/// @dev Exposes some internal functions from various contracts to avoid | ||
/// cyclical dependencies. | ||
contract MixinAbstract { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kk I'll look into it a bit more during the final pass. If not then could be good to make this an interface since it's declarations only.
if (unsyncedStake.currentEpoch >= lastRewardEpoch) { | ||
return reward; | ||
} | ||
// From here we know: `unsyncedStake.currentEpoch < currentEpoch > 0`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the intervals have been shifted. Is this on purpose?
# Previously the ranges were:
[unsyncedStake.currentEpoch-1 .. unsyncedStake.currentEpoch]
[unsyncedStake.currentEpoch .. lastRewardEpoch]
# Now the ranges are:
[unsyncedStake.currentEpoch .. unsyncedStake.currentEpoch + 1]
[unsyncedStake.currentEpoch + 1 .. lastRewardEpoch + 1]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. This is from crediting rewards at the top of an epoch rather than at the end, and folding in unfinalized rewards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo nits! 🚀 🚀 🚀
`@0x/contracts-staking`: Fix linter errors.
Description
At long last, multi-block finalization is here!
Overview
Multi-Block finalization provides an asynchronous method for finalizing pool rewards that can be done over the span of multiple transactions, without halting the next epoch.
endEpoch()
, the epoch will immediately advance and finalization begins.finalizePools()
-- potentially over several transactions.Notes
currentEpoch
andcurrentEpoch-1
. Now we maintain them forcurrentEpoch
andcurrentEpoch+1
(I know, it's weird).MixinFinalizer
, which contains the bulk of the finalization logic. Notable functions include:endEpoch()
, which anyone can call to end an epoch and begin the finalization process.finalizePools()
, which finalizes multiple pools at once._finalizePool()
, an internal function that finalizes a single pool. Called byMixinStakingPoolRewards
when syncing stake._getUnfinalizedPoolRewards()
, an internal function that calculates the unfinalized rewards owed to a pool. Also called byMixinStakingPoolRewards
in order to return accurate balances while pools are still being finalized.MixinExchangeFees
has been pretty heavily modified to integrate the tracking we need.but I'm still missing ones for the new logic added topayProtocolFee()
. Any takers?EthVault
andStakingPoolRewardVault
to support efficient batching of finalization:recordDepositFor()
pattern and just bulk transferring funds via their fallbacks.FinalizerActor
has been updated to accurately and more robustly compute finalization balances.cobbDouglas()
function is now in its own library named, surprise,LibCobbDouglas
.LibFractions
to fix precision issues I was running into._getUnfinalizedPoolRewards()
ofMixinFinalizer
.Further Reading
That oooold quip doc I created on MBF still largely applies, if you want a natural language description of the finalization algorithm and state variables associated with it. Ignore the one titled "Marrying Delayed Staking with MBF." That was the work of a lunatic.
Testing instructions
Types of changes
Checklist:
[WIP]
if necessary.