Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x04716DB62C085D9e08050fcF6F7D775A03d07720
Balance 0 ETH
Nonce 1
Code Size 11615 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

11615 bytes
0x608060405234801561001057600080fd5b50600436106103a45760003560e01c80636eb2dc53116101e9578063a0b4dbb11161010f578063b4add307116100ad578063e2bbb1581161007c578063e2bbb1581461080d578063f1a2c98714610820578063f6be71d114610829578063fe4656a41461083c57600080fd5b8063b4add307146107cc578063bcf18bfd146107d4578063d45f2af0146107e7578063d547741f146107fa57600080fd5b8063a7379086116100e9578063a73790861461078b578063a83019fa1461079e578063ad4c4305146107a6578063b255f4e2146107b957600080fd5b8063a0b4dbb114610768578063a217fddf1461077b578063a63e8c4b1461078357600080fd5b80637d1cce2c1161018757806391a0ac6a1161015657806391a0ac6a1461070157806391d148541461070957806396cbc3c61461071c578063976fc43a1461072457600080fd5b80637d1cce2c1461069857806386eeec5d146106ab5780638a7fe60f146106be5780638d86c1a0146106ee57600080fd5b80637b3ba717116101c35780637b3ba7171461064d5780637caa75a5146106555780637cbc23731461065e5780637cd570b61461067157600080fd5b80636eb2dc53146105f75780636f307dc31461061e57806371a973051461064557600080fd5b806339908710116102ce57806350960e131161026c5780635e516c4c1161023b5780635e516c4c146105b35780635ff12547146105bc578063660cf34e146105c45780636ad62098146105d757600080fd5b806350960e13146105865780635865677b1461058f57806358c0a3641461059757806358cc3366146105a057600080fd5b8063401b1a74116102a8578063401b1a7414610550578063441a3e70146105585780634cc797251461056b5780634f66577c1461057e57600080fd5b806339908710146105155780633b62142b146105285780633cf1dee21461053057600080fd5b80631e655e9c116103465780632f2ff15d116103155780632f2ff15d146104c95780633553523e146104dc57806336568abe146104ef578063375190bf1461050257600080fd5b80631e655e9c1461045f57806321960fbf14610472578063248a9ca31461049357806325914e59146104b657600080fd5b80630fb5a6b4116103825780630fb5a6b41461042557806310690a501461043c578063172cfa4c146104445780631b2df8501461045757600080fd5b806301ffc9a7146103a957806304bda262146103d15780630cb5dec014610410575b600080fd5b6103bc6103b73660046128c8565b61084f565b60405190151581526020015b60405180910390f35b6103f87f0000000000000000000000004809010926aec940b550d34a46a52739f996d75d81565b6040516001600160a01b0390911681526020016103c8565b61042361041e36600461290e565b610886565b005b61042e60015481565b6040519081526020016103c8565b61042e610990565b610423610452366004612929565b6109a2565b61042e610b8e565b61042e61046d36600461294b565b610bb6565b61048561048036600461294b565b610bc1565b6040516103c89291906129b4565b61042e6104a136600461294b565b60009081526020819052604090206001015490565b6104236104c436600461294b565b610bd7565b6104236104d73660046129cf565b610c0b565b6104236104ea366004612929565b610c35565b6104236104fd3660046129cf565b610c76565b61042e61051036600461294b565b610cf4565b61042361052336600461294b565b610d08565b61042e610d3c565b61042e61053e36600461294b565b60076020526000908152604090205481565b61042e610d49565b610423610566366004612929565b610d53565b6103f861057936600461294b565b610f28565b61042e610f52565b61042e60055481565b610485610f5f565b61042e60045481565b6104236105ae36600461294b565b610f73565b61042e60035481565b61042e610fa7565b61042e6105d236600461294b565b610fb3565b6105ea6105e5366004612929565b610fc0565b6040516103c891906129fb565b6103f87f000000000000000000000000128d86a9e854a709df06b884f81eee7240f6ccf781565b6103f87f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881565b61042e610fd3565b61042e610fdd565b61042e60065481565b61042361066c366004612929565b610fec565b6103f87f0000000000000000000000005475611dffb8ef4d697ae39df9395513b6e947d781565b6104236106a636600461294b565b6110fa565b61042e6106b9366004612a48565b61112e565b6106d16106cc36600461290e565b611144565b6040805182511515815260209283015192810192909252016103c8565b6104856106fc366004612929565b61119c565b61042e6111b6565b6103bc6107173660046129cf565b6111c0565b61042e6111e9565b61075161073236600461290e565b6009602052600090815260409020805460019091015460ff9091169082565b6040805192151583526020830191909152016103c8565b61042e61077636600461294b565b6111f4565b61042e600081565b61042e611201565b61042e610799366004612a7b565b61120d565b61042e61121a565b6104236107b436600461290e565b611227565b61042e6107c7366004612a7b565b6113e2565b61042e6113ef565b6104856107e236600461294b565b6113f9565b6104236107f536600461294b565b611406565b6104236108083660046129cf565b61143a565b61042361081b366004612929565b61145f565b61042e60025481565b61042361083736600461294b565b61150a565b61042e61084a366004612929565b61153e565b60006001600160e01b03198216637965db0b60e01b148061088057506301ffc9a760e01b6001600160e01b03198316145b92915050565b60405160200161089590612aa5565b604051602081830303815290604052805190602001206108b48161154c565b6001600160a01b0382166000908152600960205260409020805460ff16156109235760405162461bcd60e51b815260206004820152601760248201527f43453a206164617074657220616c72656164792073657400000000000000000060448201526064015b60405180910390fd5b600880546001808201835560008390527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee390910180546001600160a01b0319166001600160a01b038716179055825460ff19168117835590546109869190612af2565b6001909101555050565b600061099d600154611559565b905090565b6040516020016109b190612b05565b604051602081830303815290604052805190602001206109d08161154c565b826109da60085490565b116109f75760405162461bcd60e51b815260040161091a90612b3c565b600060088481548110610a0c57610a0c612b81565b600091825260209091200154604051632e1a7d4d60e01b8152600481018590526001600160a01b0391821692507f0000000000000000000000004809010926aec940b550d34a46a52739f996d75d90911690632e1a7d4d90602401600060405180830381600087803b158015610a8157600080fd5b505af1158015610a95573d6000803e3d6000fd5b505060405163095ea7b360e01b81526001600160a01b038481166004830152602482018790527f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4816925063095ea7b391506044016020604051808303816000875af1158015610b08573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b2c9190612b97565b506040516390ca796b60e01b8152600481018490526001600160a01b038216906390ca796b906024015b600060405180830381600087803b158015610b7057600080fd5b505af1158015610b84573d6000803e3d6000fd5b5050505050505050565b604051602001610b9d90612b05565b6040516020818303038152906040528051906020012081565b60006108808261167e565b60006060610bce836118e0565b91509150915091565b604051602001610be690612b05565b60405160208183030381529060405280519060200120610c058161154c565b50600355565b600082815260208190526040902060010154610c268161154c565b610c3083836119d0565b505050565b604051602001610c4490612b05565b60405160208183030381529060405280519060200120610c638161154c565b5060009182526007602052604090912055565b6001600160a01b0381163314610ce65760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b606482015260840161091a565b610cf08282611a54565b5050565b600081815260076020526040812054610880565b604051602001610d1790612b05565b60405160208183030381529060405280519060200120610d368161154c565b50600455565b600061099d600154611ab9565b600061099d611c64565b604051602001610d6290612b05565b60405160208183030381529060405280519060200120610d818161154c565b82610d8b60085490565b11610da85760405162461bcd60e51b815260040161091a90612b3c565b600060088481548110610dbd57610dbd612b81565b600091825260209091200154604051632e1a7d4d60e01b8152600481018590526001600160a01b0390911691508190632e1a7d4d90602401600060405180830381600087803b158015610e0f57600080fd5b505af1158015610e23573d6000803e3d6000fd5b505060405163095ea7b360e01b81526001600160a01b037f0000000000000000000000004809010926aec940b550d34a46a52739f996d75d81166004830152602482018790527f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4816925063095ea7b391506044016020604051808303816000875af1158015610eb6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eda9190612b97565b506040516390ca796b60e01b8152600481018490527f0000000000000000000000004809010926aec940b550d34a46a52739f996d75d6001600160a01b0316906390ca796b90602401610b56565b60088181548110610f3857600080fd5b6000918252602090912001546001600160a01b0316905081565b600061099d600154611da3565b60006060610f6b611dc2565b915091509091565b604051602001610f8290612b05565b60405160208183030381529060405280519060200120610fa18161154c565b50600255565b600061099d6000611ec7565b6000610880333384611f1d565b6060610fcc8383612012565b9392505050565b600061099d6120d9565b604051602001610b9d90612aa5565b604051602001610ffb90612b05565b6040516020818303038152906040528051906020012061101a8161154c565b8261102460085490565b116110415760405162461bcd60e51b815260040161091a90612b3c565b6000606060006008868154811061105a5761105a612b81565b60009182526020909120015460405163db006a7560e01b8152600481018790526001600160a01b039091169150819063db006a75906024015b600060405180830381600087803b1580156110ad57600080fd5b505af11580156110c1573d6000803e3d6000fd5b505050506110cd611dc2565b909350915081836110f15760405162461bcd60e51b815260040161091a9190612bb9565b50505050505050565b60405160200161110990612b05565b604051602081830303815290604052805190602001206111288161154c565b50600555565b600061113c338585856121e3565b949350505050565b604080518082018252600080825260208083018290528351808501855282815281018290526001600160a01b038516825260098152908390208351808501909452805460ff1615158452600101549083015290610880565b600060606111aa84846122f8565b915091505b9250929050565b600061099d6123e2565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b600061099d60085490565b600061088033338461241a565b600061099d60006124aa565b6000610fcc33848461241a565b600061099d6001546124c1565b60405160200161123690612aa5565b604051602081830303815290604052805190602001206112558161154c565b6001600160a01b0382166000908152600960205260409020805460ff166112b45760405162461bcd60e51b815260206004820152601360248201527210d14e881859185c1d195c881b9bdd081cd95d606a1b604482015260640161091a565b600060016112c160085490565b6112cb9190612af2565b90506000600882815481106112e2576112e2612b81565b6000918252602090912001546001840154600880546001600160a01b03909316935090918490811061131657611316612b81565b600091825260209091200154600880546001600160a01b03909216918390811061134257611342612b81565b600091825260208083209190910180546001600160a01b0319166001600160a01b039485161790559184168152600990915260409020600101819055600880548061138f5761138f612bcc565b60008281526020808220830160001990810180546001600160a01b03191690559092019092556001600160a01b039790971681526009909652505060408420805460ff1916815560010193909355505050565b6000610fcc338484611f1d565b600061099d6124da565b60006060610bce836125ea565b60405160200161141590612b05565b604051602081830303815290604052805190602001206114348161154c565b50600655565b6000828152602081905260409020600101546114558161154c565b610c308383611a54565b60405160200161146e90612b05565b6040516020818303038152906040528051906020012061148d8161154c565b8261149760085490565b116114b45760405162461bcd60e51b815260040161091a90612b3c565b600060606000600886815481106114cd576114cd612b81565b60009182526020909120015460405163b6b55f2560e01b8152600481018790526001600160a01b039091169150819063b6b55f2590602401611093565b60405160200161151990612b05565b604051602081830303815290604052805190602001206115388161154c565b50600155565b6000610fcc333385856121e3565b61155681336126c1565b50565b600854600090815b818110156116775760006008828154811061157e5761157e612b81565b60009182526020918290200154604080516303ed69ad60e21b815290516001600160a01b0390921693508392630fb5a6b4926004808401938290030181865afa1580156115cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115f39190612be2565b85106115ff575061166f565b806001600160a01b031663d4c3eea06040518163ffffffff1660e01b8152600401602060405180830381865afa15801561163d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116619190612be2565b61166b9085612bfb565b9350505b600101611561565b5050919050565b6000807f000000000000000000000000128d86a9e854a709df06b884f81eee7240f6ccf76001600160a01b0316631e863b0a6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156116df573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117039190612be2565b905060007f000000000000000000000000128d86a9e854a709df06b884f81eee7240f6ccf76001600160a01b031663382d6d2c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611765573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117899190612be2565b90506000815b8381116118d7576117a08642612bfb565b60405163842cfa8d60e01b8152600481018390527f000000000000000000000000128d86a9e854a709df06b884f81eee7240f6ccf76001600160a01b03169063842cfa8d90602401602060405180830381865afa158015611805573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118299190612be2565b11156118c55760405163bd85b03960e01b8152600481018290527f000000000000000000000000128d86a9e854a709df06b884f81eee7240f6ccf76001600160a01b03169063bd85b03990602401602060405180830381865afa158015611894573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118b89190612be2565b6118c29083612bfb565b91505b806118cf81612c0e565b91505061178f565b50949350505050565b600060606005547f0000000000000000000000005475611dffb8ef4d697ae39df9395513b6e947d76001600160a01b031663fc7b9c186040518163ffffffff1660e01b8152600401602060405180830381865afa158015611945573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119699190612be2565b6119739085612bfb565b11156119b757505060408051808201909152601e81527f43453a20616d6f756e74206578636565647320534d2064656274206d617800006020820152600092909150565b5050604080516020810190915260008152600192909150565b6119da82826111c0565b610cf0576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055611a103390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b611a5e82826111c0565b15610cf0576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b600854600090815b81811015611bd757600060088281548110611ade57611ade612b81565b60009182526020918290200154604080516303ed69ad60e21b815290516001600160a01b0390921693508392630fb5a6b4926004808401938290030181865afa158015611b2f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b539190612be2565b8511611b5f5750611bcf565b806001600160a01b031663d4c3eea06040518163ffffffff1660e01b8152600401602060405180830381865afa158015611b9d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bc19190612be2565b611bcb9085612bfb565b9350505b600101611ac1565b507f0000000000000000000000004809010926aec940b550d34a46a52739f996d75d6001600160a01b031663d4c3eea06040518163ffffffff1660e01b8152600401602060405180830381865afa158015611c36573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c5a9190612be2565b610fcc9083612bfb565b6008546000908190815b81811015611d0f5760088181548110611c8957611c89612b81565b600091825260209182902001546040805163132d1d1560e11b815290516001600160a01b039092169263265a3a2a926004808401938290030181865afa158015611cd7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cfb9190612be2565b611d059084612bfb565b9250600101611c6e565b507f0000000000000000000000004809010926aec940b550d34a46a52739f996d75d6001600160a01b031663265a3a2a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d6e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d929190612be2565b611d9c9083612bfb565b9250505090565b6000611dad6124da565b9050611db88261167e565b6108809082612af2565b60006060611dd060006124aa565b6002541115611e1457505060408051808201909152601781527f43453a20696e76616c696420617373657420726174696f0000000000000000006020820152600091565b611e1e6000611ec7565b6003541115611e6257505060408051808201909152601881527f43453a20696e76616c69642065717569747920726174696f00000000000000006020820152600091565b611e6d6001546124c1565b6004541115611eb157505060408051808201909152601b81527f43453a20696e76616c6964206c697175696469747920726174696f00000000006020820152600091565b5050604080516020810190915260008152600191565b600080611ed26123e2565b90506000611ede611c64565b905081600003611ef2575060009392505050565b80600003611f0557506000199392505050565b80611f1383620f4240612c27565b61113c9190612c3e565b6000806060611f2b846118e0565b90925090508082611f4f5760405162461bcd60e51b815260040161091a9190612bb9565b50604051636361ddf360e11b81526001600160a01b0387811660048301528681166024830152604482018690527f0000000000000000000000005475611dffb8ef4d697ae39df9395513b6e947d7169063c6c3bbe6906064015b600060405180830381600087803b158015611fc357600080fd5b505af1158015611fd7573d6000803e3d6000fd5b50505050611fe3611dc2565b909250905080826120075760405162461bcd60e51b815260040161091a9190612bb9565b509295945050505050565b606060008267ffffffffffffffff81111561202f5761202f612c60565b604051908082528060200260200182016040528015612058578160200160208202803683370190505b509050835b6120678486612bfb565b8110156120d1576008818154811061208157612081612b81565b6000918252602090912001546001600160a01b0316826120a18784612af2565b815181106120b1576120b1612b81565b6001600160a01b039092166020928302919091019091015260010161205d565b509392505050565b6008546000908190815b8181101561218457600881815481106120fe576120fe612b81565b60009182526020918290200154604080516306a61f7560e51b815290516001600160a01b039092169263d4c3eea0926004808401938290030181865afa15801561214c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121709190612be2565b61217a9084612bfb565b92506001016120e3565b507f0000000000000000000000004809010926aec940b550d34a46a52739f996d75d6001600160a01b031663d4c3eea06040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d6e573d6000803e3d6000fd5b60008060606121f285856122f8565b909250905080826122165760405162461bcd60e51b815260040161091a9190612bb9565b5060405163b3f1c93d60e01b81526001600160a01b038881166004830152878116602483015260448201879052606482018690526000917f000000000000000000000000128d86a9e854a709df06b884f81eee7240f6ccf79091169063b3f1c93d906084016020604051808303816000875af115801561229a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122be9190612be2565b90506122c8611dc2565b909350915081836122ec5760405162461bcd60e51b815260040161091a9190612bb9565b50979650505050505050565b60008281526007602052604081205460609060405163bd85b03960e01b8152600481018690527f000000000000000000000000128d86a9e854a709df06b884f81eee7240f6ccf76001600160a01b03169063bd85b03990602401602060405180830381865afa15801561236f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123939190612be2565b61239d9085612bfb565b11156123c7576000604051806060016040528060278152602001612d0360279139915091506111af565b50506040805160208101909152600081526001909250929050565b6000806123ed6120d9565b905060006123f96124da565b90508181116124115761240c8183612af2565b611d9c565b60009250505090565b6000806060612428846125ea565b9092509050808261244c5760405162461bcd60e51b815260040161091a9190612bb9565b50604051636361ddf360e11b81526001600160a01b0387811660048301528681166024830152604482018690527f0000000000000000000000004809010926aec940b550d34a46a52739f996d75d169063c6c3bbe690606401611fa9565b6000806124b56120d9565b90506000611ede6124da565b6000806124cd83611ab9565b90506000611ede84611da3565b60007f000000000000000000000000128d86a9e854a709df06b884f81eee7240f6ccf76001600160a01b031663fc7b9c186040518163ffffffff1660e01b8152600401602060405180830381865afa15801561253a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061255e9190612be2565b7f0000000000000000000000005475611dffb8ef4d697ae39df9395513b6e947d76001600160a01b031663c13dbfed6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156125bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125e09190612be2565b61099d9190612bfb565b600060606006547f0000000000000000000000004809010926aec940b550d34a46a52739f996d75d6001600160a01b03166359356c5c6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561264f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126739190612be2565b61267d9085612bfb565b11156119b757505060408051808201909152601f81527f43453a20616d6f756e7420657863656564732050534d2064656274206d6178006020820152600092909150565b6126cb82826111c0565b610cf0576126d88161271a565b6126e383602061272c565b6040516020016126f4929190612c76565b60408051601f198184030181529082905262461bcd60e51b825261091a91600401612bb9565b60606108806001600160a01b03831660145b6060600061273b836002612c27565b612746906002612bfb565b67ffffffffffffffff81111561275e5761275e612c60565b6040519080825280601f01601f191660200182016040528015612788576020820181803683370190505b509050600360fc1b816000815181106127a3576127a3612b81565b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106127d2576127d2612b81565b60200101906001600160f81b031916908160001a90535060006127f6846002612c27565b612801906001612bfb565b90505b6001811115612879576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061283557612835612b81565b1a60f81b82828151811061284b5761284b612b81565b60200101906001600160f81b031916908160001a90535060049490941c9361287281612ceb565b9050612804565b508315610fcc5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161091a565b6000602082840312156128da57600080fd5b81356001600160e01b031981168114610fcc57600080fd5b80356001600160a01b038116811461290957600080fd5b919050565b60006020828403121561292057600080fd5b610fcc826128f2565b6000806040838503121561293c57600080fd5b50508035926020909101359150565b60006020828403121561295d57600080fd5b5035919050565b60005b8381101561297f578181015183820152602001612967565b50506000910152565b600081518084526129a0816020860160208601612964565b601f01601f19169290920160200192915050565b821515815260406020820152600061113c6040830184612988565b600080604083850312156129e257600080fd5b823591506129f2602084016128f2565b90509250929050565b6020808252825182820181905260009190848201906040850190845b81811015612a3c5783516001600160a01b031683529284019291840191600101612a17565b50909695505050505050565b600080600060608486031215612a5d57600080fd5b612a66846128f2565b95602085013595506040909401359392505050565b60008060408385031215612a8e57600080fd5b612a97836128f2565b946020939093013593505050565b6020808252601a908201527f6372656469742e656e666f726365722e73757065727669736f72000000000000604082015260600190565b634e487b7160e01b600052601160045260246000fd5b8181038181111561088057610880612adc565b60208082526017908201527f6372656469742e656e666f726365722e6d616e61676572000000000000000000604082015260600190565b60208082526025908201527f43453a204173736574204164617074657220696e646578206f7574206f6620626040820152646f756e647360d81b606082015260800190565b634e487b7160e01b600052603260045260246000fd5b600060208284031215612ba957600080fd5b81518015158114610fcc57600080fd5b602081526000610fcc6020830184612988565b634e487b7160e01b600052603160045260246000fd5b600060208284031215612bf457600080fd5b5051919050565b8082018082111561088057610880612adc565b600060018201612c2057612c20612adc565b5060010190565b808202811582820484141761088057610880612adc565b600082612c5b57634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052604160045260246000fd5b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351612cae816017850160208801612964565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351612cdf816028840160208801612964565b01602801949350505050565b600081612cfa57612cfa612adc565b50600019019056fe43453a20616d6f756e742065786365656473207465726d206d696e7465722064656274206d6178a26469706673582212208784637906c0f2f1267716ba73505ba3bbd5446eb99a9fbf094e91ccc4c176ed64736f6c63430008180033

