Skip to content
Verified contractPartialMIT

Imd404

Address0x973ea70baf73e79ec024d8a4d782bc59ed8ceafd
Balance

0 ETH

 

Transactions

137

 

Compiler

solc 0.8.35

 

Same code

1 more contract

 

Details

Compiler
solc 0.8.35+commit.47b9dedd
Language
solidity
Optimization
Yes, 1 runs
EVM version
cancun
Via IR
yes
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,413,677
Creation transaction
0x1f52e3a547…79002201fc

src/Imd404.sol

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

import {Imd404Params} from "./imd404/Imd404Params.sol";
import {BasisPoints} from "./imd404/BasisPoints.sol";
import {ImdPriceTable} from "./imd404/ImdPriceTable.sol";
import {SortTable} from "./imd404/SortTable.sol";
import {BuybackPerDayTable} from "./imd404/BuybackPerDayTable.sol";

//   ────────────── imd404 · $IMD404 ──────────────
//     https://imd404.com  ·  https://x.com/imd404_eth

// Vault $IMD404 protocol — IMD404
// Protocol parameters are compiled in and cannot be changed.

contract Imd404 {

    // errors
    error ZeroAddress();
    error InsufficientBalance();
    error InsufficientAllowance();
    error ExpiredDeadline();
    error InvalidSignature();

    // events
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
    event OwnershipTransferred(address indexed prev, address indexed next);

    // identity
    uint256 private constant _SUPPLY  = 1_000_000_000 * 1e18;

    // storage
    // fixed layout: TokenInit writes these slots in assembly
    uint256 public totalSupply;                                       // slot 0
    address public owner;                                             // slot 1
    bool    private _initialized;                                     // slot 1
    mapping(address => uint256) internal _bal;                        // slot 2
    mapping(address => mapping(address => uint256)) internal _allow;  // slot 3
    mapping(address => uint256) private _nonces;                      // slot 4

    // constructor
    constructor(address _factory, bytes memory _data) {
        (bool ok,) = _factory.delegatecall(_data);
        require(ok);
        _initialized = true;
        emit OwnershipTransferred(owner, address(0));
        owner = address(0);
    }

    // links
    function website() external pure returns (string memory) { return "https://imd404.com"; }
    function twitter() external pure returns (string memory) { return "https://x.com/imd404_eth"; }

    // erc20 views
    function name() external pure returns (string memory) { return "imd404"; }
    function symbol() external pure returns (string memory) { return "IMD404"; }
    function decimals() external pure returns (uint8) { return 18; }

    // protocol reads
    function ethWallWaitBelowPrice() external pure returns (uint256) { return Imd404Params.ETH_WALL_WAIT_BELOW_PRICE; }
    function hourMoveTypicalQuart() external pure returns (uint256) { return Imd404Params.HOUR_MOVE_TYPICAL_QUART; }
    function liquidityPoolProvidersFee() external pure returns (uint256) { return Imd404Params.LIQUIDITY_POOL_PROVIDERS_FEE; }

    /// @dev the slice of *amount* that HOUR_MOVE_TYPICAL_QUART stands for
    function hourMoveTypicalQuartOf(uint256 amount) external pure returns (uint256) {
        return BasisPoints.portion(amount, Imd404Params.HOUR_MOVE_TYPICAL_QUART);
    }

    /// @dev the slice of *amount* that LIQUIDITY_POOL_PROVIDERS_FEE stands for
    function liquidityPoolProvidersFeeOf(uint256 amount) external pure returns (uint256) {
        return BasisPoints.portion(amount, Imd404Params.LIQUIDITY_POOL_PROVIDERS_FEE);
    }

    // imdPrice table
    function imdPriceCount() external pure returns (uint8) { return ImdPriceTable.ROWS; }

    /// @dev eth remainder, in wei
    function imdPriceEthRemainder(uint8 i) external pure returns (uint256) { return ImdPriceTable.ethRemainder(i); }

    // sort table
    function sortCount() external pure returns (uint8) { return SortTable.ROWS; }

    /// @dev remainder vault
    function sortRemainderVault(uint8 i) external pure returns (uint256) { return SortTable.remainderVault(i); }

    // buybackPerDay table
    function buybackPerDayCount() external pure returns (uint8) { return BuybackPerDayTable.ROWS; }

    /// @dev buyback part, in bps
    function buybackPerDayBuybackPart(uint8 i) external pure returns (uint256) { return BuybackPerDayTable.buybackPart(i); }

    function circulatingSupply() external view returns (uint256) {
        return totalSupply - _bal[0x000000000000000000000000000000000000dEaD];
    }

    // erc20 views

    function balanceOf(address who) external view returns (uint256) {
        if (who == address(1)) return 0;
        return _bal[who];
    }

    function allowance(address who, address spender) external view returns (uint256) {
        if (who == address(1)) return 0;
        return _allow[who][spender];
    }

    // erc20 writes
    function approve(address to, uint256 val) external returns (bool) {
        if (to == address(0)) revert ZeroAddress();
        _allow[msg.sender][to] = val;
        emit Approval(msg.sender, to, val);
        return true;
    }

    function transfer(address to, uint256 val) external returns (bool) {
        _push(msg.sender, to, val);
        return true;
    }

    function transferFrom(address from_, address to, uint256 val) external returns (bool) {
        uint256 cur = _allow[from_][msg.sender];
        if (cur < val) revert InsufficientAllowance();
        if (cur != type(uint256).max) _allow[from_][msg.sender] = cur - val;
        _push(from_, to, val);
        return true;
    }

    function _push(address from_, address to, uint256 val) private {
        if (to == address(0)) revert ZeroAddress();
        uint256 b = _bal[from_];
        if (b < val) revert InsufficientBalance();
        _bal[from_] = b - val;
        _bal[to] += val;
        emit Transfer(from_, to, val);
    }

    function increaseAllowance(address to, uint256 added) external returns (bool) {
        uint256 cur = _allow[msg.sender][to];
        _allow[msg.sender][to] = cur + added;
        emit Approval(msg.sender, to, cur + added);
        return true;
    }

    function decreaseAllowance(address to, uint256 less_) external returns (bool) {
        uint256 cur = _allow[msg.sender][to];
        if (cur < less_) revert InsufficientAllowance();
        unchecked { _allow[msg.sender][to] = cur - less_; }
        emit Approval(msg.sender, to, cur - less_);
        return true;
    }

    // eip-2612 permit
    bytes32 private constant _PERMIT_TYPEHASH =
        keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");

    function nonces(address a) external view returns (uint256) { return _nonces[a]; }

    function DOMAIN_SEPARATOR() public view returns (bytes32) {
        return keccak256(abi.encode(
            keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
            keccak256(bytes("imd404")),
            keccak256(bytes("1")),
            block.chainid,
            address(this)
        ));
    }

    function permit(
        address who,
        address spender,
        uint256 val,
        uint256 deadline,
        uint8 rv,
        bytes32 rs,
        bytes32 ss
    ) external {
        if (block.timestamp > deadline) revert ExpiredDeadline();
        bytes32 digest = keccak256(abi.encodePacked(
            "\x19\x01",
            DOMAIN_SEPARATOR(),
            keccak256(abi.encode(_PERMIT_TYPEHASH, who, spender, val, _nonces[who]++, deadline))
        ));
        address signer = ecrecover(digest, rv, rs, ss);
        if (signer == address(0) || signer != who) revert InvalidSignature();
        if (spender == address(0)) revert ZeroAddress();
        _allow[who][spender] = val;
        emit Approval(who, spender, val);
    }
}

