Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x9905F34bA39A54310c2dA3aD25a418d35Abc2a75
Balance 0 ETH
Nonce 1
Code Size 20584 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

20584 bytes
0x608060405234801561001057600080fd5b50600436106102d65760003560e01c8063939d623711610182578063cd5ce885116100e9578063e493a9a4116100a2578063f2e41f281161007c578063f2e41f28146108f9578063f2fde38b146109cf578063f40f0f52146109e2578063f887ea40146109f557600080fd5b8063e493a9a414610885578063e592855a14610898578063ed5ae090146108bf57600080fd5b8063cd5ce885146107e7578063cf59d56314610821578063cf8afec81461083c578063dd62ed3e1461084f578063e0bab4c414610862578063e3161ddd1461087d57600080fd5b8063a9059cbb1161013b578063a9059cbb14610775578063ad5c464814610788578063b3ff01791461079d578063b66dc5c3146107b0578063bdda7353146107c3578063c54e44eb146107cc57600080fd5b8063939d62371461072357806395d89b411461072c578063964b434e14610734578063a39205e61461073c578063a457c2d71461074f578063a587f4f31461076257600080fd5b8063372500ab11610241578063667f2a31116101fa578063715018a6116101d4578063715018a6146106ec57806389a30271146106f45780638da5cb5b146107095780639231cf741461071a57600080fd5b8063667f2a31146105fb57806370385a6c1461060e57806370a08231146106c357600080fd5b8063372500ab146104ee57806339509351146104f657806343f5d1c0146105095780634d064c6c1461051c5780635a0acd0c1461052f57806364239fc0146105f257600080fd5b806317c5da6a1161029357806317c5da6a1461045557806318160ddd1461045d5780631959a0021461046f57806323b872dd146104b957806325397245146104cc578063313ce567146104df57600080fd5b8063042a2077146102db57806306fdde03146102f0578063095ea7b31461030e57806309a4f60c146103315780630fd9eeeb14610344578063127ff76a14610371575b600080fd5b6102ee6102e9366004614b06565b610a0a565b005b6102f8610a3f565b6040516103059190614b6f565b60405180910390f35b61032161031c366004614ba5565b610ad1565b6040519015158152602001610305565b6102ee61033f366004614b06565b610aeb565b610359600080516020614fd383398151915281565b6040516001600160a01b039091168152602001610305565b6103ed61037f366004614b06565b600960208190526000918252604090912080546001820154600283015460038401546004850154600586015460068701546007880154600889015498909901546001600160a01b03978816999688169895979496939592949193909116919060ff808216916101009004168b565b604080516001600160a01b039c8d1681529a8c1660208c01528a01989098526060890196909652608088019490945260a087019290925260c086015290941660e084015261010083019390935291151561012082015290151561014082015261016001610305565b6102ee610cf4565b6002545b604051908152602001610305565b61049e61047d366004614bcf565b60076020526000908152604090208054600182015460029092015490919083565b60408051938452602084019290925290820152606001610305565b6103216104c7366004614bea565b610d6f565b6102ee6104da366004614c26565b610d93565b60405160128152602001610305565b6102ee611265565b610321610504366004614ba5565b611368565b6102ee610517366004614c4b565b61138a565b6102ee61052a366004614b06565b6116f1565b61059c61053d366004614b06565b60009081526009602081905260409091208054600182015460028301546003840154600585015460068601546007870154600888015497909801546001600160a01b039687169995871698949793969295919492909216929160ff1690565b604080516001600160a01b039a8b168152988a1660208a01528801969096526060870194909452608086019290925260a085015290931660c083015260e082019290925290151561010082015261012001610305565b610461600a5481565b6102ee610609366004614b06565b611702565b61067361061c366004614b06565b6000908152600860208190526040909120805460018201546002830154600484015460058501546006860154600787015496909701546001600160a01b039586169894861697939692959194919093169260ff1690565b604080516001600160a01b03998a16815297891660208901528701959095526060860193909352608085019190915290931660a083015260c082019290925290151560e082015261010001610305565b6104616106d1366004614bcf565b6001600160a01b031660009081526020819052604090205490565b6102ee61191b565b61035960008051602061501383398151915281565b6005546001600160a01b0316610359565b610461600d5481565b610461600c5481565b6102f861192d565b61046161193c565b6102ee61074a366004614b06565b611a68565b61032161075d366004614ba5565b611c5a565b6102ee610770366004614ba5565b611cd5565b610321610783366004614ba5565b611da4565b610359600080516020614fb383398151915281565b6102ee6107ab366004614b06565b611db2565b6102ee6107be366004614b06565b611dc3565b610461600b5481565b61035973dac17f958d2ee523a2206206994597c13d831ec781565b6104616107f5366004614c6d565b60008281526009602090815260408083206001600160a01b0385168452600a0190915290205492915050565b610359735f98805a4e8be255a32880fdec7f6728c6568ba081565b6102ee61084a366004614c99565b612086565b61046161085d366004614ccc565b612348565b610359736b175474e89094c44da98b954eedeac495271d0f81565b6102ee612373565b6102ee610893366004614c4b565b6124a8565b6103597f00000000000000000000000091293f7517acb93c65ae031b7809be2fbc5ffbea81565b6104616108cd366004614c6d565b60008281526008602090815260408083206001600160a01b038516845260090190915290205492915050565b61096d610907366004614b06565b60086020819052600091825260409091208054600182015460028301546003840154600485015460058601546006870154600788015497909801546001600160a01b03968716989587169794969395929491939092169160ff808216916101009004168a565b604080516001600160a01b039b8c168152998b1660208b01528901979097526060880195909552608087019390935260a086019190915290941660c084015260e083019390935291151561010082015290151561012082015261014001610305565b6102ee6109dd366004614bcf565b6127fc565b6104616109f0366004614bcf565b612872565b610359600080516020614ff383398151915281565b610a126129de565b610a328173dac17f958d2ee523a2206206994597c13d831ec76000610d93565b610a3c6001600655565b50565b606060038054610a4e90614cf6565b80601f0160208091040260200160405190810160405280929190818152602001828054610a7a90614cf6565b8015610ac75780601f10610a9c57610100808354040283529160200191610ac7565b820191906000526020600020905b815481529060010190602001808311610aaa57829003601f168201915b5050505050905090565b600033610adf818585612a37565b60019150505b92915050565b610af36129de565b60008181526009602081905260409091209081015460ff16610b535760405162461bcd60e51b8152602060048201526014602482015273105d58dd1a5bdb881b9bdd08199a5b9a5cda195960621b60448201526064015b60405180910390fd5b336000908152600a82016020526040902054610ba55760405162461bcd60e51b8152602060048201526011602482015270139bc8189a59081d1bc81c995d1c9858dd607a1b6044820152606401610b4a565b60078101546001600160a01b03163303610c015760405162461bcd60e51b815260206004820152601a60248201527f43616e6e6f7420726574726163742077696e6e696e67206269640000000000006044820152606401610b4a565b336000818152600a8301602052604080822080549290556001840154905163a9059cbb60e01b815291926001600160a01b039091169163a9059cbb91610c4b918590600401614d30565b6020604051808303816000875af1158015610c6a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c8e9190614d49565b610caa5760405162461bcd60e51b8152600401610b4a90614d6b565b6040805182815260006020820152339185917f3a6992490c68488c9ee14686d0cf94768202dbb6b0ddd7a834c8723645f855ce91015b60405180910390a35050610a3c6001600655565b336001600160a01b037f00000000000000000000000091293f7517acb93c65ae031b7809be2fbc5ffbea1614610d655760405162461bcd60e51b815260206004820152601660248201527513db9b1e4814d354c8119d5b990818d85b8818d85b1b60521b6044820152606401610b4a565b610d6d612373565b565b600033610d7d858285612b5b565b610d88858585612bcf565b506001949350505050565b816001600160a01b03811673dac17f958d2ee523a2206206994597c13d831ec71480610dd557506001600160a01b038116600080516020615013833981519152145b80610dfc57506001600160a01b038116736b175474e89094c44da98b954eedeac495271d0f145b80610e2357506001600160a01b038116735f98805a4e8be255a32880fdec7f6728c6568ba0145b610e3f5760405162461bcd60e51b8152600401610b4a90614d94565b610e476129de565b33600090815260208190526040902054841115610ea25760405162461bcd60e51b8152602060048201526019602482015278496e73756666696369656e7420424f4e442062616c616e636560381b6044820152606401610b4a565b62015180821115610ef15760405162461bcd60e51b815260206004820152601960248201527841756374696f6e206475726174696f6e20746f6f206c6f6e6760381b6044820152606401610b4a565b60007f00000000000000000000000091293f7517acb93c65ae031b7809be2fbc5ffbea6001600160a01b031663cd377c536040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f51573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f759190614dc0565b9050600a610f8c670de0b6b3a7640000600b614def565b610f969190614e06565b811015610fe55760405162461bcd60e51b815260206004820181905260248201527f4352206d757374206265203e3d20312e3120666f7220726564656d7074696f6e6044820152606401610b4a565b60007f00000000000000000000000091293f7517acb93c65ae031b7809be2fbc5ffbea6001600160a01b031663624736e06040518163ffffffff1660e01b8152600401602060405180830381865afa158015611045573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110699190614dc0565b9050600081611080670de0b6b3a764000089614def565b61108a9190614e06565b604051639b51fb0d60e01b81526000600482018190529192506001600160a01b037f00000000000000000000000091293f7517acb93c65ae031b7809be2fbc5ffbea1690639b51fb0d90602401602060405180830381865afa1580156110f4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111189190614dc0565b90508181101561116a5760405162461bcd60e51b815260206004820152601f60248201527f4e6f7420656e6f756768205742474c20696e206669727374206275636b6574006044820152606401610b4a565b6111743389612d73565b600b80546000918261118583614e28565b9091555060008181526009602052604090208054336001600160a01b03199182161782556001820180549091166001600160a01b038c16179055600281018b905560038101859055600481018990554260058201819055919250906111eb908990614e41565b6006820155604080516001600160a01b038b168152602081018c9052908101899052339083907f5bff6f1baf5d51e3878a65d7bdc6423e2dd9d73731fb513ec5957f3044f5f94b9060600160405180910390a38760000361124f5761124f82612ea5565b50505050505061125f6001600655565b50505050565b61126d6129de565b611275612373565b3360009081526007602052604081206001810154600c548254929392670de0b6b3a7640000916112a491614def565b6112ae9190614e06565b6112b89190614e54565b9050600081116113005760405162461bcd60e51b81526020600482015260136024820152724e6f207265776172647320746f20636c61696d60681b6044820152606401610b4a565b600c548254670de0b6b3a76400009161131891614def565b6113229190614e06565b600183015560405181815233907f106f923f993c2149d49b4255ff723acafa1f2d94393f561d3eda32ae348f72419060200160405180910390a25050610d6d6001600655565b600033610adf81858561137b8383612348565b6113859190614e41565b612a37565b6113926129de565b60008281526009602081905260409091209081015460ff16156113c75760405162461bcd60e51b8152600401610b4a90614e67565b8060060154421061140a5760405162461bcd60e51b815260206004820152600d60248201526c105d58dd1a5bdb88195b991959609a1b6044820152606401610b4a565b8060080154821161144b5760405162461bcd60e51b815260206004820152600b60248201526a42696420746f6f206c6f7760a81b6044820152606401610b4a565b60018101546040516323b872dd60e01b81526001600160a01b03909116906323b872dd9061148190339030908790600401614e9e565b6020604051808303816000875af11580156114a0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114c49190614d49565b6114e05760405162461bcd60e51b8152600401610b4a90614d6b565b336000908152600a82016020526040902054156115a0576001810154336000818152600a840160205260409081902054905163a9059cbb60e01b81526001600160a01b039093169263a9059cbb9261153c929091600401614d30565b6020604051808303816000875af115801561155b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061157f9190614d49565b61159b5760405162461bcd60e51b8152600401610b4a90614ec2565b6115c8565b600b81018054600181018255600091825260209091200180546001600160a01b031916331790555b60078101546001600160a01b0316156116775760018101546007820154600883015460405163a9059cbb60e01b81526001600160a01b039384169363a9059cbb9361161893911691600401614d30565b6020604051808303816000875af1158015611637573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061165b9190614d49565b6116775760405162461bcd60e51b8152600401610b4a90614ec2565b336000818152600a83016020526040908190208490556007830180546001600160a01b03191683179055600883018490555184907f7d977ef231d95a4fcabaadda7f9307c9827a35b7676f31e7d7fd8ba03e2541d5906116da9086815260200190565b60405180910390a3506116ed6001600655565b5050565b6116f96129de565b610a3281612ea5565b61170a6129de565b600081116117655760405162461bcd60e51b815260206004820152602260248201527f426f6e6420616d6f756e74206d7573742062652067726561746572207468616e604482015261020360f41b6064820152608401610b4a565b336000908152602081905260409020548111156117c05760405162461bcd60e51b8152602060048201526019602482015278496e73756666696369656e7420424f4e442062616c616e636560381b6044820152606401610b4a565b6117c8612373565b33600090815260076020526040902080548211156118285760405162461bcd60e51b815260206004820152601d60248201527f496e73756666696369656e74207573657220626f6e6420616d6f756e740000006044820152606401610b4a565b600061183333612872565b9050828260000160008282546118499190614e54565b9091555050600c548254670de0b6b3a76400009161186691614def565b6118709190614e06565b600183015561187f3384612d73565b600061188b8285614e41565b6040516303893b3760e21b81529091506001600160a01b037f00000000000000000000000091293f7517acb93c65ae031b7809be2fbc5ffbea1690630e24ecdc906118dc9033908590600401614d30565b600060405180830381600087803b1580156118f657600080fd5b505af115801561190a573d6000803e3d6000fd5b50505050505050610a3c6001600655565b6119236131b6565b610d6d6000613210565b606060048054610a4e90614cf6565b600c54600d546000919042118015611955575060025415155b15611a50576000600d544261196a9190614e54565b905060007f00000000000000000000000091293f7517acb93c65ae031b7809be2fbc5ffbea6001600160a01b031663962ca4966040518163ffffffff1660e01b8152600401602060405180830381865afa1580156119cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119f09190614dc0565b90506000611a036301e133806064614def565b8383611a0e60025490565b611a189190614def565b611a229190614def565b611a2c9190614e06565b9050611a40670de0b6b3a764000082614def565b611a4a9085614e41565b93505050505b611a62670de0b6b3a764000082614e06565b91505090565b611a706129de565b60008181526008602081905260409091209081015460ff16611acb5760405162461bcd60e51b8152602060048201526014602482015273105d58dd1a5bdb881b9bdd08199a5b9a5cda195960621b6044820152606401610b4a565b336000908152600982016020526040902054611b1d5760405162461bcd60e51b8152602060048201526011602482015270139bc8189a59081d1bc81c995d1c9858dd607a1b6044820152606401610b4a565b60068101546001600160a01b03163303611b795760405162461bcd60e51b815260206004820152601a60248201527f43616e6e6f7420726574726163742077696e6e696e67206269640000000000006044820152606401610b4a565b33600081815260098301602052604080822080549290555163a9059cbb60e01b81529091600080516020614fd38339815191529163a9059cbb91611bc1918590600401614d30565b6020604051808303816000875af1158015611be0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c049190614d49565b611c205760405162461bcd60e51b8152600401610b4a90614d6b565b6040805182815260016020820152339185917f3a6992490c68488c9ee14686d0cf94768202dbb6b0ddd7a834c8723645f855ce9101610ce0565b60003381611c688286612348565b905083811015611cc85760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610b4a565b610d888286868403612a37565b816001600160a01b03811673dac17f958d2ee523a2206206994597c13d831ec71480611d1757506001600160a01b038116600080516020615013833981519152145b80611d3e57506001600160a01b038116736b175474e89094c44da98b954eedeac495271d0f145b80611d6557506001600160a01b038116735f98805a4e8be255a32880fdec7f6728c6568ba0145b611d815760405162461bcd60e51b8152600401610b4a90614d94565b611d896129de565b611d9583836000612086565b611d9f6001600655565b505050565b600033610adf818585612bcf565b611dba6129de565b610a3281613262565b611dcb6129de565b60008111611e1b5760405162461bcd60e51b815260206004820152601d60248201527f416d6f756e74206d7573742062652067726561746572207468616e20300000006044820152606401610b4a565b6040516323b872dd60e01b8152600080516020614fd3833981519152906323b872dd90611e709033907f00000000000000000000000091293f7517acb93c65ae031b7809be2fbc5ffbea908690600401614e9e565b6020604051808303816000875af1158015611e8f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611eb39190614d49565b611ecf5760405162461bcd60e51b8152600401610b4a90614d6b565b611ed7612373565b336000908152600760205260409020805415611f475760008160010154670de0b6b3a7640000600c548460000154611f0f9190614def565b611f199190614e06565b611f239190614e54565b90508015611f455780826001016000828254611f3f9190614e41565b90915550505b505b60007f00000000000000000000000091293f7517acb93c65ae031b7809be2fbc5ffbea6001600160a01b031663624736e06040518163ffffffff1660e01b8152600401602060405180830381865afa158015611fa7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fcb9190614dc0565b90506000670de0b6b3a7640000611fe28386614def565b611fec9190614e06565b9050808360000160008282546120029190614e41565b9091555050600c548354670de0b6b3a76400009161201f91614def565b6120299190614e06565b600184015542600284015561203e33826134d8565b604080518581526020810183905233917f90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a15910160405180910390a2505050610a3c6001600655565b826001600160a01b03811673dac17f958d2ee523a2206206994597c13d831ec714806120c857506001600160a01b038116600080516020615013833981519152145b806120ef57506001600160a01b038116736b175474e89094c44da98b954eedeac495271d0f145b8061211657506001600160a01b038116735f98805a4e8be255a32880fdec7f6728c6568ba0145b6121325760405162461bcd60e51b8152600401610b4a90614d94565b61213a6129de565b6000831161218a5760405162461bcd60e51b815260206004820152601d60248201527f416d6f756e74206d7573742062652067726561746572207468616e20300000006044820152606401610b4a565b620151808211156121d95760405162461bcd60e51b815260206004820152601960248201527841756374696f6e206475726174696f6e20746f6f206c6f6e6760381b6044820152606401610b4a565b6040516323b872dd60e01b81526001600160a01b038516906323b872dd9061220990339030908890600401614e9e565b6020604051808303816000875af1158015612228573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061224c9190614d49565b6122685760405162461bcd60e51b8152600401610b4a90614d6b565b600a80546000918261227983614e28565b9091555060008181526008602052604090208054336001600160a01b03199182161782556001820180549091166001600160a01b03891617905560028101869055600381018590554260048201819055919250906122d8908590614e41565b6005820155604080516001600160a01b038816815260208101879052908101859052339083907f0e04d5f86ccad2d272fee1b1c7fd6224cf3ec4e4dac90c9d184b15ad846b8abf9060600160405180910390a38360000361233c5761233c82613262565b505061125f6001600655565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b600d54421161237e57565b600061238960025490565b90508060000361239a575042600d55565b6000600d54426123aa9190614e54565b905060007f00000000000000000000000091293f7517acb93c65ae031b7809be2fbc5ffbea6001600160a01b031663962ca4966040518163ffffffff1660e01b8152600401602060405180830381865afa15801561240c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124309190614dc0565b905060006124436301e133806064614def565b8361244e8487614def565b6124589190614def565b6124629190614e06565b90506000612478670de0b6b3a764000083614def565b90506124848582614e06565b905080600c60008282546124989190614e41565b909155505042600d555050505050565b6124b06129de565b60008281526008602081905260409091209081015460ff16156124e55760405162461bcd60e51b8152600401610b4a90614e67565b806005015442106125285760405162461bcd60e51b815260206004820152600d60248201526c105d58dd1a5bdb88195b991959609a1b6044820152606401610b4a565b806007015482116125695760405162461bcd60e51b815260206004820152600b60248201526a42696420746f6f206c6f7760a81b6044820152606401610b4a565b6040516323b872dd60e01b8152600080516020614fd3833981519152906323b872dd9061259e90339030908790600401614e9e565b6020604051808303816000875af11580156125bd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125e19190614d49565b6125fd5760405162461bcd60e51b8152600401610b4a90614d6b565b336000908152600982016020526040902054156126ba573360008181526009830160205260409081902054905163a9059cbb60e01b8152600080516020614fd38339815191529263a9059cbb9261265692600401614d30565b6020604051808303816000875af1158015612675573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126999190614d49565b6126b55760405162461bcd60e51b8152600401610b4a90614ec2565b6126e2565b600a81018054600181018255600091825260209091200180546001600160a01b031916331790555b60068101546001600160a01b031615612799576006810154600782015460405163a9059cbb60e01b8152600080516020614fd38339815191529263a9059cbb9261273a926001600160a01b0390921691600401614d30565b6020604051808303816000875af1158015612759573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061277d9190614d49565b6127995760405162461bcd60e51b8152600401610b4a90614ec2565b336000818152600983016020526040908190208490556006830180546001600160a01b03191683179055600783018490555184907f0be3d3df04290fc44ea265b01853dfde0fc87f50fd1a652db4a0489217a96797906116da9086815260200190565b6128046131b6565b6001600160a01b0381166128695760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610b4a565b610a3c81613210565b6001600160a01b0381166000908152600760205260408120600c548261289760025490565b9050600d54421180156128a957508015155b156129a5576000600d54426128be9190614e54565b905060007f00000000000000000000000091293f7517acb93c65ae031b7809be2fbc5ffbea6001600160a01b031663962ca4966040518163ffffffff1660e01b8152600401602060405180830381865afa158015612920573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129449190614dc0565b905060006129576301e133806064614def565b836129628487614def565b61296c9190614def565b6129769190614e06565b90508361298b670de0b6b3a764000083614def565b6129959190614e06565b61299f9086614e41565b94505050505b60018301548354670de0b6b3a7640000906129c1908590614def565b6129cb9190614e06565b6129d59190614e54565b95945050505050565b600260065403612a305760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610b4a565b6002600655565b6001600160a01b038316612a995760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610b4a565b6001600160a01b038216612afa5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610b4a565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6000612b678484612348565b9050600019811461125f5781811015612bc25760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610b4a565b61125f8484848403612a37565b6001600160a01b038316612c335760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610b4a565b6001600160a01b038216612c955760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610b4a565b6001600160a01b03831660009081526020819052604090205481811015612d0d5760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610b4a565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a361125f565b6001600160a01b038216612dd35760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610b4a565b6001600160a01b03821660009081526020819052604090205481811015612e475760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610b4a565b6001600160a01b0383166000818152602081815260408083208686039055600280548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b60008181526009602081905260409091209081015460ff1615612eda5760405162461bcd60e51b8152600401610b4a90614e67565b8060060154421015612f225760405162461bcd60e51b8152602060048201526011602482015270105d58dd1a5bdb881b9bdd08195b991959607a1b6044820152606401610b4a565b60098101805460ff19166001179055600781015460009081906001600160a01b0316156130b45750506008810154600782015460038301546040516323b872dd60e01b81526001600160a01b0390921691600080516020614fd3833981519152916323b872dd91612fba917f00000000000000000000000091293f7517acb93c65ae031b7809be2fbc5ffbea91869190600401614e9e565b6020604051808303816000875af1158015612fd9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ffd9190614d49565b6130195760405162461bcd60e51b8152600401610b4a90614d6b565b6001830154835460405163a9059cbb60e01b81526001600160a01b039283169263a9059cbb92613050929116908690600401614d30565b6020604051808303816000875af115801561306f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130939190614d49565b6130af5760405162461bcd60e51b8152600401610b4a90614d6b565b61316c565b600383015460018401546130d191906001600160a01b0316613597565b6001840154845460405163a9059cbb60e01b81529294503093506001600160a01b039182169263a9059cbb9261310d9216908690600401614d30565b6020604051808303816000875af115801561312c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131509190614d49565b61316c5760405162461bcd60e51b8152600401610b4a90614d6b565b806001600160a01b0316847fe36680f2e79c825d5c50f07e3e276f2b5a02902f8e290e09b89c183dc730e75d846040516131a891815260200190565b60405180910390a350505050565b6005546001600160a01b03163314610d6d5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610b4a565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60008181526008602081905260409091209081015460ff16156132975760405162461bcd60e51b8152600401610b4a90614e67565b80600501544210156132df5760405162461bcd60e51b8152602060048201526011602482015270105d58dd1a5bdb881b9bdd08195b991959607a1b6044820152606401610b4a565b60088101805460ff19166001179055600681015460009081906001600160a01b031615613464575050600781015460068201546001830154600284015460405163a9059cbb60e01b81526001600160a01b03938416939092169163a9059cbb9161334e91859190600401614d30565b6020604051808303816000875af115801561336d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133919190614d49565b6133ad5760405162461bcd60e51b8152600401610b4a90614d6b565b60405163a9059cbb60e01b8152600080516020614fd38339815191529063a9059cbb90613400907f00000000000000000000000091293f7517acb93c65ae031b7809be2fbc5ffbea908690600401614d30565b6020604051808303816000875af115801561341f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134439190614d49565b61345f5760405162461bcd60e51b8152600401610b4a90614d6b565b613487565b60018301546002840154613481916001600160a01b031690613e7b565b91503090505b825461349c906001600160a01b031683614615565b806001600160a01b0316847fe8fa982fde4cda98d5df9026b3087d27e753ac19df18ba4b49b8bd75060807e0846040516131a891815260200190565b6001600160a01b03821661352e5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610b4a565b80600260008282546135409190614e41565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b6040516323b872dd60e01b8152600090600080516020614fd3833981519152906323b872dd906135ef907f00000000000000000000000091293f7517acb93c65ae031b7809be2fbc5ffbea9030908890600401614e9e565b6020604051808303816000875af115801561360e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136329190614d49565b61364e5760405162461bcd60e51b8152600401610b4a90614d6b565b604051636eb1769f60e11b8152600090600080516020614fd38339815191529063dd62ed3e90613692903090600080516020614ff383398151915290600401614ee9565b602060405180830381865afa1580156136af573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136d39190614dc0565b90508381101561371457600019613712600080516020614ff38339815191526136fc8484614e54565b600080516020614fd383398151915291906147d3565b505b6001600160a01b03831673dac17f958d2ee523a2206206994597c13d831ec7148061375557506001600160a01b038316600080516020615013833981519152145b156139e6576040805160a0810190915260009080613795600080516020614fd38339815191526064600080516020614fb383398151915260c08501614f03565b60408051601f19818403018152918152908252306020830152428282015260608201889052600060809092018290525163c04b8d5960e01b815291925090600080516020614ff38339815191529063c04b8d59906137f7908590600401614f3e565b6020604051808303816000875af1158015613816573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061383a9190614dc0565b604051636eb1769f60e11b8152909150600080516020614fb38339815191529063dd62ed3e9061387e903090600080516020614ff383398151915290600401614ee9565b602060405180830381865afa15801561389b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138bf9190614dc0565b925080831015613900576000196138fe600080516020614ff38339815191526138e88684614e54565b600080516020614fb383398151915291906147d3565b505b6040805160a081019091528061392a600080516020614fb383398151915260648960c08501614f03565b6040516020818303038152906040528152602001306001600160a01b0316815260200142815260200182815260200160008152509150600080516020614ff38339815191526001600160a01b031663c04b8d59836040518263ffffffff1660e01b815260040161399a9190614f3e565b6020604051808303816000875af11580156139b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139dd9190614dc0565b93505050613e74565b6001600160a01b038316735f98805a4e8be255a32880fdec7f6728c6568ba01480613a2d57506001600160a01b038316736b175474e89094c44da98b954eedeac495271d0f145b15613e74576040805160a0810190915260009080613a6d600080516020614fd38339815191526064600080516020614fb383398151915260c08501614f03565b60408051601f19818403018152918152908252306020830152428282015260608201889052600060809092018290525163c04b8d5960e01b815291925090600080516020614ff38339815191529063c04b8d5990613acf908590600401614f3e565b6020604051808303816000875af1158015613aee573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b129190614dc0565b604051636eb1769f60e11b8152909150600080516020614fb38339815191529063dd62ed3e90613b56903090600080516020614ff383398151915290600401614ee9565b602060405180830381865afa158015613b73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b979190614dc0565b925080831015613bc257600019613bc0600080516020614ff38339815191526138e88684614e54565b505b6040805160a0810190915280613bfa600080516020614fb3833981519152606460008051602061501383398151915260c08501614f03565b60408051601f19818403018152918152908252306020830152428282015260608201849052600060809092018290525163c04b8d5960e01b815291935090600080516020614ff38339815191529063c04b8d5990613c5c908690600401614f3e565b6020604051808303816000875af1158015613c7b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c9f9190614dc0565b604051636eb1769f60e11b81529091506000805160206150138339815191529063dd62ed3e90613ce3903090600080516020614ff383398151915290600401614ee9565b602060405180830381865afa158015613d00573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d249190614dc0565b935080841015613d6557600019613d63600080516020614ff3833981519152613d4d8784614e54565b60008051602061501383398151915291906147d3565b505b6064735f98805a4e8be255a32880fdec7f6728c6568b9f196001600160a01b03881601613d9157506101f45b6040805160a0810190915280613dba600080516020615013833981519152848b60c08501614f03565b6040516020818303038152906040528152602001306001600160a01b0316815260200142815260200183815260200160008152509350600080516020614ff38339815191526001600160a01b031663c04b8d59856040518263ffffffff1660e01b8152600401613e2a9190614f3e565b6020604051808303816000875af1158015613e49573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613e6d9190614dc0565b9550505050505b5092915050565b600080836001600160a01b031663dd62ed3e30600080516020614ff38339815191526040518363ffffffff1660e01b8152600401613eba929190614ee9565b602060405180830381865afa158015613ed7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613efb9190614dc0565b905082811015613f3757600019613f35600080516020614ff3833981519152613f248484614e54565b6001600160a01b03881691906147d3565b505b6001600160a01b03841673dac17f958d2ee523a2206206994597c13d831ec71480613f7857506001600160a01b038416600080516020615013833981519152145b156141c7576040805160a0810190915260009080613faa876064600080516020614fb383398151915260c08501614f03565b60408051601f19818403018152918152908252306020830152428282015260608201879052600060809092018290525163c04b8d5960e01b815291925090600080516020614ff38339815191529063c04b8d599061400c908590600401614f3e565b6020604051808303816000875af115801561402b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061404f9190614dc0565b604051636eb1769f60e11b8152909150600080516020614fb38339815191529063dd62ed3e90614093903090600080516020614ff383398151915290600401614ee9565b602060405180830381865afa1580156140b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140d49190614dc0565b9250808310156140ff576000196140fd600080516020614ff38339815191526138e88684614e54565b505b6040805160a0810190915280614137600080516020614fb38339815191526064600080516020614fd383398151915260c08501614f03565b60405160208183030381529060405281526020017f00000000000000000000000091293f7517acb93c65ae031b7809be2fbc5ffbea6001600160a01b0316815260200142815260200182815260200160008152509150600080516020614ff38339815191526001600160a01b031663c04b8d59836040518263ffffffff1660e01b815260040161399a9190614f3e565b6001600160a01b038416735f98805a4e8be255a32880fdec7f6728c6568ba0148061420e57506001600160a01b038416736b175474e89094c44da98b954eedeac495271d0f145b15613e74576064735f98805a4e8be255a32880fdec7f6728c6568b9f196001600160a01b0386160161423f57506101f45b6040805160a081019091526000908061426b888560008051602061501383398151915260c08501614f03565b60408051601f19818403018152918152908252306020830152428282015260608201889052600060809092018290525163c04b8d5960e01b815291925090600080516020614ff38339815191529063c04b8d59906142cd908590600401614f3e565b6020604051808303816000875af11580156142ec573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143109190614dc0565b604051636eb1769f60e11b81529091506000805160206150138339815191529063dd62ed3e90614354903090600080516020614ff383398151915290600401614ee9565b602060405180830381865afa158015614371573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143959190614dc0565b9350808410156143c0576000196143be600080516020614ff3833981519152613d4d8784614e54565b505b6040805160a08101909152806143f86000805160206150138339815191526064600080516020614fb383398151915260c08501614f03565b60408051601f19818403018152918152908252306020830152428282015260608201849052600060809092018290525163c04b8d5960e01b815291935090600080516020614ff38339815191529063c04b8d599061445a908690600401614f3e565b6020604051808303816000875af1158015614479573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061449d9190614dc0565b604051636eb1769f60e11b8152909150600080516020614fb38339815191529063dd62ed3e906144e1903090600080516020614ff383398151915290600401614ee9565b602060405180830381865afa1580156144fe573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145229190614dc0565b94508085101561454d5760001961454b600080516020614ff38339815191526138e88884614e54565b505b6040805160a0810190915280614585600080516020614fb38339815191526064600080516020614fd383398151915260c08501614f03565b60405160208183030381529060405281526020017f00000000000000000000000091293f7517acb93c65ae031b7809be2fbc5ffbea6001600160a01b0316815260200142815260200182815260200160008152509250600080516020614ff38339815191526001600160a01b031663c04b8d59846040518263ffffffff1660e01b8152600401613e2a9190614f3e565b61461d612373565b6001600160a01b03821660009081526007602052604090208054156146965760008160010154670de0b6b3a7640000600c54846000015461465e9190614def565b6146689190614e06565b6146729190614e54565b90508015614694578082600101600082825461468e9190614e41565b90915550505b505b60007f00000000000000000000000091293f7517acb93c65ae031b7809be2fbc5ffbea6001600160a01b031663cd377c536040518163ffffffff1660e01b8152600401602060405180830381865afa1580156146f6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061471a9190614dc0565b61472c84670de0b6b3a7640000614def565b6147369190614e06565b90508082600001600082825461474c9190614e41565b9091555050600c548254670de0b6b3a76400009161476991614def565b6147739190614e06565b600183015542600283015561478884826134d8565b6040805160008152602081018390526001600160a01b038616917f90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a15910160405180910390a250505050565b604051636eb1769f60e11b81526000906001600160a01b0385169063dd62ed3e906148049030908790600401614ee9565b602060405180830381865afa158015614821573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906148459190614dc0565b905061125f8463095ea7b360e01b8561485e8686614e41565b60405160240161486f929190614d30565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915260006148f6826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166149769092919063ffffffff16565b90508051600014806149175750808060200190518101906149179190614d49565b611d9f5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610b4a565b6060614985848460008561498d565b949350505050565b6060824710156149ee5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610b4a565b600080866001600160a01b03168587604051614a0a9190614f96565b60006040518083038185875af1925050503d8060008114614a47576040519150601f19603f3d011682016040523d82523d6000602084013e614a4c565b606091505b5091509150614a5d87838387614a68565b979650505050505050565b60608315614ad7578251600003614ad0576001600160a01b0385163b614ad05760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610b4a565b5081614985565b6149858383815115614aec5781518083602001fd5b8060405162461bcd60e51b8152600401610b4a9190614b6f565b600060208284031215614b1857600080fd5b5035919050565b60005b83811015614b3a578181015183820152602001614b22565b50506000910152565b60008151808452614b5b816020860160208601614b1f565b601f01601f19169290920160200192915050565b602081526000614b826020830184614b43565b9392505050565b80356001600160a01b0381168114614ba057600080fd5b919050565b60008060408385031215614bb857600080fd5b614bc183614b89565b946020939093013593505050565b600060208284031215614be157600080fd5b614b8282614b89565b600080600060608486031215614bff57600080fd5b614c0884614b89565b9250614c1660208501614b89565b9150604084013590509250925092565b600080600060608486031215614c3b57600080fd5b83359250614c1660208501614b89565b60008060408385031215614c5e57600080fd5b50508035926020909101359150565b60008060408385031215614c8057600080fd5b82359150614c9060208401614b89565b90509250929050565b600080600060608486031215614cae57600080fd5b614cb784614b89565b95602085013595506040909401359392505050565b60008060408385031215614cdf57600080fd5b614ce883614b89565b9150614c9060208401614b89565b600181811c90821680614d0a57607f821691505b602082108103614d2a57634e487b7160e01b600052602260045260246000fd5b50919050565b6001600160a01b03929092168252602082015260400190565b600060208284031215614d5b57600080fd5b81518015158114614b8257600080fd5b6020808252600f908201526e151c985b9cd9995c8819985a5b1959608a1b604082015260600190565b60208082526012908201527124b73b30b634b21039ba30b13632b1b7b4b760711b604082015260600190565b600060208284031215614dd257600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b8082028115828204841417610ae557610ae5614dd9565b600082614e2357634e487b7160e01b600052601260045260246000fd5b500490565b600060018201614e3a57614e3a614dd9565b5060010190565b80820180821115610ae557610ae5614dd9565b81810381811115610ae557610ae5614dd9565b60208082526018908201527f41756374696f6e20616c72656164792066696e69736865640000000000000000604082015260600190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6020808252600d908201526c14995d1d5c9b8819985a5b1959609a1b604082015260600190565b6001600160a01b0392831681529116602082015260400190565b606093841b6bffffffffffffffffffffffff19908116825260e89390931b6001600160e81b0319166014820152921b166017820152602b0190565b602081526000825160a06020840152614f5a60c0840182614b43565b905060018060a01b0360208501511660408401526040840151606084015260608401516080840152608084015160a08401528091505092915050565b60008251614fa8818460208701614b1f565b919091019291505056fe000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000002ba64efb7a4ec8983e22a49c81fa216ac33f383a000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48a26469706673582212201e63b9a3691d8313d6c947602bcf9565c30be7b5268de896ef85dc648b37c98064736f6c63430008140033