Verified Source Code Full Match

Compiler: v0.8.24+commit.e11b9ed9 EVM: paris Optimization: Yes (200 runs)
Term.sol 69 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.24;

import {AccessControl} from "openzeppelin-contracts/contracts/access/AccessControl.sol";

import {ITerm} from "src/interfaces/ITerm.sol";

import {ERC1155} from "openzeppelin-contracts/contracts/token/ERC1155/ERC1155.sol";
import {ERC1155Supply} from "openzeppelin-contracts/contracts/token/ERC1155/extensions/ERC1155Supply.sol";
import {ERC1155Burnable} from "openzeppelin-contracts/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";

contract Term is AccessControl, ERC1155Supply, ERC1155Burnable {
    bytes32 public constant MINTER = keccak256(abi.encode("term.minter"));

    constructor(address admin, string memory uri) ERC1155(uri) {
        _grantRole(DEFAULT_ADMIN_ROLE, admin);
    }

    /// @notice Increase specific token's total supply
    /// @param to address to increment the token balance
    /// @param id token identifier
    /// @param amount quantity of token added
    function mint(
        address to,
        uint256 id,
        uint256 amount
    ) external onlyRole(MINTER) {
        _mint(to, id, amount, "");
    }

    /// @notice Increase multiple token's total supply in batch
    /// @param to address to increment the token balance
    /// @param ids array of token identifiers
    /// @param amounts array of quantity of token added
    function mintBatch(
        address to,
        uint256[] memory ids,
        uint256[] memory amounts
    ) external onlyRole(MINTER) {
        _mintBatch(to, ids, amounts, "");
    }

    function supportsInterface(
        bytes4 interfaceId
    ) public view virtual override(ERC1155, AccessControl) returns (bool) {
        // TODO: Combine with `AccessControl`

        return super.supportsInterface(interfaceId);
    }

    function _beforeTokenTransfer(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal override(ERC1155, ERC1155Supply) {
        ERC1155Supply._beforeTokenTransfer(
            operator,
            from,
            to,
            ids,
            amounts,
            data
        );
    }
}
CreditEnforcer.sol 682 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.24;

import {AccessControl} from "openzeppelin-contracts/contracts/access/AccessControl.sol";

import {ICreditEnforcer} from "src/interfaces/ICreditEnforcer.sol";

import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";

import {ITermIssuer} from "src/interfaces/ITermIssuer.sol";
import {IPegStabilityModule} from "src/interfaces/IPegStabilityModule.sol";
import {ISavingModule} from "src/interfaces/ISavingModule.sol";

import {IAssetAdapter} from "src/adapters/AssetAdapter.sol";

contract CreditEnforcer is AccessControl, ICreditEnforcer {
    bytes32 public constant MANAGER =
        keccak256(abi.encode("credit.enforcer.manager"));

    bytes32 public constant SUPERVISOR =
        keccak256(abi.encode("credit.enforcer.supervisor"));

    struct AssetAdapter {
        bool set;
        uint256 index;
    }

    IERC20 public immutable underlying;

    ITermIssuer public immutable termIssuer;

    ISavingModule public immutable sm;
    IPegStabilityModule public immutable psm;

    uint256 public duration = 365 days;

    uint256 public assetRatioMin = type(uint256).max;
    uint256 public equityRatioMin = type(uint256).max;
    uint256 public liquidityRatioMin = type(uint256).max;

    uint256 public smDebtMax = 0;
    uint256 public psmDebtMax = 0;

    mapping(uint256 => uint256) public termDebtMax;

    address[] public assetAdapterList;
    mapping(address => AssetAdapter) public assetAdapterMap;

    constructor(
        address admin,
        IERC20 underlying_,
        ITermIssuer termIssuer_,
        IPegStabilityModule psm_,
        ISavingModule sm_
    ) {
        _grantRole(DEFAULT_ADMIN_ROLE, admin);

        underlying = underlying_;
        termIssuer = termIssuer_;
        psm = psm_;
        sm = sm_;
    }

    /// @notice Issue the stablecoin, check the debt cap and solvency
    /// @param amount Transfer amount of the underlying
    function mintStablecoin(uint256 amount) external returns (uint256) {
        return _mintStablecoin(msg.sender, msg.sender, amount);
    }

    /// @notice Issue the stablecoin to a recipient, check the debt cap and
    /// solvency
    /// @param amount Transfer amount of the underlying
    function mintStablecoin(
        address to,
        uint256 amount
    ) external returns (uint256) {
        return _mintStablecoin(msg.sender, to, amount);
    }

    function _mintStablecoin(
        address from,
        address to,
        uint256 amount
    ) private returns (uint256) {
        bool valid;
        string memory message;

        (valid, message) = _checkPSMDebtMax(amount);
        require(valid, message);

        psm.mint(from, to, amount);

        (valid, message) = _checkRatios();
        require(valid, message);

        return amount;
    }

    /// @notice Issue the savingcoin to the sender, check the debt cap and
    /// solvency
    /// @param amount Underlying amount
    function mintSavingcoin(uint256 amount) external returns (uint256) {
        return _mintSavingcoin(msg.sender, msg.sender, amount);
    }

    /// @notice Issue the savingcoin to a recipient, check the debt cap and
    /// solvency
    /// @param to Receiver address
    /// @param amount Underlying amount
    function mintSavingcoin(
        address to,
        uint256 amount
    ) external returns (uint256) {
        return _mintSavingcoin(msg.sender, to, amount);
    }

    function _mintSavingcoin(
        address from,
        address to,
        uint256 amount
    ) private returns (uint256) {
        bool valid;
        string memory message;

        (valid, message) = _checkSMDebtMax(amount);
        require(valid, message);

        sm.mint(from, to, amount);

        (valid, message) = _checkRatios();
        require(valid, message);

        return amount;
    }

    /// @notice Issue the term to the sender, check the debt cap and solvency
    /// @param id Term index
    /// @param amount Term mint balance
    function mintTerm(uint256 id, uint256 amount) external returns (uint256) {
        return _mintTerm(msg.sender, msg.sender, id, amount);
    }

    /// @notice Issue the term to a recipient, check the debt cap and solvency
    /// @param to Receiver address
    /// @param id Term index
    /// @param amount Term mint balance
    function mintTerm(
        address to,
        uint256 id,
        uint256 amount
    ) external returns (uint256) {
        return _mintTerm(msg.sender, to, id, amount);
    }

    function _mintTerm(
        address from,
        address to,
        uint256 id,
        uint256 amount
    ) private returns (uint256) {
        bool valid;
        string memory message;

        (valid, message) = _checkTermDebtMax(id, amount);
        require(valid, message);

        uint256 cost = termIssuer.mint(from, to, id, amount);

        (valid, message) = _checkRatios();
        require(valid, message);

        return cost;
    }

    /// @notice Move capital (underlying) to a fund and check solvency
    /// @param index Fund index
    /// @param amount Underlying amount
    function allocate(
        uint256 index,
        uint256 amount
    ) external onlyRole(MANAGER) {
        require(
            _assetAdapterLength() > index,
            "CE: Asset Adapter index out of bounds"
        );

        address assetAdapterAddress = assetAdapterList[index];

        psm.withdraw(amount);

        underlying.approve(assetAdapterAddress, amount);
        IAssetAdapter(assetAdapterAddress).allocate(amount);
    }

    /// @notice Move capital (underlying) from a fund and check solvency
    /// @param index Fund index
    /// @param amount Underlying amount
    function withdraw(
        uint256 index,
        uint256 amount
    ) external onlyRole(MANAGER) {
        require(
            _assetAdapterLength() > index,
            "CE: Asset Adapter index out of bounds"
        );

        address assetAdapterAddress = assetAdapterList[index];
        IAssetAdapter(assetAdapterAddress).withdraw(amount);

        underlying.approve(address(psm), amount);
        psm.allocate(amount);
    }

    /// @notice Submit a deposit order on a fund and check solvency
    /// @param index Fund index
    /// @param amount Underlying amount
    function deposit(uint256 index, uint256 amount) external onlyRole(MANAGER) {
        require(
            _assetAdapterLength() > index,
            "CE: Asset Adapter index out of bounds"
        );

        bool valid;
        string memory message;

        address assetAdapterAddress = assetAdapterList[index];
        IAssetAdapter(assetAdapterAddress).deposit(amount);

        (valid, message) = _checkRatios();
        require(valid, message);
    }

    /// @notice Submit a redemption order on a fund and check solvency
    /// @param index Fund index
    /// @param amount Underlying amount
    function redeem(uint256 index, uint256 amount) external onlyRole(MANAGER) {
        require(
            _assetAdapterLength() > index,
            "CE: Asset Adapter index out of bounds"
        );

        bool valid;
        string memory message;

        address assetAdapterAddress = assetAdapterList[index];
        IAssetAdapter(assetAdapterAddress).redeem(amount);

        (valid, message) = _checkRatios();
        require(valid, message);
    }

    /// @notice Check PSM's max debt status if specified amount of underlying stablecoin was swapped
    /// @param amount amount of underlying stablecoin
    /// @return valid If swapping with the amount is valid in terms of PSM debt
    /// @return message error message
    function checkPSMDebtMax(
        uint256 amount
    ) external view returns (bool, string memory) {
        return _checkPSMDebtMax(amount);
    }

    function _checkPSMDebtMax(
        uint256 amount
    ) private view returns (bool, string memory) {
        if (amount + psm.underlyingBalance() > psmDebtMax) {
            return (false, "CE: amount exceeds PSM debt max");
        }

        return (true, "");
    }

    /// @notice Check SM's max debt status if specifie amount of underlying stablecoin was swapped
    /// @param amount amount of underlying stablecoin
    /// @return valid If swapping with the amount is valid in terms of SM debt
    /// @return message error message
    function checkSMDebtMax(
        uint256 amount
    ) external view returns (bool, string memory) {
        return _checkSMDebtMax(amount);
    }

    function _checkSMDebtMax(
        uint256 amount
    ) private view returns (bool, string memory) {
        if (amount + sm.totalDebt() > smDebtMax) {
            return (false, "CE: amount exceeds SM debt max");
        }

        return (true, "");
    }

    /// @notice Check specific Term's max debt status if specifie amount of that term was minted
    /// @param id Term identifier
    /// @param amount term amount
    /// @return valid If minting the term with the amount is valid in terms of it's max debt
    /// @return message error message
    function checkTermDebtMax(
        uint256 id,
        uint256 amount
    ) external view returns (bool, string memory) {
        return _checkTermDebtMax(id, amount);
    }

    function _checkTermDebtMax(
        uint256 id,
        uint256 amount
    ) private view returns (bool, string memory) {
        if (amount + termIssuer.totalSupply(id) > _getTermDebtMax(id)) {
            return (false, "CE: amount exceeds term minter debt max");
        }

        return (true, "");
    }

    /// @notice Check balance sheet ratios
    /// @return valid If ratios are valid
    /// @return message error message
    function checkRatios() external view returns (bool, string memory) {
        return _checkRatios();
    }

    function _checkRatios() private view returns (bool, string memory) {
        if (assetRatioMin > _assetRatio(0)) {
            return (false, "CE: invalid asset ratio");
        }

        if (equityRatioMin > _equityRatio(0)) {
            return (false, "CE: invalid equity ratio");
        }

        if (liquidityRatioMin > _liquidityRatio(duration)) {
            return (false, "CE: invalid liquidity ratio");
        }

        return (true, "");
    }

    /// @notice Get asset ratio
    /// @return ratio asset ratio
    function assetRatio() external view returns (uint256) {
        return _assetRatio(0);
    }

    function _assetRatio(uint256) private view returns (uint256) {
        uint256 assets_ = _assets();
        uint256 liabilities_ = _liabilities();

        if (assets_ == 0) return 0;
        if (liabilities_ == 0) return type(uint256).max;

        return (assets_ * 1e6) / liabilities_;
    }

    /// @notice Get equity ratio
    /// @return ratio equity ratio
    function equityRatio() external view returns (uint256) {
        return _equityRatio(0);
    }

    function _equityRatio(uint256) private view returns (uint256) {
        uint256 equity_ = _equity();
        uint256 riskWeightedAssets_ = _riskWeightedAssets();

        if (equity_ == 0) return 0;
        if (riskWeightedAssets_ == 0) return type(uint256).max;

        return (equity_ * 1e6) / riskWeightedAssets_;
    }

    /// @notice Get liquidity ratio
    /// @return ratio liquidity ratio
    function liquidityRatio() external view returns (uint256) {
        return _liquidityRatio(duration);
    }

    function _liquidityRatio(uint256 duration_) private view returns (uint256) {
        uint256 assets_ = _shortTermAssets(duration_);
        uint256 liabilities_ = _shortTermLiabilities(duration_);

        if (assets_ == 0) return 0;
        if (liabilities_ == 0) return type(uint256).max;

        return (assets_ * 1e6) / liabilities_;
    }

    /// @notice Get short term assets
    /// @return assets short term assets
    function shortTermAssets() external view returns (uint256) {
        return _shortTermAssets(duration);
    }

    function _shortTermAssets(
        uint256 _duration
    ) private view returns (uint256 stAssets) {
        uint256 length = assetAdapterList.length;

        for (uint256 i = 0; i < length; i++) {
            IAssetAdapter assetAdapter = IAssetAdapter(assetAdapterList[i]);

            if (_duration <= assetAdapter.duration()) continue;

            stAssets += assetAdapter.totalValue();
        }

        stAssets += psm.totalValue();
    }

    /// @notice Get extended assets
    /// @return assets extended assets
    function extendedAssets() external view returns (uint256) {
        return _extendedAssets(duration);
    }

    function _extendedAssets(
        uint256 _duration
    ) private view returns (uint256 eAssets) {
        uint256 length = assetAdapterList.length;

        for (uint256 i = 0; i < length; i++) {
            IAssetAdapter assetAdapter = IAssetAdapter(assetAdapterList[i]);

            if (_duration >= assetAdapter.duration()) continue;

            eAssets += assetAdapter.totalValue();
        }
    }

    /// @notice Get short term liabilities
    /// @return liabilities short term liabilities
    function shortTermLiabilities() external view returns (uint256) {
        return _shortTermLiabilities(duration);
    }

    function _shortTermLiabilities(
        uint256 duration_
    ) private view returns (uint256 totalLiabilities) {
        totalLiabilities = _liabilities();
        totalLiabilities -= _extendedLiabilities(duration_);

        // NOTE: The `extendedLiabilities` can not be greater than the
        // `liabilities`, but we may want to do a check here anyways, just in
        // case.
    }

    /// @notice Get extended liabilities
    /// @return liabilities extended liabilities
    function extendedLiabilities(
        uint256 duration_
    ) external view returns (uint256) {
        return _extendedLiabilities(duration_);
    }

    function _extendedLiabilities(
        uint256 duration_
    ) private view returns (uint256) {
        uint256 latestID = termIssuer.latestID();
        uint256 earliestID = termIssuer.earliestID();

        uint256 sum = 0;
        for (uint256 i = earliestID; i <= latestID; i++) {
            // MTS - BTS > duration

            // prettier-ignore
            if (termIssuer.maturityTimestamp(i) <= block.timestamp + duration_) {
                continue;
            }

            sum += termIssuer.totalSupply(i);
        }

        return sum;
    }

    /// @notice Get capital at risk
    /// @return riskWeightedAssets capital at risk
    function riskWeightedAssets() external view returns (uint256) {
        return _riskWeightedAssets();
    }

    function _riskWeightedAssets() private view returns (uint256) {
        uint256 total = 0;

        uint256 length = assetAdapterList.length;
        for (uint256 i = 0; i < length; i++) {
            total += IAssetAdapter(assetAdapterList[i]).totalRiskValue();
        }

        return total + psm.totalRiskValue();
    }

    /// @notice Get equity
    /// @return equity equity
    function equity() external view returns (uint256) {
        return _equity();
    }

    function _equity() private view returns (uint256) {
        uint256 assets_ = _assets();
        uint256 liabilities_ = _liabilities();

        return liabilities_ > assets_ ? 0 : assets_ - liabilities_;
    }

    /// @notice Get assets
    /// @return assets assets
    function assets() external view returns (uint256) {
        return _assets();
    }

    function _assets() private view returns (uint256) {
        uint256 total = 0;

        uint256 length = assetAdapterList.length;
        for (uint256 i = 0; i < length; i++) {
            total += IAssetAdapter(assetAdapterList[i]).totalValue();
        }

        return total + psm.totalValue();
    }

    /// @notice Get liabilities
    /// @return liabilities liabilities
    function liabilities() external view returns (uint256) {
        return _liabilities();
    }

    function _liabilities() private view returns (uint256) {
        return sm.rusdTotalLiability() + termIssuer.totalDebt();
    }

    /// @notice Set a length of time that determines long term and short term
    /// @param duration_ Length of time used to determine long and short term
    /// balance sheet items
    function setDuration(uint256 duration_) external onlyRole(MANAGER) {
        duration = duration_;
    }

    /// @notice Set a floor for the asset ratio
    /// @param assetRatioMin_ Value assigned to the minimum asset ratio
    function setAssetRatioMin(
        uint256 assetRatioMin_
    ) external onlyRole(MANAGER) {
        assetRatioMin = assetRatioMin_;
    }

    /// @notice Set a floor for the equity ratio
    /// @param equityRatioMin_ Value assigned to the minimum equity ratio
    function setEquityRatioMin(
        uint256 equityRatioMin_
    ) external onlyRole(MANAGER) {
        equityRatioMin = equityRatioMin_;
    }

    /// @notice Set a floor for the liquidity ratio
    /// @param liquidityRatioMin_ Value assigned to the minimum liquidity ratio
    function setLiquidityRatioMin(
        uint256 liquidityRatioMin_
    ) external onlyRole(MANAGER) {
        liquidityRatioMin = liquidityRatioMin_;
    }

    /// @notice Set a ceiling for the maximum amount of underlying stablecoin
    /// that can be held in the PSM at any given time
    /// @param psmDebtMax_ Maximum underlying balance
    function setPSMDebtMax(uint256 psmDebtMax_) external onlyRole(MANAGER) {
        psmDebtMax = psmDebtMax_;
    }

    /// @notice Set a ceiling for the maximum amount of native stablecoin
    /// that can be held in the SM at any given time
    /// @param smDebtMax_ Maximum stablecoin deposit
    function setSMDebtMax(uint256 smDebtMax_) external onlyRole(MANAGER) {
        smDebtMax = smDebtMax_;
    }

    /// @notice Set a ceiling for the maximum amount of term debt that can be
    /// issued for any given maturity
    /// @param id Term index
    /// @param amount Highest permitted debt value
    function setTermDebtMax(
        uint256 id,
        uint256 amount
    ) external onlyRole(MANAGER) {
        _setTermDebtMax(id, amount);
    }

    function _setTermDebtMax(uint256 id, uint256 amount) private {
        termDebtMax[id] = amount;
    }

    /// @notice Get the maximum amount of term debt that can be issued for specified term id
    /// @param id term identifier
    /// @return amount term's max debt
    function getTermDebtMax(uint256 id) external view returns (uint256) {
        return _getTermDebtMax(id);
    }

    function _getTermDebtMax(uint256 id) private view returns (uint256) {
        return termDebtMax[id];
    }

    function assetAdapterLength() external view returns (uint256) {
        return _assetAdapterLength();
    }

    function _assetAdapterLength() private view returns (uint256) {
        return assetAdapterList.length;
    }

    /// @notice Get a list of Asset Adapters
    /// @param startIndex Start index
    /// @param length Number of Asset Adapters to return
    /// @return list List of Asset Adapters
    function getAssetAdapterList(
        uint256 startIndex,
        uint256 length
    ) external view returns (address[] memory) {
        return _getAssetAdapterList(startIndex, length);
    }

    function _getAssetAdapterList(
        uint256 startIndex,
        uint256 length
    ) private view returns (address[] memory) {
        address[] memory list = new address[](length);

        for (uint256 i = startIndex; i < startIndex + length; i++) {
            list[i - startIndex] = assetAdapterList[i];
        }

        return list;
    }

    /// @notice Get a Asset Adapter
    /// @param adapter Asset Adapter address
    /// @return assetAdapter Asset Adapter
    function getAssetAdapter(
        address adapter
    ) external view returns (AssetAdapter memory) {
        return _getAssetAdapter(adapter);
    }

    function _getAssetAdapter(
        address adapter
    ) private view returns (AssetAdapter memory) {
        return assetAdapterMap[adapter];
    }

    /// @notice Add a Asset Adapter
    /// @param adapter Asset Adapter address
    function addAssetAdapter(address adapter) external onlyRole(SUPERVISOR) {
        AssetAdapter storage assetAdapter = assetAdapterMap[adapter];

        require(!assetAdapter.set, "CE: adapter already set");

        assetAdapterList.push(adapter);

        assetAdapter.set = true;
        assetAdapter.index = _assetAdapterLength() - 1;
    }

    /// @notice Remove a Asset Adapter
    /// @param adapter Asset Adapter address
    function removeAssetAdapter(address adapter) external onlyRole(SUPERVISOR) {
        AssetAdapter storage assetAdapter = assetAdapterMap[adapter];

        require(assetAdapter.set, "CE: adapter not set");

        uint256 lastIndex = _assetAdapterLength() - 1;
        address key = assetAdapterList[lastIndex];

        uint256 index = assetAdapter.index;

        assetAdapterList[index] = assetAdapterList[lastIndex];
        assetAdapterMap[key].index = index;

        assetAdapterList.pop();

        delete assetAdapterMap[adapter];
    }
}
IFund.sol 17 lines
// SPDX-License-Identifier: MIT

import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";

pragma solidity ^0.8.24;

interface IFund is IERC20 {
    function deposit(uint256) external;

    function redeem(uint256) external;

    function userDeposits(address) external view returns (uint256, uint256);

    function userRedemptions(address) external view returns (uint256, uint256);

    function currentPrice() external view returns (uint256);
}
ITerm.sol 11 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.24;

interface ITerm {
    function mint(address, uint256, uint256) external;

    function burn(address, uint256, uint256) external;

    function totalSupply(uint256) external view returns (uint256);
}
IToken.sol 11 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.24;

import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";

interface IToken is IERC20 {
    function mint(address, uint256) external;

    function burnFrom(address, uint256) external;
}
IOracle.sol 7 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.24;

interface IOracle {
    function latestAnswer() external view returns (int256);
}
AssetAdapter.sol 284 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.24;

import {AccessControl} from "openzeppelin-contracts/contracts/access/AccessControl.sol";

import {AggregatorV3Interface} from "chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol";

import {IFund} from "src/interfaces/IFund.sol";
import {IAssetAdapter} from "src/interfaces/IAssetAdapter.sol";
import {IOracle} from "src/interfaces/IOracle.sol";

contract UnderlyingAssetPrice is IOracle {
    AggregatorV3Interface aggregator;

    constructor(address _aggregator) {
        aggregator = AggregatorV3Interface(_aggregator);
    }

    function latestAnswer() external view returns (int256) {
        int256 answer;
        uint256 updatedAt;

        (, answer, , updatedAt, ) = aggregator.latestRoundData();

        return (block.timestamp > 1.1 days + updatedAt) ? int256(1e8) : answer;
    }
}

contract AssetPrice is IOracle {
    IFund public immutable fund;

    constructor(address fundAddress) {
        fund = IFund(fundAddress);
    }

    function latestAnswer() external view returns (int256) {
        uint256 currentPrice = fund.currentPrice();

        return
            currentPrice > uint256(type(int256).max)
                ? type(int256).max
                : int256(currentPrice);
    }
}

contract AssetAdapter is AccessControl, IAssetAdapter {
    bytes32 public constant MANAGER =
        keccak256(abi.encode("asset.adapter.manager"));

    bytes32 public constant CONTROLLER =
        keccak256(abi.encode("asset.adapter.controller"));

    uint256 public immutable duration;

    IOracle public immutable underlyingPriceOracle;
    IOracle public immutable fundPriceOracle;

    uint256 public underlyingRiskWeight = 0e6; // 100% = 1000000
    uint256 public fundRiskWeight = 0e6; // 100% = 1000000

    IFund public immutable fund;
    IERC20 public immutable underlying;

    uint8 public immutable DECIMAL_FACTOR;

    constructor(
        address admin,
        address underlyingAddr,
        address fundAddr,
        address underlyingPriceOracleAddr,
        address fundPriceOracleAddr,
        uint256 _duration
    ) {
        _grantRole(DEFAULT_ADMIN_ROLE, admin);

        duration = _duration;

        underlying = IERC20(underlyingAddr);
        DECIMAL_FACTOR = IERC20Metadata(address(underlying)).decimals();

        fund = IFund(fundAddr);

        underlyingPriceOracle = IOracle(underlyingPriceOracleAddr);
        fundPriceOracle = IOracle(fundPriceOracleAddr);
    }

    /// @notice Deposit underlying into the contract
    /// @param amount underlying amount
    function allocate(uint256 amount) external {
        underlying.transferFrom(msg.sender, address(this), amount);

        emit Allocate(msg.sender, amount, block.timestamp);
    }

    /// @notice Withdraw underlying from the contract
    /// @param amount underlying amount
    function withdraw(uint256 amount) external onlyRole(CONTROLLER) {
        underlying.transfer(msg.sender, amount);

        emit Withdraw(msg.sender, amount, block.timestamp);
    }

    function deposit(uint256 amount) external onlyRole(CONTROLLER) {
        underlying.approve(address(fund), amount);

        fund.deposit(amount);

        emit Deposit(msg.sender, amount, block.timestamp);
    }

    function redeem(uint256 amount) external onlyRole(CONTROLLER) {
        fund.approve(address(fund), amount);

        fund.redeem(amount);

        emit Redeem(msg.sender, amount, block.timestamp);
    }

    /// @notice Set risk weight of pool's junior token
    /// @param riskWeight value for the risk weight
    function setUnderlyingRiskWeight(
        uint256 riskWeight
    ) external onlyRole(MANAGER) {
        require(1e6 > riskWeight, "FA: Risk Weight can not be above 100%");

        underlyingRiskWeight = riskWeight;

        emit UnderlyingRiskWeightUpdate(riskWeight, block.timestamp);
    }

    /// @notice Set risk weight of pool's junior token
    /// @param riskWeight value for the risk weight
    function setFundRiskWeight(uint256 riskWeight) external onlyRole(MANAGER) {
        require(1e6 > riskWeight, "FA: Risk Weight can not be above 100%");

        fundRiskWeight = riskWeight;

        emit FundRiskWeightUpdate(riskWeight, block.timestamp);
    }

    /// @notice Total value held by this contract
    /// @return Asset value of the contract in USD
    function totalValue() external view returns (uint256) {
        uint256 total = 0;

        total += _underlyingTotalValue();
        total += _fundTotalValue();

        return total;
    }

    /// @notice Risk adjusted value held by this contract
    function totalRiskValue() external view returns (uint256) {
        uint256 total = 0;

        total += _underlyingTotalRiskValue();
        total += _fundTotalRiskValue();

        return total;
    }

    function underlyingTotalRiskValue() external view returns (uint256) {
        return _underlyingTotalRiskValue();
    }

    function _underlyingTotalRiskValue() private view returns (uint256) {
        uint256 assets;

        (, assets) = fund.userDeposits(address(this));

        return _underlyingRiskValue(assets + _underlyingBalance());
    }

    function underlyingRiskValue(
        uint256 amount
    ) external view returns (uint256) {
        return _underlyingRiskValue(amount);
    }

    function _underlyingRiskValue(
        uint256 amount
    ) private view returns (uint256) {
        return (underlyingRiskWeight * _underlyingValue(amount)) / 1e6;
    }

    function underlyingTotalValue() external view returns (uint256) {
        return _underlyingTotalValue();
    }

    function _underlyingTotalValue() private view returns (uint256) {
        uint256 assets;

        (, assets) = fund.userDeposits(address(this));

        return _underlyingValue(assets + _underlyingBalance());
    }

    function underlyingValue(uint256 amount) external view returns (uint256) {
        return _underlyingValue(amount);
    }

    function _underlyingValue(uint256 amount) private view returns (uint256) {
        return
            (_underlyingPriceOracleLatestAnswer() *
                amount *
                (10 ** (18 - DECIMAL_FACTOR))) / 1e8;
    }

    function underlyingBalance() external view returns (uint256) {
        return _underlyingBalance();
    }

    function _underlyingBalance() private view returns (uint256) {
        return underlying.balanceOf(address(this));
    }

    function fundTotalRiskValue() external view returns (uint256) {
        return _fundTotalRiskValue();
    }

    function _fundTotalRiskValue() private view returns (uint256) {
        uint256 shares;

        (, shares) = fund.userRedemptions(address(this));

        return _fundRiskValue(shares + _fundBalance());
    }

    function fundRiskValue(uint256 amount) external view returns (uint256) {
        return _fundRiskValue(amount);
    }

    function _fundRiskValue(uint256 amount) private view returns (uint256) {
        return (fundRiskWeight * _fundValue(amount)) / 1e6;
    }

    function fundTotalValue() external view returns (uint256) {
        return _fundTotalValue();
    }

    function _fundTotalValue() private view returns (uint256) {
        uint256 shares;

        (, shares) = fund.userRedemptions(address(this));

        return _fundValue(shares + _fundBalance());
    }

    function fundValue(uint256 amount) external view returns (uint256) {
        return _fundValue(amount);
    }

    function _fundValue(uint256 amount) private view returns (uint256) {
        return (_fundPriceOracleLatestAnswer() * amount) / 1e8;
    }

    function fundBalance() external view returns (uint256) {
        return _fundBalance();
    }

    function _fundBalance() private view returns (uint256) {
        return fund.balanceOf(address(this));
    }

    function _underlyingPriceOracleLatestAnswer()
        private
        view
        returns (uint256)
    {
        int256 latestAnswer = underlyingPriceOracle.latestAnswer();

        return latestAnswer > 0 ? uint256(latestAnswer) : 0;
    }

    function _fundPriceOracleLatestAnswer() private view returns (uint256) {
        int256 latestAnswer = fundPriceOracle.latestAnswer();

        return latestAnswer > 0 ? uint256(latestAnswer) : 0;
    }
}
ITermIssuer.sol 58 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.24;

import {IToken} from "./IToken.sol";
import {ITerm} from "../Term.sol";

interface ITermIssuer {
    event MintTerm(
        address indexed from,
        address indexed to,
        uint256 indexed termId,
        uint256 principle,
        uint256 cost,
        uint256 timestamp
    );

    event RedeemTerm(
        address indexed from,
        address indexed to,
        uint256 indexed termId,
        uint256 principle,
        uint256 timestamp
    );

    function mint(
        address,
        address,
        uint256,
        uint256
    ) external returns (uint256);

    function redeem(uint256, uint256) external;

    function redeem(address, uint256, uint256) external;

    function applyDiscount(
        uint256,
        uint256,
        uint256
    ) external view returns (uint256);

    function getDiscountRate(uint256 id) external view returns (uint256);

    function latestID() external view returns (uint256);

    function earliestID() external view returns (uint256);

    function maturityTimestamp(uint256) external view returns (uint256);

    function totalSupply(uint256) external view returns (uint256);

    function totalDebt() external view returns (uint256);

    function rusd() external view returns (IToken);

    function term() external view returns (ITerm);
}
IAssetAdapter.sol 61 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.24;

import {IOracle} from "src/interfaces/IOracle.sol";
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";

interface IAssetAdapter {
    event Allocate(address indexed signer, uint256 amount, uint256 timestamp);
    event Withdraw(address indexed signer, uint256 amount, uint256 timestamp);
    event Deposit(address indexed signer, uint256 amount, uint256 timestamp);
    event Redeem(address indexed signer, uint256 amount, uint256 timestamp);
    event UnderlyingRiskWeightUpdate(uint256 riskWeight, uint256 timestamp);
    event FundRiskWeightUpdate(uint256 riskWeight, uint256 timestamp);

    function duration() external view returns (uint256);

    function underlyingPriceOracle() external view returns (IOracle);

    function fundPriceOracle() external view returns (IOracle);

    function underlyingRiskWeight() external view returns (uint256);

    function fundRiskWeight() external view returns (uint256);

    //! function fund() external view returns (uint256); DIFFERS IN `ASSETADAPTER` AND MORPHO ADAPTERS

    function underlying() external view returns (IERC20);

    function allocate(uint256) external;

    function withdraw(uint256) external;

    function deposit(uint256) external;

    function redeem(uint256) external;

    function totalValue() external view returns (uint256);

    function totalRiskValue() external view returns (uint256);

    function underlyingTotalRiskValue() external view returns (uint256);

    function underlyingRiskValue(uint256) external view returns (uint256);

    function underlyingTotalValue() external view returns (uint256);

    function underlyingValue(uint256) external view returns (uint256);

    function underlyingBalance() external view returns (uint256);

    function fundTotalRiskValue() external view returns (uint256);

    function fundRiskValue(uint256) external view returns (uint256);

    function fundTotalValue() external view returns (uint256);

    function fundValue(uint256) external view returns (uint256);

    function fundBalance() external view returns (uint256);
}
ISavingModule.sol 34 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.24;

interface ISavingModule {
    event Mint(
        address indexed from,
        address indexed to,
        uint256 mintAmount,
        uint256 burnAmount,
        uint256 timestamp
    );

    event Redeem(
        address indexed from,
        address indexed to,
        uint256 redeemAmount,
        uint256 burnAmount,
        uint256 timestamp
    );

    event Update(
        uint256 compoundFactorAccum,
        uint256 currentRate,
        uint256 rate,
        uint256 timestamp
    );

    function mint(address, address, uint256) external;

    function rusdTotalLiability() external view returns (uint256);

    function totalDebt() external view returns (uint256);
}
ICreditEnforcer.sol 14 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.24;

import {IPegStabilityModule} from "./IPegStabilityModule.sol";
import {ITermIssuer} from "./ITermIssuer.sol";

interface ICreditEnforcer {
    function mintTerm(uint256, uint256) external returns (uint256);

    function psm() external view returns (IPegStabilityModule);

    function termIssuer() external view returns (ITermIssuer);
}
IPegStabilityModule.sol 35 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.24;

interface IPegStabilityModule {
    event Allocate(address indexed signer, uint256 amount, uint256 timestamp);
    event Withdraw(address indexed signer, uint256 amount, uint256 timestamp);
    event UnderlyingRiskWeightUpdate(uint256 riskWeight, uint256 timestamp);

    event Mint(
        address indexed from,
        address indexed to,
        uint256 amount,
        uint256 timestamp
    );

    event Redeem(
        address indexed from,
        address indexed to,
        uint256 amount,
        uint256 timestamp
    );

    function allocate(uint256) external;

    function withdraw(uint256) external;

    function mint(address, address, uint256) external;

    function totalValue() external view returns (uint256);

    function totalRiskValue() external view returns (uint256);

    function underlyingBalance() external view returns (uint256);
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @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
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 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 functionCallWithValue(target, data, 0, "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");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, 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) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, 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) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // 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
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with 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;
    }
}
Strings.sol 70 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/Math.sol";

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }
}
Math.sol 345 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @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.
        return (a & b) + (a ^ b) / 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 == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1);

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator,
        Rounding rounding
    ) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10**64) {
                value /= 10**64;
                result += 64;
            }
            if (value >= 10**32) {
                value /= 10**32;
                result += 32;
            }
            if (value >= 10**16) {
                value /= 10**16;
                result += 16;
            }
            if (value >= 10**8) {
                value /= 10**8;
                result += 8;
            }
            if (value >= 10**4) {
                value /= 10**4;
                result += 4;
            }
            if (value >= 10**2) {
                value /= 10**2;
                result += 2;
            }
            if (value >= 10**1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
        }
    }
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @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);

    /**
     * @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 `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, 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 `from` to `to` 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 from,
        address to,
        uint256 amount
    ) external returns (bool);
}
AccessControl.sol 247 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol)

pragma solidity ^0.8.0;

import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
        return _roles[role].members[account];
    }

    /**
     * @dev Revert with a standard message if `_msgSender()` is missing `role`.
     * Overriding this function changes the behavior of the {onlyRole} modifier.
     *
     * Format of the revert message is described in {_checkRole}.
     *
     * _Available since v4.6._
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        Strings.toHexString(account),
                        " is missing role ",
                        Strings.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleGranted} event.
     */
    function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleRevoked} event.
     */
    function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address account) public virtual override {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * May emit a {RoleGranted} event.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     *
     * NOTE: This function is deprecated in favor of {_grantRole}.
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }
}
IAccessControl.sol 88 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) external;
}
ERC1155.sol 517 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC1155/ERC1155.sol)

