Address Contract Verified
Address
0xA760212ef90b5D4Be755FF7DAa546420D7fD6663
Balance
0 ETH
Nonce
1
Code Size
9989 bytes
Creator
0xB6E8cdb6...adD6 at tx 0xe4c7f2f1...ee7158
Indexed Transactions
0
Contract Bytecode
9989 bytes
0x608060405234801561001057600080fd5b50600436106101a35760003560e01c80637504db3e116100ee578063b8e7023d11610097578063d2acd13d11610071578063d2acd13d14610436578063f2fde38b14610449578063f3a6bd521461045c578063f7c618c11461046f57600080fd5b8063b8e7023d146103e7578063bb0fd147146103fa578063bca568421461040d57600080fd5b80638da5cb5b116100c85780638da5cb5b146103a257806390a6bd51146103b35780639be65a60146103d457600080fd5b80637504db3e146103695780637b0472f01461037c57806388f2de9f1461038f57600080fd5b80632e17de78116101505780636588103b1161012a5780636588103b1461030d578063666c4b5c14610338578063715018a61461036157600080fd5b80632e17de78146102d4578063532224f4146102e757806361cab72d146102fa57600080fd5b80631bbda52b116101815780631bbda52b146102855780632716ae661461029a5780632a182489146102b157600080fd5b8063068bcd8d146101a857806309813482146101f9578063150b7a0214610236575b600080fd5b6101bb6101b63660046120e8565b610482565b6040516101f0919081518152602080830151908201526040808301511515908201526060918201519181019190915260800190565b60405180910390f35b61020c6102073660046120e8565b61053c565b604080516001600160a01b03909516855260208501939093529183015260608201526080016101f0565b61025461024436600461212c565b630a85bd0160e11b949350505050565b6040517fffffffff0000000000000000000000000000000000000000000000000000000090911681526020016101f0565b610298610293366004612258565b610631565b005b6102a360025481565b6040519081526020016101f0565b6102c46102bf3660046120e8565b6107bd565b60405190151581526020016101f0565b6102986102e23660046120e8565b610817565b6102986102f53660046122bc565b61093a565b6102986103083660046122e9565b610a4f565b600454610320906001600160a01b031681565b6040516001600160a01b0390911681526020016101f0565b6102a3610346366004612305565b6001600160a01b031660009081526008602052604090205490565b610298610b13565b610298610377366004612305565b610b67565b61029861038a366004612322565b610c18565b6102c461039d3660046120e8565b610d6d565b6000546001600160a01b0316610320565b6103c66103c1366004612344565b610df9565b6040516101f0929190612379565b6102986103e2366004612305565b610f29565b6102986103f5366004612322565b6110a5565b6102986104083660046123c1565b6111ff565b6102a361041b366004612305565b6001600160a01b031660009081526007602052604090205490565b6102986104443660046123ed565b611356565b610298610457366004612305565b6114d0565b61029861046a366004612258565b611589565b600554610320906001600160a01b031681565b6104af60405180608001604052806000815260200160008152602001600015158152602001600081525090565b60025482106104f35760405162461bcd60e51b815260206004820152601b602482015260008051602061269083398151915260448201526064015b60405180910390fd5b506000908152600160208181526040928390208351608081018552815481529281015491830191909152600281015460ff16151592820192909252600390910154606082015290565b6000818152600660205260408120600201548190819081906001600160a01b03166105a95760405162461bcd60e51b815260206004820152601760248201527f5374616b653a20546f6b656e206e6f74207374616b656400000000000000000060448201526064016104ea565b600085815260066020908152604080832081516060810183528154815260018201549381018490526002909101546001600160a01b03169181019190915291906105f290610482565b905081604001518260200151826020015184600001516106129190612445565b835185516106209190612445565b955095509550955050509193509193565b8260025481106106715760405162461bcd60e51b815260206004820152601b602482015260008051602061269083398151915260448201526064016104ea565b60008181526001602052604090206002015460ff166106d25760405162461bcd60e51b815260206004820152601860248201527f506f6f6c61626c653a20506f6f6c20697320636c6f736564000000000000000060448201526064016104ea565b600260035414156107255760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016104ea565b60026003553360005b8381101561076b57610759828787878581811061074d5761074d61245d565b90506020020135611748565b8061076381612473565b91505061072e565b50806001600160a01b03167f9cb8bf6c3e49c9547ec614a3c027ea19c19d43d5c7a00755e304b742923874238686866040516107a9939291906124dd565b60405180910390a250506001600355505050565b600060025482106107fe5760405162461bcd60e51b815260206004820152601b602482015260008051602061269083398151915260448201526064016104ea565b5060009081526001602052604090206002015460ff1690565b6002600354141561086a5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016104ea565b60026003819055600082815260066020526040902001546001600160a01b031633146108d45760405162461bcd60e51b815260206004820152601960248201527829ba30b5b29d102737ba1037bbb732b91037b3103a37b5b2b760391b60448201526064016104ea565b3360006108e18284611832565b90506108ed8282611980565b816001600160a01b03167f85082129d87b2fe11527cb1b3b7a520aeb5aa6913f88a3d8757fe40d1db02fdd8460405161092891815260200190565b60405180910390a25050600160035550565b6000546001600160a01b031633146109825760405162461bcd60e51b815260206004820181905260248201526000805160206126b083398151915260448201526064016104ea565b60025482106109c15760405162461bcd60e51b815260206004820152601b602482015260008051602061269083398151915260448201526064016104ea565b600082815260016020818152604092839020843581559084013591810191909155906109f39060608401908401612505565b60028201805460ff1916911515919091179055606082013560038201556040517f7bc88466db0a5c28612bd0db9ed2dc9e57583c2b25548d1a7b33a1b57d3f8c0f90610a429085908490612522565b60405180910390a1505050565b6000546001600160a01b03163314610a975760405162461bcd60e51b815260206004820181905260248201526000805160206126b083398151915260448201526064016104ea565b60025460008181526001602052604090208290610ab48282612558565b5050600254610ac4906001612445565b6002556000818152600160205260409081902090517ff170715f6c4300e572bf83fd219333fb050850fff498e5f52595f1e13dc0e20b91610b0791849190612522565b60405180910390a15050565b6000546001600160a01b03163314610b5b5760405162461bcd60e51b815260206004820181905260248201526000805160206126b083398151915260448201526064016104ea565b610b6560006119d1565b565b6000546001600160a01b03163314610baf5760405162461bcd60e51b815260206004820181905260248201526000805160206126b083398151915260448201526064016104ea565b60405147906001600160a01b0383169082156108fc029083906000818181858888f19350505050158015610be7573d6000803e3d6000fd5b506040518181527f5c0a34c718716ee467140afbc9fb741fc2980e41d00f04a8f7f635d76484ff4790602001610b07565b816002548110610c585760405162461bcd60e51b815260206004820152601b602482015260008051602061269083398151915260448201526064016104ea565b60008181526001602052604090206002015460ff16610cb95760405162461bcd60e51b815260206004820152601860248201527f506f6f6c61626c653a20506f6f6c20697320636c6f736564000000000000000060448201526064016104ea565b60026003541415610d0c5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016104ea565b600260035533610d1d818585611748565b60408051858152602081018590526001600160a01b038316917f5af417134f72a9d41143ace85b0a26dce6f550f894f2cbc1eeee8810603d91b691015b60405180910390a2505060016003555050565b6000818152600660205260408120600201546001600160a01b0316610dd45760405162461bcd60e51b815260206004820152601760248201527f5374616b653a20546f6b656e206e6f74207374616b656400000000000000000060448201526064016104ea565b600082815260066020526040902060018101549054610df39190611a21565b92915050565b6001600160a01b038316600090815260076020526040812054606091908490610e23908590612599565b811115610e51576001600160a01b038616600090815260076020526040902054610e4e908590612599565b90505b60008167ffffffffffffffff811115610e6c57610e6c612116565b604051908082528060200260200182016040528015610e95578160200160208202803683370190505b50905060005b82811015610f0f576001600160a01b0388166000908152600760205260409020610ec58288612445565b81548110610ed557610ed561245d565b9060005260206000200154828281518110610ef257610ef261245d565b602090810291909101015280610f0781612473565b915050610e9b565b5080610f1b8387612445565b935093505050935093915050565b6000546001600160a01b03163314610f715760405162461bcd60e51b815260206004820181905260248201526000805160206126b083398151915260448201526064016104ea565b6040516370a0823160e01b81523060048201526000906001600160a01b038316906370a082319060240160206040518083038186803b158015610fb357600080fd5b505afa158015610fc7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610feb91906125b0565b90508061104a5760405162461bcd60e51b815260206004820152602760248201527f4f7065726174696f6e733a2043616e6e6f74207265636f766572207a65726f2060448201526662616c616e636560c81b60648201526084016104ea565b61105e6001600160a01b0383163383611ad3565b816001600160a01b03167f14f11966a996e0629572e51064726d2057a80fbd34efc066682c06a71dbb6e988260405161109991815260200190565b60405180910390a25050565b600260035414156110f85760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016104ea565b60026003819055600082815260066020526040902001546001600160a01b031633146111625760405162461bcd60e51b815260206004820152601960248201527829ba30b5b29d102737ba1037bbb732b91037b3103a37b5b2b760391b60448201526064016104ea565b33600061116f8484611b3f565b905061117b8282611980565b816001600160a01b03167f85082129d87b2fe11527cb1b3b7a520aeb5aa6913f88a3d8757fe40d1db02fdd846040516111b691815260200190565b60405180910390a260408051858152602081018590526001600160a01b038416917f5af417134f72a9d41143ace85b0a26dce6f550f894f2cbc1eeee8810603d91b69101610d5a565b6000546001600160a01b031633146112475760405162461bcd60e51b815260206004820181905260248201526000805160206126b083398151915260448201526064016104ea565b6004546001600160a01b03838116911614156112b55760405162461bcd60e51b815260206004820152602760248201527f5374616b653a2043616e6e6f74207265636f766572207374616b656420636f6c6044820152663632b1ba34b7b760c91b60648201526084016104ea565b6040516323b872dd60e01b8152306004820152336024820152604481018290526001600160a01b038316906323b872dd90606401600060405180830381600087803b15801561130357600080fd5b505af1158015611317573d6000803e3d6000fd5b50505050816001600160a01b03167f861c3ea25dbda3af0bf5d258ba8582c0276c9446b1479e817be3f1b4a89acf918260405161109991815260200190565b600260035414156113a95760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016104ea565b6002600355336000805b8381101561148a57826001600160a01b0316600660008787858181106113db576113db61245d565b60209081029290920135835250810191909152604001600020600201546001600160a01b03161461144a5760405162461bcd60e51b815260206004820152601960248201527829ba30b5b29d102737ba1037bbb732b91037b3103a37b5b2b760391b60448201526064016104ea565b61146c838686848181106114605761146061245d565b90506020020135611832565b6114769083612445565b91508061148281612473565b9150506113b3565b506114958282611980565b816001600160a01b03167f82d1e5b1747de628b87fc583915fd7ba5a43d2d1195c691ea894ba77cda297df8585604051610d5a9291906125c9565b6000546001600160a01b031633146115185760405162461bcd60e51b815260206004820181905260248201526000805160206126b083398151915260448201526064016104ea565b6001600160a01b03811661157d5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016104ea565b611586816119d1565b50565b600260035414156115dc5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016104ea565b6002600355336000805b838110156116bd57826001600160a01b03166006600087878581811061160e5761160e61245d565b60209081029290920135835250810191909152604001600020600201546001600160a01b03161461167d5760405162461bcd60e51b815260206004820152601960248201527829ba30b5b29d102737ba1037bbb732b91037b3103a37b5b2b760391b60448201526064016104ea565b61169f868686848181106116935761169361245d565b90506020020135611b3f565b6116a99083612445565b9150806116b581612473565b9150506115e6565b506116c88282611980565b816001600160a01b03167f82d1e5b1747de628b87fc583915fd7ba5a43d2d1195c691ea894ba77cda297df85856040516117039291906125c9565b60405180910390a2816001600160a01b03167f9cb8bf6c3e49c9547ec614a3c027ea19c19d43d5c7a00755e304b742923874238686866040516107a9939291906124dd565b60048054604051632142170760e11b81526001600160a01b0386811693820193909352306024820152604481018490529116906342842e0e90606401600060405180830381600087803b15801561179e57600080fd5b505af11580156117b2573d6000803e3d6000fd5b50506040805160608101825242815260208082019687526001600160a01b039788168284018181526000888152600684528581209451855598516001808601919091559051600290940180546001600160a01b03191694909a16939093179098559686526007875290852080549182018155855294909320909301555050565b600081815260066020526040812060018101549054611852908290611c48565b61189e5760405162461bcd60e51b815260206004820152601960248201527f5374616b653a204e6f742079657420756e7374616b61626c650000000000000060448201526064016104ea565b6000838152600660205260408120546118b8908390611a21565b60048054604051632142170760e11b815230928101929092526001600160a01b0388811660248401526044830188905292935091909116906342842e0e90606401600060405180830381600087803b15801561191357600080fd5b505af1158015611927573d6000803e3d6000fd5b505050506119358585611cf5565b60008481526006602052604081208181556001810182905560020180546001600160a01b0319169055811561197757600061196f84610482565b606001519150505b95945050505050565b80156119cd576119908282611e21565b6001600160a01b0382166000908152600860205260409020546119b39082611e8b565b6001600160a01b0383166000908152600860205260409020555b5050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60006002548310611a625760405162461bcd60e51b815260206004820152601b602482015260008051602061269083398151915260448201526064016104ea565b428210611ab15760405162461bcd60e51b815260206004820152601e60248201527f506f6f6c61626c653a20496e76616c6964206465706f7369742064617465000060448201526064016104ea565b600083815260016020526040902054611aca8342612599565b10159392505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1663a9059cbb60e01b179052611b3a908490611e9e565b505050565b6000611b4a836107bd565b611b965760405162461bcd60e51b815260206004820152601560248201527f5374616b653a20506f6f6c20697320636c6f736564000000000000000000000060448201526064016104ea565b600082815260066020526040902060018101549054611bb6908290611c48565b611c025760405162461bcd60e51b815260206004820152601960248201527f5374616b653a204e6f742079657420756e7374616b61626c650000000000000060448201526064016104ea565b600083815260066020526040812054611c1c908390611a21565b600085815260066020526040812060018101889055429055909150811561197757600061196f84610482565b60006002548310611c895760405162461bcd60e51b815260206004820152601b602482015260008051602061269083398151915260448201526064016104ea565b428210611cd85760405162461bcd60e51b815260206004820152601e60248201527f506f6f6c61626c653a20496e76616c6964206465706f7369742064617465000060448201526064016104ea565b60008381526001602081905260409091200154611aca8342612599565b600080805b6001600160a01b038516600090815260076020526040902054811015611dbe576001600160a01b0385166000908152600760205260409020805482908110611d4457611d4461245d565b9060005260206000200154915083821415611d6b57611d64836001612445565b9250611dac565b6001600160a01b03851660009081526007602052604090208290611d8f8584612599565b81548110611d9f57611d9f61245d565b6000918252602090912001555b80611db681612473565b915050611cfa565b5060005b82811015611e1a576001600160a01b0385166000908152600760205260409020805480611df157611df16125dd565b600190038181906000526020600020016000905590558080611e1290612473565b915050611dc2565b5050505050565b6005546040516340c10f1960e01b81526001600160a01b03848116600483015260248201849052909116906340c10f1990604401600060405180830381600087803b158015611e6f57600080fd5b505af1158015611e83573d6000803e3d6000fd5b505050505050565b6000611e978284612445565b9392505050565b6000611ef3826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316611f709092919063ffffffff16565b805190915015611b3a5780806020019051810190611f1191906125f3565b611b3a5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016104ea565b6060611f7f8484600085611f87565b949350505050565b606082471015611fe85760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016104ea565b843b6120365760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016104ea565b600080866001600160a01b031685876040516120529190612640565b60006040518083038185875af1925050503d806000811461208f576040519150601f19603f3d011682016040523d82523d6000602084013e612094565b606091505b50915091506120a48282866120af565b979650505050505050565b606083156120be575081611e97565b8251156120ce5782518084602001fd5b8160405162461bcd60e51b81526004016104ea919061265c565b6000602082840312156120fa57600080fd5b5035919050565b6001600160a01b038116811461158657600080fd5b634e487b7160e01b600052604160045260246000fd5b6000806000806080858703121561214257600080fd5b843561214d81612101565b9350602085013561215d81612101565b925060408501359150606085013567ffffffffffffffff8082111561218157600080fd5b818701915087601f83011261219557600080fd5b8135818111156121a7576121a7612116565b604051601f8201601f19908116603f011681019083821181831017156121cf576121cf612116565b816040528281528a60208487010111156121e857600080fd5b82602086016020830137600060208483010152809550505050505092959194509250565b60008083601f84011261221e57600080fd5b50813567ffffffffffffffff81111561223657600080fd5b6020830191508360208260051b850101111561225157600080fd5b9250929050565b60008060006040848603121561226d57600080fd5b83359250602084013567ffffffffffffffff81111561228b57600080fd5b6122978682870161220c565b9497909650939450505050565b6000608082840312156122b657600080fd5b50919050565b60008060a083850312156122cf57600080fd5b823591506122e084602085016122a4565b90509250929050565b6000608082840312156122fb57600080fd5b611e9783836122a4565b60006020828403121561231757600080fd5b8135611e9781612101565b6000806040838503121561233557600080fd5b50508035926020909101359150565b60008060006060848603121561235957600080fd5b833561236481612101565b95602085013595506040909401359392505050565b604080825283519082018190526000906020906060840190828701845b828110156123b257815184529284019290840190600101612396565b50505092019290925292915050565b600080604083850312156123d457600080fd5b82356123df81612101565b946020939093013593505050565b6000806020838503121561240057600080fd5b823567ffffffffffffffff81111561241757600080fd5b6124238582860161220c565b90969095509350505050565b634e487b7160e01b600052601160045260246000fd5b600082198211156124585761245861242f565b500190565b634e487b7160e01b600052603260045260246000fd5b60006000198214156124875761248761242f565b5060010190565b81835260007f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8311156124c057600080fd5b8260051b8083602087013760009401602001938452509192915050565b83815260406020820152600061197760408301848661248e565b801515811461158657600080fd5b60006020828403121561251757600080fd5b8135611e97816124f7565b8281528154602082015260018201546040820152600282015460ff16151560608201526003820154608082015260a08101611e97565b8135815560208201356001820155600281016040830135612578816124f7565b60ff1982541660ff8215151681178355505050606082013560038201555050565b6000828210156125ab576125ab61242f565b500390565b6000602082840312156125c257600080fd5b5051919050565b602081526000611f7f60208301848661248e565b634e487b7160e01b600052603160045260246000fd5b60006020828403121561260557600080fd5b8151611e97816124f7565b60005b8381101561262b578181015183820152602001612613565b8381111561263a576000848401525b50505050565b60008251612652818460208701612610565b9190910192915050565b602081526000825180602084015261267b816040850160208701612610565b601f01601f1916919091016040019291505056fe506f6f6c61626c653a20496e76616c696420706f6f6c496e64657800000000004f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572a26469706673582212201191b02097a38414652b544e8ce624fe03e86bb68cc0e63d4f1bb0bcccf9886764736f6c63430008090033
Verified Source Code Full Match
Compiler: v0.8.9+commit.e5eed63a
EVM: london
Optimization: Yes (500 runs)
NftStakeVaultV2.sol 228 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma abicoder v2;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@minting-station/contracts/contracts/libraries/Poolable.sol";
import "@minting-station/contracts/contracts/libraries/Recoverable.sol";
/** @title NftStakeVaultV2
*/
contract NftStakeVaultV2 is Ownable, Poolable, Recoverable, ReentrancyGuard, ERC721Holder {
using SafeMath for uint256;
using SafeERC20 for IERC20;
struct PoolDeposit {
uint256 depositDate;
uint256 pool;
address owner;
}
IERC721 public nftCollection;
IERC20 public rewardToken;
// poolDeposit per tokenId
mapping(uint256 => PoolDeposit) _deposits;
// owner to tokenId mapping
mapping(address => uint256[]) _userTokens;
// user rewards mapping
mapping(address => uint256) _userRewards;
event Stake(address indexed account, uint256 poolId, uint256 tokenId);
event Unstake(address indexed account, uint256 tokenId);
constructor(IERC721 _nftCollection, IERC20 _rewardToken) {
nftCollection = _nftCollection;
rewardToken = _rewardToken;
}
function _popToken(address account, uint256 tokenId) private {
uint256 delta = 0;
uint256 token;
for (uint256 i = 0; i < _userTokens[account].length; i++) {
token = _userTokens[account][i];
if (token == tokenId) {
delta = delta + 1;
}
else {
_userTokens[account][i - delta] = token;
}
}
for (uint256 i = 0; i < delta; i++) {
_userTokens[account].pop();
}
}
function _sendRewards(address destination, uint256 amount) internal virtual {
rewardToken.safeTransfer(destination, amount);
}
function _sendAndUpdateRewards(address account, uint256 amount) internal {
if (amount > 0) {
_sendRewards(account, amount);
_userRewards[account] = _userRewards[account].add(amount);
}
}
function _stake(address account, uint256 poolId, uint256 tokenId) internal {
// transfer token
nftCollection.safeTransferFrom(account, address(this), tokenId);
// add deposit
_deposits[tokenId] = PoolDeposit({depositDate: block.timestamp, pool: poolId, owner: account});
_userTokens[account].push(tokenId);
}
/**
* @notice Stake a token from the collection
*/
function stake(uint256 poolId, uint256 tokenId) external whenPoolOpened(poolId) nonReentrant {
address account = _msgSender();
_stake(account, poolId, tokenId);
emit Stake(account, poolId, tokenId);
}
function _unstake(address account, uint256 tokenId) internal returns (uint256) {
uint256 poolId = _deposits[tokenId].pool;
require(isUnlockable(poolId, _deposits[tokenId].depositDate), "Stake: Not yet unstakable");
bool unlocked = isUnlocked(poolId, _deposits[tokenId].depositDate);
// transfer token
nftCollection.safeTransferFrom(address(this), account, tokenId);
// update deposit
_popToken(account, tokenId);
delete _deposits[tokenId];
uint256 rewards = 0;
if (unlocked) {
Pool memory pool = getPool(poolId);
rewards = pool.rewardAmount;
}
return rewards;
}
/**
* @notice Unstake a token
*/
function unstake(uint256 tokenId) external nonReentrant {
require(_deposits[tokenId].owner == _msgSender(), "Stake: Not owner of token");
address account = _msgSender();
uint256 rewards = _unstake(account, tokenId);
_sendAndUpdateRewards(account, rewards);
emit Unstake(account, tokenId);
}
function _restake(uint256 newPoolId, uint256 tokenId) internal returns (uint256) {
require(isPoolOpened(newPoolId), "Stake: Pool is closed");
uint256 oldPoolId = _deposits[tokenId].pool;
require(isUnlockable(oldPoolId, _deposits[tokenId].depositDate), "Stake: Not yet unstakable");
bool unlocked = isUnlocked(oldPoolId, _deposits[tokenId].depositDate);
// update deposit
_deposits[tokenId].pool = newPoolId;
_deposits[tokenId].depositDate = block.timestamp;
uint256 rewards = 0;
if (unlocked) {
Pool memory pool = getPool(oldPoolId);
rewards = pool.rewardAmount;
}
return rewards;
}
/**
* @notice Allow a user to [re]stake a token in a new pool without unstaking it first.
*/
function restake(uint256 newPoolId, uint256 tokenId) external nonReentrant {
require(_deposits[tokenId].owner == _msgSender(), "Stake: Not owner of token");
address account = _msgSender();
uint256 rewards = _restake(newPoolId, tokenId);
_sendAndUpdateRewards(account, rewards);
emit Unstake(account, tokenId);
emit Stake(account, newPoolId, tokenId);
}
/**
* @notice Checks if a token has been deposited for enough time to get rewards
*/
function isTokenUnlocked(uint256 tokenId) public view returns (bool) {
require(_deposits[tokenId].owner != address(0), "Stake: Token not staked");
return isUnlocked(_deposits[tokenId].pool, _deposits[tokenId].depositDate);
}
/**
* @notice Get the stake detail for a token (owner, poolId, min unstakable date, reward unlock date)
*/
function getStakeInfo(uint256 tokenId)
external
view
returns (
address, // owner
uint256, // poolId
uint256, // unlock date
uint256 // reward date
)
{
require(_deposits[tokenId].owner != address(0), "Stake: Token not staked");
PoolDeposit memory deposit = _deposits[tokenId];
Pool memory pool = getPool(deposit.pool);
return (deposit.owner, deposit.pool, deposit.depositDate + pool.minDuration, deposit.depositDate + pool.lockDuration);
}
/**
* @notice Get the number of tokens staked by a user
*/
function getUserStakedTokensCount(address account) external view returns (uint256) {
return _userTokens[account].length;
}
/**
* @notice Get the list of tokens staked by a user
*/
function getUserStakedTokens(
address account,
uint256 size,
uint256 cursor
) external view returns (uint256[] memory, uint256) {
uint256 length = size;
if (length > _userTokens[account].length - cursor) {
length = _userTokens[account].length - cursor;
}
uint256[] memory values = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
values[i] = _userTokens[account][cursor + i];
}
return (values, cursor + length);
}
/**
* @notice Returns the total reward for a user
*/
function getUserTotalRewards(address account) external view returns (uint256) {
return _userRewards[account];
}
function recoverNonFungibleToken(address _token, uint256 _tokenId) external override onlyOwner {
// staked collection cannot be recovered by admin
require(_token != address(nftCollection), "Stake: Cannot recover staked collection");
IERC721(_token).transferFrom(address(this), address(msg.sender), _tokenId);
emit NonFungibleTokenRecovery(_token, _tokenId);
}
}
SamuraiSagaStakeVaultV2.sol 58 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./interfaces/IMintableERC20.sol";
import "./NftStakeVaultV2.sol";
/** @title SamuraiSagaStakeVaultV2
*/
contract SamuraiSagaStakeVaultV2 is NftStakeVaultV2 {
event BatchStake(address indexed account, uint256 poolId, uint256[] tokenIds);
event BatchUnstake(address indexed account, uint256[] tokenIds);
constructor(IERC721 _nftCollection, IMintableERC20 _rewardToken)
NftStakeVaultV2(_nftCollection, _rewardToken) {
}
function _sendRewards(address destination, uint256 amount) internal override {
IMintableERC20(address(rewardToken)).mint(destination, amount);
}
function batchStake(uint256 poolId, uint256[] calldata tokenIds) external whenPoolOpened(poolId) nonReentrant {
address account = _msgSender();
for (uint256 i = 0; i < tokenIds.length; i++) {
_stake(account, poolId, tokenIds[i]);
}
emit BatchStake(account, poolId, tokenIds);
}
function batchUnstake(uint256[] calldata tokenIds) external nonReentrant {
address account = _msgSender();
uint256 rewards = 0;
for (uint256 i = 0; i < tokenIds.length; i++) {
require(_deposits[tokenIds[i]].owner == account, "Stake: Not owner of token");
rewards = rewards + _unstake(account, tokenIds[i]);
}
_sendAndUpdateRewards(account, rewards);
emit BatchUnstake(account, tokenIds);
}
function batchRestake(uint256 poolId, uint256[] calldata tokenIds) external nonReentrant {
address account = _msgSender();
uint256 rewards = 0;
for (uint256 i = 0; i < tokenIds.length; i++) {
require(_deposits[tokenIds[i]].owner == account, "Stake: Not owner of token");
rewards = rewards + _restake(poolId, tokenIds[i]);
}
_sendAndUpdateRewards(account, rewards);
emit BatchUnstake(account, tokenIds);
emit BatchStake(account, poolId, tokenIds);
}
}
IMintableERC20.sol 9 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface IMintableERC20 is IERC20 {
function mint(address destination, uint256 amount) external;
}
Address.sol 217 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Address.sol)
pragma solidity ^0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
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;
}
}
Ownable.sol 76 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (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 Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing 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);
}
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
SafeMath.sol 227 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (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 substraction 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;
}
}
}
IERC721.sol 143 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (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`, 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 be 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: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* 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 Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @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 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);
/**
* @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;
}
ReentrancyGuard.sol 63 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (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() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
SafeERC20.sol 99 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
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);
}
IERC721Receiver.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
Poolable.sol 104 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma abicoder v2;
import "@openzeppelin/contracts/access/Ownable.sol";
/** @title Poolable.
@dev This contract manage configuration of pools
*/
abstract contract Poolable is Ownable {
struct Pool {
uint256 lockDuration; // locked timespan
uint256 minDuration; // min deposit timespan
bool opened; // flag indicating if the pool is open
uint256 rewardAmount; // amount rewarded when lockDuration is reached
}
// pools mapping
mapping(uint256 => Pool) private _pools;
uint256 public poolsLength;
/**
* @dev Emitted when a pool is created
*/
event PoolAdded(uint256 poolIndex, Pool pool);
/**
* @dev Emitted when a pool is updated
*/
event PoolUpdated(uint256 poolIndex, Pool pool);
/**
* @dev Modifier that checks that the pool at index `poolIndex` is open
*/
modifier whenPoolOpened(uint256 poolIndex) {
require(poolIndex < poolsLength, "Poolable: Invalid poolIndex");
require(_pools[poolIndex].opened, "Poolable: Pool is closed");
_;
}
/**
* @dev Modifier that checks that the now() - `depositDate` is above or equal to the min lock duration for pool at index `poolIndex`
*/
modifier whenUnlocked(uint256 poolIndex, uint256 depositDate) {
require(
isUnlocked(poolIndex, depositDate),
"Poolable: Not unlocked"
);
_;
}
function getPool(uint256 poolIndex) public view returns (Pool memory) {
require(poolIndex < poolsLength, "Poolable: Invalid poolIndex");
return _pools[poolIndex];
}
function addPool(Pool calldata pool) external onlyOwner {
uint256 poolIndex = poolsLength;
_pools[poolIndex] = pool;
poolsLength = poolsLength + 1;
emit PoolAdded(poolIndex, _pools[poolIndex]);
}
function updatePool(uint256 poolIndex, Pool calldata pool)
external
onlyOwner
{
require(poolIndex < poolsLength, "Poolable: Invalid poolIndex");
Pool storage editedPool = _pools[poolIndex];
editedPool.lockDuration = pool.lockDuration;
editedPool.minDuration = pool.minDuration;
editedPool.opened = pool.opened;
editedPool.rewardAmount = pool.rewardAmount;
emit PoolUpdated(poolIndex, editedPool);
}
function isUnlocked(uint256 poolIndex, uint256 depositDate) internal view returns (bool) {
require(poolIndex < poolsLength, "Poolable: Invalid poolIndex");
require(
depositDate < block.timestamp,
"Poolable: Invalid deposit date"
);
return block.timestamp - depositDate >= _pools[poolIndex].lockDuration;
}
function isUnlockable(uint256 poolIndex, uint256 depositDate) internal view returns (bool) {
require(poolIndex < poolsLength, "Poolable: Invalid poolIndex");
require(
depositDate < block.timestamp,
"Poolable: Invalid deposit date"
);
return block.timestamp - depositDate >= _pools[poolIndex].minDuration;
}
function isPoolOpened(uint256 poolIndex) public view returns (bool) {
require(poolIndex < poolsLength, "Poolable: Invalid poolIndex");
return _pools[poolIndex].opened;
}
}
ERC721Holder.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/utils/ERC721Holder.sol)
pragma solidity ^0.8.0;
import "../IERC721Receiver.sol";
/**
* @dev Implementation of the {IERC721Receiver} interface.
*
* Accepts all token transfers.
* Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}.
*/
contract ERC721Holder is IERC721Receiver {
/**
* @dev See {IERC721Receiver-onERC721Received}.
*
* Always returns `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address,
address,
uint256,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC721Received.selector;
}
}
Recoverable.sol 48 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma abicoder v2;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "../interfaces/IRecoverable.sol";
abstract contract Recoverable is Ownable, IRecoverable {
using SafeERC20 for IERC20;
event NonFungibleTokenRecovery(address indexed token, uint256 tokenId);
event TokenRecovery(address indexed token, uint256 amount);
event EthRecovery(uint256 amount);
/**
* @notice Allows the owner to recover non-fungible tokens sent to the contract by mistake
* @param _token: NFT token address
* @param _tokenId: tokenId
* @dev Callable by owner
*/
function recoverNonFungibleToken(address _token, uint256 _tokenId) external virtual onlyOwner {
IERC721(_token).transferFrom(address(this), address(msg.sender), _tokenId);
emit NonFungibleTokenRecovery(_token, _tokenId);
}
/**
* @notice Allows the owner to recover tokens sent to the contract by mistake
* @param _token: token address
* @dev Callable by owner
*/
function recoverToken(address _token) external virtual onlyOwner {
uint256 balance = IERC20(_token).balanceOf(address(this));
require(balance != 0, "Operations: Cannot recover zero balance");
IERC20(_token).safeTransfer(address(msg.sender), balance);
emit TokenRecovery(_token, balance);
}
function recoverEth(address payable _to) external virtual onlyOwner {
uint256 balance = address(this).balance;
_to.transfer(balance);
emit EthRecovery(balance);
}
}
IRecoverable.sol 27 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IRecoverable {
/**
* @notice Allows the owner to recover non-fungible tokens sent to the NFT contract by mistake and this contract
* @param _token: NFT token address
* @param _tokenId: tokenId
* @dev Callable by owner
*/
function recoverNonFungibleToken(address _token, uint256 _tokenId) external;
/**
* @notice Allows the owner to recover tokens sent to the NFT contract and this contract by mistake
* @param _token: token address
* @dev Callable by owner
*/
function recoverToken(address _token) external;
/**
* @notice Allows the owner to recover ETH sent to the NFT contract ans and contract by mistake
* @param _to: target address
* @dev Callable by owner
*/
function recoverEth(address payable _to) external;
}
Read Contract
getPool 0x068bcd8d → tuple
getStakeInfo 0x09813482 → address, uint256, uint256, uint256
getUserStakedTokens 0x90a6bd51 → uint256[], uint256
getUserStakedTokensCount 0xbca56842 → uint256
getUserTotalRewards 0x666c4b5c → uint256
isPoolOpened 0x2a182489 → bool
isTokenUnlocked 0x88f2de9f → bool
nftCollection 0x6588103b → address
owner 0x8da5cb5b → address
poolsLength 0x2716ae66 → uint256
rewardToken 0xf7c618c1 → address
Write Contract 14 functions
These functions modify contract state and require a wallet transaction to execute.
addPool 0x04ee6a83
tuple pool
batchRestake 0xf3a6bd52
uint256 poolId
uint256[] tokenIds
batchStake 0x1bbda52b
uint256 poolId
uint256[] tokenIds
batchUnstake 0xd2acd13d
uint256[] tokenIds
onERC721Received 0x150b7a02
address
address
uint256
bytes
returns: bytes4
recoverEth 0x7504db3e
address _to
recoverNonFungibleToken 0xbb0fd147
address _token
uint256 _tokenId
recoverToken 0x9be65a60
address _token
renounceOwnership 0x715018a6
No parameters
restake 0xb8e7023d
uint256 newPoolId
uint256 tokenId
stake 0x7b0472f0
uint256 poolId
uint256 tokenId
transferOwnership 0xf2fde38b
address newOwner
unstake 0x2e17de78
uint256 tokenId
updatePool 0x0af2d64f
uint256 poolIndex
tuple pool
Recent Transactions
No transactions found for this address