Address Contract Verified
Address
0xcc2fadfFA21401801F07BD58B3159c34316553F7
Balance
0 ETH
Nonce
1
Code Size
9506 bytes
Creator
0xD6afecB8...465A at tx 0xd5d0ef1c...cfb1f6
Indexed Transactions
0
Contract Bytecode
9506 bytes
0x608060405234801561000f575f5ffd5b50600436106101fd575f3560e01c8063922aa0e711610114578063d56d229d116100a9578063ec16d07611610079578063ec16d07614610234578063ed49893d14610546578063f2fde38b1461054f578063f6ed201714610562578063fb99c06414610575575f5ffd5b8063d56d229d146104de578063db14f6bc14610505578063ddd710fb14610526578063e7f5aad914610539575f5ffd5b8063bbb85188116100e4578063bbb8518814610437578063beceed3914610474578063c29f5d9714610487578063c34531531461049a575f5ffd5b8063922aa0e7146103d7578063a694fc3a146103ea578063a98ad46c146103fd578063b310ce5a14610424575f5ffd5b8063715018a611610195578063817b1cd211610165578063817b1cd21461038f57806384ce14b01461039857806385f4498b146103ab57806386989038146103be5780638da5cb5b146103c7575f5ffd5b8063715018a61461032c57806371aaad331461033457806374958e35146103475780637628fd4014610350575f5ffd5b80632def6620116101d05780632def6620146102e7578063372500ab146102f15780634ee13a88146102f95780635dad25bc1461030c575f5ffd5b806306032d74146102015780630a171df81461023457806316934fc41461024c57806326d02dea146102b5575b5f5ffd5b61021461020f366004612277565b61057e565b604080519384526020840192909252908201526060015b60405180910390f35b61023e62278d0081565b60405190815260200161022b565b61028b61025a366004612277565b600260208190525f918252604090912080546001820154928201546003830154600490930154919392909160ff1685565b6040805195865260208601949094529284019190915260608301521515608082015260a00161022b565b6102d76102c3366004612292565b60036020525f908152604090205460ff1681565b604051901515815260200161022b565b6102ef61068d565b005b6102ef6108f7565b6102ef610307366004612292565b610b82565b61031f61031a366004612277565b610c8a565b60405161022b91906122e3565b6102ef610e27565b6102ef610342366004612292565b610e38565b61023e60065481565b6103777f000000000000000000000000afb942e2a12ac0861ad81b5c37682f588912c1d981565b6040516001600160a01b03909116815260200161022b565b61023e60045481565b6102d76103a6366004612277565b610e88565b6102d76103b9366004612277565b610ebe565b61023e60055481565b5f546001600160a01b0316610377565b61023e6103e5366004612277565b610f3c565b6102ef6103f8366004612292565b610fee565b6103777f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec781565b6102ef610432366004612277565b6114d5565b61043f611672565b604080519788526020880196909652948601939093526060850191909152608084015260a083015260c082015260e00161022b565b6102ef610482366004612292565b6118d8565b61023e610495366004612277565b6119af565b6104ad6104a8366004612277565b611a41565b60408051968752602087019590955293850192909252606084015215156080830152151560a082015260c00161022b565b6103777f000000000000000000000000e0d947b837b42ea1bcd7dec7640d5b3bb2455d4e81565b610518610513366004612277565b611ac4565b60405161022b9291906122f5565b6102d7610534366004612277565b611e05565b61023e65048c2739500081565b61023e6101f581565b6102ef61055d366004612277565b611f18565b61023e610570366004612277565b611f8e565b61023e6103e881565b6001600160a01b0381165f908152600260208181526040808420815160a0810183528154815260018201549381019390935292830154908201526003820154606082015260049091015460ff161580156080830181905283928392909183916105f7575060208201516105f49062278d0061212f565b42105b15610623576106204261061a62278d00856020015161212f90919063ffffffff16565b90612141565b90505b60808201515f908015610647575060408301516106439062278d0061212f565b4210155b15610677575f61066484604001514261214190919063ffffffff16565b90506106738162278d0061214c565b9150505b61068087611f8e565b9790965090945092505050565b610695612157565b335f9081526002602052604090206004015460ff166106cf5760405162461bcd60e51b81526004016106c69061230f565b60405180910390fd5b6106d833610ebe565b61071d5760405162461bcd60e51b815260206004820152601660248201527514dd1a5b1b081a5b881b1bd8dadd5c081c195c9a5bd960521b60448201526064016106c6565b335f81815260026020818152604092839020835160a081018552815480825260018301549382019390935292810154838501526003810154606084015260049081015460ff1615156080840152925163a9059cbb60e01b81529283019390935260248201929092526001600160a01b037f000000000000000000000000afb942e2a12ac0861ad81b5c37682f588912c1d9169063a9059cbb906044016020604051808303815f875af11580156107d5573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107f99190612338565b61083e5760405162461bcd60e51b8152602060048201526016602482015275141492559256081d1c985b9cd9995c8819985a5b195960521b60448201526064016106c6565b60608101515f908152600360208181526040808420805460ff1990811690915533855260029283905290842084815560018101859055918201849055918101929092556004918201805490911690558151905461089a91612141565b6004556005546108ab906001612141565b60055580516040805191825242602083015233917f7fc4727e062e336010f2c282598ef5f14facb3de68cf8195c2f23e1454b2b74e91015b60405180910390a2506108f560018055565b565b6108ff612157565b335f9081526002602052604090206004015460ff166109305760405162461bcd60e51b81526004016106c69061230f565b61093933611e05565b6109945760405162461bcd60e51b815260206004820152602660248201527f4e4654206e6f206c6f6e676572206f776e6564202d207374616b65206c6971756044820152651a59185d195960d21b60648201526084016106c6565b335f90815260026020819052604090912001546109b49062278d0061212f565b421015610a035760405162461bcd60e51b815260206004820181905260248201527f4d75737420776169742033302064617973206265747765656e20636c61696d7360448201526064016106c6565b5f610a0d33611f8e565b90505f8111610a545760405162461bcd60e51b81526020600482015260136024820152724e6f207265776172647320746f20636c61696d60681b60448201526064016106c6565b335f81815260026020819052604091829020429101555163a9059cbb60e01b81526004810191909152602481018290526001600160a01b037f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7169063a9059cbb906044016020604051808303815f875af1158015610ad4573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610af89190612338565b610b3b5760405162461bcd60e51b81526020600482015260146024820152731554d115081d1c985b9cd9995c8819985a5b195960621b60448201526064016106c6565b600654610b48908261212f565b6006556040805182815242602082015233917fdacbdde355ba930696a362ea6738feb9f8bd52dfb3d81947558fd3217e23e32591016108e3565b610b8a6121b0565b610b92612157565b7f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec76001600160a01b031663a9059cbb610bd25f546001600160a01b031690565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602481018490526044016020604051808303815f875af1158015610c1c573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c409190612338565b610c7e5760405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b60448201526064016106c6565b610c8760018055565b50565b60605f5f610c9784611ac4565b9150915081610cb6575050604080515f81526020810190915292915050565b5f815167ffffffffffffffff811115610cd157610cd1612357565b604051908082528060200260200182016040528015610cfa578160200160208202803683370190505b5090505f805b8351811015610d8c5760035f858381518110610d1e57610d1e61236b565b60209081029190910181015182528101919091526040015f205460ff16610d8457838181518110610d5157610d5161236b565b6020026020010151838381518110610d6b57610d6b61236b565b602090810291909101015281610d8081612393565b9250505b600101610d00565b505f8167ffffffffffffffff811115610da757610da7612357565b604051908082528060200260200182016040528015610dd0578160200160208202803683370190505b5090505f5b82811015610e1c57838181518110610def57610def61236b565b6020026020010151828281518110610e0957610e0961236b565b6020908102919091010152600101610dd5565b509695505050505050565b610e2f6121b0565b6108f55f612209565b610e406121b0565b610e48612157565b7f000000000000000000000000afb942e2a12ac0861ad81b5c37682f588912c1d96001600160a01b031663a9059cbb610bd25f546001600160a01b031690565b6001600160a01b0381165f9081526002602052604081206004015460ff168015610eb85750610eb682611e05565b155b92915050565b6001600160a01b0381165f908152600260208181526040808420815160a0810183528154815260018201549381019390935292830154908201526003820154606082015260049091015460ff16151560808201819052610f2057505f92915050565b6020810151610f329062278d0061212f565b4210159392505050565b6001600160a01b0381165f908152600260208181526040808420815160a0810183528154815260018201549381019390935292830154908201526003820154606082015260049091015460ff16151560808201819052610f9e57505f92915050565b6040810151610fb09062278d0061212f565b421015610fbf57505f92915050565b5f610fd782604001514261214190919063ffffffff16565b9050610fe68162278d0061214c565b949350505050565b610ff6612157565b335f9081526002602052604090206004015460ff161561104a5760405162461bcd60e51b815260206004820152600f60248201526e416c7265616479207374616b696e6760881b60448201526064016106c6565b6101f5811015801561105e57506103e88111155b6110aa5760405162461bcd60e51b815260206004820152601860248201527f496e76616c6964206469616d6f6e6420746f6b656e204944000000000000000060448201526064016106c6565b6040516331a9108f60e11b81526004810182905233906001600160a01b037f000000000000000000000000e0d947b837b42ea1bcd7dec7640d5b3bb2455d4e1690636352211e90602401602060405180830381865afa15801561110f573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061113391906123ab565b6001600160a01b0316146111815760405162461bcd60e51b8152602060048201526015602482015274139bdd081bdddb995c881bd9881d1a1a5cc8139195605a1b60448201526064016106c6565b5f8181526003602052604090205460ff16156111df5760405162461bcd60e51b815260206004820152601c60248201527f4e465420616c7265616479207573656420666f72207374616b696e670000000060448201526064016106c6565b604051632783162d60e11b8152600481018290525f907f000000000000000000000000e0d947b837b42ea1bcd7dec7640d5b3bb2455d4e6001600160a01b031690634f062c5a906024015f60405180830381865afa158015611243573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261126a91908101906123c6565b604080518082019091526007815266111a585b5bdb9960ca1b6020918201528151908201209091507faadb29765cb3e4f21bde5ecd65db8e565d901b6c9394dcec22aa81b8ff2d6e2f146113005760405162461bcd60e51b815260206004820152601760248201527f4e4654206973206e6f74204469616d6f6e64207469657200000000000000000060448201526064016106c6565b6040516323b872dd60e01b815233600482015230602482015265048c2739500060448201527f000000000000000000000000afb942e2a12ac0861ad81b5c37682f588912c1d96001600160a01b0316906323b872dd906064016020604051808303815f875af1158015611375573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113999190612338565b6113de5760405162461bcd60e51b8152602060048201526016602482015275141492559256081d1c985b9cd9995c8819985a5b195960521b60448201526064016106c6565b6040805160a08101825265048c2739500080825242602080840182815284860192835260608501888152600160808701818152335f90815260028087528a822099518a55945189840155955193880193909355905160038088019190915591516004968701805491151560ff1992831617905589855291909252949091208054909416179092555461146f9161212f565b60045560055461148090600161212f565b6005556040805165048c273950008152602081018490524281830152905133917fb4caaf29adda3eefee3ad552a8e85058589bf834c7466cae4ee58787f70589ed919081900360600190a250610c8760018055565b6114dd6121b0565b6114e5612157565b6001600160a01b0381165f9081526002602052604090206004015460ff1661151f5760405162461bcd60e51b81526004016106c69061230f565b61152881610e88565b61156d5760405162461bcd60e51b81526020600482015260166024820152755374616b65206e6f74206c6971756964617461626c6560501b60448201526064016106c6565b6001600160a01b0381165f818152600260208181526040808420815160a081018352815481526001820180548286015282860180548386015260038085018054606086018190526004808801805460ff1615156080890152918c52928952968a20805460ff199081169091559a8a5297909652928790558690559085905593909255815490931690558051915490916116069190612141565b600455600554611617906001612141565b6005558051606082015160408051928352602083019190915233916001600160a01b038516917fe828f4812dd0a9b1a5ba6610c6b803f3ab1ec0a4bcd3e916095401f808d0cd80910160405180910390a350610c8760018055565b5f5f5f5f5f5f5f5f5f60055411611689575f61171d565b6005546040516370a0823160e01b815230600482015261171d91906001600160a01b037f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec716906370a0823190602401602060405180830381865afa1580156116f3573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117179190612479565b9061214c565b600480546005546006546040516370a0823160e01b81523094810194909452939450909290916001600160a01b037f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec716906370a0823190602401602060405180830381865afa158015611792573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117b69190612479565b6040516370a0823160e01b81523060048201527f000000000000000000000000afb942e2a12ac0861ad81b5c37682f588912c1d96001600160a01b0316906370a0823190602401602060405180830381865afa158015611818573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061183c9190612479565b6040516370a0823160e01b81523060048201527f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec76001600160a01b0316906370a0823190602401602060405180830381865afa15801561189e573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118c29190612479565b949d939c50919a50985096509094509092509050565b6040516323b872dd60e01b8152336004820152306024820152604481018290527f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec76001600160a01b0316906323b872dd906064016020604051808303815f875af1158015611948573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061196c9190612338565b610c875760405162461bcd60e51b81526020600482015260146024820152731554d115081d1c985b9cd9995c8819985a5b195960621b60448201526064016106c6565b6001600160a01b0381165f908152600260208181526040808420815160a0810183528154815260018201549381019390935292830154908201526003820154606082015260049091015460ff16151560808201819052611a1157505f92915050565b60208101515f90611a259062278d0061212f565b9050804210611a3757505f9392505050565b610fe68142612141565b6001600160a01b0381165f908152600260208181526040808420815160a081018352815480825260018301549482018590529482015492810183905260038201546060820181905260049092015460ff161515608082018190528695869586958695869594611aaf8d610ebe565b949d939c50919a509850965090945092505050565b6040516370a0823160e01b81526001600160a01b0382811660048301525f9160609183917f000000000000000000000000e0d947b837b42ea1bcd7dec7640d5b3bb2455d4e909116906370a0823190602401602060405180830381865afa158015611b31573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b559190612479565b90505f8167ffffffffffffffff811115611b7157611b71612357565b604051908082528060200260200182016040528015611b9a578160200160208202803683370190505b5090505f805b83811015611d6657604051632f745c5960e01b81526001600160a01b038881166004830152602482018390525f917f000000000000000000000000e0d947b837b42ea1bcd7dec7640d5b3bb2455d4e90911690632f745c5990604401602060405180830381865afa158015611c17573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c3b9190612479565b90506101f58110158015611c5157506103e88111155b15611d5d57604051632783162d60e11b8152600481018290525f907f000000000000000000000000e0d947b837b42ea1bcd7dec7640d5b3bb2455d4e6001600160a01b031690634f062c5a906024015f60405180830381865afa158015611cba573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052611ce191908101906123c6565b604080518082019091526007815266111a585b5bdb9960ca1b6020918201528151908201209091507f5524d689a34c1b0de421a1329a2471a9a26fe4936c6b2313dd557e4700d291d101611d5b5781858581518110611d4257611d4261236b565b602090810291909101015283611d5781612393565b9450505b505b50600101611ba0565b505f8167ffffffffffffffff811115611d8157611d81612357565b604051908082528060200260200182016040528015611daa578160200160208202803683370190505b5090505f5b82811015611df657838181518110611dc957611dc961236b565b6020026020010151828281518110611de357611de361236b565b6020908102919091010152600101611daf565b50901515969095509350505050565b6001600160a01b0381165f908152600260208181526040808420815160a0810183528154815260018201549381019390935292830154908201526003820154606082015260049091015460ff16151560808201819052611e6757505f92915050565b60608101516040516331a9108f60e11b815260048101919091527f000000000000000000000000e0d947b837b42ea1bcd7dec7640d5b3bb2455d4e6001600160a01b031690636352211e90602401602060405180830381865afa925050508015611eee575060408051601f3d908101601f19168201909252611eeb918101906123ab565b60015b611efa57505f92915050565b836001600160a01b0316816001600160a01b03161492505050919050565b611f206121b0565b6001600160a01b038116611f855760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016106c6565b610c8781612209565b6001600160a01b0381165f908152600260208181526040808420815160a0810183528154815260018201549381019390935292830154908201526003820154606082015260049091015460ff16158015608083015280611fed57508051155b80611ff85750600554155b1561200557505f92915050565b61200e83611e05565b61201a57505f92915050565b604081015161202c9062278d0061212f565b42101561203b57505f92915050565b5f61205382604001514261214190919063ffffffff16565b90505f6120638262278d0061214c565b6040516370a0823160e01b81523060048201529091505f906001600160a01b037f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec716906370a0823190602401602060405180830381865afa1580156120ca573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906120ee9190612479565b9050805f0361210257505f95945050505050565b5f6121186005548361214c90919063ffffffff16565b90506121248184612258565b979650505050505050565b5f61213a8284612490565b9392505050565b5f61213a82846124a3565b5f61213a82846124b6565b6002600154036121a95760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016106c6565b6002600155565b5f546001600160a01b031633146108f55760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016106c6565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b5f61213a82846124d5565b6001600160a01b0381168114610c87575f5ffd5b5f60208284031215612287575f5ffd5b813561213a81612263565b5f602082840312156122a2575f5ffd5b5035919050565b5f8151808452602084019350602083015f5b828110156122d95781518652602095860195909101906001016122bb565b5093949350505050565b602081525f61213a60208301846122a9565b8215158152604060208201525f610fe660408301846122a9565b6020808252600f908201526e4e6f20616374697665207374616b6560881b604082015260600190565b5f60208284031215612348575f5ffd5b8151801515811461213a575f5ffd5b634e487b7160e01b5f52604160045260245ffd5b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b5f600182016123a4576123a461237f565b5060010190565b5f602082840312156123bb575f5ffd5b815161213a81612263565b5f602082840312156123d6575f5ffd5b815167ffffffffffffffff8111156123ec575f5ffd5b8201601f810184136123fc575f5ffd5b805167ffffffffffffffff81111561241657612416612357565b604051601f8201601f19908116603f0116810167ffffffffffffffff8111828210171561244557612445612357565b60405281815282820160200186101561245c575f5ffd5b8160208401602083015e5f91810160200191909152949350505050565b5f60208284031215612489575f5ffd5b5051919050565b80820180821115610eb857610eb861237f565b81810381811115610eb857610eb861237f565b5f826124d057634e487b7160e01b5f52601260045260245ffd5b500490565b8082028115828204841417610eb857610eb861237f56fea2646970667358221220075b30ece88f0902cdab2cbb33ab5bd0b13fc03362cccc0a00f3768fbc64f40b64736f6c634300081e0033
Verified Source Code Full Match
Compiler: v0.8.30+commit.73712a01
EVM: prague
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;
}
}
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);
}
IERC721.sol 132 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
SafeMath.sol 215 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/SafeMath.sol)
pragma solidity ^0.8.0;
// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.
/**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}
PrivixStake.sol 399 lines
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import "@openzeppelin/[email protected]/token/ERC20/IERC20.sol"; import "@openzeppelin/[email protected]/token/ERC721/IERC721.sol"; import "@openzeppelin/[email protected]/access/Ownable.sol"; import "@openzeppelin/[email protected]/security/ReentrancyGuard.sol"; import "@openzeppelin/[email protected]/utils/math/SafeMath.sol"; interface IPrivixNFTPass { function getTier(uint256 tokenId) external view returns (string memory); function ownerOf(uint256 tokenId) external view returns (address); function balanceOf(address owner) external view returns (uint256); function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256); } contract DiamondStaking is Ownable, ReentrancyGuard { using SafeMath for uint256; /* ─────────────────── Constants ─────────────────── */ uint256 public constant STAKING_AMOUNT = 5000 * 10**9; // 5000 PRIVIX (9 decimals) uint256 public constant LOCKUP_PERIOD = 30 days; // 30 days lockup uint256 public constant DIAMOND_START = 501; // Diamond NFT range start uint256 public constant DIAMOND_END = 1000; // Diamond NFT range end /* ─────────────────── Contract References ─────────────────── */ IERC20 public immutable privixToken; IERC20 public immutable usdtToken; IPrivixNFTPass public immutable nftContract; /* ─────────────────── Staking Data ─────────────────── */ struct StakeInfo { uint256 amount; // Amount of PRIVIX staked uint256 stakeTime; // Timestamp when staked uint256 lastClaimTime; // Last time rewards were claimed uint256 diamondTokenId; // Diamond NFT token ID used for staking bool isActive; // Whether stake is active } mapping(address => StakeInfo) public stakes; mapping(uint256 => bool) public nftUsedForStaking; // Track which NFTs are being used for staking /* ─────────────────── Reward Configuration ─────────────────── */ // Pool-based rewards: Total USDT divided equally among all stakers uint256 public constant REWARD_PERIOD = 30 days; // Users can claim every 30 days /* ─────────────────── Pool Stats ─────────────────── */ uint256 public totalStaked; uint256 public totalStakers; uint256 public totalRewardsPaid; /* ─────────────────── Events ─────────────────── */ event Staked(address indexed user, uint256 amount, uint256 diamondTokenId, uint256 timestamp); event Unstaked(address indexed user, uint256 amount, uint256 timestamp); event RewardsClaimed(address indexed user, uint256 amount, uint256 timestamp); event RewardRateUpdated(uint256 newRate); event StakeLiquidated(address indexed user, uint256 amount, uint256 diamondTokenId, address indexed liquidator); /* ─────────────────── Constructor ─────────────────── */ constructor( address _privixToken, address _usdtToken, address _nftContract ) { privixToken = IERC20(_privixToken); usdtToken = IERC20(_usdtToken); nftContract = IPrivixNFTPass(_nftContract); } /* ─────────────────── View Functions ─────────────────── */ /// Check if user owns any diamond NFTs function userOwnsDiamondNFT(address user) public view returns (bool, uint256[] memory) { uint256 balance = nftContract.balanceOf(user); uint256[] memory diamondTokens = new uint256[](balance); uint256 diamondCount = 0; for (uint256 i = 0; i < balance; i++) { uint256 tokenId = nftContract.tokenOfOwnerByIndex(user, i); if (tokenId >= DIAMOND_START && tokenId <= DIAMOND_END) { // Double check with getTier function string memory tier = nftContract.getTier(tokenId); if (keccak256(bytes(tier)) == keccak256(bytes("Diamond"))) { diamondTokens[diamondCount] = tokenId; diamondCount++; } } } // Resize array to actual diamond count uint256[] memory result = new uint256[](diamondCount); for (uint256 i = 0; i < diamondCount; i++) { result[i] = diamondTokens[i]; } return (diamondCount > 0, result); } /// Get available diamond NFTs for staking (not currently used) function getAvailableDiamondNFTs(address user) external view returns (uint256[] memory) { (bool owns, uint256[] memory allDiamonds) = userOwnsDiamondNFT(user); if (!owns) { return new uint256[](0); } uint256[] memory available = new uint256[](allDiamonds.length); uint256 availableCount = 0; for (uint256 i = 0; i < allDiamonds.length; i++) { if (!nftUsedForStaking[allDiamonds[i]]) { available[availableCount] = allDiamonds[i]; availableCount++; } } // Resize to actual available count uint256[] memory result = new uint256[](availableCount); for (uint256 i = 0; i < availableCount; i++) { result[i] = available[i]; } return result; } /// Calculate pending rewards for a user (pool-based with compounding) function getPendingRewards(address user) public view returns (uint256) { StakeInfo memory userStake = stakes[user]; if (!userStake.isActive || userStake.amount == 0 || totalStakers == 0) { return 0; } // No rewards if NFT was transferred if (!stakerStillOwnsNFT(user)) { return 0; } // Check if at least one 30-day period has passed since last claim if (block.timestamp < userStake.lastClaimTime.add(REWARD_PERIOD)) { return 0; // No rewards available yet } // Calculate how many full 30-day periods have passed since last claim uint256 timeSinceLastClaim = block.timestamp.sub(userStake.lastClaimTime); uint256 periodsElapsed = timeSinceLastClaim.div(REWARD_PERIOD); // Calculate user's equal share of the total USDT pool uint256 totalUsdtPool = usdtToken.balanceOf(address(this)); if (totalUsdtPool == 0) { return 0; } uint256 singlePeriodReward = totalUsdtPool.div(totalStakers); // Multiply by number of periods elapsed for compounding effect return singlePeriodReward.mul(periodsElapsed); } /// Check if user can unstake (lockup period passed) function canUnstake(address user) public view returns (bool) { StakeInfo memory userStake = stakes[user]; if (!userStake.isActive) return false; return block.timestamp >= userStake.stakeTime.add(LOCKUP_PERIOD); } /// Check if staker still owns their staked NFT function stakerStillOwnsNFT(address user) public view returns (bool) { StakeInfo memory userStake = stakes[user]; if (!userStake.isActive) return false; try nftContract.ownerOf(userStake.diamondTokenId) returns (address owner) { return owner == user; } catch { return false; // NFT might be burned or doesn't exist } } /// Check if a stake is eligible for liquidation (NFT transferred) function isStakeLiquidatable(address user) public view returns (bool) { return stakes[user].isActive && !stakerStillOwnsNFT(user); } /// Get time left in lockup period function getLockupTimeLeft(address user) external view returns (uint256) { StakeInfo memory userStake = stakes[user]; if (!userStake.isActive) return 0; uint256 unlockTime = userStake.stakeTime.add(LOCKUP_PERIOD); if (block.timestamp >= unlockTime) return 0; return unlockTime.sub(block.timestamp); } /// Get how many reward periods have elapsed since last claim function getRewardPeriodsElapsed(address user) external view returns (uint256) { StakeInfo memory userStake = stakes[user]; if (!userStake.isActive) return 0; if (block.timestamp < userStake.lastClaimTime.add(REWARD_PERIOD)) { return 0; // No full periods elapsed yet } uint256 timeSinceLastClaim = block.timestamp.sub(userStake.lastClaimTime); return timeSinceLastClaim.div(REWARD_PERIOD); } /// Get basic staking info for a user function getStakeInfo(address user) external view returns ( uint256 amount, uint256 stakeTime, uint256 lastClaimTime, uint256 diamondTokenId, bool isActive, bool canUnstakeNow ) { StakeInfo memory userStake = stakes[user]; return ( userStake.amount, userStake.stakeTime, userStake.lastClaimTime, userStake.diamondTokenId, userStake.isActive, canUnstake(user) ); } /// Get reward info for a user (separate to avoid stack too deep) function getRewardInfo(address user) external view returns ( uint256 pendingRewards, uint256 rewardPeriodsElapsed, uint256 lockupTimeLeft ) { StakeInfo memory userStake = stakes[user]; uint256 lockupLeft = 0; if (userStake.isActive && block.timestamp < userStake.stakeTime.add(LOCKUP_PERIOD)) { lockupLeft = userStake.stakeTime.add(LOCKUP_PERIOD).sub(block.timestamp); } // Calculate periods elapsed inline to avoid external call uint256 periodsElapsed = 0; if (userStake.isActive && block.timestamp >= userStake.lastClaimTime.add(REWARD_PERIOD)) { uint256 timeSinceLastClaim = block.timestamp.sub(userStake.lastClaimTime); periodsElapsed = timeSinceLastClaim.div(REWARD_PERIOD); } return ( getPendingRewards(user), periodsElapsed, lockupLeft ); } /* ─────────────────── Staking Functions ─────────────────── */ /// Stake PRIVIX tokens with diamond NFT verification function stake(uint256 diamondTokenId) external nonReentrant { require(!stakes[msg.sender].isActive, "Already staking"); require(diamondTokenId >= DIAMOND_START && diamondTokenId <= DIAMOND_END, "Invalid diamond token ID"); require(nftContract.ownerOf(diamondTokenId) == msg.sender, "Not owner of this NFT"); require(!nftUsedForStaking[diamondTokenId], "NFT already used for staking"); string memory tier = nftContract.getTier(diamondTokenId); require(keccak256(bytes(tier)) == keccak256(bytes("Diamond")), "NFT is not Diamond tier"); require( privixToken.transferFrom(msg.sender, address(this), STAKING_AMOUNT), "PRIVIX transfer failed" ); // Record stake stakes[msg.sender] = StakeInfo({ amount: STAKING_AMOUNT, stakeTime: block.timestamp, lastClaimTime: block.timestamp, diamondTokenId: diamondTokenId, isActive: true }); // Mark NFT as used for staking nftUsedForStaking[diamondTokenId] = true; // Update pool stats totalStaked = totalStaked.add(STAKING_AMOUNT); totalStakers = totalStakers.add(1); emit Staked(msg.sender, STAKING_AMOUNT, diamondTokenId, block.timestamp); } /// Claim pending rewards (every 30 days + must own NFT) function claimRewards() external nonReentrant { require(stakes[msg.sender].isActive, "No active stake"); require(stakerStillOwnsNFT(msg.sender), "NFT no longer owned - stake liquidated"); require( block.timestamp >= stakes[msg.sender].lastClaimTime.add(LOCKUP_PERIOD), "Must wait 30 days between claims" ); uint256 pending = getPendingRewards(msg.sender); require(pending > 0, "No rewards to claim"); // Update last claim time stakes[msg.sender].lastClaimTime = block.timestamp; // Transfer USDT rewards require(usdtToken.transfer(msg.sender, pending), "USDT transfer failed"); totalRewardsPaid = totalRewardsPaid.add(pending); emit RewardsClaimed(msg.sender, pending, block.timestamp); } /// Unstake tokens (after lockup period) function unstake() external nonReentrant { require(stakes[msg.sender].isActive, "No active stake"); require(canUnstake(msg.sender), "Still in lockup period"); StakeInfo memory userStake = stakes[msg.sender]; require(privixToken.transfer(msg.sender, userStake.amount), "PRIVIX transfer failed"); nftUsedForStaking[userStake.diamondTokenId] = false; // Clear stake data delete stakes[msg.sender]; // Update pool stats totalStaked = totalStaked.sub(userStake.amount); totalStakers = totalStakers.sub(1); emit Unstaked(msg.sender, userStake.amount, block.timestamp); } function liquidateStake(address user) external onlyOwner nonReentrant { require(stakes[user].isActive, "No active stake"); require(isStakeLiquidatable(user), "Stake not liquidatable"); StakeInfo memory userStake = stakes[user]; // Free up the NFT for others to use nftUsedForStaking[userStake.diamondTokenId] = false; // Completely remove the stake data - user loses all claim to rewards delete stakes[user]; // Update pool stats (remove from active staking) totalStaked = totalStaked.sub(userStake.amount); totalStakers = totalStakers.sub(1); emit StakeLiquidated(user, userStake.amount, userStake.diamondTokenId, msg.sender); } /// Add USDT to reward pool function addRewards(uint256 amount) external { require(usdtToken.transferFrom(msg.sender, address(this), amount), "USDT transfer failed"); } /* ─────────────────── Owner Functions ─────────────────── */ /// Owner emergency functions function ownerWithdrawPrivix(uint256 amount) external onlyOwner nonReentrant { require(privixToken.transfer(owner(), amount), "Transfer failed"); } function ownerWithdrawUsdt(uint256 amount) external onlyOwner nonReentrant { require(usdtToken.transfer(owner(), amount), "Transfer failed"); } /// Get pool statistics function getPoolStats() external view returns ( uint256 _totalStaked, uint256 _totalStakers, uint256 _totalRewardsPaid, uint256 _rewardPoolBalance, uint256 _contractPrivixBalance, uint256 _contractUsdtBalance, uint256 _rewardPerStaker ) { uint256 rewardPerStaker = totalStakers > 0 ? usdtToken.balanceOf(address(this)).div(totalStakers) : 0; return ( totalStaked, totalStakers, totalRewardsPaid, usdtToken.balanceOf(address(this)), // Total USDT pool privixToken.balanceOf(address(this)), usdtToken.balanceOf(address(this)), rewardPerStaker // USDT per staker if distributed now ); } }
Read Contract
DIAMOND_END 0xfb99c064 → uint256
DIAMOND_START 0xed49893d → uint256
LOCKUP_PERIOD 0xec16d076 → uint256
REWARD_PERIOD 0x0a171df8 → uint256
STAKING_AMOUNT 0xe7f5aad9 → uint256
canUnstake 0x85f4498b → bool
getAvailableDiamondNFTs 0x5dad25bc → uint256[]
getLockupTimeLeft 0xc29f5d97 → uint256
getPendingRewards 0xf6ed2017 → uint256
getPoolStats 0xbbb85188 → uint256, uint256, uint256, uint256, uint256, uint256, uint256
getRewardInfo 0x06032d74 → uint256, uint256, uint256
getRewardPeriodsElapsed 0x922aa0e7 → uint256
getStakeInfo 0xc3453153 → uint256, uint256, uint256, uint256, bool, bool
isStakeLiquidatable 0x84ce14b0 → bool
nftContract 0xd56d229d → address
nftUsedForStaking 0x26d02dea → bool
owner 0x8da5cb5b → address
privixToken 0x7628fd40 → address
stakerStillOwnsNFT 0xddd710fb → bool
stakes 0x16934fc4 → uint256, uint256, uint256, uint256, bool
totalRewardsPaid 0x74958e35 → uint256
totalStaked 0x817b1cd2 → uint256
totalStakers 0x86989038 → uint256
usdtToken 0xa98ad46c → address
userOwnsDiamondNFT 0xdb14f6bc → bool, uint256[]
Write Contract 9 functions
These functions modify contract state and require a wallet transaction to execute.
addRewards 0xbeceed39
uint256 amount
claimRewards 0x372500ab
No parameters
liquidateStake 0xb310ce5a
address user
ownerWithdrawPrivix 0x71aaad33
uint256 amount
ownerWithdrawUsdt 0x4ee13a88
uint256 amount
renounceOwnership 0x715018a6
No parameters
stake 0xa694fc3a
uint256 diamondTokenId
transferOwnership 0xf2fde38b
address newOwner
unstake 0x2def6620
No parameters
Recent Transactions
No transactions found for this address