Verified Source Code Full Match

Compiler: v0.8.20+commit.a1b79de6 EVM: paris Optimization: Yes (200 runs)
Ownable.sol 83 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

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

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

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

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

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
ReentrancyGuard.sol 77 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == _ENTERED;
    }
}
ERC20.sol 365 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

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

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

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the default value returned by this function, unless
     * it's overridden.
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

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

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address to, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `amount`.
     */
    function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, amount);
        _transfer(from, to, amount);
        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, allowance(owner, spender) + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        address owner = _msgSender();
        uint256 currentAllowance = allowance(owner, spender);
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(owner, spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     */
    function _transfer(address from, address to, uint256 amount) internal virtual {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
            // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
            // decrementing then incrementing.
            _balances[to] += amount;
        }

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        unchecked {
            // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
            _balances[account] += amount;
        }
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
            // Overflow not possible: amount <= accountBalance <= totalSupply.
            _totalSupply -= amount;
        }

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(address owner, address spender, uint256 amount) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
}
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);
}
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

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

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}
IERC20.sol 78 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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);
}
SafeERC20.sol 143 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";

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

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return
            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
    }
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [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://consensys.net/diligence/blog/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.8.0/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 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (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;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
IUniswapV3SwapCallback.sol 21 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Callback for IUniswapV3PoolActions#swap
/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface
interface IUniswapV3SwapCallback {
    /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.
    /// @dev In the implementation you must pay the pool tokens owed for the swap.
    /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.
    /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
    /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
    /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
    /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
    function uniswapV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata data
    ) external;
}
ISwapRouter.sol 67 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

