Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x37ff55dAC7cAC15012b38f9FC173f7f0243159c8
Balance 0 ETH
Nonce 1
Code Size 8239 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

8239 bytes
0x60806040526004361061013c575f3560e01c80638da5cb5b116100b3578063e243ceb81161006d578063e243ceb8146104a1578063eb91e651146104c0578063ecf877f1146104df578063f2fde38b146104fe578063f9f92be41461051d578063ff41e60d1461055b575f80fd5b80638da5cb5b146103845780639fac38d3146103aa578063a3e2931c146103c9578063a5ba3b1e146103e8578063ae9567151461041e578063ca6668231461048c575f80fd5b806353a58de11161010457806353a58de1146102ca5780635951f24814610300578063715018a61461031f578063859a9dae1461033357806386c984c41461035257806387019f2814610365575f80fd5b8063172bd6de14610140578063195256bb146101615780631da4c66b146101805780632e37eef6146101c957806337a7149c146102ab575b5f80fd5b34801561014b575f80fd5b5061015f61015a366004611aa1565b610594565b005b34801561016c575f80fd5b5061015f61017b366004611b04565b61080b565b34801561018b575f80fd5b506101b661019a366004611b53565b600560209081525f928352604080842090915290825290205481565b6040519081526020015b60405180910390f35b3480156101d4575f80fd5b5061024b6101e3366004611b7d565b600260208190525f91825260409091208054600182015492820154600383015460048401546005850154600686015460078701546008909701549597969495939492939192909160ff808216916101008104909116906201000090046001600160a01b03168b565b604080519b8c5260208c019a909a52988a01979097526060890195909552608088019390935260a087019190915260c086015260e0850152151561010084015215156101208301526001600160a01b0316610140820152610160016101c0565b3480156102b6575f80fd5b5061015f6102c5366004611b94565b6109bd565b3480156102d5575f80fd5b506101b66102e4366004611b53565b600460209081525f928352604080842090915290825290205481565b34801561030b575f80fd5b5061015f61031a366004611cb2565b6109e4565b34801561032a575f80fd5b5061015f610c2c565b34801561033e575f80fd5b5061015f61034d366004611d5a565b610c3f565b61015f610360366004611d9f565b610d18565b348015610370575f80fd5b5061015f61037f366004611d5a565b610f85565b34801561038f575f80fd5b505f546040516001600160a01b0390911681526020016101c0565b3480156103b5575f80fd5b5061015f6103c4366004611aa1565b610f8d565b3480156103d4575f80fd5b5061015f6103e3366004611b04565b611378565b3480156103f3575f80fd5b506101b6610402366004611b53565b600660209081525f928352604080842090915290825290205481565b348015610429575f80fd5b50610465610438366004611b7d565b60036020525f90815260409020805460018201546002909201546001600160a01b03909116919060ff1683565b604080516001600160a01b03909416845260208401929092521515908201526060016101c0565b348015610497575f80fd5b506101b660085481565b3480156104ac575f80fd5b5061015f6104bb366004611de7565b6114f0565b3480156104cb575f80fd5b5061015f6104da366004611ed3565b611694565b3480156104ea575f80fd5b5061015f6104f9366004611eec565b6116bc565b348015610509575f80fd5b5061015f610518366004611ed3565b6116f8565b348015610528575f80fd5b5061054b610537366004611ed3565b60016020525f908152604090205460ff1681565b60405190151581526020016101c0565b348015610566575f80fd5b5061054b610575366004611b53565b600760209081525f928352604080842090915290825290205460ff1681565b5f838152600260205260409020600881015460ff166105f15760405162461bcd60e51b815260206004820152601460248201527310db185a5b5a5b99c81b9bdd08195b98589b195960621b60448201526064015b60405180910390fd5b335f9081526001602052604090205460ff16156106435760405162461bcd60e51b815260206004820152601060248201526f155cd95c88189b1858dadb1a5cdd195960821b60448201526064016105e8565b5f8481526007602090815260408083206001600160a01b038a16845290915290205460ff166106ac5760405162461bcd60e51b8152602060048201526015602482015274151bdad95b881b9bdd081dda1a5d195b1a5cdd1959605a1b60448201526064016105e8565b5f848152600560209081526040808320338452909152902054156107045760405162461bcd60e51b815260206004820152600f60248201526e105b1c9958591e4818db185a5b5959608a1b60448201526064016105e8565b61076c8383808060200260200160405190810160405280939291908181526020018383602002808284375f9201919091525050505060038301546040516107519033908a90602001611f2b565b60405160208183030381529060405280519060200120611735565b6107a85760405162461bcd60e51b815260206004820152600d60248201526c24b73b30b634b210383937b7b360991b60448201526064016105e8565b6107bc6001600160a01b038716338761174c565b5f848152600560209081526040808320338452909152812080548792906107e4908490611f5c565b9250508190555084816007015f8282546107fe9190611f5c565b9091555050505050505050565b5f8381526002602052604090206008015460ff1661083c576040516371642c7760e11b815260040160405180910390fd5b5f8381526005602090815260408083203384529091529020541561087357604051630c8d9eab60e31b815260040160405180910390fd5b335f9081526001602052604090205460ff16156108a35760405163473250af60e01b815260040160405180910390fd5b5f33856040516020016108b7929190611f2b565b60405160208183030381529060405280519060200120905061091c8383808060200260200160405190810160405280939291908181526020018383602002808284375f9201829052508981526002602052604090206003015492508591506117359050565b610939576040516309bde33960e01b815260040160405180910390fd5b604051339086156108fc029087905f818181858888f19350505050158015610963573d5f803e3d5ffd5b505f8481526005602090815260408083203384529091528120805487929061098c908490611f5c565b90915550505f84815260026020526040812060070180548792906109b1908490611f5c565b90915550505050505050565b6109c56117b0565b5f92835260026020819052604090932092830191909155600390910155565b6109ec6117b0565b600880545f91826109fc83611f6f565b9190505590506040518061016001604052808c81526020018b81526020018a81526020018981526020018881526020018781526020015f81526020015f815260200185151581526020018615158152602001846001600160a01b031681525060025f8381526020019081526020015f205f820151815f01556020820151816001015560408201518160020155606082015181600301556080820151816004015560a0820151816005015560c0820151816006015560e08201518160070155610100820151816008015f6101000a81548160ff0219169083151502179055506101208201518160080160016101000a81548160ff0219169083151502179055506101408201518160080160026101000a8154816001600160a01b0302191690836001600160a01b031602179055509050505f5b8251811015610b9f575f828152600760205260408120845160019290869085908110610b5c57610b5c611f87565b6020908102919091018101516001600160a01b031682528101919091526040015f20805460ff191691151591909117905580610b9781611f6f565b915050610b2e565b5060408051828152602081018d90529081018b9052606081018a90526080810189905260a0810188905260c0810187905285151560e08201528415156101008201526001600160a01b0384166101208201527fe497e8922e9a320543fa23957afd45b34dcd84fd8b678a9946600962071ff6fe906101400160405180910390a15050505050505050505050565b610c346117b0565b610c3d5f6117dc565b565b610c476117b0565b5f8481526003602052604090206002015460ff1615610c7957604051631407152b60e21b815260040160405180910390fd5b5f848152600360205260409020546001600160a01b03848116911614610cb257604051635061304160e01b815260040160405180910390fd5b604080516060810182526001600160a01b03948516815260208082019485529215158183019081525f96875260039093529420935184546001600160a01b0319169316929092178355516001830155516002909101805460ff1916911515919091179055565b335f9081526001602052604090205460ff1615610d485760405163473250af60e01b815260040160405180910390fd5b6040516001600160601b03193360601b1660208201525f90603401604051602081830303815290604052805190602001209050610dc98383808060200260200160405190810160405280939291908181526020018383602002808284375f920182905250898152600260208190526040909120015492508591506117359050565b610de6576040516309bde33960e01b815260040160405180910390fd5b5f84815260026020526040902060040154341015610e1757604051632fcd1a0f60e01b815260040160405180910390fd5b5f84815260026020526040902060050154341115610e485760405163ea5d71ed60e01b815260040160405180910390fd5b5f848152600260209081526040808320600501546004835281842033855290925290912054610e78903490611f5c565b1115610e975760405163d630062d60e01b815260040160405180910390fd5b5f84815260026020526040902054421080610ec157505f8481526002602052604090206001015442115b15610edf576040516321094a9b60e01b815260040160405180910390fd5b5f84815260046020908152604080832033845290915281208054349290610f07908490611f5c565b90915550505f8481526002602052604081206006018054349290610f2c908490611f5c565b90915550505f848152600260205260408082206008015490516001600160a01b036201000090920491909116913480156108fc02929091818181858888f19350505050158015610f7e573d5f803e3d5ffd5b5050505050565b610cb26117b0565b5f838152600260209081526040808320600783528184206001600160a01b038a1685529092529091205460ff16610ffe5760405162461bcd60e51b8152602060048201526015602482015274151bdad95b881b9bdd081dda1a5d195b1a5cdd1959605a1b60448201526064016105e8565b335f9081526001602052604090205460ff16156110505760405162461bcd60e51b815260206004820152601060248201526f155cd95c88189b1858dadb1a5cdd195960821b60448201526064016105e8565b6008810154610100900460ff166110a05760405162461bcd60e51b815260206004820152601460248201527311195c1bdcda5d1cc81b9bdd08195b98589b195960621b60448201526064016105e8565b604051636eb1769f60e11b815233600482015230602482015285906001600160a01b0388169063dd62ed3e90604401602060405180830381865afa1580156110ea573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061110e9190611f9b565b10156111505760405162461bcd60e51b8152602060048201526011602482015270416c6c6f77616e636520746f6f206c6f7760781b60448201526064016105e8565b6111a88383808060200260200160405190810160405280939291908181526020018383602002808284375f9201919091525050505060028301546040516001600160601b03193360601b166020820152603401610751565b6111e45760405162461bcd60e51b815260206004820152600d60248201526c24b73b30b634b210383937b7b360991b60448201526064016105e8565b806004015485101580156111fc575080600501548511155b6112395760405162461bcd60e51b815260206004820152600e60248201526d125b9d985b1a5908185b5bdd5b9d60921b60448201526064016105e8565b60058101545f858152600460209081526040808320338452909152902054611262908790611f5c565b11156112b05760405162461bcd60e51b815260206004820152601760248201527f4465706f7369742065786365656473206d6178696d756d00000000000000000060448201526064016105e8565b805442108015906112c5575080600101544211155b6113045760405162461bcd60e51b815260206004820152601060248201526f5068617365206e6f742061637469766560801b60448201526064016105e8565b5f8481526004602090815260408083203384529091528120805487929061132c908490611f5c565b9250508190555084816006015f8282546113469190611f5c565b90915550506008810154611370906001600160a01b0388811691339162010000909104168861182b565b505050505050565b5f8481526003602052604090206002015460ff166113a957604051631407152b60e21b815260040160405180910390fd5b5f848152600660209081526040808320338452909152902054156113e057604051630c8d9eab60e31b815260040160405180910390fd5b335f9081526001602052604090205460ff16156114105760405163473250af60e01b815260040160405180910390fd5b5f3384604051602001611424929190611f2b565b6040516020818303038152906040528051906020012090506114898383808060200260200160405190810160405280939291908181526020018383602002808284375f9201829052508a81526003602052604090206001015492508591506117359050565b6114a6576040516309bde33960e01b815260040160405180910390fd5b5f858152600360205260409020546114c8906001600160a01b0316338661174c565b5f858152600660209081526040808320338452909152812080548692906109b1908490611f5c565b6114f86117b0565b5f8381526002602081815260408084208651815591860151600183015585015191810191909155606084015160038201556080840151600482015560a0840151600582015560c0840151600682015560e08401516007820155610100808501516008909201805461012087015161014088015161ffff1990921694151561ff001916949094179315159092029290921762010000600160b01b031916620100006001600160a01b03909216919091021790555b815181101561161a575f848152600760205260408120835182908590859081106115d7576115d7611f87565b6020908102919091018101516001600160a01b031682528101919091526040015f20805460ff19169115159190911790558061161281611f6f565b9150506115ab565b505f5b815181101561168e575f84815260076020526040812083516001929085908590811061164b5761164b611f87565b6020908102919091018101516001600160a01b031682528101919091526040015f20805460ff19169115159190911790558061168681611f6f565b91505061161d565b50505050565b61169c6117b0565b6001600160a01b03165f908152600160205260409020805460ff19169055565b6116c46117b0565b5f92835260026020526040909220600801805492151560ff19921515610100029290921661ffff1990931692909217179055565b6117006117b0565b6001600160a01b03811661172957604051631e4fbdf760e01b81525f60048201526024016105e8565b611732816117dc565b50565b5f826117418584611864565b1490505b9392505050565b6040516001600160a01b038381166024830152604482018390526117ab91859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b0383818316178352505050506118b2565b505050565b5f546001600160a01b03163314610c3d5760405163118cdaa760e01b81523360048201526024016105e8565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6040516001600160a01b03848116602483015283811660448301526064820183905261168e9186918216906323b872dd90608401611779565b5f81815b84518110156118a8576118948286838151811061188757611887611f87565b6020026020010151611913565b9150806118a081611f6f565b915050611868565b5090505b92915050565b5f6118c66001600160a01b0384168361193c565b905080515f141580156118ea5750808060200190518101906118e89190611fb2565b155b156117ab57604051635274afe760e01b81526001600160a01b03841660048201526024016105e8565b5f81831061192d575f828152602084905260409020611745565b505f9182526020526040902090565b606061174583835f845f80856001600160a01b031684866040516119609190611fcd565b5f6040518083038185875af1925050503d805f811461199a576040519150601f19603f3d011682016040523d82523d5f602084013e61199f565b606091505b50915091506119af8683836119b9565b9695505050505050565b6060826119ce576119c982611a15565b611745565b81511580156119e557506001600160a01b0384163b155b15611a0e57604051639996b31560e01b81526001600160a01b03851660048201526024016105e8565b5080611745565b805115611a255780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b80356001600160a01b0381168114611a54575f80fd5b919050565b5f8083601f840112611a69575f80fd5b50813567ffffffffffffffff811115611a80575f80fd5b6020830191508360208260051b8501011115611a9a575f80fd5b9250929050565b5f805f805f60808688031215611ab5575f80fd5b611abe86611a3e565b94506020860135935060408601359250606086013567ffffffffffffffff811115611ae7575f80fd5b611af388828901611a59565b969995985093965092949392505050565b5f805f8060608587031215611b17575f80fd5b8435935060208501359250604085013567ffffffffffffffff811115611b3b575f80fd5b611b4787828801611a59565b95989497509550505050565b5f8060408385031215611b64575f80fd5b82359150611b7460208401611a3e565b90509250929050565b5f60208284031215611b8d575f80fd5b5035919050565b5f805f60608486031215611ba6575f80fd5b505081359360208301359350604090920135919050565b8015158114611732575f80fd5b8035611a5481611bbd565b634e487b7160e01b5f52604160045260245ffd5b604051610160810167ffffffffffffffff81118282101715611c0d57611c0d611bd5565b60405290565b5f82601f830112611c22575f80fd5b8135602067ffffffffffffffff80831115611c3f57611c3f611bd5565b8260051b604051601f19603f83011681018181108482111715611c6457611c64611bd5565b604052938452858101830193838101925087851115611c81575f80fd5b83870191505b84821015611ca757611c9882611a3e565b83529183019190830190611c87565b979650505050505050565b5f805f805f805f805f806101408b8d031215611ccc575f80fd5b8a35995060208b0135985060408b0135975060608b0135965060808b0135955060a08b0135945060c08b0135611d0181611bbd565b935060e08b0135611d1181611bbd565b9250611d206101008c01611a3e565b91506101208b013567ffffffffffffffff811115611d3c575f80fd5b611d488d828e01611c13565b9150509295989b9194979a5092959850565b5f805f8060808587031215611d6d575f80fd5b84359350611d7d60208601611a3e565b9250604085013591506060850135611d9481611bbd565b939692955090935050565b5f805f60408486031215611db1575f80fd5b83359250602084013567ffffffffffffffff811115611dce575f80fd5b611dda86828701611a59565b9497909650939450505050565b5f805f8385036101a0811215611dfb575f80fd5b8435935061016080601f1983011215611e12575f80fd5b611e1a611be9565b91506020860135825260408601356020830152606086013560408301526080860135606083015260a0860135608083015260c086013560a083015260e086013560c08301526101008087013560e0840152610120611e79818901611bca565b828501526101409150611e8d828901611bca565b90840152611e9c878301611a3e565b9083015250915061018084013567ffffffffffffffff811115611ebd575f80fd5b611ec986828701611c13565b9150509250925092565b5f60208284031215611ee3575f80fd5b61174582611a3e565b5f805f60608486031215611efe575f80fd5b833592506020840135611f1081611bbd565b91506040840135611f2081611bbd565b809150509250925092565b60609290921b6001600160601b0319168252601482015260340190565b634e487b7160e01b5f52601160045260245ffd5b808201808211156118ac576118ac611f48565b5f60018201611f8057611f80611f48565b5060010190565b634e487b7160e01b5f52603260045260245ffd5b5f60208284031215611fab575f80fd5b5051919050565b5f60208284031215611fc2575f80fd5b815161174581611bbd565b5f82515f5b81811015611fec5760208186018101518583015201611fd2565b505f92019182525091905056fea2646970667358221220ac92075cd6ed1e66d4d9a91e8a6cf2949d42192ae7e7ec323c27ead4a37d8d5e64736f6c63430008140033

