Cryo Explorer Ethereum Mainnet

Address Contract Partially Verified

Address 0x9D7e85d095934471a2788F485A3c765d0A463bD7
Balance 0 ETH
Nonce 1
Code Size 10580 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

10580 bytes
0x608060405234801561001057600080fd5b506004361061027f5760003560e01c8063715018a61161015c578063ad5c4648116100ce578063dd62ed3e11610087578063dd62ed3e14610770578063e71bdf411461079e578063e80c72c0146107c4578063f2fde38b14610877578063f6bcbd311461089d578063fa352c00146108cb5761027f565b8063ad5c4648146106d9578063ae4e7fdf146106e1578063b5d832fe146106e9578063c0bd65d71461070f578063cb24019814610717578063d505accf1461071f5761027f565b806395d89b411161012057806395d89b411461063d5780639d8e2177146106455780639dc29fac1461064d578063a457c2d714610679578063a9059cbb146106a5578063abf1614b146106d15761027f565b8063715018a6146105f75780637ecebe00146105ff57806387b65207146106255780638da5cb5b1461062d57806393c19e18146106355761027f565b80633644e515116101f55780634ba2363a116101b95780634ba2363a1461050c578063522c80671461051457806358ada5261461058b57806361d027b3146105c15780636a5e2650146105c957806370a08231146105d15761027f565b80633644e5151461048057806336569e771461048857806339509351146104ac57806340c10f19146104d8578063459e414f146105045761027f565b806318160ddd1161024757806318160ddd146103c95780631a28ff05146103d1578063204f83f91461041c57806323b872dd1461042457806330adf81f1461045a578063313ce567146104625761027f565b8063028f7d551461028457806306fdde03146102bc578063095ea7b3146103395780630e6dfcd51461037957806312970eac146103c1575b600080fd5b6102ba6004803603604081101561029a57600080fd5b5080356001600160a01b031690602001356001600160e01b0319166108f1565b005b6102c46109c5565b6040805160208082528351818301528351919283929083019185019080838360005b838110156102fe5781810151838201526020016102e6565b50505050905090810190601f16801561032b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6103656004803603604081101561034f57600080fd5b506001600160a01b038135169060200135610a5c565b604080519115158252519081900360200190f35b6103af6004803603606081101561038f57600080fd5b506001600160a01b03813581169160208101359091169060400135610a7a565b60408051918252519081900360200190f35b6103af610d1e565b6103af610d24565b6102ba600480360360c08110156103e757600080fd5b506001600160a01b03813581169160208101359091169060408101359060ff6060820135169060808101359060a00135610d2a565b6103af610f4d565b6103656004803603606081101561043a57600080fd5b506001600160a01b03813581169160208101359091169060400135610f53565b6103af610fe0565b61046a611004565b6040805160ff9092168252519081900360200190f35b6103af61100d565b610490611031565b604080516001600160a01b039092168252519081900360200190f35b610365600480360360408110156104c257600080fd5b506001600160a01b038135169060200135611040565b6102ba600480360360408110156104ee57600080fd5b506001600160a01b038135169060200135611094565b6103af611146565b61049061116a565b6102ba6004803603604081101561052a57600080fd5b8135919081019060408101602082013564010000000081111561054c57600080fd5b82018360208201111561055e57600080fd5b8035906020019184600183028401116401000000008311171561058057600080fd5b509092509050611179565b610365600480360360408110156105a157600080fd5b5080356001600160a01b031690602001356001600160e01b03191661126c565b61049061128c565b6103af61129b565b6103af600480360360208110156105e757600080fd5b50356001600160a01b03166112a1565b6102ba6112bc565b6103af6004803603602081101561061557600080fd5b50356001600160a01b0316611369565b6102ba61137b565b610490611598565b6103af6115ac565b6102c46115b2565b6103af611613565b6102ba6004803603604081101561066357600080fd5b506001600160a01b038135169060200135611623565b6103656004803603604081101561068f57600080fd5b506001600160a01b0381351690602001356116d0565b610365600480360360408110156106bb57600080fd5b506001600160a01b03813516906020013561173e565b6103af611752565b6103af611824565b610365611830565b6103af600480360360208110156106ff57600080fd5b50356001600160a01b0316611840565b6103af611852565b6103af611876565b6102ba600480360360e081101561073557600080fd5b506001600160a01b03813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135611927565b6103af6004803603604081101561078657600080fd5b506001600160a01b0381358116916020013516611b55565b6102ba600480360360208110156107b457600080fd5b50356001600160a01b0316611b80565b6102ba600480360360408110156107da57600080fd5b6001600160a01b03823516919081019060408101602082013564010000000081111561080557600080fd5b82018360208201111561081757600080fd5b8035906020019184602083028401116401000000008311171561083957600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550611b8d945050505050565b6102ba6004803603602081101561088d57600080fd5b50356001600160a01b0316611c1b565b610365600480360360408110156108b357600080fd5b506001600160a01b0381358116916020013516611d24565b6102ba600480360360208110156108e157600080fd5b50356001600160a01b0316611d44565b6108f9611d4e565b60055461010090046001600160a01b0390811691161461094e576040805162461bcd60e51b81526020600482018190526024820152600080516020612870833981519152604482015290519081900360640190fd5b6001600160a01b03821660008181526006602090815260408083206001600160e01b0319861680855290835292819020805460ff1916600117905580519384529083019190915280517f80e6a982b9aa622283c64c5ba322fc345fe769ac330a174f3254e52926e5fcf89281900390910190a15050565b60038054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610a515780601f10610a2657610100808354040283529160200191610a51565b820191906000526020600020905b815481529060010190602001808311610a3457829003601f168201915b505050505090505b90565b6000610a70610a69611d4e565b8484611d52565b5060015b92915050565b6000836040518060400160405280601e81526020017f46594461693a204f6e6c7920486f6c646572204f722044656c65676174650000815250816001600160a01b0316336001600160a01b03161480610af657506001600160a01b038216600090815260086020908152604080832033845290915290205460ff165b8190610b805760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610b45578181015183820152602001610b2d565b50505050905090810190601f168015610b725780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b50601054600114610bc8576040805162461bcd60e51b815260206004820152600d60248201526c119651185a4e88131bd8dad959609a1b604482015290519081900360640190fd5b6000601055600c54600160a01b900460ff161515600114610c30576040805162461bcd60e51b815260206004820152601a60248201527f46594461693a206679446169206973206e6f74206d6174757265000000000000604482015290519081900360640190fd5b610c3a8685611e3e565b6000610c4d85610c48611876565b611f46565b600c5460408051635502770360e01b81526001600160a01b038a8116600483015260248201859052915193945091169163550277039160448082019260009290919082900301818387803b158015610ca457600080fd5b505af1158015610cb8573d6000803e3d6000fd5b50505050856001600160a01b0316876001600160a01b03167f5cdf07ad0fc222442720b108e3ed4c4640f0fadc2ab2253e66f259a0fea834808784604051808381526020018281526020019250505060405180910390a360016010559695505050505050565b600e5481565b60025490565b42841015610d7f576040805162461bcd60e51b815260206004820152601c60248201527f44656c656761626c653a205369676e6174757265206578706972656400000000604482015290519081900360640190fd5b6001600160a01b0380871660008181526007602090815260408083208054600180820190925582517f0d077601844dd17f704bafff948229d27f33b57445915754dfe3d095fda2beb78186015280840196909652958b166060860152608085019590955260a08085018a90528151808603909101815260c08501825280519083012061190160f01b60e08601527fa9b5be00a19236acf53b8aeac381788afa1d439b48a99dcb8d04b3e2303a711b60e286015261010280860182905282518087039091018152610122860180845281519185019190912090859052610142860180845281905260ff8a1661016287015261018286018990526101a2860188905291519095919491926101c2808401939192601f1981019281900390910190855afa158015610eb1573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811615801590610ee75750886001600160a01b0316816001600160a01b0316145b610f38576040805162461bcd60e51b815260206004820152601c60248201527f44656c656761626c653a20496e76616c6964207369676e617475726500000000604482015290519081900360640190fd5b610f428989611f7b565b505050505050505050565b600d5481565b6000610f60848484612062565b610fd684610f6c611d4e565b610fd185604051806060016040528060288152602001612848602891396001600160a01b038a16600090815260016020526040812090610faa611d4e565b6001600160a01b03168152602081019190915260400160002054919063ffffffff6121c916565b611d52565b5060019392505050565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b60055460ff1690565b7fd7f98f71d60cb9e36bfba4ac8f3e429ac1a3ba523ea92dfdc97a58689c93ebd781565b600a546001600160a01b031681565b6000610a7061104d611d4e565b84610fd1856001600061105e611d4e565b6001600160a01b03908116825260208083019390935260409182016000908120918c16815292529020549063ffffffff61222316565b6040805180820182526015815274119651185a4e88139bdd08105d5d1a1bdc9a5e9959605a1b602080830191909152336000908152600682528381206001600160e01b031982351682529091529190912054819060ff166111365760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315610b45578181015183820152602001610b2d565b50611141838361227d565b505050565b7fa9b5be00a19236acf53b8aeac381788afa1d439b48a99dcb8d04b3e2303a711b81565b600b546001600160a01b031681565b6010546001146111c0576040805162461bcd60e51b815260206004820152600d60248201526c119651185a4e88131bd8dad959609a1b604482015290519081900360640190fd5b60006010556111cf338461227d565b6040805163be0e792760e01b8152600481018581526024820192835260448201849052339263be0e792792879287928792606401848480828437600081840152601f19601f820116905080830192505050945050505050600060405180830381600087803b15801561124057600080fd5b505af1158015611254573d6000803e3d6000fd5b505050506112623384611e3e565b5050600160105550565b600660209081526000928352604080842090915290825290205460ff1681565b600c546001600160a01b031681565b60105481565b6001600160a01b031660009081526020819052604090205490565b6112c4611d4e565b60055461010090046001600160a01b03908116911614611319576040805162461bcd60e51b81526020600482018190526024820152600080516020612870833981519152604482015290519081900360640190fd5b60055460405160009161010090046001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a360058054610100600160a81b0319169055565b60096020526000908152604090205481565b600d5442116113d1576040805162461bcd60e51b815260206004820152601a60248201527f46594461693a20546f6f206561726c7920746f206d6174757265000000000000604482015290519081900360640190fd5b600c54600160a01b900460ff1615156001141561142e576040805162461bcd60e51b8152602060048201526016602482015275119651185a4e88105b1c9958591e481b585d1d5c995960521b604482015290519081900360640190fd5b600a5460408051636cb1c69b60e11b8152644554482d4160d81b600482015290516001600160a01b039092169163d9638d369160248082019260a092909190829003018186803b15801561148157600080fd5b505afa158015611495573d6000803e3d6000fd5b505050506040513d60a08110156114ab57600080fd5b5060200151600f8190556114cb906b033b2e3c9fd0803ce80000006122d5565b600f55600b546040805163324abb3160e21b815290516001600160a01b039092169163c92aecc491600480820192602092909190829003018186803b15801561151357600080fd5b505afa158015611527573d6000803e3d6000fd5b505050506040513d602081101561153d57600080fd5b5051600e819055600c805460ff60a01b1916600160a01b179055600f5460408051918252602082019290925281517f30a742d45111295203c4b8db614c8b05dd1323a7c5159fb88b0cc73be46b7a75929181900390910190a1565b60055461010090046001600160a01b031690565b600f5481565b60048054604080516020601f6002600019610100600188161502019095169490940493840181900481028201810190925282815260609390929091830182828015610a515780601f10610a2657610100808354040283529160200191610a51565b6b033b2e3c9fd0803ce800000081565b6040805180820182526015815274119651185a4e88139bdd08105d5d1a1bdc9a5e9959605a1b602080830191909152336000908152600682528381206001600160e01b031982351682529091529190912054819060ff166116c55760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315610b45578181015183820152602001610b2d565b506111418383611e3e565b6000610a706116dd611d4e565b84610fd1856040518060600160405280602581526020016128fa6025913960016000611707611d4e565b6001600160a01b03908116825260208083019390935260409182016000908120918d1681529252902054919063ffffffff6121c916565b6000610a7061174b611d4e565b8484612062565b600c54600090600160a01b900460ff1615156001146117745750600f54610a59565b600a5460408051636cb1c69b60e11b8152644554482d4160d81b600482015290516000926001600160a01b03169163d9638d369160248083019260a0929190829003018186803b1580156117c757600080fd5b505afa1580156117db573d6000803e3d6000fd5b505050506040513d60a08110156117f157600080fd5b5060200151600f5490915061181e906b033b2e3c9fd0803ce8000000906118199084906122ec565b6122d5565b91505090565b644554482d4160d81b81565b600c54600160a01b900460ff1681565b60076020526000908152604090205481565b7f0d077601844dd17f704bafff948229d27f33b57445915754dfe3d095fda2beb781565b600c54600090600160a01b900460ff1615156001146118985750600e54610a59565b6119226118a3611752565b600b546040805163324abb3160e21b8152905161191d926001600160a01b03169163c92aecc4916004808301926020929190829003018186803b1580156118e957600080fd5b505afa1580156118fd573d6000803e3d6000fd5b505050506040513d602081101561191357600080fd5b5051600e54612360565b612382565b905090565b4284101561197c576040805162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e65000000604482015290519081900360640190fd5b6001600160a01b0380881660008181526009602090815260408083208054600180820190925582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958c166060860152608085018b905260a085019590955260c08085018a90528151808603909101815260e08501825280519083012061190160f01b6101008601527fd7f98f71d60cb9e36bfba4ac8f3e429ac1a3ba523ea92dfdc97a58689c93ebd761010286015261012280860182905282518087039091018152610142860180845281519185019190912090859052610162860180845281905260ff8a166101828701526101a286018990526101c2860188905291519095919491926101e2808401939192601f1981019281900390910190855afa158015611ab7573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811615801590611aed5750896001600160a01b0316816001600160a01b0316145b611b3e576040805162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e61747572650000604482015290519081900360640190fd5b611b498a8a8a611d52565b50505050505050505050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b611b8a3382611f7b565b50565b611b95611d4e565b60055461010090046001600160a01b03908116911614611bea576040805162461bcd60e51b81526020600482018190526024820152600080516020612870833981519152604482015290519081900360640190fd5b60005b815181101561114157611c1383838381518110611c0657fe5b60200260200101516108f1565b600101611bed565b611c23611d4e565b60055461010090046001600160a01b03908116911614611c78576040805162461bcd60e51b81526020600482018190526024820152600080516020612870833981519152604482015290519081900360640190fd5b6001600160a01b038116611cbd5760405162461bcd60e51b81526004018080602001828103825260268152602001806127976026913960400191505060405180910390fd5b6005546040516001600160a01b0380841692610100900416907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600580546001600160a01b0390921661010002610100600160a81b0319909216919091179055565b600860209081526000928352604080842090915290825290205460ff1681565b611b8a3382612391565b3390565b6001600160a01b038316611d975760405162461bcd60e51b81526004018080602001828103825260248152602001806128d66024913960400191505060405180910390fd5b6001600160a01b038216611ddc5760405162461bcd60e51b81526004018080602001828103825260228152602001806127bd6022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b038216611e835760405162461bcd60e51b81526004018080602001828103825260218152602001806128906021913960400191505060405180910390fd5b611e8f82600083611141565b611ed281604051806060016040528060228152602001612775602291396001600160a01b038516600090815260208190526040902054919063ffffffff6121c916565b6001600160a01b038316600090815260208190526040902055600254611efe908263ffffffff61246f16565b6002556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b6000611f746b033b2e3c9fd0803ce8000000611f68858563ffffffff6124b116565b9063ffffffff61250a16565b9392505050565b6001600160a01b0380831660009081526008602090815260408083209385168352929052205460ff1615611ff6576040805162461bcd60e51b815260206004820152601c60248201527f44656c656761626c653a20416c72656164792064656c65676174656400000000604482015290519081900360640190fd5b6001600160a01b03808316600081815260086020908152604080832094861680845294825291829020805460ff19166001908117909155825190815291517f045b0fef01772d2fbba53dbd38c9777806eac0865b00af43abcfbcaf50da92069281900390910190a35050565b6001600160a01b0383166120a75760405162461bcd60e51b81526004018080602001828103825260258152602001806128b16025913960400191505060405180910390fd5b6001600160a01b0382166120ec5760405162461bcd60e51b81526004018080602001828103825260238152602001806127526023913960400191505060405180910390fd5b6120f7838383611141565b61213a816040518060600160405280602681526020016127df602691396001600160a01b038616600090815260208190526040902054919063ffffffff6121c916565b6001600160a01b03808516600090815260208190526040808220939093559084168152205461216f908263ffffffff61222316565b6001600160a01b038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b6000818484111561221b5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315610b45578181015183820152602001610b2d565b505050900390565b600082820183811015611f74576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b612287828261254c565b600160701b612294610d24565b11156122d15760405162461bcd60e51b81526004018080602001828103825260228152602001806128056022913960400191505060405180910390fd5b5050565b6000818310156122e55781611f74565b5090919050565b60008061230b846b033b2e3c9fd0803ce800000063ffffffff6124b116565b905061231d818463ffffffff61264816565b15612348576123436001612337838663ffffffff61250a16565b9063ffffffff61222316565b612358565b612358818463ffffffff61250a16565b949350505050565b6000611f7482611f68856b033b2e3c9fd0803ce800000063ffffffff6124b116565b60008183106122e55781611f74565b6001600160a01b0380831660009081526008602090815260408083209385168352929052205460ff1661240b576040805162461bcd60e51b815260206004820152601e60248201527f44656c656761626c653a20416c726561647920756e64656c6567617465640000604482015290519081900360640190fd5b6001600160a01b038083166000818152600860209081526040808320948616808452948252808320805460ff191690558051928352517f045b0fef01772d2fbba53dbd38c9777806eac0865b00af43abcfbcaf50da92069281900390910190a35050565b6000611f7483836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506121c9565b6000826124c057506000610a74565b828202828482816124cd57fe5b0414611f745760405162461bcd60e51b81526004018080602001828103825260218152602001806128276021913960400191505060405180910390fd5b6000611f7483836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f00000000000081525061268a565b6001600160a01b0382166125a7576040805162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b6125b360008383611141565b6002546125c6908263ffffffff61222316565b6002556001600160a01b0382166000908152602081905260409020546125f2908263ffffffff61222316565b6001600160a01b0383166000818152602081815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b6000611f7483836040518060400160405280601881526020017f536166654d6174683a206d6f64756c6f206279207a65726f00000000000000008152506126ef565b600081836126d95760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315610b45578181015183820152602001610b2d565b5060008385816126e557fe5b0495945050505050565b6000818361273e5760405162461bcd60e51b8152602060048201818152835160248401528351909283926044909101919085019080838360008315610b45578181015183820152602001610b2d565b5082848161274857fe5b0694935050505056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a206275726e20616d6f756e7420657863656564732062616c616e63654f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636546594461693a20546f74616c20737570706c79206c696d6974206578636565646564536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f7745524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e63654f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657245524332303a206275726e2066726f6d20746865207a65726f206164647265737345524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220201936ac9e113200c8cd02d21dc37fc18ad5fd2cd1594dfa0b697d14cf226d0a64736f6c634300060a0033

