Forkchoice Ethereum Mainnet

Address Contract Partially Verified

Address 0x4edF071a7dEe52fBE663DF7873994725ba91Cdc7
Balance 0 ETH
Nonce 1
Code Size 8127 bytes
Indexed Transactions 0 (1 on-chain, 0.7% indexed)
External Etherscan · Sourcify

Contract Bytecode

8127 bytes
0x608060405234801561001057600080fd5b50600436106100ea5760003560e01c8063715018a61161008c578063963dfa8611610066578063963dfa86146101a1578063c19d93fb146101b4578063f2fde38b14610206578063fb12e1a41461021957600080fd5b8063715018a61461016b57806388ef1d05146101735780638da5cb5b1461018657600080fd5b806342e94c90116100c857806342e94c90146101095780634eef850d14610132578063540dd4bf146101455780635a3c5a1a1461016357600080fd5b806324600fc3146100ef578063380d831b146100f95780633ccfd60b14610101575b600080fd5b6100f7610221565b005b6100f76103b4565b6100f7610446565b61011c610117366004611be1565b61070f565b6040516101299190611c7e565b60405180910390f35b6100f7610140366004611d6a565b6108ee565b61014f6207a12081565b60405162ffffff9091168152602001610129565b6100f7610cc3565b6100f76110be565b6100f7610181366004611e10565b6110d2565b6000546040516001600160a01b039091168152602001610129565b6100f76101af366004611be1565b611246565b60408051808201825260008082526020918201528151808301835260015462ffffff811680835264ffffffffff6301000000909204821692840192835284519081529151169181019190915201610129565b6100f7610214366004611be1565b6112d0565b6100f7611310565b610229611331565b6040805180820190915260015462ffffff811682526301000000900464ffffffffff16602082018190526000036102735760405163028504eb60e51b815260040160405180910390fd5b6040516370a0823160e01b8152306004820152610309907f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec79033906001600160a01b038316906370a08231906024015b602060405180830381865afa1580156102e0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103049190611e81565b61135e565b6040516370a0823160e01b815230600482015261035d907f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb489033906001600160a01b038316906370a08231906024016102c3565b6040516370a0823160e01b81523060048201526103b1907f0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f9033906001600160a01b038316906370a08231906024016102c3565b50565b6103bc611331565b6040805180820190915260015462ffffff811682526301000000900464ffffffffff166020820181905215610404576040516374cc28f360e11b815260040160405180910390fd5b61040d81611479565b80516001805460209093015164ffffffffff1663010000000267ffffffffffffffff1990931662ffffff90921691909117919091179055565b6040805180820190915260015462ffffff811682526301000000900464ffffffffff16602082018190521561048e576040516374cc28f360e11b815260040160405180910390fd5b60006104993361070f565b9050806040015162ffffff166000036104c55760405163405204db60e01b815260040160405180910390fd5b6040808201805160009182905233825260026020819052929091208351815492938593839160ff1990911690600190849081111561050557610505611c11565b021790555060208281015182546040850151606086015166ffffffffffff001990921661010062ffffff9485160266ffffff0000000019161764010000000093909116929092029190911764ffffffffff60381b1916600160381b64ffffffffff909216919091021782556080830151805160018401805460ff191660ff909216919091178155918101519091906105a39060028501906005611a3d565b50505060a0820151805160038301805460ff191660ff90921691909117815560208201516105d79060048501906005611ad3565b5050855162ffffff908590031680875260018054602089015164ffffffffff1663010000000267ffffffffffffffff19909116909217919091179055505082516040517f1ae53e138c8a31c03f2f06a90e9d31c32f28814b701a19f3ace5ced1dc98eb43925061064991908490611e9a565b60405180910390a161070a60008351600281111561066957610669611c11565b146106d45760018351600281111561068357610683611c11565b146106ae577f0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f6106f6565b7f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486106f6565b7f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec75b3361030485600001518562ffffff166114bd565b505050565b610717611b54565b6001600160a01b0382166000908152600260208190526040808320815160c08101909252805491929091839160ff9091169081111561075857610758611c11565b600281111561076957610769611c11565b81528154610100810462ffffff9081166020808501919091526401000000008304909116604080850191909152600160381b90920464ffffffffff1660608401528151808301835260018501805460ff168252835160a081019485905260809095019491939092840191906002870190600590826000855b82829054906101000a900461ffff1661ffff16815260200190600201906020826001010492830192600103820291508084116107e157505050929093525050509082525060408051808201825260038401805460ff168252825160a0810193849052602094850194929391928401916004870190600590826000855b825461010083900a900460ff1681526020600192830181810494850194909303909202910180841161085d5790505050505050815250508152505090508060600151620151800164ffffffffff16421015806108c857506001546301000000900464ffffffffff1615155b156108e85760408101805160208301805190910162ffffff169052600090525b92915050565b8462ffffff166000036109145760405163405204db60e01b815260040160405180910390fd5b6040805180820190915260015462ffffff811682526301000000900464ffffffffff16602082018190521561095c576040516374cc28f360e11b815260040160405180910390fd5b80516207a1200362ffffff808216908816106109bc578062ffffff168762ffffff1611156109b35760405190965086907f33fb177adf56ce3cae4a36202899475a073f532b50c172bf1ac7ca65117b21a590600090a15b6109bc82611479565b8151870162ffffff16825260006109d23361070f565b9050806040015181602001510162ffffff16600003610a1957808960028111156109fe576109fe611c11565b90816002811115610a1157610a11611c11565b905250610a5c565b80516002811115610a2c57610a2c611c11565b896002811115610a3e57610a3e611c11565b14610a5c57604051636cab2bdf60e01b815260040160405180910390fd5b604081018051890162ffffff1690524264ffffffffff166060820152610a858787878785611518565b82516001805460208087015164ffffffffff1663010000000267ffffffffffffffff1990921662ffffff909416939093171781553360009081526002928390526040902083518154859492939192849260ff1990921691908490811115610aee57610aee611c11565b021790555060208281015182546040850151606086015166ffffffffffff001990921661010062ffffff9485160266ffffff0000000019161764010000000093909116929092029190911764ffffffffff60381b1916600160381b64ffffffffff909216919091021782556080830151805160018401805460ff191660ff90921691909117815591810151909190610b8c9060028501906005611a3d565b50505060a0820151805160038301805460ff191660ff9092169190911781556020820151610bc09060048501906005611ad3565b5050509050507f99c2878ae8656cdfb99c1564e8021b6e059a42cdf13e13191dfd290f81262b0d8989604051610bf7929190611e9a565b60405180910390a1610cb860008a6002811115610c1657610c16611c11565b14610c805760018a6002811115610c2f57610c2f611c11565b14610c5a577f0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f610ca2565b7f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48610ca2565b7f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec75b3330610cb38d8d62ffffff166114bd565b6118c5565b505050505050505050565b6001546301000000900464ffffffffff16801580610ced5750806301e133800164ffffffffff1642105b15610d0b57604051631ffa4c0760e01b815260040160405180910390fd5b6000610d163361070f565b608081015160a08201518151929350909160ff16158015610d395750805160ff16155b15610d575760405163421e345560e01b815260040160405180910390fd5b60005b825160ff16811015610e80577f0000000000000000000000005726c14663a1ead4a7d320e8a653c9710b2a2e896001600160a01b03166323b872dd303386602001518560058110610dad57610dad611eba565b60200201516040516001600160e01b031960e086901b1681526001600160a01b03938416600482015292909116602483015261ffff166044820152606401600060405180830381600087803b158015610e0557600080fd5b505af1158015610e19573d6000803e3d6000fd5b505050507fd991e33263669bca0940547a879f84f4285b8ed838fec597b0d76da7f92f0e0e83602001518260058110610e5457610e54611eba565b6020020151604051610e70919061ffff91909116815260200190565b60405180910390a1600101610d5a565b5060005b815160ff16811015610fa8577f0000000000000000000000007cd51fa7e155805c34f333ba493608742a67da8e6001600160a01b03166323b872dd303385602001518560058110610ed757610ed7611eba565b60200201516040516001600160e01b031960e086901b1681526001600160a01b03938416600482015292909116602483015260ff166044820152606401600060405180830381600087803b158015610f2e57600080fd5b505af1158015610f42573d6000803e3d6000fd5b505050507f8f9494a580b0a355573018bee09cb3a364a46057224864d1c3a9d89ef21a302f82602001518260058110610f7d57610f7d611eba565b6020020151604051610f98919060ff91909116815260200190565b60405180910390a1600101610e84565b50608083015160009081905260a0840151819052338152600260208190526040909120845181548693839160ff1916906001908490811115610fec57610fec611c11565b021790555060208281015182546040850151606086015166ffffffffffff001990921661010062ffffff9485160266ffffff0000000019161764010000000093909116929092029190911764ffffffffff60381b1916600160381b64ffffffffff909216919091021782556080830151805160018401805460ff191660ff9092169190911781559181015190919061108a9060028501906005611a3d565b50505060a0820151805160038301805460ff191660ff9092169190911781556020820151610cb89060048501906005611ad3565b6110c6611331565b6110d060006119ed565b565b6040805180820190915260015462ffffff811682526301000000900464ffffffffff16602082018190521561111a576040516374cc28f360e11b815260040160405180910390fd5b60006111253361070f565b90506111348686868685611518565b336000908152600260208190526040909120825181548493839160ff191690600190849081111561116757611167611c11565b021790555060208281015182546040850151606086015166ffffffffffff001990921661010062ffffff9485160266ffffff0000000019161764010000000093909116929092029190911764ffffffffff60381b1916600160381b64ffffffffff909216919091021782556080830151805160018401805460ff191660ff909216919091178155918101519091906112059060028501906005611a3d565b50505060a0820151805160038301805460ff191660ff90921691909117815560208201516112399060048501906005611ad3565b5050505050505050505050565b61124e611331565b6040805180820190915260015462ffffff811682526301000000900464ffffffffff16602082018190526000036112985760405163028504eb60e51b815260040160405180910390fd5b6040516370a0823160e01b81523060048201526112cc90839033906001600160a01b038316906370a08231906024016102c3565b5050565b6112d8611331565b6001600160a01b03811661130757604051631e4fbdf760e01b8152600060048201526024015b60405180910390fd5b6103b1816119ed565b611318611331565b6001805467ffffffffff00000019166301000000179055565b6000546001600160a01b031633146110d05760405163118cdaa760e01b81523360048201526024016112fe565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b17905291516000928392908716916113ba9190611ed0565b6000604051808303816000865af19150503d80600081146113f7576040519150601f19603f3d011682016040523d82523d6000602084013e6113fc565b606091505b50915091508180156114265750805115806114265750808060200190518101906114269190611eff565b6114725760405162461bcd60e51b815260206004820152601f60248201527f5472616e7366657248656c7065723a205452414e534645525f4641494c45440060448201526064016112fe565b5050505050565b4264ffffffffff1660208281018290526040519182527f5cd4a0a005e42e3f28a570526cac39d36845c0aa72891bb6c4527a83fcc6a46f910160405180910390a150565b6000808360028111156114d2576114d2611c11565b036114e35750620f424081026108e8565b60018360028111156114f7576114f7611c11565b036115085750620f424081026108e8565b50670de0b6b3a764000002919050565b60a08101515160808201515160059160ff90811691166115388588611f21565b6115429190611f21565b61154c9190611f21565b111561156b5760405163ad24298960e01b815260040160405180910390fd5b60005b8481101561163b5785858281811061158857611588611eba565b905060200201602081019061159d9190611f42565b60808301516020810151815160ff600182018116909352909116600581106115c7576115c7611eba565b61ffff90921660209290920201527f7fa5a6bf4f7b1fabc2db8fd2ea6ac29c651a714019defc813a983f60e0e5632686868381811061160857611608611eba565b905060200201602081019061161d9190611f42565b60405161ffff909116815260200160405180910390a160010161156e565b5060005b8281101561170a5783838281811061165957611659611eba565b905060200201602081019061166e9190611f66565b60a08301516020810151815160ff6001820181169093529091166005811061169857611698611eba565b60ff90921660209290920201527f96dfc51321bcc27a9f4aae3a4cfe16b8fe999379db0ce7a7a30e062e0fd417a18484838181106116d8576116d8611eba565b90506020020160208101906116ed9190611f66565b60405160ff909116815260200160405180910390a160010161163f565b5060005b848110156117e4577f0000000000000000000000005726c14663a1ead4a7d320e8a653c9710b2a2e896001600160a01b03166323b872dd333089898681811061175957611759611eba565b905060200201602081019061176e9190611f42565b6040516001600160e01b031960e086901b1681526001600160a01b03938416600482015292909116602483015261ffff166044820152606401600060405180830381600087803b1580156117c157600080fd5b505af11580156117d5573d6000803e3d6000fd5b5050505080600101905061170e565b5060005b828110156118bd577f0000000000000000000000007cd51fa7e155805c34f333ba493608742a67da8e6001600160a01b03166323b872dd333087878681811061183357611833611eba565b90506020020160208101906118489190611f66565b6040516001600160e01b031960e086901b1681526001600160a01b03938416600482015292909116602483015260ff166044820152606401600060405180830381600087803b15801561189a57600080fd5b505af11580156118ae573d6000803e3d6000fd5b505050508060010190506117e8565b505050505050565b604080516001600160a01b0385811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b17905291516000928392908816916119299190611ed0565b6000604051808303816000865af19150503d8060008114611966576040519150601f19603f3d011682016040523d82523d6000602084013e61196b565b606091505b50915091508180156119955750805115806119955750808060200190518101906119959190611eff565b6118bd5760405162461bcd60e51b8152602060048201526024808201527f5472616e7366657248656c7065723a205452414e534645525f46524f4d5f46416044820152631253115160e21b60648201526084016112fe565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600183019183908215611ac35791602002820160005b83821115611a9357835183826101000a81548161ffff021916908361ffff1602179055509260200192600201602081600101049283019260010302611a53565b8015611ac15782816101000a81549061ffff0219169055600201602081600101049283019260010302611a93565b505b50611acf929150611b96565b5090565b600183019183908215611ac35791602002820160005b83821115611b2757835183826101000a81548160ff021916908360ff1602179055509260200192600101602081600001049283019260010302611ae9565b8015611ac15782816101000a81549060ff0219169055600101602081600001049283019260010302611b27565b6040805160c081019091528060008152600060208201819052604082018190526060820152608001611b84611bab565b8152602001611b91611bab565b905290565b5b80821115611acf5760008155600101611b97565b6040518060400160405280600060ff168152602001611b916040518060a001604052806005906020820280368337509192915050565b600060208284031215611bf357600080fd5b81356001600160a01b0381168114611c0a57600080fd5b9392505050565b634e487b7160e01b600052602160045260246000fd5b60038110611c4557634e487b7160e01b600052602160045260246000fd5b9052565b60ff815116825260208101516020830160005b600581101561147257825160ff16825260209283019290910190600101611c5c565b600061020082019050611c92828451611c27565b62ffffff602084015116602083015262ffffff604084015116604083015264ffffffffff6060840151166060830152608083015160ff81511660808401526020810151905060a0830160005b6005811015611d0157825161ffff16825260209283019290910190600101611cde565b50505060a0830151611d17610140840182611c49565b5092915050565b60008083601f840112611d3057600080fd5b50813567ffffffffffffffff811115611d4857600080fd5b6020830191508360208260051b8501011115611d6357600080fd5b9250929050565b60008060008060008060808789031215611d8357600080fd5b863560038110611d9257600080fd5b9550602087013562ffffff81168114611daa57600080fd5b9450604087013567ffffffffffffffff811115611dc657600080fd5b611dd289828a01611d1e565b909550935050606087013567ffffffffffffffff811115611df257600080fd5b611dfe89828a01611d1e565b979a9699509497509295939492505050565b60008060008060408587031215611e2657600080fd5b843567ffffffffffffffff811115611e3d57600080fd5b611e4987828801611d1e565b909550935050602085013567ffffffffffffffff811115611e6957600080fd5b611e7587828801611d1e565b95989497509550505050565b600060208284031215611e9357600080fd5b5051919050565b60408101611ea88285611c27565b62ffffff831660208301529392505050565b634e487b7160e01b600052603260045260246000fd5b6000825160005b81811015611ef15760208186018101518583015201611ed7565b506000920191825250919050565b600060208284031215611f1157600080fd5b81518015158114611c0a57600080fd5b808201808211156108e857634e487b7160e01b600052601160045260246000fd5b600060208284031215611f5457600080fd5b813561ffff81168114611c0a57600080fd5b600060208284031215611f7857600080fd5b813560ff81168114611c0a57600080fdfea2646970667358221220d9978d46c23671cd98a8b93debd9acfe69dd55377de5bfff80d4c9a1d0d5059f64736f6c634300081c0033