pragma solidity ^0.8.0;

import "./IERC1155.sol";
import "./IERC1155Receiver.sol";
import "./extensions/IERC1155MetadataURI.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/introspection/ERC165.sol";

/**
 * @dev Implementation of the basic standard multi-token.
 * See https://eips.ethereum.org/EIPS/eip-1155
 * Originally based on code by Enjin: https://github.com/enjin/erc-1155
 *
 * _Available since v3.1._
 */
contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
    using Address for address;

    // Mapping from token ID to account balances
    mapping(uint256 => mapping(address => uint256)) private _balances;

    // Mapping from account to operator approvals
    mapping(address => mapping(address => bool)) private _operatorApprovals;

    // Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json
    string private _uri;

    /**
     * @dev See {_setURI}.
     */
    constructor(string memory uri_) {
        _setURI(uri_);
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
        return
            interfaceId == type(IERC1155).interfaceId ||
            interfaceId == type(IERC1155MetadataURI).interfaceId ||
            super.supportsInterface(interfaceId);
    }

    /**
     * @dev See {IERC1155MetadataURI-uri}.
     *
     * This implementation returns the same URI for *all* token types. It relies
     * on the token type ID substitution mechanism
     * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
     *
     * Clients calling this function must replace the `\{id\}` substring with the
     * actual token type ID.
     */
    function uri(uint256) public view virtual override returns (string memory) {
        return _uri;
    }

    /**
     * @dev See {IERC1155-balanceOf}.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
        require(account != address(0), "ERC1155: address zero is not a valid owner");
        return _balances[id][account];
    }

    /**
     * @dev See {IERC1155-balanceOfBatch}.
     *
     * Requirements:
     *
     * - `accounts` and `ids` must have the same length.
     */
    function balanceOfBatch(address[] memory accounts, uint256[] memory ids)
        public
        view
        virtual
        override
        returns (uint256[] memory)
    {
        require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch");

        uint256[] memory batchBalances = new uint256[](accounts.length);

        for (uint256 i = 0; i < accounts.length; ++i) {
            batchBalances[i] = balanceOf(accounts[i], ids[i]);
        }

        return batchBalances;
    }

    /**
     * @dev See {IERC1155-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual override {
        _setApprovalForAll(_msgSender(), operator, approved);
    }

    /**
     * @dev See {IERC1155-isApprovedForAll}.
     */
    function isApprovedForAll(address account, address operator) public view virtual override returns (bool) {
        return _operatorApprovals[account][operator];
    }

    /**
     * @dev See {IERC1155-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) public virtual override {
        require(
            from == _msgSender() || isApprovedForAll(from, _msgSender()),
            "ERC1155: caller is not token owner or approved"
        );
        _safeTransferFrom(from, to, id, amount, data);
    }

    /**
     * @dev See {IERC1155-safeBatchTransferFrom}.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) public virtual override {
        require(
            from == _msgSender() || isApprovedForAll(from, _msgSender()),
            "ERC1155: caller is not token owner or approved"
        );
        _safeBatchTransferFrom(from, to, ids, amounts, data);
    }

    /**
     * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `from` must have a balance of tokens of type `id` of at least `amount`.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function _safeTransferFrom(
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) internal virtual {
        require(to != address(0), "ERC1155: transfer to the zero address");

        address operator = _msgSender();
        uint256[] memory ids = _asSingletonArray(id);
        uint256[] memory amounts = _asSingletonArray(amount);

        _beforeTokenTransfer(operator, from, to, ids, amounts, data);

        uint256 fromBalance = _balances[id][from];
        require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
        unchecked {
            _balances[id][from] = fromBalance - amount;
        }
        _balances[id][to] += amount;

        emit TransferSingle(operator, from, to, id, amount);

        _afterTokenTransfer(operator, from, to, ids, amounts, data);

        _doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);
    }

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_safeTransferFrom}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function _safeBatchTransferFrom(
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual {
        require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
        require(to != address(0), "ERC1155: transfer to the zero address");

        address operator = _msgSender();

        _beforeTokenTransfer(operator, from, to, ids, amounts, data);

        for (uint256 i = 0; i < ids.length; ++i) {
            uint256 id = ids[i];
            uint256 amount = amounts[i];

            uint256 fromBalance = _balances[id][from];
            require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
            unchecked {
                _balances[id][from] = fromBalance - amount;
            }
            _balances[id][to] += amount;
        }

        emit TransferBatch(operator, from, to, ids, amounts);

        _afterTokenTransfer(operator, from, to, ids, amounts, data);

        _doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data);
    }

    /**
     * @dev Sets a new URI for all token types, by relying on the token type ID
     * substitution mechanism
     * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
     *
     * By this mechanism, any occurrence of the `\{id\}` substring in either the
     * URI or any of the amounts in the JSON file at said URI will be replaced by
     * clients with the token type ID.
     *
     * For example, the `https://token-cdn-domain/\{id\}.json` URI would be
     * interpreted by clients as
     * `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json`
     * for token type ID 0x4cce0.
     *
     * See {uri}.
     *
     * Because these URIs cannot be meaningfully represented by the {URI} event,
     * this function emits no events.
     */
    function _setURI(string memory newuri) internal virtual {
        _uri = newuri;
    }

    /**
     * @dev Creates `amount` tokens of token type `id`, and assigns them to `to`.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function _mint(
        address to,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) internal virtual {
        require(to != address(0), "ERC1155: mint to the zero address");

        address operator = _msgSender();
        uint256[] memory ids = _asSingletonArray(id);
        uint256[] memory amounts = _asSingletonArray(amount);

        _beforeTokenTransfer(operator, address(0), to, ids, amounts, data);

        _balances[id][to] += amount;
        emit TransferSingle(operator, address(0), to, id, amount);

        _afterTokenTransfer(operator, address(0), to, ids, amounts, data);

        _doSafeTransferAcceptanceCheck(operator, address(0), to, id, amount, data);
    }

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - `ids` and `amounts` must have the same length.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function _mintBatch(
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual {
        require(to != address(0), "ERC1155: mint to the zero address");
        require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");

        address operator = _msgSender();

        _beforeTokenTransfer(operator, address(0), to, ids, amounts, data);

        for (uint256 i = 0; i < ids.length; i++) {
            _balances[ids[i]][to] += amounts[i];
        }

        emit TransferBatch(operator, address(0), to, ids, amounts);

        _afterTokenTransfer(operator, address(0), to, ids, amounts, data);

        _doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
    }

    /**
     * @dev Destroys `amount` tokens of token type `id` from `from`
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `from` must have at least `amount` tokens of token type `id`.
     */
    function _burn(
        address from,
        uint256 id,
        uint256 amount
    ) internal virtual {
        require(from != address(0), "ERC1155: burn from the zero address");

        address operator = _msgSender();
        uint256[] memory ids = _asSingletonArray(id);
        uint256[] memory amounts = _asSingletonArray(amount);

        _beforeTokenTransfer(operator, from, address(0), ids, amounts, "");

        uint256 fromBalance = _balances[id][from];
        require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
        unchecked {
            _balances[id][from] = fromBalance - amount;
        }

        emit TransferSingle(operator, from, address(0), id, amount);

        _afterTokenTransfer(operator, from, address(0), ids, amounts, "");
    }

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - `ids` and `amounts` must have the same length.
     */
    function _burnBatch(
        address from,
        uint256[] memory ids,
        uint256[] memory amounts
    ) internal virtual {
        require(from != address(0), "ERC1155: burn from the zero address");
        require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");

        address operator = _msgSender();

        _beforeTokenTransfer(operator, from, address(0), ids, amounts, "");

        for (uint256 i = 0; i < ids.length; i++) {
            uint256 id = ids[i];
            uint256 amount = amounts[i];

            uint256 fromBalance = _balances[id][from];
            require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
            unchecked {
                _balances[id][from] = fromBalance - amount;
            }
        }

        emit TransferBatch(operator, from, address(0), ids, amounts);

        _afterTokenTransfer(operator, from, address(0), ids, amounts, "");
    }

    /**
     * @dev Approve `operator` to operate on all of `owner` tokens
     *
     * Emits an {ApprovalForAll} event.
     */
    function _setApprovalForAll(
        address owner,
        address operator,
        bool approved
    ) internal virtual {
        require(owner != operator, "ERC1155: setting approval status for self");
        _operatorApprovals[owner][operator] = approved;
        emit ApprovalForAll(owner, operator, approved);
    }

    /**
     * @dev Hook that is called before any token transfer. This includes minting
     * and burning, as well as batched variants.
     *
     * The same hook is called on both single and batched variants. For single
     * transfers, the length of the `ids` and `amounts` arrays will be 1.
     *
     * Calling conditions (for each `id` and `amount` pair):
     *
     * - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * of token type `id` will be  transferred to `to`.
     * - When `from` is zero, `amount` tokens of token type `id` will be minted
     * for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
     * will be burned.
     * - `from` and `to` are never both zero.
     * - `ids` and `amounts` have the same, non-zero length.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual {}

    /**
     * @dev Hook that is called after any token transfer. This includes minting
     * and burning, as well as batched variants.
     *
     * The same hook is called on both single and batched variants. For single
     * transfers, the length of the `id` and `amount` arrays will be 1.
     *
     * Calling conditions (for each `id` and `amount` pair):
     *
     * - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * of token type `id` will be  transferred to `to`.
     * - When `from` is zero, `amount` tokens of token type `id` will be minted
     * for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
     * will be burned.
     * - `from` and `to` are never both zero.
     * - `ids` and `amounts` have the same, non-zero length.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual {}

    function _doSafeTransferAcceptanceCheck(
        address operator,
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) private {
        if (to.isContract()) {
            try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
                if (response != IERC1155Receiver.onERC1155Received.selector) {
                    revert("ERC1155: ERC1155Receiver rejected tokens");
                }
            } catch Error(string memory reason) {
                revert(reason);
            } catch {
                revert("ERC1155: transfer to non-ERC1155Receiver implementer");
            }
        }
    }

    function _doSafeBatchTransferAcceptanceCheck(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) private {
        if (to.isContract()) {
            try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
                bytes4 response
            ) {
                if (response != IERC1155Receiver.onERC1155BatchReceived.selector) {
                    revert("ERC1155: ERC1155Receiver rejected tokens");
                }
            } catch Error(string memory reason) {
                revert(reason);
            } catch {
                revert("ERC1155: transfer to non-ERC1155Receiver implementer");
            }
        }
    }

    function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) {
        uint256[] memory array = new uint256[](1);
        array[0] = element;

        return array;
    }
}
IERC1155.sol 125 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/IERC1155.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165.sol";

/**
 * @dev Required interface of an ERC1155 compliant contract, as defined in the
 * https://eips.ethereum.org/EIPS/eip-1155[EIP].
 *
 * _Available since v3.1._
 */
