Contract 0x20086fF8EA495A9134F3091b72C3700d687E6A90 1

Contract Overview

Balance:
0 MATIC

Txn Hash Method
Block
From
To
Value [Txn Fee]
Latest 1 internal transaction
Parent Txn Hash Block From To Value
0x00d91d4418422f40be8b8e88a5935593929e386a2a5baec120ddebce80404a33258801432022-04-10 22:00:38125 days 23 hrs ago 0x83ca42fec0fd918308b80a47bf398f346a76fd8e  Contract Creation0 MATIC
[ Download CSV Export 
Loading

Similar Match Source Code
Note: This contract matches the deployed ByteCode of the Source Code for Contract 0x41183f22A83ca02E59b0dACDBcc89E68165e70d2

Contract Name:
StakesAlmond

Compiler Version
v0.8.4+commit.c7e474f2

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, MIT license

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 1 : AlmondFlattened.sol
// SPDX-License-Identifier: MIT

/**

MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMWWWWWWWWWWWWWWWMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMWWNXXKKKKKKKXXXXKKKKKKXXNWWMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMWNXKKKKXXNWWWWMMWWWWMWWWWNXXXKKKXNWMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMWNXKKKXNWMMMMMMMMMNOdxKWMMMMMMMMWNXKKKXNWMMMMMMMMMMMMMM
MMMMMMMMMMMMMWXKKKNWMMMMMMMMMMMMNx:;;l0WMMMMMMMMMMMWNK0KXWMMMMMMMMMMMM
MMMMMMMMMMMWXKKXWMMMMMMMMMMMMMMXd:;;;;cOWMMMMMMMMMMMMMWXKKXWMMMMMMMMMM
MMMMMMMMMWNKKXWMMMMMMMMMMMMMMWKo;;col:;:kNMMMMMMMMMMMMMMWX0KNWMMMMMMMM
MMMMMMMMWX0XWMMMMMMMMMMMMMMMWOl;;oKWXkc;:dXMMMMMMMMMMMMMMMWX0XWMMMMMMM
MMMMMMMNKKNWMMMMMMMMMMMMMMMNkc;:dXMMMWOc;;oKWMMMMMMMMMMMMMMWNKKNMMMMMM
MMMMMMNKKNMMMMMMMMMMMMMMMMNx:;:xNMMMMMW0l;;l0WMMMMMMMWMMMMMMMNKKNMMMMM
MMMMMNKKNMMMMMMMMMMMMMMMMXd:;ckNMMMMMMMMKo:;cOWMMMMXkxkXWMMMMMNKKNMMMM
MMMMWK0NMMMMMMMMMMMMMMMWKo;;l0WMMMMMMMMMMXx:;:xNMMW0lccxXMMMMMMN0KWMMM
MMMMX0XWMMMMMMWWMMMMMMWOl;;oKWMMMMMMMMMMMMNkc;:dXMMNklcoKMMMMMMMX0XMMM
MMMWKKNMMWK0OkkkkkkKWNkc;:dXMMMMMMMMMMMMMMMWOl;;oKWMXdcxNMMMMMMMNKKWMM
MMMN0XWMMWNXX0OdlccdKOc;:xNMMMWXKKXNWNNNNWWMW0o;;l0WNkdKWMMMMMMMWX0NMM
MMMX0XMMMMMMMMMN0dlcdOxoONMMMMW0xdddddodxk0KNWXd:;l0Kx0WMMMMMMMMMX0XMM
MMMX0NMMMMMMMMMMWXxlcoOXWMMMMWKkolclodkKNNNNWWMNxcxOkKWMMMMMMMMMMX0XMM
MMMX0XMMMMMMMMMMMMNklclkNMMWXklccodxdodKWMMMMMMMNKOkKWMMMMMMMMMMMX0XMM
MMMN0XWMMMMMMMMMMMMNOoclxXN0occcdKX0xlco0WMMMMMMNOOXMMMMMMMMMMMMMX0NMM
MMMWKKWMMMMMMMMMMMMMW0dccoxocccdKWMWNklclONMMMMXOONMMMMMMMMMMMMMWKKWMM
MMMMX0XMMMMMMMMMMMMMMWKdcccccco0WMMMMNOoclkNWWKk0NMMMMMMMMMMMMMMX0XWMM
MMMMWKKNMMMMMMMMMMMMMMMXxlcccckNMMMMMMW0oclxK0kKWMMMMMMMMMMMMMMNKKWMMM
MMMMMN0KWMMMMMMMMMMMMMMMNklccoKWMMMMMMMWKdlcoxKWMMMMMMMMMMMMMMWK0NMMMM
MMMMMMN0KWMMMMMMMMMMMMMMMNOod0KXWMMMMMMNK0xoxXWMMMMMMMMMMMMMMWK0NMMMMM
MMMMMMMN0KNMMMMMMMMMMMMMMMWXKkll0WMMMMXdcoOKNMMMMMMMMMMMMMMMNK0NMMMMMM
MMMMMMMMNK0XWMMMMMMMMMMMMMMMNd:;cOWMWKo:;c0WMMMMMMMMMMMMMMWX0KNMMMMMMM
MMMMMMMMMWXKKNWMMMMMMMMMMMMMMXd:;cx0kl;;l0WMMMMMMMMMMMMMWNKKXWMMMMMMMM
MMMMMMMMMMMWX0KNWMMMMMMMMMMMMMNkc;;::;:oKWMMMMMMMMMMMMWNK0XWMMMMMMMMMM
MMMMMMMMMMMMMNXKKXNWMMMMMMMMMMMWOc;;;:dXMMMMMMMMMMMWNXKKXWMMMMMMMMMMMM
MMMMMMMMMMMMMMMWNKKKXNWMMMMMMMMMW0l:ckNMMMMMMMMMWNXKKKNWMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMWNXKKKXXNWWWMMMMX0KWMMMWWWNXXKKKXNWMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMWWNXXKKKKKXXXXXXXXXXKKKKXXNWWMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMWWNNNNNNNNNNNNWWWMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM


---------------------- [ WPSmartContracts.com ] ----------------------

                       [ Blockchain Made Easy ]


    |
    |  Advanced Stakes v.1
    |
    |----------------------------
    |
    |  Flavor
    |
    |  >  Almond: Fully featured ERC-20 Staking contract with maturity 
    |             time an annual interest in a dual token system
    |

*/

pragma solidity ^0.8.2;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */

library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");

        return c;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return sub(a, b, "SafeMath: subtraction overflow");
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        uint256 c = a - b;

        return c;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        // 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 0;
        }

        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");

        return c;
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return div(a, b, "SafeMath: division by zero");
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        // Solidity only automatically asserts when dividing by 0
        require(b > 0, errorMessage);
        uint256 c = a / b;
        // assert(a == b * c + a % b); // There is no case in which this doesn't hold

        return c;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * Reverts when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return mod(a, b, "SafeMath: modulo by zero");
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * Reverts with custom message when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b != 0, errorMessage);
        return a % b;
    }
}

