Forkchoice Ethereum Mainnet

Address Contract Partially Verified

Address 0xd75ffA16FFbCf4078d55fF246CfBA79Bb8cE3F63
Balance 0 ETH
Nonce 2
Code Size 8764 bytes
Indexed Transactions 0 (2 on-chain, 0.6% indexed)
External Etherscan · Sourcify

Contract Bytecode

8764 bytes
0x608060405234801561001057600080fd5b50600436106102115760003560e01c80637165485d11610125578063bfa65d17116100ad578063dfb84f651161007c578063dfb84f6514610444578063f4b9fa751461044c578063f77c479114610454578063f9137fcd1461045c578063fbfa77cf1461047957610211565b8063bfa65d171461040f578063bfd131f114610417578063c2a2a07b1461041f578063ce8c42e81461042757610211565b8063975057e7116100f4578063975057e7146103d25780639da1f330146103da578063a47406f0146103e2578063a950eec2146103ea578063b50303061461040757610211565b80637165485d146103585780638335fc21146103605780639137c1a71461038657806395ed7da3146103ac57610211565b806333303f8e116101a857806345d01e4a1161017757806345d01e4a146102fe5780634fa5d85414610306578063501859461461030e5780635aa6e675146103485780636f307dc31461035057610211565b806333303f8e146102de578063366cd4f3146102e65780633a7087e0146102ee5780633e413bee146102f657610211565b8063269a08d5116101e4578063269a08d5146102945780632e3f1474146102b15780632f48ab7d146102ce57806332bd678f146102d657610211565b80630240c3e9146102165780631113ef521461023a57806317e3a3d5146102725780631c13e96e1461027a575b600080fd5b61021e610481565b604080516001600160a01b039092168252519081900360200190f35b6102706004803603606081101561025057600080fd5b506001600160a01b03813581169160208101359091169060400135610499565b005b61021e6105c9565b6102826105d8565b60408051918252519081900360200190f35b610282600480360360208110156102aa57600080fd5b50356105de565b610270600480360360208110156102c757600080fd5b5035610690565b61021e610792565b61021e6107aa565b61021e6107c2565b61021e6107d1565b61021e6107e9565b61021e610801565b610282610819565b6102706109cd565b6103346004803603602081101561032457600080fd5b50356001600160a01b0316610a74565b604080519115158252519081900360200190f35b61021e610a89565b61021e610b09565b61021e610b18565b6102706004803603602081101561037657600080fd5b50356001600160a01b0316610b27565b6102706004803603602081101561039c57600080fd5b50356001600160a01b0316610c02565b61021e600480360360208110156103c257600080fd5b50356001600160a01b0316610d38565b61021e610d53565b610282610d62565b610282610d68565b6102826004803603602081101561040057600080fd5b5035610d6e565b61021e610e05565b61021e610e14565b610270610e23565b610334611043565b6102706004803603602081101561043d57600080fd5b50356110a6565b61021e6112d8565b61021e6112f0565b61021e611308565b6102826004803603602081101561047257600080fd5b5035611357565b61021e6113f4565b7345f783cce6b7ff23b2ab2d70e416cdb7d6055f5181565b600054604080516337b87c3960e21b815233600482015290516001600160a01b039092169163dee1f0e491602480820192602092909190829003018186803b1580156104e457600080fd5b505afa1580156104f8573d6000803e3d6000fd5b505050506040513d602081101561050e57600080fd5b5051610552576040805162461bcd60e51b815260206004820152600e60248201526d4e6f7420676f7665726e616e636560901b604482015290519081900360640190fd5b6001600160a01b03821660009081526008602052604090205460ff16156105aa5760405162461bcd60e51b81526004018080602001828103825260238152602001806121646023913960400191505060405180910390fd5b6105c46001600160a01b038316848363ffffffff61140316565b505050565b6005546001600160a01b031681565b600b5481565b600061068a600360009054906101000a90046001600160a01b03166001600160a01b03166377c7b8fc6040518163ffffffff1660e01b815260040160206040518083038186803b15801561063157600080fd5b505afa158015610645573d6000803e3d6000fd5b505050506040513d602081101561065b57600080fd5b505161067e670de0b6b3a764000061067286611357565b9063ffffffff61145516565b9063ffffffff6114b516565b92915050565b600054604080516337b87c3960e21b815233600482015290516001600160a01b039092169163dee1f0e491602480820192602092909190829003018186803b1580156106db57600080fd5b505afa1580156106ef573d6000803e3d6000fd5b505050506040513d602081101561070557600080fd5b5051610749576040805162461bcd60e51b815260206004820152600e60248201526d4e6f7420676f7665726e616e636560901b604482015290519081900360640190fd5b606481111561078d576040805162461bcd60e51b815260206004820152600b60248201526a06174206d6f7374203130360ac1b604482015290519081900360640190fd5b600b55565b73dac17f958d2ee523a2206206994597c13d831ec781565b73d6ad7a6750a7593e092a9b218d66c0a814a3436e81565b6003546001600160a01b031681565b7316de59092dae5ccf4a1e6439d611fd0653f0bd0181565b73df5e0e81dff6faf3a7e52ba697820c5e32d806a881565b73a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881565b60048054604080516370a0823160e01b815230938101939093525160009283926001600160a01b0316916370a0823191602480820192602092909190829003018186803b15801561086957600080fd5b505afa15801561087d573d6000803e3d6000fd5b505050506040513d602081101561089357600080fd5b50516004805460408051631df1ee3f60e21b815290519394506000936001600160a01b03909216926377c7b8fc928282019260209290829003018186803b1580156108dd57600080fd5b505afa1580156108f1573d6000803e3d6000fd5b505050506040513d602081101561090757600080fd5b50519050670de0b6b3a7640000600061092a8261067e868663ffffffff61145516565b9050600061093782611357565b600154604080516370a0823160e01b815230600482015290519293506109c2926001600160a01b03909216916370a0823191602480820192602092909190829003018186803b15801561098957600080fd5b505afa15801561099d573d6000803e3d6000fd5b505050506040513d60208110156109b357600080fd5b5051829063ffffffff6114f716565b955050505050505b90565b6002546001600160a01b03163314806109fe57506109e9611308565b6001600160a01b0316336001600160a01b0316145b80610a215750610a0c610a89565b6001600160a01b0316336001600160a01b0316145b610a5c5760405162461bcd60e51b815260040180806020018281038252603981526020018061212b6039913960400191505060405180910390fd5b610a64611551565b610a6f600a54611357565b600955565b60086020526000908152604090205460ff1681565b60008060009054906101000a90046001600160a01b03166001600160a01b0316635aa6e6756040518163ffffffff1660e01b815260040160206040518083038186803b158015610ad857600080fd5b505afa158015610aec573d6000803e3d6000fd5b505050506040513d6020811015610b0257600080fd5b5051905090565b6001546001600160a01b031681565b6006546001600160a01b031681565b600054604080516337b87c3960e21b815233600482015290516001600160a01b039092169163dee1f0e491602480820192602092909190829003018186803b158015610b7257600080fd5b505afa158015610b86573d6000803e3d6000fd5b505050506040513d6020811015610b9c57600080fd5b5051610be0576040805162461bcd60e51b815260206004820152600e60248201526d4e6f7420676f7665726e616e636560901b604482015290519081900360640190fd5b600780546001600160a01b0319166001600160a01b0392909216919091179055565b600054604080516337b87c3960e21b815233600482015290516001600160a01b039092169163dee1f0e491602480820192602092909190829003018186803b158015610c4d57600080fd5b505afa158015610c61573d6000803e3d6000fd5b505050506040513d6020811015610c7757600080fd5b5051610cbb576040805162461bcd60e51b815260206004820152600e60248201526d4e6f7420676f7665726e616e636560901b604482015290519081900360640190fd5b6001600160a01b038116610d16576040805162461bcd60e51b815260206004820152601e60248201527f6e65772073746f726167652073686f756c646e277420626520656d7074790000604482015290519081900360640190fd5b600080546001600160a01b0319166001600160a01b0392909216919091179055565b600c602052600090815260409020546001600160a01b031681565b6000546001600160a01b031681565b60095481565b600a5481565b600061068a600360009054906101000a90046001600160a01b03166001600160a01b03166377c7b8fc6040518163ffffffff1660e01b815260040160206040518083038186803b158015610dc157600080fd5b505afa158015610dd5573d6000803e3d6000fd5b505050506040513d6020811015610deb57600080fd5b505161067e84670de0b6b3a764000063ffffffff61145516565b6007546001600160a01b031681565b6004546001600160a01b031681565b6002546001600160a01b0316331480610e545750610e3f611308565b6001600160a01b0316336001600160a01b0316145b80610e775750610e62610a89565b6001600160a01b0316336001600160a01b0316145b610eb25760405162461bcd60e51b815260040180806020018281038252603981526020018061212b6039913960400191505060405180910390fd5b60048054604080516370a0823160e01b81523093810193909352516000926001600160a01b03909216916370a08231916024808301926020929190829003018186803b158015610f0157600080fd5b505afa158015610f15573d6000803e3d6000fd5b505050506040513d6020811015610f2b57600080fd5b50516004805460408051632e1a7d4d60e01b8152928301849052519293506001600160a01b031691632e1a7d4d9160248082019260009290919082900301818387803b158015610f7a57600080fd5b505af1158015610f8e573d6000803e3d6000fd5b50505050610f9d600019611686565b600154604080516370a0823160e01b815230600482015290516000926001600160a01b0316916370a08231916024808301926020929190829003018186803b158015610fe857600080fd5b505afa158015610ffc573d6000803e3d6000fd5b505050506040513d602081101561101257600080fd5b50519050801561103f5760025460015461103f916001600160a01b0391821691168363ffffffff61140316565b5050565b600080611051600a54611357565b905060095481111561108657600b5460640361107d60095461067e60648561145590919063ffffffff16565b119150506109ca565b600b5460640361107d8261067e606460095461145590919063ffffffff16565b6002546001600160a01b03163314806110d757506110c2611308565b6001600160a01b0316336001600160a01b0316145b806110fa57506110e5610a89565b6001600160a01b0316336001600160a01b0316145b6111355760405162461bcd60e51b815260040180806020018281038252603981526020018061212b6039913960400191505060405180910390fd5b60048054604080516370a0823160e01b81523093810193909352516000926001600160a01b03909216916370a08231916024808301926020929190829003018186803b15801561118457600080fd5b505afa158015611198573d6000803e3d6000fd5b505050506040513d60208110156111ae57600080fd5b50516004805460408051632e1a7d4d60e01b8152928301849052519293506001600160a01b031691632e1a7d4d9160248082019260009290919082900301818387803b1580156111fd57600080fd5b505af1158015611211573d6000803e3d6000fd5b5050505061121e82611686565b600154604080516370a0823160e01b815230600482015290516000926001600160a01b0316916370a08231916024808301926020929190829003018186803b15801561126957600080fd5b505afa15801561127d573d6000803e3d6000fd5b505050506040513d602081101561129357600080fd5b5051905080156112d0576002546112d0906001600160a01b03166112b785846119a0565b6001546001600160a01b0316919063ffffffff61140316565b6105c4611551565b7383f798e925bcd4017eb265844fddabb448f1707d81565b736b175474e89094c44da98b954eedeac495271d0f81565b60008060009054906101000a90046001600160a01b03166001600160a01b031663f77c47916040518163ffffffff1660e01b815260040160206040518083038186803b158015610ad857600080fd5b6007546001546000916001600160a01b031690638c92b130908490600160a01b900460ff16600281111561138757fe5b6040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b1580156113c257600080fd5b505afa1580156113d6573d6000803e3d6000fd5b505050506040513d60208110156113ec57600080fd5b505192915050565b6002546001600160a01b031681565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526105c49084906119b6565b6000826114645750600061068a565b8282028284828161147157fe5b04146114ae5760405162461bcd60e51b81526004018080602001828103825260218152602001806121876021913960400191505060405180910390fd5b9392505050565b60006114ae83836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250611b74565b6000828201838110156114ae576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b611559611c16565b600554604080516370a0823160e01b815230600482015290516000926001600160a01b0316916370a08231916024808301926020929190829003018186803b1580156115a457600080fd5b505afa1580156115b8573d6000803e3d6000fd5b505050506040513d60208110156115ce57600080fd5b505190508015611683576004546005546115fc916001600160a01b039182169116600063ffffffff611eaf16565b60045460055461161f916001600160a01b0391821691168363ffffffff611eaf16565b600480546040805163b6b55f2560e01b8152928301849052516001600160a01b039091169163b6b55f2591602480830192600092919082900301818387803b15801561166a57600080fd5b505af115801561167e573d6000803e3d6000fd5b505050505b50565b600554604080516370a0823160e01b815230600482015290516000926001600160a01b0316916370a08231916024808301926020929190829003018186803b1580156116d157600080fd5b505afa1580156116e5573d6000803e3d6000fd5b505050506040513d60208110156116fb57600080fd5b50519050600061170a826105de565b905080611718575050611683565b600060001984146117315761172c84610d6e565b611733565b815b905061173d61210c565b61174f61174a84846119a0565b611fc2565b600354604080516370a0823160e01b815230600482015290519293506000926001600160a01b03909216916370a0823191602480820192602092909190829003018186803b1580156117a057600080fd5b505afa1580156117b4573d6000803e3d6000fd5b505050506040513d60208110156117ca57600080fd5b50516006546005549192506117f3916001600160a01b039081169116600063ffffffff611eaf16565b600654600554611816916001600160a01b0391821691168763ffffffff611eaf16565b600654604051630c53debb60e11b81526001600160a01b03909116906318a7bd7690849088906004018083608080838360005b83811015611861578181015183820152602001611849565b5050505090500182815260200192505050600060405180830381600087803b15801561188c57600080fd5b505af11580156118a0573d6000803e3d6000fd5b5050600354604080516370a0823160e01b81523060048201529051600094506001600160a01b0390921692506370a08231916024808301926020929190829003018186803b1580156118f157600080fd5b505afa158015611905573d6000803e3d6000fd5b505050506040513d602081101561191b57600080fd5b5051905081811115611997576003546001600160a01b0316632e1a7d4d611948838563ffffffff61203416565b6040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b15801561197e57600080fd5b505af1158015611992573d6000803e3d6000fd5b505050505b50505050505050565b60008183106119af57816114ae565b5090919050565b6119c8826001600160a01b0316612076565b611a19576040805162461bcd60e51b815260206004820152601f60248201527f5361666545524332303a2063616c6c20746f206e6f6e2d636f6e747261637400604482015290519081900360640190fd5b60006060836001600160a01b0316836040518082805190602001908083835b60208310611a575780518252601f199092019160209182019101611a38565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114611ab9576040519150601f19603f3d011682016040523d82523d6000602084013e611abe565b606091505b509150915081611b15576040805162461bcd60e51b815260206004820181905260248201527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564604482015290519081900360640190fd5b805115611b6e57808060200190516020811015611b3157600080fd5b5051611b6e5760405162461bcd60e51b815260040180806020018281038252602a8152602001806121a8602a913960400191505060405180910390fd5b50505050565b60008183611c005760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611bc5578181015183820152602001611bad565b50505050905090810190601f168015611bf25780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b506000838581611c0c57fe5b0495945050505050565b600154604080516370a0823160e01b815230600482015290516000926001600160a01b0316916370a08231916024808301926020929190829003018186803b158015611c6157600080fd5b505afa158015611c75573d6000803e3d6000fd5b505050506040513d6020811015611c8b57600080fd5b505190508015611d4257600354600154611cb9916001600160a01b039182169116600063ffffffff611eaf16565b600354600154611cdc916001600160a01b0391821691168363ffffffff611eaf16565b6003546040805163b6b55f2560e01b81526004810184905290516001600160a01b039092169163b6b55f259160248082019260009290919082900301818387803b158015611d2957600080fd5b505af1158015611d3d573d6000803e3d6000fd5b505050505b600354604080516370a0823160e01b815230600482015290516000926001600160a01b0316916370a08231916024808301926020929190829003018186803b158015611d8d57600080fd5b505afa158015611da1573d6000803e3d6000fd5b505050506040513d6020811015611db757600080fd5b50519050801561103f57600654600354611de5916001600160a01b039182169116600063ffffffff611eaf16565b600654600354611e08916001600160a01b0391821691168363ffffffff611eaf16565b6000611e1261210c565b611e1b83611fc2565b60065460405162a6cbcd60e21b81529192506001600160a01b03169063029b2f3490839085906004018083608080838360005b83811015611e66578181015183820152602001611e4e565b5050505090500182815260200192505050600060405180830381600087803b158015611e9157600080fd5b505af1158015611ea5573d6000803e3d6000fd5b5050505050505050565b801580611f35575060408051636eb1769f60e11b81523060048201526001600160a01b03848116602483015291519185169163dd62ed3e91604480820192602092909190829003018186803b158015611f0757600080fd5b505afa158015611f1b573d6000803e3d6000fd5b505050506040513d6020811015611f3157600080fd5b5051155b611f705760405162461bcd60e51b81526004018080602001828103825260368152602001806121d26036913960400191505060405180910390fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b1790526105c49084906119b6565b611fca61210c565b611fd261210c565b6040518060800160405280600081526020016000815260200160008152602001600081525090508281600160149054906101000a900460ff16600281111561201657fe5b66ffffffffffffff166004811061202957fe5b602002015292915050565b60006114ae83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506120b2565b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4708181148015906120aa57508115155b949350505050565b600081848411156121045760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315611bc5578181015183820152602001611bad565b505050900390565b6040518060800160405280600490602082028038833950919291505056fe5468652073656e6465722068617320746f2062652074686520636f6e74726f6c6c65722c20676f7665726e616e63652c206f72207661756c74746f6b656e20697320646566696e6564206173206e6f742073616c7661676561626c65536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f775361666545524332303a204552433230206f7065726174696f6e20646964206e6f7420737563636565645361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f20746f206e6f6e2d7a65726f20616c6c6f77616e6365a265627a7a72315820998b86d02135963bd8a70cd9b46c488890defb6cbcfc4978ff97649ffc674c7e64736f6c63430005100032