interface IERC1155 is IERC165 {
    /**
     * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
     */
    event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);

    /**
     * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
     * transfers.
     */
    event TransferBatch(
        address indexed operator,
        address indexed from,
        address indexed to,
        uint256[] ids,
        uint256[] values
    );

    /**
     * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
     * `approved`.
     */
    event ApprovalForAll(address indexed account, address indexed operator, bool approved);

    /**
     * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
     *
     * If an {URI} event was emitted for `id`, the standard
     * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
     * returned by {IERC1155MetadataURI-uri}.
     */
    event URI(string value, uint256 indexed id);

    /**
     * @dev Returns the amount of tokens of token type `id` owned by `account`.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function balanceOf(address account, uint256 id) external view returns (uint256);

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
     *
     * Requirements:
     *
     * - `accounts` and `ids` must have the same length.
     */
    function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
        external
        view
        returns (uint256[] memory);

    /**
     * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
     *
     * Emits an {ApprovalForAll} event.
     *
     * Requirements:
     *
     * - `operator` cannot be the caller.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
     *
     * See {setApprovalForAll}.
     */
    function isApprovedForAll(address account, address operator) external view returns (bool);

    /**
     * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
     * - `from` must have a balance of tokens of type `id` of at least `amount`.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes calldata data
    ) external;

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - `ids` and `amounts` must have the same length.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] calldata ids,
        uint256[] calldata amounts,
        bytes calldata data
    ) external;
}
ERC165.sol 29 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
AggregatorV3Interface.sol 32 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface AggregatorV3Interface {
  function decimals() external view returns (uint8);

  function description() external view returns (string memory);

  function version() external view returns (uint256);

  function getRoundData(uint80 _roundId)
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );

  function latestRoundData()
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );
}
IERC1155Receiver.sol 58 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165.sol";

/**
 * @dev _Available since v3.1._
 */