Verified Source Code Partial Match

Compiler: v0.6.10+commit.00c0fcaf EVM: istanbul Optimization: Yes (200 runs)
FYDai.sol 1475 lines
// File: @openzeppelin/contracts/math/Math.sol


pragma solidity ^0.6.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: contracts/interfaces/IVat.sol

pragma solidity ^0.6.10;


/// @dev Interface to interact with the vat contract from MakerDAO
/// Taken from https://github.com/makerdao/developerguides/blob/master/devtools/working-with-dsproxy/working-with-dsproxy.md
interface IVat {
    // function can(address, address) external view returns (uint);
    function hope(address) external;
    function nope(address) external;
    function live() external view returns (uint);
    function ilks(bytes32) external view returns (uint, uint, uint, uint, uint);
    function urns(bytes32, address) external view returns (uint, uint);
    function gem(bytes32, address) external view returns (uint);
    // function dai(address) external view returns (uint);
    function frob(bytes32, address, address, address, int, int) external;
    function fork(bytes32, address, address, int, int) external;
    function move(address, address, uint) external;
    function flux(bytes32, address, address, uint) external;
}

// File: contracts/interfaces/IPot.sol

pragma solidity ^0.6.10;


/// @dev interface for the pot contract from MakerDao
/// Taken from https://github.com/makerdao/developerguides/blob/master/dai/dsr-integration-guide/dsr.sol
interface IPot {
    function chi() external view returns (uint256);
    function pie(address) external view returns (uint256); // Not a function, but a public variable.
    function rho() external returns (uint256);
    function drip() external returns (uint256);
    function join(uint256) external;
    function exit(uint256) external;
}

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