Verified Source Code Full Match

Compiler: v0.8.20+commit.a1b79de6 EVM: shanghai Optimization: Yes (200 runs)
NebulaDeals.sol 327 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";

contract NebulaDeals is Ownable {
    using SafeERC20 for IERC20;

    struct Phase {
        uint256 start;
        uint256 end;
        bytes32 depositMerkleRoot;
        bytes32 claimMerkleRoot;
        uint256 minimumDeposit;
        uint256 maximumDeposit;
        uint256 totalDeposits;
        uint256 totalClaims;
        bool claimEnabled;
        bool depositEnabled;
        address depositAddress;
    }

    struct CustomClaim {
        address token;
        bytes32 claimMerkleRoot;
        bool claimEnabled;
    }

    mapping(address => bool) public blacklist;
    mapping(uint256 => Phase) public phases;
    mapping(uint256 => CustomClaim) public customClaims;
    mapping(uint256 => mapping(address => uint256)) public deposits;
    mapping(uint256 => mapping(address => uint256)) public claims;
    mapping(uint256 => mapping(address => uint256)) public tokenClaims;
    mapping(uint256 => mapping(address => bool)) public phaseTokens;

    uint256 public globalId = 1;

    error TokenNotWhitelisted();
    error UserBlacklisted();
    error DepositsNotEnabled();
    error InvalidToken();
    error AllowanceTooLow();
    error InvalidProof();
    error AmountBelowMinimum();
    error AmountAboveMaximum();
    error DepositExceedsMaximum();
    error PhaseNotActive();
    error ClaimingNotEnabled();
    error AlreadyClaimed();
    error ClaimsNotEnabled();
    error CannotChangeToken();

    event PhaseCreated(
        uint256 id,
        uint256 start,
        uint256 end,
        bytes32 depositMerkleRoot,
        bytes32 claimMerkleRoot,
        uint256 minimumDeposit,
        uint256 maximumDeposit,
        bool depositEnabled,
        bool claimEnabled,
        address depositAddress
    );

    constructor() Ownable(msg.sender) {}

    function depositERC20(
        address _token,
        uint256 _amount,
        uint256 _phase,
        bytes32[] calldata _merkleProof
    ) external {
        Phase storage phase = phases[_phase];
        require(phaseTokens[_phase][_token], "Token not whitelisted");
        require(!blacklist[msg.sender], "User blacklisted");
        require(phase.depositEnabled, "Deposits not enabled");
        require(
            IERC20(_token).allowance(msg.sender, address(this)) >= _amount,
            "Allowance too low"
        );
        require(
            MerkleProof.verify(
                _merkleProof,
                phase.depositMerkleRoot,
                keccak256(abi.encodePacked(_msgSender()))
            ),
            "Invalid proof"
        );
        require(
            _amount >= phase.minimumDeposit && _amount <= phase.maximumDeposit,
            "Invalid amount"
        );
        require(
            deposits[_phase][msg.sender] + _amount <= phase.maximumDeposit,
            "Deposit exceeds maximum"
        );
        require(
            block.timestamp >= phase.start && block.timestamp <= phase.end,
            "Phase not active"
        );

        deposits[_phase][msg.sender] += _amount;
        phase.totalDeposits += _amount;
        IERC20(_token).safeTransferFrom(
            msg.sender,
            phase.depositAddress,
            _amount
        );
    }

    function claim(
        address _token,
        uint256 _amount,
        uint256 _phase,
        bytes32[] calldata _merkleProof
    ) external {
        Phase storage phase = phases[_phase];
        require(phase.claimEnabled, "Claiming not enabled");
        require(!blacklist[msg.sender], "User blacklisted");
        require(phaseTokens[_phase][_token], "Token not whitelisted");
        require(claims[_phase][msg.sender] == 0, "Already claimed");
        require(
            MerkleProof.verify(
                _merkleProof,
                phase.claimMerkleRoot,
                keccak256(abi.encodePacked(msg.sender, _amount))
            ),
            "Invalid proof"
        );

        IERC20(_token).safeTransfer(msg.sender, _amount);
        claims[_phase][msg.sender] += _amount;
        phase.totalClaims += _amount;
    }

    function createPhase(
        uint256 _start,
        uint256 _end,
        bytes32 _depositMerkleRoot,
        bytes32 _claimMerkleRoot,
        uint256 _minimumDeposit,
        uint256 _maximumDeposit,
        bool _depositEnabled,
        bool _claimEnabled,
        address _depositAddress,
        address[] memory _depositTokens
    ) external onlyOwner {
        uint256 id = globalId++;
        phases[id] = Phase(
            _start,
            _end,
            _depositMerkleRoot,
            _claimMerkleRoot,
            _minimumDeposit,
            _maximumDeposit,
            0,
            0,
            _claimEnabled,
            _depositEnabled,
            _depositAddress
        );
        for (uint i = 0; i < _depositTokens.length; i++) {
            phaseTokens[id][_depositTokens[i]] = true;
        }

        emit PhaseCreated(
            id,
            _start,
            _end,
            _depositMerkleRoot,
            _claimMerkleRoot,
            _minimumDeposit,
            _maximumDeposit,
            _depositEnabled,
            _claimEnabled,
            _depositAddress
        );
    }

    function depositETH(
        uint256 _phase,
        bytes32[] calldata _merkleProof
    ) external payable {
        if (blacklist[msg.sender]) revert UserBlacklisted();
        bytes32 leaf = keccak256(abi.encodePacked(_msgSender()));
        if (
            !MerkleProof.verify(
                _merkleProof,
                phases[_phase].depositMerkleRoot,
                leaf
            )
        ) revert InvalidProof();
        if (msg.value < phases[_phase].minimumDeposit)
            revert AmountBelowMinimum();
        if (msg.value > phases[_phase].maximumDeposit)
            revert AmountAboveMaximum();
        if (
            deposits[_phase][msg.sender] + msg.value >
            phases[_phase].maximumDeposit
        ) revert DepositExceedsMaximum();
        if (
            phases[_phase].start > block.timestamp ||
            phases[_phase].end < block.timestamp
        ) revert PhaseNotActive();

        deposits[_phase][msg.sender] += msg.value;
        phases[_phase].totalDeposits += msg.value;
        payable(phases[_phase].depositAddress).transfer(msg.value);
    }

    function claimETH(
        uint256 _amount,
        uint256 _phase,
        bytes32[] calldata _merkleProof
    ) external {
        if (!phases[_phase].claimEnabled) revert ClaimingNotEnabled();
        if (claims[_phase][msg.sender] != 0) revert AlreadyClaimed();
        if (blacklist[msg.sender]) revert UserBlacklisted();
        bytes32 leaf = keccak256(abi.encodePacked((msg.sender), _amount));
        if (
            !MerkleProof.verify(
                _merkleProof,
                phases[_phase].claimMerkleRoot,
                leaf
            )
        ) revert InvalidProof();

        payable(msg.sender).transfer(_amount);
        claims[_phase][msg.sender] += _amount;
        phases[_phase].totalClaims += _amount;
    }

    function claimAllocation(
        uint256 _phase,
        uint256 _amount,
        bytes32[] calldata _merkleProof
    ) external {
        if (!customClaims[_phase].claimEnabled) revert ClaimsNotEnabled();
        if (tokenClaims[_phase][msg.sender] != 0) revert AlreadyClaimed();
        if (blacklist[msg.sender]) revert UserBlacklisted();
        bytes32 leaf = keccak256(abi.encodePacked((msg.sender), _amount));
        if (
            !MerkleProof.verify(
                _merkleProof,
                customClaims[_phase].claimMerkleRoot,
                leaf
            )
        ) revert InvalidProof();

        SafeERC20.safeTransfer(
            IERC20(customClaims[_phase].token),
            msg.sender,
            _amount
        );

        tokenClaims[_phase][msg.sender] += _amount;
    }

    function removeBlacklist(address _user) external onlyOwner {
        blacklist[_user] = false;
    }

    function updateOpportunityStatus(
        uint256 _id,
        bool _depositEnabled,
        bool _claimEnabled
    ) external onlyOwner {
        phases[_id].depositEnabled = _depositEnabled;
        phases[_id].claimEnabled = _claimEnabled;
    }

    function updateOpportunityDetails(
        uint256 _id,
        bytes32 _depositMerkleRoot,
        bytes32 _claimMerkleRoot
    ) external onlyOwner {
        phases[_id].depositMerkleRoot = _depositMerkleRoot;
        phases[_id].claimMerkleRoot = _claimMerkleRoot;
    }

    function updatePhase(
        uint256 _id,
        Phase memory _newPhase,
        address[] memory _depositTokens
    ) external onlyOwner {
        phases[_id] = _newPhase;
        for (uint i = 0; i < _depositTokens.length; i++) {
            phaseTokens[_id][_depositTokens[i]] = false;
        }
        for (uint i = 0; i < _depositTokens.length; i++) {
            phaseTokens[_id][_depositTokens[i]] = true;
        }
    }

    function createCustomClaim(
        uint256 _phase,
        address _token,
        bytes32 _claimMerkleRoot,
        bool _claimEnabled
    ) external onlyOwner {
        customClaims[_phase] = CustomClaim(
            _token,
            _claimMerkleRoot,
            _claimEnabled
        );
    }

    function updateCustomClaim(
        uint256 _phase,
        address _token,
        bytes32 _claimMerkleRoot,
        bool _claimEnabled
    ) external onlyOwner {
        if (customClaims[_phase].claimEnabled) revert ClaimsNotEnabled();
        if (customClaims[_phase].token != _token) revert CannotChangeToken();
        customClaims[_phase] = CustomClaim(
            _token,
            _claimMerkleRoot,
            _claimEnabled
        );
    }
}
Address.sol 159 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error AddressInsufficientBalance(address account);

    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @dev A call to an address target failed. The target may have reverted.
     */
    error FailedInnerCall();

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        if (address(this).balance < amount) {
            revert AddressInsufficientBalance(address(this));
        }

        (bool success, ) = recipient.call{value: amount}("");
        if (!success) {
            revert FailedInnerCall();
        }
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason or custom error, it is bubbled
     * up by this function (like regular Solidity function calls). However, if
     * the call reverted with no returned reason, this function reverts with a
     * {FailedInnerCall} error.
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
     * unsuccessful call.
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata
    ) internal view returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {FailedInnerCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert FailedInnerCall();
        }
    }
}
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;
    }
}
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);
    }
}
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);
}
SafeERC20.sol 118 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    /**
     * @dev An operation with an ERC20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data);
        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
    }
}
MerkleProof.sol 232 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MerkleProof.sol)

pragma solidity ^0.8.20;

/**
 * @dev These functions deal with verification of Merkle Tree proofs.
 *
 * The tree and the proofs can be generated using our
 * https://github.com/OpenZeppelin/merkle-tree[JavaScript library].
 * You will find a quickstart guide in the readme.
 *
 * WARNING: You should avoid using leaf values that are 64 bytes long prior to
 * hashing, or use a hash function other than keccak256 for hashing leaves.
 * This is because the concatenation of a sorted pair of internal nodes in
 * the Merkle tree could be reinterpreted as a leaf value.
 * OpenZeppelin's JavaScript library generates Merkle trees that are safe
 * against this attack out of the box.
 */
