Verified contractPartialMIT
EthSnapshot
Address0xa459fc0a2abb6b7632e76084c53ec29bbbc10a70
- Balance
0 ETH
- Transactions
2
- Compiler
solc 0.8.26
- Same code
Only this contract
Details
- Compiler
- solc 0.8.26+commit.8a97fa7a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,358,395
- Creation transaction
- 0xd85b8c298b…9c66d8a296
src/cells/EthSnapshot.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
/// @title EthSnapshot (lives on Ethereum)
/// @notice A price "photographer": anyone (in practice the bot, right after a batch closes) calls `snapshot()`, and
/// the contract ITSELF reads a fixed list of on-chain sources on Ethereum (e.g. stake.link's wstLINK →
/// LINK rate, a Curve pool's EMA price and balances) and commits the raw values with the block time.
/// Robinhood Chain proves the commitment from an Ethereum block hash and gets the values. Whoever calls
/// cannot influence what is read: the sources and the calls are fixed at deployment, forever.
/// @dev No owner, no settings. A new source = a new contract (and a holders' vote to use it).
/// Storage (proven from Robinhood Chain): `count` = slot 0, `commits` = slot 1;
/// commits[i] = keccak256(abi.encode(i, timestamp, blockNumber, values)).
/// A source that fails or answers too short is recorded as 0 (the reader treats 0 as "no value").
contract EthSnapshot {
struct Source {
address target;
bytes data; // static call data, e.g. abi.encodeCall(IWst.getUnderlyingByWrapped, (1e18))
uint8 word; // which 32-byte word of the answer to keep (0 = first)
}
uint256 public count; // slot 0
mapping(uint256 index => bytes32) public commits; // slot 1
Source[] private _sources;
uint256 public lastTimestamp;
error InvalidConfig();
error SameBlock();
event Snapshot(uint256 indexed index, uint256 timestamp, uint256 blockNumber, uint256[] values);
constructor(Source[] memory sources_) {
if (sources_.length == 0 || sources_.length > 16) revert InvalidConfig();
for (uint256 i; i < sources_.length; i++) {
if (sources_[i].target.code.length == 0) revert InvalidConfig();
_sources.push(sources_[i]);
}
}
/// @notice Read every source now and commit the values. At most one snapshot per block.
function snapshot() external returns (uint256 index, uint256[] memory values) {
if (block.timestamp == lastTimestamp) revert SameBlock();
lastTimestamp = block.timestamp;
values = read();
index = count++;
commits[index] = keccak256(abi.encode(index, block.timestamp, block.number, values));
emit Snapshot(index, block.timestamp, block.number, values);
}
/// @notice What a snapshot would record right now.
function read() public view returns (uint256[] memory values) {
values = new uint256[](_sources.length);
for (uint256 i; i < _sources.length; i++) {
Source storage s = _sources[i];
(bool ok, bytes memory out) = s.target.staticcall{gas: 200_000}(s.data);
uint256 at = uint256(s.word) * 32;
if (ok && out.length >= at + 32) {
uint256 v;
assembly {
v := mload(add(add(out, 32), at))
}
values[i] = v;
}
}
}
function sources() external view returns (Source[] memory) {
return _sources;
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": false,
"bytecodeHash": "none",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"forge-std/=lib/forge-std/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.