Verified Source Code Partial Match

Compiler: v0.5.16+commit.9c3226ce EVM: istanbul Optimization: Yes (150 runs)
CRVStrategyStableMainnet.sol 1112 lines
// File: @openzeppelin/contracts/math/Math.sol

pragma solidity ^0.5.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a >= b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow, so we distribute
        return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
    }
}

// File: @openzeppelin/contracts/math/SafeMath.sol

pragma solidity ^0.5.0;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");

        return c;
    }

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

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

        return c;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
        if (a == 0) {
            return 0;
        }

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

        return c;
    }

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

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

        return c;
    }

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

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

// File: @openzeppelin/contracts/token/ERC20/IERC20.sol

pragma solidity ^0.5.0;

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

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

    /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * 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);
}

// File: @openzeppelin/contracts/utils/Address.sol

pragma solidity ^0.5.5;

/**
 * @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) {
        // According to EIP-1052, 0x0 is the value returned for not-yet created accounts
        // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
        // for accounts without code, i.e. `keccak256('')`
        bytes32 codehash;
        bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
        // solhint-disable-next-line no-inline-assembly
        assembly { codehash := extcodehash(account) }
        return (codehash != accountHash && codehash != 0x0);
    }

    /**
     * @dev Converts an `address` into `address payable`. Note that this is
     * simply a type cast: the actual underlying value is not changed.
     *
     * _Available since v2.4.0._
     */
    function toPayable(address account) internal pure returns (address payable) {
        return address(uint160(account));
    }

    /**
     * @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].
     *
     * _Available since v2.4.0._
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        // solhint-disable-next-line avoid-call-value
        (bool success, ) = recipient.call.value(amount)("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }
}

// File: @openzeppelin/contracts/token/ERC20/SafeERC20.sol

pragma solidity ^0.5.0;




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

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

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

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

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

    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 newAllowance = token.allowance(address(this), spender).sub(value, "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.

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

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

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

// File: @openzeppelin/contracts/token/ERC20/ERC20Detailed.sol

pragma solidity ^0.5.0;


/**
 * @dev Optional functions from the ERC20 standard.
 */