library MerkleProof {
    /**
     *@dev The multiproof provided is not valid.
     */
    error MerkleProofInvalidMultiproof();

    /**
     * @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
     * defined by `root`. For this, a `proof` must be provided, containing
     * sibling hashes on the branch from the leaf to the root of the tree. Each
     * pair of leaves and each pair of pre-images are assumed to be sorted.
     */
    function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
        return processProof(proof, leaf) == root;
    }

    /**
     * @dev Calldata version of {verify}
     */
    function verifyCalldata(bytes32[] calldata proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
        return processProofCalldata(proof, leaf) == root;
    }

    /**
     * @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
     * from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
     * hash matches the root of the tree. When processing the proof, the pairs
     * of leafs & pre-images are assumed to be sorted.
     */
    function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = _hashPair(computedHash, proof[i]);
        }
        return computedHash;
    }

    /**
     * @dev Calldata version of {processProof}
     */
    function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = _hashPair(computedHash, proof[i]);
        }
        return computedHash;
    }

    /**
     * @dev Returns true if the `leaves` can be simultaneously proven to be a part of a Merkle tree defined by
     * `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
     *
     * CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
     */
    function multiProofVerify(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32 root,
        bytes32[] memory leaves
    ) internal pure returns (bool) {
        return processMultiProof(proof, proofFlags, leaves) == root;
    }

    /**
     * @dev Calldata version of {multiProofVerify}
     *
     * CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
     */
    function multiProofVerifyCalldata(
        bytes32[] calldata proof,
        bool[] calldata proofFlags,
        bytes32 root,
        bytes32[] memory leaves
    ) internal pure returns (bool) {
        return processMultiProofCalldata(proof, proofFlags, leaves) == root;
    }

    /**
     * @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction
     * proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another
     * leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false
     * respectively.
     *
     * CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
     * is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
     * tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
     */
    function processMultiProof(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32[] memory leaves
    ) internal pure returns (bytes32 merkleRoot) {
        // This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
        // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
        // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
        // the Merkle tree.
        uint256 leavesLen = leaves.length;
        uint256 proofLen = proof.length;
        uint256 totalHashes = proofFlags.length;

        // Check proof validity.
        if (leavesLen + proofLen != totalHashes + 1) {
            revert MerkleProofInvalidMultiproof();
        }

        // The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
        // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
        bytes32[] memory hashes = new bytes32[](totalHashes);
        uint256 leafPos = 0;
        uint256 hashPos = 0;
        uint256 proofPos = 0;
        // At each step, we compute the next hash using two values:
        // - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
        //   get the next hash.
        // - depending on the flag, either another value from the "main queue" (merging branches) or an element from the
        //   `proof` array.
        for (uint256 i = 0; i < totalHashes; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i]
                ? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
                : proof[proofPos++];
            hashes[i] = _hashPair(a, b);
        }

        if (totalHashes > 0) {
            if (proofPos != proofLen) {
                revert MerkleProofInvalidMultiproof();
            }
            unchecked {
                return hashes[totalHashes - 1];
            }
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }

    /**
     * @dev Calldata version of {processMultiProof}.
     *
     * CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
     */
    function processMultiProofCalldata(
        bytes32[] calldata proof,
        bool[] calldata proofFlags,
        bytes32[] memory leaves
    ) internal pure returns (bytes32 merkleRoot) {
        // This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
        // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
        // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
        // the Merkle tree.
        uint256 leavesLen = leaves.length;
        uint256 proofLen = proof.length;
        uint256 totalHashes = proofFlags.length;

        // Check proof validity.
        if (leavesLen + proofLen != totalHashes + 1) {
            revert MerkleProofInvalidMultiproof();
        }

        // The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
        // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
        bytes32[] memory hashes = new bytes32[](totalHashes);
        uint256 leafPos = 0;
        uint256 hashPos = 0;
        uint256 proofPos = 0;
        // At each step, we compute the next hash using two values:
        // - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
        //   get the next hash.
        // - depending on the flag, either another value from the "main queue" (merging branches) or an element from the
        //   `proof` array.
        for (uint256 i = 0; i < totalHashes; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i]
                ? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
                : proof[proofPos++];
            hashes[i] = _hashPair(a, b);
        }

        if (totalHashes > 0) {
            if (proofPos != proofLen) {
                revert MerkleProofInvalidMultiproof();
            }
            unchecked {
                return hashes[totalHashes - 1];
            }
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }

    /**
     * @dev Sorts the pair (a, b) and hashes the result.
     */
    function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) {
        return a < b ? _efficientHash(a, b) : _efficientHash(b, a);
    }

    /**
     * @dev Implementation of keccak256(abi.encode(a, b)) that doesn't allocate or expand memory.
     */
    function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, a)
            mstore(0x20, b)
            value := keccak256(0x00, 0x40)
        }
    }
}
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

