Skip to content
Verified contractExactMIT

Volt

Address0x374817fcfaf2d78d3a314a8741cfa03faea44b3f
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, 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
0x53d670e03a…4cbe89c763

src/Volt.sol

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

// https://x.com/WireERC

contract Volt {
    string public constant name = "Volt";
    string public constant symbol = "VOLT";
    uint8 public constant decimals = 18;
    uint256 public immutable totalSupply;

    mapping(address => int256) internal _settled;
    mapping(address => uint64) internal _lastUpdate;
    mapping(address => int256) public netFlow; // tokens/sec, inflow positive
    mapping(address => mapping(address => uint256)) public allowance;

    struct Stream { address from; address to; uint256 rate; uint64 start; bool open; }
    Stream[] public streams;                                   // index 0 is a sentinel
    mapping(address => mapping(address => uint256)) public wireId; // (from,to) => id, 0 = none
    mapping(address => uint256) public outCount;               // open wires out of an account
    mapping(address => uint256) public inCount;                // open wires into an account

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
    event WireOpened(uint256 indexed id, address indexed from, address indexed to, uint256 rate);
    event WireCut(uint256 indexed id, address indexed by);

    constructor(uint256 supply, address to) {
        totalSupply = supply;
        _settled[to] = int256(supply);
        _lastUpdate[to] = uint64(block.timestamp);
        streams.push(Stream(address(0), address(0), 0, 0, false));
        emit Transfer(address(0), to, supply);
    }

    // ── realtime accounting ──────────────────────────────────────────────────
    function _settle(address a) internal {
        uint64 nowt = uint64(block.timestamp);
        uint256 dt = nowt - _lastUpdate[a];
        if (dt != 0 && netFlow[a] != 0) _settled[a] += netFlow[a] * int256(dt);
        _lastUpdate[a] = nowt;
    }

    function realtimeBalanceOf(address a) public view returns (int256) {
        uint256 dt = block.timestamp - _lastUpdate[a];
        return _settled[a] + netFlow[a] * int256(dt);
    }

    function balanceOf(address a) public view returns (uint256) {
        int256 b = realtimeBalanceOf(a);
        return b > 0 ? uint256(b) : 0;
    }

    function flowOf(address a) external view returns (int256) { return netFlow[a]; }
    function streamCount() external view returns (uint256) { return streams.length - 1; }

    // ── ERC-20 (one-shot) ────────────────────────────────────────────────────
    function approve(address spender, uint256 value) external returns (bool) {
        allowance[msg.sender][spender] = value;
        emit Approval(msg.sender, spender, value);
        return true;
    }
    function transfer(address to, uint256 amount) external returns (bool) { return _move(msg.sender, to, amount); }
    function transferFrom(address from, address to, uint256 amount) external returns (bool) {
        uint256 a = allowance[from][msg.sender];
        if (a != type(uint256).max) { require(a >= amount, "allowance"); allowance[from][msg.sender] = a - amount; }
        return _move(from, to, amount);
    }
    function _move(address from, address to, uint256 amount) internal returns (bool) {
        require(to != address(0), "zero");
        _settle(from); _settle(to);
        require(_settled[from] >= int256(amount), "balance");
        _settled[from] -= int256(amount);
        _settled[to] += int256(amount);
        emit Transfer(from, to, amount);
        return true;
    }

    // ── the wire primitive ───────────────────────────────────────────────────
    /// @notice Open a continuous wire: stream `rate` tokens/sec from you to `to`.
    function openWire(address to, uint256 rate) external returns (uint256 id) {
        require(to != address(0) && to != msg.sender && rate > 0, "args");
        require(wireId[msg.sender][to] == 0, "wire exists");
        _settle(msg.sender); _settle(to);
        require(realtimeBalanceOf(msg.sender) > 0, "insolvent");
        netFlow[msg.sender] -= int256(rate);
        netFlow[to] += int256(rate);
        streams.push(Stream(msg.sender, to, rate, uint64(block.timestamp), true));
        id = streams.length - 1;
        wireId[msg.sender][to] = id;
        outCount[msg.sender] += 1; inCount[to] += 1;
        emit WireOpened(id, msg.sender, to, rate);
    }

    /// @notice Cut an open wire (either endpoint may pull the plug).
    function cut(uint256 id) external {
        Stream storage s = streams[id];
        require(s.open, "closed");
        require(msg.sender == s.from || msg.sender == s.to, "auth");
        _settle(s.from); _settle(s.to);
        netFlow[s.from] += int256(s.rate);
        netFlow[s.to] -= int256(s.rate);
        s.open = false;
        wireId[s.from][s.to] = 0;
        outCount[s.from] -= 1; inCount[s.to] -= 1;
        emit WireCut(id, msg.sender);
    }

    /// @notice Crystallize your live balance into settled state (optional; every
    ///         open/cut/transfer already settles the parties involved).
    function tap() external { _settle(msg.sender); }
}
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.