Cryo Explorer Ethereum Mainnet

Address Contract Partially Verified

Address 0xbaFFeb35357316c8256e0cF534c9258C2a55A130
Balance 0 ETH
Nonce 1
Code Size 8279 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

8279 bytes
0x608060405234801561001057600080fd5b50600436106100ea5760003560e01c8063894e9a0d1161008c578063985bb2b411610066578063985bb2b41461025d578063a82ccd4d14610286578063cc1b4bf6146102a3578063f2fde38b146102e3576100ea565b8063894e9a0d146101dd5780638da5cb5b1461024d5780638f32d59b14610255576100ea565b80633656eec2116100c85780633656eec2146101555780636db9241b14610181578063715018a6146101b25780637a9b2c6c146101ba576100ea565b80630c56ae3b146100ef5780631e99d569146101135780633028f63a1461012d575b600080fd5b6100f7610309565b604080516001600160a01b039092168252519081900360200190f35b61011b610318565b60408051918252519081900360200190f35b6101536004803603602081101561014357600080fd5b50356001600160a01b031661031e565b005b61011b6004803603604081101561016b57600080fd5b50803590602001356001600160a01b0316610387565b61019e6004803603602081101561019757600080fd5b503561066d565b604080519115158252519081900360200190f35b610153610984565b61019e600480360360408110156101d057600080fd5b5080359060200135610a15565b6101fa600480360360208110156101f357600080fd5b5035610da8565b604080516001600160a01b03998a168152978916602089015287810196909652939096166060860152608085019190915260a084015260c083019390935260e08201929092529051908190036101000190f35b6100f7610e7c565b61019e610e8b565b61019e6004803603606081101561027357600080fd5b5080359060208101359060400135610e9c565b61011b6004803603602081101561029c57600080fd5b50356112eb565b61011b600480360360a08110156102b957600080fd5b506001600160a01b0381358116916020810135916040820135169060608101359060800135611426565b610153600480360360208110156102f957600080fd5b50356001600160a01b03166119f5565b6004546001600160a01b031681565b60025481565b610326610e8b565b610365576040805162461bcd60e51b81526020600482018190526024820152600080516020611f56833981519152604482015290519081900360640190fd5b600480546001600160a01b0319166001600160a01b0392909216919091179055565b6000828152600360205260408120600701548390600160a01b900460ff166103ee576040805162461bcd60e51b81526020600482015260156024820152741cdd1c99585b48191bd95cc81b9bdd08195e1a5cdd605a1b604482015290519081900360640190fd5b6103f6611e14565b50600084815260036020818152604092839020835161012081018552815481526001820154928101929092526002810154938201939093529082015460608201526004820154608082015260058201546001600160a01b0390811660a08301526006830154811660c083015260079092015491821660e0820152600160a01b90910460ff16151561010082015261048b611e7d565b6000610496876112eb565b90506104a6818460200151611a48565b60208401819052838260038111156104ba57fe5b60038111156104c557fe5b90525060009050825160038111156104d957fe5b146105155760405162461bcd60e51b8152600401808060200182810382526023815260200180611f766023913960400191505060405180910390fd5b6040830151835111156105ba5761053483600001518460400151611a8a565b604084018190528382600381111561054857fe5b600381111561055357fe5b905250600090508251600381111561056757fe5b1461056e57fe5b61058082602001518360400151611a8a565b602084018190528382600381111561059457fe5b600381111561059f57fe5b90525060009050825160038111156105b357fe5b146105ba57fe5b8260a001516001600160a01b0316866001600160a01b031614156105e657506020015192506106669050565b8260c001516001600160a01b0316866001600160a01b0316141561065e5761061683604001518360200151611a8a565b606084018190528382600381111561062a57fe5b600381111561063557fe5b905250600090508251600381111561064957fe5b1461065057fe5b506060015192506106669050565b600094505050505b5092915050565b60008054600101808255828252600360205260408220600701548390600160a01b900460ff166106dc576040805162461bcd60e51b81526020600482015260156024820152741cdd1c99585b48191bd95cc81b9bdd08195e1a5cdd605a1b604482015290519081900360640190fd5b60008481526003602052604090206006015484906001600160a01b031633148061071f57506000818152600360205260409020600501546001600160a01b031633145b61075a5760405162461bcd60e51b8152600401808060200182810382526037815260200180611f996037913960400191505060405180910390fd5b610762611e14565b506000858152600360208181526040808420815161012081018352815481526001820154938101939093526002810154918301919091529182015460608201526004820154608082015260058201546001600160a01b0390811660a08301526006830154811660c0830181905260079093015490811660e0830152600160a01b900460ff16151561010082015291906107fc908890610387565b9050600061080e888460a00151610387565b60008981526003602081905260408220828155600181018390556002810183905590810182905560048101919091556005810180546001600160a01b0319908116909155600682018054909116905560070180546001600160a81b031916905560e0840151909150811561089c5760a084015161089c906001600160a01b038316908463ffffffff611aad16565b82156108c25760c08401516108c2906001600160a01b038316908563ffffffff611aad16565b8360a001516001600160a01b03168460c001516001600160a01b03168a7fca3e6079b726e7728802a0537949e2d1c7762304fa641fb06eb56daf2ba8c6b98686604051808381526020018281526020019250505060405180910390a460019750505050505050600054811461097e576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b50919050565b61098c610e8b565b6109cb576040805162461bcd60e51b81526020600482018190526024820152600080516020611f56833981519152604482015290519081900360640190fd5b6001546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600180546001600160a01b0319169055565b60008054600101808255838252600360205260408220600701548490600160a01b900460ff16610a84576040805162461bcd60e51b81526020600482015260156024820152741cdd1c99585b48191bd95cc81b9bdd08195e1a5cdd605a1b604482015290519081900360640190fd5b60008581526003602052604090206006015485906001600160a01b0316331480610ac757506000818152600360205260409020600501546001600160a01b031633145b610b025760405162461bcd60e51b8152600401808060200182810382526037815260200180611f996037913960400191505060405180910390fd5b60008511610b48576040805162461bcd60e51b815260206004820152600e60248201526d616d6f756e74206973207a65726f60901b604482015290519081900360640190fd5b610b50611e14565b506000868152600360208181526040808420815161012081018352815481526001820154938101939093526002810154918301919091529182015460608201526004820154608082015260058201546001600160a01b0390811660a083018190526006840154821660c084015260079093015490811660e0830152600160a01b900460ff1615156101008201529190610bea908990610387565b905086811015610c2b5760405162461bcd60e51b8152600401808060200182810382526024815260200180611eef6024913960400191505060405180910390fd5b6000610c3b836040015189611a8a565b60008b815260036020526040812060020191909155909150816003811115610c5f57fe5b14610c6657fe5b600089815260036020526040902060020154610cdd5760008981526003602081905260408220828155600181018390556002810183905590810182905560048101919091556005810180546001600160a01b0319908116909155600682018054909116905560070180546001600160a81b03191690555b610d038360a00151898560e001516001600160a01b0316611aad9092919063ffffffff16565b8260a001516001600160a01b0316897f36c3ab437e6a424ed25dc4bfdeb62706aa06558660fab2dab229d2555adaf89c8a6040518082815260200191505060405180910390a36001965050505050506000548114610666576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b600080600080600080600080886003600082815260200190815260200160002060070160149054906101000a900460ff16610e22576040805162461bcd60e51b81526020600482015260156024820152741cdd1c99585b48191bd95cc81b9bdd08195e1a5cdd605a1b604482015290519081900360640190fd5b50505060009687525050600360208190526040909520600681015460058201548254600784015498840154600485015460028601546001909601546001600160a01b039586169c9486169b939a5094909216975095509350565b6001546001600160a01b031690565b6001546001600160a01b0316331490565b60008054600101808255848252600360205260408220600701548590600160a01b900460ff16610f0b576040805162461bcd60e51b81526020600482015260156024820152741cdd1c99585b48191bd95cc81b9bdd08195e1a5cdd605a1b604482015290519081900360640190fd5b60008681526003602052604090206005015486906001600160a01b03163314610f655760405162461bcd60e51b8152600401808060200182810382526029815260200180611ffa6029913960400191505060405180910390fd5b60008611610fab576040805162461bcd60e51b815260206004820152600e60248201526d616d6f756e74206973207a65726f60901b604482015290519081900360640190fd5b610fb3611e14565b506000878152600360208181526040808420815161012081018352815481526001820154938101939093526002810154918301919091529182015460608201526004820154608082015260058201546001600160a01b0390811660a083018190526006840154821660c084015260079093015490811660e0830152600160a01b900460ff161515610100820152919061104d908a90610387565b90508781101561108e5760405162461bcd60e51b8152600401808060200182810382526024815260200180611eef6024913960400191505060405180910390fd5b600061109e83604001518a611a8a565b60008c8152600360205260408120600201919091559091508160038111156110c257fe5b146110c957fe5b60008a8152600360205260409020600201546111405760008a81526003602081905260408220828155600181018390556002810183905590810182905560048101919091556005810180546001600160a01b0319908116909155600682018054909116905560070180546001600160a81b03191690555b60e0830151600480546040805163095ea7b360e01b81526001600160a01b0392831693810193909352602483018d90525192169163095ea7b3916044808201926020929091908290030181600087803b15801561119c57600080fd5b505af11580156111b0573d6000803e3d6000fd5b505050506040513d60208110156111c657600080fd5b50506004805460a085015160408051638dbdbe6d60e01b81529384018d9052602484018c90526001600160a01b03918216604485015251911691638dbdbe6d91606480830192600092919082900301818387803b15801561122657600080fd5b505af115801561123a573d6000803e3d6000fd5b505050508260a001516001600160a01b03168a7f36c3ab437e6a424ed25dc4bfdeb62706aa06558660fab2dab229d2555adaf89c8b6040518082815260200191505060405180910390a360019650505050505060005481146112e3576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b509392505050565b6000818152600360205260408120600701548290600160a01b900460ff16611352576040805162461bcd60e51b81526020600482015260156024820152741cdd1c99585b48191bd95cc81b9bdd08195e1a5cdd605a1b604482015290519081900360640190fd5b61135a611e14565b506000838152600360208181526040928390208351610120810185528154815260018201549281019290925260028101549382019390935290820154606082018190526004830154608083015260058301546001600160a01b0390811660a08401526006840154811660c084015260079093015492831660e0830152600160a01b90920460ff1615156101008201529042116113fa57600092505061097e565b806080015142101561141357606001514203915061097e565b6060810151608090910151039392505050565b6000611430610e8b565b61146f576040805162461bcd60e51b81526020600482018190526024820152600080516020611f56833981519152604482015290519081900360640190fd5b6001600160a01b0386166114ca576040805162461bcd60e51b815260206004820152601a60248201527f73747265616d20746f20746865207a65726f2061646472657373000000000000604482015290519081900360640190fd5b6001600160a01b038616301415611528576040805162461bcd60e51b815260206004820152601d60248201527f73747265616d20746f2074686520636f6e747261637420697473656c66000000604482015290519081900360640190fd5b6001600160a01b03861633141561157d576040805162461bcd60e51b815260206004820152601460248201527339ba3932b0b6903a37903a34329031b0b63632b960611b604482015290519081900360640190fd5b600085116115c4576040805162461bcd60e51b815260206004820152600f60248201526e6465706f736974206973207a65726f60881b604482015290519081900360640190fd5b428310156116035760405162461bcd60e51b8152600401808060200182810382526021815260200180611f136021913960400191505060405180910390fd5b828211611657576040805162461bcd60e51b815260206004820152601f60248201527f73746f702074696d65206265666f7265207468652073746172742074696d6500604482015290519081900360640190fd5b61165f611ea6565b6116698385611a8a565b602083018190528282600381111561167d57fe5b600381111561168857fe5b905250600090508151600381111561169c57fe5b146116a357fe5b80602001518610156116fc576040805162461bcd60e51b815260206004820152601f60248201527f6465706f73697420736d616c6c6572207468616e2074696d652064656c746100604482015290519081900360640190fd5b8060200151868161170957fe5b06156117465760405162461bcd60e51b8152600401808060200182810382526022815260200180611f346022913960400191505060405180910390fd5b611754868260200151611b04565b604083018190528282600381111561176857fe5b600381111561177357fe5b905250600090508151600381111561178757fe5b1461178e57fe5b6000600254905060405180610120016040528088815260200183604001518152602001888152602001868152602001858152602001896001600160a01b03168152602001336001600160a01b03168152602001876001600160a01b031681526020016001151581525060036000838152602001908152602001600020600082015181600001556020820151816001015560408201518160020155606082015181600301556080820151816004015560a08201518160050160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060c08201518160060160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060e08201518160070160006101000a8154816001600160a01b0302191690836001600160a01b031602179055506101008201518160070160146101000a81548160ff0219169083151502179055509050506118f46002546001611b2f565b60028190558382600381111561190657fe5b600381111561191157fe5b905250600090508251600381111561192557fe5b14611977576040805162461bcd60e51b815260206004820181905260248201527f6e6578742073747265616d2069642063616c63756c6174696f6e206572726f72604482015290519081900360640190fd5b6119926001600160a01b03871633308a63ffffffff611b5516565b604080518881526001600160a01b038881166020830152818301889052606082018790529151918a1691339184917f7b01d409597969366dc268d7f957a990d1ca3d3449baf8fb45db67351aecfe789181900360800190a4979650505050505050565b6119fd610e8b565b611a3c576040805162461bcd60e51b81526020600482018190526024820152600080516020611f56833981519152604482015290519081900360640190fd5b611a4581611bb5565b50565b60008083611a5b57506000905080611a83565b83830283858281611a6857fe5b0414611a7c57506002915060009050611a83565b6000925090505b9250929050565b600080838311611aa1575060009050818303611a83565b50600390506000611a83565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052611aff908490611c56565b505050565b60008082611b185750600190506000611a83565b6000838581611b2357fe5b04915091509250929050565b600080838301848110611b4757600092509050611a83565b506002915060009050611a83565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b179052611baf908590611c56565b50505050565b6001600160a01b038116611bfa5760405162461bcd60e51b8152600401808060200182810382526026815260200180611ec96026913960400191505060405180910390fd5b6001546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600180546001600160a01b0319166001600160a01b0392909216919091179055565b611c68826001600160a01b0316611e0e565b611cb9576040805162461bcd60e51b815260206004820152601f60248201527f5361666545524332303a2063616c6c20746f206e6f6e2d636f6e747261637400604482015290519081900360640190fd5b60006060836001600160a01b0316836040518082805190602001908083835b60208310611cf75780518252601f199092019160209182019101611cd8565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114611d59576040519150601f19603f3d011682016040523d82523d6000602084013e611d5e565b606091505b509150915081611db5576040805162461bcd60e51b815260206004820181905260248201527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564604482015290519081900360640190fd5b805115611baf57808060200190516020811015611dd157600080fd5b5051611baf5760405162461bcd60e51b815260040180806020018281038252602a815260200180611fd0602a913960400191505060405180910390fd5b3b151590565b604051806101200160405280600081526020016000815260200160008152602001600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681526020016000151581525090565b604080516080810190915280600081526020016000815260200160008152602001600081525090565b604080516060810190915280600081526020016000815260200160008152509056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373616d6f756e7420657863656564732074686520617661696c61626c652062616c616e636573746172742074696d65206265666f726520626c6f636b2e74696d657374616d706465706f736974206e6f74206d756c7469706c65206f662074696d652064656c74614f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572726563697069656e742062616c616e63652063616c63756c6174696f6e206572726f7263616c6c6572206973206e6f74207468652073656e646572206f722074686520726563697069656e74206f66207468652073747265616d5361666545524332303a204552433230206f7065726174696f6e20646964206e6f74207375636365656463616c6c6572206973206e6f742074686520726563697069656e74206f66207468652073747265616da265627a7a72315820e894d6173fb1a54e29dfb5dfcb924eb7b69952b7480fbf6c4938b2eb431cd09664736f6c63430005110032