interface IERC1155Receiver is IERC165 {
    /**
     * @dev Handles the receipt of a single ERC1155 token type. This function is
     * called at the end of a `safeTransferFrom` after the balance has been updated.
     *
     * NOTE: To accept the transfer, this must return
     * `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
     * (i.e. 0xf23a6e61, or its own function selector).
     *
     * @param operator The address which initiated the transfer (i.e. msg.sender)
     * @param from The address which previously owned the token
     * @param id The ID of the token being transferred
     * @param value The amount of tokens being transferred
     * @param data Additional data with no specified format
     * @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
     */
    function onERC1155Received(
        address operator,
        address from,
        uint256 id,
        uint256 value,
        bytes calldata data
    ) external returns (bytes4);

    /**
     * @dev Handles the receipt of a multiple ERC1155 token types. This function
     * is called at the end of a `safeBatchTransferFrom` after the balances have
     * been updated.
     *
     * NOTE: To accept the transfer(s), this must return
     * `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
     * (i.e. 0xbc197c81, or its own function selector).
     *
     * @param operator The address which initiated the batch transfer (i.e. msg.sender)
     * @param from The address which previously owned the token
     * @param ids An array containing ids of each token being transferred (order and length must match values array)
     * @param values An array containing amounts of each token being transferred (order and length must match ids array)
     * @param data Additional data with no specified format
     * @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
     */
    function onERC1155BatchReceived(
        address operator,
        address from,
        uint256[] calldata ids,
        uint256[] calldata values,
        bytes calldata data
    ) external returns (bytes4);
}
IERC20Metadata.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @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);
}
ERC1155Supply.sol 64 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC1155/extensions/ERC1155Supply.sol)