contract ERC20Detailed is IERC20 {
    string private _name;
    string private _symbol;
    uint8 private _decimals;

    /**
     * @dev Sets the values for `name`, `symbol`, and `decimals`. All three of
     * these values are immutable: they can only be set once during
     * construction.
     */
    constructor (string memory name, string memory symbol, uint8 decimals) public {
        _name = name;
        _symbol = symbol;
        _decimals = decimals;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view 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.
     *
     * 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 returns (uint8) {
        return _decimals;
    }
}

// File: contracts/strategies/curve/interfaces/Gauge.sol

pragma solidity 0.5.16;

interface Gauge {
    function deposit(uint) external;
    function balanceOf(address) external view returns (uint);
    function withdraw(uint) external;
}

interface Mintr {
    function mint(address) external;
}

// File: contracts/strategies/curve/interfaces/ICurveFi.sol

pragma solidity 0.5.16;

interface ICurveFi {
  function get_virtual_price() external view returns (uint);
  function add_liquidity(
    uint256[4] calldata amounts,
    uint256 min_mint_amount
  ) external;
  function remove_liquidity_imbalance(
    uint256[4] calldata amounts,
    uint256 max_burn_amount
  ) external;
  function remove_liquidity(
    uint256 _amount,
    uint256[4] calldata amounts
  ) external;
  function exchange(
    int128 from, int128 to, uint256 _from_amount, uint256 _min_to_amount
  ) external;
  function calc_token_amount(
    uint256[4] calldata amounts,
    bool deposit
  ) external view returns(uint);
}

// File: contracts/strategies/curve/interfaces/yVault.sol

pragma solidity 0.5.16;

interface yERC20 {
  function deposit(uint256 _amount) external;
  function withdraw(uint256 _amount) external;
  function getPricePerFullShare() external view returns (uint256);
}

// File: contracts/strategies/curve/interfaces/IPriceConvertor.sol

pragma solidity 0.5.16;

interface IPriceConvertor {
  function yCrvToUnderlying(uint256 _token_amount, uint256 i) external view returns (uint256);
}

// File: contracts/hardworkInterface/IVault.sol

pragma solidity 0.5.16;


interface IVault {
    // the IERC20 part is the share

    function underlyingBalanceInVault() external view returns (uint256);
    function underlyingBalanceWithInvestment() external view returns (uint256);

    function governance() external view returns (address);
    function controller() external view returns (address);
    function underlying() external view returns (address);
    function strategy() external view returns (address);

    function setStrategy(address _strategy) external;
    function setVaultFractionToInvest(uint256 numerator, uint256 denominator) external;

    function deposit(uint256 amountWei) external;
    function depositFor(uint256 amountWei, address holder) external;

    function withdrawAll() external;
    function withdraw(uint256 numberOfShares) external;
    function getPricePerFullShare() external view returns (uint256);

    function underlyingBalanceWithInvestmentForHolder(address holder) view external returns (uint256);

    // hard work should be callable only by the controller (by the hard worker) or by governance
    function doHardWork() external;
    function rebalance() external;
}

// File: contracts/hardworkInterface/IController.sol

pragma solidity 0.5.16;

interface IController {
    // [Grey list]
    // An EOA can safely interact with the system no matter what.
    // If you're using Metamask, you're using an EOA.
    // Only smart contracts may be affected by this grey list.
    //
    // This contract will not be able to ban any EOA from the system
    // even if an EOA is being added to the greyList, he/she will still be able
    // to interact with the whole system as if nothing happened.
    // Only smart contracts will be affected by being added to the greyList.
    // This grey list is only used in Vault.sol, see the code there for reference
    function greyList(address _target) external returns(bool);

    function addVaultAndStrategy(address _vault, address _strategy) external;
    function doHardWork(address _vault) external;
    function hasVault(address _vault) external returns(bool);

    function salvage(address _token, uint256 amount) external;
    function salvageStrategy(address _strategy, address _token, uint256 amount) external;

    function notifyFee(address _underlying, uint256 fee) external;
    function profitSharingNumerator() external view returns (uint256);
    function profitSharingDenominator() external view returns (uint256);
}

// File: contracts/hardworkInterface/IStrategy.sol

pragma solidity 0.5.16;


interface IStrategy {
    
    function unsalvagableTokens(address tokens) external view returns (bool);
    
    function governance() external view returns (address);
    function controller() external view returns (address);
    function underlying() external view returns (address);
    function vault() external view returns (address);

    function withdrawAllToVault() external;
    function withdrawToVault(uint256 amount) external;

    function investedUnderlyingBalance() external view returns (uint256); // itsNotMuch()

    // should only be called by controller
    function salvage(address recipient, address token, uint256 amount) external;

    function doHardWork() external;
    function depositArbCheck() external view returns(bool);
}

// File: contracts/Storage.sol

pragma solidity 0.5.16;

contract Storage {

  address public governance;
  address public controller;

  constructor() public {
    governance = msg.sender;
  }

  modifier onlyGovernance() {
    require(isGovernance(msg.sender), "Not governance");
    _;
  }

  function setGovernance(address _governance) public onlyGovernance {
    require(_governance != address(0), "new governance shouldn't be empty");
    governance = _governance;
  }

  function setController(address _controller) public onlyGovernance {
    require(_controller != address(0), "new controller shouldn't be empty");
    controller = _controller;
  }

  function isGovernance(address account) public view returns (bool) {
    return account == governance;
  }

  function isController(address account) public view returns (bool) {
    return account == controller;
  }
}

// File: contracts/Governable.sol

pragma solidity 0.5.16;


contract Governable {

  Storage public store;

  constructor(address _store) public {
    require(_store != address(0), "new storage shouldn't be empty");
    store = Storage(_store);
  }

  modifier onlyGovernance() {
    require(store.isGovernance(msg.sender), "Not governance");
    _;
  }

  function setStorage(address _store) public onlyGovernance {
    require(_store != address(0), "new storage shouldn't be empty");
    store = Storage(_store);
  }

  function governance() public view returns (address) {
    return store.governance();
  }
}

// File: contracts/Controllable.sol

pragma solidity 0.5.16;


contract Controllable is Governable {

  constructor(address _storage) Governable(_storage) public {
  }

  modifier onlyController() {
    require(store.isController(msg.sender), "Not a controller");
    _;
  }

  modifier onlyControllerOrGovernance(){
    require((store.isController(msg.sender) || store.isGovernance(msg.sender)),
      "The caller must be controller or governance");
    _;
  }

  function controller() public view returns (address) {
    return store.controller();
  }
}

// File: contracts/strategies/curve/CRVStrategyStable.sol

pragma solidity 0.5.16;















/**
* The goal of this strategy is to take a stable asset (DAI, USDC, USDT), turn it into ycrv using
* the curve mechanisms, and supply ycrv into the ycrv vault. The ycrv vault will likely not have
* a reward token distribution pool to avoid double dipping. All the calls to functions from this
* strategy will be routed to the controller which should then call the respective methods on the
* ycrv vault. This strategy will not be liquidating any yield crops (CRV), because the strategy
* of the ycrv vault will do that for us.
*/
contract CRVStrategyStable is IStrategy, Controllable {

  enum TokenIndex {DAI, USDC, USDT}

  using SafeERC20 for IERC20;
  using Address for address;
  using SafeMath for uint256;

  // underlying asset
  address public underlying;

  // the matching enum record used to determine the index
  TokenIndex tokenIndex;

  // our vault holding the underlying asset
  address public vault;

  // the y-vault (yield tokens from Curve) corresponding to our asset
  address public yVault;

  // our vault for depositing the yCRV tokens
  address public ycrvVault;

  // the address of yCRV token
  address public ycrv;

  // the address of the Curve protocol
  address public curve;

  // the address of the IPriceConvertor
  address public convertor;

  // these tokens cannot be claimed by the governance
  mapping(address => bool) public unsalvagableTokens;

  uint256 public curvePriceCheckpoint;
  uint256 public ycrvUnit;
  uint256 public arbTolerance = 3;

  modifier restricted() {
    require(msg.sender == vault || msg.sender == controller()
      || msg.sender == governance(),
      "The sender has to be the controller, governance, or vault");
    _;
  }

  constructor(
    address _storage,
    address _underlying,
    address _vault,
    address _ycrvVault,
    address _yVault,
    uint256 _tokenIndex,
    address _ycrv,
    address _curveProtocol,
    address _convertor
  )
  Controllable(_storage) public {
    vault = _vault;
    ycrvVault = _ycrvVault;
    underlying = _underlying;
    tokenIndex = TokenIndex(_tokenIndex);
    yVault = _yVault;
    ycrv = _ycrv;
    curve = _curveProtocol;
    convertor = _convertor;

    // set these tokens to be not salvageable
    unsalvagableTokens[underlying] = true;
    unsalvagableTokens[yVault] = true;
    unsalvagableTokens[ycrv] = true;
    unsalvagableTokens[ycrvVault] = true;

    ycrvUnit = 10 ** 18;
    // starting with a stable price, the mainnet will override this value
    curvePriceCheckpoint = ycrvUnit;
  }

  function depositArbCheck() public view returns(bool) {
    uint256 currentPrice = underlyingValueFromYCrv(ycrvUnit);
    if (currentPrice > curvePriceCheckpoint) {
      return currentPrice.mul(100).div(curvePriceCheckpoint) > 100 - arbTolerance;
    } else {
      return curvePriceCheckpoint.mul(100).div(currentPrice) > 100 - arbTolerance;
    }
  }

  function setArbTolerance(uint256 tolerance) external onlyGovernance {
    require(tolerance <= 100, "at most 100");
    arbTolerance = tolerance;
  }

  /**
  * Uses the Curve protocol to convert the underlying asset into yAsset and then to yCRV.
  */
  function yCurveFromUnderlying() internal {
    // convert underlying asset to yAsset
    uint256 underlyingBalance = IERC20(underlying).balanceOf(address(this));
    if (underlyingBalance > 0) {
      IERC20(underlying).safeApprove(yVault, 0);
      IERC20(underlying).safeApprove(yVault, underlyingBalance);
      yERC20(yVault).deposit(underlyingBalance);
    }
    // convert yAsset to yCRV
    uint256 yBalance = IERC20(yVault).balanceOf(address(this));
    if (yBalance > 0) {
      IERC20(yVault).safeApprove(curve, 0);
      IERC20(yVault).safeApprove(curve, yBalance);
      // we can accept 0 as minimum because this is called only by a trusted role
      uint256 minimum = 0;
      uint256[4] memory coinAmounts = wrapCoinAmount(yBalance);
      ICurveFi(curve).add_liquidity(
        coinAmounts, minimum
      );
    }
    // now we have yCRV
  }

  /**
  * Uses the Curve protocol to convert the yCRV back into the underlying asset. If it cannot acquire
  * the limit amount, it will acquire the maximum it can.
  */
  function yCurveToUnderlying(uint256 underlyingLimit) internal {
    uint256 ycrvBalance = IERC20(ycrv).balanceOf(address(this));

    // this is the maximum number of y-tokens we can get for our yCRV
    uint256 yTokenMaximumAmount = yTokenValueFromYCrv(ycrvBalance);
    if (yTokenMaximumAmount == 0) {
      return;
    }

    // ensure that we will not overflow in the conversion
    uint256 yTokenDesiredAmount = underlyingLimit == uint256(~0) ?
      yTokenMaximumAmount : yTokenValueFromUnderlying(underlyingLimit);

    uint256[4] memory yTokenAmounts = wrapCoinAmount(
      Math.min(yTokenMaximumAmount, yTokenDesiredAmount));
    uint256 yUnderlyingBalanceBefore = IERC20(yVault).balanceOf(address(this));
    IERC20(ycrv).safeApprove(curve, 0);
    IERC20(ycrv).safeApprove(curve, ycrvBalance);
    ICurveFi(curve).remove_liquidity_imbalance(
      yTokenAmounts, ycrvBalance
    );
    // now we have yUnderlying asset
    uint256 yUnderlyingBalanceAfter = IERC20(yVault).balanceOf(address(this));
    if (yUnderlyingBalanceAfter > yUnderlyingBalanceBefore) {
      // we received new yUnderlying tokens for yCRV
      yERC20(yVault).withdraw(yUnderlyingBalanceAfter.sub(yUnderlyingBalanceBefore));
    }
  }

  /**
  * Withdraws an underlying asset from the strategy to the vault in the specified amount by asking
  * the yCRV vault for yCRV (currently all of it), and then removing imbalanced liquidity from
  * the Curve protocol. The rest is deposited back to the yCRV vault. If the amount requested cannot
  * be obtained, the method will get as much as we have.
  */
  function withdrawToVault(uint256 amountUnderlying) external restricted {
    // todo: If we want to be more accurate, we need to calculate how much yCRV we will need here
    uint256 shares = IERC20(ycrvVault).balanceOf(address(this));
    IVault(ycrvVault).withdraw(shares);
    yCurveToUnderlying(amountUnderlying);
    // we can transfer the asset to the vault
    uint256 actualBalance = IERC20(underlying).balanceOf(address(this));
    if (actualBalance > 0) {
      IERC20(underlying).safeTransfer(vault, Math.min(amountUnderlying, actualBalance));
    }

    // invest back the rest
    investAllUnderlying();
  }

  /**
  * Withdraws all assets from the vault. We ask the yCRV vault to give us our entire yCRV balance
  * and then convert it to the underlying asset using the Curve protocol.
  */
  function withdrawAllToVault() external restricted {
    uint256 shares = IERC20(ycrvVault).balanceOf(address(this));
    IVault(ycrvVault).withdraw(shares);
    // withdraw everything until there is only dust left
    yCurveToUnderlying(uint256(~0));
    uint256 actualBalance = IERC20(underlying).balanceOf(address(this));
    if (actualBalance > 0) {
      IERC20(underlying).safeTransfer(vault, actualBalance);
    }
  }

  /**
  * Invests all underlying assets into our yCRV vault.
  */
  function investAllUnderlying() internal {
    // convert the entire balance not yet invested into yCRV first
    yCurveFromUnderlying();

    // then deposit into the yCRV vault
    uint256 ycrvBalance = IERC20(ycrv).balanceOf(address(this));
    if (ycrvBalance > 0) {
      IERC20(ycrv).safeApprove(ycrvVault, 0);
      IERC20(ycrv).safeApprove(ycrvVault, ycrvBalance);
      // deposits the entire balance and also asks the vault to invest it (public function)
      IVault(ycrvVault).deposit(ycrvBalance);
    }
  }

  /**
  * The hard work only invests all underlying assets, and then tells the controller to call hard
  * work on the yCRV vault.
  */
  function doHardWork() public restricted {
    investAllUnderlying();
    curvePriceCheckpoint = underlyingValueFromYCrv(ycrvUnit);
  }

  /**
  * Salvages a token. We cannot salvage the shares in the yCRV pool, yCRV tokens, or underlying
  * assets.
  */
  function salvage(address recipient, address token, uint256 amount) public onlyGovernance {
    // To make sure that governance cannot come in and take away the coins
    require(!unsalvagableTokens[token], "token is defined as not salvageable");
    IERC20(token).safeTransfer(recipient, amount);
  }

  /**
  * Returns the underlying invested balance. This is the amount of yCRV that we are entitled to
  * from the yCRV vault (based on the number of shares we currently have), converted to the
  * underlying assets by the Curve protocol, plus the current balance of the underlying assets.
  */
  function investedUnderlyingBalance() public view returns (uint256) {
    uint256 shares = IERC20(ycrvVault).balanceOf(address(this));
    uint256 price = IVault(ycrvVault).getPricePerFullShare();
    // the price is in yCRV units, because this is a yCRV vault
    // the multiplication doubles the number of decimals for shares, so we need to divide
    // the precision is always 10 ** 18 as the yCRV vault has 18 decimals
    uint256 precision = 10 ** 18;
    uint256 ycrvBalance = shares.mul(price).div(precision);
    // now we can convert the balance to the token amount
    uint256 ycrvValue = underlyingValueFromYCrv(ycrvBalance);
    return ycrvValue.add(IERC20(underlying).balanceOf(address(this)));
  }

  /**
  * Returns the value of yCRV in underlying token accounting for slippage and fees.
  */
  function yTokenValueFromYCrv(uint256 ycrvBalance) public view returns (uint256) {
    return underlyingValueFromYCrv(ycrvBalance) // this is in DAI, we will convert to yDAI
    .mul(10 ** 18)
    .div(yERC20(yVault).getPricePerFullShare()); // function getPricePerFullShare() has 18 decimals for all tokens
  }

  /**
  * Returns the value of yCRV in y-token (e.g., yCRV -> yDai) accounting for slippage and fees.
  */
  function underlyingValueFromYCrv(uint256 ycrvBalance) public view returns (uint256) {
    return IPriceConvertor(convertor).yCrvToUnderlying(ycrvBalance, uint256(tokenIndex));
  }

  /**
  * Returns the value of the underlying token in yToken
  */
  function yTokenValueFromUnderlying(uint256 amountUnderlying) public view returns (uint256) {
    // 1 yToken = this much underlying, 10 ** 18 precision for all tokens
    return amountUnderlying
      .mul(10 ** 18)
      .div(yERC20(yVault).getPricePerFullShare());
  }

  /**
  * Wraps the coin amount in the array for interacting with the Curve protocol
  */
  function wrapCoinAmount(uint256 amount) internal view returns (uint256[4] memory) {
    uint256[4] memory amounts = [uint256(0), uint256(0), uint256(0), uint256(0)];
    amounts[uint56(tokenIndex)] = amount;
    return amounts;
  }

  /**
  * Replaces the price convertor
  */
  function setConvertor(address _convertor) public onlyGovernance {
    // different price conversion from yCurve to yToken can help in emergency recovery situation
    // or if there is a bug discovered in the price computation
    convertor = _convertor;
  }
}

// File: contracts/strategies/curve/PriceConvertor.sol

pragma solidity 0.5.16;


interface IConvertor {
  function calc_withdraw_one_coin(uint256 _token_amount, int128 i) external view returns (uint256);
}

contract PriceConvertor is IPriceConvertor {

  IConvertor public zap = IConvertor(0xbBC81d23Ea2c3ec7e56D39296F0cbB648873a5d3);

  function yCrvToUnderlying(uint256 _token_amount, uint256 i) public view returns (uint256) {
    // this returning the DAI amount, not yDAI
    return zap.calc_withdraw_one_coin(_token_amount, int128(i));
  }
}

contract MockPriceConvertor is IPriceConvertor {
  function yCrvToUnderlying(uint256 _token_amount, uint256 /* i */) public view returns (uint256) {
    // counting 1:1
    return _token_amount;
  }
}

// File: contracts/strategies/curve/CRVStrategyStableMainnet.sol

pragma solidity 0.5.16;



/**
* Adds the mainnet addresses to the CRVStrategyStable
*/
contract CRVStrategyStableMainnet is CRVStrategyStable {

  // token addresses
  // y-addresses are taken from: https://docs.yearn.finance/yearn.finance/yearn-1
  address constant public dai = address(0x6B175474E89094C44Da98b954EedeAC495271d0F);
  address constant public ydai = address(0x16de59092dAE5CcF4A1E6439D611fd0653f0Bd01);
  address constant public usdc = address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);
  address constant public yusdc = address(0xd6aD7a6750A7593E092a9B218d66C0A814a3436e);
  address constant public usdt = address(0xdAC17F958D2ee523a2206206994597C13D831ec7);
  address constant public yusdt = address(0x83f798e925BcD4017Eb265844FDDAbb448f1707D);

  // pre-defined constant mapping: underlying -> y-token
  mapping(address => address) public yVaults;

  // yDAIyUSDCyUSDTyTUSD
  address constant public __ycrv = address(0xdF5e0e81Dff6FAF3A7e52BA697820c5e32D806A8);

  // protocols
  address constant public __curve = address(0x45F783CCE6B7FF23B2ab2D70e416cdb7D6055f51);

  constructor(
    address _storage,
    address _underlying,
    address _vault,
    address _ycrvVault
  )
  CRVStrategyStable(_storage, _underlying, _vault, _ycrvVault, address(0), 0,
    __ycrv,
    __curve,
    address(0)
  )
  public {
    yVaults[dai] = ydai;
    yVaults[usdc] = yusdc;
    yVaults[usdt] = yusdt;
    yVault = yVaults[underlying];
    require(yVault != address(0), "underlying not supported: yVault is not defined");
    if (_underlying == dai) {
      tokenIndex = TokenIndex.DAI;
    } else if (_underlying == usdc) {
      tokenIndex = TokenIndex.USDC;
    } else if (_underlying == usdt) {
      tokenIndex = TokenIndex.USDT;
    } else {
      revert("What is this asset?");
    }
    convertor = address(new PriceConvertor());
    curvePriceCheckpoint = underlyingValueFromYCrv(ycrvUnit);
  }
}