Read Contract

blacklist 0xf9f92be4 → bool
claims 0x1da4c66b → uint256
customClaims 0xae956715 → address, bytes32, bool
deposits 0x53a58de1 → uint256
globalId 0xca666823 → uint256
owner 0x8da5cb5b → address
phaseTokens 0xff41e60d → bool
phases 0x2e37eef6 → uint256, uint256, bytes32, bytes32, uint256, uint256, uint256, uint256, bool, bool, address
tokenClaims 0xa5ba3b1e → uint256

Write Contract 14 functions

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

claim 0x172bd6de
address _token
uint256 _amount
uint256 _phase
bytes32[] _merkleProof
claimAllocation 0xa3e2931c
uint256 _phase
uint256 _amount
bytes32[] _merkleProof
claimETH 0x195256bb
uint256 _amount
uint256 _phase
bytes32[] _merkleProof
createCustomClaim 0x87019f28
uint256 _phase
address _token
bytes32 _claimMerkleRoot
bool _claimEnabled
createPhase 0x5951f248
uint256 _start
uint256 _end
bytes32 _depositMerkleRoot
bytes32 _claimMerkleRoot
uint256 _minimumDeposit
uint256 _maximumDeposit
bool _depositEnabled
bool _claimEnabled
address _depositAddress
address[] _depositTokens
depositERC20 0x9fac38d3
address _token
uint256 _amount
uint256 _phase
bytes32[] _merkleProof
depositETH 0x86c984c4
uint256 _phase
bytes32[] _merkleProof
removeBlacklist 0xeb91e651
address _user
renounceOwnership 0x715018a6
No parameters
transferOwnership 0xf2fde38b
address newOwner
updateCustomClaim 0x859a9dae
uint256 _phase
address _token
bytes32 _claimMerkleRoot
bool _claimEnabled
updateOpportunityDetails 0x37a7149c
uint256 _id
bytes32 _depositMerkleRoot
bytes32 _claimMerkleRoot
updateOpportunityStatus 0xecf877f1
uint256 _id
bool _depositEnabled
bool _claimEnabled
updatePhase 0xaaebd2f5
uint256 _id
tuple _newPhase
address[] _depositTokens

Recent Transactions

No transactions found for this address