/**
 * @title Owner
 * @dev Set & change owner
 */
contract Owner {

    address private owner;
    
    // event for EVM logging
    event OwnerSet(address indexed oldOwner, address indexed newOwner);
    
    // modifier to check if caller is owner
    modifier isOwner() {
        // If the first argument of 'require' evaluates to 'false', execution terminates and all
        // changes to the state and to Ether balances are reverted.
        // This used to consume all gas in old EVM versions, but not anymore.
        // It is often a good idea to use 'require' to check if functions are called correctly.
        // As a second argument, you can also provide an explanation about what went wrong.
        require(msg.sender == owner, "Caller is not owner");
        _;
    }
    
    /**
     * @dev Set contract deployer as owner
     */
    constructor(address _owner) {
        owner = _owner;
        emit OwnerSet(address(0), owner);
    }

    /**
     * @dev Change owner
     * @param newOwner address of new owner
     */
    function changeOwner(address newOwner) public isOwner {
        emit OwnerSet(owner, newOwner);
        owner = newOwner;
    }

    /**
     * @dev Return owner address 
     * @return address of owner
     */
    function getOwner() public view returns (address) {
        return owner;
    }
}

/**
 * @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;

    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() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

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

        _;

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

// Using consensys implementation of ERC-20, because of decimals

// Abstract contract for the full ERC 20 Token standard
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md

abstract contract EIP20Interface {
    /* This is a slight change to the EIP20 base standard.
    function totalSupply() constant returns (uint256 supply);
    is replaced with:
    uint256 public totalSupply;
    This automatically creates a getter function for the totalSupply.
    This is moved to the base contract since public getter functions are not
    currently recognised as an implementation of the matching abstract
    function by the compiler.
    */
    /// total amount of tokens
    uint256 public totalSupply;

    /// @param _owner The address from which the balance will be retrieved
    /// @return balance The balance
    function balanceOf(address _owner) virtual public view returns (uint256 balance);

    /// @notice send `_value` token to `_to` from `msg.sender`
    /// @param _to The address of the recipient
    /// @param _value The amount of token to be transferred
    /// @return success Whether the transfer was successful or not
    function transfer(address _to, uint256 _value) virtual public returns (bool success);

    /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
    /// @param _from The address of the sender
    /// @param _to The address of the recipient
    /// @param _value The amount of token to be transferred
    /// @return success Whether the transfer was successful or not
    function transferFrom(address _from, address _to, uint256 _value) virtual public returns (bool success);

    /// @notice `msg.sender` approves `_spender` to spend `_value` tokens
    /// @param _spender The address of the account able to transfer the tokens
    /// @param _value The amount of tokens to be approved for transfer
    /// @return success Whether the approval was successful or not
    function approve(address _spender, uint256 _value) virtual public returns (bool success);

    /// @param _owner The address of the account owning tokens
    /// @param _spender The address of the account able to transfer the tokens
    /// @return remaining Amount of remaining tokens allowed to spent
    function allowance(address _owner, address _spender) virtual public view returns (uint256 remaining);

    // solhint-disable-next-line no-simple-event-func-name
    event Transfer(address indexed _from, address indexed _to, uint256 _value);
    event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}

