8000 Lazy oracle unit tests by vp4242 · Pull Request #1192 · lidofinance/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Lazy oracle unit tests #1192

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

Open
wants to merge 11 commits into
base: feat/testnet-2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 6 additions & 7 deletions contracts/0.8.25/vaults/LazyOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ contract LazyOracle is ILazyOracle, AccessControlEnumerableUpgradeable {

struct VaultInfo {
address vault;
uint96 vaultIndex;
uint256 balance;
int256 inOutDelta;
bytes32 withdrawalCredentials;
Expand Down Expand Up @@ -205,9 +204,8 @@ contract LazyOracle is ILazyOracle, AccessControlEnumerableUpgradeable {
VaultHub.VaultRecord memory record = vaultHub.vaultRecord(vaultAddress);
batch[i] = VaultInfo(
vaultAddress,
connection.vaultIndex,
address(vault).balance,
vaultHub.inOutDeltaAsOfLastRefSlot(vaultAddress),
record.inOutDelta.value,
vault.withdrawalCredentials(),
record.liabilityShares,
_mintableStETH(vaultAddress),
Expand Down Expand Up @@ -300,10 +298,10 @@ contract LazyOracle is ILazyOracle, AccessControlEnumerableUpgradeable {
/// @param _totalValue the total value of the vault in refSlot
/// @return totalValueWithoutQuarantine the smoothed total value of the vault after sanity checks
/// @return inOutDeltaOnRefSlot the inOutDelta in the refSlot
function _handleSanityChecks(
address _vault,
uint256 _totalValue
) public returns (uint256 totalValueWithoutQuarantine, int256 inOutDeltaOnRefSlot) {
function _handleSanityChecks(address _vault, uint256 _totalValue)
internal
returns (uint256 totalValueWithoutQuarantine, int256 inOutDeltaOnRefSlot)
{
VaultHub vaultHub = _vaultHub();
VaultHub.VaultRecord memory record = vaultHub.vaultRecord(_vault);

Expand Down Expand Up @@ -404,6 +402,7 @@ contract LazyOracle is ILazyOracle, AccessControlEnumerableUpgradeable {
event QuarantinedDeposit(address indexed vault, uint128 delta);
event SanityParamsUpdated(uint64 quarantinePeriod, uint16 maxRewardRatioBP);
event QuarantineExpired(address indexed vault, uint128 delta);

error AdminCannotBeZero();
error NotAuthorized();
error InvalidProof();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: UNLICENSED
// for testing purposes only

pragma solidity >=0.8.0;

contract Lido__MockForLazyOracle {
constructor() {}

function getPooledEthBySharesRoundUp(uint256 value) external view returns (uint256) {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: UNLICENSED
// for testing purposes only

pragma solidity >=0.8.0;
10000
contract OperatorGrid__MockForLazyOracle {
constructor() {}

function effectiveShareLimit(address) external view returns (uint256) {
return 1000000000000000000;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// SPDX-License-Identifier: UNLICENSED
// for testing purposes only

pragma solidity >=0.8.0;

import {ILidoLocator} from "contracts/common/interfaces/ILidoLocator.sol";
import {ILido} from "contracts/common/interfaces/ILido.sol";
import {ILidoLocator} from "contracts/common/interfaces/ILidoLocator.sol";
import {VaultHub} from "contracts/0.8.25/vaults/VaultHub.sol";
import {RefSlotCache} from "contracts/0.8.25/vaults/lib/RefSlotCache.sol";

contract VaultHub__MockForLazyOracle {
using RefSlotCache for RefSlotCache.Int112WithRefSlotCache;

address[] public mock__vaults;
mapping(address vault => VaultHub.VaultConnection connection) public mock__vaultConnections;
mapping(address vault => VaultHub.VaultRecord record) public mock__vaultRecords;

address public mock__lastReportedVault;
uint256 public mock__lastReported_timestamp;
uint256 public mock__lastReported_totalValue;
int256 public mock__lastReported_inOutDelta;
uint256 public mock__lastReported_cumulativeLidoFees;
uint256 public mock__lastReported_liabilityShares;
uint256 public mock__lastReported_slashingReserve;

constructor() {
mock__vaults.push(address(0));
}

function mock__addVault(address vault) external {
mock__vaults.push(vault);
}

function mock__setVaultConnection(address vault, VaultHub.VaultConnection memory connection) external {
mock__vaultConnections[vault] = connection;
}

function mock__setVaultRecord(address vault, VaultHub.VaultRecord memory record) external {
mock__vaultRecords[vault] = record;
}

function vaultsCount() external view returns (uint256) {
return mock__vaults.length - 1;
}

function vaultByIndex(uint256 index) external view returns (address) {
return mock__vaults[index];
}

function inOutDeltaAsOfLastRefSlot(address vault) external view returns (int256) {
return mock__vaultRecords[vault].inOutDelta.value;
}

function vaultConnection(address vault) external view returns (VaultHub.VaultConnection memory) {
return mock__vaultConnections[vault];
}

function maxLockableValue(address vault) external view returns (uint256) {
return 1000000000000000000;
}

function vaultRecord(address vault) external view returns (VaultHub.VaultRecord memory) {
return mock__vaultRecords[vault];
}

function applyVaultReport(
address _vault,
uint256 _reportTimestamp,
uint256 _reportTotalValue,
int256 _reportInOutDelta,
uint256 _reportCumulativeLidoFees,
uint256 _reportLiabilityShares,
uint256 _reportSlashingReserve
) external {
mock__lastReportedVault = _vault;
mock__lastReported_timestamp = _reportTimestamp;
mock__lastReported_totalValue = _reportTotalValue;
mock__lastReported_inOutDelta = _reportInOutDelta;
mock__lastReported_cumulativeLidoFees = _reportCumulativeLidoFees;
mock__lastReported_liabilityShares = _reportLiabilityShares;
mock__lastReported_slashingReserve = _reportSlashingReserve;

mock__vaultRecords[_vault].report.inOutDelta = int112(_reportInOutDelta);
mock__vaultRecords[_vault].inOutDelta.value = int112(_reportInOutDelta);
mock__vaultRecords[_vault].inOutDelta.valueOnRefSlot = int112(_reportInOutDelta);
mock__vaultRecords[_vault].inOutDelta.refSlot = uint32(_reportTimestamp);
mock__vaultRecords[_vault].report.timestamp = uint32(_reportTimestamp);
mock__vaultRecords[_vault].report.totalValue = uint112(_reportTotalValue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: UNLICENSED
// for testing purposes only

pragma solidity >=0.8.0;

contract Vault__MockForLazyOracle {
constructor() {}

function withdrawalCredentials() external view returns (bytes32) {
return bytes32(0);
}
}
Loading
Loading
0