Verified Source Code Partial Match

Compiler: v0.5.17+commit.d19bba13 EVM: istanbul Optimization: Yes (200 runs)
Types.sol 19 lines
pragma solidity =0.5.17;

/**
 * @title Sablier Types
 * @author Sablier
 */
library Types {
    struct Stream {
        uint256 deposit;
        uint256 ratePerSecond;
        uint256 remainingBalance;
        uint256 startTime;
        uint256 stopTime;
        address recipient;
        address sender;
        address tokenAddress;
        bool isEntity;
    }
}
Sablier.sol 363 lines
pragma solidity =0.5.17;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/ownership/Ownable.sol";
import "@sablier/shared-contracts/compound/CarefulMath.sol";

import "./interfaces/ISablier.sol";
import "./interfaces/ITimeLockPool.sol";
import "./Types.sol";

/**
 * @title Sablier
 * @author Sablier
 * @notice Money streaming.
 */
contract Sablier is ISablier, ReentrancyGuard, CarefulMath, Ownable {
    using SafeERC20 for IERC20;

    /*** Storage Properties ***/

    /**
     * @notice Counter for new stream ids.
     */
    uint256 public nextStreamId;

    /**
     * @notice The stream objects identifiable by their unsigned integer ids.
     */
    mapping(uint256 => Types.Stream) private streams;

    /**
     * @notice Address of the staking pool
     */
    ITimeLockPool public stakingPool;

    /*** Modifiers ***/

    /**
     * @dev Throws if the caller is not the sender of the recipient of the stream.
     */
    modifier onlySenderOrRecipient(uint256 streamId) {
        require(
            msg.sender == streams[streamId].sender || msg.sender == streams[streamId].recipient,
            "caller is not the sender or the recipient of the stream"
        );
        _;
    }

    /**
     * @dev Throws if the caller is not the recipient of the stream.
     */
    modifier onlyRecipient(uint256 streamId) {
        require(
            msg.sender == streams[streamId].recipient,
            "caller is not the recipient of the stream"
        );
        _;
    }

    /**
     * @dev Throws if the provided id does not point to a valid stream.
     */
    modifier streamExists(uint256 streamId) {
        require(streams[streamId].isEntity, "stream does not exist");
        _;
    }

    /*** Contract Logic Starts Here */

    constructor() public {
        nextStreamId = 100000;
    }

    /*** View Functions ***/

    /**
     * @notice Returns the stream with all its properties.
     * @dev Throws if the id does not point to a valid stream.
     * @param streamId The id of the stream to query.
     * @return The stream object.
     */
    function getStream(uint256 streamId)
        external
        view
        streamExists(streamId)
        returns (
            address sender,
            address recipient,
            uint256 deposit,
            address tokenAddress,
            uint256 startTime,
            uint256 stopTime,
            uint256 remainingBalance,
            uint256 ratePerSecond
        )
    {
        sender = streams[streamId].sender;
        recipient = streams[streamId].recipient;
        deposit = streams[streamId].deposit;
        tokenAddress = streams[streamId].tokenAddress;
        startTime = streams[streamId].startTime;
        stopTime = streams[streamId].stopTime;
        remainingBalance = streams[streamId].remainingBalance;
        ratePerSecond = streams[streamId].ratePerSecond;
    }

    /**
     * @notice Returns either the delta in seconds between `block.timestamp` and `startTime` or
     *  between `stopTime` and `startTime, whichever is smaller. If `block.timestamp` is before
     *  `startTime`, it returns 0.
     * @dev Throws if the id does not point to a valid stream.
     * @param streamId The id of the stream for which to query the delta.
     * @return The time delta in seconds.
     */
    function deltaOf(uint256 streamId) public view streamExists(streamId) returns (uint256 delta) {
        Types.Stream memory stream = streams[streamId];
        if (block.timestamp <= stream.startTime) return 0;
        if (block.timestamp < stream.stopTime) return block.timestamp - stream.startTime;
        return stream.stopTime - stream.startTime;
    }

    struct BalanceOfLocalVars {
        MathError mathErr;
        uint256 recipientBalance;
        uint256 withdrawalAmount;
        uint256 senderBalance;
    }

    /**
     * @notice Returns the available funds for the given stream id and address.
     * @dev Throws if the id does not point to a valid stream.
     * @param streamId The id of the stream for which to query the balance.
     * @param who The address for which to query the balance.
     * @return The total funds allocated to `who` as uint256.
     */
    function balanceOf(uint256 streamId, address who) public view streamExists(streamId) returns (uint256 balance) {
        Types.Stream memory stream = streams[streamId];
        BalanceOfLocalVars memory vars;

        uint256 delta = deltaOf(streamId);
        (vars.mathErr, vars.recipientBalance) = mulUInt(delta, stream.ratePerSecond);
        require(vars.mathErr == MathError.NO_ERROR, "recipient balance calculation error");

        /*
         * If the stream `balance` does not equal `deposit`, it means there have been withdrawals.
         * We have to subtract the total amount withdrawn from the amount of money that has been
         * streamed until now.
         */
        if (stream.deposit > stream.remainingBalance) {
            (vars.mathErr, vars.withdrawalAmount) = subUInt(stream.deposit, stream.remainingBalance);
            assert(vars.mathErr == MathError.NO_ERROR);
            (vars.mathErr, vars.recipientBalance) = subUInt(vars.recipientBalance, vars.withdrawalAmount);
            /* `withdrawalAmount` cannot and should not be bigger than `recipientBalance`. */
            assert(vars.mathErr == MathError.NO_ERROR);
        }

        if (who == stream.recipient) return vars.recipientBalance;
        if (who == stream.sender) {
            (vars.mathErr, vars.senderBalance) = subUInt(stream.remainingBalance, vars.recipientBalance);
            /* `recipientBalance` cannot and should not be bigger than `remainingBalance`. */
            assert(vars.mathErr == MathError.NO_ERROR);
            return vars.senderBalance;
        }
        return 0;
    }

    /*** Public Effects & Interactions Functions ***/

    struct CreateStreamLocalVars {
        MathError mathErr;
        uint256 duration;
        uint256 ratePerSecond;
    }

    /**
     * @notice Creates a new stream funded by `msg.sender` and paid towards `recipient`.
     * @dev Throws if the recipient is the zero address, the contract itself or the caller.
     *  Throws if the deposit is 0.
     *  Throws if the start time is before `block.timestamp`.
     *  Throws if the stop time is before the start time.
     *  Throws if the duration calculation has a math error.
     *  Throws if the deposit is smaller than the duration.
     *  Throws if the deposit is not a multiple of the duration.
     *  Throws if the rate calculation has a math error.
     *  Throws if the next stream id calculation has a math error.
     *  Throws if the contract is not allowed to transfer enough tokens.
     *  Throws if there is a token transfer failure.
     * @param recipient The address towards which the money is streamed.
     * @param deposit The amount of money to be streamed.
     * @param tokenAddress The ERC20 token to use as streaming currency.
     * @param startTime The unix timestamp for when the stream starts.
     * @param stopTime The unix timestamp for when the stream stops.
     * @return The uint256 id of the newly created stream.
     */
    function createStream(address recipient, uint256 deposit, address tokenAddress, uint256 startTime, uint256 stopTime)
        public
        onlyOwner
        returns (uint256)
    {
        require(recipient != address(0x00), "stream to the zero address");
        require(recipient != address(this), "stream to the contract itself");
        require(recipient != msg.sender, "stream to the caller");
        require(deposit > 0, "deposit is zero");
        require(startTime >= block.timestamp, "start time before block.timestamp");
        require(stopTime > startTime, "stop time before the start time");

        CreateStreamLocalVars memory vars;
        (vars.mathErr, vars.duration) = subUInt(stopTime, startTime);
        /* `subUInt` can only return MathError.INTEGER_UNDERFLOW but we know `stopTime` is higher than `startTime`. */
        assert(vars.mathErr == MathError.NO_ERROR);

        /* Without this, the rate per second would be zero. */
        require(deposit >= vars.duration, "deposit smaller than time delta");

        /* This condition avoids dealing with remainders */
        require(deposit % vars.duration == 0, "deposit not multiple of time delta");

        (vars.mathErr, vars.ratePerSecond) = divUInt(deposit, vars.duration);
        /* `divUInt` can only return MathError.DIVISION_BY_ZERO but we know `duration` is not zero. */
        assert(vars.mathErr == MathError.NO_ERROR);

        /* Create and store the stream object. */
        uint256 streamId = nextStreamId;
        streams[streamId] = Types.Stream({
            remainingBalance: deposit,
            deposit: deposit,
            isEntity: true,
            ratePerSecond: vars.ratePerSecond,
            recipient: recipient,
            sender: msg.sender,
            startTime: startTime,
            stopTime: stopTime,
            tokenAddress: tokenAddress
        });

        /* Increment the next stream id. */
        (vars.mathErr, nextStreamId) = addUInt(nextStreamId, uint256(1));
        require(vars.mathErr == MathError.NO_ERROR, "next stream id calculation error");

        IERC20(tokenAddress).safeTransferFrom(msg.sender, address(this), deposit);
        emit CreateStream(streamId, msg.sender, recipient, deposit, tokenAddress, startTime, stopTime);
        return streamId;
    }

    /**
     * @notice Withdraws from the contract to the recipient's account.
     * @dev Throws if the id does not point to a valid stream.
     *  Throws if the caller is not the sender or the recipient of the stream.
     *  Throws if the amount exceeds the available balance.
     *  Throws if there is a token transfer failure.
     * @param streamId The id of the stream to withdraw tokens from.
     * @param amount The amount of tokens to withdraw.
     */
    function withdrawFromStream(uint256 streamId, uint256 amount)
        external
        nonReentrant
        streamExists(streamId)
        onlySenderOrRecipient(streamId)
        returns (bool)
    {
        require(amount > 0, "amount is zero");
        Types.Stream memory stream = streams[streamId];

        uint256 balance = balanceOf(streamId, stream.recipient);
        require(balance >= amount, "amount exceeds the available balance");

        MathError mathErr;
        (mathErr, streams[streamId].remainingBalance) = subUInt(stream.remainingBalance, amount);
        /**
         * `subUInt` can only return MathError.INTEGER_UNDERFLOW but we know that `remainingBalance` is at least
         * as big as `amount`.
         */
        assert(mathErr == MathError.NO_ERROR);

        if (streams[streamId].remainingBalance == 0) delete streams[streamId];

        IERC20(stream.tokenAddress).safeTransfer(stream.recipient, amount);
        emit WithdrawFromStream(streamId, stream.recipient, amount);
        return true;
    }


    /**
     * @notice Withdraws from the contract to the recipient's account.
     * @dev Throws if the id does not point to a valid stream.
     *  Throws if the caller is not the sender or the recipient of the stream.
     *  Throws if the amount exceeds the available balance.
     *  Throws if there is a token transfer failure.
     * @param streamId The id of the stream to withdraw tokens from.
     * @param amount The amount of tokens to withdraw.
     * @param duration Duration of stake
     */
    function withdrawFromStreamAndStake(uint256 streamId, uint256 amount, uint256 duration)
        external
        nonReentrant
        streamExists(streamId)
        onlyRecipient(streamId)
        returns (bool)
    {
        require(amount > 0, "amount is zero");
        Types.Stream memory stream = streams[streamId];

        uint256 balance = balanceOf(streamId, stream.recipient);
        require(balance >= amount, "amount exceeds the available balance");

        MathError mathErr;
        (mathErr, streams[streamId].remainingBalance) = subUInt(stream.remainingBalance, amount);
        /**
         * `subUInt` can only return MathError.INTEGER_UNDERFLOW but we know that `remainingBalance` is at least
         * as big as `amount`.
         */
        assert(mathErr == MathError.NO_ERROR);

        if (streams[streamId].remainingBalance == 0) delete streams[streamId];

        IERC20(stream.tokenAddress).approve(address(stakingPool), amount);
        stakingPool.deposit(amount, duration, stream.recipient);

        emit WithdrawFromStream(streamId, stream.recipient, amount);
        return true;
    }

    /**
     * @notice Cancels the stream and transfers the tokens back on a pro rata basis.
     * @dev Throws if the id does not point to a valid stream.
     *  Throws if the caller is not the sender or the recipient of the stream.
     *  Throws if there is a token transfer failure.
     * @param streamId The id of the stream to cancel.
     * @return bool true=success, otherwise false.
     */
    function cancelStream(uint256 streamId)
        external
        nonReentrant
        streamExists(streamId)
        onlySenderOrRecipient(streamId)
        returns (bool)
    {
        Types.Stream memory stream = streams[streamId];
        uint256 senderBalance = balanceOf(streamId, stream.sender);
        uint256 recipientBalance = balanceOf(streamId, stream.recipient);

        delete streams[streamId];

        IERC20 token = IERC20(stream.tokenAddress);
        if (recipientBalance > 0) token.safeTransfer(stream.recipient, recipientBalance);
        if (senderBalance > 0) token.safeTransfer(stream.sender, senderBalance);

        emit CancelStream(streamId, stream.sender, stream.recipient, senderBalance, recipientBalance);
        return true;
    }


    /**
     * @notice Update the staking pool address
     * @dev throws if called by non owner
     * @param newStakingPool Address of the new staking pool
     */
    function setStakingPool(address newStakingPool) external onlyOwner {
        stakingPool = ITimeLockPool(newStakingPool);
    }
}
ISablier.sol 60 lines
pragma solidity >=0.5.17;

