lidofinance / lido-oracle

Pythonic Lido Oracle daemon
GNU General Public License v3.0
46 stars 26 forks source link

Report number of validators, get timing and epoch from oracle contract, remove slot-related logic, ABI changes. #35

Closed ongrid closed 3 years ago

ongrid commented 3 years ago

Related oracle interface

contract LidoOracle {

    // timing parameters of Beacon Chain specification (may be overriden by corresponding setter)
    // See https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/beacon-chain.md
    struct BeaconSpec {
        uint64 slotsPerEpoch = 32; // SLOTS_PER_EPOCH
        uint64 secondsPerSlot = 12; // SECONDS_PER_SLOT
        // The genesis expected to happen on Dec 1, 2020, 12pm UTC
        // But the exact time depends on actual staking and will be known post factum
        uint64 genesisTime = 1606824000;
    }

    BeaconSpec public beaconSpec;
    uint256 lastPushedEpochId;

    function setBeaconSpec(uint64 slotsPerEpoch, uint64 secondsPerSlot, uint64 genesisTime) public {
        // Some require for sanity checks here
        beaconSpec.slotsPerEpoch = slotsPerEpoch;
        beaconSpec.secondsPerSlot = secondsPerSlot;
        beaconSpec.genesisTime = genesisTime;
    }

    // Returns the current reportable epoch object with its timestamp boundaries.
    // Used by oracle daemons
    function getCurrentReportableEpoch() public {
        epochId = getCurrentEpochID();
        // Use SafeMath here
        startTimestamp = epochId * beaconSpec.secondsPerSlot * beaconSpec.slotsPerEpoch
        endTimestamp = (epochId + 1) * beaconSpec.secondsPerSlot * beaconSpec.slotsPerEpoch - 1
    }

    // Returns the current epochId
    function getCurrentReportableEpochID() internal {
        // Switch to safeMath
        return(block.timestamp / beaconSpec.secondsPerSlot / beaconSpec.slotsPerEpoch);
    }

    // instead of pushData. Called by Oracle Daemons
    function reportBeacon(uint256 _epoch, uint128 _beaconValidators, uint128 _beaconBalance) public {
        require(_epoch > lastPushedEpochId);
        require(_epoch <= getCurrentEpochID());
        report = Report(beaconValidators: _beaconValidators, beaconBalance: _beaconBalance});
        // add event just for mock debugging
    }
}
ongrid commented 3 years ago

Everything is either DONE or moved to separate, more specific issues.