pragma solidity ^0.8.0;

import "../ERC1155.sol";

/**
 * @dev Extension of ERC1155 that adds tracking of total supply per id.
 *
 * Useful for scenarios where Fungible and Non-fungible tokens have to be
 * clearly identified. Note: While a totalSupply of 1 might mean the
 * corresponding is an NFT, there is no guarantees that no other token with the
 * same id are not going to be minted.
 */
abstract contract ERC1155Supply is ERC1155 {
    mapping(uint256 => uint256) private _totalSupply;

    /**
     * @dev Total amount of tokens in with a given id.
     */
    function totalSupply(uint256 id) public view virtual returns (uint256) {
        return _totalSupply[id];
    }

    /**
     * @dev Indicates whether any token exist with a given id, or not.
     */
    function exists(uint256 id) public view virtual returns (bool) {
        return ERC1155Supply.totalSupply(id) > 0;
    }

    /**
     * @dev See {ERC1155-_beforeTokenTransfer}.
     */
    function _beforeTokenTransfer(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual override {
        super._beforeTokenTransfer(operator, from, to, ids, amounts, data);

        if (from == address(0)) {
            for (uint256 i = 0; i < ids.length; ++i) {
                _totalSupply[ids[i]] += amounts[i];
            }
        }

        if (to == address(0)) {
            for (uint256 i = 0; i < ids.length; ++i) {
                uint256 id = ids[i];
                uint256 amount = amounts[i];
                uint256 supply = _totalSupply[id];
                require(supply >= amount, "ERC1155: burn amount exceeds totalSupply");
                unchecked {
                    _totalSupply[id] = supply - amount;
                }
            }
        }
    }
}
ERC1155Burnable.sol 40 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC1155/extensions/ERC1155Burnable.sol)