/**
 * @title ISablier
 * @author Sablier
 */
interface ISablier {
    /**
     * @notice Emits when a stream is successfully created.
     */
    event CreateStream(
        uint256 indexed streamId,
        address indexed sender,
        address indexed recipient,
        uint256 deposit,
        address tokenAddress,
        uint256 startTime,
        uint256 stopTime
    );

    /**
     * @notice Emits when the recipient of a stream withdraws a portion or all their pro rata share of the stream.
     */
    event WithdrawFromStream(uint256 indexed streamId, address indexed recipient, uint256 amount);

    /**
     * @notice Emits when a stream is successfully cancelled and tokens are transferred back on a pro rata basis.
     */
    event CancelStream(
        uint256 indexed streamId,
        address indexed sender,
        address indexed recipient,
        uint256 senderBalance,
        uint256 recipientBalance
    );

    function balanceOf(uint256 streamId, address who) external view returns (uint256 balance);

    function getStream(uint256 streamId)
        external
        view
        returns (
            address sender,
            address recipient,
            uint256 deposit,
            address token,
            uint256 startTime,
            uint256 stopTime,
            uint256 remainingBalance,
            uint256 ratePerSecond
        );

    function createStream(address recipient, uint256 deposit, address tokenAddress, uint256 startTime, uint256 stopTime)
        external
        returns (uint256 streamId);

