Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: new accounting oracle report for Lido (feature/shapella-upgrade) #549

Merged
merged 64 commits into from
Feb 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
4401449
chore: temporary disable strict sizer
TheDZhon Feb 1, 2023
a9346c9
feat: abandon IBeaconReportReceiver
TheDZhon Feb 1, 2023
cf1dd7f
feat: refactor oracle report
TheDZhon Feb 1, 2023
5810ad3
Merge branch 'feature/rebase-limiter' into feature/plain-coverage
TheDZhon Feb 1, 2023
fad9e70
feat: remove pre-rebase handler
TheDZhon Feb 1, 2023
67c6d83
feat: move bunker mode awareness to WQ
TheDZhon Feb 1, 2023
3f8df22
chore: remove deprecated OrderedCallbacksArray
TheDZhon Feb 1, 2023
ec13eea
fix: remove IBeaconReportReceiver
TheDZhon Feb 1, 2023
ae902e2
chore: strict sizer is back
TheDZhon Feb 1, 2023
47f62e6
feat: add ILidoLocator
TheDZhon Feb 1, 2023
fd1def8
feat: use ILidoLocator
TheDZhon Feb 1, 2023
fc9dc24
Merge branch 'feature/rebase-limiter' into feature/plain-coverage
TheDZhon Feb 2, 2023
dabf8da
Versioned.sol inheritance
bulbozaur Feb 2, 2023
9ca8cbf
Versioned.sol inheritance
bulbozaur Feb 2, 2023
d79b768
Versioned.sol comment
bulbozaur Feb 2, 2023
cebbe23
rename setter
bulbozaur Feb 2, 2023
f55ff7a
Merge pull request #530 from lidofinance/feature/versioned
TheDZhon Feb 2, 2023
4c13c77
fix: missing view for ILidoLocator
TheDZhon Feb 2, 2023
8f053ac
LidoLocator update tests
bulbozaur Feb 3, 2023
1609c56
Merge branch 'feature/shapella-upgrade' into feature/plain-coverage
TheDZhon Feb 3, 2023
72566eb
update burner related tests
TheDZhon Feb 2, 2023
0a82ba0
Merge branch 'feature/shapella-upgrade' into feature/plain-coverage
TheDZhon Feb 3, 2023
bb347f0
Merge branch 'feature/shapella-upgrade' into feature/plain-coverage
TheDZhon Feb 3, 2023
f95b717
Merge branch feature/plain-coverage
bulbozaur Feb 3, 2023
cfb4ba9
Merge remote-tracking branch 'origin/feature/plain-coverage' into fea…
bulbozaur Feb 3, 2023
8ff0b09
feat: timed withdrawals pause
TheDZhon Feb 3, 2023
e67568f
Merge branch 'feature/shapella-upgrade' into feature/plain-coverage
TheDZhon Feb 3, 2023
57a5fc5
Merge remote-tracking branch 'origin/feature/shapella-upgrade' into f…
TheDZhon Feb 3, 2023
ac20406
chore: wv init to v1 api change
TheDZhon Feb 3, 2023
d729c7e
fix: new common lido locator interface
TheDZhon Feb 3, 2023
afdf94a
fix: revive getOracle, getTreasury for Lido
TheDZhon Feb 3, 2023
f593930
test fixes
bulbozaur Feb 4, 2023
6fa0b9f
Merge branch 'feature/plain-coverage' into feature/lido-locator-tests
bulbozaur Feb 4, 2023
0908f2c
test fixes
bulbozaur Feb 4, 2023
52b5efa
Merge pull request #538 from lidofinance/feature/lido-locator-tests
TheDZhon Feb 4, 2023
7eb8b8f
fix: reorder args of `updateBunkerMode`
TheDZhon Feb 3, 2023
0ba5642
fix: del bunker from Lido, WQ bunker args reord
TheDZhon Feb 4, 2023
efe479c
feat: new test funcs for events and OZ ACL
TheDZhon Feb 4, 2023
114f3cd
feat: refactor burner + revive tests
TheDZhon Feb 4, 2023
0c7bca4
chore: embed IERC2612 into StETHPermit
TheDZhon Feb 5, 2023
bd72f67
fix: inheritance order for Lido
TheDZhon Feb 5, 2023
869acc8
doc: structured storage for Lido
TheDZhon Feb 5, 2023
717ef37
fix: update oracle report to pass timestamps
TheDZhon Feb 5, 2023
82ca306
chore: abis
TheDZhon Feb 5, 2023
541cd4b
Merge remote-tracking branch 'origin/feature/shapella-upgrade' into f…
TheDZhon Feb 5, 2023
51ea6ee
fix: proper initialization for Lido
TheDZhon Feb 5, 2023
9e457d1
doc: del `receiveStakingRouter` copypasta in Lido
TheDZhon Feb 5, 2023
d70b9f4
doc: process CL state update
TheDZhon Feb 5, 2023
efb59fe
doc: `rewardsBase` -> `preCLBalanceWithAppeared`
TheDZhon Feb 5, 2023
bf25804
fix: low-level lido math to lib
TheDZhon Feb 5, 2023
d4124f8
fix: `_getTotalShares` != 0 for _submit in Lido
TheDZhon Feb 5, 2023
bf507d5
feat: canDeposit for Lido
TheDZhon Feb 5, 2023
24f5fb4
chore: rename _processETHDistribution
TheDZhon Feb 5, 2023
17924c1
chore: `_applyCoverage` cleanups
TheDZhon Feb 5, 2023
8db8ef5
chore: EIP712StETH with ver "2"
TheDZhon Feb 5, 2023
b653a83
chore: CONTRACT_VERSION_POSITION precalc keccak
TheDZhon Feb 5, 2023
188b88d
test fixes
bulbozaur Feb 5, 2023
ae10bb9
Merge remote-tracking branch 'origin/feature/plain-coverage' into fea…
bulbozaur Feb 5, 2023
47922b3
chore: fix stethpermit test domain separator
TheDZhon Feb 5, 2023
7c55d17
Merge pull request #548 from lidofinance/feature/plain-coverage-test-fix
TheDZhon Feb 5, 2023
37fd5fe
fix LidoLocator
bulbozaur Feb 5, 2023
110a539
Merge branch 'feature/shapella-upgrade' into feature/plain-coverage
TheDZhon Feb 5, 2023
2114c10
Merge remote-tracking branch 'origin/feature/plain-coverage' into fea…
TheDZhon Feb 5, 2023
0ccacaf
test: disable positive-token-rebase test
TheDZhon Feb 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
600 changes: 334 additions & 266 deletions contracts/0.4.24/Lido.sol

