Contract 0xE8061a74412E78Dda7A762b8f6361518BB9783D3

 
 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0x40b4f59aa285e7f64df4a7d2dcd97e37bec15049ca2a0752a258bccfd38625e70x60a0604084842202021-06-21 7:47:3999 days 18 hrs agoTranchess: Deployer IN  Contract Creation0 BNB0.00396821
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
InterestRateBallot

Compiler Version
v0.6.12+commit.27d51765

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 4 : InterestRateBallot.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.10 <0.8.0;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "../interfaces/IBallot.sol";
import "../interfaces/IVotingEscrow.sol";

contract InterestRateBallot is IBallot {
    using SafeMath for uint256;

    uint256 public immutable maxTime;

    uint256 public stepSize = 0.02e18;
    uint256 public minRange = 0;
    uint256 public maxOption = 3;

    IVotingEscrow public votingEscrow;

    mapping(address => Voter) public voters;

    // unlockTime => amount that will be unlocked at unlockTime
    mapping(uint256 => uint256) public scheduledUnlock;
    mapping(uint256 => uint256) public scheduledWeightedUnlock;

    constructor(address votingEscrow_) public {
        votingEscrow = IVotingEscrow(votingEscrow_);
        maxTime = votingEscrow.maxTime();
    }

    function getWeight(uint256 index) public view returns (uint256) {
        uint256 delta = stepSize.mul(index);
        return minRange.add(delta);
    }

    function getReceipt(address account) external view returns (Voter memory) {
        return voters[account];
    }

    function balanceOf(address account) external view returns (uint256) {
        return _balanceOfAtTimestamp(account, block.timestamp);
    }

    function totalSupply() external view returns (uint256) {
        return _totalSupplyAtTimestamp(block.timestamp);
    }

    function balanceOfAtTimestamp(address account, uint256 timestamp)
        external
        view
        returns (uint256)
    {
        return _balanceOfAtTimestamp(account, timestamp);
    }

    function totalSupplyAtTimestamp(uint256 timestamp) external view returns (uint256) {
        return _totalSupplyAtTimestamp(timestamp);
    }

    function sumAtTimestamp(uint256 timestamp) external view returns (uint256) {
        return _sumAtTimestamp(timestamp);
    }

    function count(uint256 timestamp) external view override returns (uint256) {
        return _averageAtTimestamp(timestamp);
    }

    function cast(uint256 option) external {
        require(option < maxOption, "Invalid option");

        IVotingEscrow.LockedBalance memory lockedBalance =
            votingEscrow.getLockedBalance(msg.sender);
        Voter memory voter = voters[msg.sender];
        uint256 weight = getWeight(option);
        require(lockedBalance.amount > 0, "Zero value");

        // update scheduled unlock
        scheduledUnlock[voter.unlockTime] -= voter.amount;
        scheduledUnlock[lockedBalance.unlockTime] += lockedBalance.amount;

        scheduledWeightedUnlock[voter.unlockTime] -= voter.amount * voter.weight;
        scheduledWeightedUnlock[lockedBalance.unlockTime] += lockedBalance.amount * weight;

        emit Voted(
            msg.sender,
            voter.amount,
            voter.unlockTime,
            voter.weight,
            lockedBalance.amount,
            lockedBalance.unlockTime,
            weight
        );

        // update voter amount per account
        voters[msg.sender] = Voter({
            amount: lockedBalance.amount,
            unlockTime: lockedBalance.unlockTime,
            weight: weight
        });
    }

    function _balanceOfAtTimestamp(address account, uint256 timestamp)
        private
        view
        returns (uint256)
    {
        require(timestamp >= block.timestamp, "Must be current or future time");
        Voter memory voter = voters[account];
        if (timestamp > voter.unlockTime) {
            return 0;
        }
        return (voter.amount * (voter.unlockTime - timestamp)) / maxTime;
    }

    function _totalSupplyAtTimestamp(uint256 timestamp) private view returns (uint256) {
        uint256 total = 0;
        for (
            uint256 weekCursor = (timestamp / 1 weeks) * 1 weeks + 1 weeks;
            weekCursor <= timestamp + maxTime;
            weekCursor += 1 weeks
        ) {
            total += (scheduledUnlock[weekCursor] * (weekCursor - timestamp)) / maxTime;
        }

        return total;
    }

    function _sumAtTimestamp(uint256 timestamp) private view returns (uint256) {
        uint256 sum = 0;
        for (
            uint256 weekCursor = (timestamp / 1 weeks) * 1 weeks + 1 weeks;
            weekCursor <= timestamp + maxTime;
            weekCursor += 1 weeks
        ) {
            sum += (scheduledWeightedUnlock[weekCursor] * (weekCursor - timestamp)) / maxTime;
        }

        return sum;
    }

    function _averageAtTimestamp(uint256 timestamp) private view returns (uint256) {
        uint256 sum = 0;
        uint256 total = 0;
        for (
            uint256 weekCursor = (timestamp / 1 weeks) * 1 weeks + 1 weeks;
            weekCursor <= timestamp + maxTime;
            weekCursor += 1 weeks
        ) {
            sum += (scheduledWeightedUnlock[weekCursor] * (weekCursor - timestamp)) / maxTime;
            total += (scheduledUnlock[weekCursor] * (weekCursor - timestamp)) / maxTime;
        }

        if (total == 0) {
            return getWeight(maxOption.sub(1) / 2);
        }
        return sum / total;
    }
}

