Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xd084104A486f5D98ad7D065f23E881489ea3BC4A
Balance 0 ETH
Nonce 1
Code Size 9172 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

9172 bytes
0x608060405234801561001057600080fd5b50600436106101165760003560e01c8063779972da116100a2578063a694fc3a11610071578063a694fc3a146102d1578063b5d5b5fa146102ed578063cdc87f681461031d578063eb4af0451461034d578063f2fde38b1461036957610116565b8063779972da146102375780637ecebe00146102535780638b730bd3146102835780638da5cb5b146102b357610116565b806351d18598116100e957806351d18598146101a5578063584b62a1146101c3578063715018a6146101f557806374de4ec4146101ff57806376618f271461021b57610116565b806315566a5b1461011b5780632421a9f2146101395780632e17de78146101575780633b521efe14610173575b600080fd5b610123610385565b6040516101309190611839565b60405180910390f35b61014161038b565b60405161014e91906118d3565b60405180910390f35b610171600480360381019061016c919061192e565b6103b1565b005b61018d60048036038101906101889190611999565b61068a565b60405161019c939291906119d9565b60405180910390f35b6101ad610728565b6040516101ba9190611839565b60405180910390f35b6101dd60048036038101906101d89190611999565b610732565b6040516101ec939291906119d9565b60405180910390f35b6101fd610769565b005b6102196004803603810190610214919061192e565b61077d565b005b61023560048036038101906102309190611b56565b6108a0565b005b610251600480360381019061024c919061192e565b610bc3565b005b61026d60048036038101906102689190611bc5565b610c0e565b60405161027a9190611839565b60405180910390f35b61029d60048036038101906102989190611bc5565b610c26565b6040516102aa9190611cb0565b60405180910390f35b6102bb610e8d565b6040516102c89190611ce1565b60405180910390f35b6102eb60048036038101906102e6919061192e565b610eb6565b005b61030760048036038101906103029190611999565b611167565b6040516103149190611839565b60405180910390f35b61033760048036038101906103329190611bc5565b611198565b6040516103449190611839565b60405180910390f35b6103676004803603810190610362919061192e565b6112d0565b005b610383600480360381019061037e9190611bc5565b6112e2565b005b60065481565b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6103b9611368565b6000600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002060405180606001604052908160008201548152602001600182015481526020016002820154815250509050600081600001511161047d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161047490611d59565b60405180910390fd5b806040015181602001516104919190611da8565b4210156104d3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104ca90611e28565b60405180910390fd5b6000816000015190506000600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600085815260200190815260200160002060000181905550600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb33836040518363ffffffff1660e01b8152600401610592929190611e48565b6020604051808303816000875af11580156105b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105d59190611ea9565b610614576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161060b90611f22565b60405180910390fd5b80600460008282546106269190611f42565b925050819055503373ffffffffffffffffffffffffffffffffffffffff167f7fc4727e062e336010f2c282598ef5f14facb3de68cf8195c2f23e1454b2b74e8285604051610675929190611f76565b60405180910390a250506106876113ae565b50565b600080600080600760008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600086815260200190815260200160002060405180606001604052908160008201548152602001600182015481526020016002820154815250509050806000015181602001518260400151935093509350509250925092565b6000600454905090565b6007602052816000526040600020602052806000526040600020600091509150508060000154908060010154908060020154905083565b6107716113b7565b61077b600061143e565b565b6107856113b7565b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166323b872dd3330846040518463ffffffff1660e01b81526004016107e493929190611f9f565b6020604051808303816000875af1158015610803573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108279190611ea9565b610866576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161085d90611f22565b60405180910390fd5b7fde88a922e0d3b88b24e9623efeb464919c6bf9f66857a65e2bfcf2ce87a9433d816040516108959190611839565b60405180910390a150565b6108a8611368565b600083116108eb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108e290612022565b60405180910390fd5b600960003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821461096c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109639061208e565b60405180910390fd5b6000338484306040516020016109859493929190612117565b60405160208183030381529060405280519060200120905060006109a882611502565b905060006109b68285611538565b90506109c0610e8d565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614610a2d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a24906121b1565b60405180910390fd5b6001600960003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610a7d9190611da8565b92505081905550600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb33886040518363ffffffff1660e01b8152600401610ae1929190611e48565b6020604051808303816000875af1158015610b00573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b249190611ea9565b610b63576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b5a90611f22565b60405180910390fd5b3373ffffffffffffffffffffffffffffffffffffffff167ff01da32686223933d8a18a391060918c7f11a3648639edd87ae013e2e27317438787604051610bab929190611f76565b60405180910390a2505050610bbe6113ae565b505050565b610bcb6113b7565b806006819055507f8249ec545e68f6f1e1230133ca48c704d831a7f8e635ded80f3dd9e99b09bb2f600654604051610c039190611839565b60405180910390a150565b60096020528060005260406000206000915090505481565b60606000600860008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020805480602002602001604051908101604052809291908181526020018280548015610cb357602002820191906000526020600020905b815481526020019060010190808311610c9f575b505050505090506000805b8251811015610d59576000600760008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000858481518110610d1d57610d1c6121d1565b5b60200260200101518152602001908152602001600020600001541115610d4c578180610d4890612200565b9250505b8080600101915050610cbe565b5060008167ffffffffffffffff811115610d7657610d75611a2b565b5b604051908082528060200260200182016040528015610da45781602001602082028036833780820191505090505b5090506000805b8451811015610e80576000600760008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000878481518110610e0a57610e096121d1565b5b60200260200101518152602001908152602001600020600001541115610e7357848181518110610e3d57610e3c6121d1565b5b6020026020010151838381518110610e5857610e576121d1565b5b6020026020010181815250508180610e6f90612200565b9250505b8080600101915050610dab565b5081945050505050919050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60008111610ef9576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ef090612022565b60405180910390fd5b600354811015610f3e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f35906122ba565b60405180910390fd5b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166323b872dd3330846040518463ffffffff1660e01b8152600401610f9d93929190611f9f565b6020604051808303816000875af1158015610fbc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fe09190611ea9565b5060006002549050600160026000828254610ffb9190611da8565b925050819055506040518060600160405280838152602001428152602001600654815250600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000838152602001908152602001600020600082015181600001556020820151816001015560408201518160020155905050600860003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081908060018154018082558091505060019003906000526020600020016000909190919091505581600460008282546111089190611da8565b925050819055503373ffffffffffffffffffffffffffffffffffffffff167fb4caaf29adda3eefee3ad552a8e85058589bf834c7466cae4ee58787f70589ed838360065460405161115b939291906119d9565b60405180910390a25050565b6008602052816000526040600020818154811061118357600080fd5b90600052602060002001600091509150505481565b600080600090506000600860008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561122a57602002820191906000526020600020905b815481526020019060010190808311611216575b5050505050905060005b81518110156112c557600760008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000838381518110611291576112906121d1565b5b6020026020010151815260200190815260200160002060000154836112b69190611da8565b92508080600101915050611234565b508192505050919050565b6112d86113b7565b8060038190555050565b6112ea6113b7565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff160361135c5760006040517f1e4fbdf70000000000000000000000000000000000000000000000000000000081526004016113539190611ce1565b60405180910390fd5b6113658161143e565b50565b6002600154036113a4576040517f3ee5aeb500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6002600181905550565b60018081905550565b6113bf611564565b73ffffffffffffffffffffffffffffffffffffffff166113dd610e8d565b73ffffffffffffffffffffffffffffffffffffffff161461143c57611400611564565b6040517f118cdaa70000000000000000000000000000000000000000000000000000000081526004016114339190611ce1565b60405180910390fd5b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b60007f19457468657265756d205369676e6564204d6573736167653a0a33320000000060005281601c52603c6000209050919050565b600080600080611548868661156c565b92509250925061155882826115c8565b82935050505092915050565b600033905090565b600080600060418451036115b15760008060006020870151925060408701519150606087015160001a90506115a38882858561172c565b9550955095505050506115c1565b60006002855160001b9250925092505b9250925092565b600060038111156115dc576115db6122da565b5b8260038111156115ef576115ee6122da565b5b03156117285760016003811115611609576116086122da565b5b82600381111561161c5761161b6122da565b5b03611653576040517ff645eedf00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60026003811115611667576116666122da565b5b82600381111561167a576116796122da565b5b036116bf578060001c6040517ffce698f70000000000000000000000000000000000000000000000000000000081526004016116b69190611839565b60405180910390fd5b6003808111156116d2576116d16122da565b5b8260038111156116e5576116e46122da565b5b0361172757806040517fd78bce0c00000000000000000000000000000000000000000000000000000000815260040161171e9190612322565b60405180910390fd5b5b5050565b60008060007f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08460001c111561176c576000600385925092509250611816565b6000600188888888604051600081526020016040526040516117919493929190612359565b6020604051602081039080840390855afa1580156117b3573d6000803e3d6000fd5b505050602060405103519050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff160361180757600060016000801b93509350935050611816565b8060008060001b935093509350505b9450945094915050565b6000819050919050565b61183381611820565b82525050565b600060208201905061184e600083018461182a565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600061189961189461188f84611854565b611874565b611854565b9050919050565b60006118ab8261187e565b9050919050565b60006118bd826118a0565b9050919050565b6118cd816118b2565b82525050565b60006020820190506118e860008301846118c4565b92915050565b6000604051905090565b600080fd5b600080fd5b61190b81611820565b811461191657600080fd5b50565b60008135905061192881611902565b92915050565b600060208284031215611944576119436118f8565b5b600061195284828501611919565b91505092915050565b600061196682611854565b9050919050565b6119768161195b565b811461198157600080fd5b50565b6000813590506119938161196d565b92915050565b600080604083850312156119b0576119af6118f8565b5b60006119be85828601611984565b92505060206119cf85828601611919565b9150509250929050565b60006060820190506119ee600083018661182a565b6119fb602083018561182a565b611a08604083018461182a565b949350505050565b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b611a6382611a1a565b810181811067ffffffffffffffff82111715611a8257611a81611a2b565b5b80604052505050565b6000611a956118ee565b9050611aa18282611a5a565b919050565b600067ffffffffffffffff821115611ac157611ac0611a2b565b5b611aca82611a1a565b9050602081019050919050565b82818337600083830152505050565b6000611af9611af484611aa6565b611a8b565b905082815260208101848484011115611b1557611b14611a15565b5b611b20848285611ad7565b509392505050565b600082601f830112611b3d57611b3c611a10565b5b8135611b4d848260208601611ae6565b91505092915050565b600080600060608486031215611b6f57611b6e6118f8565b5b6000611b7d86828701611919565b9350506020611b8e86828701611919565b925050604084013567ffffffffffffffff811115611baf57611bae6118fd565b5b611bbb86828701611b28565b9150509250925092565b600060208284031215611bdb57611bda6118f8565b5b6000611be984828501611984565b91505092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b611c2781611820565b82525050565b6000611c398383611c1e565b60208301905092915050565b6000602082019050919050565b6000611c5d82611bf2565b611c678185611bfd565b9350611c7283611c0e565b8060005b83811015611ca3578151611c8a8882611c2d565b9750611c9583611c45565b925050600181019050611c76565b5085935050505092915050565b60006020820190508181036000830152611cca8184611c52565b905092915050565b611cdb8161195b565b82525050565b6000602082019050611cf66000830184611cd2565b92915050565b600082825260208201905092915050565b7f5374616b6520646f6573206e6f74206578697374000000000000000000000000600082015250565b6000611d43601483611cfc565b9150611d4e82611d0d565b602082019050919050565b60006020820190508181036000830152611d7281611d36565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000611db382611820565b9150611dbe83611820565b9250828201905080821115611dd657611dd5611d79565b5b92915050565b7f5374616b65206973207374696c6c206c6f636b65640000000000000000000000600082015250565b6000611e12601583611cfc565b9150611e1d82611ddc565b602082019050919050565b60006020820190508181036000830152611e4181611e05565b9050919050565b6000604082019050611e5d6000830185611cd2565b611e6a602083018461182a565b9392505050565b60008115159050919050565b611e8681611e71565b8114611e9157600080fd5b50565b600081519050611ea381611e7d565b92915050565b600060208284031215611ebf57611ebe6118f8565b5b6000611ecd84828501611e94565b91505092915050565b7f5472616e73666572206661696c65640000000000000000000000000000000000600082015250565b6000611f0c600f83611cfc565b9150611f1782611ed6565b602082019050919050565b60006020820190508181036000830152611f3b81611eff565b9050919050565b6000611f4d82611820565b9150611f5883611820565b9250828203905081811115611f7057611f6f611d79565b5b92915050565b6000604082019050611f8b600083018561182a565b611f98602083018461182a565b9392505050565b6000606082019050611fb46000830186611cd2565b611fc16020830185611cd2565b611fce604083018461182a565b949350505050565b7f416d6f756e74206d7573742062652067726561746572207468616e2030000000600082015250565b600061200c601d83611cfc565b915061201782611fd6565b602082019050919050565b6000602082019050818103600083015261203b81611fff565b9050919050565b7f496e76616c6964206e6f6e636500000000000000000000000000000000000000600082015250565b6000612078600d83611cfc565b915061208382612042565b602082019050919050565b600060208201905081810360008301526120a78161206b565b9050919050565b60008160601b9050919050565b60006120c6826120ae565b9050919050565b60006120d8826120bb565b9050919050565b6120f06120eb8261195b565b6120cd565b82525050565b6000819050919050565b61211161210c82611820565b6120f6565b82525050565b600061212382876120df565b6014820191506121338286612100565b6020820191506121438285612100565b60208201915061215382846120df565b60148201915081905095945050505050565b7f496e76616c6964207369676e6174757265000000000000000000000000000000600082015250565b600061219b601183611cfc565b91506121a682612165565b602082019050919050565b600060208201905081810360008301526121ca8161218e565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600061220b82611820565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff820361223d5761223c611d79565b5b600182019050919050565b7f416d6f756e74206d7573742062652067726561746572207468616e206d696e2060008201527f7374616b6520616d6f756e740000000000000000000000000000000000000000602082015250565b60006122a4602c83611cfc565b91506122af82612248565b604082019050919050565b600060208201905081810360008301526122d381612297565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b6000819050919050565b61231c81612309565b82525050565b60006020820190506123376000830184612313565b92915050565b600060ff82169050919050565b6123538161233d565b82525050565b600060808201905061236e6000830187612313565b61237b602083018661234a565b6123886040830185612313565b6123956060830184612313565b9594505050505056fea264697066735822122006cf15bb437044e47fc53fe44ce02af7f1c4fa8a73d1288fae9fea8b3dd3c17364736f6c63430008180033