/*
Implements EIP20 token standard: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
*/

contract EIP20 is EIP20Interface {

    uint256 constant private MAX_UINT256 = 2**256 - 1;
    mapping (address => uint256) public balances;
    mapping (address => mapping (address => uint256)) public allowed;
    /*
    NOTE:
    The following variables are OPTIONAL vanities. One does not have to include them.
    They allow one to customise the token contract & in no way influences the core functionality.
    Some wallets/interfaces might not even bother to look at this information.
    */
    string public name;                   //fancy name: eg Simon Bucks
    uint8 public decimals;                //How many decimals to show.
    string public symbol;                 //An identifier: eg SBX

    constructor(
        uint256 _initialAmount,
        string memory _tokenName,
        uint8 _decimalUnits,
        string memory _tokenSymbol
    ) {
        balances[msg.sender] = _initialAmount;               // Give the creator all initial tokens
        totalSupply = _initialAmount;                        // Update total supply
        name = _tokenName;                                   // Set the name for display purposes
        decimals = _decimalUnits;                            // Amount of decimals for display purposes
        symbol = _tokenSymbol;                               // Set the symbol for display purposes
    }

    function transfer(address _to, uint256 _value) override public returns (bool success) {
        require(balances[msg.sender] >= _value);
        balances[msg.sender] -= _value;
        balances[_to] += _value;
        emit Transfer(msg.sender, _to, _value); //solhint-disable-line indent, no-unused-vars
        return true;
    }

    function transferFrom(address _from, address _to, uint256 _value) override public returns (bool success) {
        uint256 the_allowance = allowed[_from][msg.sender];
        require(balances[_from] >= _value && the_allowance >= _value);
        balances[_to] += _value;
        balances[_from] -= _value;
        if (the_allowance < MAX_UINT256) {
            allowed[_from][msg.sender] -= _value;
        }
        emit Transfer(_from, _to, _value); //solhint-disable-line indent, no-unused-vars
        return true;
    }

    function balanceOf(address _owner) override public view returns (uint256 balance) {
        return balances[_owner];
    }

    function approve(address _spender, uint256 _value) override public returns (bool success) {
        allowed[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value); //solhint-disable-line indent, no-unused-vars
        return true;
    }

    function allowance(address _owner, address _spender) override public view returns (uint256 remaining) {
        return allowed[_owner][_spender];
    }
}

/**
 * 
 * Stakes is an interest gain contract for ERC-20 tokens
 * 
 * asset is the EIP20 token to deposit
 * asset2 is the EIP20 token to get interest
 * interest_rate: percentage rate of token1
 * interest_rate2: percentage rate of token2
 * maturity is the time in seconds after which is safe to end the stake
 * penalization for ending a stake before maturity time
 * lower_amount is the minimum amount for creating a stake
 * 
 */