pragma solidity ^0.6.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves `amount` tokens from the caller's account to `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: contracts/interfaces/IWeth.sol

pragma solidity ^0.6.10;


interface IWeth {
    function deposit() external payable;
    function withdraw(uint) external;
    function approve(address, uint) external returns (bool) ;
    function transfer(address, uint) external returns (bool);
    function transferFrom(address, address, uint) external returns (bool);
}

// File: contracts/interfaces/IGemJoin.sol

pragma solidity ^0.6.10;


/// @dev Interface to interact with the `Join.sol` contract from MakerDAO using ERC20
interface IGemJoin {
    function rely(address usr) external;
    function deny(address usr) external;
    function cage() external;
    function join(address usr, uint WAD) external;
    function exit(address usr, uint WAD) external;
}

// File: contracts/interfaces/IDaiJoin.sol

pragma solidity ^0.6.10;


/// @dev Interface to interact with the `Join.sol` contract from MakerDAO using Dai
interface IDaiJoin {
    function rely(address usr) external;
    function deny(address usr) external;
    function cage() external;
    function join(address usr, uint WAD) external;
    function exit(address usr, uint WAD) external;
}

// File: contracts/interfaces/IChai.sol

pragma solidity ^0.6.10;


/// @dev interface for the chai contract
/// Taken from https://github.com/makerdao/developerguides/blob/master/dai/dsr-integration-guide/dsr.sol
interface IChai {
    function balanceOf(address account) external view returns (uint256);
    function transfer(address dst, uint wad) external returns (bool);
    function move(address src, address dst, uint wad) external returns (bool);
    function transferFrom(address src, address dst, uint wad) external returns (bool);
    function approve(address usr, uint wad) external returns (bool);
    function dai(address usr) external returns (uint wad);
    function join(address dst, uint wad) external;
    function exit(address src, uint wad) external;
    function draw(address src, uint wad) external;
    function permit(address holder, address spender, uint256 nonce, uint256 expiry, bool allowed, uint8 v, bytes32 r, bytes32 s) external;
    function nonces(address account) external view returns (uint256);
}

