Address Contract Partially Verified
Address
0xd60929C3A153dDfee363c957490a305b1122E0d9
Balance
0 ETH
Nonce
1
Code Size
9901 bytes
Creator
0x72C1a1c2...7662 at tx 0x06618d78...5c44dd
Indexed Transactions
0
Contract Bytecode
9901 bytes
0x608060405234801561001057600080fd5b50600436106101b95760003560e01c806370a08231116100f9578063aa7fada511610097578063db77e2b211610071578063db77e2b214610412578063dd62ed3e14610430578063f2fde38b14610476578063f3fef3a31461048957600080fd5b8063aa7fada5146103e4578063b7aa0231146103ec578063cf8fbec9146103ff57600080fd5b806395d89b41116100d357806395d89b41146103ae5780639a674aca146103b6578063a457c2d7146103be578063a9059cbb146103d157600080fd5b806370a08231146103355780637ddd28d61461036b5780638da5cb5b1461039057600080fd5b806323b872dd1161016657806340c10f191161014057806340c10f19146102c357806342966c68146102d657806347e7ef24146102e957806363813c78146102fc57600080fd5b806323b872dd1461026d578063313ce5671461028057806339509351146102b057600080fd5b806318160ddd1161019757806318160ddd146102095780631da7063e1461021b57806321a6ba5d1461022e57600080fd5b806306fdde03146101be578063095ea7b3146101dc5780631765e27c146101ff575b600080fd5b6101c661049c565b6040516101d3919061225d565b60405180910390f35b6101ef6101ea3660046122d7565b61052e565b60405190151581526020016101d3565b610207610548565b005b6002545b6040519081526020016101d3565b610207610229366004612301565b61063a565b60075473ffffffffffffffffffffffffffffffffffffffff165b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016101d3565b6101ef61027b36600461232d565b6107af565b60075474010000000000000000000000000000000000000000900460ff1660405160ff90911681526020016101d3565b6101ef6102be3660046122d7565b6107d5565b6102076102d13660046122d7565b610821565b6102076102e4366004612369565b61090f565b6102076102f73660046122d7565b610996565b6101ef61030a366004612382565b73ffffffffffffffffffffffffffffffffffffffff1660009081526009602052604090205460ff1690565b61020d610343366004612382565b73ffffffffffffffffffffffffffffffffffffffff1660009081526020819052604090205490565b600754760100000000000000000000000000000000000000000000900460ff166101ef565b60055473ffffffffffffffffffffffffffffffffffffffff16610248565b6101c6610c8a565b610207610c99565b6101ef6103cc3660046122d7565b610d6d565b6101ef6103df3660046122d7565b610e49565b60065461020d565b6102076103fa366004612382565b610e57565b61020761040d366004612382565b610f5b565b60085473ffffffffffffffffffffffffffffffffffffffff16610248565b61020d61043e36600461239d565b73ffffffffffffffffffffffffffffffffffffffff918216600090815260016020908152604080832093909416825291909152205490565b610207610484366004612382565b61105b565b6102076104973660046122d7565b611188565b6060600380546104ab906123c7565b80601f01602080910402602001604051908101604052809291908181526020018280546104d7906123c7565b80156105245780601f106104f957610100808354040283529160200191610524565b820191906000526020600020905b81548152906001019060200180831161050757829003601f168201915b5050505050905090565b60003361053c818585611444565b60019150505b92915050565b60055473ffffffffffffffffffffffffffffffffffffffff1633146105ce576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064015b60405180910390fd5b600780547fffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffffff167601000000000000000000000000000000000000000000001790556040517f73da10e045484e407747da33a3d548a5b3beb6d9571b54264f186eba2b88ff3590600090a1565b60055473ffffffffffffffffffffffffffffffffffffffff1633146106bb576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016105c5565b631dcd6500821115610729576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f6e6577207769746864726177206665652065786365656473206d6178696d756d60448201526064016105c5565b6006829055600780547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83169081179091556040805184815260208101929092527f03f27107304d4b62ba745a7acf4f870cc719efdea0818154ec216095d7e28428910160405180910390a15050565b6000336107bd8582856115f8565b6107c88585856116cf565b60019150505b9392505050565b33600081815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8716845290915281205490919061053c908290869061081c90879061244a565b611444565b3360009081526009602052604090205460ff1661089a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f50544f4b454e3a204e4f545f415554484f52495a45440000000000000000000060448201526064016105c5565b80610901576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f45524332303a207a65726f206d696e7420616d6f756e7400000000000000000060448201526064016105c5565b61090b8282611982565b5050565b3360009081526009602052604090205460ff16610988576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f50544f4b454e3a204e4f545f415554484f52495a45440000000000000000000060448201526064016105c5565b610993335b82611aa2565b50565b600754760100000000000000000000000000000000000000000000900460ff16610a42576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f50544f4b454e3a204465706f73697420616e64207769746864726177616c206e60448201527f6f7420656e61626c65640000000000000000000000000000000000000000000060648201526084016105c5565b6008546040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009173ffffffffffffffffffffffffffffffffffffffff16906370a082319060240160206040518083038186803b158015610aac57600080fd5b505afa158015610ac0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ae49190612462565b9050610b0b3360085473ffffffffffffffffffffffffffffffffffffffff16903085611c8c565b6008546040517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152610bb891839173ffffffffffffffffffffffffffffffffffffffff909116906370a082319060240160206040518083038186803b158015610b7a57600080fd5b505afa158015610b8e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bb29190612462565b90611d68565b915081610c21576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f6465706f73697420616d6f756e742063616e6e6f74206265207a65726f00000060448201526064016105c5565b610c3583610c30600085611d74565b611982565b6040805173ffffffffffffffffffffffffffffffffffffffff85168152602081018490527fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c91015b60405180910390a1505050565b6060600480546104ab906123c7565b60055473ffffffffffffffffffffffffffffffffffffffff163314610d1a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016105c5565b600780547fffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffffff1690556040517fc30c5eebdcb5648945e38f63fbbd4e4e108e40f034f92dedd848c743f817a0c390600090a1565b33600081815260016020908152604080832073ffffffffffffffffffffffffffffffffffffffff8716845290915281205490919083811015610e31576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760448201527f207a65726f00000000000000000000000000000000000000000000000000000060648201526084016105c5565b610e3e8286868403611444565b506001949350505050565b60003361053c8185856116cf565b60055473ffffffffffffffffffffffffffffffffffffffff163314610ed8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016105c5565b73ffffffffffffffffffffffffffffffffffffffff811660008181526009602090815260409182902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016905590519182527f545be0cd37a1ed07438ce725da2f7f10c42b0db291044496e6ddde4bf8ec731891015b60405180910390a150565b60055473ffffffffffffffffffffffffffffffffffffffff163314610fdc576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016105c5565b73ffffffffffffffffffffffffffffffffffffffff811660008181526009602090815260409182902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600117905590519182527f35fb906cc79d20f946f13a287522ce169494baddb33c908e2dcfafd85f345a419101610f50565b60055473ffffffffffffffffffffffffffffffffffffffff1633146110dc576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016105c5565b73ffffffffffffffffffffffffffffffffffffffff811661117f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f646472657373000000000000000000000000000000000000000000000000000060648201526084016105c5565b61099381611e40565b600754760100000000000000000000000000000000000000000000900460ff16611234576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f50544f4b454e3a204465706f73697420616e64207769746864726177616c206e60448201527f6f7420656e61626c65640000000000000000000000000000000000000000000060648201526084016105c5565b8061129b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f776974686472617720616d6f756e742063616e6e6f74206265207a65726f000060448201526064016105c5565b6112a43361098d565b6112af600182611d74565b90508061133e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f756e6465726c79696e6720746f6b656e20616d6f756e742063616e6e6f74206260448201527f65207a65726f000000000000000000000000000000000000000000000000000060648201526084016105c5565b600060065460001415801561136a575060075473ffffffffffffffffffffffffffffffffffffffff1615155b156113cc576113936402540be40061138d60065485611eb790919063ffffffff16565b90611ec3565b905061139f8282611d68565b6007546008549193506113cc9173ffffffffffffffffffffffffffffffffffffffff908116911683611ecf565b6008546113f09073ffffffffffffffffffffffffffffffffffffffff168484611ecf565b6040805173ffffffffffffffffffffffffffffffffffffffff85168152602081018490529081018290527ff279e6a1f5e320cca91135676d9cb6e44ca8a08c0b88342bcdb1144f6511b56890606001610c7d565b73ffffffffffffffffffffffffffffffffffffffff83166114e6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460448201527f726573730000000000000000000000000000000000000000000000000000000060648201526084016105c5565b73ffffffffffffffffffffffffffffffffffffffff8216611589576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f20616464726560448201527f737300000000000000000000000000000000000000000000000000000000000060648201526084016105c5565b73ffffffffffffffffffffffffffffffffffffffff83811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b73ffffffffffffffffffffffffffffffffffffffff8381166000908152600160209081526040808320938616835292905220547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81146116c957818110156116bc576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e636500000060448201526064016105c5565b6116c98484848403611444565b50505050565b73ffffffffffffffffffffffffffffffffffffffff8316611772576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f20616460448201527f647265737300000000000000000000000000000000000000000000000000000060648201526084016105c5565b73ffffffffffffffffffffffffffffffffffffffff8216611815576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201527f657373000000000000000000000000000000000000000000000000000000000060648201526084016105c5565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260208190526040902054818110156118cb576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e742065786365656473206260448201527f616c616e6365000000000000000000000000000000000000000000000000000060648201526084016105c5565b73ffffffffffffffffffffffffffffffffffffffff80851660009081526020819052604080822085850390559185168152908120805484929061190f90849061244a565b925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161197591815260200190565b60405180910390a36116c9565b73ffffffffffffffffffffffffffffffffffffffff82166119ff576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f20616464726573730060448201526064016105c5565b8060026000828254611a11919061244a565b909155505073ffffffffffffffffffffffffffffffffffffffff821660009081526020819052604081208054839290611a4b90849061244a565b909155505060405181815273ffffffffffffffffffffffffffffffffffffffff8316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b73ffffffffffffffffffffffffffffffffffffffff8216611b45576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f2061646472657360448201527f730000000000000000000000000000000000000000000000000000000000000060648201526084016105c5565b73ffffffffffffffffffffffffffffffffffffffff821660009081526020819052604090205481811015611bfb576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e60448201527f636500000000000000000000000000000000000000000000000000000000000060648201526084016105c5565b73ffffffffffffffffffffffffffffffffffffffff83166000908152602081905260408120838303905560028054849290611c3790849061247b565b909155505060405182815260009073ffffffffffffffffffffffffffffffffffffffff8516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef906020016115eb565b505050565b60405173ffffffffffffffffffffffffffffffffffffffff808516602483015283166044820152606481018290526116c99085907f23b872dd00000000000000000000000000000000000000000000000000000000906084015b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152611f25565b60006107ce828461247b565b60008215611de557600754611dde90611da99074010000000000000000000000000000000000000000900460ff16600a6125b2565b60075461138d90611dd7907501000000000000000000000000000000000000000000900460ff16600a6125b2565b8590611eb7565b9050610542565b600754611dde90611e13907501000000000000000000000000000000000000000000900460ff16600a6125b2565b60075461138d90611dd79074010000000000000000000000000000000000000000900460ff16600a6125b2565b6005805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60006107ce82846125c1565b60006107ce82846125fe565b60405173ffffffffffffffffffffffffffffffffffffffff8316602482015260448101829052611c879084907fa9059cbb0000000000000000000000000000000000000000000000000000000090606401611ce6565b6000611f87826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff166120319092919063ffffffff16565b805190915015611c875780806020019051810190611fa59190612639565b611c87576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f7420737563636565640000000000000000000000000000000000000000000060648201526084016105c5565b60606120408484600085612048565b949350505050565b6060824710156120da576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c000000000000000000000000000000000000000000000000000060648201526084016105c5565b73ffffffffffffffffffffffffffffffffffffffff85163b612158576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016105c5565b6000808673ffffffffffffffffffffffffffffffffffffffff168587604051612181919061265b565b60006040518083038185875af1925050503d80600081146121be576040519150601f19603f3d011682016040523d82523d6000602084013e6121c3565b606091505b50915091506121d38282866121de565b979650505050505050565b606083156121ed5750816107ce565b8251156121fd5782518084602001fd5b816040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105c5919061225d565b60005b8381101561224c578181015183820152602001612234565b838111156116c95750506000910152565b602081526000825180602084015261227c816040850160208701612231565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169190910160400192915050565b803573ffffffffffffffffffffffffffffffffffffffff811681146122d257600080fd5b919050565b600080604083850312156122ea57600080fd5b6122f3836122ae565b946020939093013593505050565b6000806040838503121561231457600080fd5b82359150612324602084016122ae565b90509250929050565b60008060006060848603121561234257600080fd5b61234b846122ae565b9250612359602085016122ae565b9150604084013590509250925092565b60006020828403121561237b57600080fd5b5035919050565b60006020828403121561239457600080fd5b6107ce826122ae565b600080604083850312156123b057600080fd5b6123b9836122ae565b9150612324602084016122ae565b600181811c908216806123db57607f821691505b60208210811415612415577f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000821982111561245d5761245d61241b565b500190565b60006020828403121561247457600080fd5b5051919050565b60008282101561248d5761248d61241b565b500390565b600181815b808511156124eb57817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048211156124d1576124d161241b565b808516156124de57918102915b93841c9390800290612497565b509250929050565b60008261250257506001610542565b8161250f57506000610542565b8160018114612525576002811461252f5761254b565b6001915050610542565b60ff8411156125405761254061241b565b50506001821b610542565b5060208310610133831016604e8410600b841016171561256e575081810a610542565b6125788383612492565b807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048211156125aa576125aa61241b565b029392505050565b60006107ce60ff8416836124f3565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04831182151516156125f9576125f961241b565b500290565b600082612634577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b60006020828403121561264b57600080fd5b815180151581146107ce57600080fd5b6000825161266d818460208701612231565b919091019291505056fea26469706673582212208872e01f1ca906b6ae4534f64ef951c5fdb787888c89ac8dd0dbe01ccf9b747564736f6c63430008080033
Verified Source Code Partial Match
Compiler: v0.8.8+commit.dddeac2f
EVM: istanbul
Optimization: Yes (999999 runs)
PToken.sol 156 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
contract PToken is ERC20, Ownable {
using SafeMath for uint;
using SafeERC20 for IERC20;
uint256 constant FEE_DENOMINATOR = 10**10;
uint256 private _withdrawFeeRate;
address private _feeCollector;
uint8 private _decimals;
uint8 private _underlyingTokenDecimals;
bool private _depositWithdrawEnabled;
address private _tokenUnderlying;
mapping (address => bool) private _authorizedCaller;
uint256 private constant MAX_WITHDRAW_FEE = 5*10**8;
event Deposit(address to, uint256 amount);
event Withdraw(address to, uint256 amount, uint256 fee);
event SetAuthorizedCaller(address caller);
event RemoveAuthorizedCaller(address caller);
event EnableDepositWithdraw();
event DisableDepositWithdraw();
event SetWithdrawFee(uint256 withdrawFeeRate, address feeCollector);
modifier onlyAuthorizedCaller() {
require(_authorizedCaller[_msgSender()],"PTOKEN: NOT_AUTHORIZED");
_;
}
modifier onlyDepositWithdrawEnabled() {
require(_depositWithdrawEnabled, "PTOKEN: Deposit and withdrawal not enabled");
_;
}
constructor (string memory name_, string memory symbol_, address tokenUnderlying_) ERC20(name_, symbol_) {
_decimals = 18;
_underlyingTokenDecimals = ERC20(tokenUnderlying_).decimals();
_tokenUnderlying = tokenUnderlying_;
_depositWithdrawEnabled = false;
}
function decimals() public view override returns (uint8) {
return _decimals;
}
function tokenUnderlying() public view returns(address) {
return _tokenUnderlying;
}
function mint(address to, uint256 amount) external onlyAuthorizedCaller {
require(amount != 0, "ERC20: zero mint amount");
_mint(to, amount);
}
function burn(uint256 amount) external onlyAuthorizedCaller {
_burn(_msgSender(), amount);
}
// deposit input amount is the original token amount
// e.g. USDT decimals is 6 , pUSDT decimals is 18
// when deposit 1$ USDT , amount is 10**6 , and you'll receive 10**18 pUSDT
function deposit(address to, uint256 amount) external onlyDepositWithdrawEnabled {
uint256 balanceBefore = IERC20(_tokenUnderlying).balanceOf(address(this));
IERC20(_tokenUnderlying).safeTransferFrom(_msgSender(), address(this), amount);
amount = IERC20(_tokenUnderlying).balanceOf(address(this)).sub(balanceBefore);
require(amount != 0, "deposit amount cannot be zero");
_mint(to, _precisionConversion(false, amount));
emit Deposit(to, amount);
}
// withdraw input amount is the ptoken amount
// e.g. USDT decimals is 6 , pUSDT decimals is 18
// when withdraw 1$ pUSDT , amount is 10**18 , and you'll receive 10**6 USDT
function withdraw(address to, uint256 amount) external onlyDepositWithdrawEnabled {
require(amount != 0, "withdraw amount cannot be zero");
_burn(_msgSender(), amount);
amount = _precisionConversion(true, amount);
require(amount != 0, "underlying token amount cannot be zero");
uint256 fee = 0;
if (_withdrawFeeRate != 0 && _feeCollector != address(0)) {
fee = amount.mul(_withdrawFeeRate).div(FEE_DENOMINATOR);
amount = amount.sub(fee);
IERC20(_tokenUnderlying).safeTransfer(_feeCollector, fee);
}
IERC20(_tokenUnderlying).safeTransfer(to, amount);
emit Withdraw(to, amount, fee);
}
function setAuthorizedCaller(address caller) external onlyOwner {
_authorizedCaller[caller] = true;
emit SetAuthorizedCaller(caller);
}
function removeAuthorizedCaller(address caller) external onlyOwner {
_authorizedCaller[caller] = false;
emit RemoveAuthorizedCaller(caller);
}
function enableDepositWithdraw() external onlyOwner {
_depositWithdrawEnabled = true;
emit EnableDepositWithdraw();
}
function disableDepositWithdraw() external onlyOwner {
_depositWithdrawEnabled = false;
emit DisableDepositWithdraw();
}
function setWithdrawFee(uint256 withdrawFeeRate_, address feeCollector_) external onlyOwner {
require(withdrawFeeRate_ <= MAX_WITHDRAW_FEE, "new withdraw fee exceeds maximum");
_withdrawFeeRate = withdrawFeeRate_;
_feeCollector = feeCollector_;
emit SetWithdrawFee(_withdrawFeeRate, _feeCollector);
}
function checkAuthorizedCaller(address caller) external view returns (bool) {
return _authorizedCaller[caller];
}
function checkIfDepositWithdrawEnabled() external view returns (bool) {
return _depositWithdrawEnabled;
}
function checkWithdrawFeeRate() external view returns (uint256) {
return _withdrawFeeRate;
}
function checkFeeCollector() external view returns (address) {
return _feeCollector;
}
function _precisionConversion(bool fromPToken, uint256 amount) internal view returns(uint256) {
if (fromPToken) {
return amount.mul(10**_underlyingTokenDecimals).div(10**_decimals);
} else {
return amount.mul(10**_decimals).div(10**_underlyingTokenDecimals);
}
}
}
Ownable.sol 64 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Address.sol 222 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
ERC20.sol 383 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* The default value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* overridden;
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, _allowances[owner][spender] + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = _allowances[owner][spender];
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `sender` to `recipient`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
}
_balances[to] += amount;
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
}
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Spend `amount` form the allowance of `owner` toward `spender`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(
address owner,
address spender,
uint256 amount
) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
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 `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, 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.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` 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 from,
address to,
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);
}
SafeMath.sol 227 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/math/SafeMath.sol)
pragma solidity ^0.8.0;
// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.
/**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the 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) {
return a + b;
}
/**
* @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 a - b;
}
/**
* @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) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting 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 a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting 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) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* 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) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}
SafeERC20.sol 99 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.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 IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
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));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
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'
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) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - 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. We use {Address.functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
IERC20Metadata.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
Read Contract
allowance 0xdd62ed3e → uint256
balanceOf 0x70a08231 → uint256
checkAuthorizedCaller 0x63813c78 → bool
checkFeeCollector 0x21a6ba5d → address
checkIfDepositWithdrawEnabled 0x7ddd28d6 → bool
checkWithdrawFeeRate 0xaa7fada5 → uint256
decimals 0x313ce567 → uint8
name 0x06fdde03 → string
owner 0x8da5cb5b → address
symbol 0x95d89b41 → string
tokenUnderlying 0xdb77e2b2 → address
totalSupply 0x18160ddd → uint256
Write Contract 15 functions
These functions modify contract state and require a wallet transaction to execute.
approve 0x095ea7b3
address spender
uint256 amount
returns: bool
burn 0x42966c68
uint256 amount
decreaseAllowance 0xa457c2d7
address spender
uint256 subtractedValue
returns: bool
deposit 0x47e7ef24
address to
uint256 amount
disableDepositWithdraw 0x9a674aca
No parameters
enableDepositWithdraw 0x1765e27c
No parameters
increaseAllowance 0x39509351
address spender
uint256 addedValue
returns: bool
mint 0x40c10f19
address to
uint256 amount
removeAuthorizedCaller 0xb7aa0231
address caller
setAuthorizedCaller 0xcf8fbec9
address caller
setWithdrawFee 0x1da7063e
uint256 withdrawFeeRate_
address feeCollector_
transfer 0xa9059cbb
address to
uint256 amount
returns: bool
transferFrom 0x23b872dd
address from
address to
uint256 amount
returns: bool
transferOwnership 0xf2fde38b
address newOwner
withdraw 0xf3fef3a3
address to
uint256 amount
Recent Transactions
No transactions found for this address