Address Contract Partially Verified
Address
0x7A61B7adCFD493f7CF0F86dFCECB94b72c227F22
Balance
0 ETH
Nonce
1
Code Size
15332 bytes
Creator
0x54eAde20...039e at tx 0x19b21d6c...46af2e
Indexed Transactions
0 (1 on-chain, 1.2% indexed)
Contract Bytecode
15332 bytes
0x60806040526004361061035b575f3560e01c80637ecebe00116101bd578063b56b8353116100f2578063c92aecc411610092578063d905777e1161006d578063d905777e14610ac7578063dd62ed3e14610ae6578063ef8b30f714610b1c578063fa1e2e8614610b3b575f80fd5b8063c92aecc414610a52578063ce96cb7714610a89578063d505accf14610aa8575f80fd5b8063c15bae84116100cd578063c15bae84146109cc578063c5ce281e146109e1578063c63d75b614610a14578063c6e6f59214610a33575f80fd5b8063b56b83531461096d578063ba08765214610982578063bf353dbb146109a1575f80fd5b80639f678cca1161015d578063aaf10f4211610138578063aaf10f42146108eb578063ad3cb1cc146108ff578063b3d7f6b91461092f578063b460af941461094e575f80fd5b80639f678cca146108995780639fd5a6cf146108ad578063a9059cbb146108cc575f80fd5b806394bf804d1161019857806394bf804d1461080b57806395d89b411461082a5780639b8d6d381461085b5780639c52a7f11461087a575f80fd5b80637ecebe00146107995780638129fc1c146107c457806384718d89146107d8575f80fd5b80633644e515116102935780634f1ef28611610233578063626cb3c51161020e578063626cb3c5146106fd57806365fae35e146107305780636e553f651461074f57806370a082311461076e575f80fd5b80634f1ef286146106aa57806352d1902d146106bd57806354fd4d50146106d1575f80fd5b806339b00e411161026e57806339b00e4114610606578063402d267d146106395780634cdad506146106585780634cf282fb14610677575f80fd5b80633644e5151461057557806336569e771461058957806338d52e0f146105d4575f80fd5b806320aba08b116102fe57806329ae8114116102d957806329ae8114146104e857806330adf81f14610507578063313ce5671461053a578063355274ea14610560575f80fd5b806320aba08b1461046c578063216740a0146104aa57806323b872dd146104c9575f80fd5b806309260db71161033957806309260db7146103e8578063095ea7b3146104095780630a28a4771461043857806318160ddd14610457575f80fd5b806301e1d1141461035f57806306fdde031461038657806307a2d13a146103c9575b5f80fd5b34801561036a575f80fd5b50610373610b6e565b6040519081526020015b60405180910390f35b348015610391575f80fd5b506103bc6040518060400160405280600b81526020016a5374616b6564205553445360a81b81525081565b60405161037d919061361a565b3480156103d4575f80fd5b506103736103e336600461362c565b610b7f565b3480156103f3575f80fd5b5061040761040236600461362c565b610c2b565b005b348015610414575f80fd5b5061042861042336600461365e565b610df5565b604051901515815260200161037d565b348015610443575f80fd5b5061037361045236600461362c565b610e61565b348015610462575f80fd5b5061037360015481565b348015610477575f80fd5b5060055461049290600160c01b90046001600160401b031681565b6040516001600160401b03909116815260200161037d565b3480156104b5575f80fd5b506103736104c4366004613686565b610f0c565b3480156104d4575f80fd5b506104286104e33660046136c9565b610f71565b3480156104f3575f80fd5b50610407610502366004613702565b6110fb565b348015610512575f80fd5b506103737f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b348015610545575f80fd5b5061054e601281565b60405160ff909116815260200161037d565b34801561056b575f80fd5b5061037360075481565b348015610580575f80fd5b506103736112ab565b348015610594575f80fd5b506105bc7f00000000000000000000000035d1b3f3d7966a1dfe207aa4514c12a259a0492b81565b6040516001600160a01b03909116815260200161037d565b3480156105df575f80fd5b507f000000000000000000000000dc035d45d973e3ec169d2276ddab16f1e407384f6105bc565b348015610611575f80fd5b506105bc7f000000000000000000000000836f56750517b1528b5078cba4ac4b94fbe4a39981565b348015610644575f80fd5b50610373610653366004613722565b6112b5565b348015610663575f80fd5b5061037361067236600461362c565b611391565b348015610682575f80fd5b506105bc7f000000000000000000000000dc035d45d973e3ec169d2276ddab16f1e407384f81565b6104076106b83660046137d7565b61139b565b3480156106c8575f80fd5b506103736113ba565b3480156106dc575f80fd5b506103bc604051806040016040528060018152602001603160f81b81525081565b348015610708575f80fd5b506105bc7f000000000000000000000000a950524441892a31ebddf91d3ceefa04bf45446681565b34801561073b575f80fd5b5061040761074a366004613722565b6113d6565b34801561075a575f80fd5b50610373610769366004613821565b611448565b348015610779575f80fd5b50610373610788366004613722565b60026020525f908152604090205481565b3480156107a4575f80fd5b506103736107b3366004613722565b60046020525f908152604090205481565b3480156107cf575f80fd5b5061040761147d565b3480156107e3575f80fd5b506105bc7f00000000000000000000000019c0976f590d67707e62397c87829d896dc0f1f181565b348015610816575f80fd5b50610373610825366004613821565b611715565b348015610835575f80fd5b506103bc6040518060400160405280600681526020016573745553445360d01b81525081565b348015610866575f80fd5b50610373610875366004613686565b61178d565b348015610885575f80fd5b50610407610894366004613722565b6117e3565b3480156108a4575f80fd5b50610373611854565b3480156108b8575f80fd5b506104076108c736600461384b565b611867565b3480156108d7575f80fd5b506104286108e636600461365e565b611a8a565b3480156108f6575f80fd5b506105bc611b4d565b34801561090a575f80fd5b506103bc604051806040016040528060058152602001640352e302e360dc1b81525081565b34801561093a575f80fd5b5061037361094936600461362c565b611b6c565b348015610959575f80fd5b506103736109683660046138b7565b611bf9565b348015610978575f80fd5b5061037360085481565b34801561098d575f80fd5b5061037361099c3660046138b7565b611c2d565b3480156109ac575f80fd5b506103736109bb366004613722565b5f6020819052908152604090205481565b3480156109d7575f80fd5b5061037360065481565b3480156109ec575f80fd5b506103737f4c534556322d534b592d4100000000000000000000000000000000000000000081565b348015610a1f575f80fd5b50610373610a2e366004613722565b611ca8565b348015610a3e575f80fd5b50610373610a4d36600461362c565b611d84565b348015610a5d575f80fd5b50600554610a71906001600160c01b031681565b6040516001600160c01b03909116815260200161037d565b348015610a94575f80fd5b50610373610aa3366004613722565b611e27565b348015610ab3575f80fd5b50610407610ac23660046138f0565b61213a565b348015610ad2575f80fd5b50610373610ae1366004613722565b612191565b348015610af1575f80fd5b50610373610b0036600461395d565b600360209081525f928352604080842090915290825290205481565b348015610b27575f80fd5b50610373610b3636600461362c565b6123f1565b348015610b46575f80fd5b506105bc7f0000000000000000000000003c0f895007ca717aa01c8693e59df1e8c3777feb81565b5f610b7a600154610b7f565b905090565b6005545f908190600160c01b90046001600160401b03164211610bad576005546001600160c01b0316610c02565b600554600654676765c793fa10079d601b1b916001600160c01b03811691610bee91610be990600160c01b90046001600160401b031642613999565b6123fb565b610bf891906139ac565b610c0291906139d7565b9050676765c793fa10079d601b1b610c1a82856139ac565b610c2491906139d7565b9392505050565b335f90815260208190526040902054600114610c625760405162461bcd60e51b8152600401610c59906139f6565b60405180910390fd5b5f610c6b6124e7565b90505f676765c793fa10079d601b1b82600154610c8891906139ac565b610c9291906139d7565b90505f610cb3610cad85676765c793fa10079d601b1b61273f565b8361276a565b90505f808311610cc3575f610ce2565b82610cce8382613999565b610cd890866139ac565b610ce291906139d7565b600580546001600160c01b0319166001600160c01b03929092169182179055604051633b4da69f60e01b81527f000000000000000000000000a950524441892a31ebddf91d3ceefa04bf4544666001600160a01b039081166004830152602482018590529192507f0000000000000000000000003c0f895007ca717aa01c8693e59df1e8c3777feb90911690633b4da69f906044015f604051808303815f87803b158015610d8e575f80fd5b505af1158015610da0573d5f803e3d5ffd5b50505050610dac61277f565b60408051838152602081018690529081018290527faaa7de6dcd0061e0bcd3a9bb711f1cc6d76b603c4d5cb97901525c7952076406906060015b60405180910390a15050505050565b335f8181526003602090815260408083206001600160a01b038716808552925280832085905551919290917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92590610e4f9086815260200190565b60405180910390a35060015b92915050565b6005545f908190600160c01b90046001600160401b03164211610e8f576005546001600160c01b0316610edf565b600554600654676765c793fa10079d601b1b916001600160c01b03811691610ecb91610be990600160c01b90046001600160401b031642613999565b610ed591906139ac565b610edf91906139d7565b90505f8111610eee575f610c24565b610c24610f06676765c793fa10079d601b1b856139ac565b8261273f565b5f610f178484611715565b9050826001600160a01b03168261ffff167fb30a03a0e2a407f18ae0e83491331dc069d1521e292feffb071e61c8f7f406368387604051610f62929190918252602082015260400190565b60405180910390a39392505050565b5f6001600160a01b03831615801590610f9357506001600160a01b0383163014155b610faf5760405162461bcd60e51b8152600401610c5990613a25565b6001600160a01b0384165f9081526002602052604090205482811015610fe75760405162461bcd60e51b8152600401610c5990613a55565b6001600160a01b038516331461109c576001600160a01b0385165f9081526003602090815260408083203384529091529020545f19811461109a57838110156110725760405162461bcd60e51b815260206004820152601d60248201527f5374557364732f696e73756666696369656e742d616c6c6f77616e63650000006044820152606401610c59565b6001600160a01b0386165f908152600360209081526040808320338452909152902084820390555b505b6001600160a01b038086165f8181526002602052604080822087860390559287168082529083902080548701905591515f80516020613b8f833981519152906110e89087815260200190565b60405180910390a3506001949350505050565b335f908152602081905260409020546001146111295760405162461bcd60e51b8152600401610c59906139f6565b816239ba3960e91b036111f657676765c793fa10079d601b1b81101561118a5760405162461bcd60e51b81526020600482015260166024820152755374557364732f77726f6e672d7374722d76616c756560501b6044820152606401610c59565b6005546001600160401b03600160c01b9091041642146111ec5760405162461bcd60e51b815260206004820152601960248201527f5374557364732f6368692d6e6f742d75702d746f2d64617465000000000000006044820152606401610c59565b600681905561126d565b816206361760ec1b0361120d57600781905561126d565b81636c696e6560e01b0361122557600881905561126d565b60405162461bcd60e51b815260206004820152601e60248201527f5374557364732f66696c652d756e7265636f676e697a65642d706172616d00006044820152606401610c59565b817fe986e40cc8c151830d4f61050f4fb2e4add8567caad2d5f5496f9158e91fe4c78260405161129f91815260200190565b60405180910390a25050565b5f610b7a466128d7565b6007546005545f91908290600160c01b90046001600160401b031642116112e7576005546001600160c01b0316611337565b600554600654676765c793fa10079d601b1b916001600160c01b0381169161132391610be990600160c01b90046001600160401b031642613999565b61132d91906139ac565b61133791906139d7565b9050805f0361134957505f9392505050565b5f198210156113875761137f82676765c793fa10079d601b1b8360015461137091906139ac565b61137a91906139d7565b6129ab565b949350505050565b505f199392505050565b5f610e5b82610b7f565b6113a36129bf565b6113ac82612a65565b6113b68282612a96565b5050565b5f6113c3612b57565b505f80516020613b6f8339815191525b90565b335f908152602081905260409020546001146114045760405162461bcd60e51b8152600401610c59906139f6565b6001600160a01b0381165f8181526020819052604080822060019055517fdd0e34038ac38b2a1ce960229778ac48a8719bc900b6c4f8d0475c6e8b385a609190a250565b5f6114516124e7565b611466676765c793fa10079d601b1b856139ac565b61147091906139d7565b9050610e5b838284612ba0565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff1615906001600160401b03165f811580156114c15750825b90505f826001600160401b031660011480156114dc5750303b155b9050811580156114ea575080155b156115085760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff19166001178555831561153257845460ff60401b1916600160401b1785555b61153a612d96565b676765c793fa10079d601b1b600160c01b426001600160401b03160281176005556006556040516328ec8bf160e21b81527f0000000000000000000000003c0f895007ca717aa01c8693e59df1e8c3777feb6001600160a01b0390811660048301527f00000000000000000000000035d1b3f3d7966a1dfe207aa4514c12a259a0492b169063a3b22fc4906024015f604051808303815f87803b1580156115df575f80fd5b505af11580156115f1573d5f803e3d5ffd5b505060405163095ea7b360e01b81526001600160a01b037f0000000000000000000000003c0f895007ca717aa01c8693e59df1e8c3777feb811660048301525f1960248301527f000000000000000000000000dc035d45d973e3ec169d2276ddab16f1e407384f16925063095ea7b391506044015f604051808303815f87803b15801561167c575f80fd5b505af115801561168e573d5f803e3d5ffd5b5050335f8181526020819052604080822060019055519193507fdd0e34038ac38b2a1ce960229778ac48a8719bc900b6c4f8d0475c6e8b385a60925090a2831561170e57845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602001610de6565b5050505050565b5f61173c6117216124e7565b61172b90856139ac565b676765c793fa10079d601b1b61273f565b90505f81116117825760405162461bcd60e51b81526020600482015260126024820152715374557364732f6173736574732d7a65726f60701b6044820152606401610c59565b610e5b818484612ba0565b5f6117988484611448565b9050826001600160a01b03168261ffff167fb30a03a0e2a407f18ae0e83491331dc069d1521e292feffb071e61c8f7f406368684604051610f62929190918252602082015260400190565b335f908152602081905260409020546001146118115760405162461bcd60e51b8152600401610c59906139f6565b6001600160a01b0381165f81815260208190526040808220829055517f184450df2e323acec0ed3b5c7531b81f9b4cdef7914dfd4c0a4317416bb5251b9190a250565b5f61185d6124e7565b90506113d361277f565b814211156118af5760405162461bcd60e51b815260206004820152601560248201527414dd155cd91ccbdc195c9b5a5d0b595e1c1a5c9959605a1b6044820152606401610c59565b6001600160a01b0385166118fc5760405162461bcd60e51b815260206004820152601460248201527329ba2ab9b23997b4b73b30b634b216b7bbb732b960611b6044820152606401610c59565b6001600160a01b0385165f90815260046020526040812080546001810190915590611926466128d7565b604080517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c960208201526001600160a01b03808b169282019290925290881660608201526080810187905260a0810184905260c0810186905260e001604051602081830303815290604052805190602001206040516020016119bf92919061190160f01b81526002810192909252602282015260420190565b6040516020818303038152906040528051906020012090506119e2878285612d9e565b611a265760405162461bcd60e51b815260206004820152601560248201527414dd155cd91ccbda5b9d985b1a590b5c195c9b5a5d605a1b6044820152606401610c59565b6001600160a01b038781165f818152600360209081526040808320948b168084529482529182902089905590518881527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a350505050505050565b5f6001600160a01b03831615801590611aac57506001600160a01b0383163014155b611ac85760405162461bcd60e51b8152600401610c5990613a25565b335f9081526002602052604090205482811015611af75760405162461bcd60e51b8152600401610c5990613a55565b335f81815260026020908152604080832087860390556001600160a01b03881680845292819020805488019055518681529192915f80516020613b8f833981519152910160405180910390a35060019392505050565b5f610b7a5f80516020613b6f833981519152546001600160a01b031690565b6005545f908190600160c01b90046001600160401b03164211611b9a576005546001600160c01b0316611bea565b600554600654676765c793fa10079d601b1b916001600160c01b03811691611bd691610be990600160c01b90046001600160401b031642613999565b611be091906139ac565b611bea91906139d7565b9050610c2461172b82856139ac565b5f611c1f611c12676765c793fa10079d601b1b866139ac565b611c1a6124e7565b61273f565b9050610c2484828585612f26565b5f676765c793fa10079d601b1b611c426124e7565b611c4c90866139ac565b611c5691906139d7565b90505f8111611c9c5760405162461bcd60e51b81526020600482015260126024820152715374557364732f6173736574732d7a65726f60701b6044820152606401610c59565b610c2481858585612f26565b6007546005545f91908290600160c01b90046001600160401b03164211611cda576005546001600160c01b0316611d2a565b600554600654676765c793fa10079d601b1b916001600160c01b03811691611d1691610be990600160c01b90046001600160401b031642613999565b611d2091906139ac565b611d2a91906139d7565b9050805f03611d3c57505f9392505050565b5f198210156113875780676765c793fa10079d601b1b611d7084676765c793fa10079d601b1b8560015461137091906139ac565b611d7a91906139ac565b61137f91906139d7565b6005545f908190600160c01b90046001600160401b03164211611db2576005546001600160c01b0316611e02565b600554600654676765c793fa10079d601b1b916001600160c01b03811691611dee91610be990600160c01b90046001600160401b031642613999565b611df891906139ac565b611e0291906139d7565b90505f8111611e11575f610c24565b80610c1a676765c793fa10079d601b1b856139ac565b6005545f908190600160c01b90046001600160401b03164211611e55576005546001600160c01b0316611ea5565b600554600654676765c793fa10079d601b1b916001600160c01b03811691611e9191610be990600160c01b90046001600160401b031642613999565b611e9b91906139ac565b611ea591906139d7565b604051636cb1c69b60e11b81527f4c534556322d534b592d4100000000000000000000000000000000000000000060048201529091505f9081906001600160a01b037f00000000000000000000000035d1b3f3d7966a1dfe207aa4514c12a259a0492b169063d9638d369060240160a060405180830381865afa158015611f2e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f529190613a8c565b505050915091505f807f00000000000000000000000019c0976f590d67707e62397c87829d896dc0f1f16001600160a01b031663d9638d367f4c534556322d534b592d410000000000000000000000000000000000000000006040518263ffffffff1660e01b8152600401611fc991815260200190565b6040805180830381865afa158015611fe3573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906120079190613ac8565b915091508042116120185782612047565b676765c793fa10079d601b1b8361203384610be98542613999565b61203d91906139ac565b61204791906139d7565b6001600160a01b0388165f9081526002602052604090205490935061212f9061206f90610b7f565b676765c793fa10079d601b1b6121208860015461208c91906139ac565b7f000000000000000000000000836f56750517b1528b5078cba4ac4b94fbe4a3996001600160a01b03166308bf162f6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156120e8573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061210c9190613aea565b612116898b6139ac565b61137a9190613b01565b61212a91906139d7565b61276a565b979650505050505050565b6121888787878786868960405160200161217493929190928352602083019190915260f81b6001600160f81b031916604082015260410190565b604051602081830303815290604052611867565b50505050505050565b6005545f908190600160c01b90046001600160401b031642116121bf576005546001600160c01b031661220f565b600554600654676765c793fa10079d601b1b916001600160c01b038116916121fb91610be990600160c01b90046001600160401b031642613999565b61220591906139ac565b61220f91906139d7565b604051636cb1c69b60e11b81527f4c534556322d534b592d4100000000000000000000000000000000000000000060048201529091505f9081906001600160a01b037f00000000000000000000000035d1b3f3d7966a1dfe207aa4514c12a259a0492b169063d9638d369060240160a060405180830381865afa158015612298573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906122bc9190613a8c565b505050915091505f807f00000000000000000000000019c0976f590d67707e62397c87829d896dc0f1f16001600160a01b031663d9638d367f4c534556322d534b592d410000000000000000000000000000000000000000006040518263ffffffff1660e01b815260040161233391815260200190565b6040805180830381865afa15801561234d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906123719190613ac8565b9150915080421161238257826123b1565b676765c793fa10079d601b1b8361239d84610be98542613999565b6123a791906139ac565b6123b191906139d7565b92505f85116123c0575f61212f565b6001600160a01b0387165f9081526002602052604090205460015461212f919087906121209061208c9083906139ac565b5f610e5b82611d84565b5f8280156124c05760018316801561241557849250612424565b676765c793fa10079d601b1b92505b506002909204916b019d971e4fe8401e740000005b83156124ba57848502858682041461244f575f80fd5b8181018181101561245e575f80fd5b676765c793fa10079d601b1b900495505060018416156124af57848302838682041415861515161561248e575f80fd5b8181018181101561249d575f80fd5b676765c793fa10079d601b1b90049350505b600284049350612439565b506124e0565b8280156124cf575f92506124de565b676765c793fa10079d601b1b92505b505b5092915050565b6005545f906001600160c01b03811690600160c01b90046001600160401b031682428210156126fc57676765c793fa10079d601b1b8361252f6006548542610be99190613999565b61253991906139ac565b61254391906139d7565b600154909450676765c793fa10079d601b1b61255f85836139ac565b61256991906139d7565b676765c793fa10079d601b1b61257f87846139ac565b61258991906139d7565b6125939190613999565b91506001600160a01b037f00000000000000000000000035d1b3f3d7966a1dfe207aa4514c12a259a0492b1663f24e23eb7f000000000000000000000000a950524441892a31ebddf91d3ceefa04bf454466306125fb676765c793fa10079d601b1b876139ac565b6040516001600160e01b031960e086901b1681526001600160a01b03938416600482015292909116602483015260448201526064015f604051808303815f87803b158015612647575f80fd5b505af1158015612659573d5f803e3d5ffd5b505060405163ef693bed60e01b8152306004820152602481018590527f0000000000000000000000003c0f895007ca717aa01c8693e59df1e8c3777feb6001600160a01b0316925063ef693bed91506044015f604051808303815f87803b1580156126c2575f80fd5b505af11580156126d4573d5f803e3d5ffd5b50505050506001600160401b034216600160c01b026001600160c01b03851617600555612700565b8293505b60408051858152602081018390527fad1e8a53178522eb68a9d94d862bf30c841f709d2115f743eb6b34528751c79f910160405180910390a150505090565b5f825f0361274d575f610c24565b81600184038161275f5761275f6139c3565b046001019392505050565b5f8183106127785781610c24565b5090919050565b6008546005546001546001600160a01b037f00000000000000000000000035d1b3f3d7966a1dfe207aa4514c12a259a0492b1692631a0b287e927f4c534556322d534b592d4100000000000000000000000000000000000000000092612877929161212a916127f7916001600160c01b0316906139ac565b7f000000000000000000000000836f56750517b1528b5078cba4ac4b94fbe4a3996001600160a01b03166308bf162f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612853573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061137a9190613aea565b6040516001600160e01b031960e085901b1681526004810192909252636c696e6560e01b602483015260448201526064015f604051808303815f87803b1580156128bf575f80fd5b505af11580156128d1573d5f803e3d5ffd5b50505050565b604080518082018252600b81526a5374616b6564205553445360a81b6020918201528151808301835260018152603160f81b9082015281517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f818301527f4cf429c888f1a4eff3b986a9e14aea2a83fe058800374d3655d4fe365a2b022f818401527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6606082015260808101939093523060a0808501919091528251808503909101815260c0909301909152815191012090565b5f8183116129b9575f610c24565b50900390565b306001600160a01b037f0000000000000000000000007a61b7adcfd493f7cf0f86dfcecb94b72c227f22161480612a4557507f0000000000000000000000007a61b7adcfd493f7cf0f86dfcecb94b72c227f226001600160a01b0316612a395f80516020613b6f833981519152546001600160a01b031690565b6001600160a01b031614155b15612a635760405163703e46dd60e11b815260040160405180910390fd5b565b335f90815260208190526040902054600114612a935760405162461bcd60e51b8152600401610c59906139f6565b50565b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015612af0575060408051601f3d908101601f19168201909252612aed91810190613aea565b60015b612b1857604051634c9c8ce360e01b81526001600160a01b0383166004820152602401610c59565b5f80516020613b6f8339815191528114612b4857604051632a87526960e21b815260048101829052602401610c59565b612b5283836133b6565b505050565b306001600160a01b037f0000000000000000000000007a61b7adcfd493f7cf0f86dfcecb94b72c227f221614612a635760405163703e46dd60e11b815260040160405180910390fd5b6001600160a01b03811615801590612bc157506001600160a01b0381163014155b612bdd5760405162461bcd60e51b8152600401610c5990613a25565b6001546007546005548590676765c793fa10079d601b1b90612c08906001600160c01b0316856139ac565b612c1291906139d7565b612c1c9190613b01565b1115612c6a5760405162461bcd60e51b815260206004820152601b60248201527f5374557364732f6d696e742d6f7665722d737570706c792d63617000000000006044820152606401610c59565b6040516323b872dd60e01b8152336004820152306024820152604481018590527f000000000000000000000000dc035d45d973e3ec169d2276ddab16f1e407384f6001600160a01b0316906323b872dd906064015f604051808303815f87803b158015612cd5575f80fd5b505af1158015612ce7573d5f803e3d5ffd5b5050506001600160a01b0383165f90815260026020526040902080548501905550612d128382613b01565b600155612d1d61277f565b60408051858152602081018590526001600160a01b0384169133917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7910160405180910390a36040518381526001600160a01b038316905f905f80516020613b8f8339815191529060200160405180910390a350505050565b612a6361340b565b5f8151604103612e375760208281015160408085015160608087015183515f8082529681018086528a9052951a928501839052840183905260808401819052919260019060a0016020604051602081039080840390855afa158015612e05573d5f803e3d5ffd5b505050602060405103516001600160a01b0316876001600160a01b031603612e335760019350505050610c24565b5050505b6001600160a01b0384163b15610c24575f80856001600160a01b03168585604051602401612e66929190613b14565b60408051601f198184030181529181526020820180516001600160e01b0316630b135d3f60e11b17905251612e9b9190613b2c565b5f60405180830381855afa9150503d805f8114612ed3576040519150601f19603f3d011682016040523d82523d5f602084013e612ed8565b606091505b5091509150818015612eeb575080516020145b8015612f1c57508051630b135d3f60e11b90612f109083016020908101908401613b47565b6001600160e01b031916145b9695505050505050565b6001600160a01b0381165f9081526002602052604090205483811015612f5e5760405162461bcd60e51b8152600401610c5990613a55565b60405163089c54b560e31b81527f4c534556322d534b592d4100000000000000000000000000000000000000000060048201525f907f00000000000000000000000019c0976f590d67707e62397c87829d896dc0f1f16001600160a01b0316906344e2a5a8906024016020604051808303815f875af1158015612fe3573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906130079190613aea565b604051636cb1c69b60e11b81527f4c534556322d534b592d4100000000000000000000000000000000000000000060048201529091505f906001600160a01b037f00000000000000000000000035d1b3f3d7966a1dfe207aa4514c12a259a0492b169063d9638d369060240160a060405180830381865afa15801561308e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906130b29190613a8c565b50506005546001549394506130d5936001600160c01b03909116925090506139ac565b6130ea676765c793fa10079d601b1b896139ac565b7f000000000000000000000000836f56750517b1528b5078cba4ac4b94fbe4a3996001600160a01b03166308bf162f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613146573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061316a9190613aea565b61317485856139ac565b61317e9190613b01565b6131889190613b01565b11156131d65760405162461bcd60e51b815260206004820181905260248201527f5374557364732f696e73756666696369656e742d756e757365642d66756e64736044820152606401610c59565b6001600160a01b038416331461328b576001600160a01b0384165f9081526003602090815260408083203384529091529020545f19811461328957868110156132615760405162461bcd60e51b815260206004820152601d60248201527f5374557364732f696e73756666696369656e742d616c6c6f77616e63650000006044820152606401610c59565b6001600160a01b0385165f908152600360209081526040808320338452909152902087820390555b505b6001600160a01b0384165f90815260026020526040902086840390556001805487900390556132b861277f565b60405163a9059cbb60e01b81526001600160a01b038681166004830152602482018990527f000000000000000000000000dc035d45d973e3ec169d2276ddab16f1e407384f169063a9059cbb906044015f604051808303815f87803b15801561331f575f80fd5b505af1158015613331573d5f803e3d5ffd5b50506040518881525f92506001600160a01b03871691505f80516020613b8f8339815191529060200160405180910390a360408051888152602081018890526001600160a01b03808716929088169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db910160405180910390a450505050505050565b6133bf82613454565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a280511561340357612b5282826134b7565b6113b6613529565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff16612a6357604051631afcd79f60e31b815260040160405180910390fd5b806001600160a01b03163b5f0361348957604051634c9c8ce360e01b81526001600160a01b0382166004820152602401610c59565b5f80516020613b6f83398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b60605f80846001600160a01b0316846040516134d39190613b2c565b5f60405180830381855af49150503d805f811461350b576040519150601f19603f3d011682016040523d82523d5f602084013e613510565b606091505b5091509150613520858383613548565b95945050505050565b3415612a635760405163b398979f60e01b815260040160405180910390fd5b60608261355d57613558826135a4565b610c24565b815115801561357457506001600160a01b0384163b155b1561359d57604051639996b31560e01b81526001600160a01b0385166004820152602401610c59565b5080610c24565b8051156135b45780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b5f5b838110156135e75781810151838201526020016135cf565b50505f910152565b5f81518084526136068160208601602086016135cd565b601f01601f19169290920160200192915050565b602081525f610c2460208301846135ef565b5f6020828403121561363c575f80fd5b5035919050565b80356001600160a01b0381168114613659575f80fd5b919050565b5f806040838503121561366f575f80fd5b61367883613643565b946020939093013593505050565b5f805f60608486031215613698575f80fd5b833592506136a860208501613643565b9150604084013561ffff811681146136be575f80fd5b809150509250925092565b5f805f606084860312156136db575f80fd5b6136e484613643565b92506136f260208501613643565b9150604084013590509250925092565b5f8060408385031215613713575f80fd5b50508035926020909101359150565b5f60208284031215613732575f80fd5b610c2482613643565b634e487b7160e01b5f52604160045260245ffd5b5f82601f83011261375e575f80fd5b81356001600160401b03808211156137785761377861373b565b604051601f8301601f19908116603f011681019082821181831017156137a0576137a061373b565b816040528381528660208588010111156137b8575f80fd5b836020870160208301375f602085830101528094505050505092915050565b5f80604083850312156137e8575f80fd5b6137f183613643565b915060208301356001600160401b0381111561380b575f80fd5b6138178582860161374f565b9150509250929050565b5f8060408385031215613832575f80fd5b8235915061384260208401613643565b90509250929050565b5f805f805f60a0868803121561385f575f80fd5b61386886613643565b945061387660208701613643565b9350604086013592506060860135915060808601356001600160401b0381111561389e575f80fd5b6138aa8882890161374f565b9150509295509295909350565b5f805f606084860312156138c9575f80fd5b833592506138d960208501613643565b91506138e760408501613643565b90509250925092565b5f805f805f805f60e0888a031215613906575f80fd5b61390f88613643565b965061391d60208901613643565b95506040880135945060608801359350608088013560ff81168114613940575f80fd5b9699959850939692959460a0840135945060c09093013592915050565b5f806040838503121561396e575f80fd5b61397783613643565b915061384260208401613643565b634e487b7160e01b5f52601160045260245ffd5b81810381811115610e5b57610e5b613985565b8082028115828204841417610e5b57610e5b613985565b634e487b7160e01b5f52601260045260245ffd5b5f826139f157634e487b7160e01b5f52601260045260245ffd5b500490565b60208082526015908201527414dd155cd91ccbdb9bdd0b585d5d1a1bdc9a5e9959605a1b604082015260600190565b6020808252601690820152755374557364732f696e76616c69642d6164647265737360501b604082015260600190565b6020808252601b908201527f5374557364732f696e73756666696369656e742d62616c616e63650000000000604082015260600190565b5f805f805f60a08688031215613aa0575f80fd5b5050835160208501516040860151606087015160809097015192989197509594509092509050565b5f8060408385031215613ad9575f80fd5b505080516020909101519092909150565b5f60208284031215613afa575f80fd5b5051919050565b80820180821115610e5b57610e5b613985565b828152604060208201525f61137f60408301846135ef565b5f8251613b3d8184602087016135cd565b9190910192915050565b5f60208284031215613b57575f80fd5b81516001600160e01b031981168114610c24575f80fdfe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbcddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa2646970667358221220909b8c051671aa30e6b275bcb998bae8410483c23f6449370ff2f64010d075f464736f6c63430008150033
Verified Source Code Partial Match
Compiler: v0.8.21+commit.d9974bed
EVM: shanghai
Optimization: Yes (200 runs)
StUsds.sol 592 lines
// SPDX-License-Identifier: AGPL-3.0-or-later
/// StUsds.sol
// Copyright (C) 2017, 2018, 2019 dbrock, rain, mrchico
// Copyright (C) 2021 Dai Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
pragma solidity ^0.8.21;
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
interface IERC1271 {
function isValidSignature(
bytes32,
bytes memory
) external view returns (bytes4);
}
interface VatLike {
function ilks(bytes32) external view returns (uint256, uint256, uint256, uint256, uint256);
function file(bytes32, bytes32, uint256) external;
function hope(address) external;
function suck(address, address, uint256) external;
}
interface JugLike {
function ilks(bytes32) external view returns (uint256, uint256);
function drip(bytes32) external returns (uint256);
}
interface ClipLike {
function ilk() external view returns (bytes32);
function Due() external view returns (uint256);
}
interface UsdsJoinLike {
function vat() external view returns (address);
function usds() external view returns (address);
function join(address, uint256) external;
function exit(address, uint256) external;
}
interface UsdsLike {
function approve(address, uint256) external;
function transfer(address, uint256) external;
function transferFrom(address, address, uint256) external;
}
contract StUsds is UUPSUpgradeable {
// --- Storage Variables ---
// Admin
mapping (address => uint256) public wards;
// ERC20
uint256 public totalSupply;
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
mapping (address => uint256) public nonces;
// Savings yield
uint192 public chi; // The Rate Accumulator [ray]
uint64 public rho; // Time of last drip [unix epoch time]
uint256 public str; // The staked usds rate [ray]
uint256 public cap; // Supply max deposits [wad]
uint256 public line; // Borrow max ceiling [rad]
// --- Constants ---
// ERC20
string public constant name = "Staked USDS";
string public constant symbol = "stUSDS";
string public constant version = "1";
uint8 public constant decimals = 18;
// Math
uint256 private constant RAY = 10 ** 27;
// --- Immutables ---
// EIP712
bytes32 public constant PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
// Savings yield
UsdsJoinLike public immutable usdsJoin;
VatLike public immutable vat;
JugLike public immutable jug;
ClipLike public immutable clip;
UsdsLike public immutable usds;
address public immutable vow;
bytes32 public immutable ilk;
// --- Events ---
// Admin
event Rely(address indexed usr);
event Deny(address indexed usr);
event File(bytes32 indexed what, uint256 data);
event Cut(uint256 assets, uint256 oldChi, uint256 newChi);
// ERC20
event Approval(address indexed owner, address indexed spender, uint256 value);
event Transfer(address indexed from, address indexed to, uint256 value);
// ERC4626
event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);
event Withdraw(address indexed sender, address indexed receiver, address indexed owner, uint256 assets, uint256 shares);
// Referral
event Referral(uint16 indexed referral, address indexed owner, uint256 assets, uint256 shares);
// Savings yield
event Drip(uint256 chi, uint256 diff);
// --- Modifiers ---
modifier auth {
require(wards[msg.sender] == 1, "StUsds/not-authorized");
_;
}
// --- Constructor ---
constructor(address usdsJoin_, address jug_, address clip_, address vow_) {
_disableInitializers(); // Avoid initializing in the context of the implementation
usdsJoin = UsdsJoinLike(usdsJoin_);
vat = VatLike(UsdsJoinLike(usdsJoin_).vat());
jug = JugLike(jug_);
clip = ClipLike(clip_);
usds = UsdsLike(UsdsJoinLike(usdsJoin_).usds());
vow = vow_;
ilk = clip.ilk();
}
// --- Upgradability ---
function initialize() initializer external {
__UUPSUpgradeable_init();
chi = uint192(RAY);
rho = uint64(block.timestamp);
str = RAY;
vat.hope(address(usdsJoin));
usds.approve(address(usdsJoin), type(uint256).max);
wards[msg.sender] = 1;
emit Rely(msg.sender);
}
function _authorizeUpgrade(address newImplementation) internal override auth {}
function getImplementation() external view returns (address) {
return ERC1967Utils.getImplementation();
}
// --- Internals ---
// EIP712
function _calculateDomainSeparator(uint256 chainId) private view returns (bytes32) {
return keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256(bytes(version)),
chainId,
address(this)
)
);
}
function DOMAIN_SEPARATOR() external view returns (bytes32) {
return _calculateDomainSeparator(block.chainid);
}
// Math
function _rpow(uint256 x, uint256 n) internal pure returns (uint256 z) {
assembly {
switch x case 0 {switch n case 0 {z := RAY} default {z := 0}}
default {
switch mod(n, 2) case 0 { z := RAY } default { z := x }
let half := div(RAY, 2) // for rounding.
for { n := div(n, 2) } n { n := div(n,2) } {
let xx := mul(x, x)
if iszero(eq(div(xx, x), x)) { revert(0,0) }
let xxRound := add(xx, half)
if lt(xxRound, xx) { revert(0,0) }
x := div(xxRound, RAY)
if mod(n,2) {
let zx := mul(z, x)
if and(iszero(iszero(x)), iszero(eq(div(zx, x), z))) { revert(0,0) }
let zxRound := add(zx, half)
if lt(zxRound, zx) { revert(0,0) }
z := div(zxRound, RAY)
}
}
}
}
}
function _divup(uint256 x, uint256 y) internal pure returns (uint256 z) {
// Note: _divup(0,0) will return 0 differing from natural solidity division
unchecked {
z = x != 0 ? ((x - 1) / y) + 1 : 0;
}
}
function _subcap(uint256 x, uint256 y) internal pure returns (uint256 z) {
unchecked {
z = x > y ? x - y : 0;
}
}
function _min(uint256 x, uint256 y) internal pure returns (uint256 z) {
z = x < y ? x : y;
}
// --- Admin external functions ---
function rely(address usr) external auth {
wards[usr] = 1;
emit Rely(usr);
}
function deny(address usr) external auth {
wards[usr] = 0;
emit Deny(usr);
}
function file(bytes32 what, uint256 data) external auth {
if (what == "str") {
require(data >= RAY, "StUsds/wrong-str-value");
require(rho == block.timestamp, "StUsds/chi-not-up-to-date");
str = data;
} else if (what == "cap") {
cap = data;
} else if (what == "line") {
line = data; // If it is desired the new value has an immediate effect on vat[ilk].line, then call drip() right after
} else revert("StUsds/file-unrecognized-param");
emit File(what, data);
}
function cut(uint256 rad) external auth {
uint256 oldChi = _drip();
uint256 totalAssets_ = totalSupply * oldChi / RAY;
uint256 assets = _min(_divup(rad, RAY), totalAssets_);
uint256 newChi = chi = totalAssets_ > 0
? uint192(oldChi * (totalAssets_ - assets) / totalAssets_) // safe as newChi <= oldChi
: 0;
usdsJoin.join(vow, assets);
_setLine();
emit Cut(assets, oldChi, newChi);
}
// --- Set ilk debt ceiling ---
function _setLine() internal {
// It is assumed that general vat.Line will be set to a relatively
// big number that won't require any constant update
vat.file(ilk, "line", _min(line, _subcap(totalSupply * chi, clip.Due())));
}
// --- Savings Rate Accumulation external/internal function ---
function _drip() internal returns (uint256 nChi) {
(uint256 chi_, uint256 rho_) = (chi, rho);
uint256 diff;
if (block.timestamp > rho_) {
nChi = _rpow(str, block.timestamp - rho_) * chi_ / RAY;
uint256 totalSupply_ = totalSupply;
diff = totalSupply_ * nChi / RAY - totalSupply_ * chi_ / RAY;
vat.suck(vow, address(this), diff * RAY);
usdsJoin.exit(address(this), diff);
chi = uint192(nChi); // safe as nChi is limited to maxUint256/RAY (which is < maxUint192)
rho = uint64(block.timestamp);
} else {
nChi = chi_;
}
emit Drip(nChi, diff);
}
function drip() external returns (uint256 nChi) {
nChi = _drip();
_setLine();
}
// --- ERC20 Mutations ---
function transfer(address to, uint256 value) external returns (bool) {
require(to != address(0) && to != address(this), "StUsds/invalid-address");
uint256 balance = balanceOf[msg.sender];
require(balance >= value, "StUsds/insufficient-balance");
unchecked {
balanceOf[msg.sender] = balance - value;
balanceOf[to] += value; // note: we don't need an overflow check here b/c sum of all balances == totalSupply
}
emit Transfer(msg.sender, to, value);
return true;
}
function transferFrom(address from, address to, uint256 value) external returns (bool) {
require(to != address(0) && to != address(this), "StUsds/invalid-address");
uint256 balance = balanceOf[from];
require(balance >= value, "StUsds/insufficient-balance");
if (from != msg.sender) {
uint256 allowed = allowance[from][msg.sender];
if (allowed != type(uint256).max) {
require(allowed >= value, "StUsds/insufficient-allowance");
unchecked {
allowance[from][msg.sender] = allowed - value;
}
}
}
unchecked {
balanceOf[from] = balance - value;
balanceOf[to] += value; // note: we don't need an overflow check here b/c sum of all balances == totalSupply
}
emit Transfer(from, to, value);
return true;
}
function approve(address spender, uint256 value) external returns (bool) {
allowance[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
// --- Mint/Burn Internal ---
function _mint(uint256 assets, uint256 shares, address receiver) internal {
require(receiver != address(0) && receiver != address(this), "StUsds/invalid-address");
uint256 totalSupply_ = totalSupply;
require(totalSupply_ * chi / RAY + assets <= cap, "StUsds/mint-over-supply-cap");
usds.transferFrom(msg.sender, address(this), assets);
unchecked {
balanceOf[receiver] = balanceOf[receiver] + shares; // note: we don't need an overflow check here b/c balanceOf[receiver] <= totalSupply
}
totalSupply = totalSupply_ + shares;
_setLine();
emit Deposit(msg.sender, receiver, assets, shares);
emit Transfer(address(0), receiver, shares);
}
function _burn(uint256 assets, uint256 shares, address receiver, address owner) internal {
uint256 balance = balanceOf[owner];
require(balance >= shares, "StUsds/insufficient-balance");
uint256 rate = jug.drip(ilk);
(uint256 Art,,,,) = vat.ilks(ilk);
require(Art * rate + clip.Due() + assets * RAY <= totalSupply * chi, "StUsds/insufficient-unused-funds");
if (owner != msg.sender) {
uint256 allowed = allowance[owner][msg.sender];
if (allowed != type(uint256).max) {
require(allowed >= shares, "StUsds/insufficient-allowance");
unchecked {
allowance[owner][msg.sender] = allowed - shares;
}
}
}
unchecked {
balanceOf[owner] = balance - shares; // note: we don't need overflow checks b/c require(balance >= shares) and balance <= totalSupply
totalSupply = totalSupply - shares;
}
_setLine();
usds.transfer(receiver, assets);
emit Transfer(owner, address(0), shares);
emit Withdraw(msg.sender, receiver, owner, assets, shares);
}
// --- ERC-4626 ---
function asset() external view returns (address) {
return address(usds);
}
function totalAssets() external view returns (uint256) {
return convertToAssets(totalSupply);
}
function convertToShares(uint256 assets) public view returns (uint256) {
uint256 chi_ = (block.timestamp > rho) ? _rpow(str, block.timestamp - rho) * chi / RAY : chi;
return chi_ > 0 ? assets * RAY / chi_ : 0;
}
function convertToAssets(uint256 shares) public view returns (uint256) {
uint256 chi_ = (block.timestamp > rho) ? _rpow(str, block.timestamp - rho) * chi / RAY : chi;
return shares * chi_ / RAY;
}
function maxDeposit(address) external view returns (uint256) {
uint256 cap_ = cap;
uint256 chi_ = (block.timestamp > rho) ? _rpow(str, block.timestamp - rho) * chi / RAY : chi;
if (chi_ == 0) {
return 0;
} else if (cap_ < type(uint256).max) {
return _subcap(cap_, totalSupply * chi_ / RAY);
} else {
return type(uint256).max;
}
}
function previewDeposit(uint256 assets) external view returns (uint256) {
return convertToShares(assets);
}
function deposit(uint256 assets, address receiver) public returns (uint256 shares) {
shares = assets * RAY / _drip();
_mint(assets, shares, receiver);
}
function deposit(uint256 assets, address receiver, uint16 referral) external returns (uint256 shares) {
shares = deposit(assets, receiver);
emit Referral(referral, receiver, assets, shares);
}
function maxMint(address) external view returns (uint256) {
uint256 cap_ = cap;
uint256 chi_ = (block.timestamp > rho) ? _rpow(str, block.timestamp - rho) * chi / RAY : chi;
if (chi_ == 0) {
return 0;
} else if (cap_ < type(uint256).max) {
return _subcap(cap_, totalSupply * chi_ / RAY) * RAY / chi_;
} else {
return type(uint256).max;
}
}
function previewMint(uint256 shares) external view returns (uint256) {
uint256 chi_ = (block.timestamp > rho) ? _rpow(str, block.timestamp - rho) * chi / RAY : chi;
return _divup(shares * chi_, RAY);
}
function mint(uint256 shares, address receiver) public returns (uint256 assets) {
assets = _divup(shares * _drip(), RAY);
require(assets > 0, "StUsds/assets-zero");
_mint(assets, shares, receiver);
}
function mint(uint256 shares, address receiver, uint16 referral) external returns (uint256 assets) {
assets = mint(shares, receiver);
emit Referral(referral, receiver, assets, shares);
}
function maxWithdraw(address owner) external view returns (uint256) {
uint256 chi_ = (block.timestamp > rho) ? _rpow(str, block.timestamp - rho) * chi / RAY : chi;
(uint256 Art, uint256 rate,,,) = vat.ilks(ilk);
(uint256 duty_, uint256 rho_) = jug.ilks(ilk);
rate = (block.timestamp > rho_) ? _rpow(duty_, block.timestamp - rho_) * rate / RAY : rate;
return _min(
convertToAssets(balanceOf[owner]),
_subcap(totalSupply * chi_, Art * rate + clip.Due()) / RAY
);
}
function previewWithdraw(uint256 assets) external view returns (uint256) {
uint256 chi_ = (block.timestamp > rho) ? _rpow(str, block.timestamp - rho) * chi / RAY : chi;
return chi_ > 0 ? _divup(assets * RAY, chi_) : 0;
}
function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares) {
shares = _divup(assets * RAY, _drip());
_burn(assets, shares, receiver, owner);
}
function maxRedeem(address owner) external view returns (uint256) {
uint256 chi_ = (block.timestamp > rho) ? _rpow(str, block.timestamp - rho) * chi / RAY : chi;
(uint256 Art, uint256 rate,,,) = vat.ilks(ilk);
(uint256 duty_, uint256 rho_) = jug.ilks(ilk);
rate = (block.timestamp > rho_) ? _rpow(duty_, block.timestamp - rho_) * rate / RAY : rate;
return chi_ > 0
? _min(
balanceOf[owner],
_subcap(totalSupply * chi_, Art * rate + clip.Due()) / chi_
)
: 0;
}
function previewRedeem(uint256 shares) external view returns (uint256) {
return convertToAssets(shares);
}
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets) {
assets = shares * _drip() / RAY;
require(assets > 0, "StUsds/assets-zero");
_burn(assets, shares, receiver, owner);
}
// --- Approve by signature ---
function _isValidSignature(
address signer,
bytes32 digest,
bytes memory signature
) internal view returns (bool valid) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
if (signer == ecrecover(digest, v, r, s)) {
return true;
}
}
if (signer.code.length > 0) {
(bool success, bytes memory result) = signer.staticcall(
abi.encodeCall(IERC1271.isValidSignature, (digest, signature))
);
valid = (success &&
result.length == 32 &&
abi.decode(result, (bytes4)) == IERC1271.isValidSignature.selector);
}
}
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
bytes memory signature
) public {
require(block.timestamp <= deadline, "StUsds/permit-expired");
require(owner != address(0), "StUsds/invalid-owner");
uint256 nonce;
unchecked { nonce = nonces[owner]++; }
bytes32 digest =
keccak256(abi.encodePacked(
"\x19\x01",
_calculateDomainSeparator(block.chainid),
keccak256(abi.encode(
PERMIT_TYPEHASH,
owner,
spender,
value,
nonce,
deadline
))
));
require(_isValidSignature(owner, digest, signature), "StUsds/invalid-permit");
allowance[owner][spender] = value;
emit Approval(owner, spender, value);
}
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external {
permit(owner, spender, value, deadline, abi.encodePacked(r, s, v));
}
}
UUPSUpgradeable.sol 153 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/UUPSUpgradeable.sol)
pragma solidity ^0.8.20;
import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {Initializable} from "./Initializable.sol";
/**
* @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
* {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
*
* A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
* reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
* `UUPSUpgradeable` with a custom implementation of upgrades.
*
* The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
*/
abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable {
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address private immutable __self = address(this);
/**
* @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
* and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
* while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
* If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
* be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
* during an upgrade.
*/
string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";
/**
* @dev The call is from an unauthorized context.
*/
error UUPSUnauthorizedCallContext();
/**
* @dev The storage `slot` is unsupported as a UUID.
*/
error UUPSUnsupportedProxiableUUID(bytes32 slot);
/**
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
* a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
* for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
* function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
* fail.
*/
modifier onlyProxy() {
_checkProxy();
_;
}
/**
* @dev Check that the execution is not being performed through a delegate call. This allows a function to be
* callable on the implementing contract but not through proxies.
*/
modifier notDelegated() {
_checkNotDelegated();
_;
}
function __UUPSUpgradeable_init() internal onlyInitializing {
}
function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
}
/**
* @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
* implementation. It is used to validate the implementation's compatibility when performing an upgrade.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
*/
function proxiableUUID() external view virtual notDelegated returns (bytes32) {
return ERC1967Utils.IMPLEMENTATION_SLOT;
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
* encoded in `data`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, data);
}
/**
* @dev Reverts if the execution is not performed via delegatecall or the execution
* context is not of a proxy with an ERC1967-compliant implementation pointing to self.
* See {_onlyProxy}.
*/
function _checkProxy() internal view virtual {
if (
address(this) == __self || // Must be called through delegatecall
ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
) {
revert UUPSUnauthorizedCallContext();
}
}
/**
* @dev Reverts if the execution is performed via delegatecall.
* See {notDelegated}.
*/
function _checkNotDelegated() internal view virtual {
if (address(this) != __self) {
// Must not be called through delegatecall
revert UUPSUnauthorizedCallContext();
}
}
/**
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
* {upgradeToAndCall}.
*
* Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
*
* ```solidity
* function _authorizeUpgrade(address) internal onlyOwner {}
* ```
*/
function _authorizeUpgrade(address newImplementation) internal virtual;
/**
* @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
*
* As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
* is expected to be the implementation slot in ERC1967.
*
* Emits an {IERC1967-Upgraded} event.
*/
function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
revert UUPSUnsupportedProxiableUUID(slot);
}
ERC1967Utils.upgradeToAndCall(newImplementation, data);
} catch {
// The implementation is not UUPS
revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
}
}
}
draft-IERC1822.sol 20 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.20;
/**
* @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822Proxiable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}
ERC1967Utils.sol 193 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/ERC1967/ERC1967Utils.sol)
pragma solidity ^0.8.20;
import {IBeacon} from "../beacon/IBeacon.sol";
import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";
/**
* @dev This abstract contract provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
*/
library ERC1967Utils {
// We re-declare ERC-1967 events here because they can't be used directly from IERC1967.
// This will be fixed in Solidity 0.8.21. At that point we should remove these events.
/**
* @dev Emitted when the implementation is upgraded.
*/
event Upgraded(address indexed implementation);
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Emitted when the beacon is changed.
*/
event BeaconUpgraded(address indexed beacon);
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev The `implementation` of the proxy is invalid.
*/
error ERC1967InvalidImplementation(address implementation);
/**
* @dev The `admin` of the proxy is invalid.
*/
error ERC1967InvalidAdmin(address admin);
/**
* @dev The `beacon` of the proxy is invalid.
*/
error ERC1967InvalidBeacon(address beacon);
/**
* @dev An upgrade function sees `msg.value > 0` that may be lost.
*/
error ERC1967NonPayable();
/**
* @dev Returns the current implementation address.
*/
function getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
if (newImplementation.code.length == 0) {
revert ERC1967InvalidImplementation(newImplementation);
}
StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Performs implementation upgrade with additional setup call if data is nonempty.
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
* to avoid stuck value in the contract.
*
* Emits an {IERC1967-Upgraded} event.
*/
function upgradeToAndCall(address newImplementation, bytes memory data) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
if (data.length > 0) {
Address.functionDelegateCall(newImplementation, data);
} else {
_checkNonPayable();
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Returns the current admin.
*
* TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using
* the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
* `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
*/
function getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
if (newAdmin == address(0)) {
revert ERC1967InvalidAdmin(address(0));
}
StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {IERC1967-AdminChanged} event.
*/
function changeAdmin(address newAdmin) internal {
emit AdminChanged(getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Returns the current beacon.
*/
function getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the EIP1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
if (newBeacon.code.length == 0) {
revert ERC1967InvalidBeacon(newBeacon);
}
StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;
address beaconImplementation = IBeacon(newBeacon).implementation();
if (beaconImplementation.code.length == 0) {
revert ERC1967InvalidImplementation(beaconImplementation);
}
}
/**
* @dev Change the beacon and trigger a setup call if data is nonempty.
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
* to avoid stuck value in the contract.
*
* Emits an {IERC1967-BeaconUpgraded} event.
*
* CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
* it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
* efficiency.
*/
function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
_setBeacon(newBeacon);
emit BeaconUpgraded(newBeacon);
if (data.length > 0) {
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
} else {
_checkNonPayable();
}
}
/**
* @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
* if an upgrade doesn't perform an initialization call.
*/
function _checkNonPayable() private {
if (msg.value > 0) {
revert ERC1967NonPayable();
}
}
}
Initializable.sol 228 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.20;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Storage of the initializable contract.
*
* It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
* when using with upgradeable contracts.
*
* @custom:storage-location erc7201:openzeppelin.storage.Initializable
*/
struct InitializableStorage {
/**
* @dev Indicates that the contract has been initialized.
*/
uint64 _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool _initializing;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
/**
* @dev The contract is already initialized.
*/
error InvalidInitialization();
/**
* @dev The contract is not initializing.
*/
error NotInitializing();
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint64 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
* number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
* production.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
// Cache values to avoid duplicated sloads
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
// Allowed calls:
// - initialSetup: the contract is not in the initializing state and no previous version was
// initialized
// - construction: the contract is initialized at version 1 (no reininitialization) and the
// current contract is just being deployed
bool initialSetup = initialized == 0 && isTopLevelCall;
bool construction = initialized == 1 && address(this).code.length == 0;
if (!initialSetup && !construction) {
revert InvalidInitialization();
}
$._initialized = 1;
if (isTopLevelCall) {
$._initializing = true;
}
_;
if (isTopLevelCall) {
$._initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint64 version) {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing || $._initialized >= version) {
revert InvalidInitialization();
}
$._initialized = version;
$._initializing = true;
_;
$._initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
_checkInitializing();
_;
}
/**
* @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
*/
function _checkInitializing() internal view virtual {
if (!_isInitializing()) {
revert NotInitializing();
}
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing) {
revert InvalidInitialization();
}
if ($._initialized != type(uint64).max) {
$._initialized = type(uint64).max;
emit Initialized(type(uint64).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint64) {
return _getInitializableStorage()._initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _getInitializableStorage()._initializing;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
assembly {
$.slot := INITIALIZABLE_STORAGE
}
}
}
IBeacon.sol 16 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.20;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeacon {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {UpgradeableBeacon} will check that this address is a contract.
*/
function implementation() external view returns (address);
}
Address.sol 159 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @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.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @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 or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* 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.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @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`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) 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 FailedInnerCall();
}
}
}
StorageSlot.sol 135 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```solidity
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
/**
* @dev Returns an `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
}
Read Contract
DOMAIN_SEPARATOR 0x3644e515 → bytes32
PERMIT_TYPEHASH 0x30adf81f → bytes32
UPGRADE_INTERFACE_VERSION 0xad3cb1cc → string
allowance 0xdd62ed3e → uint256
asset 0x38d52e0f → address
balanceOf 0x70a08231 → uint256
cap 0x355274ea → uint256
chi 0xc92aecc4 → uint192
clip 0x39b00e41 → address
convertToAssets 0x07a2d13a → uint256
convertToShares 0xc6e6f592 → uint256
decimals 0x313ce567 → uint8
getImplementation 0xaaf10f42 → address
ilk 0xc5ce281e → bytes32
jug 0x84718d89 → address
line 0xb56b8353 → uint256
maxDeposit 0x402d267d → uint256
maxMint 0xc63d75b6 → uint256
maxRedeem 0xd905777e → uint256
maxWithdraw 0xce96cb77 → uint256
name 0x06fdde03 → string
nonces 0x7ecebe00 → uint256
previewDeposit 0xef8b30f7 → uint256
previewMint 0xb3d7f6b9 → uint256
previewRedeem 0x4cdad506 → uint256
previewWithdraw 0x0a28a477 → uint256
proxiableUUID 0x52d1902d → bytes32
rho 0x20aba08b → uint64
str 0xc15bae84 → uint256
symbol 0x95d89b41 → string
totalAssets 0x01e1d114 → uint256
totalSupply 0x18160ddd → uint256
usds 0x4cf282fb → address
usdsJoin 0xfa1e2e86 → address
vat 0x36569e77 → address
version 0x54fd4d50 → string
vow 0x626cb3c5 → address
wards 0xbf353dbb → uint256
Write Contract 18 functions
These functions modify contract state and require a wallet transaction to execute.
approve 0x095ea7b3
address spender
uint256 value
returns: bool
cut 0x09260db7
uint256 rad
deny 0x9c52a7f1
address usr
deposit 0x6e553f65
uint256 assets
address receiver
returns: uint256
deposit 0x9b8d6d38
uint256 assets
address receiver
uint16 referral
returns: uint256
drip 0x9f678cca
No parameters
returns: uint256
file 0x29ae8114
bytes32 what
uint256 data
initialize 0x8129fc1c
No parameters
mint 0x216740a0
uint256 shares
address receiver
uint16 referral
returns: uint256
mint 0x94bf804d
uint256 shares
address receiver
returns: uint256
permit 0x9fd5a6cf
address owner
address spender
uint256 value
uint256 deadline
bytes signature
permit 0xd505accf
address owner
address spender
uint256 value
uint256 deadline
uint8 v
bytes32 r
bytes32 s
redeem 0xba087652
uint256 shares
address receiver
address owner
returns: uint256
rely 0x65fae35e
address usr
transfer 0xa9059cbb
address to
uint256 value
returns: bool
transferFrom 0x23b872dd
address from
address to
uint256 value
returns: bool
upgradeToAndCall 0x4f1ef286
address newImplementation
bytes data
withdraw 0xb460af94
uint256 assets
address receiver
address owner
returns: uint256
Recent Transactions
This address has 1 on-chain transactions, but only 1.2% of the chain is indexed. Transactions will appear as indexing progresses. View on Etherscan →