Skip to content
Verified contractExactMIT

WireGrid

Address0xcce64cb7d5427bdaff60d6d3aa512c4dcb05a00c
Balance

0.02 ETH

 

Transactions

2

 

Compiler

solc 0.8.26

 

Same code

1 more contract

 

Details

Compiler
solc 0.8.26+commit.8a97fa7a
Language
solidity
Optimization
Yes, 1,000,000 runs
EVM version
cancun
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,676,681
Creation transaction
0xfa856fa139…ae8841d963

src/WireGrid.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

/*
    THE GRID — plug in, draw current, cash out. A money-game on Ethereum.

      PLUG    deposit ETH to wire conductors into the grid.
      SPLICE  compound your current into more conductors — widen the cable.
      CUT     sell your accrued current back to ETH — pull the plug.

    Conductors produce "current" every second; a constant-product market prices
    current in ETH against the grid's pot. No mint, no admin over your node — only
    your own conductors and the pot's ETH. Uses block.timestamp. Themed on Wire,
    the streaming primitive: your current is a live draw off the grid.
*/

contract WireGrid {
    uint256 private constant CURRENT_PER_CONDUCTOR = 1080000; // seconds of draw per conductor
    uint256 private constant PSN = 10000;
    uint256 private constant PSNH = 5000;
    uint256 public constant DEV_FEE = 3;    // %
    uint256 public constant REF_BONUS = 12; // % of spliced current to the referrer

    address public immutable dev;
    bool public energized;
    uint256 public marketCurrent;

    mapping(address => uint256) public conductors;
    mapping(address => uint256) public claimedCurrent;
    mapping(address => uint256) public lastDraw;
    mapping(address => address) public patched; // referrer

    event Plugged(address indexed who, uint256 ethIn, uint256 currentBought);
    event Spliced(address indexed who, uint256 newConductors);
    event Cut(address indexed who, uint256 ethOut);
    event Energized(uint256 eth);

    constructor() { dev = msg.sender; }
    modifier live() { require(energized, "grid dark"); _; }

    /// @notice PLUG — wire conductors with ETH.
    function plug(address ref) public payable live {
        uint256 bought = calcBuy(msg.value, address(this).balance - msg.value);
        bought -= _fee(bought);
        uint256 fee = _fee(msg.value);
        (bool ok, ) = payable(dev).call{value: fee}(""); require(ok, "fee");
        claimedCurrent[msg.sender] += bought;
        _splice(ref);
        emit Plugged(msg.sender, msg.value, bought);
    }

    /// @notice SPLICE — compound current into more conductors.
    function splice(address ref) public live { _splice(ref); }

    function _splice(address ref) internal {
        if (ref == msg.sender) ref = address(0);
        if (patched[msg.sender] == address(0) && ref != address(0)) patched[msg.sender] = ref;
        uint256 used = myCurrent(msg.sender);
        uint256 gained = used / CURRENT_PER_CONDUCTOR;
        conductors[msg.sender] += gained;
        claimedCurrent[msg.sender] = 0;
        lastDraw[msg.sender] = block.timestamp;
        if (patched[msg.sender] != address(0)) claimedCurrent[patched[msg.sender]] += (used * REF_BONUS) / 100;
        marketCurrent += used / 5;
        emit Spliced(msg.sender, gained);
    }

    /// @notice CUT — sell your current back to ETH.
    function cut() public live {
        uint256 have = myCurrent(msg.sender);
        require(have > 0, "no current");
        uint256 ethValue = calcSell(have);
        uint256 fee = _fee(ethValue);
        claimedCurrent[msg.sender] = 0;
        lastDraw[msg.sender] = block.timestamp;
        marketCurrent += have;
        (bool okf, ) = payable(dev).call{value: fee}(""); require(okf, "fee");
        (bool ok, ) = payable(msg.sender).call{value: ethValue - fee}(""); require(ok, "pay");
        emit Cut(msg.sender, ethValue - fee);
    }

    /// @notice Energize the grid (dev seeds the pot to open the game).
    function energize() external payable {
        require(msg.sender == dev, "not dev");
        require(marketCurrent == 0, "on");
        energized = true;
        marketCurrent = 108_000_000_000;
        emit Energized(msg.value);
    }

    // ── views ──────────────────────────────────────────────────────────────────
    function myCurrent(address a) public view returns (uint256) { return claimedCurrent[a] + drawSince(a); }
    function drawSince(address a) public view returns (uint256) {
        if (lastDraw[a] == 0) return 0;
        uint256 s = _min(CURRENT_PER_CONDUCTOR, block.timestamp - lastDraw[a]);
        return s * conductors[a];
    }
    function calcTrade(uint256 rt, uint256 rs, uint256 bs) public pure returns (uint256) {
        return (PSN * bs) / (PSNH + ((PSN * rs + PSNH * rt) / rt));
    }
    function calcSell(uint256 c) public view returns (uint256) { return c == 0 ? 0 : calcTrade(c, marketCurrent, address(this).balance); }
    function calcBuy(uint256 eth, uint256 bal) public view returns (uint256) { return calcTrade(eth, bal, marketCurrent); }
    function currentRewards(address a) external view returns (uint256) { return calcSell(myCurrent(a)); }
    function getPot() external view returns (uint256) { return address(this).balance; }
    function myConductors(address a) external view returns (uint256) { return conductors[a]; }
    function _fee(uint256 x) private pure returns (uint256) { return (x * DEV_FEE) / 100; }
    function _min(uint256 a, uint256 b) private pure returns (uint256) { return a < b ? a : b; }
    receive() external payable {}
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 1000000,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "forge-std/=lib/forge-std/src/",
    "v4-core/=lib/v4-core/src/",
    "@ensdomains/=lib/v4-core/node_modules/@ensdomains/",
    "@openzeppelin/=lib/v4-core/lib/openzeppelin-contracts/",
    "ds-test/=lib/v4-core/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "hardhat/=lib/v4-core/node_modules/hardhat/",
    "openzeppelin-contracts/=lib/v4-core/lib/openzeppelin-contracts/",
    "solmate/=lib/v4-core/lib/solmate/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.