import '@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol';

/// @title Router token swapping functionality
/// @notice Functions for swapping tokens via Uniswap V3
interface ISwapRouter is IUniswapV3SwapCallback {
    struct ExactInputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);

    struct ExactInputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);

    struct ExactOutputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);

    struct ExactOutputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
}
BondToken.sol 762 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";

import "./interfaces/IUniswapV3Pool.sol";

interface ISMSFund {
    function getWBGLPrice() external view returns (uint256);
    function getCurrentAPY() external view returns (uint256);
    function getCollateralRatio() external view returns (uint256);
    function buckets(uint256 index) external view returns (uint256);
    function accumulatedDebt() external view returns (uint256);
    function mintSMSFromBond(address user, uint256 USDamount) external;
}

contract BondToken is ERC20, Ownable, ReentrancyGuard {
    using SafeERC20 for IERC20;

    ISMSFund public immutable smsFund;
    
    // Token addresses from SMSFund
    address public constant WBGL = 0x2bA64EFB7A4Ec8983E22A49c81fa216AC33f383A;
    address public constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
    address public constant LUSD = 0x5f98805A4E8be255a32880FDeC7F6728C6568bA0;
    address public constant USDT = 0xdAC17F958D2ee523a2206206994597C13D831ec7;
    address public constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
    address public constant DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
    
    ISwapRouter public constant router = ISwapRouter(0xE592427A0AEce92De3Edee1F18E0157C05861564);
    
    struct UserInfo {
        uint256 amount;
        uint256 rewardDebt;
        uint256 lastUpdateTime;
    }
    
    struct DepositAuction {
        address depositor;
        address stablecoin;
        uint256 stablecoinAmount;
        uint256 auctionDuration;
        uint256 startTime;
        uint256 endTime;
        address bestBidder;
        uint256 bestBidAmount; // WBGL amount
        bool finished;
        bool executed;
        mapping(address => uint256) bids;
        address[] bidders;
    }
    
    struct RedeemAuction {
        address redeemer;
        address stablecoin;
        uint256 bondAmount;
        uint256 wbglAmount;
        uint256 auctionDuration;
        uint256 startTime;
        uint256 endTime;
        address bestBidder;
        uint256 bestBidAmount; // Stablecoin amount
        bool finished;
        bool executed;
        mapping(address => uint256) bids;
        address[] bidders;
    }
    
    mapping(address => UserInfo) public userInfo;
    mapping(uint256 => DepositAuction) public depositAuctions;
    mapping(uint256 => RedeemAuction) public redeemAuctions;
    
    uint256 public nextDepositAuctionId;
    uint256 public nextRedeemAuctionId;
    
    uint256 public accRewardPerShare;
    uint256 public lastRewardTime;
    
    uint256 private constant PRECISION = 1e18;
    uint256 private constant YEAR_SECONDS = 365 days;
    uint256 private constant MAX_AUCTION_DURATION = 24 hours;
    uint256 private constant USDC_PRECISION = 1e6;
    
    event Deposit(address indexed user, uint256 wbglAmount, uint256 bondAmount);
    event Withdraw(address indexed user, uint256 bondAmount, uint256 wbglAmount);
    event RewardClaimed(address indexed user, uint256 amount);
    event DepositAuctionCreated(uint256 indexed auctionId, address indexed depositor, address stablecoin, uint256 amount, uint256 duration);
    event DepositAuctionBid(uint256 indexed auctionId, address indexed bidder, uint256 wbglAmount);
    event DepositAuctionFinished(uint256 indexed auctionId, address indexed winner, uint256 wbglAmount);
    event RedeemAuctionCreated(uint256 indexed auctionId, address indexed redeemer, address stablecoin, uint256 bondAmount, uint256 duration);
    event RedeemAuctionBid(uint256 indexed auctionId, address indexed bidder, uint256 stablecoinAmount);
    event RedeemAuctionFinished(uint256 indexed auctionId, address indexed winner, uint256 stablecoinAmount);
    event BidRetracted(uint256 indexed auctionId, address indexed bidder, uint256 amount, bool isDeposit);
    
    constructor(address _smsFund) ERC20("Bond Token", "BOND") {
        smsFund = ISMSFund(_smsFund);
        lastRewardTime = block.timestamp;
    }
    
    modifier onlySMSFund() {
        require(msg.sender == address(smsFund), "Only SMS Fund can call");
        _;
    }
    
    modifier validStablecoin(address stablecoin) {
        require(
            stablecoin == USDT || 
            stablecoin == USDC || 
            stablecoin == DAI || 
            stablecoin == LUSD, 
            "Invalid stablecoin"
        );
        _;
    }
    
    function updatePool() public {
        if (block.timestamp <= lastRewardTime) {
            return;
        }
        
        uint256 bondSupply = totalSupply();
        if (bondSupply == 0) {
            lastRewardTime = block.timestamp;
            return;
        }
        
        uint256 timeElapsed = block.timestamp - lastRewardTime;
        uint256 apy = smsFund.getCurrentAPY();
        uint256 reward = (bondSupply * apy * timeElapsed) / (100 * YEAR_SECONDS);
        
        uint256 increment = (reward * PRECISION);
        increment = increment / bondSupply;
        accRewardPerShare += increment;
        lastRewardTime = block.timestamp;
    }
    
    function pendingReward(address _user) public view returns (uint256) {
        UserInfo storage user = userInfo[_user];
        uint256 _accRewardPerShare = accRewardPerShare;
        
        uint256 bondSupply = totalSupply();
        if (block.timestamp > lastRewardTime && bondSupply != 0) {
            uint256 timeElapsed = block.timestamp - lastRewardTime;
            uint256 apy = smsFund.getCurrentAPY();
            uint256 reward = (bondSupply * apy * timeElapsed) / (100 * YEAR_SECONDS);
            _accRewardPerShare += (reward * PRECISION) / bondSupply;
        }
        
        return (user.amount * _accRewardPerShare) / PRECISION - user.rewardDebt;
    }
    
    function pendingTotalRewards() external view returns (uint256) {
        uint256 _accRewardPerShare = accRewardPerShare;
        
        if (block.timestamp > lastRewardTime && totalSupply() != 0) {
            uint256 timeElapsed = block.timestamp - lastRewardTime;
            uint256 apy = smsFund.getCurrentAPY();
            uint256 reward = (totalSupply() * apy * timeElapsed) / (100 * YEAR_SECONDS);
            _accRewardPerShare += (reward * PRECISION);
        }
        
        return (_accRewardPerShare) / PRECISION;
    }

    function burnBondForSMS(uint256 bondAmount) external nonReentrant {
        require(bondAmount > 0, "Bond amount must be greater than 0");
        require(balanceOf(msg.sender) >= bondAmount, "Insufficient BOND balance");
        
        updatePool();
        
        UserInfo storage user = userInfo[msg.sender];
        require(user.amount >= bondAmount, "Insufficient user bond amount");
        
        // Calculate pending rewards for the amount being burned
        uint256 pendingRewardsForBurn = pendingReward(msg.sender);

        // Update user info before burning
        user.amount -= bondAmount;
        user.rewardDebt = (user.amount * accRewardPerShare) / PRECISION;
        
        // Burn the BOND tokens
        _burn(msg.sender, bondAmount);
        
        uint256 valueInUSD = (bondAmount + pendingRewardsForBurn);

        // Call SMS Fund to mint SMS tokens
        smsFund.mintSMSFromBond(msg.sender, valueInUSD);
    }
    
    function depositWBGL(uint256 amount) external nonReentrant {
        require(amount > 0, "Amount must be greater than 0");
        
        require(IERC20(WBGL).transferFrom(msg.sender, address(smsFund), amount), "Transfer failed");
        
        updatePool();
        
        UserInfo storage user = userInfo[msg.sender];
        
        if (user.amount > 0) {
            uint256 pending = (user.amount * accRewardPerShare) / PRECISION - user.rewardDebt;
            if (pending > 0) {
                user.rewardDebt += pending;
            }
        }
        
        uint256 wbglPrice = smsFund.getWBGLPrice();
        uint256 bondAmount = (amount * wbglPrice) / PRECISION;
        
        user.amount += bondAmount;
        user.rewardDebt = (user.amount * accRewardPerShare) / PRECISION;
        user.lastUpdateTime = block.timestamp;
        
        _mint(msg.sender, bondAmount);
        
        emit Deposit(msg.sender, amount, bondAmount);
    }
    
    function depositStablecoin(address stablecoin, uint256 amount) external validStablecoin(stablecoin) nonReentrant {
        depositStablecoinWithAuction(stablecoin, amount, 0);
    }
    
    function depositStablecoinWithAuction(address stablecoin, uint256 amount, uint256 auctionDuration) public validStablecoin(stablecoin) nonReentrant {
        require(amount > 0, "Amount must be greater than 0");
        require(auctionDuration <= MAX_AUCTION_DURATION, "Auction duration too long");
        
        require(IERC20(stablecoin).transferFrom(msg.sender, address(this), amount), "Transfer failed");
        
        uint256 auctionId = nextDepositAuctionId++;
        DepositAuction storage auction = depositAuctions[auctionId];
        
        auction.depositor = msg.sender;
        auction.stablecoin = stablecoin;
        auction.stablecoinAmount = amount;
        auction.auctionDuration = auctionDuration;
        auction.startTime = block.timestamp;
        auction.endTime = block.timestamp + auctionDuration;
        
        emit DepositAuctionCreated(auctionId, msg.sender, stablecoin, amount, auctionDuration);
        
        // If auction duration is 0, finish immediately
        if (auctionDuration == 0) {
            _finishDepositAuction(auctionId);
        }
    }
    
    function bidOnDepositAuction(uint256 auctionId, uint256 wbglAmount) external nonReentrant {
        DepositAuction storage auction = depositAuctions[auctionId];
        require(!auction.finished, "Auction already finished");
        require(block.timestamp < auction.endTime, "Auction ended");
        require(wbglAmount > auction.bestBidAmount, "Bid too low");
        
        require(IERC20(WBGL).transferFrom(msg.sender, address(this), wbglAmount), "Transfer failed");
        
        // Return previous bid if exists
        if (auction.bids[msg.sender] > 0) {
            require(IERC20(WBGL).transfer(msg.sender, auction.bids[msg.sender]), "Return failed");
        } else {
            auction.bidders.push(msg.sender);
        }
        
        // Return previous best bid
        if (auction.bestBidder != address(0)) {
            require(IERC20(WBGL).transfer(auction.bestBidder, auction.bestBidAmount), "Return failed");
        }
        
        auction.bids[msg.sender] = wbglAmount;
        auction.bestBidder = msg.sender;
        auction.bestBidAmount = wbglAmount;
        
        emit DepositAuctionBid(auctionId, msg.sender, wbglAmount);
    }
    
    function finishDepositAuction(uint256 auctionId) external nonReentrant {
        _finishDepositAuction(auctionId);
    }
    
    function _finishDepositAuction(uint256 auctionId) internal {
        DepositAuction storage auction = depositAuctions[auctionId];
        require(!auction.finished, "Auction already finished");
        require(block.timestamp >= auction.endTime, "Auction not ended");
        
        auction.finished = true;
        
        uint256 wbglAmount;
        address winner;
        
        if (auction.bestBidder != address(0)) {
            // Auction had bids
            wbglAmount = auction.bestBidAmount;
            winner = auction.bestBidder;
            
            // Transfer stablecoin to winner
            require(IERC20(auction.stablecoin).transfer(winner, auction.stablecoinAmount), "Transfer failed");
            
            // Transfer WBGL to SMS Fund
            require(IERC20(WBGL).transfer(address(smsFund), wbglAmount), "Transfer failed");
        } else {
            // No bids, execute Uniswap trade
            wbglAmount = _executeStablecoinToWBGLSwap(auction.stablecoin, auction.stablecoinAmount);
            winner = address(this); // Contract executed the trade
        }
        
        // Mint BOND tokens to depositor
        _mintBondTokens(auction.depositor, wbglAmount);
        
        emit DepositAuctionFinished(auctionId, winner, wbglAmount);
    }
    
    function redeemBond(uint256 bondAmount) external nonReentrant {
        redeemBondWithAuction(bondAmount, USDT, 0);
    }
    
    function redeemBondWithAuction(uint256 bondAmount, address stablecoin, uint256 auctionDuration) public validStablecoin(stablecoin) nonReentrant {
        require(balanceOf(msg.sender) >= bondAmount, "Insufficient BOND balance");
        require(auctionDuration <= MAX_AUCTION_DURATION, "Auction duration too long");
        
        uint256 cr = smsFund.getCollateralRatio();
        require(cr >= (11 * PRECISION) / 10, "CR must be >= 1.1 for redemption");
        
        // Calculate WBGL amount to be redeemed
        uint256 wbglPrice = smsFund.getWBGLPrice();
        uint256 wbglAmount = (bondAmount * PRECISION) / wbglPrice;
        
        // Check if first bucket has enough WBGL
        uint256 firstBucketAmount = smsFund.buckets(0);
        require(firstBucketAmount >= wbglAmount, "Not enough WBGL in first bucket");
        
        // Burn BOND tokens
        _burn(msg.sender, bondAmount);
        
        uint256 auctionId = nextRedeemAuctionId++;
        RedeemAuction storage auction = redeemAuctions[auctionId];
        
        auction.redeemer = msg.sender;
        auction.stablecoin = stablecoin;
        auction.bondAmount = bondAmount;
        auction.wbglAmount = wbglAmount;
        auction.auctionDuration = auctionDuration;
        auction.startTime = block.timestamp;
        auction.endTime = block.timestamp + auctionDuration;
        
        emit RedeemAuctionCreated(auctionId, msg.sender, stablecoin, bondAmount, auctionDuration);
        
        // If auction duration is 0, finish immediately
        if (auctionDuration == 0) {
            _finishRedeemAuction(auctionId);
        }
    }
    
    function bidOnRedeemAuction(uint256 auctionId, uint256 stablecoinAmount) external nonReentrant {
        RedeemAuction storage auction = redeemAuctions[auctionId];
        require(!auction.finished, "Auction already finished");
        require(block.timestamp < auction.endTime, "Auction ended");
        require(stablecoinAmount > auction.bestBidAmount, "Bid too low");
        
        require(IERC20(auction.stablecoin).transferFrom(msg.sender, address(this), stablecoinAmount), "Transfer failed");
        
        // Return previous bid if exists
        if (auction.bids[msg.sender] > 0) {
            require(IERC20(auction.stablecoin).transfer(msg.sender, auction.bids[msg.sender]), "Return failed");
        } else {
            auction.bidders.push(msg.sender);
        }
        
        // Return previous best bid
        if (auction.bestBidder != address(0)) {
            require(IERC20(auction.stablecoin).transfer(auction.bestBidder, auction.bestBidAmount), "Return failed");
        }
        
        auction.bids[msg.sender] = stablecoinAmount;
        auction.bestBidder = msg.sender;
        auction.bestBidAmount = stablecoinAmount;
        
        emit RedeemAuctionBid(auctionId, msg.sender, stablecoinAmount);
    }
    
    function finishRedeemAuction(uint256 auctionId) external nonReentrant {
        _finishRedeemAuction(auctionId);
    }
    
    function _finishRedeemAuction(uint256 auctionId) internal {
        RedeemAuction storage auction = redeemAuctions[auctionId];
        require(!auction.finished, "Auction already finished");
        require(block.timestamp >= auction.endTime, "Auction not ended");
        
        auction.finished = true;
        
        uint256 stablecoinAmount;
        address winner;
        
        if (auction.bestBidder != address(0)) {
            // Auction had bids
            stablecoinAmount = auction.bestBidAmount;
            winner = auction.bestBidder;
            
            // Transfer WBGL to winner (from SMS Fund first bucket)
            require(IERC20(WBGL).transferFrom(address(smsFund), winner, auction.wbglAmount), "Transfer failed");
            
            // Transfer stablecoin to redeemer
            require(IERC20(auction.stablecoin).transfer(auction.redeemer, stablecoinAmount), "Transfer failed");
        } else {
            // No bids, execute Uniswap trade
            stablecoinAmount = _executeWBGLToStablecoinSwap(auction.wbglAmount, auction.stablecoin);
            winner = address(this); // Contract executed the trade
            
            // Transfer stablecoin to redeemer
            require(IERC20(auction.stablecoin).transfer(auction.redeemer, stablecoinAmount), "Transfer failed");
        }
        
        emit RedeemAuctionFinished(auctionId, winner, stablecoinAmount);
    }
    
    function retractDepositBid(uint256 auctionId) external nonReentrant {
        DepositAuction storage auction = depositAuctions[auctionId];
        require(auction.finished, "Auction not finished");
        require(auction.bids[msg.sender] > 0, "No bid to retract");
        require(msg.sender != auction.bestBidder, "Cannot retract winning bid");
        
        uint256 bidAmount = auction.bids[msg.sender];
        auction.bids[msg.sender] = 0;
        
        require(IERC20(WBGL).transfer(msg.sender, bidAmount), "Transfer failed");
        
        emit BidRetracted(auctionId, msg.sender, bidAmount, true);
    }
    
    function retractRedeemBid(uint256 auctionId) external nonReentrant {
        RedeemAuction storage auction = redeemAuctions[auctionId];
        require(auction.finished, "Auction not finished");
        require(auction.bids[msg.sender] > 0, "No bid to retract");
        require(msg.sender != auction.bestBidder, "Cannot retract winning bid");
        
        uint256 bidAmount = auction.bids[msg.sender];
        auction.bids[msg.sender] = 0;
        
        require(IERC20(auction.stablecoin).transfer(msg.sender, bidAmount), "Transfer failed");
        
        emit BidRetracted(auctionId, msg.sender, bidAmount, false);
    }
    
    function _executeStablecoinToWBGLSwap(address stablecoin, uint256 amount) internal returns (uint256 amountOut) {
        // Swap stablecoin to WBGL using the same logic as SMSFund
        uint256 allowance = IERC20(stablecoin).allowance(address(this), address(router));
        if (allowance < amount) {
            uint256 newAllowance = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
            IERC20(stablecoin).safeIncreaseAllowance(address(router), newAllowance - allowance);
        }

        if (stablecoin == USDT || stablecoin == USDC) {
            // First swap stablecoin to WETH
            ISwapRouter.ExactInputParams memory params = ISwapRouter.ExactInputParams({
                path: abi.encodePacked(
                    stablecoin,
                    uint24(100), // 0.01% fee
                    WETH
                ),
                recipient: address(this),
                deadline: block.timestamp,
                amountIn: amount,
                amountOutMinimum: 0
            });

            uint256 wethOut = ISwapRouter(router).exactInput(params);
            
            allowance = IERC20(WETH).allowance(address(this), address(router));
            if (allowance < wethOut) {
                uint256 newAllowance = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
                IERC20(WETH).safeIncreaseAllowance(address(router), newAllowance - allowance);
            }

            // swap WETH to WBGL
            params = ISwapRouter.ExactInputParams({
                path: abi.encodePacked(
                    WETH,
                    uint24(100), // 0.01% fee
                    WBGL
                ),
                recipient: address(smsFund),
                deadline: block.timestamp,
                amountIn: wethOut,
                amountOutMinimum: 0
            });

            amountOut = ISwapRouter(router).exactInput(params);

        } else if (stablecoin == LUSD || stablecoin == DAI) {
            // First swap LUSD/DAI to USDC
            uint24 poolFee = 100;
            if (stablecoin == LUSD) {
                poolFee = 500;
            }
            ISwapRouter.ExactInputParams memory params = ISwapRouter.ExactInputParams({
                path: abi.encodePacked(
                    stablecoin,
                    poolFee,
                    USDC
                ),
                recipient: address(this),
                deadline: block.timestamp,
                amountIn: amount,
                amountOutMinimum: 0
            });

            uint256 usdcOut = ISwapRouter(router).exactInput(params);

            allowance = IERC20(USDC).allowance(address(this), address(router));
            if (allowance < usdcOut) {
                uint256 newAllowance = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
                IERC20(USDC).safeIncreaseAllowance(address(router), newAllowance - allowance);
            }

            // swap USDC to WETH
            params = ISwapRouter.ExactInputParams({
                path: abi.encodePacked(
                    USDC,
                    uint24(100), // 0.01% fee
                    WETH
                ),
                recipient: address(this),
                deadline: block.timestamp,
                amountIn: usdcOut,
                amountOutMinimum: 0
            });

            uint256 wethOut = ISwapRouter(router).exactInput(params);

            allowance = IERC20(WETH).allowance(address(this), address(router));
            if (allowance < wethOut) {
                uint256 newAllowance = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
                IERC20(WETH).safeIncreaseAllowance(address(router), newAllowance - allowance);
            }

            // swap WETH to WBGL
            params = ISwapRouter.ExactInputParams({
                path: abi.encodePacked(
                    WETH,
                    uint24(100), // 0.01% fee
                    WBGL
                ),
                recipient: address(smsFund),
                deadline: block.timestamp,
                amountIn: wethOut,
                amountOutMinimum: 0
            });

            amountOut = ISwapRouter(router).exactInput(params);
        }
    }
    
    function _executeWBGLToStablecoinSwap(uint256 wbglAmount, address stablecoin) internal returns (uint256 amountOut) {
        // Get WBGL from SMS Fund first bucket
        require(IERC20(WBGL).transferFrom(address(smsFund), address(this), wbglAmount), "Transfer failed");
        
        uint256 allowance = IERC20(WBGL).allowance(address(this), address(router));
        if (allowance < wbglAmount) {
            uint256 newAllowance = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
            IERC20(WBGL).safeIncreaseAllowance(address(router), newAllowance - allowance);
        }

        if (stablecoin == USDT || stablecoin == USDC) {
            // First swap WBGL to WETH
            ISwapRouter.ExactInputParams memory params = ISwapRouter.ExactInputParams({
                path: abi.encodePacked(
                    WBGL,
                    uint24(100), // 0.01% fee
                    WETH
                ),
                recipient: address(this),
                deadline: block.timestamp,
                amountIn: wbglAmount,
                amountOutMinimum: 0
            });

            uint256 wethOut = ISwapRouter(router).exactInput(params);
            
            allowance = IERC20(WETH).allowance(address(this), address(router));
            if (allowance < wethOut) {
                uint256 newAllowance = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
                IERC20(WETH).safeIncreaseAllowance(address(router), newAllowance - allowance);
            }

            // swap WETH to stablecoin
            params = ISwapRouter.ExactInputParams({
                path: abi.encodePacked(
                    WETH,
                    uint24(100), // 0.01% fee
                    stablecoin
                ),
                recipient: address(this),
                deadline: block.timestamp,
                amountIn: wethOut,
                amountOutMinimum: 0
            });

            amountOut = ISwapRouter(router).exactInput(params);

        } else if (stablecoin == LUSD || stablecoin == DAI) {
            // First swap WBGL to WETH
            ISwapRouter.ExactInputParams memory params = ISwapRouter.ExactInputParams({
                path: abi.encodePacked(
                    WBGL,
                    uint24(100), // 0.01% fee
                    WETH
                ),
                recipient: address(this),
                deadline: block.timestamp,
                amountIn: wbglAmount,
                amountOutMinimum: 0
            });

            uint256 wethOut = ISwapRouter(router).exactInput(params);

            allowance = IERC20(WETH).allowance(address(this), address(router));
            if (allowance < wethOut) {
                uint256 newAllowance = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
                IERC20(WETH).safeIncreaseAllowance(address(router), newAllowance - allowance);
            }

            // swap WETH to USDC
            params = ISwapRouter.ExactInputParams({
                path: abi.encodePacked(
                    WETH,
                    uint24(100), // 0.01% fee
                    USDC
                ),
                recipient: address(this),
                deadline: block.timestamp,
                amountIn: wethOut,
                amountOutMinimum: 0
            });

            uint256 usdcOut = ISwapRouter(router).exactInput(params);

            allowance = IERC20(USDC).allowance(address(this), address(router));
            if (allowance < usdcOut) {
                uint256 newAllowance = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
                IERC20(USDC).safeIncreaseAllowance(address(router), newAllowance - allowance);
            }

            // swap USDC to final stablecoin
            uint24 poolFee = 100;
            if (stablecoin == LUSD) {
                poolFee = 500;
            }
            params = ISwapRouter.ExactInputParams({
                path: abi.encodePacked(
                    USDC,
                    poolFee,
                    stablecoin
                ),
                recipient: address(this),
                deadline: block.timestamp,
                amountIn: usdcOut,
                amountOutMinimum: 0
            });

            amountOut = ISwapRouter(router).exactInput(params);
        }
    }
    
    function _mintBondTokens(address to, uint256 wbglAmount) internal {
        updatePool();
        
        UserInfo storage user = userInfo[to];
        
        if (user.amount > 0) {
            uint256 pending = (user.amount * accRewardPerShare) / PRECISION - user.rewardDebt;
            if (pending > 0) {
                user.rewardDebt += pending;
            }
        }
        
        uint256 bondAmount = wbglAmount * 1e18 / smsFund.getCollateralRatio(); // 1:1 for stablecoins
        
        user.amount += bondAmount;
        user.rewardDebt = (user.amount * accRewardPerShare) / PRECISION;
        user.lastUpdateTime = block.timestamp;
        
        _mint(to, bondAmount);
        
        emit Deposit(to, 0, bondAmount);
    }
    
    function claimRewards() external nonReentrant {
        updatePool();
        
        UserInfo storage user = userInfo[msg.sender];
        uint256 pending = (user.amount * accRewardPerShare) / PRECISION - user.rewardDebt;
        
        require(pending > 0, "No rewards to claim");
        
        user.rewardDebt = (user.amount * accRewardPerShare) / PRECISION;
        
        emit RewardClaimed(msg.sender, pending);
    }
        
    function updateDebt() external onlySMSFund {
        updatePool();
    }

    function getDepositAuctionInfo(uint256 auctionId) external view returns (
        address depositor,
        address stablecoin,
        uint256 stablecoinAmount,
        uint256 startTime,
        uint256 endTime,
        address bestBidder,
        uint256 bestBidAmount,
        bool finished
    ) {
        DepositAuction storage auction = depositAuctions[auctionId];
        return (
            auction.depositor,
            auction.stablecoin,
            auction.stablecoinAmount,
            auction.startTime,
            auction.endTime,
            auction.bestBidder,
            auction.bestBidAmount,
            auction.finished
        );
    }
    
    function getRedeemAuctionInfo(uint256 auctionId) external view returns (
        address redeemer,
        address stablecoin,
        uint256 bondAmount,
        uint256 wbglAmount,
        uint256 startTime,
        uint256 endTime,
        address bestBidder,
        uint256 bestBidAmount,
        bool finished
    ) {
        RedeemAuction storage auction = redeemAuctions[auctionId];
        return (
            auction.redeemer,
            auction.stablecoin,
            auction.bondAmount,
            auction.wbglAmount,
            auction.startTime,
            auction.endTime,
            auction.bestBidder,
            auction.bestBidAmount,
            auction.finished
        );
    }
    
    function getDepositAuctionBid(uint256 auctionId, address bidder) external view returns (uint256) {
        return depositAuctions[auctionId].bids[bidder];
    }
    
    function getRedeemAuctionBid(uint256 auctionId, address bidder) external view returns (uint256) {
        return redeemAuctions[auctionId].bids[bidder];
    }
}
IUniswapV3Pool.sol 53 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IUniswapV3Pool {
    function factory() external view returns (address);
    function token0() external view returns (address);
    function token1() external view returns (address);
    function fee() external view returns (uint24);
    function tickSpacing() external view returns (int24);
    function maxLiquidityPerTick() external view returns (uint128);
    
    function slot0()
        external
        view
        returns (
            uint160 sqrtPriceX96,
            int24 tick,
            uint16 observationIndex,
            uint16 observationCardinality,
            uint16 observationCardinalityNext,
            uint8 feeProtocol,
            bool unlocked
        );
        
    function liquidity() external view returns (uint128);
    
    function observe(uint32[] calldata secondsAgos)
        external
        view
        returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);
        
    function swap(
        address recipient,
        bool zeroForOne,
        int256 amountSpecified,
        uint160 sqrtPriceLimitX96,
        bytes calldata data
    ) external returns (int256 amount0, int256 amount1);
    
    function mint(
        address recipient,
        int24 tickLower,
        int24 tickUpper,
        uint128 amount,
        bytes calldata data
    ) external returns (uint256 amount0, uint256 amount1);
    
    function burn(
        int24 tickLower,
        int24 tickUpper,
        uint128 amount
    ) external returns (uint256 amount0, uint256 amount1);
} 