contract StakesAlmond is Owner, ReentrancyGuard {

    using SafeMath for uint256;

    // token to deposit
    EIP20 public asset;

    // token to pay interest
    EIP20 public asset2;

    // stakes history
    struct Record {
        uint256 from;
        uint256 amount;
        uint256 gain;
        uint256 gain2;
        uint256 penalization;
        uint256 to;
        bool ended;
    }

    // contract parameters
    uint8 public interest_rate;
    uint8 public interest_rate2;
    uint256 public maturity;
    uint8 public penalization;
    uint256 public lower_amount;

    // conversion ratio for token1 and token2
    // 1:10 ratio will be: 
    // ratio1 = 1 
    // ratio2 = 10
    uint256 public ratio1;
    uint256 public ratio2;

    mapping(address => Record[]) public ledger;

    event StakeStart(address indexed user, uint256 value, uint256 index);
    event StakeEnd(address indexed user, uint256 value, uint256 penalty, uint256 interest, uint256 index);
    
    constructor(
        EIP20 _erc20, EIP20 _erc20_2, address _owner, uint8 _rate, uint8 _rate2, uint256 _maturity, 
        uint8 _penalization, uint256 _lower, uint256 _ratio1, uint256 _ratio2) Owner(_owner) {
        require(_penalization<=100, "Penalty has to be an integer between 0 and 100");
        asset = _erc20;
        asset2 = _erc20_2;
        ratio1 = _ratio1;
        ratio2 = _ratio2;
        interest_rate = _rate;
        interest_rate2 = _rate2;
        maturity = _maturity;
        penalization = _penalization;
        lower_amount = _lower;
    }
    
    function start(uint256 _value) external {
        require(_value >= lower_amount, "Invalid value");
        asset.transferFrom(msg.sender, address(this), _value);
        ledger[msg.sender].push(Record(block.timestamp, _value, 0, 0, 0, 0, false));
        emit StakeStart(msg.sender, _value, ledger[msg.sender].length-1);
    }

    function end(uint256 i) external nonReentrant {

        require(i < ledger[msg.sender].length, "Invalid index");
        require(ledger[msg.sender][i].ended==false, "Invalid stake");
        
        // penalization
        if(block.timestamp.sub(ledger[msg.sender][i].from) < maturity) {

            uint256 _penalization = ledger[msg.sender][i].amount.mul(penalization).div(100);
            asset.transfer(msg.sender, ledger[msg.sender][i].amount.sub(_penalization));
            asset.transfer(getOwner(), _penalization);
            ledger[msg.sender][i].penalization = _penalization;
            ledger[msg.sender][i].to = block.timestamp;
            ledger[msg.sender][i].ended = true;
            emit StakeEnd(msg.sender, ledger[msg.sender][i].amount, _penalization, 0, i);

        // interest gained
        } else {
            
            // interest is calculated in asset2
            uint256 _interest = get_gains(msg.sender, i);

            // check that the owner can pay interest before trying to pay, token 1
            if (_interest>0 && asset.allowance(getOwner(), address(this)) >= _interest && asset.balanceOf(getOwner()) >= _interest) {
                asset.transferFrom(getOwner(), msg.sender, _interest);
            } else {
                _interest = 0;
            }

            // interest is calculated in asset2
            uint256 _interest2 = get_gains2(msg.sender, i);

            // check that the owner can pay interest before trying to pay, token 1
            if (_interest2>0 && asset2.allowance(getOwner(), address(this)) >= _interest2 && asset2.balanceOf(getOwner()) >= _interest2) {
                asset2.transferFrom(getOwner(), msg.sender, _interest2);
            } else {
                _interest2 = 0;
            }

            // the original asset is returned to the investor
            asset.transfer(msg.sender, ledger[msg.sender][i].amount);
            ledger[msg.sender][i].gain = _interest;
            ledger[msg.sender][i].gain2 = _interest2;
            ledger[msg.sender][i].to = block.timestamp;
            ledger[msg.sender][i].ended = true;
            emit StakeEnd(msg.sender, ledger[msg.sender][i].amount, 0, _interest, i);

        }
    }

    function set(EIP20 _erc20, EIP20 _erc20_2, uint256 _lower, uint256 _maturity, uint8 _rate, uint8 _rate2, uint8 _penalization, uint256 _ratio1, uint256 _ratio2) public isOwner {
        require(_penalization<=100, "Invalid value");
        asset = _erc20;
        asset2 = _erc20_2;
        ratio1 = _ratio1;
        ratio2 = _ratio2;
        lower_amount = _lower;
        maturity = _maturity;
        interest_rate = _rate;
        interest_rate2 = _rate2;
        penalization = _penalization;
    }

    // calculate interest of the token 1 to the current date time
    function get_gains(address _address, uint256 _rec_number) public view returns (uint256) {
        uint256 _record_seconds = block.timestamp.sub(ledger[_address][_rec_number].from);
        uint256 _year_seconds = 365*24*60*60;
        return _record_seconds.mul(
            ledger[_address][_rec_number].amount.mul(interest_rate).div(100)
        ).div(_year_seconds);
    }

    // calculate interest to the current date time
    function get_gains2(address _address, uint256 _rec_number) public view returns (uint256) {
        uint256 _record_seconds = block.timestamp.sub(ledger[_address][_rec_number].from);
        uint256 _year_seconds = 365*24*60*60;
        // now we calculate the value of the transforming the staked asset (asset) into the asset2
        // first we calculate the ratio
        uint256 value_in_asset2 = ledger[_address][_rec_number].amount.mul(ratio2).div(ratio1);
        // now we transform into decimals of the asset2
        value_in_asset2 = value_in_asset2.mul(10**asset2.decimals()).div(10**asset.decimals());
        uint256 interest = _record_seconds.mul(
            value_in_asset2.mul(interest_rate2).div(100)
        ).div(_year_seconds);
        // now lets calculate the interest rate based on the converted value in asset 2
        return interest;
    }

    function ledger_length(address _address) public view 
        returns (uint256) {
        return ledger[_address].length;
    }

}