Read Contract

__curve 0x0240c3e9 → address
__ycrv 0x3a7087e0 → address
arbTolerance 0x1c13e96e → uint256
controller 0xf77c4791 → address
convertor 0xb5030306 → address
curve 0x7165485d → address
curvePriceCheckpoint 0x9da1f330 → uint256
dai 0xf4b9fa75 → address
depositArbCheck 0xc2a2a07b → bool
governance 0x5aa6e675 → address
investedUnderlyingBalance 0x45d01e4a → uint256
store 0x975057e7 → address
underlying 0x6f307dc3 → address
underlyingValueFromYCrv 0xf9137fcd → uint256
unsalvagableTokens 0x50185946 → bool
usdc 0x3e413bee → address
usdt 0x2f48ab7d → address
vault 0xfbfa77cf → address
yTokenValueFromUnderlying 0xa950eec2 → uint256
yTokenValueFromYCrv 0x269a08d5 → uint256
yVault 0x33303f8e → address
yVaults 0x95ed7da3 → address
ycrv 0x17e3a3d5 → address
ycrvUnit 0xa47406f0 → uint256
ycrvVault 0xbfa65d17 → address
ydai 0x366cd4f3 → address
yusdc 0x32bd678f → address
yusdt 0xdfb84f65 → address

Write Contract 7 functions

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

doHardWork 0x4fa5d854
No parameters
salvage 0x1113ef52
address recipient
address token
uint256 amount
setArbTolerance 0x2e3f1474
uint256 tolerance
setConvertor 0x8335fc21
address _convertor
setStorage 0x9137c1a7
address _store
withdrawAllToVault 0xbfd131f1
No parameters
withdrawToVault 0xce8c42e8
uint256 amountUnderlying

Recent Transactions

This address has 2 on-chain transactions, but only 0.6% of the chain is indexed. Transactions will appear as indexing progresses. View on Etherscan →