pragma solidity ^0.8.0;

import "../ERC1155.sol";

/**
 * @dev Extension of {ERC1155} that allows token holders to destroy both their
 * own tokens and those that they have been approved to use.
 *
 * _Available since v3.1._
 */
abstract contract ERC1155Burnable is ERC1155 {
    function burn(
        address account,
        uint256 id,
        uint256 value
    ) public virtual {
        require(
            account == _msgSender() || isApprovedForAll(account, _msgSender()),
            "ERC1155: caller is not token owner or approved"
        );

        _burn(account, id, value);
    }

    function burnBatch(
        address account,
        uint256[] memory ids,
        uint256[] memory values
    ) public virtual {
        require(
            account == _msgSender() || isApprovedForAll(account, _msgSender()),
            "ERC1155: caller is not token owner or approved"
        );

        _burnBatch(account, ids, values);
    }
}
IERC1155MetadataURI.sol 22 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC1155/extensions/IERC1155MetadataURI.sol)

pragma solidity ^0.8.0;

import "../IERC1155.sol";

/**
 * @dev Interface of the optional ERC1155MetadataExtension interface, as defined
 * in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
 *
 * _Available since v3.1._
 */
interface IERC1155MetadataURI is IERC1155 {
    /**
     * @dev Returns the URI for token type `id`.
     *
     * If the `\{id\}` substring is present in the URI, it must be replaced by
     * clients with the actual token type ID.
     */
    function uri(uint256 id) external view returns (string memory);
}