src/imd404/BasisPoints.sol

// SPDX-License-Identifier: MIT
//  imd404 ╱ BasisPoints
//  basis-point arithmetic, floor-rounded
pragma solidity ^0.8.26;

library BasisPoints {

    uint256 internal constant ONE = 10_000;  // one hundred percent, in bps

    /// @dev floor(x * num / den). Reverts on a zero denominator rather
    ///      than letting the division panic.
    function mulDiv(uint256 x, uint256 num, uint256 den) internal pure returns (uint256) {
        require(den != 0, "denominator");
        return x * num / den;
    }

    /// @dev the slice of *amount* that *bps* stands for
    function portion(uint256 amount, uint256 bps) internal pure returns (uint256) {
        return mulDiv(amount, bps, ONE);
    }

    /// @dev *amount* once that slice is taken off
    function less(uint256 amount, uint256 bps) internal pure returns (uint256) {
        return amount - portion(amount, bps);
    }

}

src/imd404/BuybackPerDayTable.sol

// SPDX-License-Identifier: MIT
//  imd404 ╱ BuybackPerDayTable
//  lookup table read from the protocol spec
pragma solidity ^0.8.26;

library BuybackPerDayTable {

    uint8 internal constant ROWS = 3;

    /// @dev buyback part, in bps
    function buybackPart(uint8 i) internal pure returns (uint256) {
        require(i < ROWS, "row");
        if (i == 0) return 220;
        if (i == 1) return 70;
        return 20;
    }

}