Read Contract

DAI 0xe0bab4c4 → address
LUSD 0xcf59d563 → address
USDC 0x89a30271 → address
USDT 0xc54e44eb → address
WBGL 0x0fd9eeeb → address
WETH 0xad5c4648 → address
accRewardPerShare 0x939d6237 → uint256
allowance 0xdd62ed3e → uint256
balanceOf 0x70a08231 → uint256
decimals 0x313ce567 → uint8
depositAuctions 0xf2e41f28 → address, address, uint256, uint256, uint256, uint256, address, uint256, bool, bool
getDepositAuctionBid 0xed5ae090 → uint256
getDepositAuctionInfo 0x70385a6c → address, address, uint256, uint256, uint256, address, uint256, bool
getRedeemAuctionBid 0xcd5ce885 → uint256
getRedeemAuctionInfo 0x5a0acd0c → address, address, uint256, uint256, uint256, uint256, address, uint256, bool
lastRewardTime 0x9231cf74 → uint256
name 0x06fdde03 → string
nextDepositAuctionId 0x64239fc0 → uint256
nextRedeemAuctionId 0xbdda7353 → uint256
owner 0x8da5cb5b → address
pendingReward 0xf40f0f52 → uint256
pendingTotalRewards 0x964b434e → uint256
redeemAuctions 0x127ff76a → address, address, uint256, uint256, uint256, uint256, uint256, address, uint256, bool, bool
router 0xf887ea40 → address
smsFund 0xe592855a → address
symbol 0x95d89b41 → string
totalSupply 0x18160ddd → uint256
userInfo 0x1959a002 → uint256, uint256, uint256