Read Contract

DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
MANAGER 0x1b2df850 → bytes32
SUPERVISOR 0x7b3ba717 → bytes32
assetAdapterLength 0x96cbc3c6 → uint256
assetAdapterList 0x4cc79725 → address
assetAdapterMap 0x976fc43a → bool, uint256
assetRatio 0xa63e8c4b → uint256
assetRatioMin 0xf1a2c987 → uint256
assets 0x71a97305 → uint256
checkPSMDebtMax 0xbcf18bfd → bool, string
checkRatios 0x5865677b → bool, string
checkSMDebtMax 0x21960fbf → bool, string
checkTermDebtMax 0x8d86c1a0 → bool, string
duration 0x0fb5a6b4 → uint256
equity 0x91a0ac6a → uint256
equityRatio 0x5ff12547 → uint256
equityRatioMin 0x5e516c4c → uint256
extendedAssets 0x10690a50 → uint256
extendedLiabilities 0x1e655e9c → uint256
getAssetAdapter 0x8a7fe60f → tuple
getAssetAdapterList 0x6ad62098 → address[]
getRoleAdmin 0x248a9ca3 → bytes32
getTermDebtMax 0x375190bf → uint256
hasRole 0x91d14854 → bool
liabilities 0xb4add307 → uint256
liquidityRatio 0xa83019fa → uint256
liquidityRatioMin 0x58c0a364 → uint256
psm 0x04bda262 → address
psmDebtMax 0x7caa75a5 → uint256
riskWeightedAssets 0x401b1a74 → uint256
shortTermAssets 0x3b62142b → uint256
shortTermLiabilities 0x4f66577c → uint256
sm 0x7cd570b6 → address
smDebtMax 0x50960e13 → uint256
supportsInterface 0x01ffc9a7 → bool
termDebtMax 0x3cf1dee2 → uint256
termIssuer 0x6eb2dc53 → address
underlying 0x6f307dc3 → address

Write Contract 22 functions

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

addAssetAdapter 0x0cb5dec0
address adapter
allocate 0x172cfa4c
uint256 index
uint256 amount
deposit 0xe2bbb158
uint256 index
uint256 amount
grantRole 0x2f2ff15d
bytes32 role
address account
mintSavingcoin 0x660cf34e
uint256 amount
returns: uint256
mintSavingcoin 0xb255f4e2
address to
uint256 amount
returns: uint256
mintStablecoin 0xa0b4dbb1
uint256 amount
returns: uint256
mintStablecoin 0xa7379086
address to
uint256 amount
returns: uint256
mintTerm 0x86eeec5d
address to
uint256 id
uint256 amount
returns: uint256
mintTerm 0xfe4656a4
uint256 id
uint256 amount
returns: uint256
redeem 0x7cbc2373
uint256 index
uint256 amount
removeAssetAdapter 0xad4c4305
address adapter
renounceRole 0x36568abe
bytes32 role
address account
revokeRole 0xd547741f
bytes32 role
address account
setAssetRatioMin 0x58cc3366
uint256 assetRatioMin_
setDuration 0xf6be71d1
uint256 duration_
setEquityRatioMin 0x25914e59
uint256 equityRatioMin_
setLiquidityRatioMin 0x39908710
uint256 liquidityRatioMin_
setPSMDebtMax 0xd45f2af0
uint256 psmDebtMax_
setSMDebtMax 0x7d1cce2c
uint256 smDebtMax_
setTermDebtMax 0x3553523e
uint256 id
uint256 amount
withdraw 0x441a3e70
uint256 index
uint256 amount

Recent Transactions

No transactions found for this address