Verified Source Code Partial Match

Compiler: v0.8.28+commit.7893614a EVM: paris Optimization: Yes (200 runs)
Sale.sol 16 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import {BaseSale} from "./BaseSale.sol";

contract Sale is BaseSale {
    constructor()
        BaseSale(
            0xdAC17F958D2ee523a2206206994597C13D831ec7, // USDT
            0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48, // USDC
            0x6B175474E89094C44Da98b954EedeAC495271d0F, // DAI
            0x5726C14663A1EaD4A7D320E8A653c9710b2A2E89, // Butterin Cards
            0x7cd51FA7E155805C34F333ba493608742A67Da8e // Mined JPEG
        )
    {}
}
BaseSale.sol 419 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import {TransferHelper} from "solidity-lib/TransferHelper.sol";
import {IERC20} from "openzeppelin/token/ERC20/IERC20.sol";
import {IERC721} from "openzeppelin/token/ERC721/IERC721.sol";
import {Ownable} from "openzeppelin/access/Ownable.sol";
import {SaleStructs} from "./SaleStructs.sol";

/** @notice Sale contract for SIR
    @notice Accepts USDT, USDC & DAI
    @notice Users can lock up to 5 Buterin Cards or Mined JPEGs to boost their token allocations
    @notice Users can withdraw their deposits before 24 hours have passed
    @notice Users can withdraw their NFTs 1 year after the sale ended
 */