// File: contracts/interfaces/ITreasury.sol

pragma solidity ^0.6.10;








interface ITreasury {
    function debt() external view returns(uint256);
    function savings() external view returns(uint256);
    function pushDai(address user, uint256 dai) external;
    function pullDai(address user, uint256 dai) external;
    function pushChai(address user, uint256 chai) external;
    function pullChai(address user, uint256 chai) external;
    function pushWeth(address to, uint256 weth) external;
    function pullWeth(address to, uint256 weth) external;
    function shutdown() external;
    function live() external view returns(bool);

    function vat() external view returns (IVat);
    function weth() external view returns (IWeth);
    function dai() external view returns (IERC20);
    function daiJoin() external view returns (IDaiJoin);
    function wethJoin() external view returns (IGemJoin);
    function pot() external view returns (IPot);
    function chai() external view returns (IChai);
}

// File: contracts/interfaces/IERC2612.sol

// Code adapted from https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2237/
pragma solidity ^0.6.0;

/**
 * @dev Interface of the ERC2612 standard as defined in the EIP.
 *
 * Adds the {permit} method, which can be used to change one's
 * {IERC20-allowance} without having to send a transaction, by signing a
 * message. This allows users to spend tokens without having to hold Ether.
 *
 * See https://eips.ethereum.org/EIPS/eip-2612.
 */
