Address Contract Partially Verified
Address
0x8897cA3e1B9BC5D5D715b653f186Cc7767bD4c66
Balance
0 ETH
Nonce
1
Code Size
8519 bytes
Creator
0xB593d82d...C835 at tx 0x380b1777...7a579d
Indexed Transactions
0
Contract Bytecode
8519 bytes
0x608060405234801561001057600080fd5b50600436106101a95760003560e01c806370a08231116100f9578063c884ef8311610097578063e58bb63911610071578063e58bb63914610569578063ebf0c71714610571578063f235757f14610579578063f5e5602d1461059f576101a9565b8063c884ef831461050d578063dd62ed3e14610533578063e3056a3414610561576101a9565b806395d89b41116100d357806395d89b4114610490578063a457c2d714610498578063a9059cbb146104c4578063b6b55f25146104f0576101a9565b806370a08231146104455780638406c0791461046b5780638ad96d7d14610473576101a9565b80632e1a7d4d11610166578063395093511161014057806339509351146103e3578063633156371461040f5780636548e9bc1461041757806369e527da1461043d576101a9565b80632e1a7d4d146102fe5780632f52ebb71461031b578063313ce567146103c5576101a9565b806306fdde03146101ae578063095ea7b31461022b5780630c340a241461026b57806318160ddd1461028f57806321ff9970146102a957806323b872dd146102c8575b600080fd5b6101b661064b565b6040805160208082528351818301528351919283929083019185019080838360005b838110156101f05781810151838201526020016101d8565b50505050905090810190601f16801561021d5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102576004803603604081101561024157600080fd5b506001600160a01b0381351690602001356106e1565b604080519115158252519081900360200190f35b6102736106fe565b604080516001600160a01b039092168252519081900360200190f35b610297610713565b60408051918252519081900360200190f35b6102c6600480360360208110156102bf57600080fd5b5035610719565b005b610257600480360360608110156102de57600080fd5b506001600160a01b03813581169160208101359091169060400135610783565b6102c66004803603602081101561031457600080fd5b503561080b565b6102c66004803603604081101561033157600080fd5b8135919081019060408101602082013564010000000081111561035357600080fd5b82018360208201111561036557600080fd5b8035906020019184602083028401116401000000008311171561038757600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550610ac8945050505050565b6103cd610c49565b6040805160ff9092168252519081900360200190f35b610257600480360360408110156103f957600080fd5b506001600160a01b038135169060200135610c52565b610273610ca0565b6102c66004803603602081101561042d57600080fd5b50356001600160a01b0316610cc4565b610273610d3e565b6102976004803603602081101561045b57600080fd5b50356001600160a01b0316610d62565b610273610d7d565b6102c66004803603602081101561048957600080fd5b5035610d8c565b6101b6610e1b565b610257600480360360408110156104ae57600080fd5b506001600160a01b038135169060200135610e7c565b610257600480360360408110156104da57600080fd5b506001600160a01b038135169060200135610ee4565b6102c66004803603602081101561050657600080fd5b5035610ef8565b6102976004803603602081101561052357600080fd5b50356001600160a01b03166112e8565b6102976004803603604081101561054957600080fd5b506001600160a01b03813581169160200135166112fa565b610273611325565b6102c6611334565b6102976113f6565b6102c66004803603602081101561058f57600080fd5b50356001600160a01b03166113fc565b6102c6600480360360608110156105b557600080fd5b813591908101906040810160208201356401000000008111156105d757600080fd5b8201836020820111156105e957600080fd5b8035906020019184602083028401116401000000008311171561060b57600080fd5b91908080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525092955050913592506114a8915050565b60458054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156106d75780601f106106ac576101008083540402835291602001916106d7565b820191906000526020600020905b8154815290600101906020018083116106ba57829003601f168201915b5050505050905090565b60006106f56106ee6115f0565b84846115f4565b50600192915050565b6000546201000090046001600160a01b031681565b60445490565b6049546001600160a01b031633148061074257506000546201000090046001600160a01b031633145b61077e576040805162461bcd60e51b815260206004820152600860248201526710b932b630bcb2b960c11b604482015290519081900360640190fd5b604a55565b60006107908484846116e0565b6108008461079c6115f0565b6107fb85604051806060016040528060288152602001611ffb602891396001600160a01b038a166000908152604360205260408120906107da6115f0565b6001600160a01b03168152602081019190915260400160002054919061183d565b6115f4565b5060015b9392505050565b60026048541415610863576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b600260485561087233826118d4565b60007f00000000000000000000000057ab1ec28d129707052df4df418d58a2d46d5f516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b1580156108e157600080fd5b505afa1580156108f5573d6000803e3d6000fd5b505050506040513d602081101561090b57600080fd5b50516040805163db006a7560e01b81526004810185905290519192506001600160a01b037f000000000000000000000000a7c4054afd3dbbbf5bfe80f41862b89ea05c9806169163db006a75916024808201926020929091908290030181600087803b15801561097a57600080fd5b505af115801561098e573d6000803e3d6000fd5b505050506040513d60208110156109a457600080fd5b5051156109e2576040805162461bcd60e51b81526020600482015260076024820152662172656465656d60c81b604482015290519081900360640190fd5b60007f00000000000000000000000057ab1ec28d129707052df4df418d58a2d46d5f516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b158015610a5157600080fd5b505afa158015610a65573d6000803e3d6000fd5b505050506040513d6020811015610a7b57600080fd5b50519050610abe33610a8d83856119d0565b6001600160a01b037f00000000000000000000000057ab1ec28d129707052df4df418d58a2d46d5f51169190611a2d565b5050600160485550565b60026048541415610b20576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b6002604855604080513360601b60208083019190915260348083018690528351808403909101815260549092019092528051910120604a54610b6490839083611a7f565b610b9e576040805162461bcd60e51b815260206004820152600660248201526510b83937b7b360d11b604482015290519081900360640190fd5b336000908152604b6020526040812054610bb99085906119d0565b336000818152604b60205260409020869055909150610c03907f00000000000000000000000057ab1ec28d129707052df4df418d58a2d46d5f516001600160a01b03169083611a2d565b604080513381526020810183905281517f47cee97cb7acd717b3c0aa1435d004cd5b3c8c57d70dbceb4e4458bbd60e39d4929181900390910190a1505060016048555050565b60475460ff1690565b60006106f5610c5f6115f0565b846107fb8560436000610c706115f0565b6001600160a01b03908116825260208083019390935260409182016000908120918c168152925290205490611b28565b7f00000000000000000000000057ab1ec28d129707052df4df418d58a2d46d5f5181565b6000546201000090046001600160a01b03163314610d1c576040805162461bcd60e51b815260206004820152601060248201526f3737ba103a34329033b7bb32b93737b960811b604482015290519081900360640190fd5b604980546001600160a01b0319166001600160a01b0392909216919091179055565b7f000000000000000000000000a7c4054afd3dbbbf5bfe80f41862b89ea05c980681565b6001600160a01b031660009081526042602052604090205490565b6049546001600160a01b031681565b6000546201000090046001600160a01b03163314610de4576040805162461bcd60e51b815260206004820152601060248201526f3737ba103a34329033b7bb32b93737b960811b604482015290519081900360640190fd5b610e186001600160a01b037f00000000000000000000000057ab1ec28d129707052df4df418d58a2d46d5f51163383611a2d565b50565b60468054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156106d75780601f106106ac576101008083540402835291602001916106d7565b60006106f5610e896115f0565b846107fb856040518060600160405280602581526020016120ed6025913960436000610eb36115f0565b6001600160a01b03908116825260208083019390935260409182016000908120918d1681529252902054919061183d565b60006106f5610ef16115f0565b84846116e0565b60026048541415610f50576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b6002604855604080516370a0823160e01b815230600482015290516000916001600160a01b037f00000000000000000000000057ab1ec28d129707052df4df418d58a2d46d5f5116916370a0823191602480820192602092909190829003018186803b158015610fbf57600080fd5b505afa158015610fd3573d6000803e3d6000fd5b505050506040513d6020811015610fe957600080fd5b505190506110226001600160a01b037f00000000000000000000000057ab1ec28d129707052df4df418d58a2d46d5f5116333085611b82565b60007f00000000000000000000000057ab1ec28d129707052df4df418d58a2d46d5f516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b15801561109157600080fd5b505afa1580156110a5573d6000803e3d6000fd5b505050506040513d60208110156110bb57600080fd5b5051604080516370a0823160e01b815230600482015290519192506000916001600160a01b037f000000000000000000000000a7c4054afd3dbbbf5bfe80f41862b89ea05c980616916370a08231916024808301926020929190829003018186803b15801561112957600080fd5b505afa15801561113d573d6000803e3d6000fd5b505050506040513d602081101561115357600080fd5b505190506001600160a01b037f000000000000000000000000a7c4054afd3dbbbf5bfe80f41862b89ea05c98061663a0712d6861119084866119d0565b6040518263ffffffff1660e01b815260040180828152602001915050602060405180830381600087803b1580156111c657600080fd5b505af11580156111da573d6000803e3d6000fd5b505050506040513d60208110156111f057600080fd5b50511561122c576040805162461bcd60e51b8152602060048201526005602482015264085b5a5b9d60da1b604482015290519081900360640190fd5b60007f000000000000000000000000a7c4054afd3dbbbf5bfe80f41862b89ea05c98066001600160a01b03166370a08231306040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b15801561129b57600080fd5b505afa1580156112af573d6000803e3d6000fd5b505050506040513d60208110156112c557600080fd5b505190506112dc336112d783856119d0565b611be2565b50506001604855505050565b604b6020526000908152604090205481565b6001600160a01b03918216600090815260436020908152604080832093909416825291909152205490565b6001546001600160a01b031681565b6001546001600160a01b03163314611393576040805162461bcd60e51b815260206004820152601860248201527f6e6f74207468652070656e64696e6720676f7665726e6f720000000000000000604482015290519081900360640190fd5b600180546001600160a01b03191690556000805462010000600160b01b031916336201000081029190911790915560408051918252517fd345d81ce68c70b119a17eee79dc1421700bd9cb21ca148a62dc90983964e82f916020908290030190a1565b604a5481565b6000546201000090046001600160a01b03163314611454576040805162461bcd60e51b815260206004820152601060248201526f3737ba103a34329033b7bb32b93737b960811b604482015290519081900360640190fd5b600180546001600160a01b0383166001600160a01b0319909116811790915560408051918252517f964dea888b00b2ab53f13dfe7ca334b46e99338c222ae232d98547a1da019f609181900360200190a150565b6114b28383610ac8565b6114bb8161080b565b505050565b801580611546575060408051636eb1769f60e11b81523060048201526001600160a01b03848116602483015291519185169163dd62ed3e91604480820192602092909190829003018186803b15801561151857600080fd5b505afa15801561152c573d6000803e3d6000fd5b505050506040513d602081101561154257600080fd5b5051155b6115815760405162461bcd60e51b81526004018080602001828103825260368152602001806120b76036913960400191505060405180910390fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b1790526114bb908490611cd4565b3b151590565b60606115e88484600085611d85565b949350505050565b3390565b6001600160a01b0383166116395760405162461bcd60e51b81526004018080602001828103825260248152602001806120696024913960400191505060405180910390fd5b6001600160a01b03821661167e5760405162461bcd60e51b8152600401808060200182810382526022815260200180611f8d6022913960400191505060405180910390fd5b6001600160a01b03808416600081815260436020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b0383166117255760405162461bcd60e51b81526004018080602001828103825260258152602001806120446025913960400191505060405180910390fd5b6001600160a01b03821661176a5760405162461bcd60e51b8152600401808060200182810382526023815260200180611f486023913960400191505060405180910390fd5b6117758383836114bb565b6117b281604051806060016040528060268152602001611faf602691396001600160a01b038616600090815260426020526040902054919061183d565b6001600160a01b0380851660009081526042602052604080822093909355908416815220546117e19082611b28565b6001600160a01b0380841660008181526042602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600081848411156118cc5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611891578181015183820152602001611879565b50505050905090810190601f1680156118be5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6001600160a01b0382166119195760405162461bcd60e51b81526004018080602001828103825260218152602001806120236021913960400191505060405180910390fd5b611925826000836114bb565b61196281604051806060016040528060228152602001611f6b602291396001600160a01b038516600090815260426020526040902054919061183d565b6001600160a01b03831660009081526042602052604090205560445461198890826119d0565b6044556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b600082821115611a27576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526114bb908490611cd4565b600081815b8551811015611b1d576000868281518110611a9b57fe5b60200260200101519050808311611ae25782816040516020018083815260200182815260200192505050604051602081830303815290604052805190602001209250611b14565b808360405160200180838152602001828152602001925050506040516020818303038152906040528051906020012092505b50600101611a84565b509092149392505050565b600082820183811015610804576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b604080516001600160a01b0380861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b179052611bdc908590611cd4565b50505050565b6001600160a01b038216611c3d576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b611c49600083836114bb565b604454611c569082611b28565b6044556001600160a01b038216600090815260426020526040902054611c7c9082611b28565b6001600160a01b03831660008181526042602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b6060611d29826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166115d99092919063ffffffff16565b8051909150156114bb57808060200190516020811015611d4857600080fd5b50516114bb5760405162461bcd60e51b815260040180806020018281038252602a81526020018061208d602a913960400191505060405180910390fd5b606082471015611dc65760405162461bcd60e51b8152600401808060200182810382526026815260200180611fd56026913960400191505060405180910390fd5b611dcf856115d3565b611e20576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b60006060866001600160a01b031685876040518082805190602001908083835b60208310611e5f5780518252601f199092019160209182019101611e40565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114611ec1576040519150601f19603f3d011682016040523d82523d6000602084013e611ec6565b606091505b5091509150611ed6828286611ee1565b979650505050505050565b60608315611ef0575081610804565b825115611f005782518084602001fd5b60405162461bcd60e51b815260206004820181815284516024840152845185939192839260440191908501908083836000831561189157818101518382015260200161187956fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e6365416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f20616464726573735361666545524332303a204552433230206f7065726174696f6e20646964206e6f7420737563636565645361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f20746f206e6f6e2d7a65726f20616c6c6f77616e636545524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa26469706673582212202a8b24a38863836f544cb92622b5cdd8ae21d3df690341b9f4c04bd6b50c5c7164736f6c634300060c0033
Verified Source Code Partial Match
Compiler: v0.6.12+commit.27d51765
EVM: istanbul
Optimization: Yes (200 runs)
SafeBox.sol 1160 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.6.12;
// Part: ICErc20
interface ICErc20 {
function decimals() external returns (uint8);
function underlying() external returns (address);
function mint(uint mintAmount) external returns (uint);
function redeem(uint redeemTokens) external returns (uint);
function balanceOf(address user) external view returns (uint);
function borrowBalanceCurrent(address account) external returns (uint);
function borrowBalanceStored(address account) external view returns (uint);
function borrow(uint borrowAmount) external returns (uint);
function repayBorrow(uint repayAmount) external returns (uint);
}
// Part: OpenZeppelin/[email protected]/Address
/**
* @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
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on 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;
}
/**
* @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");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(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");
// solhint-disable-next-line avoid-low-level-calls
(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");
// solhint-disable-next-line avoid-low-level-calls
(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");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private 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
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// Part: OpenZeppelin/[email protected]/Context
/*
* @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 GSN 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 payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
// Part: OpenZeppelin/[email protected]/IERC20
/**
* @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 `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.
*
* 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 `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);
}
// Part: OpenZeppelin/[email protected]/MerkleProof
/**
* @dev These functions deal with verification of Merkle trees (hash trees),
*/
library MerkleProof {
/**
* @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
* defined by `root`. For this, a `proof` must be provided, containing
* sibling hashes on the branch from the leaf to the root of the tree. Each
* pair of leaves and each pair of pre-images are assumed to be sorted.
*/
function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
bytes32 proofElement = proof[i];
if (computedHash <= proofElement) {
// Hash(current computed hash + current element of the proof)
computedHash = keccak256(abi.encodePacked(computedHash, proofElement));
} else {
// Hash(current element of the proof + current computed hash)
computedHash = keccak256(abi.encodePacked(proofElement, computedHash));
}
}
// Check if the computed hash (root) is equal to the provided root
return computedHash == root;
}
}
// Part: OpenZeppelin/[email protected]/ReentrancyGuard
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor () internal {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and make it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
// Part: OpenZeppelin/[email protected]/SafeMath
/**
* @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, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
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) {
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) {
// 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) {
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) {
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) {
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");
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) {
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, reverting 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) {
require(b > 0, "SafeMath: division by zero");
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) {
require(b > 0, "SafeMath: modulo by zero");
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) {
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.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
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) {
require(b > 0, errorMessage);
return a % b;
}
}
// Part: OpenZeppelin/[email protected]/ERC20
/**
* @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 guidelines: functions revert instead
* of 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 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name_, string memory symbol_) public {
_name = name_;
_symbol = symbol_;
_decimals = 18;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual 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 {_setupDecimals} is
* called.
*
* 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 returns (uint8) {
return _decimals;
}
/**
* @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:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, 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}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), 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}.
*
* Requirements:
*
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
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) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(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) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is 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:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, 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:
*
* - `to` 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 = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(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);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(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 Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/
function _setupDecimals(uint8 decimals_) internal virtual {
_decimals = decimals_;
}
/**
* @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 to 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 { }
}
// Part: OpenZeppelin/[email protected]/Initializable
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
*/
bool private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Modifier to protect an initializer function from being invoked twice.
*/
modifier initializer() {
require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized");
bool isTopLevelCall = !_initializing;
if (isTopLevelCall) {
_initializing = true;
_initialized = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
}
}
/// @dev Returns true if and only if the function is running in the constructor
function _isConstructor() private view returns (bool) {
return !Address.isContract(address(this));
}
}
// Part: OpenZeppelin/[email protected]/SafeERC20
/**
* @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 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));
}
/**
* @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'
// 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, "SafeERC20: decreased allowance below zero");
_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
// solhint-disable-next-line max-line-length
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
// Part: Governable
contract Governable is Initializable {
event SetGovernor(address governor);
event SetPendingGovernor(address pendingGovernor);
event AcceptGovernor(address governor);
address public governor; // The current governor.
address public pendingGovernor; // The address pending to become the governor once accepted.
bytes32[64] _gap; // reserve space for upgrade
modifier onlyGov() {
require(msg.sender == governor, 'not the governor');
_;
}
/// @dev Initialize using msg.sender as the first governor.
function __Governable__init() internal initializer {
governor = msg.sender;
pendingGovernor = address(0);
emit SetGovernor(msg.sender);
}
/// @dev Set the pending governor, which will be the governor once accepted.
/// @param _pendingGovernor The address to become the pending governor.
function setPendingGovernor(address _pendingGovernor) external onlyGov {
pendingGovernor = _pendingGovernor;
emit SetPendingGovernor(_pendingGovernor);
}
/// @dev Accept to become the new governor. Must be called by the pending governor.
function acceptGovernor() external {
require(msg.sender == pendingGovernor, 'not the pending governor');
pendingGovernor = address(0);
governor = msg.sender;
emit AcceptGovernor(msg.sender);
}
}
// File: SafeBox.sol
contract SafeBox is Governable, ERC20, ReentrancyGuard {
using SafeMath for uint;
using SafeERC20 for IERC20;
event Claim(address user, uint amount);
ICErc20 public immutable cToken;
IERC20 public immutable uToken;
address public relayer;
bytes32 public root;
mapping(address => uint) public claimed;
constructor(
ICErc20 _cToken,
string memory _name,
string memory _symbol
) public ERC20(_name, _symbol) {
_setupDecimals(_cToken.decimals());
IERC20 _uToken = IERC20(_cToken.underlying());
__Governable__init();
cToken = _cToken;
uToken = _uToken;
relayer = msg.sender;
_uToken.safeApprove(address(_cToken), uint(-1));
}
function setRelayer(address _relayer) external onlyGov {
relayer = _relayer;
}
function updateRoot(bytes32 _root) external {
require(msg.sender == relayer || msg.sender == governor, '!relayer');
root = _root;
}
function deposit(uint amount) external nonReentrant {
uint uBalanceBefore = uToken.balanceOf(address(this));
uToken.safeTransferFrom(msg.sender, address(this), amount);
uint uBalanceAfter = uToken.balanceOf(address(this));
uint cBalanceBefore = cToken.balanceOf(address(this));
require(cToken.mint(uBalanceAfter.sub(uBalanceBefore)) == 0, '!mint');
uint cBalanceAfter = cToken.balanceOf(address(this));
_mint(msg.sender, cBalanceAfter.sub(cBalanceBefore));
}
function withdraw(uint amount) public nonReentrant {
_burn(msg.sender, amount);
uint uBalanceBefore = uToken.balanceOf(address(this));
require(cToken.redeem(amount) == 0, '!redeem');
uint uBalanceAfter = uToken.balanceOf(address(this));
uToken.safeTransfer(msg.sender, uBalanceAfter.sub(uBalanceBefore));
}
function claim(uint totalAmount, bytes32[] memory proof) public nonReentrant {
bytes32 leaf = keccak256(abi.encodePacked(msg.sender, totalAmount));
require(MerkleProof.verify(proof, root, leaf), '!proof');
uint send = totalAmount.sub(claimed[msg.sender]);
claimed[msg.sender] = totalAmount;
uToken.safeTransfer(msg.sender, send);
emit Claim(msg.sender, send);
}
function adminClaim(uint amount) external onlyGov {
uToken.safeTransfer(msg.sender, amount);
}
function claimAndWithdraw(
uint totalAmount,
bytes32[] memory proof,
uint withdrawAmount
) external {
claim(totalAmount, proof);
withdraw(withdrawAmount);
}
}
Read Contract
allowance 0xdd62ed3e → uint256
balanceOf 0x70a08231 → uint256
cToken 0x69e527da → address
claimed 0xc884ef83 → uint256
decimals 0x313ce567 → uint8
governor 0x0c340a24 → address
name 0x06fdde03 → string
pendingGovernor 0xe3056a34 → address
relayer 0x8406c079 → address
root 0xebf0c717 → bytes32
symbol 0x95d89b41 → string
totalSupply 0x18160ddd → uint256
uToken 0x63315637 → address
Write Contract 14 functions
These functions modify contract state and require a wallet transaction to execute.
acceptGovernor 0xe58bb639
No parameters
adminClaim 0x8ad96d7d
uint256 amount
approve 0x095ea7b3
address spender
uint256 amount
returns: bool
claim 0x2f52ebb7
uint256 totalAmount
bytes32[] proof
claimAndWithdraw 0xf5e5602d
uint256 totalAmount
bytes32[] proof
uint256 withdrawAmount
decreaseAllowance 0xa457c2d7
address spender
uint256 subtractedValue
returns: bool
deposit 0xb6b55f25
uint256 amount
increaseAllowance 0x39509351
address spender
uint256 addedValue
returns: bool
setPendingGovernor 0xf235757f
address _pendingGovernor
setRelayer 0x6548e9bc
address _relayer
transfer 0xa9059cbb
address recipient
uint256 amount
returns: bool
transferFrom 0x23b872dd
address sender
address recipient
uint256 amount
returns: bool
updateRoot 0x21ff9970
bytes32 _root
withdraw 0x2e1a7d4d
uint256 amount
Recent Transactions
No transactions found for this address