Verified Source Code Full Match

Compiler: v0.8.24+commit.e11b9ed9 EVM: paris Optimization: No
Staking.sol 146 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

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

import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

contract Staking is Ownable, ReentrancyGuard {
    uint256 _stakeId = 0;
    uint256 _minStakeAmount = 0;

    uint256 totalStakedTokens = 0;

    struct Stake {
        uint256 amount;
        uint256 startTime;
        uint256 lockPeriod;
    }

    IERC20 public _stakingToken;
    uint256 public _lockPeriod;

    mapping(address => mapping(uint256 => Stake)) public stakes;
    mapping(address => uint256[]) public userStakes;
    mapping(address => uint256) public nonces;

    event Staked(address indexed user, uint256 amount, uint256 stakeId, uint256 lockPeriod);
    event Unstaked(address indexed user, uint256 amount, uint256 stakeId);
    event LockPeriodUpdated(uint256 newLockPeriod);
    event RewardAdded(uint256 amount);
    event RewardClaimed(address indexed user, uint256 amount, uint256 nonce);

    constructor(IERC20 stakingToken, uint256 lockPeriod, uint256 minStakeAmount) Ownable(msg.sender) {
        _stakingToken = stakingToken;
        _lockPeriod = lockPeriod;
        _minStakeAmount = minStakeAmount;
    }

    function setLockPeriod(uint256 lockPeriod) external onlyOwner {
        _lockPeriod = lockPeriod;
        emit LockPeriodUpdated(_lockPeriod);
    }

    function setMinStakeAmount(uint256 minStakeAmount) external onlyOwner {
        _minStakeAmount = minStakeAmount;
    }

    function stake(uint256 amount) external {
        require(amount > 0, "Amount must be greater than 0");
        require(amount >= _minStakeAmount, "Amount must be greater than min stake amount");
        
        _stakingToken.transferFrom(msg.sender, address(this), amount);

        uint256 stakeId = _stakeId;
        _stakeId += 1;

        stakes[msg.sender][stakeId] = Stake({
            amount: amount,
            startTime: block.timestamp,
            lockPeriod: _lockPeriod
        });

        userStakes[msg.sender].push(stakeId);
        totalStakedTokens += amount;

        emit Staked(msg.sender, amount, stakeId, _lockPeriod);
    }

    function unstake(uint256 stakeId) nonReentrant external {
        Stake memory userStake = stakes[msg.sender][stakeId];
        require(userStake.amount > 0, "Stake does not exist");
        require(block.timestamp >= userStake.startTime + userStake.lockPeriod, "Stake is still locked");

        uint256 amount = userStake.amount;
        stakes[msg.sender][stakeId].amount = 0;

        require(_stakingToken.transfer(msg.sender, amount), "Transfer failed");
        totalStakedTokens -= amount;
        emit Unstaked(msg.sender, amount, stakeId);
    }

    function getStakeInfo(address user, uint256 stakeId) external view returns (uint256 amount, uint256 startTime, uint256 lockPeriod) {
        Stake memory userStake = stakes[user][stakeId];
        return (userStake.amount, userStake.startTime, userStake.lockPeriod);
    }

    function getTotalStakedTokens() external view returns (uint256) {
        return totalStakedTokens;
    }

    function getTotalStakedTokens(address user) external view returns (uint256) {
        uint256 totalStaked = 0;
        uint256[] memory userStakeIds = userStakes[user];
        for (uint256 i = 0; i < userStakeIds.length; i++) {
            totalStaked += stakes[user][userStakeIds[i]].amount;
        }
        return totalStaked;
    }

    function addReward(uint256 amount) external onlyOwner {
        require(_stakingToken.transferFrom(msg.sender, address(this), amount), "Transfer failed");
        emit RewardAdded(amount);
    }

    function claimReward(uint256 amount, uint256 nonce, bytes memory signature) nonReentrant external {
        require(amount > 0, "Amount must be greater than 0");
        require(nonce == nonces[msg.sender], "Invalid nonce");
        bytes32 message = keccak256(abi.encodePacked(msg.sender, amount, nonce, address(this)));
        bytes32 messageHash = MessageHashUtils.toEthSignedMessageHash(message);

        address signer = ECDSA.recover(messageHash, signature);
        require(signer == owner(), "Invalid signature");

        nonces[msg.sender] += 1;

        require(_stakingToken.transfer(msg.sender, amount), "Transfer failed");

        emit RewardClaimed(msg.sender, amount, nonce);
    }

    function getActiveStakeIds(address user) external view returns (uint256[] memory) {
        uint256[] memory userStakeIds = userStakes[user];
        uint256 activeStakeCount = 0;

        for (uint256 i = 0; i < userStakeIds.length; i++) {
            if (stakes[user][userStakeIds[i]].amount > 0) {
                activeStakeCount++;
            }
        }

        uint256[] memory activeStakes = new uint256[](activeStakeCount);
        uint256 index = 0;

        for (uint256 i = 0; i < userStakeIds.length; i++) {
            if (stakes[user][userStakeIds[i]].amount > 0) {
                activeStakes[index] = userStakeIds[i];
                index++;
            }
        }

        return activeStakes;
    }
}
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;
    }
}
Strings.sol 94 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)

pragma solidity ^0.8.20;

import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant HEX_DIGITS = "0123456789abcdef";
    uint8 private constant ADDRESS_LENGTH = 20;

    /**
     * @dev The `value` string doesn't fit in the specified `length`.
     */
    error StringsInsufficientHexLength(uint256 value, uint256 length);

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toStringSigned(int256 value) internal pure returns (string memory) {
        return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        uint256 localValue = value;
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = HEX_DIGITS[localValue & 0xf];
            localValue >>= 4;
        }
        if (localValue != 0) {
            revert StringsInsufficientHexLength(value, length);
        }
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
     * representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
    }

    /**
     * @dev Returns true if the two strings are equal.
     */
    function equal(string memory a, string memory b) internal pure returns (bool) {
        return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
    }
}
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);
    }
}
Math.sol 415 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)

pragma solidity ^0.8.20;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Muldiv operation overflow.
     */
    error MathOverflowedMulDiv();

    enum Rounding {
        Floor, // Toward negative infinity
        Ceil, // Toward positive infinity
        Trunc, // Toward zero
        Expand // Away from zero
    }

    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds towards infinity instead
     * of rounding towards zero.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        if (b == 0) {
            // Guarantee the same behavior as in a regular Solidity division.
            return a / b;
        }

        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
     * denominator == 0.
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
     * Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0 = x * y; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            if (denominator <= prod1) {
                revert MathOverflowedMulDiv();
            }

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator.
            // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.

            uint256 twos = denominator & (0 - denominator);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
            // works in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
     * towards zero.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
        }
    }

    /**
     * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
     */
    function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
        return uint8(rounding) % 2 == 1;
    }
}
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);
}
ReentrancyGuard.sol 84 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant NOT_ENTERED = 1;
    uint256 private constant ENTERED = 2;

    uint256 private _status;

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    constructor() {
        _status = NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if (_status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

        // Any calls to nonReentrant after this point will fail
        _status = ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == ENTERED;
    }
}
SignedMath.sol 43 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.20;

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Returns the largest of two signed numbers.
     */
    function max(int256 a, int256 b) internal pure returns (int256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two signed numbers.
     */
    function min(int256 a, int256 b) internal pure returns (int256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}
ECDSA.sol 174 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.20;

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    enum RecoverError {
        NoError,
        InvalidSignature,
        InvalidSignatureLength,
        InvalidSignatureS
    }

    /**
     * @dev The signature derives the `address(0)`.
     */
    error ECDSAInvalidSignature();

    /**
     * @dev The signature has an invalid length.
     */
    error ECDSAInvalidSignatureLength(uint256 length);

    /**
     * @dev The signature has an S value that is in the upper half order.
     */
    error ECDSAInvalidSignatureS(bytes32 s);

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
     * return address(0) without also returning an error description. Errors are documented using an enum (error type)
     * and a bytes32 providing additional information about the error.
     *
     * If no error is returned, then the address can be used for verification purposes.
     *
     * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) {
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            /// @solidity memory-safe-assembly
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     */
    function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) {
        unchecked {
            bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
            // We do not check for an overflow here since the shift operation results in 0 or 1.
            uint8 v = uint8((uint256(vs) >> 255) + 27);
            return tryRecover(hash, v, r, s);
        }
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
     */
    function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function tryRecover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address, RecoverError, bytes32) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
            return (address(0), RecoverError.InvalidSignatureS, s);
        }

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        if (signer == address(0)) {
            return (address(0), RecoverError.InvalidSignature, bytes32(0));
        }

        return (signer, RecoverError.NoError, bytes32(0));
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
     */
    function _throwError(RecoverError error, bytes32 errorArg) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert ECDSAInvalidSignature();
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert ECDSAInvalidSignatureLength(uint256(errorArg));
        } else if (error == RecoverError.InvalidSignatureS) {
            revert ECDSAInvalidSignatureS(errorArg);
        }
    }
}
MessageHashUtils.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MessageHashUtils.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.
 *
 * The library provides methods for generating a hash of a message that conforms to the
 * https://eips.ethereum.org/EIPS/eip-191[EIP 191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]
 * specifications.
 */