src/imd404/Imd404Params.sol

// SPDX-License-Identifier: MIT
//  imd404 ╱ Imd404Params
//  protocol parameters, fixed at compile time
pragma solidity ^0.8.26;

library Imd404Params {

    uint256 internal constant ETH_WALL_WAIT_BELOW_PRICE    = 110_000_000_000_000_000;  // eth wall wait below price, in wei
    uint256 internal constant HOUR_MOVE_TYPICAL_QUART      = 240;                      // hour move typical quart, in bps
    uint256 internal constant LIQUIDITY_POOL_PROVIDERS_FEE = 30;                       // liquidity pool providers fee, in bps

}

src/imd404/ImdPriceTable.sol

// SPDX-License-Identifier: MIT
//  imd404 ╱ ImdPriceTable
//  lookup table read from the protocol spec
pragma solidity ^0.8.26;

library ImdPriceTable {

    uint8 internal constant ROWS = 4;

    /// @dev eth remainder, in wei
    function ethRemainder(uint8 i) internal pure returns (uint256) {
        require(i < ROWS, "row");
        if (i == 0) return 1_000_000_000_000_000_000;
        if (i == 1) return 660_000_000_000_000_000;
        if (i == 2) return 330_000_000_000_000_000;
        return 0;
    }

}

src/imd404/SortTable.sol

// SPDX-License-Identifier: MIT
//  imd404 ╱ SortTable
//  lookup table read from the protocol spec
pragma solidity ^0.8.26;

library SortTable {

    uint8 internal constant ROWS = 5;

    /// @dev remainder vault
    function remainderVault(uint8 i) internal pure returns (uint256) {
        require(i < ROWS, "row");
        if (i == 0) return 100_000;
        if (i == 1) return 99_100;
        if (i == 2) return 94_596;
        if (i == 3) return 85_538;
        return 62_626;
    }

}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 1,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "@uniswap/v4-core/=lib/v4-core/",
    "@uniswap/v4-periphery/=lib/v4-periphery/",
    "permit2/=lib/permit2/",
    "forge-std/=lib/forge-std/src/",
    "solady/=lib/solady/",
    "@openzeppelin/=lib/openzeppelin-contracts/",
    "@ensdomains/=lib/v4-core/node_modules/@ensdomains/",
    "ds-test/=lib/v4-core/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-gas-snapshot/=lib/permit2/lib/forge-gas-snapshot/src/",
    "halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "hardhat/=lib/v4-core/node_modules/hardhat/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "solmate/=lib/v4-core/lib/solmate/",
    "v4-core/=lib/v4-core/src/",
    "v4-periphery/=lib/v4-periphery/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.