File 2 of 4 : SafeMath.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

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

File 3 of 4 : IBallot.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.10 <0.8.0;

interface IBallot {
    struct Voter {
        uint256 amount;
        uint256 unlockTime;
        uint256 weight;
    }

    function count(uint256 timestamp) external view returns (uint256);

    // An event emitted when a new proposal is created
    event Voted(
        address indexed account,
        uint256 oldAmount,
        uint256 oldUnlockTime,
        uint256 oldWeight,
        uint256 amount,
        uint256 indexed unlockTime,
        uint256 indexed weight
    );
}

File 4 of 4 : IVotingEscrow.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.10 <0.8.0;
pragma experimental ABIEncoderV2;

interface IVotingEscrow {
    struct LockedBalance {
        uint256 amount;
        uint256 unlockTime;
    }

    function token() external view returns (address);

    function maxTime() external view returns (uint256);

    function balanceOf(address account) external view returns (uint256);

    function totalSupply() external view returns (uint256);

    function balanceOfAtTimestamp(address account, uint256 timestamp)
        external
        view
        returns (uint256);

    function getTimestampDropBelow(address account, uint256 threshold)
        external
        view
        returns (uint256);

    function getLockedBalance(address account) external view returns (LockedBalance memory);
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"votingEscrow_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"oldAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"oldUnlockTime","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"oldWeight","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"unlockTime","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"weight","type":"uint256"}],"name":"Voted","type":"event"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"balanceOfAtTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"option","type":"uint256"}],"name":"cast","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"count","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getReceipt","outputs":[{"components":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"unlockTime","type":"uint256"},{"internalType":"uint256","name":"weight","type":"uint256"}],"internalType":"struct IBallot.Voter","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getWeight","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxOption","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minRange","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"scheduledUnlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"scheduledWeightedUnlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stepSize","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"sumAtTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"totalSupplyAtTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"voters","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"unlockTime","type":"uint256"},{"internalType":"uint256","name":"weight","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"votingEscrow","outputs":[{"internalType":"contract IVotingEscrow","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

60a060405266470de4df8200006000556000600155600360025534801561002557600080fd5b50604051610d9b380380610d9b833981016040819052610044916100e1565b600380546001600160a01b0319166001600160a01b038381169190911791829055604080516322e67e7160e01b8152905192909116916322e67e7191600480820192602092909190829003018186803b1580156100a057600080fd5b505afa1580156100b4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100d8919061010f565b60805250610127565b6000602082840312156100f2578081fd5b81516001600160a01b0381168114610108578182fd5b9392505050565b600060208284031215610120578081fd5b5051919050565b608051610c32610169600039806102b252806105be52806105f65280610649528061068152806106b352806107c8528061086a52806108a25250610c326000f3fe608060405234801561001057600080fd5b506004361061010b5760003560e01c8063690733d6116100a2578063a3ec138d11610071578063a3ec138d146101ef578063a5f065c214610211578063bba8124914610224578063d851fdfd1461022c578063de4e211b1461023f5761010b565b8063690733d6146101a15780636e80ef28146101b457806370a08231146101c7578063738198b4146101da5761010b565b80633b3546c8116100de5780633b3546c81461015e5780634f2ba10c146101715780634f2bfe5b146101845780635ac87f0b146101995761010b565b806304562d951461011057806318160ddd1461013957806322e67e711461014e57806336ebafe914610156575b600080fd5b61012361011e366004610998565b610252565b6040516101309190610ba1565b60405180910390f35b6101416102a0565b6040516101309190610bc2565b6101416102b0565b6101416102d4565b61014161016c366004610a27565b6102da565b61014161017f3660046109b3565b6102eb565b61018c6102fe565b6040516101309190610a3f565b61014161030d565b6101416101af366004610a27565b610313565b6101416101c2366004610a27565b610325565b6101416101d5366004610998565b610337565b6101ed6101e8366004610a27565b610343565b005b6102026101fd366004610998565b610551565b60405161013093929190610bcb565b61014161021f366004610a27565b610572565b61014161057d565b61014161023a366004610a27565b610583565b61014161024d366004610a27565b6105a3565b61025a610946565b506001600160a01b03811660009081526004602090815260409182902082516060810184528154815260018201549281019290925260020154918101919091525b919050565b60006102ab426105ae565b905090565b7f000000000000000000000000000000000000000000000000000000000000000081565b60005481565b60006102e582610638565b92915050565b60006102f7838361074a565b9392505050565b6003546001600160a01b031681565b60025481565b60066020526000908152604090205481565b60056020526000908152604090205481565b60006102e5824261074a565b600254811061036d5760405162461bcd60e51b815260040161036490610add565b60405180910390fd5b610375610967565b60035460405163c408689360e01b81526001600160a01b039091169063c4086893906103a5903390600401610a3f565b604080518083038186803b1580156103bc57600080fd5b505afa1580156103d0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103f491906109dd565b90506103fe610946565b5033600090815260046020908152604080832081516060810183528154815260018201549381019390935260020154908201529061043b84610583565b835190915061045c5760405162461bcd60e51b815260040161036490610b46565b815160208084018051600090815260058352604080822080549590950390945586518784018051835285832080549092019091558487018051885185518552600690965286842080549690910290950390945587518151835291859020805492870290920190915551855191519251875194518695929433947f93ca33695a65edef4edddc066bf24257e1751d77915dcafa3c7417e0d6e768fa94610502949193610be1565b60405180910390a4604080516060810182528451815260209485015185820190815281830193845233600090815260049096529190942093518455516001840155516002909201919091555050565b60046020526000908152604090208054600182015460029092015490919083565b60006102e5826105ae565b60015481565b60008054819061059390846107fb565b6001549091506102f79082610835565b60006102e58261085a565b60008062093a808084048102015b7f000000000000000000000000000000000000000000000000000000000000000084018111610631576000818152600560205260409020547f000000000000000000000000000000000000000000000000000000000000000090858303028161062157fe5b04919091019062093a80016105bc565b5092915050565b6000808062093a808085048102015b7f000000000000000000000000000000000000000000000000000000000000000085018111610701576000818152600660205260409020547f00000000000000000000000000000000000000000000000000000000000000009086830302816106ac57fe5b04830192507f0000000000000000000000000000000000000000000000000000000000000000858203600560008481526020019081526020016000205402816106f157fe5b04919091019062093a8001610647565b50806107385761072f600261072260016002546108dd90919063ffffffff16565b8161072957fe5b04610583565b9250505061029b565b80828161074157fe5b04949350505050565b60004282101561076c5760405162461bcd60e51b815260040161036490610b6a565b610774610946565b506001600160a01b0383166000908152600460209081526040918290208251606081018452815481526001820154928101839052600290910154928101929092528311156107c65760009150506102e5565b7f0000000000000000000000000000000000000000000000000000000000000000838260200151038260000151028161074157fe5b60008261080a575060006102e5565b8282028284828161081757fe5b04146102f75760405162461bcd60e51b815260040161036490610b05565b6000828201838110156102f75760405162461bcd60e51b815260040161036490610aa6565b60008062093a808084048102015b7f000000000000000000000000000000000000000000000000000000000000000084018111610631576000818152600660205260409020547f00000000000000000000000000000000000000000000000000000000000000009085830302816108cd57fe5b04919091019062093a8001610868565b60006102f783836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506000818484111561093e5760405162461bcd60e51b81526004016103649190610a53565b505050900390565b60405180606001604052806000815260200160008152602001600081525090565b604051806040016040528060008152602001600081525090565b80356001600160a01b03811681146102e557600080fd5b6000602082840312156109a9578081fd5b6102f78383610981565b600080604083850312156109c5578081fd5b6109cf8484610981565b946020939093013593505050565b6000604082840312156109ee578081fd5b6040516040810181811067ffffffffffffffff82111715610a0d578283fd5b604052825181526020928301519281019290925250919050565b600060208284031215610a38578081fd5b5035919050565b6001600160a01b0391909116815260200190565b6000602080835283518082850152825b81811015610a7f57858101830151858201604001528201610a63565b81811115610a905783604083870101525b50601f01601f1916929092016040019392505050565b6020808252601b908201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604082015260600190565b6020808252600e908201526d24b73b30b634b21037b83a34b7b760911b604082015260600190565b60208082526021908201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6040820152607760f81b606082015260800190565b6020808252600a90820152695a65726f2076616c756560b01b604082015260600190565b6020808252601e908201527f4d7573742062652063757272656e74206f72206675747572652074696d650000604082015260600190565b81518152602080830151908201526040918201519181019190915260600190565b90815260200190565b9283526020830191909152604082015260600190565b9384526020840192909252604083015260608201526080019056fea26469706673582212203aa5e9b3155185a8136037543004efb5f9d2e903b74ecf9d340984a448d2e0cb64736f6c634300060c0033000000000000000000000000c11f14da5e998be1010c06f9d92574c2e88672c1

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000c11f14da5e998be1010c06f9d92574c2e88672c1

-----Decoded View---------------
Arg [0] : votingEscrow_ (address): 0xc11f14da5e998be1010c06f9d92574c2e88672c1

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000c11f14da5e998be1010c06f9d92574c2e88672c1


Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.