library MessageHashUtils {
    /**
     * @dev Returns the keccak256 digest of an EIP-191 signed data with version
     * `0x45` (`personal_sign` messages).
     *
     * The digest is calculated by prefixing a bytes32 `messageHash` with
     * `"\x19Ethereum Signed Message:\n32"` and hashing the result. It corresponds with the
     * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
     *
     * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with
     * keccak256, although any bytes32 value can be safely used because the final digest will
     * be re-hashed.
     *
     * See {ECDSA-recover}.
     */
    function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, "\x19Ethereum Signed Message:\n32") // 32 is the bytes-length of messageHash
            mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix
            digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)
        }
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-191 signed data with version
     * `0x45` (`personal_sign` messages).
     *
     * The digest is calculated by prefixing an arbitrary `message` with
     * `"\x19Ethereum Signed Message:\n" + len(message)` and hashing the result. It corresponds with the
     * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
     *
     * See {ECDSA-recover}.
     */
    function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {
        return
            keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message));
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-191 signed data with version
     * `0x00` (data with intended validator).
     *
     * The digest is calculated by prefixing an arbitrary `data` with `"\x19\x00"` and the intended
     * `validator` address. Then hashing the result.
     *
     * See {ECDSA-recover}.
     */
    function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked(hex"19_00", validator, data));
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-712 typed data (EIP-191 version `0x01`).
     *
     * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with
     * `\x19\x01` and hashing the result. It corresponds to the hash signed by the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.
     *
     * See {ECDSA-recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, hex"19_01")
            mstore(add(ptr, 0x02), domainSeparator)
            mstore(add(ptr, 0x22), structHash)
            digest := keccak256(ptr, 0x42)
        }
    }
}

Read Contract

_lockPeriod 0x15566a5b → uint256
_stakingToken 0x2421a9f2 → address
getActiveStakeIds 0x8b730bd3 → uint256[]
getStakeInfo 0x3b521efe → uint256, uint256, uint256
getTotalStakedTokens 0x51d18598 → uint256
getTotalStakedTokens 0xcdc87f68 → uint256
nonces 0x7ecebe00 → uint256
owner 0x8da5cb5b → address
stakes 0x584b62a1 → uint256, uint256, uint256
userStakes 0xb5d5b5fa → uint256

Write Contract 8 functions

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

addReward 0x74de4ec4
uint256 amount
claimReward 0x76618f27
uint256 amount
uint256 nonce
bytes signature
renounceOwnership 0x715018a6
No parameters
setLockPeriod 0x779972da
uint256 lockPeriod
setMinStakeAmount 0xeb4af045
uint256 minStakeAmount
stake 0xa694fc3a
uint256 amount
transferOwnership 0xf2fde38b
address newOwner
unstake 0x2e17de78
uint256 stakeId

Recent Transactions

No transactions found for this address