Settings
{
  "evmVersion": "istanbul",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs",
    "useLiteralContent": true
  },
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "remappings": [],
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "abi"
      ]
    }
  }
}

Contract ABI

[{"inputs":[{"internalType":"contract EIP20","name":"_erc20","type":"address"},{"internalType":"contract EIP20","name":"_erc20_2","type":"address"},{"internalType":"address","name":"_owner","type":"address"},{"internalType":"uint8","name":"_rate","type":"uint8"},{"internalType":"uint8","name":"_rate2","type":"uint8"},{"internalType":"uint256","name":"_maturity","type":"uint256"},{"internalType":"uint8","name":"_penalization","type":"uint8"},{"internalType":"uint256","name":"_lower","type":"uint256"},{"internalType":"uint256","name":"_ratio1","type":"uint256"},{"internalType":"uint256","name":"_ratio2","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"penalty","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"interest","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"}],"name":"StakeEnd","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"}],"name":"StakeStart","type":"event"},{"inputs":[],"name":"asset","outputs":[{"internalType":"contract EIP20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"asset2","outputs":[{"internalType":"contract EIP20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"changeOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"i","type":"uint256"}],"name":"end","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"},{"internalType":"uint256","name":"_rec_number","type":"uint256"}],"name":"get_gains","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"},{"internalType":"uint256","name":"_rec_number","type":"uint256"}],"name":"get_gains2","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"interest_rate","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"interest_rate2","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"ledger","outputs":[{"internalType":"uint256","name":"from","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"gain","type":"uint256"},{"internalType":"uint256","name":"gain2","type":"uint256"},{"internalType":"uint256","name":"penalization","type":"uint256"},{"internalType":"uint256","name":"to","type":"uint256"},{"internalType":"bool","name":"ended","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"ledger_length","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lower_amount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maturity","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"penalization","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ratio1","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ratio2","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract EIP20","name":"_erc20","type":"address"},{"internalType":"contract EIP20","name":"_erc20_2","type":"address"},{"internalType":"uint256","name":"_lower","type":"uint256"},{"internalType":"uint256","name":"_maturity","type":"uint256"},{"internalType":"uint8","name":"_rate","type":"uint8"},{"internalType":"uint8","name":"_rate2","type":"uint8"},{"internalType":"uint8","name":"_penalization","type":"uint8"},{"internalType":"uint256","name":"_ratio1","type":"uint256"},{"internalType":"uint256","name":"_ratio2","type":"uint256"}],"name":"set","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"start","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60806040523480156200001157600080fd5b5060405162001cd538038062001cd5833981016040819052620000349162000191565b600080546001600160a01b0319166001600160a01b038a1690811782556040518a92907f342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a735908290a35060018055606460ff85161115620000f15760405162461bcd60e51b815260206004820152602e60248201527f50656e616c74792068617320746f20626520616e20696e74656765722062657460448201526d07765656e203020616e64203130360941b606482015260840160405180910390fd5b600280546001600160a01b0319166001600160a01b039b8c1617905560038054600793909355600891909155979098166001600160a81b031990981697909717600160a01b60ff958616021760ff60a81b1916600160a81b93851693909302929092179094556004939093556005805460ff19169390911692909217909155506006556200025c565b805160ff811681146200018c57600080fd5b919050565b6000806000806000806000806000806101408b8d031215620001b1578586fd5b8a51620001be8162000243565b60208c0151909a50620001d18162000243565b60408c0151909950620001e48162000243565b9750620001f460608c016200017a565b96506200020460808c016200017a565b955060a08b015194506200021b60c08c016200017a565b935060e08b015192506101008b015191506101208b015190509295989b9194979a5092959850565b6001600160a01b03811681146200025957600080fd5b50565b611a69806200026c6000396000f3fe608060405234801561001057600080fd5b50600436106101165760003560e01c806395805dad116100a2578063b7f8f9ea11610071578063b7f8f9ea1461026e578063cbb3d80814610281578063d36a1b8614610295578063e9423bf2146102a9578063f44c0a64146102bc57600080fd5b806395805dad146102165780639665e82a14610229578063a6f9dae114610232578063aa4c0dd91461024557600080fd5b806338d52e0f116100e957806338d52e0f146101685780634a5064a91461019357806357ca87401461019c57806374f1ca3a146101bb578063893d20e81461020557600080fd5b80630ad245281461011b5780630c98c9c114610130578063204f83f91461014c57806335ddfdcb14610155575b600080fd5b61012e610129366004611813565b6102cf565b005b61013960065481565b6040519081526020015b60405180910390f35b61013960045481565b61012e61016336600461177c565b610f06565b60025461017b906001600160a01b031681565b6040516001600160a01b039091168152602001610143565b61013960085481565b6005546101a99060ff1681565b60405160ff9091168152602001610143565b6101ce6101c9366004611731565b61101c565b604080519788526020880196909652948601939093526060850191909152608084015260a0830152151560c082015260e001610143565b6000546001600160a01b031661017b565b61012e610224366004611813565b611079565b61013960075481565b61012e610240366004611715565b61122f565b610139610253366004611715565b6001600160a01b031660009081526009602052604090205490565b61013961027c366004611731565b6112da565b6003546101a990600160a01b900460ff1681565b6003546101a990600160a81b900460ff1681565b60035461017b906001600160a01b031681565b6101396102ca366004611731565b61139b565b600260015414156103275760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064015b60405180910390fd5b600260015533600090815260096020526040902054811061037a5760405162461bcd60e51b815260206004820152600d60248201526c092dcecc2d8d2c840d2dcc8caf609b1b604482015260640161031e565b3360009081526009602052604090208054829081106103a957634e487b7160e01b600052603260045260246000fd5b600091825260209091206006600790920201015460ff16156103fd5760405162461bcd60e51b815260206004820152600d60248201526c496e76616c6964207374616b6560981b604482015260640161031e565b600454336000908152600960205260409020805461044c91908490811061043457634e487b7160e01b600052603260045260246000fd5b600091825260209091206007909102015442906115a3565b10156107f057600554336000908152600960205260408120805491926104bb926064926104b59260ff16918790811061049557634e487b7160e01b600052603260045260246000fd5b9060005260206000209060070201600101546115ec90919063ffffffff16565b9061166b565b60025433600081815260096020526040902080549394506001600160a01b039092169263a9059cbb92610529918691908890811061050957634e487b7160e01b600052603260045260246000fd5b9060005260206000209060070201600101546115a390919063ffffffff16565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401602060405180830381600087803b15801561056f57600080fd5b505af1158015610583573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105a7919061175c565b506002546001600160a01b031663a9059cbb6105cb6000546001600160a01b031690565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101849052604401602060405180830381600087803b15801561061357600080fd5b505af1158015610627573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061064b919061175c565b5033600090815260096020526040902080548291908490811061067e57634e487b7160e01b600052603260045260246000fd5b9060005260206000209060070201600401819055504260096000336001600160a01b03166001600160a01b0316815260200190815260200160002083815481106106d857634e487b7160e01b600052603260045260246000fd5b906000526020600020906007020160050181905550600160096000336001600160a01b03166001600160a01b03168152602001908152602001600020838154811061073357634e487b7160e01b600052603260045260246000fd5b60009182526020808320600792909202909101600601805460ff1916931515939093179092553380825260099092526040902080547f1deb31f039e2645a4e97af07659090228d39e7f992bfaf37af3838ad9665e23a9190859081106107a957634e487b7160e01b600052603260045260246000fd5b600091825260208220600160079092020101546040516107e2928691889093845260208401929092526040830152606082015260800190565b60405180910390a250610eff565b60006107fc33836112da565b90506000811180156108ae575060025481906001600160a01b031663dd62ed3e61082e6000546001600160a01b031690565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015230602482015260440160206040518083038186803b15801561087357600080fd5b505afa158015610887573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108ab919061182b565b10155b8015610954575060025481906001600160a01b03166370a082316108da6000546001600160a01b031690565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260240160206040518083038186803b15801561091957600080fd5b505afa15801561092d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610951919061182b565b10155b15610a08576002546001600160a01b03166323b872dd61097c6000546001600160a01b031690565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015233602482015260448101849052606401602060405180830381600087803b1580156109ca57600080fd5b505af11580156109de573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a02919061175c565b50610a0c565b5060005b6000610a18338461139b565b9050600081118015610aca575060035481906001600160a01b031663dd62ed3e610a4a6000546001600160a01b031690565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015230602482015260440160206040518083038186803b158015610a8f57600080fd5b505afa158015610aa3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ac7919061182b565b10155b8015610b70575060035481906001600160a01b03166370a08231610af66000546001600160a01b031690565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260240160206040518083038186803b158015610b3557600080fd5b505afa158015610b49573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b6d919061182b565b10155b15610c24576003546001600160a01b03166323b872dd610b986000546001600160a01b031690565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015233602482015260448101849052606401602060405180830381600087803b158015610be657600080fd5b505af1158015610bfa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1e919061175c565b50610c28565b5060005b60025433600081815260096020526040902080546001600160a01b039093169263a9059cbb92919087908110610c6e57634e487b7160e01b600052603260045260246000fd5b60009182526020909120600160079092020101546040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401602060405180830381600087803b158015610cc857600080fd5b505af1158015610cdc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d00919061175c565b50336000908152600960205260409020805483919085908110610d3357634e487b7160e01b600052603260045260246000fd5b9060005260206000209060070201600201819055508060096000336001600160a01b03166001600160a01b031681526020019081526020016000208481548110610d8d57634e487b7160e01b600052603260045260246000fd5b9060005260206000209060070201600301819055504260096000336001600160a01b03166001600160a01b031681526020019081526020016000208481548110610de757634e487b7160e01b600052603260045260246000fd5b906000526020600020906007020160050181905550600160096000336001600160a01b03166001600160a01b031681526020019081526020016000208481548110610e4257634e487b7160e01b600052603260045260246000fd5b60009182526020808320600792909202909101600601805460ff1916931515939093179092553380825260099092526040902080547f1deb31f039e2645a4e97af07659090228d39e7f992bfaf37af3838ad9665e23a919086908110610eb857634e487b7160e01b600052603260045260246000fd5b90600052602060002090600702016001015460008587604051610ef4949392919093845260208401929092526040830152606082015260800190565b60405180910390a250505b5060018055565b6000546001600160a01b03163314610f565760405162461bcd60e51b815260206004820152601360248201527221b0b63632b91034b9903737ba1037bbb732b960691b604482015260640161031e565b60648360ff161115610f9a5760405162461bcd60e51b815260206004820152600d60248201526c496e76616c69642076616c756560981b604482015260640161031e565b600280546001600160a01b0319166001600160a01b039a8b1617905560038054600793909355600891909155600696909655600494909455949095166001600160a81b031990921691909117600160a01b60ff928316021760ff60a81b1916600160a81b948216949094029390931790556005805460ff191691909216179055565b6009602052816000526040600020818154811061103857600080fd5b600091825260209091206007909102018054600182015460028301546003840154600485015460058601546006909601549497509295509093909260ff1687565b6006548110156110bb5760405162461bcd60e51b815260206004820152600d60248201526c496e76616c69642076616c756560981b604482015260640161031e565b6002546040516323b872dd60e01b8152336004820152306024820152604481018390526001600160a01b03909116906323b872dd90606401602060405180830381600087803b15801561110d57600080fd5b505af1158015611121573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611145919061175c565b50336000818152600960208181526040808420815160e081018352428152808401888152928101868152606082018781526080830188815260a0840189815260c085018a8152865460018082018955888d528a8d20975160079092029097019081559751888701559351600288015591516003870155516004860155516005850155516006909301805460ff1916931515939093179092559385905291905290547f01030a23696d25d6138e45b2944d465c807d48422a2700ae29527f92b6cb439c91849161121491906119df565b6040805192835260208301919091520160405180910390a250565b6000546001600160a01b0316331461127f5760405162461bcd60e51b815260206004820152601360248201527221b0b63632b91034b9903737ba1037bbb732b960691b604482015260640161031e565b600080546040516001600160a01b03808516939216917f342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a73591a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b038216600090815260096020526040812080548291611318918590811061043457634e487b7160e01b600052603260045260246000fd5b905060006301e133809050611390816104b561138960646104b5600360149054906101000a900460ff1660ff16600960008d6001600160a01b03166001600160a01b031681526020019081526020016000208b8154811061049557634e487b7160e01b600052603260045260246000fd5b85906115ec565b925050505b92915050565b6001600160a01b0382166000908152600960205260408120805482916113d9918590811061043457634e487b7160e01b600052603260045260246000fd5b905060006301e13380905060006114366007546104b5600854600960008b6001600160a01b03166001600160a01b03168152602001908152602001600020898154811061049557634e487b7160e01b600052603260045260246000fd5b905061155c600260009054906101000a90046001600160a01b03166001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b15801561148957600080fd5b505afa15801561149d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114c19190611843565b6114cc90600a611915565b6003546040805163313ce56760e01b815290516104b5926001600160a01b03169163313ce567916004808301926020929190829003018186803b15801561151257600080fd5b505afa158015611526573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061154a9190611843565b61155590600a611915565b84906115ec565b90506000611598836104b561159160646104b5600360159054906101000a900460ff1660ff16886115ec90919063ffffffff16565b87906115ec565b979650505050505050565b60006115e583836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506116ad565b9392505050565b6000826115fb57506000611395565b600061160783856119c0565b90508261161485836118b2565b146115e55760405162461bcd60e51b815260206004820152602160248201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6044820152607760f81b606482015260840161031e565b60006115e583836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f0000000000008152506116e7565b600081848411156116d15760405162461bcd60e51b815260040161031e919061185f565b5060006116de84866119df565b95945050505050565b600081836117085760405162461bcd60e51b815260040161031e919061185f565b5060006116de84866118b2565b600060208284031215611726578081fd5b81356115e581611a0c565b60008060408385031215611743578081fd5b823561174e81611a0c565b946020939093013593505050565b60006020828403121561176d578081fd5b815180151581146115e5578182fd5b60008060008060008060008060006101208a8c03121561179a578485fd5b89356117a581611a0c565b985060208a01356117b581611a0c565b975060408a0135965060608a0135955060808a01356117d381611a24565b945060a08a01356117e381611a24565b935060c08a01356117f381611a24565b8093505060e08a013591506101008a013590509295985092959850929598565b600060208284031215611824578081fd5b5035919050565b60006020828403121561183c578081fd5b5051919050565b600060208284031215611854578081fd5b81516115e581611a24565b6000602080835283518082850152825b8181101561188b5785810183015185820160400152820161186f565b8181111561189c5783604083870101525b50601f01601f1916929092016040019392505050565b6000826118cd57634e487b7160e01b81526012600452602481fd5b500490565b600181815b8085111561190d5781600019048211156118f3576118f36119f6565b8085161561190057918102915b93841c93908002906118d7565b509250929050565b60006115e560ff84168360008261192e57506001611395565b8161193b57506000611395565b8160018114611951576002811461195b57611977565b6001915050611395565b60ff84111561196c5761196c6119f6565b50506001821b611395565b5060208310610133831016604e8410600b841016171561199a575081810a611395565b6119a483836118d2565b80600019048211156119b8576119b86119f6565b029392505050565b60008160001904831182151516156119da576119da6119f6565b500290565b6000828210156119f1576119f16119f6565b500390565b634e487b7160e01b600052601160045260246000fd5b6001600160a01b0381168114611a2157600080fd5b50565b60ff81168114611a2157600080fdfea2646970667358221220b639b7975cbeebf42903f5bfa77f0fde434592a45a45a2f2d5ba18ce069d14b964736f6c63430008040033000000000000000000000000e4379a25a0db888e19ec2c14416fe68a62aca5cc000000000000000000000000e4379a25a0db888e19ec2c14416fe68a62aca5cc000000000000000000000000e4379a25a0db888e19ec2c14416fe68a62aca5cc0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000007

Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading