DiamondVault
0x4ede9a7a34f4e65ba6974eb345fc8cf8f7f5d01f
Verification
Verified
v0.8.30+commit.73712a01
Type
Contract
6,035 bytes
ABI entries
36
23 read · 6 write
License
none
Contract information
- Address
- 0x4ede9a7a34f4e65ba6974eb345fc8cf8f7f5d01f
- Chain
- Robinhood Chain (4663)
- Compiler
- v0.8.30+commit.73712a01
- Optimization
- Enabled
- Creator
- 0x6C9647b903…18f7b96F9d
- Creation tx
- 0x0bcab24a77…3f8567174f
Token
Not a token
This contract does not expose ERC-20 metadata.
Read contract (23)
accA() → uint256
accB() → uint256
carry() → uint256
commonPerShare() → uint256
commonShares() → uint256
convTotal() → uint256
convictionOf(address) → uint256
cursor() → uint256
diamondBps() → uint16
epoch() → uint64
heldSecondsOf(address) → uint256
holders(address) → uint256, uint256, uint64, uint256, uint256, int256, uint256, bool, bool
lastAccrue() → uint64
lastSeen() → uint256
leaderboard(uint256, uint256) → address[], uint256[], uint256[], uint256
listMin() → uint256
owner() → address
pending(address) → uint256
reward() → address
ring(uint256) → address
ringLength() → uint256
token() → address
totalConviction() → uint256
Events (3)
DepositedPaidSplitChanged
ABI
[
{
"inputs": [
{
"internalType": "address",
"name": "token_",
"type": "address"
},
{
"internalType": "address",
"name": "reward_",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "OnlyOwner",
"type": "error"
},
{
"inputs": [],
"name": "OnlyToken",
"type": "error"
},
{
"inputs": [],
"name": "ZeroAddress",
"type": "error"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "total",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "toCommon",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "toDiamond",
"type": "uint256"
}
],
"name": "Deposited",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "holder",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "Paid",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint16",
"name": "diamondBps",
"type": "uint16"
}
],
"name": "SplitChanged",
"type": "event"
},
{
"inputs": [],
"name": "accA",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "accB",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "carry",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "collect",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "commonPerShare",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "commonShares",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "convTotal",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "who",
"type": "address"
}
],
"name": "convictionOf",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "cursor",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "diamondBps",
"outputs": [
{
"internalType": "uint16",
"name": "",
"type": "uint16"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "epoch",
"outputs": [
{
"internalType": "uint64",
"name": "",
"type": "uint64"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "feed",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "who",
"type": "address"
}
],
"name": "heldSecondsOf",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "holders",
"outputs": [
{
"internalType": "uint256",
"name": "bal",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "convLast",
"type": "uint256"
},
{
"internalType": "uint64",
"name": "tLast",
"type": "uint64"
},
{
"internalType": "uint256",
"name": "baseA",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "baseB",
"type": "uint256"
},
{
"internalType": "int256",
"name": "commonCredit",
"type": "int256"
},
{
"internalType": "uint256",
"name": "owed",
"type": "uint256"
},
{
"internalType": "bool",
"name": "init",
"type": "bool"
},
{
"internalType": "bool",
"name": "listed",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "lastAccrue",
"outputs": [
{
"internalType": "uint64",
"name": "",
"type": "uint64"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "lastSeen",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "offset",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "count",
"type": "uint256"
}
],
"name": "leaderboard",
"outputs": [
{
"internalType": "address[]",
"name": "who",
"type": "address[]"
},
{
"internalType": "uint256[]",
"name": "conviction",
"type": "uint256[]"
},
{
"internalType": "uint256[]",
"name": "balance",
"type": "uint256[]"
},
{
"internalType": "uint256",
"name": "total",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "listMin",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "next",
"type": "address"
}
],
"name": "passOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "who",
"type": "address"
}
],
"name": "pending",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "reward",
"outputs": [
{
"internalType": "contract IERC20",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "ring",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "ringLength",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint16",
"name": "bps",
"type": "uint16"
}
],
"name": "setDiamondBps",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "who",
"type": "address"
},
{
"internalType": "uint256",
"name": "newBal",
"type": "uint256"
}
],
"name": "sync",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "token",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalConviction",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "work",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]Source code
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.30;
/*
GME · The sequel is onchain
Website: https://gmeonchain.com
X: https://x.com/GMEONCHAIN
*/
interface IERC20 {
function balanceOf(address) external view returns (uint256);
function transfer(address, uint256) external returns (bool);
function transferFrom(address, address, uint256) external returns (bool);
function totalSupply() external view returns (uint256);
}
contract DiamondVault {
error OnlyToken();
error OnlyOwner();
error ZeroAddress();
address public immutable token;
IERC20 public immutable reward;
uint64 public immutable epoch;
uint256 public immutable listMin; // min balance to enter the auto-payout ring (anti-spam)
uint256 private constant MAG = 2 ** 128;
uint16 public diamondBps = 2500;
uint256 public carry; // reward received while no pool was eligible; added to next feed
uint256 public lastSeen; // reward balance already accounted for (delta tracking)
uint256 public commonPerShare;
uint256 public commonShares;
uint256 public convTotal;
uint64 public lastAccrue;
uint256 public accA;
uint256 public accB;
struct Holder {
uint256 bal;
uint256 convLast;
uint64 tLast;
uint256 baseA;
uint256 baseB;
int256 commonCredit;
uint256 owed;
bool init;
bool listed;
}
mapping(address => Holder) public holders;
address[] public ring;
mapping(address => uint256) private ringIndex;
uint256 public cursor;
address public owner;
event Deposited(uint256 total, uint256 toCommon, uint256 toDiamond);
event Paid(address indexed holder, uint256 amount);
event SplitChanged(uint16 diamondBps);
modifier onlyToken() {
if (msg.sender != token) revert OnlyToken();
_;
}
modifier onlyOwner() {
if (msg.sender != owner) revert OnlyOwner();
_;
}
constructor(address token_, address reward_) {
if (token_ == address(0) || reward_ == address(0)) revert ZeroAddress();
token = token_;
reward = IERC20(reward_);
owner = msg.sender;
epoch = uint64(block.timestamp);
lastAccrue = uint64(block.timestamp);
listMin = IERC20(token_).totalSupply() / 1_000_000; // 0.0001% of supply
}
function _accrueGlobal() internal {
uint64 nowT = uint64(block.timestamp);
uint64 dt = nowT - lastAccrue;
if (dt > 0) {
convTotal += commonShares * dt;
lastAccrue = nowT;
}
}
function _earned(Holder storage h) internal view returns (uint256) {
int256 common = int256(commonPerShare * h.bal) - h.commonCredit;
uint256 dA = accA - h.baseA;
uint256 dB = accB - h.baseB;
uint256 bracket = dB - uint256(h.tLast) * dA;
uint256 diamond = h.convLast * dA + h.bal * bracket;
int256 total = common + int256(diamond);
if (total < 0) total = 0;
return uint256(total) / MAG;
}
function _touch(Holder storage h) internal {
_accrueGlobal();
if (h.init) {
uint256 e = _earned(h);
if (e > 0) h.owed += e;
uint64 tau = uint64(block.timestamp) - epoch;
h.convLast += h.bal * (tau - h.tLast);
h.tLast = tau;
} else {
h.tLast = uint64(block.timestamp) - epoch;
h.init = true;
}
h.baseA = accA;
h.baseB = accB;
h.commonCredit = int256(commonPerShare * h.bal);
}
function sync(address who, uint256 newBal) external onlyToken {
Holder storage h = holders[who];
_touch(h);
uint256 old = h.bal;
if (newBal > old) {
uint256 d = newBal - old;
commonShares += d;
h.commonCredit += int256(commonPerShare * d);
} else if (newBal < old) {
uint256 d = old - newBal;
commonShares -= d;
h.commonCredit -= int256(commonPerShare * d);
if (h.convLast > 0 && old > 0) {
uint256 burn = (h.convLast * d) / old;
if (burn > 0) {
h.convLast -= burn;
convTotal -= burn;
}
}
}
h.bal = newBal;
_ringSync(who, h);
}
/// @notice Account for GME received. The token swaps fees straight into this
/// vault (it can't send them to itself — INVALID_TO), so we credit the balance
/// delta rather than pulling. Also catches any GME sent here directly.
function feed(uint256) external {
_accrueGlobal();
uint256 bal = reward.balanceOf(address(this));
uint256 received = bal > lastSeen ? bal - lastSeen : 0; // guard against a reverse-split rebase
lastSeen = bal;
uint256 amt = received + carry;
carry = 0;
if (amt == 0) {
emit Deposited(0, 0, 0);
return;
}
// no eligible holders in either pool yet: hold it, distribute on the next feed
if (commonShares == 0 && convTotal == 0) {
carry = amt;
emit Deposited(received, 0, 0);
return;
}
uint256 toDiamond = (amt * diamondBps) / 10_000;
uint256 toCommon = amt - toDiamond;
// if exactly one pool is empty, route its slice to the other so nothing is orphaned
if (convTotal == 0) {
toCommon = amt;
toDiamond = 0;
} else if (commonShares == 0) {
toDiamond = amt;
toCommon = 0;
}
if (toCommon > 0) commonPerShare += (toCommon * MAG) / commonShares;
if (toDiamond > 0) {
uint256 tau = uint64(block.timestamp) - epoch;
uint256 inc = (toDiamond * MAG) / convTotal;
accA += inc;
accB += inc * tau;
}
emit Deposited(received, toCommon, toDiamond);
}
function _flush(address who, Holder storage h) internal {
uint256 pay = h.owed;
if (pay > 0) {
h.owed = 0;
try reward.transfer(who, pay) returns (bool ok) {
if (ok) {
lastSeen = lastSeen >= pay ? lastSeen - pay : 0; // balance dropped by pay
emit Paid(who, pay);
} else {
h.owed = pay;
}
} catch {
h.owed = pay;
}
}
}
function collect() external {
Holder storage h = holders[msg.sender];
_touch(h);
_flush(msg.sender, h);
}
function work(uint256) external {
uint256 n = ring.length;
if (n == 0) return;
_accrueGlobal();
uint256 gasFloor = 160_000;
uint256 i = cursor;
uint256 scanned;
while (scanned < n && gasleft() > gasFloor) {
address who = ring[i];
Holder storage h = holders[who];
_touch(h);
_flush(who, h);
unchecked {
i = (i + 1) % n;
++scanned;
}
}
cursor = i;
}
function _ringSync(address who, Holder storage h) internal {
bool shouldList = h.bal >= listMin && h.bal > 0;
if (shouldList && !h.listed) {
h.listed = true;
ringIndex[who] = ring.length;
ring.push(who);
} else if (!shouldList && h.listed) {
h.listed = false;
uint256 idx = ringIndex[who];
uint256 last = ring.length - 1;
address lastAddr = ring[last];
ring[idx] = lastAddr;
ringIndex[lastAddr] = idx;
ring.pop();
if (cursor >= ring.length) cursor = 0;
}
}
function pending(address who) external view returns (uint256) {
return _earned(holders[who]) + holders[who].owed;
}
function ringLength() external view returns (uint256) {
return ring.length;
}
function convictionOf(address who) public view returns (uint256) {
Holder storage h = holders[who];
if (!h.init) return 0;
uint256 tau = uint64(block.timestamp) - epoch;
return h.convLast + h.bal * (tau - uint256(h.tLast));
}
function totalConviction() public view returns (uint256) {
uint256 dt = uint64(block.timestamp) - lastAccrue;
return convTotal + commonShares * dt;
}
function heldSecondsOf(address who) external view returns (uint256) {
uint256 bal = holders[who].bal;
if (bal == 0) return 0;
return convictionOf(who) / bal;
}
function leaderboard(uint256 offset, uint256 count)
external
view
returns (address[] memory who, uint256[] memory conviction, uint256[] memory balance, uint256 total)
{
total = ring.length;
if (offset >= total) {
return (new address[](0), new uint256[](0), new uint256[](0), total);
}
uint256 end = offset + count;
if (end > total) end = total;
uint256 len = end - offset;
who = new address[](len);
conviction = new uint256[](len);
balance = new uint256[](len);
for (uint256 i; i < len; ++i) {
address a = ring[offset + i];
who[i] = a;
conviction[i] = convictionOf(a);
balance[i] = holders[a].bal;
}
}
function setDiamondBps(uint16 bps) external onlyOwner {
require(bps <= 5000, "cap 50%");
diamondBps = bps;
emit SplitChanged(bps);
}
function passOwnership(address next) external onlyOwner {
if (next == address(0)) revert ZeroAddress();
owner = next;
}
}
Chain explorer1684msChain node82ms