    function withdrawFromStream(uint256 streamId, uint256 funds) external returns (bool);

    function cancelStream(uint256 streamId) external returns (bool);
}
ITimeLockPool.sol 5 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.17;
interface ITimeLockPool {
    function deposit(uint256 _amount, uint256 _duration, address _receiver) external;
}
SafeMath.sol 107 lines
pragma solidity ^0.5.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) {
        require(b <= a, "SafeMath: subtraction overflow");
        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) {
        // Solidity only automatically asserts when dividing by 0
        require(b > 0, "SafeMath: division by zero");
        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) {
        require(b != 0, "SafeMath: modulo by zero");
        return a % b;
    }
}
Address.sol 27 lines
pragma solidity ^0.5.0;

/**
 * @dev Collection of functions related to the address type,
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * This test is non-exhaustive, and there may be false-negatives: during the
     * execution of a contract's constructor, its address will be reported as
     * not containing a contract.
     *
     * > It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies in extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        // solhint-disable-next-line no-inline-assembly
        assembly { size := extcodesize(account) }
        return size > 0;
    }
}
Ownable.sol 75 lines
pragma solidity ^0.5.0;

/**
 * @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.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be aplied to your functions to restrict their use to
 * the owner.
 */
contract Ownable {
    address private _owner;

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor () internal {
        _owner = msg.sender;
        emit OwnershipTransferred(address(0), _owner);
    }

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

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(isOwner(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Returns true if the caller is the current owner.
     */
    function isOwner() public view returns (bool) {
        return msg.sender == _owner;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * > Note: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public onlyOwner {
        emit OwnershipTransferred(_owner, address(0));
        _owner = 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 onlyOwner {
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     */
    function _transferOwnership(address newOwner) internal {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}
IERC20.sol 76 lines
pragma solidity ^0.5.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP. Does not include
 * the optional functions; to access them see `ERC20Detailed`.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a `Transfer` event.
     */
    function transfer(address recipient, uint256 amount) 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 `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * > 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 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a `Transfer` event.
     */
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);

    /**
     * @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);
}
SafeERC20.sol 75 lines
pragma solidity ^0.5.0;

import "./IERC20.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";

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

    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        // solhint-disable-next-line max-line-length
        require((value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 newAllowance = token.allowance(address(this), spender).add(value);
        callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 newAllowance = token.allowance(address(this), spender).sub(value);
        callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves.

        // A Solidity high level call has three parts:
        //  1. The target address is checked to verify it contains contract code
        //  2. The call itself is made, and success asserted
        //  3. The return value is decoded, which in turn checks the size of the returned data.
        // solhint-disable-next-line max-line-length
        require(address(token).isContract(), "SafeERC20: call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = address(token).call(data);
        require(success, "SafeERC20: low-level call failed");

        if (returndata.length > 0) { // Return data is optional
            // solhint-disable-next-line max-line-length
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}
ReentrancyGuard.sol 38 lines
pragma solidity ^0.5.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the `nonReentrant` modifier
 * available, which can be aplied 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.
 */
contract ReentrancyGuard {
    /// @dev counter to allow mutex lock with only one SSTORE operation
    uint256 private _guardCounter;

    constructor () internal {
        // The counter starts at one to prevent changing it from zero to a non-zero
        // value, which is a more expensive operation.
        _guardCounter = 1;
    }

    /**
     * @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 make it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _guardCounter += 1;
        uint256 localCounter = _guardCounter;
        _;
        require(localCounter == _guardCounter, "ReentrancyGuard: reentrant call");
    }
}
CarefulMath.sol 85 lines
pragma solidity >=0.5.17;

/**
  * @title Careful Math
  * @author Compound
  * @notice Derived from OpenZeppelin's SafeMath library
  *         https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/math/SafeMath.sol
  */
contract CarefulMath {

    /**
     * @dev Possible error codes that we can return
     */
    enum MathError {
        NO_ERROR,
        DIVISION_BY_ZERO,
        INTEGER_OVERFLOW,
        INTEGER_UNDERFLOW
    }

    /**
    * @dev Multiplies two numbers, returns an error on overflow.
    */
    function mulUInt(uint a, uint b) internal pure returns (MathError, uint) {
        if (a == 0) {
            return (MathError.NO_ERROR, 0);
        }

        uint c = a * b;

        if (c / a != b) {
            return (MathError.INTEGER_OVERFLOW, 0);
        } else {
            return (MathError.NO_ERROR, c);
        }
    }

    /**
    * @dev Integer division of two numbers, truncating the quotient.
    */
    function divUInt(uint a, uint b) internal pure returns (MathError, uint) {
        if (b == 0) {
            return (MathError.DIVISION_BY_ZERO, 0);
        }

        return (MathError.NO_ERROR, a / b);
    }

    /**
    * @dev Subtracts two numbers, returns an error on overflow (i.e. if subtrahend is greater than minuend).
    */
    function subUInt(uint a, uint b) internal pure returns (MathError, uint) {
        if (b <= a) {
            return (MathError.NO_ERROR, a - b);
        } else {
            return (MathError.INTEGER_UNDERFLOW, 0);
        }
    }

    /**
    * @dev Adds two numbers, returns an error on overflow.
    */
    function addUInt(uint a, uint b) internal pure returns (MathError, uint) {
        uint c = a + b;

        if (c >= a) {
            return (MathError.NO_ERROR, c);
        } else {
            return (MathError.INTEGER_OVERFLOW, 0);
        }
    }

    /**
    * @dev add a and b and then subtract c
    */
    function addThenSubUInt(uint a, uint b, uint c) internal pure returns (MathError, uint) {
        (MathError err0, uint sum) = addUInt(a, b);

        if (err0 != MathError.NO_ERROR) {
            return (err0, 0);
        }

        return subUInt(sum, c);
    }
}

Read Contract

balanceOf 0x3656eec2 → uint256
deltaOf 0xa82ccd4d → uint256
getStream 0x894e9a0d → address, address, uint256, address, uint256, uint256, uint256, uint256
isOwner 0x8f32d59b → bool
nextStreamId 0x1e99d569 → uint256
owner 0x8da5cb5b → address
stakingPool 0x0c56ae3b → address

Write Contract 7 functions

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

cancelStream 0x6db9241b
uint256 streamId
returns: bool
createStream 0xcc1b4bf6
address recipient
uint256 deposit
address tokenAddress
uint256 startTime
uint256 stopTime
returns: uint256
renounceOwnership 0x715018a6
No parameters
setStakingPool 0x3028f63a
address newStakingPool
transferOwnership 0xf2fde38b
address newOwner
withdrawFromStream 0x7a9b2c6c
uint256 streamId
uint256 amount
returns: bool
withdrawFromStreamAndStake 0x985bb2b4
uint256 streamId
uint256 amount
uint256 duration
returns: bool

Recent Transactions

No transactions found for this address