interface IERC2612 {
    /**
     * @dev Sets `amount` as the allowance of `spender` over `owner`'s tokens,
     * given `owner`'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external;

    /**
     * @dev Returns the current ERC2612 nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);
}

// File: contracts/interfaces/IFYDai.sol

pragma solidity ^0.6.10;



interface IFYDai is IERC20, IERC2612 {
    function isMature() external view returns(bool);
    function maturity() external view returns(uint);
    function chi0() external view returns(uint);
    function rate0() external view returns(uint);
    function chiGrowth() external view returns(uint);
    function rateGrowth() external view returns(uint);
    function mature() external;
    function unlocked() external view returns (uint);
    function mint(address, uint) external;
    function burn(address, uint) external;
    function flashMint(uint, bytes calldata) external;
    function redeem(address, address, uint256) external returns (uint256);
    // function transfer(address, uint) external returns (bool);
    // function transferFrom(address, address, uint) external returns (bool);
    // function approve(address, uint) external returns (bool);
}

// File: contracts/interfaces/IFlashMinter.sol

pragma solidity ^0.6.10;


interface IFlashMinter {
    function executeOnFlashMint(uint256 fyDaiAmount, bytes calldata data) external;
}

// File: contracts/interfaces/IDelegable.sol

pragma solidity ^0.6.10;


interface IDelegable {
    function addDelegate(address) external;
    function addDelegateBySignature(address, address, uint, uint8, bytes32, bytes32) external;
}

// File: contracts/helpers/Delegable.sol

pragma solidity ^0.6.10;



/// @dev Delegable enables users to delegate their account management to other users.
/// Delegable implements addDelegateBySignature, to add delegates using a signature instead of a separate transaction.
contract Delegable is IDelegable {
    event Delegate(address indexed user, address indexed delegate, bool enabled);

    // keccak256("Signature(address user,address delegate,uint256 nonce,uint256 deadline)");
    bytes32 public immutable SIGNATURE_TYPEHASH = 0x0d077601844dd17f704bafff948229d27f33b57445915754dfe3d095fda2beb7;
    bytes32 public immutable DELEGABLE_DOMAIN;
    mapping(address => uint) public signatureCount;

    mapping(address => mapping(address => bool)) public delegated;

    constructor () public {
        uint256 chainId;
        assembly {
            chainId := chainid()
        }

        DELEGABLE_DOMAIN = keccak256(
            abi.encode(
                keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'),
                keccak256(bytes('Yield')),
                keccak256(bytes('1')),
                chainId,
                address(this)
            )
        );
    }

    /// @dev Require that msg.sender is the account holder or a delegate
    modifier onlyHolderOrDelegate(address holder, string memory errorMessage) {
        require(
            msg.sender == holder || delegated[holder][msg.sender],
            errorMessage
        );
        _;
    }

    /// @dev Enable a delegate to act on the behalf of caller
    function addDelegate(address delegate) public override {
        _addDelegate(msg.sender, delegate);
    }

    /// @dev Stop a delegate from acting on the behalf of caller
    function revokeDelegate(address delegate) public {
        _revokeDelegate(msg.sender, delegate);
    }

    /// @dev Add a delegate through an encoded signature
    function addDelegateBySignature(address user, address delegate, uint deadline, uint8 v, bytes32 r, bytes32 s) public override {
        require(deadline >= block.timestamp, 'Delegable: Signature expired');

        bytes32 hashStruct = keccak256(
            abi.encode(
                SIGNATURE_TYPEHASH,
                user,
                delegate,
                signatureCount[user]++,
                deadline
            )
        );

        bytes32 digest = keccak256(
            abi.encodePacked(
                '\x19\x01',
                DELEGABLE_DOMAIN,
                hashStruct
            )
        );
        address signer = ecrecover(digest, v, r, s);
        require(
            signer != address(0) && signer == user,
            'Delegable: Invalid signature'
        );

        _addDelegate(user, delegate);
    }

    /// @dev Enable a delegate to act on the behalf of an user
    function _addDelegate(address user, address delegate) internal {
        require(!delegated[user][delegate], "Delegable: Already delegated");
        delegated[user][delegate] = true;
        emit Delegate(user, delegate, true);
    }

    /// @dev Stop a delegate from acting on the behalf of an user
    function _revokeDelegate(address user, address delegate) internal {
        require(delegated[user][delegate], "Delegable: Already undelegated");
        delegated[user][delegate] = false;
        emit Delegate(user, delegate, false);
    }
}

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


pragma solidity ^0.6.0;

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

        return c;
    }

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

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

        return c;
    }

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

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

        return c;
    }

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

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

        return c;
    }

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

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

// File: contracts/helpers/DecimalMath.sol

pragma solidity ^0.6.10;



/// @dev Implements simple fixed point math mul and div operations for 27 decimals.
contract DecimalMath {
    using SafeMath for uint256;

    uint256 constant public UNIT = 1e27;

    /// @dev Multiplies x and y, assuming they are both fixed point with 27 digits.
    function muld(uint256 x, uint256 y) internal pure returns (uint256) {
        return x.mul(y).div(UNIT);
    }

    /// @dev Divides x between y, assuming they are both fixed point with 27 digits.
    function divd(uint256 x, uint256 y) internal pure returns (uint256) {
        return x.mul(UNIT).div(y);
    }

    /// @dev Multiplies x and y, rounding up to the closest representable number.
    /// Assumes x and y are both fixed point with `decimals` digits.
    function muldrup(uint256 x, uint256 y) internal pure returns (uint256)
    {
        uint256 z = x.mul(y);
        return z.mod(UNIT) == 0 ? z.div(UNIT) : z.div(UNIT).add(1);
    }

    /// @dev Divides x between y, rounding up to the closest representable number.
    /// Assumes x and y are both fixed point with `decimals` digits.
    function divdrup(uint256 x, uint256 y) internal pure returns (uint256)
    {
        uint256 z = x.mul(UNIT);
        return z.mod(y) == 0 ? z.div(y) : z.div(y).add(1);
    }
}

// File: @openzeppelin/contracts/GSN/Context.sol


pragma solidity ^0.6.0;

/*
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with 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;
    }
}

// File: @openzeppelin/contracts/access/Ownable.sol


pragma solidity ^0.6.0;

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
contract Ownable is Context {
    address private _owner;

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

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

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

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

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

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}

// File: contracts/helpers/Orchestrated.sol

pragma solidity ^0.6.10;



/**
 * @dev Orchestrated allows to define static access control between multiple contracts.
 * This contract would be used as a parent contract of any contract that needs to restrict access to some methods,
 * which would be marked with the `onlyOrchestrated` modifier.
 * During deployment, the contract deployer (`owner`) can register any contracts that have privileged access by calling `orchestrate`.
 * Once deployment is completed, `owner` should call `transferOwnership(address(0))` to avoid any more contracts ever gaining privileged access.
 */

contract Orchestrated is Ownable {
    event GrantedAccess(address access, bytes4 signature);

    mapping(address => mapping (bytes4 => bool)) public orchestration;

    constructor () public Ownable() {}

    /// @dev Restrict usage to authorized users
    /// @param err The error to display if the validation fails 
    modifier onlyOrchestrated(string memory err) {
        require(orchestration[msg.sender][msg.sig], err);
        _;
    }

    /// @dev Add orchestration
    /// @param user Address of user or contract having access to this contract.
    /// @param signature bytes4 signature of the function we are giving orchestrated access to.
    /// It seems to me a bad idea to give access to humans, and would use this only for predictable smart contracts.
    function orchestrate(address user, bytes4 signature) public onlyOwner {
        orchestration[user][signature] = true;
        emit GrantedAccess(user, signature);
    }

    /// @dev Adds orchestration for the provided function signatures
    function batchOrchestrate(address user, bytes4[] memory signatures) public onlyOwner {
        for (uint256 i = 0; i < signatures.length; i++) {
            orchestrate(user, signatures[i]);
        }
    }
}

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


pragma solidity ^0.6.2;

/**
 * @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 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");
        return _functionCallWithValue(target, data, value, errorMessage);
    }

    function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
        require(isContract(target), "Address: call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
        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);
            }
        }
    }
}

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


pragma solidity ^0.6.0;





/**
 * @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;
    using Address for address;

    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 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. 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 returns (uint8) {
        return _decimals;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view 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 is 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 {
        _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 { }
}

// File: contracts/helpers/ERC20Permit.sol

// Adapted from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/53516bc555a454862470e7860a9b5254db4d00f5/contracts/token/ERC20/ERC20Permit.sol
pragma solidity ^0.6.0;



/**
 * @dev Extension of {ERC20} that allows token holders to use their tokens
 * without sending any transactions by setting {IERC20-allowance} with a
 * signature using the {permit} method, and then spend them via
 * {IERC20-transferFrom}.
 *
 * The {permit} signature mechanism conforms to the {IERC2612} interface.
 */
abstract contract ERC20Permit is ERC20, IERC2612 {
    mapping (address => uint256) public override nonces;

    bytes32 public immutable PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
    bytes32 public immutable DOMAIN_SEPARATOR;

    constructor(string memory name_, string memory symbol_) internal ERC20(name_, symbol_) {
        uint256 chainId;
        assembly {
            chainId := chainid()
        }

        DOMAIN_SEPARATOR = keccak256(
            abi.encode(
                keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
                keccak256(bytes(name_)),
                keccak256(bytes("1")),
                chainId,
                address(this)
            )
        );
    }

    /**
     * @dev See {IERC2612-permit}.
     *
     * In cases where the free option is not a concern, deadline can simply be
     * set to uint(-1), so it should be seen as an optional parameter
     */
    function permit(address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public virtual override {
        require(deadline >= block.timestamp, "ERC20Permit: expired deadline");

        bytes32 hashStruct = keccak256(
            abi.encode(
                PERMIT_TYPEHASH,
                owner,
                spender,
                amount,
                nonces[owner]++,
                deadline
            )
        );

        bytes32 hash = keccak256(
            abi.encodePacked(
                '\x19\x01',
                DOMAIN_SEPARATOR,
                hashStruct
            )
        );

        address signer = ecrecover(hash, v, r, s);
        require(
            signer != address(0) && signer == owner,
            "ERC20Permit: invalid signature"
        );

        _approve(owner, spender, amount);
    }
}

// File: contracts/FYDai.sol

pragma solidity ^0.6.10;













/**
 * @dev fyDai is an fyToken targeting Chai.
 * Each fyDai contract has a specific maturity time. One fyDai is worth one Chai at or after maturity time.
 * At maturity, the fyDai can be triggered to mature, which records the current rate and chi from MakerDAO and enables redemption.
 * Redeeming an fyDai means burning it, and the contract will retrieve Dai from Treasury equal to one Dai times the growth in chi since maturity.
 * fyDai also tracks the MakerDAO stability fee accumulator at the time of maturity, and the growth since. This is not used internally.
 * Minting and burning of fyDai is restricted to orchestrated contracts. Redeeming and flash-minting is allowed to anyone.
 */

contract FYDai is IFYDai, Orchestrated(), Delegable(), DecimalMath, ERC20Permit  {

    event Redeemed(address indexed from, address indexed to, uint256 fyDaiIn, uint256 daiOut);
    event Matured(uint256 rate, uint256 chi);

    bytes32 public constant WETH = "ETH-A";

    uint256 constant internal MAX_TIME_TO_MATURITY = 126144000; // seconds in four years

    IVat public vat;
    IPot public pot;
    ITreasury public treasury;

    bool public override isMature;
    uint256 public override maturity;
    uint256 public override chi0;      // Chi at maturity
    uint256 public override rate0;     // Rate at maturity

    uint public override unlocked = 1;
    modifier lock() {
        require(unlocked == 1, 'FYDai: Locked');
        unlocked = 0;
        _;
        unlocked = 1;
    }
    
    /// @dev The constructor:
    /// Sets the name and symbol for the fyDai token.
    /// Connects to Vat, Jug, Pot and Treasury.
    /// Sets the maturity date for the fyDai, in unix time.
    /// Initializes chi and rate at maturity time as 1.0 with 27 decimals.
    constructor(
        address treasury_,
        uint256 maturity_,
        string memory name,
        string memory symbol
    ) public ERC20Permit(name, symbol) {
        // solium-disable-next-line security/no-block-members
        require(maturity_ > now && maturity_ < now + MAX_TIME_TO_MATURITY, "FYDai: Invalid maturity");
        treasury = ITreasury(treasury_);
        vat = treasury.vat();
        pot = treasury.pot();
        maturity = maturity_;
        chi0 = UNIT;
        rate0 = UNIT;
    }

    /// @dev Chi differential between maturity and now in RAY. Returns 1.0 if not mature.
    /// If rateGrowth < chiGrowth, returns rate.
    //
    //          chi_now
    // chi() = ---------
    //          chi_mat
    //
    function chiGrowth() public view override returns(uint256){
        if (isMature != true) return chi0;
        return Math.min(rateGrowth(), divd(pot.chi(), chi0)); // Rounding in favour of the protocol
    }

    /// @dev Rate differential between maturity and now in RAY...

// [truncated — 54161 bytes total]

Read Contract

DELEGABLE_DOMAIN 0x459e414f → bytes32
DOMAIN_SEPARATOR 0x3644e515 → bytes32
PERMIT_TYPEHASH 0x30adf81f → bytes32
SIGNATURE_TYPEHASH 0xc0bd65d7 → bytes32
UNIT 0x9d8e2177 → uint256
WETH 0xad5c4648 → bytes32
allowance 0xdd62ed3e → uint256
balanceOf 0x70a08231 → uint256
chi0 0x12970eac → uint256
chiGrowth 0xcb240198 → uint256
decimals 0x313ce567 → uint8
delegated 0xf6bcbd31 → bool
isMature 0xae4e7fdf → bool
maturity 0x204f83f9 → uint256
name 0x06fdde03 → string
nonces 0x7ecebe00 → uint256
orchestration 0x58ada526 → bool
owner 0x8da5cb5b → address
pot 0x4ba2363a → address
rate0 0x93c19e18 → uint256
rateGrowth 0xabf1614b → uint256
signatureCount 0xb5d832fe → uint256
symbol 0x95d89b41 → string
totalSupply 0x18160ddd → uint256
treasury 0x61d027b3 → address
unlocked 0x6a5e2650 → uint256
vat 0x36569e77 → address

Write Contract 18 functions

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

addDelegate 0xe71bdf41
address delegate
addDelegateBySignature 0x1a28ff05
address user
address delegate
uint256 deadline
uint8 v
bytes32 r
bytes32 s
approve 0x095ea7b3
address spender
uint256 amount
returns: bool
batchOrchestrate 0xe80c72c0
address user
bytes4[] signatures
burn 0x9dc29fac
address from
uint256 fyDaiAmount
decreaseAllowance 0xa457c2d7
address spender
uint256 subtractedValue
returns: bool
flashMint 0x522c8067
uint256 fyDaiAmount
bytes data
increaseAllowance 0x39509351
address spender
uint256 addedValue
returns: bool
mature 0x87b65207
No parameters
mint 0x40c10f19
address to
uint256 fyDaiAmount
orchestrate 0x028f7d55
address user
bytes4 signature
permit 0xd505accf
address owner
address spender
uint256 amount
uint256 deadline
uint8 v
bytes32 r
bytes32 s
redeem 0x0e6dfcd5
address from
address to
uint256 fyDaiAmount
returns: uint256
renounceOwnership 0x715018a6
No parameters
revokeDelegate 0xfa352c00
address delegate
transfer 0xa9059cbb
address recipient
uint256 amount
returns: bool
transferFrom 0x23b872dd
address sender
address recipient
uint256 amount
returns: bool
transferOwnership 0xf2fde38b
address newOwner

Recent Transactions

No transactions found for this address