Write Contract 22 functions

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

approve 0x095ea7b3
address spender
uint256 amount
returns: bool
bidOnDepositAuction 0xe493a9a4
uint256 auctionId
uint256 wbglAmount
bidOnRedeemAuction 0x43f5d1c0
uint256 auctionId
uint256 stablecoinAmount
burnBondForSMS 0x667f2a31
uint256 bondAmount
claimRewards 0x372500ab
No parameters
decreaseAllowance 0xa457c2d7
address spender
uint256 subtractedValue
returns: bool
depositStablecoin 0xa587f4f3
address stablecoin
uint256 amount
depositStablecoinWithAuction 0xcf8afec8
address stablecoin
uint256 amount
uint256 auctionDuration
depositWBGL 0xb66dc5c3
uint256 amount
finishDepositAuction 0xb3ff0179
uint256 auctionId
finishRedeemAuction 0x4d064c6c
uint256 auctionId
increaseAllowance 0x39509351
address spender
uint256 addedValue
returns: bool
redeemBond 0x042a2077
uint256 bondAmount
redeemBondWithAuction 0x25397245
uint256 bondAmount
address stablecoin
uint256 auctionDuration
renounceOwnership 0x715018a6
No parameters
retractDepositBid 0xa39205e6
uint256 auctionId
retractRedeemBid 0x09a4f60c
uint256 auctionId
transfer 0xa9059cbb
address to
uint256 amount
returns: bool
transferFrom 0x23b872dd
address from
address to
uint256 amount
returns: bool
transferOwnership 0xf2fde38b
address newOwner
updateDebt 0x17c5da6a
No parameters
updatePool 0xe3161ddd
No parameters

Token Balances (1)

View Transfers →
USDC 2

Recent Transactions

No transactions found for this address