abstract contract BaseSale is SaleStructs, Ownable {
    address internal immutable _USDT;
    address internal immutable _USDC;
    address internal immutable _DAI;

    IERC721 internal immutable _BUTERIN_CARDS;
    IERC721 internal immutable _MINED_JPEG;

    uint8 private constant _USDT_DECIMALS = 6;
    uint8 private constant _USDC_DECIMALS = 6;
    uint8 private constant _DAI_DECIMALS = 18;

    SaleState private _state;

    mapping(address contributor => Contribution) private _contributions;

    ////////////////////////////////////////////////////////////////////////////////
    //////////////// S T A T E - C H A N G I N G  F U N C T I O N S ///////////////
    //////////////////////////////////////////////////////////////////////////////

    constructor(
        address USDT_,
        address USDC_,
        address DAI_,
        address buterinCards,
        address minedJPEG
    ) Ownable(msg.sender) {
        _USDT = USDT_;
        _USDC = USDC_;
        _DAI = DAI_;
        _BUTERIN_CARDS = IERC721(buterinCards);
        _MINED_JPEG = IERC721(minedJPEG);
    }

    /** @notice Deposits USDT, USDC or DAI and, optionally, locks up to 5 Buterin Cards or Mined JPEGs
        @notice Users can deposit multiple times
        @notice Once one stablecoin is deposited, the user cannot deposit another stablecoin
        @param stablecoin The stablecoin to deposit
        @param amountNoDecimals The amount to deposit in the stablecoin without decimals
        @param buterinCardIds The IDs of the Buterin Cards to lock
        @param minedJpegIds The IDs of the Mined JPEGs to lock
     */
    function depositAndLockNfts(
        Stablecoin stablecoin,
        uint24 amountNoDecimals,
        uint16[] calldata buterinCardIds,
        uint8[] calldata minedJpegIds
    ) external {
        // maxAmountNoDecimals ensures that the total contributions do not exceed MAX_CONTRIBUTIONS_NO_DECIMALS
        unchecked {
            if (amountNoDecimals == 0) revert NullDeposit();

            // Revert if sale is over
            SaleState memory state_ = _state;
            if (state_.timeSaleEnded > 0) revert SaleIsOver();

            // Limit the contribution if it exceeds the maximum
            uint24 maxAmountNoDecimals = MAX_CONTRIBUTIONS_NO_DECIMALS -
                state_.totalContributionsNoDecimals;
            if (amountNoDecimals >= maxAmountNoDecimals) {
                if (amountNoDecimals > maxAmountNoDecimals) {
                    // Truncate the contribution
                    amountNoDecimals = maxAmountNoDecimals;

                    // Emit event
                    emit DepositWasReduced();
                }

                // End sale
                _endSale(state_);
            }

            // Update _state
            state_.totalContributionsNoDecimals += amountNoDecimals;

            // Update contribution
            Contribution memory contribution = contributions(msg.sender);
            if (
                contribution.amountFinalNoDecimals +
                    contribution.amountWithdrawableNoDecimals ==
                0
            ) {
                // 1st contribution
                contribution.stablecoin = stablecoin;
            } else if (stablecoin != contribution.stablecoin) {
                revert WrongStablecoin();
            }
            contribution.amountWithdrawableNoDecimals += amountNoDecimals;
            contribution.timeLastContribution = uint40(block.timestamp);

            // Lock NFTs
            _lockNfts(buterinCardIds, minedJpegIds, contribution);

            // Save contribution and _state
            _state = state_;
            _contributions[msg.sender] = contribution;

            // Emit event
            emit Deposit(stablecoin, amountNoDecimals);

            // Transfer tokens to the contract
            TransferHelper.safeTransferFrom(
                stablecoin == Stablecoin.USDT
                    ? _USDT
                    : stablecoin == Stablecoin.USDC
                    ? _USDC
                    : _DAI,
                msg.sender,
                address(this),
                _addDecimals(stablecoin, amountNoDecimals)
            );
        }
    }

    /** @notice Contributors can withdraw their deposits before 24 hours have passed
     */
    function withdraw() external {
        // Revert if sale is over
        SaleState memory state_ = _state;
        if (state_.timeSaleEnded > 0) revert SaleIsOver();

        // Revert if the user has made no contribution in the last 24 hours
        Contribution memory contribution = contributions(msg.sender);
        if (contribution.amountWithdrawableNoDecimals == 0)
            revert NullDeposit();

        // Update contribution
        uint24 amountWithdrawableNoDecimals = contribution
            .amountWithdrawableNoDecimals;
        contribution.amountWithdrawableNoDecimals = 0;
        _contributions[msg.sender] = contribution;

        // Update _state
        unchecked {
            // amountWithdrawableNoDecimals is always less than or equal to totalContributionsNoDecimals
            state_.totalContributionsNoDecimals -= amountWithdrawableNoDecimals;
        }
        _state = state_;

        // Emit event
        emit Withdrawal(contribution.stablecoin, amountWithdrawableNoDecimals);

        // Transfer tokens to the user
        TransferHelper.safeTransfer(
            contribution.stablecoin == Stablecoin.USDT
                ? _USDT
                : contribution.stablecoin == Stablecoin.USDC
                ? _USDC
                : _DAI,
            msg.sender,
            _addDecimals(contribution.stablecoin, amountWithdrawableNoDecimals)
        );
    }

    /** @notice Locks up to 5 Buterin Cards or Mined JPEGs
        @param buterinCardIds The IDs of the Buterin Cards to lock
        @param minedJpegIds The IDs of the Mined JPEGs to lock
     */
    function lockNfts(
        uint16[] calldata buterinCardIds,
        uint8[] calldata minedJpegIds
    ) external {
        // Revert if sale is over
        SaleState memory state_ = _state;
        if (state_.timeSaleEnded > 0) revert SaleIsOver();

        // Lock NFTs
        Contribution memory contribution = contributions(msg.sender);
        _lockNfts(buterinCardIds, minedJpegIds, contribution);

        // Save contribution
        _contributions[msg.sender] = contribution;
    }

    /** @notice Withdraws the Buterin Cards and Mined JPEGs locked by the user
        @notice Users can withdraw their NFTs 1 year after the sale ended
     */
    function withdrawNfts() external {
        // i++ will never overflow
        unchecked {
            // Revert if it is less than 1 year since the sale ended
            uint40 timeSaleEnded = _state.timeSaleEnded;
            if (
                timeSaleEnded == 0 || block.timestamp < timeSaleEnded + 365 days
            ) revert NftsLocked();

            // Withdraw NFTs
            Contribution memory contribution = contributions(msg.sender);
            LockedButerinCards memory lockedButerinCards = contribution
                .lockedButerinCards;
            LockedMinedJpegs memory lockedMinedJpegs = contribution
                .lockedMinedJpegs;

            if (lockedButerinCards.number == 0 && lockedMinedJpegs.number == 0)
                revert NoNfts();

            // Transfer Buterin Cards
            for (uint256 i = 0; i < lockedButerinCards.number; ++i) {
                _BUTERIN_CARDS.transferFrom(
                    address(this),
                    msg.sender,
                    lockedButerinCards.ids[i]
                );
                emit ButerinCardUnlocked(lockedButerinCards.ids[i]);
            }

            // Transfer Mined JPEGs
            for (uint256 i = 0; i < lockedMinedJpegs.number; ++i) {
                _MINED_JPEG.transferFrom(
                    address(this),
                    msg.sender,
                    lockedMinedJpegs.ids[i]
                );
                emit MinedJpegUnlocked(lockedMinedJpegs.ids[i]);
            }

            // Update contribution
            contribution.lockedButerinCards.number = 0;
            contribution.lockedMinedJpegs.number = 0;

            // Save contribution
            _contributions[msg.sender] = contribution;
        }
    }

    ////////////////////////////////////////////////////////////////////////////////
    ///////////////////////// O W N E R  F U N C T I O N S ////////////////////////
    //////////////////////////////////////////////////////////////////////////////

    /** @notice Ends the sale prematurely
     */
    function endSale() external onlyOwner {
        // Get _state
        SaleState memory state_ = _state;

        // Revert if sale is already over
        if (state_.timeSaleEnded > 0) revert SaleIsOver();

        // End sale
        _endSale(state_);

        // Update _state
        _state = state_;
    }

    /** @notice Withdraws all USDT, USDC & DAI from the contract if the sale is over
     */
    function withdrawFunds() external onlyOwner {
        // Revert if sale is live
        SaleState memory state_ = _state;
        if (state_.timeSaleEnded == 0) revert SaleIsLive();

        // Withdraw USDT
        TransferHelper.safeTransfer(
            _USDT,
            msg.sender,
            IERC20(_USDT).balanceOf(address(this))
        );

        // Withdraw USDC
        TransferHelper.safeTransfer(
            _USDC,
            msg.sender,
            IERC20(_USDC).balanceOf(address(this))
        );

        // Withdraw DAI
        TransferHelper.safeTransfer(
            _DAI,
            msg.sender,
            IERC20(_DAI).balanceOf(address(this))
        );
    }

    /** @notice Withdraws any ERC20 token in case any worthy token (that is not USDT, USDC or DAI) was sent to the contract
     */
    function withdrawExoticERC20(address token) external onlyOwner {
        // Revert if sale is live
        SaleState memory state_ = _state;
        if (state_.timeSaleEnded == 0) revert SaleIsLive();

        TransferHelper.safeTransfer(
            token,
            msg.sender,
            IERC20(token).balanceOf(address(this))
        );
    }

    /** @notice Just in case something goes wrong, owner can unlock all NFTs
     */
    function unlockAllNfts() external onlyOwner {
        // It simulates that the sale ended on Jan 1, 1970, which effectively allows every contributor to withdraw their NFTs
        // It also haults deposits.
        _state.timeSaleEnded = 1;
    }

    ////////////////////////////////////////////////////////////////////////////////
    //////////////////// R E A D -  O N L Y  F U N C T I O N S ////////////////////
    //////////////////////////////////////////////////////////////////////////////

    function state() public view returns (SaleState memory) {
        return _state;
    }

    /** @notice Returns the contribution of a user including stablecoin of choice, (un)withdrawable amounts, and locked NFTs
        @param contributor The address of the contributor
     */
    function contributions(
        address contributor
    ) public view returns (Contribution memory) {
        unchecked {
            Contribution memory contribution = _contributions[contributor];
            if (
                block.timestamp >=
                contribution.timeLastContribution + 24 hours ||
                _state.timeSaleEnded > 0
            ) {
                // If 24 hours have passed since the last deposit, the user cannot withdraw the previous deposit
                contribution.amountFinalNoDecimals += contribution
                    .amountWithdrawableNoDecimals;
                contribution.amountWithdrawableNoDecimals = 0;
            }
            return contribution;
        }
    }

    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////// P R I V A T E  F U N C T I O N S ///////////////////////
    //////////////////////////////////////////////////////////////////////////////

    function _endSale(SaleState memory state_) private {
        // Update last deposit time
        state_.timeSaleEnded = uint40(block.timestamp);

        // Emit event
        emit SaleEnded(uint40(block.timestamp));
    }

    function _lockNfts(
        uint16[] calldata buterinCardIds,
        uint8[] calldata minedJpegIds,
        Contribution memory contribution
    ) private {
        // Revert if the total of locked NFTs exceeds 5
        if (
            buterinCardIds.length +
                minedJpegIds.length +
                contribution.lockedButerinCards.number +
                contribution.lockedMinedJpegs.number >
            5
        ) revert TooManyNfts();

        // ++i will never overflow
        unchecked {
            // Update contribution
            for (uint256 i = 0; i < buterinCardIds.length; ++i) {
                contribution.lockedButerinCards.ids[
                    contribution.lockedButerinCards.number++
                ] = buterinCardIds[i];
                emit ButerinCardLocked(buterinCardIds[i]);
            }

            for (uint256 i = 0; i < minedJpegIds.length; ++i) {
                contribution.lockedMinedJpegs.ids[
                    contribution.lockedMinedJpegs.number++
                ] = minedJpegIds[i];
                emit MinedJpegLocked(minedJpegIds[i]);
            }

            // Transfer Buterin Cards
            for (uint256 i = 0; i < buterinCardIds.length; ++i) {
                _BUTERIN_CARDS.transferFrom(
                    msg.sender,
                    address(this),
                    buterinCardIds[i]
                );
            }

            // Transfer Mined JPEGs
            for (uint256 i = 0; i < minedJpegIds.length; ++i) {
                _MINED_JPEG.transferFrom(
                    msg.sender,
                    address(this),
                    minedJpegIds[i]
                );
            }
        }
    }

    function _addDecimals(
        Stablecoin stablecoin,
        uint256 amountNoDecimals
    ) private pure returns (uint256) {
        unchecked {
            if (stablecoin == Stablecoin.USDT) {
                return amountNoDecimals * 10 ** _USDT_DECIMALS;
            }
            if (stablecoin == Stablecoin.USDC) {
                return amountNoDecimals * 10 ** _USDC_DECIMALS;
            }
            return amountNoDecimals * 10 ** _DAI_DECIMALS;
        }
    }
}
TransferHelper.sol 42 lines
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity >=0.6.0;

// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library TransferHelper {
    function safeApprove(
        address token,
        address to,
        uint256 value
    ) internal {
        // bytes4(keccak256(bytes('approve(address,uint256)')));
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: APPROVE_FAILED');
    }

    function safeTransfer(
        address token,
        address to,
        uint256 value
    ) internal {
        // bytes4(keccak256(bytes('transfer(address,uint256)')));
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FAILED');
    }

    function safeTransferFrom(
        address token,
        address from,
        address to,
        uint256 value
    ) internal {
        // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED');
    }

    function safeTransferETH(address to, uint256 value) internal {
        (bool success, ) = to.call{value: value}(new bytes(0));
        require(success, 'TransferHelper: ETH_TRANSFER_FAILED');
    }
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}
IERC721.sol 135 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.20;

import {IERC165} from "../../utils/introspection/IERC165.sol";

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
     *   a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or
     *   {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
     *   a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
     * understand this adds an external call which potentially creates a reentrancy vulnerability.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the address zero.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);
}
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
SaleStructs.sol 54 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

contract SaleStructs {
    uint24 public constant MAX_CONTRIBUTIONS_NO_DECIMALS = 500_000; // [$]

    event SaleEnded(uint40 timeSaleEnded);
    event DepositWasReduced();

    event Deposit(Stablecoin stablecoin, uint24 amountNoDecimals);
    event Withdrawal(Stablecoin stablecoin, uint24 amountNoDecimals);
    event ButerinCardLocked(uint16 tokenId);
    event MinedJpegLocked(uint8 tokenId);
    event ButerinCardUnlocked(uint16 tokenId);
    event MinedJpegUnlocked(uint8 tokenId);

    error WrongStablecoin();
    error NullDeposit();
    error SaleIsOver();
    error TooManyNfts();
    error NftsLocked();
    error SaleIsLive();
    error NoNfts();

    enum Stablecoin {
        USDT,
        USDC,
        DAI
    }

    struct LockedButerinCards {
        uint8 number;
        uint16[5] ids;
    }

    struct LockedMinedJpegs {
        uint8 number;
        uint8[5] ids;
    }

    struct Contribution {
        Stablecoin stablecoin;
        uint24 amountFinalNoDecimals;
        uint24 amountWithdrawableNoDecimals;
        uint40 timeLastContribution;
        LockedButerinCards lockedButerinCards;
        LockedMinedJpegs lockedMinedJpegs;
    }

    struct SaleState {
        uint24 totalContributionsNoDecimals;
        uint40 timeSaleEnded;
    }
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

Read Contract

MAX_CONTRIBUTIONS_NO_DECIMALS 0x540dd4bf → uint24
contributions 0x42e94c90 → tuple
owner 0x8da5cb5b → address
state 0xc19d93fb → tuple

Write Contract 10 functions

These functions modify contract state and require a wallet transaction to execute.

depositAndLockNfts 0x4eef850d
uint8 stablecoin
uint24 amountNoDecimals
uint16[] buterinCardIds
uint8[] minedJpegIds
endSale 0x380d831b
No parameters
lockNfts 0x88ef1d05
uint16[] buterinCardIds
uint8[] minedJpegIds
renounceOwnership 0x715018a6
No parameters
transferOwnership 0xf2fde38b
address newOwner
unlockAllNfts 0xfb12e1a4
No parameters
withdraw 0x3ccfd60b
No parameters
withdrawExoticERC20 0x963dfa86
address token
withdrawFunds 0x24600fc3
No parameters
withdrawNfts 0x5a3c5a1a
No parameters

Recent Transactions

This address has 1 on-chain transactions, but only 0.7% of the chain is indexed. Transactions will appear as indexing progresses. View on Etherscan →