Large diffs are not rendered by default.

44 changes: 43 additions & 1 deletion contracts/0.4.24/StETHPermit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,53 @@ pragma solidity 0.4.24;
import {UnstructuredStorage} from "@aragon/os/contracts/common/UnstructuredStorage.sol";

import {ECDSA} from "../common/lib/ECDSA.sol";
import {IERC2612} from "./interfaces/IERC2612.sol";
import {IEIP712} from "../common/interfaces/IEIP712.sol";

import {StETH} from "./StETH.sol";

/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC2612 {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*/
function permit(
address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s
) external;

/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);

/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}


contract StETHPermit is IERC2612, StETH {
using UnstructuredStorage for bytes32;

Expand Down
48 changes: 0 additions & 48 deletions contracts/0.4.24/interfaces/IERC2612.sol

This file was deleted.

2 changes: 1 addition & 1 deletion contracts/0.4.24/lib/Pausable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract Pausable {
require(!ACTIVE_FLAG_POSITION.getStorageBool(), "CONTRACT_IS_ACTIVE");
}

function isStopped() external view returns (bool) {
function isStopped() public view returns (bool) {
return !ACTIVE_FLAG_POSITION.getStorageBool();
}

Expand Down
23 changes: 23 additions & 0 deletions contracts/0.4.24/lib/SafeMathSigned256.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-FileCopyrightText: 2023 Lido <[email protected]>

// SPDX-License-Identifier: MIT

// See contracts/COMPILERS.md
pragma solidity 0.4.24;

library SafeMathSigned256 {
function add(int256 a, int256 b) internal pure returns (int256 c) {
c = a + b;

if (a > 0 && b > 0 && c < 0) {
revert ("MATH_SIGNED_OVERFLOW");
} else if (a < 0 && b < 0 && c > 0) {
revert ("MATH_SIGNED_UNDERFLOW");
}
}

function sub(int256 a, int256 b) internal pure returns (int256 c) {
// a - b = a + (-b)
c = add(a, -b);
}
}
13 changes: 6 additions & 7 deletions contracts/0.4.24/nos/NodeOperatorsRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {BytesLib} from "../lib/BytesLib.sol";
import {MemUtils} from "../../common/lib/MemUtils.sol";
import {MinFirstAllocationStrategy} from "../../common/lib/MinFirstAllocationStrategy.sol";
import {SigningKeysStats} from "../lib/SigningKeysStats.sol";

import {Versioned} from "../utils/Versioned.sol";

interface IStETH {
function sharesOf(address _account) external view returns (uint256);
Expand All @@ -34,7 +34,7 @@ interface IStakingModule {
/// @dev Must implement the full version of IStakingModule interface, not only the one declared locally.
/// It's also responsible for distributing rewards to node operators.
/// NOTE: the code below assumes moderate amount of node operators, i.e. up to `MAX_NODE_OPERATORS_COUNT`.
contract NodeOperatorsRegistry is AragonApp, IStakingModule {
contract NodeOperatorsRegistry is AragonApp, IStakingModule, Versioned {
using SafeMath for uint256;
using SafeMath64 for uint64;
using UnstructuredStorage for bytes32;
Expand Down Expand Up @@ -91,8 +91,6 @@ contract NodeOperatorsRegistry is AragonApp, IStakingModule {
//
bytes32 internal constant SIGNING_KEYS_MAPPING_NAME = keccak256("lido.NodeOperatorsRegistry.signingKeysMappingName");

bytes32 internal constant CONTRACT_VERSION_POSITION = keccak256("lido.NodeOperatorsRegistry.contractVersion");

bytes32 internal constant STETH_POSITION = keccak256("lido.NodeOperatorsRegistry.stETH");

/// @dev Total number of operators
Expand Down Expand Up @@ -169,7 +167,8 @@ contract NodeOperatorsRegistry is AragonApp, IStakingModule {
/// For more details see https://github.com/lidofinance/lido-improvement-proposals/blob/develop/LIPS/lip-10.md
function finalizeUpgrade_v2(address _steth, bytes32 _type) external {
require(!isPetrified(), "PETRIFIED");
require(CONTRACT_VERSION_POSITION.getStorageUint256() == 0, "WRONG_BASE_VERSION");
require(hasInitialized(), "NOT_INITIALIZED");
_checkContractVersion(0);
_initialize_v2(_steth, _type);

uint256 totalOperators = getNodeOperatorsCount();
Expand Down Expand Up @@ -212,8 +211,8 @@ contract NodeOperatorsRegistry is AragonApp, IStakingModule {
STETH_POSITION.setStorageAddress(_steth);
TYPE_POSITION.setStorageBytes32(_type);

CONTRACT_VERSION_POSITION.setStorageUint256(2);
emit ContractVersionSet(2);
_setContractVersion(2);

emit StethContractSet(_steth);
emit StakingModuleTypeSet(_type);
}
Expand Down
7 changes: 4 additions & 3 deletions contracts/0.4.24/oracle/LidoOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,14 @@ contract LidoOracle is AragonApp {
/**
* @notice Called by Lido on each rebase.
*/
function handleRebase(
function handlePostTokenRebase(
uint256 /* reportTimestamp */,
uint256 timeElapsed,
uint256 /* preTotalShares */,
uint256 preTotalEther,
uint256 postTotalShares,
uint256 postTotalEther,
uint256 /* totalSharesMintedAsFees */,
uint256 timeElapsed
uint256 /* totalSharesMintedAsFees */
)
external
{
Expand Down
12 changes: 5 additions & 7 deletions contracts/0.4.24/template/LidoTemplate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ contract LidoTemplate is IsContract {
}

// using loops to save contract size
bytes32[7] memory perms;
bytes32[6] memory perms;

// NodeOperatorsRegistry
perms[0] = _state.operators.MANAGE_SIGNING_KEYS();
Expand All @@ -595,12 +595,10 @@ contract LidoTemplate is IsContract {

// Lido
perms[0] = _state.lido.PAUSE_ROLE();
perms[1] = _state.lido.MANAGE_PROTOCOL_CONTRACTS_ROLE();
perms[2] = _state.lido.BURN_ROLE();
perms[3] = _state.lido.RESUME_ROLE();
perms[4] = _state.lido.STAKING_PAUSE_ROLE();
perms[5] = _state.lido.STAKING_CONTROL_ROLE();
for (i = 0; i < 6; ++i) {
perms[1] = _state.lido.RESUME_ROLE();
perms[2] = _state.lido.STAKING_PAUSE_ROLE();
perms[3] = _state.lido.STAKING_CONTROL_ROLE();
for (i = 0; i < 4; ++i) {
_createPermissionForVoting(acl, _state.lido, perms[i], voting);
}
}
Expand Down
24 changes: 6 additions & 18 deletions contracts/0.4.24/test_helpers/LidoMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,13 @@ contract LidoMock is Lido {
uint256 internal constant UNLIMITED_TOKEN_REBASE = uint256(-1);

function initialize(
address _oracle,
address _treasury,
address _stakingRouterAddress,
address _dsmAddress,
address _executionLayerRewardsVault,
address _withdrawalQueue,
address _lidoLocator,
address _eip712StETH
)
public
{
if (_treasury == address(0)) {
_treasury = new VaultMock();
}
if (_executionLayerRewardsVault == address(0)) {
_executionLayerRewardsVault = new VaultMock();
}
super.initialize(
_oracle,
_treasury,
_stakingRouterAddress,
_dsmAddress,
_executionLayerRewardsVault,
_withdrawalQueue,
_lidoLocator,
_eip712StETH
);

Expand Down Expand Up @@ -83,4 +67,8 @@ contract LidoMock is Lido {
function resetEip712StETH() external {
EIP712_STETH_POSITION.setStorageAddress(0);
}

function burnShares(address _account, uint256 _amount) external {
_burnShares(_account, _amount);
}
}
11 changes: 6 additions & 5 deletions contracts/0.4.24/test_helpers/LidoPushableMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ contract LidoPushableMock is Lido {
uint256 public totalRewards;
bool public distributeFeeCalled;

function initialize(address _oracle) public onlyInit {
_setProtocolContracts(_oracle, _oracle, address(0));
function initialize(address _lidoLocator) public onlyInit {
LIDO_LOCATOR_POSITION.setStorageAddress(_lidoLocator);
_resume();
initialized();
}
Expand Down Expand Up @@ -48,15 +48,16 @@ contract LidoPushableMock is Lido {
distributeFeeCalled = false;
}

function getWithdrawalCredentials() public view returns (bytes32) {
IStakingRouter stakingRouter = IStakingRouter(getStakingRouter());
function getWithdrawalCredentials() external view returns (bytes32) {
IStakingRouter stakingRouter = IStakingRouter(getLidoLocator().stakingRouter());

if (address(stakingRouter) != address(0)) {
return stakingRouter.getWithdrawalCredentials();
}
return bytes32(0);
}

function _distributeFee(uint256 _totalRewards) internal {
function _distributeFee(uint256 _totalRewards) internal returns(uint256 sharesMintedAsFees) {
totalRewards = _totalRewards;
distributeFeeCalled = true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
// SPDX-FileCopyrightText: 2023 Lido <[email protected]>
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.9;
pragma solidity 0.4.24;

import { ILegacyOracle } from "../../oracle/AccountingOracle.sol";

interface ILegacyOracle {
function getBeaconSpec() external view returns (
uint64 epochsPerFrame,
uint64 slotsPerEpoch,
uint64 secondsPerSlot,
uint64 genesisTime
);

contract MockLegacyOracle is ILegacyOracle {
function getLastCompletedEpochId() external view returns (uint256);
}

import "../oracle/LidoOracle.sol";

contract MockLegacyOracle is ILegacyOracle, LidoOracle {
uint64 internal _epochsPerFrame;
uint64 internal _slotsPerEpoch;
uint64 internal _secondsPerSlot;
uint64 internal _genesisTime;
uint256 internal _lastCompletedEpochId;

constructor(
uint64 epochsPerFrame,
uint64 slotsPerEpoch,
uint64 secondsPerSlot,
uint64 genesisTime,
uint256 lastCompletedEpochId
) {
_epochsPerFrame = epochsPerFrame;
_slotsPerEpoch = slotsPerEpoch;
_secondsPerSlot = secondsPerSlot;
_genesisTime = genesisTime;
_lastCompletedEpochId = lastCompletedEpochId;
}

function getBeaconSpec() external view returns (
uint64 epochsPerFrame,
Expand All @@ -40,6 +38,21 @@ contract MockLegacyOracle is ILegacyOracle {
);
}


function setParams(
uint64 epochsPerFrame,
uint64 slotsPerEpoch,
uint64 secondsPerSlot,
uint64 genesisTime,
uint256 lastCompletedEpochId
) external {
_epochsPerFrame = epochsPerFrame;
_slotsPerEpoch = slotsPerEpoch;
_secondsPerSlot = secondsPerSlot;
_genesisTime = genesisTime;
_lastCompletedEpochId = lastCompletedEpochId;

}
function getLastCompletedEpochId() external view returns (uint256) {
return _lastCompletedEpochId;
}
Expand Down
Loading