Address Contract Partially Verified
Address
0xC02392336420bb54CE2Da8a8aa4B118F2dceeB04
Balance
0 ETH
Nonce
1
Code Size
10662 bytes
Creator
0xaF152394...66AE at tx 0x0dad339f...ed65af
Last Active
Indexed Transactions
9 (24,219,631 → 24,318,903)
Gas Used (indexed)
1,185,178
Contract Bytecode
10662 bytes
0x608060405234801561001057600080fd5b50600436106101cf5760003560e01c8063684b51d4116101045780639ffe7973116100a2578063d505accf11610071578063d505accf146103e1578063d8a0ac26146103f4578063dd62ed3e146103fd578063f8ba4cff1461043657600080fd5b80639ffe7973146103a8578063a457c2d7146103b1578063a9059cbb146103c4578063ba9a7a56146103d757600080fd5b80637c3a00fd116100de5780637c3a00fd146103715780637ecebe001461037a57806395d89b411461038d5780639dc29fac1461039557600080fd5b8063684b51d4146103185780636f307dc31461032157806370a082311461034857600080fd5b80633644e51511610171578063453b1a8b1161014b578063453b1a8b146102aa5780634b8a3529146102b3578063550ba367146102c65780635dd925851461030557600080fd5b80633644e5151461027c578063395093511461028457806340c10f191461029757600080fd5b80631ec82cb8116101ad5780631ec82cb81461022757806322867d781461023c57806323b872dd1461024f578063313ce5671461026257600080fd5b806306fdde03146101d4578063095ea7b3146101f257806318160ddd14610215575b600080fd5b6101dc61043e565b6040516101e991906127c6565b60405180910390f35b610205610200366004612618565b610536565b60405190151581526020016101e9565b6002545b6040519081526020016101e9565b61023a610235366004612566565b61054c565b005b61021961024a366004612618565b61068e565b61020561025d366004612566565b6109ba565b61026a610a66565b60405160ff90911681526020016101e9565b610219610b31565b610205610292366004612618565b610b40565b6102196102a5366004612618565b610b7c565b610219600a5481565b6102196102c1366004612618565b610e92565b6102ed7f000000000000000000000000972a785b390d05123497169a04c72de652493be181565b6040516001600160a01b0390911681526020016101e9565b610219610313366004612708565b610fd5565b610219600b5481565b6102ed7f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881565b6102196103563660046124f3565b6001600160a01b031660009081526020819052604090205490565b61021960075481565b6102196103883660046124f3565b61100b565b6101dc611029565b6102196103a3366004612618565b611106565b61021960085481565b6102056103bf366004612618565b611264565b6102056103d2366004612618565b6112fd565b610219620f424081565b61023a6103ef3660046125a7565b61130a565b61021960095481565b61021961040b36600461252d565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b61023a61146e565b60607f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b03166306fdde036040518163ffffffff1660e01b815260040160006040518083038186803b15801561049957600080fd5b505afa9250505080156104ce57506040513d6000823e601f3d908101601f191682016040526104cb9190810190612666565b60015b610510573d8080156104fc576040519150601f19603f3d011682016040523d82523d6000602084013e610501565b606091505b5061050a6118ff565b91505090565b80604051602001610521919061279c565b60405160208183030381529060405291505090565b6000610543338484611991565b50600192915050565b600260065414156105785760405162461bcd60e51b815260040161056f906127f9565b60405180910390fd5b6002600655336001600160a01b037f000000000000000000000000972a785b390d05123497169a04c72de652493be116146105ec5760405162461bcd60e51b81526020600482015260146024820152737265636f7665722f6e6f742d4265746142616e6b60601b604482015260640161056f565b600019811415610670576040516370a0823160e01b81523060048201526001600160a01b038416906370a082319060240160206040518083038186803b15801561063557600080fd5b505afa158015610649573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061066d9190612721565b90505b6106846001600160a01b0384168383611ab5565b5050600160065550565b6000600260065414156106b35760405162461bcd60e51b815260040161056f906127f9565b6002600655336001600160a01b037f000000000000000000000000972a785b390d05123497169a04c72de652493be116146107255760405162461bcd60e51b815260206004820152601260248201527172657061792f6e6f742d4265746142616e6b60701b604482015260640161056f565b61072d61146e565b6040516370a0823160e01b815230600482015260009081906001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4816906370a082319060240160206040518083038186803b15801561079157600080fd5b505afa1580156107a5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107c99190612721565b90506108006001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4816863087611b1d565b6040516370a0823160e01b81523060048201526000907f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b0316906370a082319060240160206040518083038186803b15801561086257600080fd5b505afa158015610876573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061089a9190612721565b90506108a6828261287b565b92505050600a548111156108f45760405162461bcd60e51b81526020600482015260156024820152740e4cae0c2f25ec2dadeeadce85ae8dede5ad0d2ced605b1b604482015260640161056f565b600a54600b54610904908361285c565b61090e9190612848565b915080600960008282546109229190612830565b9250508190555080600a600082825461093b919061287b565b9250508190555081600b6000828254610954919061287b565b9091555050600b54620f424011156109ae5760405162461bcd60e51b815260206004820152601c60248201527f72657061792f746f6f2d6c6f772d73756d2d646562742d736861726500000000604482015260640161056f565b50600160065592915050565b60006109c7848484611b5b565b6001600160a01b038416600090815260016020908152604080832033845290915290205482811015610a4c5760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b606482015260840161056f565b610a598533858403611991565b60019150505b9392505050565b60007f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b158015610ac157600080fd5b505afa925050508015610af1575060408051601f3d908101601f19168201909252610aee9181019061273a565b60015b610b2c573d808015610b1f576040519150601f19603f3d011682016040523d82523d6000602084013e610b24565b606091505b50601261050a565b919050565b6000610b3b611d29565b905090565b3360008181526001602090815260408083206001600160a01b03871684529091528120549091610543918590610b77908690612830565b611991565b600060026006541415610ba15760405162461bcd60e51b815260040161056f906127f9565b6002600655610bae61146e565b6040516370a0823160e01b815230600482015260009081906001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4816906370a082319060240160206040518083038186803b158015610c1257600080fd5b505afa158015610c26573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c4a9190612721565b9050610c816001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4816333087611b1d565b6040516370a0823160e01b81523060048201526000907f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b0316906370a082319060240160206040518083038186803b158015610ce357600080fd5b505afa158015610cf7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d1b9190612721565b9050610d27828261287b565b925050506000610d3660025490565b905080610daf57610d4a620f42408361287b565b92508260096000828254610d5e9190612830565b92505081905550620f4240600a6000828254610d7a9190612830565b92505081905550620f4240600b6000828254610d969190612830565b90915550610daa90506001620f4240611e1c565b610ded565b600a54600954610dbf9190612830565b610dc9828461285c565b610dd39190612848565b92508160096000828254610de79190612830565b90915550505b60008311610e355760405162461bcd60e51b81526020600482015260156024820152741b5a5b9d0bdb9bcb58dc99591a5d0b5b5a5b9d1959605a1b604482015260640161056f565b610e3f8584611e1c565b60408051858152602081018590526001600160a01b0387169133917f2f00e3cdd69a77be7ed215ec7b2a36784dd158f921fca79ac29deffa353fe6ee910160405180910390a35050600160065592915050565b600060026006541415610eb75760405162461bcd60e51b815260040161056f906127f9565b6002600655336001600160a01b037f000000000000000000000000972a785b390d05123497169a04c72de652493be11614610f2a5760405162461bcd60e51b8152602060048201526013602482015272626f72726f772f6e6f742d4265746142616e6b60681b604482015260640161056f565b610f3261146e565b610f666001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48168484611ab5565b610f7f600b5483610f77919061285c565b600a54611efb565b90508160096000828254610f93919061287b565b9250508190555081600a6000828254610fac9190612830565b9250508190555080600b6000828254610fc59190612830565b9091555050600160065592915050565b6000610fdf61146e565b81610fec57506000919050565b611005600a5483610ffd919061285c565b600b54611efb565b92915050565b6001600160a01b038116600090815260056020526040812054611005565b60607f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b03166395d89b416040518163ffffffff1660e01b815260040160006040518083038186803b15801561108457600080fd5b505afa9250505080156110b957506040513d6000823e601f3d908101601f191682016040526110b69190810190612666565b60015b6110f5573d8080156110e7576040519150601f19603f3d011682016040523d82523d6000602084013e6110ec565b606091505b5061050a611f2d565b806040516020016105219190612773565b60006002600654141561112b5760405162461bcd60e51b815260040161056f906127f9565b600260065561113861146e565b600061114360025490565b905080600a546009546111569190612830565b611160908561285c565b61116a9190612848565b9150600082116111bc5760405162461bcd60e51b815260206004820152601760248201527f6275726e2f6e6f2d616d6f756e742d72657475726e6564000000000000000000604482015260640161056f565b81600960008282546111ce919061287b565b909155506111de90503384611f3c565b6112126001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48168584611ab5565b60408051838152602081018590526001600160a01b0386169133917f5d624aa9c148153ab3446c1b154f660ee7701e549fe9b62dab7171b1c80e6fa2910160405180910390a350600160065592915050565b3360009081526001602090815260408083206001600160a01b0386168452909152812054828110156112e65760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b606482015260840161056f565b6112f33385858403611991565b5060019392505050565b6000610543338484611b5b565b8342111561135a5760405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e65000000604482015260640161056f565b60007f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98888886113898c61208a565b6040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e00160405160208183030381529060405280519060200120905060006113e4826120b2565b905060006113f482878787612100565b9050896001600160a01b0316816001600160a01b0316146114575760405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e61747572650000604482015260640161056f565b6114628a8a8a611991565b50505050505050505050565b60006008544261147e919061287b565b9050806114885750565b426008819055507f000000000000000000000000972a785b390d05123497169a04c72de652493be16001600160a01b0316635c975abb6040518163ffffffff1660e01b815260040160206040518083038186803b1580156114e857600080fd5b505afa1580156114fc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115209190612644565b1561155f5760405162461bcd60e51b815260206004820152600f60248201526e10995d1850985b9acbdc185d5cd959608a1b604482015260640161056f565b600a54600954600754604080516379502c5560e01b815290516000916001600160a01b037f000000000000000000000000972a785b390d05123497169a04c72de652493be116916379502c5591600480820192602092909190829003018186803b1580156115cc57600080fd5b505afa1580156115e0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116049190612510565b905060007f000000000000000000000000972a785b390d05123497169a04c72de652493be16001600160a01b031663ac165d7a6040518163ffffffff1660e01b815260040160206040518083038186803b15801561166157600080fd5b505afa158015611675573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116999190612510565b90506000670de0b6b3a76400006301e13380886116b6898861285c565b6116c0919061285c565b6116ca9190612848565b6116d49190612848565b90506116e08187612830565b600a81905560405163fae7f00d60e01b8152600481018690526024810187905260448101829052606481018990529096506001600160a01b0383169063fae7f00d9060840160206040518083038186803b15801561173d57600080fd5b505afa158015611751573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117759190612721565b60075580156118f6576000836001600160a01b03166358d7bf806040518163ffffffff1660e01b815260040160206040518083038186803b1580156117b957600080fd5b505afa1580156117cd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117f19190612721565b905080156118c1576000670de0b6b3a764000061180e838561285c565b6118189190612848565b90506118bf856001600160a01b031663914870eb6040518163ffffffff1660e01b815260040160206040518083038186803b15801561185657600080fd5b505afa15801561186a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061188e9190612510565b826118998a8c612830565b6118a3919061287b565b6002546118b0908561285c565b6118ba9190612848565b611e1c565b505b6040518281527f184f65042d0acee3fe9a2216428397968211b66a6f53244a44eb13ae62bc72359060200160405180910390a1505b50505050505050565b60606003805461190e906128be565b80601f016020809104026020016040519081016040528092919081815260200182805461193a906128be565b80156119875780601f1061195c57610100808354040283529160200191611987565b820191906000526020600020905b81548152906001019060200180831161196a57829003601f168201915b5050505050905090565b6001600160a01b0383166119f35760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b606482015260840161056f565b6001600160a01b038216611a545760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b606482015260840161056f565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6040516001600160a01b038316602482015260448101829052611b1890849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526122a9565b505050565b6040516001600160a01b0380851660248301528316604482015260648101829052611b559085906323b872dd60e01b90608401611ae1565b50505050565b6001600160a01b038316611bbf5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b606482015260840161056f565b6001600160a01b038216611c215760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b606482015260840161056f565b6001600160a01b03831660009081526020819052604090205481811015611c995760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b606482015260840161056f565b6001600160a01b03808516600090815260208190526040808220858503905591851681529081208054849290611cd0908490612830565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051611d1c91815260200190565b60405180910390a3611b55565b60007f0000000000000000000000000000000000000000000000000000000000000001461415611d7857507f575d60bb2d45c4fbccbe3717f80cf1d464eaf51870d72b7a4645faab526396c290565b50604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f6020808301919091527ff298fc33cba3cfdbf2454e2f19b4a97c9207157f8eeee7439da2c9ce4b540bbb828401527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608301524660808301523060a0808401919091528351808403909101815260c0909201909252805191012090565b6001600160a01b038216611e725760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015260640161056f565b8060026000828254611e849190612830565b90915550506001600160a01b03821660009081526020819052604081208054839290611eb1908490612830565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b6000611f0782846128f3565b15611f13576001611f16565b60005b60ff16611f238385612848565b610a5f9190612830565b60606004805461190e906128be565b6001600160a01b038216611f9c5760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b606482015260840161056f565b6001600160a01b038216600090815260208190526040902054818110156120105760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b606482015260840161056f565b6001600160a01b038316600090815260208190526040812083830390556002805484929061203f90849061287b565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3505050565b6001600160a01b03811660009081526005602052604090208054600181018255905b50919050565b60006110056120bf611d29565b8360405161190160f01b6020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b60007f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a082111561217d5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b606482015260840161056f565b8360ff16601b148061219257508360ff16601c145b6121e95760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c604482015261756560f01b606482015260840161056f565b6040805160008082526020820180845288905260ff871692820192909252606081018590526080810184905260019060a0016020604051602081039080840390855afa15801561223d573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166122a05760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e61747572650000000000000000604482015260640161056f565b95945050505050565b60006122fe826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661237b9092919063ffffffff16565b805190915015611b18578080602001905181019061231c9190612644565b611b185760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161056f565b606061238a8484600085612392565b949350505050565b6060824710156123f35760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161056f565b843b6124415760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161056f565b600080866001600160a01b0316858760405161245d9190612757565b60006040518083038185875af1925050503d806000811461249a576040519150601f19603f3d011682016040523d82523d6000602084013e61249f565b606091505b50915091506124af8282866124ba565b979650505050505050565b606083156124c9575081610a5f565b8251156124d95782518084602001fd5b8160405162461bcd60e51b815260040161056f91906127c6565b60006020828403121561250557600080fd5b8135610a5f81612949565b60006020828403121561252257600080fd5b8151610a5f81612949565b6000806040838503121561254057600080fd5b823561254b81612949565b9150602083013561255b81612949565b809150509250929050565b60008060006060848603121561257b57600080fd5b833561258681612949565b9250602084013561259681612949565b929592945050506040919091013590565b600080600080600080600060e0888a0312156125c257600080fd5b87356125cd81612949565b965060208801356125dd81612949565b9550604088013594506060880135935060808801356125fb81612961565b9699959850939692959460a0840135945060c09093013592915050565b6000806040838503121561262b57600080fd5b823561263681612949565b946020939093013593505050565b60006020828403121561265657600080fd5b81518015158114610a5f57600080fd5b60006020828403121561267857600080fd5b815167ffffffffffffffff8082111561269057600080fd5b818401915084601f8301126126a457600080fd5b8151818111156126b6576126b6612933565b604051601f8201601f19908116603f011681019083821181831017156126de576126de612933565b816040528281528760208487010111156126f757600080fd5b6124af836020830160208801612892565b60006020828403121561271a57600080fd5b5035919050565b60006020828403121561273357600080fd5b5051919050565b60006020828403121561274c57600080fd5b8151610a5f81612961565b60008251612769818460208701612892565b9190910192915050565b603160f91b81526000825161278f816001850160208701612892565b9190910160010192915050565b61021160f51b8152600082516127b9816002850160208701612892565b9190910160020192915050565b60208152600082518060208401526127e5816040850160208701612892565b601f01601f19169190910160400192915050565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6000821982111561284357612843612907565b500190565b6000826128575761285761291d565b500490565b600081600019048311821515161561287657612876612907565b500290565b60008282101561288d5761288d612907565b500390565b60005b838110156128ad578181015183820152602001612895565b83811115611b555750506000910152565b600181811c908216806128d257607f821691505b602082108114156120ac57634e487b7160e01b600052602260045260246000fd5b6000826129025761290261291d565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461295e57600080fd5b50565b60ff8116811461295e57600080fdfea264697066735822122055383071d6786d3f31f38890e7dc3c03e9e58d3333aad272946e13e25f93318f64736f6c63430008060033
Verified Source Code Partial Match
Compiler: v0.8.6+commit.11564f7e
EVM: berlin
Optimization: Yes (200 runs)
BToken.sol 1710 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.6;
// Part: IBetaBank
interface IBetaBank {
/// @dev Returns the address of BToken of the given underlying token, or 0 if not exists.
function bTokens(address _underlying) external view returns (address);
/// @dev Returns the address of the underlying of the given BToken, or 0 if not exists.
function underlyings(address _bToken) external view returns (address);
/// @dev Returns the address of the oracle contract.
function oracle() external view returns (address);
/// @dev Returns the address of the config contract.
function config() external view returns (address);
/// @dev Returns the interest rate model smart contract.
function interestModel() external view returns (address);
/// @dev Returns the position's collateral token and AmToken.
function getPositionTokens(address _owner, uint _pid)
external
view
returns (address _collateral, address _bToken);
/// @dev Returns the debt of the given position. Can't be view as it needs to call accrue.
function fetchPositionDebt(address _owner, uint _pid) external returns (uint);
/// @dev Returns the LTV of the given position. Can't be view as it needs to call accrue.
function fetchPositionLTV(address _owner, uint _pid) external returns (uint);
/// @dev Opens a new position in the Beta smart contract.
function open(
address _owner,
address _underlying,
address _collateral
) external returns (uint pid);
/// @dev Borrows tokens on the given position.
function borrow(
address _owner,
uint _pid,
uint _amount
) external;
/// @dev Repays tokens on the given position.
function repay(
address _owner,
uint _pid,
uint _amount
) external;
/// @dev Puts more collateral to the given position.
function put(
address _owner,
uint _pid,
uint _amount
) external;
/// @dev Takes some collateral out of the position.
function take(
address _owner,
uint _pid,
uint _amount
) external;
/// @dev Liquidates the given position.
function liquidate(
address _owner,
uint _pid,
uint _amount
) external;
}
// Part: IBetaConfig
interface IBetaConfig {
/// @dev Returns the risk level for the given asset.
function getRiskLevel(address token) external view returns (uint);
/// @dev Returns the rate of interest collected to be distributed to the protocol reserve.
function reserveRate() external view returns (uint);
/// @dev Returns the beneficiary to receive a portion interest rate for the protocol.
function reserveBeneficiary() external view returns (address);
/// @dev Returns the ratio of which the given token consider for collateral value.
function getCollFactor(address token) external view returns (uint);
/// @dev Returns the max amount of collateral to accept globally.
function getCollMaxAmount(address token) external view returns (uint);
/// @dev Returns max ltv of collateral / debt to allow a new position.
function getSafetyLTV(address token) external view returns (uint);
/// @dev Returns max ltv of collateral / debt to liquidate a position of the given token.
function getLiquidationLTV(address token) external view returns (uint);
/// @dev Returns the bonus incentive reward factor for liquidators.
function getKillBountyRate(address token) external view returns (uint);
}
// Part: IBetaInterestModel
interface IBetaInterestModel {
/// @dev Returns the initial interest rate per year (times 1e18).
function initialRate() external view returns (uint);
/// @dev Returns the next interest rate for the market.
/// @param prevRate The current interest rate.
/// @param totalAvailable The current available liquidity.
/// @param totalLoan The current outstanding loan.
/// @param timePast The time past since last interest rate rebase in seconds.
function getNextInterestRate(
uint prevRate,
uint totalAvailable,
uint totalLoan,
uint timePast
) external view returns (uint);
}
// Part: OpenZeppelin/[email protected]/Address
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) private pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
// Part: OpenZeppelin/[email protected]/Context
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
// Part: OpenZeppelin/[email protected]/Counters
/**
* @title Counters
* @author Matt Condon (@shrugs)
* @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
* of elements in a mapping, issuing ERC721 ids, or counting request ids.
*
* Include with `using Counters for Counters.Counter;`
*/
library Counters {
struct Counter {
// This variable should never be directly accessed by users of the library: interactions must be restricted to
// the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
// this feature: see https://github.com/ethereum/solidity/issues/4637
uint256 _value; // default: 0
}
function current(Counter storage counter) internal view returns (uint256) {
return counter._value;
}
function increment(Counter storage counter) internal {
unchecked {
counter._value += 1;
}
}
function decrement(Counter storage counter) internal {
uint256 value = counter._value;
require(value > 0, "Counter: decrement overflow");
unchecked {
counter._value = value - 1;
}
}
function reset(Counter storage counter) internal {
counter._value = 0;
}
}
// Part: OpenZeppelin/[email protected]/ECDSA
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
// Check the signature length
// - case 65: r,s,v signature (standard)
// - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return recover(hash, v, r, s);
} else if (signature.length == 64) {
bytes32 r;
bytes32 vs;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly {
r := mload(add(signature, 0x20))
vs := mload(add(signature, 0x40))
}
return recover(hash, r, vs);
} else {
revert("ECDSA: invalid signature length");
}
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.2._
*/
function recover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address) {
bytes32 s;
uint8 v;
assembly {
s := and(vs, 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
v := add(shr(255, vs), 27)
}
return recover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`, `r` and `s` signature fields separately.
*/
function recover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
require(
uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0,
"ECDSA: invalid signature 's' value"
);
require(v == 27 || v == 28, "ECDSA: invalid signature 'v' value");
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
require(signer != address(0), "ECDSA: invalid signature");
return signer;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
}
}
// Part: OpenZeppelin/[email protected]/IERC20
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// Part: OpenZeppelin/[email protected]/IERC20Permit
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` 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:
*
* - `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 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current 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);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
// Part: OpenZeppelin/[email protected]/Math
/**
* @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);
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a / b + (a % b == 0 ? 0 : 1);
}
}
// Part: OpenZeppelin/[email protected]/ReentrancyGuard
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and make it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
// Part: OpenZeppelin/[email protected]/EIP712
/**
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
*
* The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
* thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
* they need in their contracts using a combination of `abi.encode` and `keccak256`.
*
* This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
* scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
* ({_hashTypedDataV4}).
*
* The implementation of the domain separator was designed to be as efficient as possible while still properly updating
* the chain id to protect against replay attacks on an eventual fork of the chain.
*
* NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
* https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
*
* _Available since v3.4._
*/
abstract contract EIP712 {
/* solhint-disable var-name-mixedcase */
// Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
// invalidate the cached domain separator if the chain id changes.
bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
uint256 private immutable _CACHED_CHAIN_ID;
bytes32 private immutable _HASHED_NAME;
bytes32 private immutable _HASHED_VERSION;
bytes32 private immutable _TYPE_HASH;
/* solhint-enable var-name-mixedcase */
/**
* @dev Initializes the domain separator and parameter caches.
*
* The meaning of `name` and `version` is specified in
* https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
*
* - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
* - `version`: the current major version of the signing domain.
*
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
constructor(string memory name, string memory version) {
bytes32 hashedName = keccak256(bytes(name));
bytes32 hashedVersion = keccak256(bytes(version));
bytes32 typeHash = keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
);
_HASHED_NAME = hashedName;
_HASHED_VERSION = hashedVersion;
_CACHED_CHAIN_ID = block.chainid;
_CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion);
_TYPE_HASH = typeHash;
}
/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view returns (bytes32) {
if (block.chainid == _CACHED_CHAIN_ID) {
return _CACHED_DOMAIN_SEPARATOR;
} else {
return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION);
}
}
function _buildDomainSeparator(
bytes32 typeHash,
bytes32 nameHash,
bytes32 versionHash
) private view returns (bytes32) {
return keccak256(abi.encode(typeHash, nameHash, versionHash, block.chainid, address(this)));
}
/**
* @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
* function returns the hash of the fully encoded EIP712 message for this domain.
*
* This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
*
* ```solidity
* bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
* keccak256("Mail(address to,string contents)"),
* mailTo,
* keccak256(bytes(mailContents))
* )));
* address signer = ECDSA.recover(digest, signature);
* ```
*/
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash);
}
}
// Part: OpenZeppelin/[email protected]/IERC20Metadata
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
// Part: OpenZeppelin/[email protected]/Pausable
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
constructor() {
_paused = false;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
require(!paused(), "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
require(paused(), "Pausable: not paused");
_;
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
// Part: OpenZeppelin/[email protected]/SafeERC20
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
// Part: OpenZeppelin/[email protected]/ERC20
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* The default value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* overridden;
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `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);
uint256 currentAllowance = _allowances[sender][_msgSender()];
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
unchecked {
_approve(sender, _msgSender(), currentAllowance - amount);
}
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
uint256 currentAllowance = _allowances[_msgSender()][spender];
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(_msgSender(), spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `sender` to `recipient`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `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);
uint256 senderBalance = _balances[sender];
require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[sender] = senderBalance - amount;
}
_balances[recipient] += amount;
emit Transfer(sender, recipient, amount);
_afterTokenTransfer(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:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
}
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]...
// [truncated — 61868 bytes total]
Read Contract
DOMAIN_SEPARATOR 0x3644e515 → bytes32
MINIMUM_LIQUIDITY 0xba9a7a56 → uint256
allowance 0xdd62ed3e → uint256
balanceOf 0x70a08231 → uint256
betaBank 0x550ba367 → address
decimals 0x313ce567 → uint8
interestRate 0x7c3a00fd → uint256
lastAccrueTime 0x9ffe7973 → uint256
name 0x06fdde03 → string
nonces 0x7ecebe00 → uint256
symbol 0x95d89b41 → string
totalDebtShare 0x684b51d4 → uint256
totalLoan 0x453b1a8b → uint256
totalLoanable 0xd8a0ac26 → uint256
totalSupply 0x18160ddd → uint256
underlying 0x6f307dc3 → address
Write Contract 13 functions
These functions modify contract state and require a wallet transaction to execute.
accrue 0xf8ba4cff
No parameters
approve 0x095ea7b3
address spender
uint256 amount
returns: bool
borrow 0x4b8a3529
address _to
uint256 _amount
returns: uint256
burn 0x9dc29fac
address _to
uint256 _credit
returns: uint256
decreaseAllowance 0xa457c2d7
address spender
uint256 subtractedValue
returns: bool
fetchDebtShareValue 0x5dd92585
uint256 _debtShare
returns: uint256
increaseAllowance 0x39509351
address spender
uint256 addedValue
returns: bool
mint 0x40c10f19
address _to
uint256 _amount
returns: uint256
permit 0xd505accf
address owner
address spender
uint256 value
uint256 deadline
uint8 v
bytes32 r
bytes32 s
recover 0x1ec82cb8
address _token
address _to
uint256 _amount
repay 0x22867d78
address _from
uint256 _amount
returns: uint256
transfer 0xa9059cbb
address recipient
uint256 amount
returns: bool
transferFrom 0x23b872dd
address sender
address recipient
uint256 amount
returns: bool
Top Interactions
| Address | Txns | Sent | Received |
|---|---|---|---|
| 0x2F6EDAba...A6b4 | 1 | 1 | |
| 0xd4e15758...9777 | 1 | 1 | |
| 0xc418f4DE...1BaC | 1 | 1 | |
| 0xBDB441D1...Df6a | 1 | 1 | |
| 0x2DB22897...dCD6 | 1 | 1 | |
| 0xFC91f727...E7d0 | 1 | 1 | |
| 0x2e62b8AF...a48c | 1 | 1 | |
| 0xb898C2b1...8167 | 1 | 1 |
Token Balances (1)
View Transfers →Recent Transactions
|
| Hash | Block | Age | From/To | Value | |
|---|---|---|---|---|---|
| 0xd06b3634...8cec57 | 24,318,903 | IN | 0xb898C2b1...8167 | 0 ETH | |
| 0x1ffb9024...403f4c | 24,318,840 | IN | 0x4a048FaF...0BBe | 0 ETH | |
| 0xa6715053...ea217b | 24,312,203 | IN | 0x2DB22897...dCD6 | 0 ETH | |
| 0xc699682e...5ae0e6 | 24,312,193 | IN | 0x2F6EDAba...A6b4 | 0 ETH | |
| 0xbbb16476...cd2236 | 24,311,736 | IN | 0xBDB441D1...Df6a | 0 ETH | |
| 0xdc2b6ceb...8826ff | 24,311,722 | IN | 0x2e62b8AF...a48c | 0 ETH | |
| 0xe7dddc84...88aef0 | 24,311,703 | IN | 0xc418f4DE...1BaC | 0 ETH | |
| 0x40ce0d7e...7b3fda | 24,311,665 | IN | 0xd4e15758...9777 | 0 ETH | |
| 0x22b23975...83849a | 24,219,631 | IN | 0xFC91f727...E7d0 | 0 ETH |