Address Contract Partially Verified
Address
0xFD64Dad84bDd0C735DEc910936F301C74fc4bcdD
Balance
0.000029747 ETH ($0.06)
Nonce
1
Code Size
19522 bytes
Creator
0x20827fDb...92D5 at tx 0xb16f0f7c...26c0d6
Indexed Transactions
0 (1 on-chain, 0.7% indexed)
Contract Bytecode
19522 bytes
0x60806040526004361061027d5760003560e01c806394c393fc1161014f578063c37f68e2116100c1578063f2b3abbd1161007a578063f2b3abbd146108f7578063f3fdb15a1461092a578063f77c47911461093f578063f851a44014610954578063f8f9da2814610969578063fca7820b1461097e5761027d565b8063c37f68e2146107d4578063c5ebeaec1461082d578063db006a7514610857578063dd62ed3e14610881578063e5974619146108bc578063e9c714f2146108e25761027d565b8063aa5af0fd11610113578063aa5af0fd146106f1578063aae40a2a14610706578063ae9d70b014610734578063b2a02ff114610749578063b71d1a0c1461078c578063bd6d894d146107bf5761027d565b806394c393fc1461064657806395d89b411461065b57806395dd919314610670578063a6afed95146106a3578063a9059cbb146106b85761027d565b80633af9e669116101f35780636c540baf116101ac5780636c540baf1461057757806370a082311461058c57806373acee98146105bf57806383de424e146105d4578063852a12e3146106075780638f840ddd146106315761027d565b80633af9e669146104d35780633b1d21a21461050657806347bd37181461051b5780634e4d9fea14610530578063601a0bf114610538578063675d972c146105625761027d565b806318160ddd1161024557806318160ddd146103ed578063182df0f51461040257806323b872dd14610417578063267822471461045a5780632d7563591461048b578063313ce567146104be5761027d565b806306fdde03146102b4578063095ea7b31461033e5780631249c58b1461038b578063173b99041461039357806317bfdfbc146103ba575b6102b2610289346109a8565b6040518060400160405280600b81526020016a1b5a5b9d0819985a5b195960aa1b815250610a38565b005b3480156102c057600080fd5b506102c9610c38565b6040805160208082528351818301528351919283929083019185019080838360005b838110156103035781810151838201526020016102eb565b50505050905090810190601f1680156103305780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561034a57600080fd5b506103776004803603604081101561036157600080fd5b506001600160a01b038135169060200135610cc5565b604080519115158252519081900360200190f35b6102b2610d32565b34801561039f57600080fd5b506103a8610d40565b60408051918252519081900360200190f35b3480156103c657600080fd5b506103a8600480360360208110156103dd57600080fd5b50356001600160a01b0316610d46565b3480156103f957600080fd5b506103a8610df2565b34801561040e57600080fd5b506103a8610df8565b34801561042357600080fd5b506103776004803603606081101561043a57600080fd5b506001600160a01b03813581169160208101359091169060400135610e5b565b34801561046657600080fd5b5061046f610ec1565b604080516001600160a01b039092168252519081900360200190f35b34801561049757600080fd5b506103a8600480360360208110156104ae57600080fd5b50356001600160a01b0316610ed0565b3480156104ca57600080fd5b506103a8610f28565b3480156104df57600080fd5b506103a8600480360360208110156104f657600080fd5b50356001600160a01b0316610f2e565b34801561051257600080fd5b506103a8610f9c565b34801561052757600080fd5b506103a8610fab565b6102b2610fb1565b34801561054457600080fd5b506103a86004803603602081101561055b57600080fd5b5035610fed565b34801561056e57600080fd5b506103a8611027565b34801561058357600080fd5b506103a861102d565b34801561059857600080fd5b506103a8600480360360208110156105af57600080fd5b50356001600160a01b0316611033565b3480156105cb57600080fd5b506103a861104e565b3480156105e057600080fd5b506103a8600480360360208110156105f757600080fd5b50356001600160a01b03166110f8565b34801561061357600080fd5b506103a86004803603602081101561062a57600080fd5b5035611243565b34801561063d57600080fd5b506103a861124e565b34801561065257600080fd5b50610377611254565b34801561066757600080fd5b506102c9611259565b34801561067c57600080fd5b506103a86004803603602081101561069357600080fd5b50356001600160a01b03166112b1565b3480156106af57600080fd5b506103a861130e565b3480156106c457600080fd5b50610377600480360360408110156106db57600080fd5b506001600160a01b038135169060200135611707565b3480156106fd57600080fd5b506103a861176c565b6102b26004803603604081101561071c57600080fd5b506001600160a01b0381358116916020013516611772565b34801561074057600080fd5b506103a86117b4565b34801561075557600080fd5b506103a86004803603606081101561076c57600080fd5b506001600160a01b03813581169160208101359091169060400135611a7f565b34801561079857600080fd5b506103a8600480360360208110156107af57600080fd5b50356001600160a01b0316611d30565b3480156107cb57600080fd5b506103a8611db7565b3480156107e057600080fd5b50610807600480360360208110156107f757600080fd5b50356001600160a01b0316611e62565b604080519485526020850193909352838301919091526060830152519081900360800190f35b34801561083957600080fd5b506103a86004803603602081101561085057600080fd5b5035611ef7565b34801561086357600080fd5b506103a86004803603602081101561087a57600080fd5b5035611f02565b34801561088d57600080fd5b506103a8600480360360408110156108a457600080fd5b506001600160a01b0381358116916020013516611f0d565b6102b2600480360360208110156108d257600080fd5b50356001600160a01b0316611f38565b3480156108ee57600080fd5b506103a8611f83565b34801561090357600080fd5b506103a86004803603602081101561091a57600080fd5b50356001600160a01b0316612072565b34801561093657600080fd5b5061046f6120ac565b34801561094b57600080fd5b5061046f6120bb565b34801561096057600080fd5b5061046f6120ca565b34801561097557600080fd5b506103a86120d9565b34801561098a57600080fd5b506103a8600480360360208110156109a157600080fd5b50356121b5565b60008054600101808255816109bb61130e565b905080156109e1576109d98160108111156109d257fe5b601e6121ef565b9250506109ef565b6109eb3385612255565b9250505b6000548114610a32576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b50919050565b81610a4257610c34565b606081516005016040519080825280601f01601f191660200182016040528015610a73576020820181803883390190505b50905060005b8251811015610ac457828181518110610a8e57fe5b602001015160f81c60f81b828281518110610aa557fe5b60200101906001600160f81b031916908160001a905350600101610a79565b8151600160fd1b90839083908110610ad857fe5b60200101906001600160f81b031916908160001a905350602860f81b828260010181518110610b0357fe5b60200101906001600160f81b031916908160001a905350600a840460300160f81b828260020181518110610b3357fe5b60200101906001600160f81b031916908160001a905350600a840660300160f81b828260030181518110610b6357fe5b60200101906001600160f81b031916908160001a905350602960f81b828260040181518110610b8e57fe5b60200101906001600160f81b031916908160001a905350818415610c305760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610bf5578181015183820152602001610bdd565b50505050905090810190601f168015610c225780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5050505b5050565b60018054604080516020600284861615610100026000190190941693909304601f81018490048402820184019092528181529291830182828015610cbd5780601f10610c9257610100808354040283529160200191610cbd565b820191906000526020600020905b815481529060010190602001808311610ca057829003601f168201915b505050505081565b3360008181526010602090815260408083206001600160a01b03871680855290835281842086905581518681529151939493909284927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929081900390910190a360019150505b92915050565b610d3e610289346109a8565b565b60095481565b6000805460010180825581610d5961130e565b14610da4576040805162461bcd60e51b81526020600482015260166024820152751858d8dc9d59481a5b9d195c995cdd0819985a5b195960521b604482015290519081900360640190fd5b610dad836112b1565b91506000548114610a32576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b600e5481565b6000806000610e0561269d565b90925090506000826003811115610e1857fe5b14610e545760405162461bcd60e51b8152600401808060200182810382526035815260200180614b816035913960400191505060405180910390fd5b9150505b90565b6000805460010180825581610e723387878761274b565b1491505b6000548114610eb9576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b509392505050565b6005546001600160a01b031681565b6004546000906001600160a01b03163314610ef857610ef1600a60416121ef565b9050610f23565b600780546001600160a01b0319166001600160a01b038481169190911791829055610a329116612a59565b919050565b60035481565b6000610f386148da565b6040518060200160405280610f4b611db7565b90526001600160a01b0384166000908152600f6020526040812054919250908190610f77908490612bc9565b90925090506000826003811115610f8a57fe5b14610f9457600080fd5b949350505050565b6000610fa6612c1d565b905090565b600c5481565b610d3e610fbd34612c49565b604051806040016040528060128152602001711c995c185e509bdc9c9bddc819985a5b195960721b815250610a38565b600080546001018082558161100061130e565b9050801561101e576109d981601081111561101757fe5b60306121ef565b6109eb84612c85565b60085481565b600a5481565b6001600160a01b03166000908152600f602052604090205490565b600080546001018082558161106161130e565b146110ac576040805162461bcd60e51b81526020600482015260166024820152751858d8dc9d59481a5b9d195c995cdd0819985a5b195960521b604482015290519081900360640190fd5b600c54915060005481146110f4576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b5090565b6004546000906001600160a01b0316331461111957610ef16001603f6121ef565b60065460408051634e1647fb60e01b815290516001600160a01b0392831692851691634e1647fb916004808301926020929190829003018186803b15801561116057600080fd5b505afa158015611174573d6000803e3d6000fd5b505050506040513d602081101561118a57600080fd5b50516111dd576040805162461bcd60e51b815260206004820152601c60248201527f6d61726b6572206d6574686f642072657475726e65642066616c736500000000604482015290519081900360640190fd5b600680546001600160a01b0319166001600160a01b03858116918217909255604080519284168352602083019190915280517ff9b6a28700579d5c8fab50f0ac2dcaa52109b85c369c4f511fcc873330ab6cbb9281900390910190a160005b9392505050565b6000610d2c82612e03565b600d5481565b600181565b6002805460408051602060018416156101000260001901909316849004601f81018490048402820184019092528181529291830182828015610cbd5780601f10610c9257610100808354040283529160200191610cbd565b60008060006112bf84612e40565b909250905060008260038111156112d257fe5b1461123c5760405162461bcd60e51b8152600401808060200182810382526037815260200180614a556037913960400191505060405180910390fd5b60006113186148ed565b6007546001600160a01b03166315f24053611331612c1d565b600c54600d546040518463ffffffff1660e01b8152600401808481526020018381526020018281526020019350505050604080518083038186803b15801561137857600080fd5b505afa15801561138c573d6000803e3d6000fd5b505050506040513d60408110156113a257600080fd5b50805160209182015160408401819052918301526601c6bf526340001015611411576040805162461bcd60e51b815260206004820152601c60248201527f626f72726f772072617465206973206162737572646c79206869676800000000604482015290519081900360640190fd5b6020810151156114345761142c600560028360200151612ef4565b915050610e58565b61143c612f5a565b60608201819052600a546114509190612f5e565b608083018190528282600381111561146457fe5b600381111561146f57fe5b905250600090508151600381111561148357fe5b1461148a57fe5b6114aa604051806020016040528083604001518152508260800151612f81565b60a08301819052828260038111156114be57fe5b60038111156114c957fe5b90525060009050815160038111156114dd57fe5b146114fe5761142c60096006836000015160038111156114f957fe5b612ef4565b61150e8160a00151600c54612bc9565b60c083018190528282600381111561152257fe5b600381111561152d57fe5b905250600090508151600381111561154157fe5b1461155d5761142c60096001836000015160038111156114f957fe5b61156d8160c00151600c54612fe9565b60e083018190528282600381111561158157fe5b600381111561158c57fe5b90525060009050815160038111156115a057fe5b146115bc5761142c60096004836000015160038111156114f957fe5b6115dd60405180602001604052806009548152508260c00151600d5461300f565b6101008301819052828260038111156115f257fe5b60038111156115fd57fe5b905250600090508151600381111561161157fe5b1461162d5761142c60096005836000015160038111156114f957fe5b6116408160a00151600b54600b5461300f565b61012083018190528282600381111561165557fe5b600381111561166057fe5b905250600090508151600381111561167457fe5b146116905761142c60096003836000015160038111156114f957fe5b606080820151600a55610120820151600b81905560e0830151600c819055610100840151600d5560c08401516040805191825260208201939093528083019190915290517f875352fb3fadeb8c0be7cbbe8ff761b308fa7033470cd0287f02f3436fd76cb9929181900390910190a1600091505090565b600080546001018082558161171e3333878761274b565b1491505b6000548114611765576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b5092915050565b600b5481565b610c3461178083348461306b565b604051806040016040528060168152602001751b1a5c5d5a59185d19509bdc9c9bddc819985a5b195960521b815250610a38565b6000806117bf610df8565b60075490915060009081906001600160a01b03166315f240536117e0612c1d565b600c54600d546040518463ffffffff1660e01b8152600401808481526020018381526020018281526020019350505050604080518083038186803b15801561182757600080fd5b505afa15801561183b573d6000803e3d6000fd5b505050506040513d604081101561185157600080fd5b5080516020909101519092509050811561189c5760405162461bcd60e51b8152600401808060200182810382526031815260200180614af46031913960400191505060405180910390fd5b60006118a66148da565b6118c0604051806020016040528087815250600e54612f81565b909250905060008260038111156118d357fe5b1461190f5760405162461bcd60e51b8152600401808060200182810382526031815260200180614a8c6031913960400191505060405180910390fd5b60006119196148da565b611925600c5484613173565b9092509050600082600381111561193857fe5b146119745760405162461bcd60e51b81526004018080602001828103825260318152602001806149d06031913960400191505060405180910390fd5b600061197e6148da565b6119ae6040518060200160405280670de0b6b3a764000081525060405180602001604052806009548152506131d2565b909250905060008260038111156119c157fe5b146119fd5760405162461bcd60e51b815260040180806020018281038252603c815260200180614b45603c913960400191505060405180910390fd5b6000611a076148da565b611a2060405180602001604052808b815250848761320c565b90925090506000826003811115611a3357fe5b14611a6f5760405162461bcd60e51b8152600401808060200182810382526031815260200180614a246031913960400191505060405180910390fd5b519a505050505050505050505090565b600080546001018082556006546040805163d02f735160e01b81523060048201523360248201526001600160a01b03888116604483015287811660648301526084820187905291518593929092169163d02f73519160a48082019260209290919082900301818787803b158015611af557600080fd5b505af1158015611b09573d6000803e3d6000fd5b505050506040513d6020811015611b1f57600080fd5b505190508015611b3e57611b366003601b83612ef4565b925050610e76565b856001600160a01b0316856001600160a01b03161415611b6457611b366006601c6121ef565b6001600160a01b0385166000908152600f602052604081205481908190611b8b9088612f5e565b90935091506000836003811115611b9e57fe5b14611bc157611bb66009601a8560038111156114f957fe5b955050505050610e76565b6001600160a01b0389166000908152600f6020526040902054611be49088612fe9565b90935090506000836003811115611bf757fe5b14611c0f57611bb6600960198560038111156114f957fe5b6001600160a01b038089166000818152600f60209081526040808320879055938d168083529184902085905583518b815293519193600080516020614b25833981519152929081900390910190a360065460408051636d35bf9160e01b81523060048201523360248201526001600160a01b038c811660448301528b81166064830152608482018b905291519190921691636d35bf919160a480830192600092919082900301818387803b158015611cc657600080fd5b505af1158015611cda573d6000803e3d6000fd5b5060009250611ce7915050565b9550505050506000548114610eb9576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6004546000906001600160a01b03163314611d5157610ef1600160456121ef565b600580546001600160a01b038481166001600160a01b0319831681179093556040805191909216808252602082019390935281517fca4f2f25d0898edd99413412fb94012f9e54ec8142f9b093e7720646a95b16a9929181900390910190a1600061123c565b6000805460010180825581611dca61130e565b14611e15576040805162461bcd60e51b81526020600482015260166024820152751858d8dc9d59481a5b9d195c995cdd0819985a5b195960521b604482015290519081900360640190fd5b611e1d610df8565b915060005481146110f4576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6001600160a01b0381166000908152600f6020526040812054819081908190818080611e8d89612e40565b935090506000816003811115611e9f57fe5b14611ebd5760095b975060009650869550859450611ef09350505050565b611ec561269d565b925090506000816003811115611ed757fe5b14611ee3576009611ea7565b5060009650919450925090505b9193509193565b6000610d2c82613256565b6000610d2c82613291565b6001600160a01b03918216600090815260106020908152604080832093909416825291909152205490565b611f80611f4582346132c7565b6040518060400160405280601881526020017f7265706179426f72726f77426568616c66206661696c65640000000000000000815250610a38565b50565b6005546000906001600160a01b031633141580611f9e575033155b15611fb657611faf600160006121ef565b9050610e58565b60048054600580546001600160a01b038082166001600160a01b031980861682179687905590921690925560408051938316808552949092166020840152815190927ff9ffabca9c8276e99321725bcb43fb076a6c66a54b7f21c4e8146d8519b417dc92908290030190a1600554604080516001600160a01b038085168252909216602083015280517fca4f2f25d0898edd99413412fb94012f9e54ec8142f9b093e7720646a95b16a99281900390910190a160009250505090565b60008061207d61130e565b905080156120a35761209b81601081111561209457fe5b60406121ef565b915050610f23565b61123c83612a59565b6007546001600160a01b031681565b6006546001600160a01b031681565b6004546001600160a01b031681565b600754600090819081906001600160a01b03166315f240536120f9612c1d565b600c54600d546040518463ffffffff1660e01b8152600401808481526020018381526020018281526020019350505050604080518083038186803b15801561214057600080fd5b505afa158015612154573d6000803e3d6000fd5b505050506040513d604081101561216a57600080fd5b50805160209091015190925090508115610e545760405162461bcd60e51b8152600401808060200182810382526037815260200180614abd6037913960400191505060405180910390fd5b60008054600101808255816121c861130e565b905080156121e6576109d98160108111156121df57fe5b60466121ef565b6109eb84613351565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa083601081111561221e57fe5b83604d81111561222a57fe5b604080519283526020830191909152600082820152519081900360600190a182601081111561123c57fe5b60065460408051634ef4c3e160e01b81523060048201526001600160a01b03858116602483015260448201859052915160009384931691634ef4c3e191606480830192602092919082900301818787803b1580156122b257600080fd5b505af11580156122c6573d6000803e3d6000fd5b505050506040513d60208110156122dc57600080fd5b5051905080156122fb576122f36003601f83612ef4565b915050610d2c565b612303612f5a565b600a5414612317576122f3600a60226121ef565b61231f614947565b61232985856133f4565b8190601081111561233657fe5b9081601081111561234357fe5b90525060008151601081111561235557fe5b146123705780516123679060266121ef565b92505050610d2c565b61237861269d565b604083018190526020830182600381111561238f57fe5b600381111561239a57fe5b90525060009050816020015160038111156123b157fe5b146123cd5761236760096021836020015160038111156114f957fe5b6123e98460405180602001604052808460400151815250613493565b606083018190526020830182600381111561240057fe5b600381111561240b57fe5b905250600090508160200151600381111561242257fe5b1461243e5761236760096020836020015160038111156114f957fe5b61244e600e548260600151612fe9565b608083018190526020830182600381111561246557fe5b600381111561247057fe5b905250600090508160200151600381111561248757fe5b146124a35761236760096024836020015160038111156114f957fe5b6001600160a01b0385166000908152600f602052604090205460608201516124cb9190612fe9565b60a08301819052602083018260038111156124e257fe5b60038111156124ed57fe5b905250600090508160200151600381111561250457fe5b146125205761236760096023836020015160038111156114f957fe5b61252a85856133f4565b8190601081111561253757fe5b9081601081111561254457fe5b90525060008151601081111561255657fe5b146125685780516123679060256121ef565b6080810151600e5560a08101516001600160a01b0386166000818152600f602090815260409182902093909355606080850151825193845293830188905282820193909352517f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f929181900390910190a1606081015160408051918252516001600160a01b038716913091600080516020614b258339815191529181900360200190a36006546060820151604080516341c728b960e01b81523060048201526001600160a01b038981166024830152604482018990526064820193909352905191909216916341c728b991608480830192600092919082900301818387803b15801561267357600080fd5b505af1158015612687573d6000803e3d6000fd5b5060009250612694915050565b95945050505050565b600080600e54600014156126b8575050600854600090612747565b60006126c2612c1d565b905060006126ce6148da565b60006126df84600c54600d546134aa565b9350905060008160038111156126f157fe5b146127055794506000935061274792505050565b61271183600e546134e8565b92509050600081600381111561272357fe5b146127375794506000935061274792505050565b5051600094509250612747915050565b9091565b600654604080516317b9b84b60e31b81523060048201526001600160a01b03868116602483015285811660448301526064820185905291516000938493169163bdcdc25891608480830192602092919082900301818787803b1580156127b057600080fd5b505af11580156127c4573d6000803e3d6000fd5b505050506040513d60208110156127da57600080fd5b5051905080156127f9576127f16003604a83612ef4565b915050610f94565b836001600160a01b0316856001600160a01b0316141561281f576127f16002604b6121ef565b60006001600160a01b03878116908716141561283e5750600019612866565b506001600160a01b038086166000908152601060209081526040808320938a16835292905220545b6000806000806128768589612f5e565b9094509250600084600381111561288957fe5b146128a75761289a6009604b6121ef565b9650505050505050610f94565b6001600160a01b038a166000908152600f60205260409020546128ca9089612f5e565b909450915060008460038111156128dd57fe5b146128ee5761289a6009604c6121ef565b6001600160a01b0389166000908152600f60205260409020546129119089612fe9565b9094509050600084600381111561292457fe5b146129355761289a6009604d6121ef565b6001600160a01b03808b166000908152600f6020526040808220859055918b16815220819055600019851461298d576001600160a01b03808b166000908152601060209081526040808320938f168352929052208390555b886001600160a01b03168a6001600160a01b0316600080516020614b258339815191528a6040518082815260200191505060405180910390a36006546040805163352b4a3f60e11b81523060048201526001600160a01b038d811660248301528c81166044830152606482018c905291519190921691636a56947e91608480830192600092919082900301818387803b158015612a2957600080fd5b505af1158015612a3d573d6000803e3d6000fd5b5060009250612a4a915050565b9b9a5050505050505050505050565b60045460009081906001600160a01b03163314612a7c5761209b600160426121ef565b612a84612f5a565b600a5414612a985761209b600a60416121ef565b600760009054906101000a90046001600160a01b03169050826001600160a01b0316632191f92a6040518163ffffffff1660e01b815260040160206040518083038186803b158015612ae957600080fd5b505afa158015612afd573d6000803e3d6000fd5b505050506040513d6020811015612b1357600080fd5b5051612b66576040805162461bcd60e51b815260206004820152601c60248201527f6d61726b6572206d6574686f642072657475726e65642066616c736500000000604482015290519081900360640190fd5b600780546001600160a01b0319166001600160a01b03858116918217909255604080519284168352602083019190915280517fedffc32e068c7c95dfd4bdfd5c4d939a084d6b11c4199eac8436ed234d72f9269281900390910190a1600061123c565b6000806000612bd66148da565b612be08686612f81565b90925090506000826003811115612bf357fe5b14612c045750915060009050612c16565b6000612c0f82613598565b9350935050505b9250929050565b6000806000612c2c4734612f5e565b90925090506000826003811115612c3f57fe5b14610e5457600080fd5b6000805460010180825581612c5c61130e565b90508015612c7a576109d9816010811115612c7357fe5b60366121ef565b6109eb3333866135a7565b600454600090819081906001600160a01b03163314612cb357612caa600160316121ef565b92505050610f23565b612cbb612f5a565b600a5414612ccf57612caa600a60336121ef565b83612cd8612c1d565b1015612cea57612caa600e60326121ef565b600d54841115612d0057612caa600260346121ef565b50600d5483810390811115612d465760405162461bcd60e51b8152600401808060200182810382526024815260200180614bea6024913960400191505060405180910390fd5b600d819055600454612d61906001600160a01b0316856139fa565b91506000826010811115612d7157fe5b14612dad5760405162461bcd60e51b8152600401808060200182810382526023815260200180614a016023913960400191505060405180910390fd5b600454604080516001600160a01b03909216825260208201869052818101839052517f3bad0c59cf2f06e7314077049f48a93578cd16f5ef92329f1dab1420a99c177e9181900360600190a16000949350505050565b6000805460010180825581612e1661130e565b90508015612e34576109d9816010811115612e2d57fe5b60276121ef565b6109eb33600086613a3c565b6001600160a01b038116600090815260116020526040812080548291829182918291612e77575060009450849350612eef92505050565b612e878160000154600b54613f45565b90945092506000846003811115612e9a57fe5b14612eaf575091935060009250612eef915050565b612ebd838260010154613f84565b90945091506000846003811115612ed057fe5b14612ee5575091935060009250612eef915050565b5060009450925050505b915091565b60007f45b96fe442630264581b197e84bbada861235052c5a1aadfff9ea4e40a969aa0846010811115612f2357fe5b84604d811115612f2f57fe5b604080519283526020830191909152818101859052519081900360600190a1836010811115610f9457fe5b4390565b600080838311612f75575060009050818303612c16565b50600390506000612c16565b6000612f8b6148da565b600080612f9c866000015186613f45565b90925090506000826003811115612faf57fe5b14612fce57506040805160208101909152600081529092509050612c16565b60408051602081019091529081526000969095509350505050565b60008083830184811061300157600092509050612c16565b506002915060009050612c16565b600080600061301c6148da565b6130268787612f81565b9092509050600082600381111561303957fe5b1461304a5750915060009050613063565b61305c61305682613598565b86612fe9565b9350935050505b935093915050565b600080546001018082558161307e61130e565b9050801561309c57611b3681601081111561309557fe5b600f6121ef565b836001600160a01b031663a6afed956040518163ffffffff1660e01b8152600401602060405180830381600087803b1580156130d757600080fd5b505af11580156130eb573d6000803e3d6000fd5b505050506040513d602081101561310157600080fd5b50519050801561312157611b3681601081111561311a57fe5b60106121ef565b61312d33878787613faf565b9250506000548114610eb9576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b600061317d6148da565b600080613192670de0b6b3a764000087613f45565b909250905060008260038111156131a557fe5b146131c457506040805160208101909152600081529092509050612c16565b612c0f8186600001516134e8565b60006131dc6148da565b6000806131f186600001518660000151612f5e565b60408051602081019091529081529097909650945050505050565b60006132166148da565b60006132206148da565b61322a878761448b565b9092509050600082600381111561323d57fe5b1461324c579092509050613063565b61305c818661448b565b600080546001018082558161326961130e565b90508015613287576109d981601081111561328057fe5b60086121ef565b6109eb3385614574565b60008054600101808255816132a461130e565b905080156132bb576109d9816010811115612e2d57fe5b6109eb33856000613a3c565b60008054600101808255816132da61130e565b90508015613300576132f88160108111156132f157fe5b60356121ef565b925050611722565b61330b3386866135a7565b9250506000548114611765576040805162461bcd60e51b815260206004820152600a6024820152691c994b595b9d195c995960b21b604482015290519081900360640190fd5b6004546000906001600160a01b0316331461337257610ef1600160476121ef565b61337a612f5a565b600a541461338e57610ef1600a60486121ef565b670de0b6b3a76400008211156133aa57610ef1600260496121ef565b6009805490839055604080518281526020810185905281517faaa68312e2ea9d50e16af5068410ab56e1a1fd06037b1a35664812c30f821460929181900390910190a1600061123c565b6000336001600160a01b03841614613445576040805162461bcd60e51b815260206004820152600f60248201526e0e6cadcc8cae440dad2e6dac2e8c6d608b1b604482015290519081900360640190fd5b81341461348a576040805162461bcd60e51b815260206004820152600e60248201526d0ecc2d8eaca40dad2e6dac2e8c6d60931b604482015290519081900360640190fd5b50600092915050565b60008060006134a06148da565b612be08686613173565b6000806000806134ba8787612fe9565b909250905060008260038111156134cd57fe5b146134de5750915060009050613063565b61305c8186612f5e565b60006134f26148da565b60008061350786670de0b6b3a7640000613f45565b9092509050600082600381111561351a57fe5b1461353957506040805160208101909152600081529092509050612c16565b6000806135468388613f84565b9092509050600082600381111561355957fe5b1461357b57506040805160208101909152600081529094509250612c16915050565b604080516020810190915290815260009890975095505050505050565b51670de0b6b3a7640000900490565b60065460408051631200453160e11b81523060048201526001600160a01b0386811660248301528581166044830152606482018590529151600093849316916324008a6291608480830192602092919082900301818787803b15801561360c57600080fd5b505af1158015613620573d6000803e3d6000fd5b505050506040513d602081101561363657600080fd5b5051905080156136555761364d6003603883612ef4565b91505061123c565b61365d612f5a565b600a54146136715761364d600a60396121ef565b613679614961565b6001600160a01b03851660009081526011602052604090206001015460608201526136a385612e40565b60808301819052602083018260038111156136ba57fe5b60038111156136c557fe5b90525060009050816020015160038111156136dc57fe5b14613701576136f860096037836020015160038111156114f957fe5b9250505061123c565b60001984141561371a5760808101516040820152613722565b604081018490525b6137308682604001516133f4565b8190601081111561373d57fe5b9081601081111561374a57fe5b90525060008151601081111561375c57fe5b1461376e5780516136f890603c6121ef565b61378081608001518260400151612f5e565b60a083018190526020830182600381111561379757fe5b60038111156137a257fe5b90525060009050816020015160038111156137b957fe5b146137d5576136f86009603a836020015160038111156114f957fe5b6137e5600c548260400151612f5e565b60c08301819052602083018260038111156137fc57fe5b600381111561380757fe5b905250600090508160200151600381111561381e57fe5b1461383a576136f86009603b836020015160038111156114f957fe5b6138488682604001516133f4565b8190601081111561385557fe5b9081601081111561386257fe5b90525060008151601081111561387457fe5b146138c6576040805162461bcd60e51b815260206004820152601f60248201527f726570617920626f72726f77207472616e7366657220696e206661696c656400604482015290519081900360640190fd5b60a080820180516001600160a01b03808916600081815260116020908152604091829020948555600b5460019095019490945560c0870151600c8190558188015195518251948e16855294840192909252828101949094526060820192909252608081019190915290517f1a2a22cb034d26d1854bdc6666a5b91fe25efbbb5dcad3b0355478d6f5c362a1929181900390910190a160065460408083015160608401518251631ededc9160e01b81523060048201526001600160a01b038b811660248301528a81166044830152606482019390935260848101919091529151921691631ededc919160a48082019260009290919082900301818387803b1580156139cf57600080fd5b505af11580156139e3573d6000803e3d6000fd5b50600092506139f0915050565b9695505050505050565b6040516000906001600160a01b0384169083156108fc0290849084818181858888f19350505050158015613a32573d6000803e3d6000fd5b5060009392505050565b6000821580613a49575081155b613a845760405162461bcd60e51b8152600401808060200182810382526034815260200180614bb66034913960400191505060405180910390fd5b613a8c614961565b613a9461269d565b6040830181905260208301826003811115613aab57fe5b6003811115613ab657fe5b9052506000905081602001516003811115613acd57fe5b14613ae95761364d6009602b836020015160038111156114f957fe5b8315613b6a576060810184905260408051602081018252908201518152613b109085612bc9565b6080830181905260208301826003811115613b2757fe5b6003811115613b3257fe5b9052506000905081602001516003811115613b4957fe5b14613b655761364d60096029836020015160038111156114f957fe5b613be3565b613b868360405180602001604052808460400151815250613493565b6060830181905260208301826003811115613b9d57fe5b6003811115613ba857fe5b9052506000905081602001516003811115613bbf57fe5b14613bdb5761364d6009602a836020015160038111156114f957fe5b608081018390525b60065460608201516040805163eabe7d9160e01b81523060048201526001600160a01b03898116602483015260448201939093529051600093929092169163eabe7d919160648082019260209290919082900301818787803b158015613c4857600080fd5b505af1158015613c5c573d6000803e3d6000fd5b505050506040513d6020811015613c7257600080fd5b505190508015613c89576136f86003602883612ef4565b613c91612f5a565b600a5414613ca5576136f8600a602c6121ef565b613cb5600e548360600151612f5e565b60a0840181905260208401826003811115613ccc57fe5b6003811115613cd757fe5b9052506000905082602001516003811115613cee57fe5b14613d0a576136f86009602e846020015160038111156114f957fe5b6001600160a01b0386166000908152600f60205260409020546060830151613d329190612f5e565b60c0840181905260208401826003811115613d4957fe5b6003811115613d5457fe5b9052506000905082602001516003811115613d6b57fe5b14613d87576136f86009602d846020015160038111156114f957fe5b8160800151613d94612c1d565b1015613da6576136f8600e602f6121ef565b613db48683608001516139fa565b82906010811115613dc157fe5b90816010811115613dce57fe5b905250600082516010811115613de057fe5b14613e32576040805162461bcd60e51b815260206004820152601a60248201527f72656465656d207472616e73666572206f7574206661696c6564000000000000604482015290519081900360640190fd5b60a0820151600e5560c08201516001600160a01b0387166000818152600f6020908152604091829020939093556060850151815190815290513093600080516020614b25833981519152928290030190a36080820151606080840151604080516001600160a01b038b168152602081019490945283810191909152517fe5b754fb1abb7f01b499791d0b820ae3b6af3424ac1c59768edb53f4ec31a9299281900390910190a160065460808301516060840151604080516351dff98960e01b81523060048201526001600160a01b038b81166024830152604482019490945260648101929092525191909216916351dff98991608480830192600092919082900301818387803b1580156139cf57600080fd5b60008083613f5857506000905080612c16565b83830283858281613f6557fe5b0414613f7957506002915060009050612c16565b600092509050612c16565b60008082613f985750600190506000612c16565b6000838581613fa357fe5b04915091509250929050565b60065460408051632fe3f38f60e11b81523060048201526001600160a01b0384811660248301528781166044830152868116606483015260848201869052915160009384931691635fc7e71e9160a480830192602092919082900301818787803b15801561401c57600080fd5b505af1158015614030573d6000803e3d6000fd5b505050506040513d602081101561404657600080fd5b50519050801561405d576127f16003601283612ef4565b614065612f5a565b600a5414614079576127f1600a60166121ef565b614081612f5a565b836001600160a01b0316636c540baf6040518163ffffffff1660e01b815260040160206040518083038186803b1580156140ba57600080fd5b505afa1580156140ce573d6000803e3d6000fd5b505050506040513d60208110156140e457600080fd5b5051146140f7576127f1600a60116121ef565b856001600160a01b0316856001600160a01b0316141561411d576127f1600660176121ef565b8361412e576127f1600760156121ef565b600019841415614144576127f1600760146121ef565b6006546040805163c488847b60e01b81523060048201526001600160a01b038681166024830152604482018890528251600094859492169263c488847b926064808301939192829003018186803b15801561419e57600080fd5b505afa1580156141b2573d6000803e3d6000fd5b505050506040513d60408110156141c857600080fd5b508051602090910151909250905081156141f3576141e96004601384612ef4565b9350505050610f94565b846001600160a01b03166370a08231886040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561424957600080fd5b505afa15801561425d573d6000803e3d6000fd5b505050506040513d602081101561427357600080fd5b5051811115614288576141e9600d601d6121ef565b60006142958989896135a7565b905080156142be576142b38160108111156142ac57fe5b60186121ef565b945050505050610f94565b6040805163b2a02ff160e01b81526001600160a01b038b811660048301528a8116602483015260448201859052915160009289169163b2a02ff191606480830192602092919082900301818787803b15801561431957600080fd5b505af115801561432d573d6000803e3d6000fd5b505050506040513d602081101561434357600080fd5b505190508015614391576040805162461bcd60e51b81526020600482015260146024820152731d1bdad95b881cd95a5e9d5c994819985a5b195960621b604482015290519081900360640190fd5b604080516001600160a01b03808d168252808c1660208301528183018b9052891660608201526080810185905290517f298637f684da70674f26509b10f07ec2fbc77a335ab1e7d6215a4b2484d8bb529181900360a00190a1600654604080516347ef3b3b60e01b81523060048201526001600160a01b038a811660248301528d811660448301528c81166064830152608482018c905260a48201879052915191909216916347ef3b3b9160c480830192600092919082900301818387803b15801561445c57600080fd5b505af1158015614470573d6000803e3d6000fd5b506000925061447d915050565b9a9950505050505050505050565b60006144956148da565b6000806144aa86600001518660000151613f45565b909250905060008260038111156144bd57fe5b146144dc57506040805160208101909152600081529092509050612c16565b6000806144f16706f05b59d3b2000084612fe9565b9092509050600082600381111561450457fe5b1461452657506040805160208101909152600081529094509250612c16915050565b60008061453b83670de0b6b3a7640000613f84565b9092509050600082600381111561454e57fe5b1461455557fe5b604080516020810190915290815260009a909950975050505050505050565b6006546040805163368f515360e21b81523060048201526001600160a01b0385811660248301526044820185905291516000938493169163da3d454c91606480830192602092919082900301818787803b1580156145d157600080fd5b505af11580156145e5573d6000803e3d6000fd5b505050506040513d60208110156145fb57600080fd5b505190508015614612576122f36003600e83612ef4565b61461a612f5a565b600a541461462d576122f3600a806121ef565b82614636612c1d565b1015614648576122f3600e60096121ef565b61465061499f565b61465985612e40565b604083018190526020830182600381111561467057fe5b600381111561467b57fe5b905250600090508160200151600381111561469257fe5b146146ae5761236760096007836020015160038111156114f957fe5b6146bc816040015185612fe9565b60608301819052602083018260038111156146d357fe5b60038111156146de57fe5b90525060009050816020015160038111156146f557fe5b14614711576123676009600c836020015160038111156114f957fe5b61471d600c5485612fe9565b608083018190526020830182600381111561473457fe5b600381111561473f57fe5b905250600090508160200151600381111561475657fe5b14614772576123676009600b836020015160038111156114f957fe5b61477c85856139fa565b8190601081111561478957fe5b9081601081111561479657fe5b9052506000815160108111156147a857fe5b146147fa576040805162461bcd60e51b815260206004820152601a60248201527f626f72726f77207472616e73666572206f7574206661696c6564000000000000604482015290519081900360640190fd5b606080820180516001600160a01b038816600081815260116020908152604091829020938455600b54600190940193909355608080870151600c819055945182519384529383018a9052828201939093529381019290925291517f13ed6866d4e1ee6da46f845c46d7e54120883d75c5ea9a2dacc1c4ca8984ab80929181900390910190a160065460408051635c77860560e01b81523060048201526001600160a01b0388811660248301526044820188905291519190921691635c77860591606480830192600092919082900301818387803b15801561267357600080fd5b6040518060200160405280600081525090565b6040805161014081019091528060008152602001600081526020016000815260200160008152602001600081526020016149256148da565b8152602001600081526020016000815260200160008152602001600081525090565b6040805160c0810190915280600081526020016000614925565b6040805160e0810190915280600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6040805160a08101909152806000815260200160008152602001600081526020016000815260200160008152509056fe737570706c7952617465506572426c6f636b3a2063616c63756c6174696e6720626f72726f7773506572206661696c6564726564756365207265736572766573207472616e73666572206f7574206661696c6564737570706c7952617465506572426c6f636b3a2063616c63756c6174696e6720737570706c7952617465206661696c6564626f72726f7742616c616e636553746f7265643a20626f72726f7742616c616e636553746f726564496e7465726e616c206661696c6564737570706c7952617465506572426c6f636b3a2063616c63756c6174696e6720756e6465726c79696e67206661696c6564626f72726f7752617465506572426c6f636b3a20696e746572657374526174654d6f64656c2e626f72726f7752617465206661696c6564737570706c7952617465506572426c6f636b3a2063616c63756c6174696e6720626f72726f7752617465206661696c6564ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef737570706c7952617465506572426c6f636b3a2063616c63756c6174696e67206f6e654d696e757352657365727665466163746f72206661696c656465786368616e67655261746553746f7265643a2065786368616e67655261746553746f726564496e7465726e616c206661696c65646f6e65206f662072656465656d546f6b656e73496e206f722072656465656d416d6f756e74496e206d757374206265207a65726f72656475636520726573657276657320756e657870656374656420756e646572666c6f77a265627a7a72315820c083756c3e8a158a35e507d4a58773aa348c98009ad6c2d72645ca1023abe1a664736f6c63430005100032
Verified Source Code Partial Match
Compiler: v0.5.16+commit.9c3226ce
EVM: istanbul
Optimization: Yes (200 runs)
AEther.sol 2288 lines
pragma solidity ^0.5.16;
/**
* @title Artem Ether Contract
* @notice Derived from Compound's cEther contract
* https://github.com/compound-finance/compound-protocol/tree/master/contracts
*/
/**
* @title Careful Math
* @notice Derived from OpenZeppelin's SafeMath library
* https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/math/SafeMath.sol
*/
contract CarefulMath {
enum MathError {
NO_ERROR,
DIVISION_BY_ZERO,
INTEGER_OVERFLOW,
INTEGER_UNDERFLOW
}
/**
* @dev Multiplies two numbers, returns an error on overflow.
*/
function mulUInt(uint a, uint b) internal pure returns (MathError, uint) {
if (a == 0) {
return (MathError.NO_ERROR, 0);
}
uint c = a * b;
if (c / a != b) {
return (MathError.INTEGER_OVERFLOW, 0);
} else {
return (MathError.NO_ERROR, c);
}
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function divUInt(uint a, uint b) internal pure returns (MathError, uint) {
if (b == 0) {
return (MathError.DIVISION_BY_ZERO, 0);
}
return (MathError.NO_ERROR, a / b);
}
/**
* @dev Subtracts two numbers, returns an error on overflow (i.e. if subtrahend is greater than minuend).
*/
function subUInt(uint a, uint b) internal pure returns (MathError, uint) {
if (b <= a) {
return (MathError.NO_ERROR, a - b);
} else {
return (MathError.INTEGER_UNDERFLOW, 0);
}
}
/**
* @dev Adds two numbers, returns an error on overflow.
*/
function addUInt(uint a, uint b) internal pure returns (MathError, uint) {
uint c = a + b;
if (c >= a) {
return (MathError.NO_ERROR, c);
} else {
return (MathError.INTEGER_OVERFLOW, 0);
}
}
/**
* @dev add a and b and then subtract c
*/
function addThenSubUInt(uint a, uint b, uint c) internal pure returns (MathError, uint) {
(MathError err0, uint sum) = addUInt(a, b);
if (err0 != MathError.NO_ERROR) {
return (err0, 0);
}
return subUInt(sum, c);
}
}
interface ControllerInterface {
function isController() external view returns (bool);
function enterMarkets(address[] calldata aTokens) external returns (uint[] memory);
function exitMarket(address aToken) external returns (uint);
function mintAllowed(address aToken, address minter, uint mintAmount) external returns (uint);
function mintVerify(address aToken, address minter, uint mintAmount, uint mintTokens) external;
function redeemAllowed(address aToken, address redeemer, uint redeemTokens) external returns (uint);
function redeemVerify(address aToken, address redeemer, uint redeemAmount, uint redeemTokens) external;
function borrowAllowed(address aToken, address borrower, uint borrowAmount) external returns (uint);
function borrowVerify(address aToken, address borrower, uint borrowAmount) external;
function repayBorrowAllowed(
address aToken,
address payer,
address borrower,
uint repayAmount) external returns (uint);
function repayBorrowVerify(
address aToken,
address payer,
address borrower,
uint repayAmount,
uint borrowerIndex) external;
function liquidateBorrowAllowed(
address aTokenBorrowed,
address aTokenCollateral,
address liquidator,
address borrower,
uint repayAmount) external returns (uint);
function liquidateBorrowVerify(
address aTokenBorrowed,
address aTokenCollateral,
address liquidator,
address borrower,
uint repayAmount,
uint seizeTokens) external;
function seizeAllowed(
address aTokenCollateral,
address aTokenBorrowed,
address liquidator,
address borrower,
uint seizeTokens) external returns (uint);
function seizeVerify(
address aTokenCollateral,
address aTokenBorrowed,
address liquidator,
address borrower,
uint seizeTokens) external;
function transferAllowed(address aToken, address src, address dst, uint transferTokens) external returns (uint);
function transferVerify(address aToken, address src, address dst, uint transferTokens) external;
function liquidateCalculateSeizeTokens(
address aTokenBorrowed,
address aTokenCollateral,
uint repayAmount) external view returns (uint, uint);
}
contract ControllerErrorReporter {
event Failure(uint error, uint info, uint detail);
function fail(Error err, FailureInfo info) internal returns (uint) {
emit Failure(uint(err), uint(info), 0);
return uint(err);
}
function failOpaque(Error err, FailureInfo info, uint opaqueError) internal returns (uint) {
emit Failure(uint(err), uint(info), opaqueError);
return uint(err);
}
enum Error {
NO_ERROR,
UNAUTHORIZED,
CONTROLLER_MISMATCH,
INSUFFICIENT_SHORTFALL,
INSUFFICIENT_LIQUIDITY,
INVALID_CLOSE_FACTOR,
INVALID_COLLATERAL_FACTOR,
INVALID_LIQUIDATION_INCENTIVE,
MARKET_NOT_ENTERED,
MARKET_NOT_LISTED,
MARKET_ALREADY_LISTED,
MATH_ERROR,
NONZERO_BORROW_BALANCE,
PRICE_ERROR,
REJECTION,
SNAPSHOT_ERROR,
TOO_MANY_ASSETS,
TOO_MUCH_REPAY
}
enum FailureInfo {
ACCEPT_ADMIN_PENDING_ADMIN_CHECK,
ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK,
EXIT_MARKET_BALANCE_OWED,
EXIT_MARKET_REJECTION,
SET_CLOSE_FACTOR_OWNER_CHECK,
SET_CLOSE_FACTOR_VALIDATION,
SET_COLLATERAL_FACTOR_OWNER_CHECK,
SET_COLLATERAL_FACTOR_NO_EXISTS,
SET_COLLATERAL_FACTOR_VALIDATION,
SET_COLLATERAL_FACTOR_WITHOUT_PRICE,
SET_IMPLEMENTATION_OWNER_CHECK,
SET_LIQUIDATION_INCENTIVE_OWNER_CHECK,
SET_LIQUIDATION_INCENTIVE_VALIDATION,
SET_MAX_ASSETS_OWNER_CHECK,
SET_PENDING_ADMIN_OWNER_CHECK,
SET_PENDING_IMPLEMENTATION_OWNER_CHECK,
SET_PRICE_ORACLE_OWNER_CHECK,
SUPPORT_MARKET_EXISTS,
SUPPORT_MARKET_OWNER_CHECK,
ZUNUSED
}
}
contract TokenErrorReporter {
event Failure(uint error, uint info, uint detail);
function fail(Error err, FailureInfo info) internal returns (uint) {
emit Failure(uint(err), uint(info), 0);
return uint(err);
}
function failOpaque(Error err, FailureInfo info, uint opaqueError) internal returns (uint) {
emit Failure(uint(err), uint(info), opaqueError);
return uint(err);
}
enum Error {
NO_ERROR,
UNAUTHORIZED,
BAD_INPUT,
CONTROLLER_REJECTION,
CONTROLLER_CALCULATION_ERROR,
INTEREST_RATE_MODEL_ERROR,
INVALID_ACCOUNT_PAIR,
INVALID_CLOSE_AMOUNT_REQUESTED,
INVALID_COLLATERAL_FACTOR,
MATH_ERROR,
MARKET_NOT_FRESH,
MARKET_NOT_LISTED,
TOKEN_INSUFFICIENT_ALLOWANCE,
TOKEN_INSUFFICIENT_BALANCE,
TOKEN_INSUFFICIENT_CASH,
TOKEN_TRANSFER_IN_FAILED,
TOKEN_TRANSFER_OUT_FAILED
}
enum FailureInfo {
ACCEPT_ADMIN_PENDING_ADMIN_CHECK,
ACCRUE_INTEREST_ACCUMULATED_INTEREST_CALCULATION_FAILED,
ACCRUE_INTEREST_BORROW_RATE_CALCULATION_FAILED,
ACCRUE_INTEREST_NEW_BORROW_INDEX_CALCULATION_FAILED,
ACCRUE_INTEREST_NEW_TOTAL_BORROWS_CALCULATION_FAILED,
ACCRUE_INTEREST_NEW_TOTAL_RESERVES_CALCULATION_FAILED,
ACCRUE_INTEREST_SIMPLE_INTEREST_FACTOR_CALCULATION_FAILED,
BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED,
BORROW_ACCRUE_INTEREST_FAILED,
BORROW_CASH_NOT_AVAILABLE,
BORROW_FRESHNESS_CHECK,
BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED,
BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED,
BORROW_MARKET_NOT_LISTED,
BORROW_CONTROLLER_REJECTION,
LIQUIDATE_ACCRUE_BORROW_INTEREST_FAILED,
LIQUIDATE_ACCRUE_COLLATERAL_INTEREST_FAILED,
LIQUIDATE_COLLATERAL_FRESHNESS_CHECK,
LIQUIDATE_CONTROLLER_REJECTION,
LIQUIDATE_CONTROLLER_CALCULATE_AMOUNT_SEIZE_FAILED,
LIQUIDATE_CLOSE_AMOUNT_IS_UINT_MAX,
LIQUIDATE_CLOSE_AMOUNT_IS_ZERO,
LIQUIDATE_FRESHNESS_CHECK,
LIQUIDATE_LIQUIDATOR_IS_BORROWER,
LIQUIDATE_REPAY_BORROW_FRESH_FAILED,
LIQUIDATE_SEIZE_BALANCE_INCREMENT_FAILED,
LIQUIDATE_SEIZE_BALANCE_DECREMENT_FAILED,
LIQUIDATE_SEIZE_CONTROLLER_REJECTION,
LIQUIDATE_SEIZE_LIQUIDATOR_IS_BORROWER,
LIQUIDATE_SEIZE_TOO_MUCH,
MINT_ACCRUE_INTEREST_FAILED,
MINT_CONTROLLER_REJECTION,
MINT_EXCHANGE_CALCULATION_FAILED,
MINT_EXCHANGE_RATE_READ_FAILED,
MINT_FRESHNESS_CHECK,
MINT_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED,
MINT_NEW_TOTAL_SUPPLY_CALCULATION_FAILED,
MINT_TRANSFER_IN_FAILED,
MINT_TRANSFER_IN_NOT_POSSIBLE,
REDEEM_ACCRUE_INTEREST_FAILED,
REDEEM_CONTROLLER_REJECTION,
REDEEM_EXCHANGE_TOKENS_CALCULATION_FAILED,
REDEEM_EXCHANGE_AMOUNT_CALCULATION_FAILED,
REDEEM_EXCHANGE_RATE_READ_FAILED,
REDEEM_FRESHNESS_CHECK,
REDEEM_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED,
REDEEM_NEW_TOTAL_SUPPLY_CALCULATION_FAILED,
REDEEM_TRANSFER_OUT_NOT_POSSIBLE,
REDUCE_RESERVES_ACCRUE_INTEREST_FAILED,
REDUCE_RESERVES_ADMIN_CHECK,
REDUCE_RESERVES_CASH_NOT_AVAILABLE,
REDUCE_RESERVES_FRESH_CHECK,
REDUCE_RESERVES_VALIDATION,
REPAY_BEHALF_ACCRUE_INTEREST_FAILED,
REPAY_BORROW_ACCRUE_INTEREST_FAILED,
REPAY_BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED,
REPAY_BORROW_CONTROLLER_REJECTION,
REPAY_BORROW_FRESHNESS_CHECK,
REPAY_BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED,
REPAY_BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED,
REPAY_BORROW_TRANSFER_IN_NOT_POSSIBLE,
SET_COLLATERAL_FACTOR_OWNER_CHECK,
SET_COLLATERAL_FACTOR_VALIDATION,
SET_CONTROLLER_OWNER_CHECK,
SET_INTEREST_RATE_MODEL_ACCRUE_INTEREST_FAILED,
SET_INTEREST_RATE_MODEL_FRESH_CHECK,
SET_INTEREST_RATE_MODEL_OWNER_CHECK,
SET_MAX_ASSETS_OWNER_CHECK,
SET_ORACLE_MARKET_NOT_LISTED,
SET_PENDING_ADMIN_OWNER_CHECK,
SET_RESERVE_FACTOR_ACCRUE_INTEREST_FAILED,
SET_RESERVE_FACTOR_ADMIN_CHECK,
SET_RESERVE_FACTOR_FRESH_CHECK,
SET_RESERVE_FACTOR_BOUNDS_CHECK,
TRANSFER_CONTROLLER_REJECTION,
TRANSFER_NOT_ALLOWED,
TRANSFER_NOT_ENOUGH,
TRANSFER_TOO_MUCH
}
}
contract Exponential is CarefulMath {
uint constant expScale = 1e18;
uint constant halfExpScale = expScale/2;
uint constant mantissaOne = expScale;
struct Exp {
uint mantissa;
}
function getExp(uint num, uint denom) pure internal returns (MathError, Exp memory) {
(MathError err0, uint scaledNumerator) = mulUInt(num, expScale);
if (err0 != MathError.NO_ERROR) {
return (err0, Exp({mantissa: 0}));
}
(MathError err1, uint rational) = divUInt(scaledNumerator, denom);
if (err1 != MathError.NO_ERROR) {
return (err1, Exp({mantissa: 0}));
}
return (MathError.NO_ERROR, Exp({mantissa: rational}));
}
function addExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) {
(MathError error, uint result) = addUInt(a.mantissa, b.mantissa);
return (error, Exp({mantissa: result}));
}
function subExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) {
(MathError error, uint result) = subUInt(a.mantissa, b.mantissa);
return (error, Exp({mantissa: result}));
}
function mulScalar(Exp memory a, uint scalar) pure internal returns (MathError, Exp memory) {
(MathError err0, uint scaledMantissa) = mulUInt(a.mantissa, scalar);
if (err0 != MathError.NO_ERROR) {
return (err0, Exp({mantissa: 0}));
}
return (MathError.NO_ERROR, Exp({mantissa: scaledMantissa}));
}
function mulScalarTruncate(Exp memory a, uint scalar) pure internal returns (MathError, uint) {
(MathError err, Exp memory product) = mulScalar(a, scalar);
if (err != MathError.NO_ERROR) {
return (err, 0);
}
return (MathError.NO_ERROR, truncate(product));
}
function mulScalarTruncateAddUInt(Exp memory a, uint scalar, uint addend) pure internal returns (MathError, uint) {
(MathError err, Exp memory product) = mulScalar(a, scalar);
if (err != MathError.NO_ERROR) {
return (err, 0);
}
return addUInt(truncate(product), addend);
}
function divScalar(Exp memory a, uint scalar) pure internal returns (MathError, Exp memory) {
(MathError err0, uint descaledMantissa) = divUInt(a.mantissa, scalar);
if (err0 != MathError.NO_ERROR) {
return (err0, Exp({mantissa: 0}));
}
return (MathError.NO_ERROR, Exp({mantissa: descaledMantissa}));
}
function divScalarByExp(uint scalar, Exp memory divisor) pure internal returns (MathError, Exp memory) {
/*
We are doing this as:
getExp(mulUInt(expScale, scalar), divisor.mantissa)
How it works:
Exp = a / b;
Scalar = s;
`s / (a / b)` = `b * s / a` and since for an Exp `a = mantissa, b = expScale`
*/
(MathError err0, uint numerator) = mulUInt(expScale, scalar);
if (err0 != MathError.NO_ERROR) {
return (err0, Exp({mantissa: 0}));
}
return getExp(numerator, divisor.mantissa);
}
function divScalarByExpTruncate(uint scalar, Exp memory divisor) pure internal returns (MathError, uint) {
(MathError err, Exp memory fraction) = divScalarByExp(scalar, divisor);
if (err != MathError.NO_ERROR) {
return (err, 0);
}
return (MathError.NO_ERROR, truncate(fraction));
}
function mulExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) {
(MathError err0, uint doubleScaledProduct) = mulUInt(a.mantissa, b.mantissa);
if (err0 != MathError.NO_ERROR) {
return (err0, Exp({mantissa: 0}));
}
// We add half the scale before dividing so that we get rounding instead of truncation.
// See "Listing 6" and text above it at https://accu.org/index.php/journals/1717
// Without this change, a result like 6.6...e-19 will be truncated to 0 instead of being rounded to 1e-18.
(MathError err1, uint doubleScaledProductWithHalfScale) = addUInt(halfExpScale, doubleScaledProduct);
if (err1 != MathError.NO_ERROR) {
return (err1, Exp({mantissa: 0}));
}
(MathError err2, uint product) = divUInt(doubleScaledProductWithHalfScale, expScale);
// The only error `div` can return is MathError.DIVISION_BY_ZERO but we control `expScale` and it is not zero.
assert(err2 == MathError.NO_ERROR);
return (MathError.NO_ERROR, Exp({mantissa: product}));
}
function mulExp(uint a, uint b) pure internal returns (MathError, Exp memory) {
return mulExp(Exp({mantissa: a}), Exp({mantissa: b}));
}
function mulExp3(Exp memory a, Exp memory b, Exp memory c) pure internal returns (MathError, Exp memory) {
(MathError err, Exp memory ab) = mulExp(a, b);
if (err != MathError.NO_ERROR) {
return (err, ab);
}
return mulExp(ab, c);
}
/**
* @dev Divides two exponentials, returning a new exponential.
* (a/scale) / (b/scale) = (a/scale) * (scale/b) = a/b,
* which we can scale as an Exp by calling getExp(a.mantissa, b.mantissa)
*/
function divExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) {
return getExp(a.mantissa, b.mantissa);
}
function truncate(Exp memory exp) pure internal returns (uint) {
// Note: We are not using careful math here as we're performing a division that cannot fail
return exp.mantissa / expScale;
}
function lessThanExp(Exp memory left, Exp memory right) pure internal returns (bool) {
return left.mantissa < right.mantissa; //TODO: Add some simple tests and this in another PR yo.
}
function lessThanOrEqualExp(Exp memory left, Exp memory right) pure internal returns (bool) {
return left.mantissa <= right.mantissa;
}
function isZeroExp(Exp memory value) pure internal returns (bool) {
return value.mantissa == 0;
}
}
/**
* @title ERC 20 Token Standard Interface
* https://eips.ethereum.org/EIPS/eip-20
*/
interface EIP20Interface {
/**
* @notice Get the total number of tokens in circulation
* @return The supply of tokens
*/
function totalSupply() external view returns (uint256);
/**
* @notice Gets the balance of the specified address
* @param owner The address from which the balance will be retrieved
* @return The balance
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @notice Transfer `amount` tokens from `msg.sender` to `dst`
* @param dst The address of the destination account
* @param amount The number of tokens to transfer
* @return Whether or not the transfer succeeded
*/
function transfer(address dst, uint256 amount) external returns (bool success);
/**
* @notice Transfer `amount` tokens from `src` to `dst`
* @param src The address of the source account
* @param dst The address of the destination account
* @param amount The number of tokens to transfer
* @return Whether or not the transfer succeeded
*/
function transferFrom(address src, address dst, uint256 amount) external returns (bool success);
/**
* @notice Approve `spender` to transfer up to `amount` from `src`
* @dev This will overwrite the approval amount for `spender`
* and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)
* @param spender The address of the account which may transfer tokens
* @param amount The number of tokens that are approved (-1 means infinite)
* @return Whether or not the approval succeeded
*/
function approve(address spender, uint256 amount) external returns (bool success);
/**
* @notice Get the current allowance from `owner` for `spender`
* @param owner The address of the account which owns the tokens to be spent
* @param spender The address of the account which may transfer tokens
* @return The number of tokens allowed to be spent (-1 means infinite)
*/
function allowance(address owner, address spender) external view returns (uint256 remaining);
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
}
/**
* @title EIP20NonStandardInterface
* @dev Version of ERC20 with no return values for `transfer` and `transferFrom`
* See https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca
*/
interface EIP20NonStandardInterface {
function totalSupply() external view returns (uint256);
function balanceOf(address owner) external view returns (uint256 balance);
function transfer(address dst, uint256 amount) external;
function transferFrom(address src, address dst, uint256 amount) external;
function approve(address spender, uint256 amount) external returns (bool success);
function allowance(address owner, address spender) external view returns (uint256 remaining);
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
}
/**
* @title Helps contracts guard against reentrancy attacks.
* @author Remco Bloemen <remco@2π.com>, Eenae <[email protected]>
* @dev If you mark a function `nonReentrant`, you should also
* mark it `external`.
*/
contract ReentrancyGuard {
/// @dev counter to allow mutex lock with only one SSTORE operation
uint256 private _guardCounter;
constructor () internal {
// The counter starts at one to prevent changing it from zero to a non-zero
// value, which is a more expensive operation.
_guardCounter = 1;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and make it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_guardCounter += 1;
uint256 localCounter = _guardCounter;
_;
require(localCounter == _guardCounter, "re-entered");
}
}
interface InterestRateModel {
function getBorrowRate(uint cash, uint borrows, uint reserves) external view returns (uint, uint);
function isInterestRateModel() external view returns (bool);
}
contract AToken is EIP20Interface, Exponential, TokenErrorReporter, ReentrancyGuard {
/**
* @notice Indicator that this is a AToken contract (for inspection)
*/
bool public constant isAToken = true;
/**
* @notice EIP-20 token name for this token
*/
string public name;
/**
* @notice EIP-20 token symbol for this token
*/
string public symbol;
/**
* @notice EIP-20 token decimals for this token
*/
uint public decimals;
/**
* @notice Maximum borrow rate that can ever be applied (.0005% / block)
*/
uint constant borrowRateMaxMantissa = 5e14;
/**
* @notice Maximum fraction of interest that can be set aside for reserves
*/
uint constant reserveFactorMaxMantissa = 1e18;
/**
* @notice Administrator for this contract
*/
address payable public admin;
/**
* @notice Pending administrator for this contract
*/
address payable public pendingAdmin;
/**
* @notice Contract which oversees inter-aToken operations
*/
ControllerInterface public controller;
/**
* @notice Model which tells what the current interest rate should be
*/
InterestRateModel public interestRateModel;
/**
* @notice Initial exchange rate used when minting the first ATokens (used when totalSupply = 0)
*/
uint public initialExchangeRateMantissa;
/**
* @notice Fraction of interest currently set aside for reserves
*/
uint public reserveFactorMantissa;
/**
* @notice Block number that interest was last accrued at
*/
uint public accrualBlockNumber;
/**
* @notice Accumulator of total earned interest since the opening of the market
*/
uint public borrowIndex;
/**
* @notice Total amount of outstanding borrows of the underlying in this market
*/
uint public totalBorrows;
/**
* @notice Total amount of reserves of the underlying held in this market
*/
uint public totalReserves;
/**
* @notice Total number of tokens in circulation
*/
uint256 public totalSupply;
/**
* @notice Official record of token balances for each account
*/
mapping (address => uint256) accountTokens;
/**
* @notice Approved token transfer amounts on behalf of others
*/
mapping (address => mapping (address => uint256)) transferAllowances;
/**
* @notice Container for borrow balance information
* @member principal Total balance (with accrued interest), after applying the most recent balance-changing action
* @member interestIndex Global borrowIndex as of the most recent balance-changing action
*/
struct BorrowSnapshot {
uint principal;
uint interestIndex;
}
/**
* @notice Mapping of account addresses to outstanding borrow balances
*/
mapping(address => BorrowSnapshot) accountBorrows;
/*** Market Events ***/
/**
* @notice Event emitted when interest is accrued
*/
event AccrueInterest(uint interestAccumulated, uint borrowIndex, uint totalBorrows);
/**
* @notice Event emitted when tokens are minted
*/
event Mint(address minter, uint mintAmount, uint mintTokens);
/**
* @notice Event emitted when tokens are redeemed
*/
event Redeem(address redeemer, uint redeemAmount, uint redeemTokens);
/**
* @notice Event emitted when underlying is borrowed
*/
event Borrow(address borrower, uint borrowAmount, uint accountBorrows, uint totalBorrows);
/**
* @notice Event emitted when a borrow is repaid
*/
event RepayBorrow(address payer, address borrower, uint repayAmount, uint accountBorrows, uint totalBorrows);
/**
* @notice Event emitted when a borrow is liquidated
*/
event LiquidateBorrow(address liquidator, address borrower, uint repayAmount, address aTokenCollateral, uint seizeTokens);
/*** Admin Events ***/
/**
* @notice Event emitted when pendingAdmin is changed
*/
event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin);
/**
* @notice Event emitted when pendingAdmin is accepted, which means admin is updated
*/
event NewAdmin(address oldAdmin, address newAdmin);
/**
* @notice Event emitted when controller is changed
*/
event NewController(ControllerInterface oldController, ControllerInterface newController);
/**
* @notice Event emitted when interestRateModel is changed
*/
event NewMarketInterestRateModel(InterestRateModel oldInterestRateModel, InterestRateModel newInterestRateModel);
/**
* @notice Event emitted when the reserve factor is changed
*/
event NewReserveFactor(uint oldReserveFactorMantissa, uint newReserveFactorMantissa);
/**
* @notice Event emitted when the reserves are reduced
*/
event ReservesReduced(address admin, uint reduceAmount, uint newTotalReserves);
constructor( ) public {
admin = msg.sender;
// Set initial exchange rate
initialExchangeRateMantissa = uint(200000000000000000000000000);
accrualBlockNumber = getBlockNumber();
borrowIndex = mantissaOne;
name = string("Artem Ether");
symbol = string("aETH");
decimals = uint(8);
}
function transferTokens(address spender, address src, address dst, uint tokens) internal returns (uint) {
/* Fail if transfer not allowed */
uint allowed = controller.transferAllowed(address(this), src, dst, tokens);
if (allowed != 0) {
return failOpaque(Error.CONTROLLER_REJECTION, FailureInfo.TRANSFER_CONTROLLER_REJECTION, allowed);
}
/* Do not allow self-transfers */
if (src == dst) {
return fail(Error.BAD_INPUT, FailureInfo.TRANSFER_NOT_ALLOWED);
}
/* Get the allowance, infinite for the account owner */
uint startingAllowance = 0;
if (spender == src) {
startingAllowance = uint(-1);
} else {
startingAllowance = transferAllowances[src][spender];
}
/* Do the calculations, checking for {under,over}flow */
MathError mathErr;
uint allowanceNew;
uint srcTokensNew;
uint dstTokensNew;
(mathErr, allowanceNew) = subUInt(startingAllowance, tokens);
if (mathErr != MathError.NO_ERROR) {
return fail(Error.MATH_ERROR, FailureInfo.TRANSFER_NOT_ALLOWED);
}
(mathErr, srcTokensNew) = subUInt(accountTokens[src], tokens);
if (mathErr != MathError.NO_ERROR) {
return fail(Error.MATH_ERROR, FailureInfo.TRANSFER_NOT_ENOUGH);
}
(mathErr, dstTokensNew) = addUInt(accountTokens[dst], tokens);
if (mathErr != MathError.NO_ERROR) {
return fail(Error.MATH_ERROR, FailureInfo.TRANSFER_TOO_MUCH);
}
/////////////////////////
// EFFECTS & INTERACTIONS
// (No safe failures beyond this point)
accountTokens[src] = srcTokensNew;
accountTokens[dst] = dstTokensNew;
/* Eat some of the allowance (if necessary) */
if (startingAllowance != uint(-1)) {
transferAllowances[src][spender] = allowanceNew;
}
/* We emit a Transfer event */
emit Transfer(src, dst, tokens);
/* We call the defense hook (which checks for under-collateralization) */
controller.transferVerify(address(this), src, dst, tokens);
return uint(Error.NO_ERROR);
}
/**
* @notice Transfer `amount` tokens from `msg.sender` to `dst`
* @param dst The address of the destination account
* @param amount The number of tokens to transfer
* @return Whether or not the transfer succeeded
*/
function transfer(address dst, uint256 amount) external nonReentrant returns (bool) {
return transferTokens(msg.sender, msg.sender, dst, amount) == uint(Error.NO_ERROR);
}
/**
* @notice Transfer `amount` tokens from `src` to `dst`
* @param src The address of the source account
* @param dst The address of the destination account
* @param amount The number of tokens to transfer
* @return Whether or not the transfer succeeded
*/
function transferFrom(address src, address dst, uint256 amount) external nonReentrant returns (bool) {
return transferTokens(msg.sender, src, dst, amount) == uint(Error.NO_ERROR);
}
/**
* @notice Approve `spender` to transfer up to `amount` from `src`
* @dev This will overwrite the approval amount for `spender`
* and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)
* @param spender The address of the account which may transfer tokens
* @param amount The number of tokens that are approved (-1 means infinite)
* @return Whether or not the approval succeeded
*/
function approve(address spender, uint256 amount) external returns (bool) {
address src = msg.sender;
transferAllowances[src][spender] = amount;
emit Approval(src, spender, amount);
return true;
}
/**
* @notice Get the current allowance from `owner` for `spender`
* @param owner The address of the account which owns the tokens to be spent
* @param spender The address of the account which may transfer tokens
* @return The number of tokens allowed to be spent (-1 means infinite)
*/
function allowance(address owner, address spender) external view returns (uint256) {
return transferAllowances[owner][spender];
}
/**
* @notice Get the token balance of the `owner`
* @param owner The address of the account to query
* @return The number of tokens owned by `owner`
*/
function balanceOf(address owner) external view returns (uint256) {
return accountTokens[owner];
}
/**
* @notice Get the underlying balance of the `owner`
* @dev This also accrues interest in a transaction
* @param owner The address of the account to query
* @return The amount of underlying owned by `owner`
*/
function balanceOfUnderlying(address owner) external returns (uint) {
Exp memory exchangeRate = Exp({mantissa: exchangeRateCurrent()});
(MathError mErr, uint balance) = mulScalarTruncate(exchangeRate, accountTokens[owner]);
require(mErr == MathError.NO_ERROR);
return balance;
}
/**
* @notice Get a snapshot of the account's balances, and the cached exchange rate
* @dev This is used by controller to more efficiently perform liquidity checks.
* @param account Address of the account to snapshot
* @return (possible error, token balance, borrow balance, exchange rate mantissa)
*/
function getAccountSnapshot(address account) external view returns (uint, uint, uint, uint) {
uint aTokenBalance = accountTokens[account];
uint borrowBalance;
uint exchangeRateMantissa;
MathError mErr;
(mErr, borrowBalance) = borrowBalanceStoredInternal(account);
if (mErr != MathError.NO_ERROR) {
return (uint(Error.MATH_ERROR), 0, 0, 0);
}
(mErr, exchangeRateMantissa) = exchangeRateStoredInternal();
if (mErr != MathError.NO_ERROR) {
return (uint(Error.MATH_ERROR), 0, 0, 0);
}
return (uint(Error.NO_ERROR), aTokenBalance, borrowBalance, exchangeRateMantissa);
}
/**
* @dev Function to simply retrieve block number
* This exists mainly for inheriting test contracts to stub this result.
*/
function getBlockNumber() internal view returns (uint) {
return block.number;
}
/**
* @notice Returns the current per-block borrow interest rate for this aToken
* @return The borrow interest rate per block, scaled by 1e18
*/
function borrowRatePerBlock() external view returns (uint) {
(uint opaqueErr, uint borrowRateMantissa) = interestRateModel.getBorrowRate(getCashPrior(), totalBorrows, totalReserves);
require(opaqueErr == 0, "borrowRatePerBlock: interestRateModel.borrowRate failed"); // semi-opaque
return borrowRateMantissa;
}
/**
* @notice Returns the current per-block supply interest rate for this aToken
* @return The supply interest rate per block, scaled by 1e18
*/
function supplyRatePerBlock() external view returns (uint) {
/* We calculate the supply rate:
* underlying = totalSupply × exchangeRate
* borrowsPer = totalBorrows ÷ underlying
* supplyRate = borrowRate × (1-reserveFactor) × borrowsPer
*/
uint exchangeRateMantissa = exchangeRateStored();
(uint e0, uint borrowRateMantissa) = interestRateModel.getBorrowRate(getCashPrior(), totalBorrows, totalReserves);
require(e0 == 0, "supplyRatePerBlock: calculating borrowRate failed"); // semi-opaque
(MathError e1, Exp memory underlying) = mulScalar(Exp({mantissa: exchangeRateMantissa}), totalSupply);
require(e1 == MathError.NO_ERROR, "supplyRatePerBlock: calculating underlying failed");
(MathError e2, Exp memory borrowsPer) = divScalarByExp(totalBorrows, underlying);
require(e2 == MathError.NO_ERROR, "supplyRatePerBlock: calculating borrowsPer failed");
(MathError e3, Exp memory oneMinusReserveFactor) = subExp(Exp({mantissa: mantissaOne}), Exp({mantissa: reserveFactorMantissa}));
require(e3 == MathError.NO_ERROR, "supplyRatePerBlock: calculating oneMinusReserveFactor failed");
(MathError e4, Exp memory supplyRate) = mulExp3(Exp({mantissa: borrowRateMantissa}), oneMinusReserveFactor, borrowsPer);
require(e4 == MathError.NO_ERROR, "supplyRatePerBlock: calculating supplyRate failed");
return supplyRate.mantissa;
}
/**
* @notice Returns the current total borrows plus accrued interest
* @return The total borrows with interest
*/
function totalBorrowsCurrent() external nonReentrant returns (uint) {
require(accrueInterest() == uint(Error.NO_ERROR), "accrue interest failed");
return totalBorrows;
}
/**
* @notice Accrue interest to updated borrowIndex and then calculate account's borrow balance using the updated borrowIndex
* @param account The address whose balance should be calculated after updating borrowIndex
* @return The calculated balance
*/
function borrowBalanceCurrent(address account) external nonReentrant returns (uint) {
require(accrueInterest() == uint(Error.NO_ERROR), "accrue interest failed");
return borrowBalanceStored(account);
}
/**
* @notice Return the borrow balance of account based on stored data
* @param account The address whose balance should be calculated
* @return The calculated balance
*/
function borrowBalanceStored(address account) public view returns (uint) {
(MathError err, uint result) = borrowBalanceStoredInternal(account);
require(err == MathError.NO_ERROR, "borrowBalanceStored: borrowBalanceStoredInternal failed");
return result;
}
/**
* @notice Return the borrow balance of account based on stored data
* @param account The address whose balance should be calculated
* @return (error code, the calculated balance or 0 if error code is non-zero)
*/
function borrowBalanceStoredInternal(address account) internal view returns (MathError, uint) {
/* Note: we do not assert that the market is up to date */
MathError mathErr;
uint principalTimesIndex;
uint result;
/* Get borrowBalance and borrowIndex */
BorrowSnapshot storage borrowSnapshot = accountBorrows[account];
/* If borrowBalance = 0 then borrowIndex is likely also 0.
* Rather than failing the calculation with a division by 0, we immediately return 0 in this case.
*/
if (borrowSnapshot.principal == 0) {
return (MathError.NO_ERROR, 0);
}
/* Calculate new borrow balance using the interest index:
* recentBorrowBalance = borrower.borrowBalance * market.borrowIndex / borrower.borrowIndex
*/
(mathErr, principalTimesIndex) = mulUInt(borrowSnapshot.principal, borrowIndex);
if (mathErr != MathError.NO_ERROR) {
return (mathErr, 0);
}
(mathErr, result) = divUInt(principalTimesIndex, borrowSnapshot.interestIndex);
if (mathErr != MathError.NO_ERROR) {
return (mathErr, 0);
}
return (MathError.NO_ERROR, result);
}
/**
* @notice Accrue interest then return the up-to-date exchange rate
* @return Calculated exchange rate scaled by 1e18
*/
function exchangeRateCurrent() public nonReentrant returns (uint) {
require(accrueInterest() == uint(Error.NO_ERROR), "accrue interest failed");
return exchangeRateStored();
}
/**
* @notice Calculates the exchange rate from the underlying to the AToken
* @dev This function does not accrue interest before calculating the exchange rate
* @return Calculated exchange rate scaled by 1e18
*/
function exchangeRateStored() public view returns (uint) {
(MathError err, uint result) = exchangeRateStoredInternal();
require(err == MathError.NO_ERROR, "exchangeRateStored: exchangeRateStoredInternal failed");
return result;
}
/**
* @notice Calculates the exchange rate from the underlying to the AToken
* @dev This function does not accrue interest before calculating the exchange rate
* @return (error code, calculated exchange rate scaled by 1e18)
*/
function exchangeRateStoredInternal() internal view returns (MathError, uint) {
if (totalSupply == 0) {
/*
* If there are no tokens minted:
* exchangeRate = initialExchangeRate
*/
return (MathError.NO_ERROR, initialExchangeRateMantissa);
} else {
/*
* Otherwise:
* exchangeRate = (totalCash + totalBorrows - totalReserves) / totalSupply
*/
uint totalCash = getCashPrior();
uint cashPlusBorrowsMinusReserves;
Exp memory exchangeRate;
MathError mathErr;
(mathErr, cashPlusBorrowsMinusReserves) = addThenSubUInt(totalCash, totalBorrows, totalReserves);
if (mathErr != MathError.NO_ERROR) {
return (mathErr, 0);
}
(mathErr, exchangeRate) = getExp(cashPlusBorrowsMinusReserves, totalSupply);
if (mathErr != MathError.NO_ERROR) {
return (mathErr, 0);
}
return (MathError.NO_ERROR, exchangeRate.mantissa);
}
}
/**
* @notice Get cash balance of this aToken in the underlying asset
* @return The quantity of underlying asset owned by this contract
*/
function getCash() external view returns (uint) {
return getCashPrior();
}
struct AccrueInterestLocalVars {
MathError mathErr;
uint opaqueErr;
uint borrowRateMantissa;
uint currentBlockNumber;
uint blockDelta;
Exp simpleInterestFactor;
uint interestAccumulated;
uint totalBorrowsNew;
uint totalReservesNew;
uint borrowIndexNew;
}
/**
* @notice Applies accrued interest to total borrows and reserves.
* @dev This calculates interest accrued from the last checkpointed block
* up to the current block and writes new checkpoint to storage.
*/
function accrueInterest() public returns (uint) {
AccrueInterestLocalVars memory vars;
/* Calculate the current borrow interest rate */
(vars.opaqueErr, vars.borrowRateMantissa) = interestRateModel.getBorrowRate(getCashPrior(), totalBorrows, totalReserves);
require(vars.borrowRateMantissa <= borrowRateMaxMantissa, "borrow rate is absurdly high");
if (vars.opaqueErr != 0) {
return failOpaque(Error.INTEREST_RATE_MODEL_ERROR, FailureInfo.ACCRUE_INTEREST_BORROW_RATE_CALCULATION_FAILED, vars.opaqueErr);
}
/* Remember the initial block number */
vars.currentBlockNumber = getBlockNumber();
/* Calculate the number of blocks elapsed since the last accrual */
(vars.mathErr, vars.blockDelta) = subUInt(vars.currentBlockNumber, accrualBlockNumber);
assert(vars.mathErr == MathError.NO_ERROR); // Block delta should always succeed and if it doesn't, blow up.
/*
* Calculate the interest accumulated into borrows and reserves and the new index:
* simpleInterestFactor = borrowRate * blockDelta
* interestAccumulated = simpleInterestFactor * totalBorrows
* totalBorrowsNew = interestAccumulated + totalBorrows
* totalReservesNew = interestAccumulated * reserveFactor + totalReserves
* borrowIndexNew = simpleInterestFactor * borrowIndex + borrowIndex
*/
(vars.mathErr, vars.simpleInterestFactor) = mulScalar(Exp({mantissa: vars.borrowRateMantissa}), vars.blockDelta);
if (vars.mathErr != MathError.NO_ERROR) {
return failOpaque(Error.MATH_ERROR, FailureInfo.ACCRUE_INTEREST_SIMPLE_INTEREST_FACTOR_CALCULATION_FAILED, uint(vars.mathErr));
}
(vars.mathErr, vars.interestAccumulated) = mulScalarTruncate(vars.simpleInterestFactor, totalBorrows);
if (vars.mathErr != MathError.NO_ERROR) {
return failOpaque(Error.MATH_ERROR, FailureInfo.ACCRUE_INTEREST_ACCUMULATED_INTEREST_CALCULATION_FAILED, uint(vars.mathErr));
}
(vars.mathErr, vars.totalBorrowsNew) = addUInt(vars.interestAccumulated, totalBorrows);
if (vars.mathErr != MathError.NO_ERROR) {
return failOpaque(Error.MATH_ERROR, FailureInfo.ACCRUE_INTEREST_NEW_TOTAL_BORROWS_CALCULATION_FAILED, uint(vars.mathErr));
}
(vars.mathErr, vars.totalReservesNew) = mulScalarTruncateAddUInt(Exp({mantissa: reserveFactorMantissa}), vars.interestAccumulated, totalReserves);
if (vars.mathErr != MathError.NO_ERROR) {
return failOpaque(Error.MATH_ERROR, FailureInfo.ACCRUE_INTEREST_NEW_TOTAL_RESERVES_CALCULATION_FAILED, uint(vars.mathErr));
}
(vars.mathErr, vars.borrowIndexNew) = mulScalarTruncateAddUInt(vars.simpleInterestFactor, borrowIndex, borrowIndex);
if (vars.mathErr != MathError.NO_ERROR) {
return failOpaque(Error.MATH_ERROR, FailureInfo.ACCRUE_INTEREST_NEW_BORROW_INDEX_CALCULATION_FAILED, uint(vars.mathErr));
}
/////////////////////////
// EFFECTS & INTERACTIONS
// (No safe failures beyond this point)
/* We write the previously calculated values into storage */
accrualBlockNumber = vars.currentBlockNumber;
borrowIndex = vars.borrowIndexNew;
totalBorrows = vars.totalBorrowsNew;
totalReserves = vars.totalReservesNew;
/* We emit an AccrueInterest event */
emit AccrueInterest(vars.interestAccumulated, vars.borrowIndexNew, totalBorrows);
return uint(Error.NO_ERROR);
}
/**
* @notice Sender supplies assets into the market and receives aTokens in exchange
* @dev Accrues interest whether or not the operation succeeds, unless reverted
* @param mintAmount The amount of the underlying asset to supply
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
*/
function mintInternal(uint mintAmount) internal nonReentrant returns (uint) {
uint error = accrueInterest();
if (error != uint(Error.NO_ERROR)) {
// accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed
return fail(Error(error), FailureInfo.MINT_ACCRUE_INTEREST_FAILED);
}
// mintFresh emits the actual Mint event if successful and logs on errors, so we don't need to
return mintFresh(msg.sender, mintAmount);
}
struct MintLocalVars {
Error err;
MathError mathErr;
uint exchangeRateMantissa;
uint mintTokens;
uint totalSupplyNew;
uint accountTokensNew;
}
/**
* @notice User supplies assets into the market and receives aTokens in exchange
* @dev Assumes interest has already been accrued up to the current block
* @param minter The address of the account which is supplying the assets
* @param mintAmount The amount of the underlying asset to supply
* @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
*/
function mintFresh(address minter, uint mintAmount) internal returns (uint) {
/* Fail if mint not allowed */
uint allowed = controller.mintAllowed(address(this), minter, mintAmount);
if (allowed != 0) {
return failOpaque(Error.CONTROLLER_REJECTION, FailureInfo.MINT_CONTROLLER_REJECTION, allowed);
}
/* Verify market's block number equals current block number */
if (accrualBlockNumber != getBlockNumber()) {
return fail(Error.MARKET_NOT_FRESH, FailureInfo.MINT_FRESHNESS_CHECK);
}
MintLocalVars memory vars;
/* Fail if checkTransferIn fails */
vars.err = checkTransferIn(minter, mintAmount);
if (vars.err != Error.NO_ERROR) {
return fail(vars.err, FailureInfo.MINT_TRANSFER_IN_NOT_POSSIBLE);
}
/*
* We get the current exchange rate and calculate the number of aTokens to be minted:
* mintTokens = mintAmount / exchangeRate
*/
(vars.mathErr, vars.exchangeRateMantissa) = exchangeRateStoredInternal();
if (vars.mathErr != MathError.NO_ERROR) {
return failOpaque(Error.MATH_ERROR, FailureInfo.MINT_EXCHANGE_RATE_READ_FAILED, uint(vars.mathErr));
}
(vars.mathErr, vars.mintTokens) = divScalarByExpTruncate(mintAmount, Exp({mantissa: vars.exchangeRateMantissa}));
if (vars.mathErr != MathError.NO_ERROR) {
return failOpaque(Error.MATH_ERROR, FailureInfo.MINT_EXCHANGE_CALCULATION_FAILED, uint(vars.mathErr));
}
/*
* We calculate the new total supply of aTokens and minter token balance, checking for overflow:
* totalSupplyNew = totalSupply + mintTokens
* accountTokensNew = accountTokens[minter] + mintTokens
*/
(vars.mathErr, vars.totalSupplyNew) = addUInt(totalSupply, vars.mintTokens);
if (vars.mathErr != MathError.NO_ERROR) {
return failOpaque(Error.MATH_ERROR, FailureInfo.MINT_NEW_TOTAL_SUPPLY_CALCULATION_FAILED, uint(vars.mathErr));
}
...
// [truncated — 95836 bytes total]
Read Contract
accrualBlockNumber 0x6c540baf → uint256
admin 0xf851a440 → address
allowance 0xdd62ed3e → uint256
balanceOf 0x70a08231 → uint256
borrowBalanceStored 0x95dd9193 → uint256
borrowIndex 0xaa5af0fd → uint256
borrowRatePerBlock 0xf8f9da28 → uint256
controller 0xf77c4791 → address
decimals 0x313ce567 → uint256
exchangeRateStored 0x182df0f5 → uint256
getAccountSnapshot 0xc37f68e2 → uint256, uint256, uint256, uint256
getCash 0x3b1d21a2 → uint256
initialExchangeRateMantissa 0x675d972c → uint256
interestRateModel 0xf3fdb15a → address
isAToken 0x94c393fc → bool
name 0x06fdde03 → string
pendingAdmin 0x26782247 → address
reserveFactorMantissa 0x173b9904 → uint256
supplyRatePerBlock 0xae9d70b0 → uint256
symbol 0x95d89b41 → string
totalBorrows 0x47bd3718 → uint256
totalReserves 0x8f840ddd → uint256
totalSupply 0x18160ddd → uint256
Write Contract 23 functions
These functions modify contract state and require a wallet transaction to execute.
_acceptAdmin 0xe9c714f2
No parameters
returns: uint256
_reduceReserves 0x601a0bf1
uint256 reduceAmount
returns: uint256
_setController 0x83de424e
address newController
returns: uint256
_setInterestRateModel 0xf2b3abbd
address newInterestRateModel
returns: uint256
_setInterestRateModel_init 0x2d756359
address newInterestRateModel
returns: uint256
_setPendingAdmin 0xb71d1a0c
address newPendingAdmin
returns: uint256
_setReserveFactor 0xfca7820b
uint256 newReserveFactorMantissa
returns: uint256
accrueInterest 0xa6afed95
No parameters
returns: uint256
approve 0x095ea7b3
address spender
uint256 amount
returns: bool
balanceOfUnderlying 0x3af9e669
address owner
returns: uint256
borrow 0xc5ebeaec
uint256 borrowAmount
returns: uint256
borrowBalanceCurrent 0x17bfdfbc
address account
returns: uint256
exchangeRateCurrent 0xbd6d894d
No parameters
returns: uint256
liquidateBorrow 0xaae40a2a
address borrower
address aTokenCollateral
mint 0x1249c58b
No parameters
redeem 0xdb006a75
uint256 redeemTokens
returns: uint256
redeemUnderlying 0x852a12e3
uint256 redeemAmount
returns: uint256
repayBorrow 0x4e4d9fea
No parameters
repayBorrowBehalf 0xe5974619
address borrower
seize 0xb2a02ff1
address liquidator
address borrower
uint256 seizeTokens
returns: uint256
totalBorrowsCurrent 0x73acee98
No parameters
returns: uint256
transfer 0xa9059cbb
address dst
uint256 amount
returns: bool
transferFrom 0x23b872dd
address src
address dst
uint256 amount
returns: bool
Recent Transactions
This address has 1 on-chain transactions, but only 0.7% of the chain is indexed. Transactions will appear as indexing progresses. View on Etherscan →