Address Contract Partially Verified
Address
0xAbDF88385995EE5B0EdF388B7c51557e64342c55
Balance
0 ETH
Nonce
1
Code Size
20147 bytes
Creator
0x0CdB34e6...77b8 at tx 0x6527fd97...67fe77
Indexed Transactions
0
Contract Bytecode
20147 bytes
0x60806040526004361061036f5760003560e01c8063715018a6116101c6578063b44a2722116100f7578063dbdf526b11610095578063efe7f82f1161006f578063efe7f82f14610ac3578063f0b7770914610ae3578063f2fde38b14610af9578063fc1be7d514610b1957600080fd5b8063dbdf526b14610a77578063e7a25f8714610a97578063efbd906014610aad57600080fd5b8063cb65b5b5116100d1578063cb65b5b5146109f7578063cdcaf95614610a17578063d6e28c4914610a37578063d74e95df14610a5757600080fd5b8063b44a272214610997578063b4c341e5146109b7578063b67b6df3146109d757600080fd5b80638da5cb5b116101645780639b5f94dc1161013e5780639b5f94dc14610852578063a4063dbc14610872578063acc2166a14610957578063b31287f41461097757600080fd5b80638da5cb5b146107f45780638f8d7a5514610812578063963978f21461083257600080fd5b80638456cb59116101a05780638456cb591461077f5780638617c377146107945780638afc7cb3146107b45780638d9f387d146107d457600080fd5b8063715018a61461073457806375da8421146107495780637fab32aa1461075f57600080fd5b8063400d592b116102a057806358bf14a01161023e578063642c489411610218578063642c4894146106bd5780636839f9d8146106dd5780636a81d9d8146106fd5780636b73e9571461071357600080fd5b806358bf14a0146106595780635c975abb1461067957806362a2416b1461069d57600080fd5b806345a6805d1161027a57806345a6805d146105d857806348ded71c146105f95780634ca6ef28146106195780634f8a74681461063957600080fd5b8063400d592b1461057857806341302c221461059857806342c1e587146105b857600080fd5b80631a4707ed1161030d5780632cfbbfec116102e75780632cfbbfec146105035780632e095a35146105235780633043fed0146105435780633f4ba83a1461056357600080fd5b80631a4707ed146104a357806327d8258d146104c35780632a48235b146104e357600080fd5b80631432d651116103495780631432d651146103fe578063150b7a021461041e578063164af9dd14610463578063198490381461048357600080fd5b8063081e3eda1461037b5780630dae33e1146103a4578063103edada146103dc57600080fd5b3661037657005b600080fd5b34801561038757600080fd5b5061039160d55481565b6040519081526020015b60405180910390f35b3480156103b057600080fd5b5060ca546103c4906001600160a01b031681565b6040516001600160a01b03909116815260200161039b565b3480156103e857600080fd5b506103fc6103f736600461403f565b610b49565b005b34801561040a57600080fd5b506103fc610419366004614103565b611051565b34801561042a57600080fd5b5061044a610439366004614157565b630a85bd0160e11b95945050505050565b6040516001600160e01b0319909116815260200161039b565b34801561046f57600080fd5b5060ce546103c4906001600160a01b031681565b34801561048f57600080fd5b506103fc61049e3660046141f6565b61115f565b3480156104af57600080fd5b506103fc6104be36600461427a565b61123d565b3480156104cf57600080fd5b506103fc6104de3660046142cd565b611303565b3480156104ef57600080fd5b506103c46104fe366004614318565b611381565b34801561050f57600080fd5b5060d0546103c4906001600160a01b031681565b34801561052f57600080fd5b506103fc61053e366004614331565b6113ab565b34801561054f57600080fd5b506103fc61055e366004614318565b611463565b34801561056f57600080fd5b506103fc6114ca565b34801561058457600080fd5b506103fc610593366004614388565b6114dc565b3480156105a457600080fd5b5060cf546103c4906001600160a01b031681565b3480156105c457600080fd5b5060cb546103c4906001600160a01b031681565b3480156105e457600080fd5b5061010b546103c4906001600160a01b031681565b34801561060557600080fd5b506103fc6106143660046143ff565b6115b5565b34801561062557600080fd5b5060c9546103c4906001600160a01b031681565b34801561064557600080fd5b506103fc610654366004614491565b61195c565b34801561066557600080fd5b506103fc61067436600461452a565b611c45565b34801561068557600080fd5b5060975460ff165b604051901515815260200161039b565b3480156106a957600080fd5b506103fc6106b8366004614563565b611d40565b3480156106c957600080fd5b506103fc6106d8366004614331565b611e3a565b3480156106e957600080fd5b506103fc6106f8366004614668565b61224b565b34801561070957600080fd5b5061039160da5481565b34801561071f57600080fd5b5061010a546103c4906001600160a01b031681565b34801561074057600080fd5b506103fc612271565b34801561075557600080fd5b5061039160d95481565b34801561076b57600080fd5b506103fc61077a36600461472a565b612283565b34801561078b57600080fd5b506103fc612455565b3480156107a057600080fd5b506103fc6107af36600461472a565b612465565b3480156107c057600080fd5b506103fc6107cf36600461474e565b6124df565b3480156107e057600080fd5b506103fc6107ef36600461477c565b61254b565b34801561080057600080fd5b506033546001600160a01b03166103c4565b34801561081e57600080fd5b506103fc61082d36600461472a565b61260f565b34801561083e57600080fd5b506103fc61084d366004614331565b61268d565b34801561085e57600080fd5b506103fc61086d366004614331565b612a4b565b34801561087e57600080fd5b506108f761088d36600461472a565b60d360205260009081526040902080546001820154600283015460038401546004850154600586015460068701546007909701546001600160a01b0396871697958716969485169593909416939192909160ff80821691610100810482169162010000909104168a565b604080516001600160a01b039b8c168152998b1660208b0152978a1697890197909752979094166060870152608086019290925260a085015260c0840152151560e08301529115156101008201529015156101208201526101400161039b565b34801561096357600080fd5b5060cd546103c4906001600160a01b031681565b34801561098357600080fd5b506103fc6109923660046147c2565b612dd8565b3480156109a357600080fd5b5060d1546103c4906001600160a01b031681565b3480156109c357600080fd5b5060cc546103c4906001600160a01b031681565b3480156109e357600080fd5b506103fc6109f236600461472a565b612e60565b348015610a0357600080fd5b5060d2546103c4906001600160a01b031681565b348015610a2357600080fd5b506103fc610a32366004614668565b612ec2565b348015610a4357600080fd5b506103fc610a52366004614807565b612ede565b348015610a6357600080fd5b506103fc610a7236600461477c565b612faf565b348015610a8357600080fd5b506103fc610a92366004614331565b61303d565b348015610aa357600080fd5b5061039160db5481565b348015610ab957600080fd5b5061039160d65481565b348015610acf57600080fd5b506103fc610ade3660046142cd565b6130dd565b348015610aef57600080fd5b5061039160d85481565b348015610b0557600080fd5b506103fc610b1436600461472a565b6131f3565b348015610b2557600080fd5b5061068d610b3436600461472a565b60d76020526000908152604090205460ff1681565b610b51613269565b6001600160a01b038816600090815260d3602052604090206007015462010000900460ff1615610b94576040516333b1990560e11b815260040160405180910390fd5b60d8548514158015610ba8575060d9548514155b8015610bb6575060da548514155b8015610bc4575060db548514155b15610be257604051632946cbf160e01b815260040160405180910390fd5b60008060d8548714610d055760cc546040516389bd7cab60e01b8152734210afa492d997595f7520dfe2e0fc0623cb4215916389bd7cab91610c3a918e916001600160a01b039091169030908c908c906004016148c6565b602060405180830381865af4158015610c57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c7b9190614918565b60cc5460c95460cd54604051630578b6b760e51b81526001600160a01b03808616600483015292831660248201529082166044820152929450169063af16d6e0906064016020604051808303816000875af1158015610cde573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d029190614918565b90505b60cc5460d8546001600160a01b03909116906347260cbb908914610d29578a610d2c565b60005b8c858560d8548d14610d3f576000610d42565b60015b60405160e087901b6001600160e01b031916815260048101959095526001600160a01b039384166024860152918316604485015290911660648301521515608482015260a401600060405180830381600087803b158015610da257600080fd5b505af1158015610db6573d6000803e3d6000fd5b505050506040518061014001604052808b6001600160a01b0316815260200160d8548914610de45789610de7565b60005b6001600160a01b03168152602001826001600160a01b03168152602001836001600160a01b0316815260200142815260200188815260200160008152602001851515815260200184151581526020016001151581525060d360008c6001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060208201518160010160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060408201518160020160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060608201518160030160006101000a8154816001600160a01b0302191690836001600160a01b031602179055506080820151816004015560a0820151816005015560c0820151816006015560e08201518160070160006101000a81548160ff0219169083151502179055506101008201518160070160016101000a81548160ff0219169083151502179055506101208201518160070160026101000a81548160ff02191690831515021790555090505060d48a9080600181540180825580915050600190039060005260206000200160009091909190916101000a8154816001600160a01b0302191690836001600160a01b03160217905550600160d56000828254610ff5919061494b565b9091555050604080516001600160a01b038c81168252838116602083015284168183015290517f4c61bab17e59e06eb29c0659ba5f68dc5bc003d57587a7280d98d532d2bf312a9181900360600190a150505050505050505050565b6110596132c3565b61106161331c565b60ce546001600160a01b03163381146110955760405162461bcd60e51b815260040161108c90614964565b60405180910390fd5b60d254604080516336c1902960e11b81526001600160a01b03808816600483015280871660248301529092166044830152833560648301526020840135608483015283013560a4820152606083013560c4820152608083013560e482015260a0830135610104820152736b47d319e96ca77d12081fc5236451c9db1277f090636d83205290610124015b60006040518083038186803b15801561113757600080fd5b505af415801561114b573d6000803e3d6000fd5b505050505061115a6001606555565b505050565b611167613269565b6001600160a01b03878116600081815260d36020526040908190206001810180546001600160a01b03199081168b8716179091556005820189905560078201805461ffff191689151561ff001916176101008915150217905560028201805490911686861690811790915560cc54925163c9365cd560e01b81526004810194909452602484018b9052604484015292169063c9365cd590606401600060405180830381600087803b15801561121b57600080fd5b505af115801561122f573d6000803e3d6000fd5b505050505050505050505050565b6112456132c3565b61010b546001600160a01b0316331461127157604051630bc12c1960e11b815260040160405180910390fd5b604051631a4707ed60e01b81526001600160a01b03808616600483015280851660248301526044820184905282166064820152736b47d319e96ca77d12081fc5236451c9db1277f090631a4707ed9060840160006040518083038186803b1580156112db57600080fd5b505af41580156112ef573d6000803e3d6000fd5b505050506112fd6001606555565b50505050565b600054610100900460ff1661132a5760405162461bcd60e51b815260040161108c90614988565b611332613369565b61133a613398565b6113426133c7565b60c980546001600160a01b039485166001600160a01b03199182161790915560ca80549385169382169390931790925560cc8054919093169116179055565b60d4818154811061139157600080fd5b6000918252602090912001546001600160a01b0316905081565b6113b36132c3565b6113bb61331c565b60ce546001600160a01b03163381146113e65760405162461bcd60e51b815260040161108c90614964565b60c95460d25460cd5460d154604051632769509b60e11b81526001600160a01b03808a1660048301528089166024830152604482018890529485166064820152928416608484015290831660a48301529190911660c4820152736b47d319e96ca77d12081fc5236451c9db1277f090634ed2a1369060e40161111f565b61146b613269565b61384081111561148e57604051636f1d586b60e01b815260040160405180910390fd5b60d68190556040518181527f03ed3de74585ccd983a50e9e38b51059a7e1d904d2a40072b6aebf1b5c64e2d7906020015b60405180910390a150565b6114d2613269565b6114da6133f6565b565b6114e46132c3565b61010b546001600160a01b0316331461151057604051630bc12c1960e11b815260040160405180910390fd5b60405163400d592b60e01b81526001600160a01b038088166004830152808716602483015260ff8616604483015280851660648301528316608482015260a48101829052736b47d319e96ca77d12081fc5236451c9db1277f09063400d592b9060c40160006040518083038186803b15801561158b57600080fd5b505af415801561159f573d6000803e3d6000fd5b505050506115ad6001606555565b505050505050565b6115bd6132c3565b6115c561331c565b60d0546001600160a01b03163381146115f05760405162461bcd60e51b815260040161108c90614964565b6001600160a01b03848116600090815260d3602052604080822060c95491516370a0823160e01b8152306004820152909391909116906370a0823190602401602060405180830381865afa15801561164c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061167091906149d3565b8254604051630cacd00160e11b81523060048201529192506000916001600160a01b0390911690631959a002906024016040805180830381865afa1580156116bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116e091906149ec565b5090506116ef88848888613448565b8254604051630cacd00160e11b81523060048201526000916001600160a01b031690631959a002906024016040805180830381865afa158015611736573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061175a91906149ec565b5060c9546040516370a0823160e01b815230600482015291925060009185916001600160a01b0316906370a0823190602401602060405180830381865afa1580156117a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117cd91906149d3565b6117d79190614a10565b60cd54865460c9546002890154604051630c25540160e11b8152949550736b47d319e96ca77d12081fc5236451c9db1277f09463184aa8029461183e946001600160a01b039182169490821693908216928992909116906001908390600090600401614a23565b60006040518083038186803b15801561185657600080fd5b505af415801561186a573d6000803e3d6000fd5b5050505060038501546001600160a01b03166340c10f198b61188c8686614a10565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b1580156118d257600080fd5b505af11580156118e6573d6000803e3d6000fd5b50505060038601546001600160a01b0390811691508a8116908c167f1d7dc13c1c23eeac1d4c587dc94c8df54855caa5b20022633443fe95d4f419eb8b8b61192e8989614a10565b6040805193845260208401929092529082015260600160405180910390a45050505050506112fd6001606555565b61196461331c565b61196c6132c3565b33600090815260d7602052604090205460ff1661199c57604051636586017760e01b815260040160405180910390fd5b6001600160a01b0382166119c35760405163e6c4247b60e01b815260040160405180910390fd5b8584146119e357604051631df89e8b60e01b815260040160405180910390fd5b6040805160018082528183019092526000916020808301908036833750506040805160018082528183019092529293506000929150602080830190803683370190505090503082600081518110611a3c57611a3c614a6e565b60200260200101906001600160a01b031690816001600160a01b0316815250508481600081518110611a7057611a70614a6e565b6001600160a01b0392831660209182029290920101526040516370a0823160e01b81523060048201526000918716906370a0823190602401602060405180830381865afa158015611ac5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ae991906149d3565b6040516301c7ba5760e61b81529091506001600160a01b038616906371ee95c090611b2290869086908f908f908f908f90600401614afa565b600060405180830381600087803b158015611b3c57600080fd5b505af1158015611b50573d6000803e3d6000fd5b50506040516370a0823160e01b8152306004820152600092506001600160a01b03891691506370a0823190602401602060405180830381865afa158015611b9b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bbf91906149d3565b90506000611bcd8383614a10565b90508015611c2d57611be96001600160a01b038916878361370c565b856001600160a01b03167f10023e167b7945b9995b012ecac59971f1dd24eb0a0ef80e1646a86706cdc15e82604051611c2491815260200190565b60405180910390a25b5050505050611c3c6001606555565b50505050505050565b611c4d6132c3565b611c55613269565b6001600160a01b038116611c7c57604051639fabe1c160e01b815260040160405180910390fd5b6001600160a01b038216611ca357604051639fabe1c160e01b815260040160405180910390fd5b604051639b3acb7360e01b81526001600160a01b038281166004830152831690639b3acb7390602401600060405180830381600087803b158015611ce657600080fd5b505af1158015611cfa573d6000803e3d6000fd5b50506040516001600160a01b03841692507f474e6b47b248d06b54ba9dfa8422fd3c5a90c4c806728e3a8c16b2e48faa48639150600090a2611d3c6001606555565b5050565b611d48613269565b60d280546001600160a01b038981166001600160a01b0319928316811790935560cc80548a8316908416811790915560d180548a8416908516811790915560cd80548a8516908616811790915560ce80548a8616908716811790915560cf80548a8716908816811790915560d08054968a16969097168617909655600160d855600260d955600360da55600060db55604080519788526020880194909452928601919091526060850152608084015260a083019190915260c08201527fd2c2b19bbbc7fdb648cbb96ff1d615e7e4a4604099f5713b40b53a0e968d2f679060e00160405180910390a150505050505050565b611e426132c3565b611e4a61331c565b60d0546001600160a01b0316338114611e755760405162461bcd60e51b815260040161108c90614964565b6001600160a01b03808416600090815260d3602090815260408083208151610140810183528154861680825260018301548716828601526002830154871682850152600383015490961660608201526004808301546080830152600583015460a0830152600683015460c083015260079092015460ff808216151560e0840152610100808304821615159084015262010000909104161515610120820152825163f9d3af2b60e01b8152925190959363f9d3af2b9380840193919291908290030181865afa158015611f4b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f6f9190614918565b90506000816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015611fb1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fd59190614918565b90506000826001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015612017573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061203b9190614918565b8451604051638494b2ed60e01b81526000600482018190526001600160a01b039092166024820152919250908190736b47d319e96ca77d12081fc5236451c9db1277f090638494b2ed90604401600060405180830381865af41580156120a5573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526120cd9190810190614c3b565b915091506120dd8160008461376f565b855160405163d935e83960e01b81526001600160a01b03808d1660048301529182166024820152604481018a905281861660648201529084166084820152736b47d319e96ca77d12081fc5236451c9db1277f09063d935e8399060a40160006040518083038186803b15801561215257600080fd5b505af4158015612166573d6000803e3d6000fd5b5050506060870151604051632770a7eb60e21b81526001600160a01b038d81166004830152602482018c90529091169150639dc29fac90604401600060405180830381600087803b1580156121ba57600080fd5b505af11580156121ce573d6000803e3d6000fd5b5050505085606001516001600160a01b031686600001516001600160a01b03168b6001600160a01b03167fbe34583ba3a350c93297e4685994be9c66848e00c896194dd0ff3a5e17e71dd28b8c604051612232929190918252602082015260400190565b60405180910390a45050505050505061115a6001606555565b61225361331c565b61225b6132c3565b6122678260018361376f565b611d3c6001606555565b612279613269565b6114da6000613ab7565b61228b61331c565b6122936132c3565b6001600160a01b03818116600090815260d36020908152604080832081516101408101835281548616815260018083015487168286015260028301548716828501526003830154909616606082015260048201546080820152600582015460a0820152600682015460c082015260079091015460ff808216151560e084015261010080830482161515908401526201000090910416151561012082015281518581528083019092529390918281019080368337019050509050828160008151811061236057612360614a6e565b6001600160a01b0392909216602092830291909101909101526040805160018082528183019092526000918160200160208202803683370190505090506000816000815181106123b2576123b2614a6e565b60200260200101818152505060d8548360a00151036123e457604051632946cbf160e01b815260040160405180910390fd5b60d9548360a0015114806123fd575060db548360a00151145b156124135761240e8260018361376f565b612445565b60da548360a001510361242c5761240e8260008361376f565b604051632946cbf160e01b815260040160405180910390fd5b5050506124526001606555565b50565b61245d613269565b6114da613b09565b61246d613269565b6001600160a01b03811661249457604051639fabe1c160e01b815260040160405180910390fd5b61010b80546001600160a01b0319166001600160a01b0383169081179091556040517f8e668b91cbea96d6c02869aaa78aaa08472128a5192a739d3113875e7b20d54a90600090a250565b6124e7613269565b6001600160a01b038216600081815260d76020908152604091829020805460ff19168515159081179091558251938452908301527f0dc929214694ec0f39d1e956e72f84da7cccf32546d93514914c9cf0d2d0fbf091015b60405180910390a15050565b61255361331c565b61255b6132c3565b60ce546001600160a01b03163381146125865760405162461bcd60e51b815260040161108c90614964565b60d25460d154604051630ac05c6b60e11b8152736b47d319e96ca77d12081fc5236451c9db1277f092631580b8d6926125d492889288926001600160a01b0391821692911690600401614d1d565b60006040518083038186803b1580156125ec57600080fd5b505af4158015612600573d6000803e3d6000fd5b5050505050611d3c6001606555565b612617613269565b6001600160a01b03811661263e57604051639fabe1c160e01b815260040160405180910390fd5b61010a80546001600160a01b0319166001600160a01b0383169081179091556040519081527f553e16b4c53d09e7c22bbd414551259359596abb29da2b7480d60a2942f7e4b5906020016114bf565b6126956132c3565b61269d61331c565b60cf546001600160a01b03163381146126c85760405162461bcd60e51b815260040161108c90614964565b6001600160a01b03808416600090815260d360205260409020600181015490916126f59116863086613b46565b80546001820154612713916001600160a01b03918216911685613b7e565b60c9546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa15801561275c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061278091906149d3565b90504260d6548360040154612795919061494b565b1115612804578154604051639a40832160e01b815260048101869052600160248201526001600160a01b0390911690639a40832190604401600060405180830381600087803b1580156127e757600080fd5b505af11580156127fb573d6000803e3d6000fd5b5050505061286f565b8154604051639a40832160e01b815260048101869052600060248201526001600160a01b0390911690639a40832190604401600060405180830381600087803b15801561285057600080fd5b505af1158015612864573d6000803e3d6000fd5b505042600485015550505b60c9546040516370a0823160e01b815230600482015260009183916001600160a01b03909116906370a0823190602401602060405180830381865afa1580156128bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128e091906149d3565b6128ea9190614a10565b60cd54845460c9546002870154604051630c25540160e11b8152949550736b47d319e96ca77d12081fc5236451c9db1277f09463184aa80294612951946001600160a01b039182169490821693908216928992909116906001908390600090600401614a23565b60006040518083038186803b15801561296957600080fd5b505af415801561297d573d6000803e3d6000fd5b5050505060038301546040516340c10f1960e01b81526001600160a01b03898116600483015260248201889052909116906340c10f1990604401600060405180830381600087803b1580156129d157600080fd5b505af11580156129e5573d6000803e3d6000fd5b505050506003830154835460408051888152602081018990526001600160a01b0393841693928316928b16917f4f229060ac3eadbf3a707014e63f49c216b6354f7e8295dce2e0946515e6393e91015b60405180910390a45050505061115a6001606555565b612a536132c3565b612a5b61331c565b60cf546001600160a01b0316338114612a865760405162461bcd60e51b815260040161108c90614964565b6001600160a01b03838116600090815260d3602052604080822060c95491516370a0823160e01b8152306004820152909391909116906370a0823190602401602060405180830381865afa158015612ae2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b0691906149d3565b90504260d6548360040154612b1b919061494b565b1115612b8a578154604051631c683a1b60e11b815260048101869052600160248201526001600160a01b03909116906338d0743690604401600060405180830381600087803b158015612b6d57600080fd5b505af1158015612b81573d6000803e3d6000fd5b50505050612bf5565b8154604051631c683a1b60e11b815260048101869052600060248201526001600160a01b03909116906338d0743690604401600060405180830381600087803b158015612bd657600080fd5b505af1158015612bea573d6000803e3d6000fd5b505042600485015550505b60c9546040516370a0823160e01b815230600482015260009183916001600160a01b03909116906370a0823190602401602060405180830381865afa158015612c42573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c6691906149d3565b612c709190614a10565b60cd54845460c9546002870154604051630c25540160e11b8152949550736b47d319e96ca77d12081fc5236451c9db1277f09463184aa80294612cd7946001600160a01b039182169490821693908216928992909116906001908390600090600401614a23565b60006040518083038186803b158015612cef57600080fd5b505af4158015612d03573d6000803e3d6000fd5b505050506003830154604051632770a7eb60e21b81526001600160a01b0389811660048301526024820188905290911690639dc29fac90604401600060405180830381600087803b158015612d5757600080fd5b505af1158015612d6b573d6000803e3d6000fd5b5050506001840154612d8891506001600160a01b0316888761370c565b6003830154835460408051888152602081018990526001600160a01b0393841693928316928b16917f518e1d56d916895b12ce6b92023b06dee7b66021055d80320658dcf62efb49759101612a35565b612de06132c3565b612de861331c565b60ce546001600160a01b0316338114612e135760405162461bcd60e51b815260040161108c90614964565b60d25460d15460405163593ff66560e11b8152736b47d319e96ca77d12081fc5236451c9db1277f09263b27fecca9261111f9289926001600160a01b039081169216908890600401614d58565b612e68613269565b60cb80546001600160a01b038381166001600160a01b031983168117909355604080519190921680825260208201939093527f7afc8d70a05f26bdab4ba44388c429415d310e9d14562232bc59f97466045995910161253f565b612eca61331c565b612ed26132c3565b6122678260008361376f565b612ee66132c3565b61010b546001600160a01b03163314612f1257604051630bc12c1960e11b815260040160405180910390fd5b60405163d6e28c4960e01b81526001600160a01b038087166004830152808616602483015260ff85166044830152808416606483015282166084820152736b47d319e96ca77d12081fc5236451c9db1277f09063d6e28c499060a40160006040518083038186803b158015612f8657600080fd5b505af4158015612f9a573d6000803e3d6000fd5b50505050612fa86001606555565b5050505050565b612fb761331c565b612fbf6132c3565b60ce546001600160a01b0316338114612fea5760405162461bcd60e51b815260040161108c90614964565b60c95460d25460cd54604051635ac9873b60e01b8152736b47d319e96ca77d12081fc5236451c9db1277f093635ac9873b936125d493899389936001600160a01b03908116938116921690600401614dd7565b6130456132c3565b61304d61331c565b60ce546001600160a01b03163381146130785760405162461bcd60e51b815260040161108c90614964565b60d25460d15460405163a415127360e01b81526001600160a01b038088166004830152808716602483015260448201869052928316606482015291166084820152736b47d319e96ca77d12081fc5236451c9db1277f09063a41512739060a40161111f565b600054610100900460ff16158080156130fd5750600054600160ff909116105b806131175750303b158015613117575060005460ff166001145b61317a5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840161108c565b6000805460ff19166001179055801561319d576000805461ff0019166101001790555b6131a8848484611303565b80156112fd576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a150505050565b6131fb613269565b6001600160a01b0381166132605760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161108c565b61245281613ab7565b6033546001600160a01b031633146114da5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161108c565b6002606554036133155760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161108c565b6002606555565b60975460ff16156114da5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015260640161108c565b6001606555565b600054610100900460ff166133905760405162461bcd60e51b815260040161108c90614988565b6114da613c30565b600054610100900460ff166133bf5760405162461bcd60e51b815260040161108c90614988565b6114da613c60565b600054610100900460ff166133ee5760405162461bcd60e51b815260040161108c90614988565b6114da613c87565b6133fe613cba565b6097805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b82546040805163f9d3af2b60e01b815290516000926001600160a01b03169163f9d3af2b9160048083019260209291908290030181865afa158015613491573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134b59190614918565b90508215613553576000816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156134fd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135219190614918565b90506135386001600160a01b038216873087613b46565b8454613551906001600160a01b03838116911686613b7e565b505b81156135ef576000816001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015613599573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135bd9190614918565b90506135d46001600160a01b038216873086613b46565b84546135ed906001600160a01b03838116911685613b7e565b505b4260d6548560040154613602919061494b565b111561368657835460405163b1b1a79560e01b815260048101859052602481018490526001604482015260806064820152600060848201526001600160a01b039091169063b1b1a7959060a401600060405180830381600087803b15801561366957600080fd5b505af115801561367d573d6000803e3d6000fd5b50505050612fa8565b835460405163b1b1a79560e01b815260048101859052602481018490526000604482018190526080606483015260848201526001600160a01b039091169063b1b1a7959060a401600060405180830381600087803b1580156136e757600080fd5b505af11580156136fb573d6000803e3d6000fd5b505042600487015550505050505050565b6040516001600160a01b03831660248201526044810182905261115a90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613d03565b8051835114613794576040516001621398b960e31b0319815260040160405180910390fd5b60005b83518110156112fd57600060d360008684815181106137b8576137b8614a6e565b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002090508060070160029054906101000a900460ff166137fe5750613aa5565b4260d6548260040154613811919061494b565b111561381e575050505050565b4260048281019190915560c9546040516370a0823160e01b815230928101929092526000916001600160a01b03909116906370a0823190602401602060405180830381865afa158015613875573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061389991906149d3565b9050841561390a578154604051639a40832160e01b815260006004820181905260248201526001600160a01b0390911690639a40832190604401600060405180830381600087803b1580156138ed57600080fd5b505af1158015613901573d6000803e3d6000fd5b5050505061396f565b8154604051639a40832160e01b815260006004820181905260248201526001600160a01b0390911690639a40832190604401600060405180830381600087803b15801561395657600080fd5b505af115801561396a573d6000803e3d6000fd5b505050505b60c9546040516370a0823160e01b815230600482015260009183916001600160a01b03909116906370a0823190602401602060405180830381865afa1580156139bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139e091906149d3565b6139ea9190614a10565b60cd54845460c95460028701548951949550736b47d319e96ca77d12081fc5236451c9db1277f09463184aa802946001600160a01b0390811694811693811692889291169060019083908e908e908110613a4657613a46614a6e565b60200260200101516040518963ffffffff1660e01b8152600401613a71989796959493929190614a23565b60006040518083038186803b158015613a8957600080fd5b505af4158015613a9d573d6000803e3d6000fd5b505050505050505b80613aaf81614e18565b915050613797565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b613b1161331c565b6097805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861342b3390565b6040516001600160a01b03808516602483015283166044820152606481018290526112fd9085906323b872dd60e01b90608401613738565b604051636eb1769f60e11b81523060048201526001600160a01b038381166024830152600091839186169063dd62ed3e90604401602060405180830381865afa158015613bcf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613bf391906149d3565b613bfd919061494b565b6040516001600160a01b0385166024820152604481018290529091506112fd90859063095ea7b360e01b90606401613738565b600054610100900460ff16613c575760405162461bcd60e51b815260040161108c90614988565b6114da33613ab7565b600054610100900460ff166133625760405162461bcd60e51b815260040161108c90614988565b600054610100900460ff16613cae5760405162461bcd60e51b815260040161108c90614988565b6097805460ff19169055565b60975460ff166114da5760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015260640161108c565b6000613d58826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316613dd59092919063ffffffff16565b80519091501561115a5780806020019051810190613d769190614e31565b61115a5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161108c565b6060613de48484600085613dec565b949350505050565b606082471015613e4d5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161108c565b600080866001600160a01b03168587604051613e699190614e4e565b60006040518083038185875af1925050503d8060008114613ea6576040519150601f19603f3d011682016040523d82523d6000602084013e613eab565b606091505b5091509150613ebc87838387613ec7565b979650505050505050565b60608315613f36578251600003613f2f576001600160a01b0385163b613f2f5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161108c565b5081613de4565b613de48383815115613f4b5781518083602001fd5b8060405162461bcd60e51b815260040161108c9190614e6a565b6001600160a01b038116811461245257600080fd5b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715613fb957613fb9613f7a565b604052919050565b600082601f830112613fd257600080fd5b813567ffffffffffffffff811115613fec57613fec613f7a565b613fff601f8201601f1916602001613f90565b81815284602083860101111561401457600080fd5b816020850160208301376000918101602001919091529392505050565b801515811461245257600080fd5b600080600080600080600080610100898b03121561405c57600080fd5b883561406781613f65565b975060208901359650604089013561407e81613f65565b955060608901359450608089013567ffffffffffffffff808211156140a257600080fd5b6140ae8c838d01613fc1565b955060a08b01359150808211156140c457600080fd5b506140d18b828c01613fc1565b93505060c08901356140e281614031565b915060e08901356140f281614031565b809150509295985092959890939650565b600080600083850361010081121561411a57600080fd5b843561412581613f65565b9350602085013561413581613f65565b925060c0603f198201121561414957600080fd5b506040840190509250925092565b60008060008060006080868803121561416f57600080fd5b853561417a81613f65565b9450602086013561418a81613f65565b935060408601359250606086013567ffffffffffffffff808211156141ae57600080fd5b818801915088601f8301126141c257600080fd5b8135818111156141d157600080fd5b8960208285010111156141e357600080fd5b9699959850939650602001949392505050565b600080600080600080600060e0888a03121561421157600080fd5b873561421c81613f65565b965060208801359550604088013561423381613f65565b945060608801359350608088013561424a81614031565b925060a088013561425a81614031565b915060c088013561426a81613f65565b8091505092959891949750929550565b6000806000806080858703121561429057600080fd5b843561429b81613f65565b935060208501356142ab81613f65565b92506040850135915060608501356142c281613f65565b939692955090935050565b6000806000606084860312156142e257600080fd5b83356142ed81613f65565b925060208401356142fd81613f65565b9150604084013561430d81613f65565b809150509250925092565b60006020828403121561432a57600080fd5b5035919050565b60008060006060848603121561434657600080fd5b833561435181613f65565b9250602084013561436181613f65565b929592945050506040919091013590565b803560ff8116811461438357600080fd5b919050565b60008060008060008060c087890312156143a157600080fd5b86356143ac81613f65565b955060208701356143bc81613f65565b94506143ca60408801614372565b935060608701356143da81613f65565b925060808701356143ea81613f65565b8092505060a087013590509295509295509295565b6000806000806080858703121561441557600080fd5b843561442081613f65565b9350602085013561443081613f65565b93969395505050506040820135916060013590565b60008083601f84011261445757600080fd5b50813567ffffffffffffffff81111561446f57600080fd5b6020830191508360208260051b850101111561448a57600080fd5b9250929050565b600080600080600080600060a0888a0312156144ac57600080fd5b873567ffffffffffffffff808211156144c457600080fd5b6144d08b838c01614445565b909950975060208a01359150808211156144e957600080fd5b506144f68a828b01614445565b909650945050604088013561450a81613f65565b9250606088013561451a81613f65565b9150608088013561426a81613f65565b6000806040838503121561453d57600080fd5b823561454881613f65565b9150602083013561455881613f65565b809150509250929050565b600080600080600080600060e0888a03121561457e57600080fd5b873561458981613f65565b9650602088013561459981613f65565b955060408801356145a981613f65565b945060608801356145b981613f65565b935060808801356145c981613f65565b925060a088013561425a81613f65565b600067ffffffffffffffff8211156145f3576145f3613f7a565b5060051b60200190565b600082601f83011261460e57600080fd5b8135602061462361461e836145d9565b613f90565b82815260059290921b8401810191818101908684111561464257600080fd5b8286015b8481101561465d5780358352918301918301614646565b509695505050505050565b6000806040838503121561467b57600080fd5b823567ffffffffffffffff8082111561469357600080fd5b818501915085601f8301126146a757600080fd5b813560206146b761461e836145d9565b82815260059290921b840181019181810190898411156146d657600080fd5b948201945b838610156146fd5785356146ee81613f65565b825294820194908201906146db565b9650508601359250508082111561471357600080fd5b50614720858286016145fd565b9150509250929050565b60006020828403121561473c57600080fd5b813561474781613f65565b9392505050565b6000806040838503121561476157600080fd5b823561476c81613f65565b9150602083013561455881614031565b6000806040838503121561478f57600080fd5b823561479a81613f65565b9150602083013567ffffffffffffffff8111156147b657600080fd5b614720858286016145fd565b600080600083850360e08112156147d857600080fd5b84356147e381613f65565b935060208501356147f381613f65565b925060a0603f198201121561414957600080fd5b600080600080600060a0868803121561481f57600080fd5b853561482a81613f65565b9450602086013561483a81613f65565b935061484860408701614372565b9250606086013561485881613f65565b9150608086013561486881613f65565b809150509295509295909350565b60005b83811015614891578181015183820152602001614879565b50506000910152565b600081518084526148b2816020860160208601614876565b601f01601f19169290920160200192915050565b6001600160a01b03868116825285811660208301528416604082015260a0606082018190526000906148fa9083018561489a565b828103608084015261490c818561489a565b98975050505050505050565b60006020828403121561492a57600080fd5b815161474781613f65565b634e487b7160e01b600052601160045260246000fd5b8082018082111561495e5761495e614935565b92915050565b6020808252600a908201526927b7363ca432b63832b960b11b604082015260600190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6000602082840312156149e557600080fd5b5051919050565b600080604083850312156149ff57600080fd5b505080516020909101519092909150565b8181038181111561495e5761495e614935565b6001600160a01b0398891681529688166020880152948716604087015260608601939093529416608084015292151560a083015260c082019290925260e08101919091526101000190565b634e487b7160e01b600052603260045260246000fd5b600081518084526020808501945080840160005b83811015614abd5781516001600160a01b031687529582019590820190600101614a98565b509495945050505050565b81835260006001600160fb1b03831115614ae157600080fd5b8260051b80836020870137939093016020019392505050565b608081526000614b0d6080830189614a84565b602083820381850152614b20828a614a84565b91508382036040850152614b3582888a614ac8565b84810360608601528581529150808201600586811b840183018860005b89811015614bc457868303601f190185528135368c9003601e19018112614b7857600080fd5b8b01868101903567ffffffffffffffff811115614b9457600080fd5b80861b3603821315614ba557600080fd5b614bb0858284614ac8565b968801969450505090850190600101614b52565b50909d9c50505050505050505050505050565b600082601f830112614be857600080fd5b81516020614bf861461e836145d9565b82815260059290921b84018101918181019086841115614c1757600080fd5b8286015b8481101561465d578051614c2e81613f65565b8352918301918301614c1b565b60008060408385031215614c4e57600080fd5b825167ffffffffffffffff80821115614c6657600080fd5b818501915085601f830112614c7a57600080fd5b81516020614c8a61461e836145d9565b82815260059290921b84018101918181019089841115614ca957600080fd5b948201945b83861015614cc757855182529482019490820190614cae565b91880151919650909350505080821115614ce057600080fd5b5061472085828601614bd7565b600081518084526020808501945080840160005b83811015614abd57815187529582019590820190600101614d01565b600060018060a01b03808716835260806020840152614d3f6080840187614ced565b9481166040840152929092166060909101525092915050565b6001600160a01b0385811682528481166020808401919091529084166040830152823560608301526101008201908301356fffffffffffffffffffffffffffffffff8116808214614da857600080fd5b8060808501525050604083013560a0830152606083013560c0830152608083013560e083015295945050505050565b600060018060a01b03808816835260a06020840152614df960a0840188614ced565b9581166040840152938416606083015250911660809091015292915050565b600060018201614e2a57614e2a614935565b5060010190565b600060208284031215614e4357600080fd5b815161474781614031565b60008251614e60818460208701614876565b9190910192915050565b602081526000614747602083018461489a56fea2646970667358221220664a43dc1e75c24827a31ae77054a2722b5072f506f4a40bd7566a5fac35037664736f6c63430008130033
Verified Source Code Partial Match
Compiler: v0.8.19+commit.7dd6d404
EVM: paris
Optimization: Yes (200 runs)
PancakeStakingSideChain.sol 158 lines
// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;
pragma abicoder v2;
import { IERC20, ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { PancakeStakingBaseUpg } from "../baseupgs/PancakeStakingBaseUpg.sol";
import "../../interfaces/pancakeswap/IAngelMerkl.sol";
import "../../interfaces/pancakeswap/IIFOV8.sol";
import "../../interfaces/pancakeswap/IICake.sol";
import "../../interfaces/cakepie/IPancakeIFOHelper.sol";
import { PancakeStakingLib } from "../../libraries/cakepie/PancakeStakingLib.sol";
/// @title PancakeStaking
/// @notice PancakeStaking is the main contract interacting with pancakeswap side.
/// @author Magpie Team
contract PancakeStakingSideChain is PancakeStakingBaseUpg {
using SafeERC20 for IERC20;
/* ============ State Variables ============ */
address public mCakeConvertorSideChain;
address public cakepieIFOManager;
/* ============ Events ============ */
event mCakeConvertorSet(address _mCakeConvertor);
event CakepieIFOManagerSet(address indexed cakepieIFOManager);
event ApproveToLocker(address indexed _veCakeUser);
event ArbRewardSentToDistributor(address indexed _receiver, uint256 _amount);
/* ============ Errors ============ */
error AddressZero();
error OnlyIFOManager();
error InvalidAddress();
error InvalidLengths();
/* ============ Constructor ============ */
receive() external payable {}
constructor() {
_disableInitializers();
}
function __PancakeStakingSideChain_init(
address _CAKE,
address _mCake,
address _masterCakepie
) public initializer {
__PancakeStakingBaseUpg_init(_CAKE, _mCake, _masterCakepie);
}
/* ============ Modifiers ============ */
modifier _onlyIFOManager() {
if (msg.sender != cakepieIFOManager) revert OnlyIFOManager();
_;
}
/* ============ External Functions ============== */
function claimArbFromMerkl(
uint256[] calldata _amount,
bytes32[][] calldata _proofs,
address _rewardToken,
address _angleMerkleDistributor,
address _arbRewardDistributor
) external whenNotPaused nonReentrant _onlyAllowedOperator {
if (_angleMerkleDistributor == address(0)) revert InvalidAddress();
if (_amount.length != _proofs.length ) revert InvalidLengths();
address[] memory receiver = new address[](1);
address[] memory arbTokenAddress = new address[](1);
receiver[0] = address(this);
arbTokenAddress[0] = _rewardToken;
uint256 balBefore = IERC20(_rewardToken).balanceOf(address(this));
IAngelMerkl(_angleMerkleDistributor).claim(
receiver,
arbTokenAddress,
_amount,
_proofs
);
uint256 balAfter = IERC20(_rewardToken).balanceOf(address(this));
uint256 amountClaimed = balAfter - balBefore;
if (amountClaimed > 0) {
IERC20(_rewardToken).safeTransfer(_arbRewardDistributor, amountClaimed);
emit ArbRewardSentToDistributor(_arbRewardDistributor, amountClaimed);
}
}
/* ============ Admin Functions ============ */
function setMCakeConvertorSideChain(address _mCakeConvertoSideChain) external onlyOwner {
if (_mCakeConvertoSideChain == address(0)) revert AddressZero();
mCakeConvertorSideChain = _mCakeConvertoSideChain;
emit mCakeConvertorSet(mCakeConvertorSideChain);
}
function depositIFO(
address _pancakeIFOHelper,
address _pancakeIFO,
uint8 _pid,
address _depositToken,
address _for,
uint256 _amount
) external nonReentrant _onlyIFOManager {
PancakeStakingLib.depositIFO(_pancakeIFOHelper, _pancakeIFO, _pid, _depositToken, _for, _amount);
}
function harvestIFO(
address _pancakeIFOHelper,
address _pancakeIFO,
uint8 _pid,
address _depositToken,
address _rewardToken
) external nonReentrant _onlyIFOManager {
PancakeStakingLib.harvestIFO(_pancakeIFOHelper, _pancakeIFO, _pid, _depositToken, _rewardToken);
}
function releaseIFO(
address _pancakeIFOHelper,
address _pancakeIFO,
bytes32 _vestingScheduleId,
address _rewardToken
) external nonReentrant _onlyIFOManager {
PancakeStakingLib.releaseIFO(_pancakeIFOHelper, _pancakeIFO, _vestingScheduleId, _rewardToken);
}
function setCakepieIFOManager(address _cakepieIFOManager) external onlyOwner {
if (_cakepieIFOManager == address(0)) revert AddressZero();
cakepieIFOManager = _cakepieIFOManager;
emit CakepieIFOManagerSet(_cakepieIFOManager);
}
function approveToLocker(
address _iCake,
address _veCakeUser
) external nonReentrant onlyOwner {
if (_veCakeUser == address(0)) revert AddressZero();
if (_iCake == address(0)) revert AddressZero();
IICake(_iCake).approveToVECakeUser(_veCakeUser);
emit ApproveToLocker(_veCakeUser);
}
}
ERC20.sol 389 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* The default value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* overridden;
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
// Overflow not possible: amount <= accountBalance <= totalSupply.
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(
address owner,
address spender,
uint256 amount
) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
SafeERC20.sol 116 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
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));
}
}
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
PancakeStakingBaseUpg.sol 604 lines
// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;
pragma abicoder v2;
import { IERC20, ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import { IERC721ReceiverUpgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721ReceiverUpgradeable.sol";
import { IMasterCakepie } from "../../interfaces/cakepie/IMasterCakepie.sol";
import { INonfungiblePositionManager } from "../../interfaces/pancakeswap/INonfungiblePositionManager.sol";
import { IMasterChefV3 } from "../../interfaces/pancakeswap/IMasterChefV3.sol";
import { IALMWrapper } from "../../interfaces/pancakeswap/IALMWrapper.sol";
import { IAdapter } from "../../interfaces/pancakeswap/IAdapter.sol";
import { IV2Wrapper } from "../../interfaces/pancakeswap/IV2Wrapper.sol";
import { ERC20FactoryLib } from "../../libraries/cakepie/ERC20FactoryLib.sol";
import { PancakeStakingLib } from "../../libraries/cakepie/PancakeStakingLib.sol";
import { IMintableERC20 } from "../../interfaces/common/IMintableERC20.sol";
import { IRewardDistributor } from "../../interfaces/cakepie/IRewardDistributor.sol";
import { IPancakeV3Helper } from "../../interfaces/cakepie/IPancakeV3Helper.sol";
import "../../interfaces/cakepie/IBaseRewardPool.sol";
/// @title PancakeStakingBaseUpg
/// @notice PancakeStakingBaseUpg is the base contract that holds cakepie common features across all supported chains (BNB, ETH, ARB)
/// PancakeStakingBaseUpg is the main contract interacting with pancakeswap
/// @author Magpie Team
abstract contract PancakeStakingBaseUpg is
Initializable,
OwnableUpgradeable,
ReentrancyGuardUpgradeable,
PausableUpgradeable,
IERC721ReceiverUpgradeable
{
using SafeERC20 for IERC20;
/* ============ Structs ============ */
struct Pool {
// Address of the pool:
// - For V3: The LP address.
// - For V2/AML: The wrapper contract for deposits, withdrawals, and harvesting.
address poolAddress;
// Token address for deposits/withdrawals:
// - For V2: The token deposited into or withdrawn from the pool.
// - For V3: Null, as NFTs are deposited.
// - For AML single-sided pools: The single-sided token address. Null otherwise.
address depositToken;
// Address of the rewarder contract (applicable for V2 and AML pools).
address rewarder;
// Address of the receipt token (applicable for V2 and AML pools).
address receiptToken;
// Timestamp of the last harvest operation (applicable for V2 and AML pools).
uint256 lastHarvestTime;
// Pool type: Specifies whether the pool is SS, V3, V2, or AML.
uint256 poolType;
// Total V3 liquidity tracked.
uint256 v3Liquidity;
// Indicates if the deposit token is `token0` (true) or `token1` (false):
// - For AML pools: Applies only if the deposit token is `token0` or `token1`.
// - Defaults to false if the deposit token is null.
bool isAmount0;
// Indicates if the pool uses native tokens.
bool isNative;
// Indicates if the pool is currently active.
bool isActive;
}
/* ============ State Variables ============ */
// Cakepie core addresses
IERC20 public CAKE;
IERC20 public mCake;
address public voteManager;
// IMasterCakepie public marketDepositHelper;
IMasterCakepie public masterCakepie;
IRewardDistributor public rewardDistributor;
address public pancakeV3Helper;
address public pancakeV2LPHelper;
address public pancakeAMLHelper;
// Pancake address to interact
INonfungiblePositionManager public nonfungiblePositionManager; // For V3 pool
IMasterChefV3 public masterChefV3; // For V3 pool
mapping(address => Pool) public pools;
address[] public poolList;
uint256 public poolLength;
uint256 public harvestTimeGap;
mapping(address => bool) public allowedOperator;
// 1st upgrade
uint256 public V3Type;
uint256 public V2Type;
uint256 public AMLType;
// 2nd upgrade
uint256 public StableSwapType;
uint256[46] private __gap;
/* ============ Events ============ */
event PoolAdded(address _poolAddress, address _rewarder, address _receiptToken);
event NewTokenStaked(
address indexed _user,
address indexed _poolAddress,
uint256 _tokenID,
uint256 _liquidity
);
event NewTokenUnstaked(
address indexed _user,
address indexed _poolAddress,
uint256 _tokenID,
uint256 _liquidity
);
event NewV2Deposit(
address indexed _user,
address indexed _pool,
uint256 _amount,
address indexed _receptToken,
uint256 _receptAmount
);
event NewAMLV2Withdraw(
address indexed _user,
address indexed _pool,
uint256 _amount,
address indexed _receptToken,
uint256 _receptAmount
);
event NewAMLV3Deposit(
address indexed _user,
address indexed _pool,
uint256 _amount0,
uint256 _amount1,
address indexed _receptToken,
uint256 _receptAmount
);
event NewAMLV3Withdraw(
address indexed _user,
address indexed _pool,
uint256 _amount,
address indexed _receptToken,
uint256 _receptAmount
);
event AllowedOperatorSet(address _operator, bool _active);
event VoteManagerSet(address _oldVoteManager, address _newVoteManager);
event V3PoolFeesPaidTo(
address indexed _user,
uint256 _positionId,
address _token,
uint256 _feeAmount
);
event HarvestTimeGapSet(uint256 _harvestTimeGap);
event ConfigSet(
address _masterChefV3,
address _masterCakepie,
address _nonfungiblePositionManager,
address _rewardDistributor,
address _pancakeV3Helper,
address _pancakeV2LPHelper,
address _pancakeAMLHelper
);
/* ============ Errors ============ */
error OnlyFarmHelper();
error OnlyActivePool();
error PoolOccupied();
error TimeGapTooMuch();
error OnlyAMLHelper();
error OnlyVoteManager();
error LengthMismatch();
error OnlyAllowedOperator();
error InvalidPoolType();
/* ============ Constructor ============ */
function __PancakeStakingBaseUpg_init(
address _CAKE,
address _mCake,
address _masterCakepie
) public onlyInitializing {
__Ownable_init();
__ReentrancyGuard_init();
__Pausable_init();
CAKE = IERC20(_CAKE);
mCake = IERC20(_mCake);
masterCakepie = IMasterCakepie(_masterCakepie);
}
/* ============ Modifiers ============ */
modifier _onlyPoolHelper(address _helper) {
if (msg.sender != _helper) {
revert("OnlyHelper");
}
_;
}
modifier _onlyAllowedOperator() {
if (!allowedOperator[msg.sender]) revert OnlyAllowedOperator();
_;
}
/* ============ External Functions ============ */
function onERC721Received(
address,
address from,
uint256 tokenId,
bytes calldata
) external override returns (bytes4) {
return IERC721ReceiverUpgradeable.onERC721Received.selector;
}
function depositV3For(
address _for,
address _v3Pool,
uint256 _tokenId
) external nonReentrant whenNotPaused _onlyPoolHelper(pancakeV3Helper) {
PancakeStakingLib.depositV3For(_for, _v3Pool, _tokenId, masterChefV3, nonfungiblePositionManager);
}
function withdrawV3For(
address _for,
address _v3Pool,
uint256 _tokenId
) external nonReentrant whenNotPaused _onlyPoolHelper(pancakeV3Helper) {
PancakeStakingLib.withdrawV3For(_for, _v3Pool, _tokenId, address(CAKE), masterChefV3, rewardDistributor, nonfungiblePositionManager);
}
function increaseLiquidityV3For(
address _for,
address _v3Pool,
IMasterChefV3.IncreaseLiquidityParams calldata params
) external nonReentrant whenNotPaused _onlyPoolHelper(pancakeV3Helper) {
PancakeStakingLib.increaseLiquidityV3For(_for, _v3Pool, masterChefV3, params);
}
function decreaseLiquidityV3For(
address _for,
address _v3Pool,
IMasterChefV3.DecreaseLiquidityParams calldata params
) external nonReentrant whenNotPaused _onlyPoolHelper(pancakeV3Helper) {
PancakeStakingLib.decreaseLiquidityV3For(_for, masterChefV3, nonfungiblePositionManager, params);
}
function depositV2LPFor(
address _for,
address _pool,
uint256 _amount
) external nonReentrant whenNotPaused _onlyPoolHelper(pancakeV2LPHelper) {
Pool storage poolInfo = pools[_pool];
IERC20(poolInfo.depositToken).safeTransferFrom(_for, address(this), _amount);
IERC20(poolInfo.depositToken).safeIncreaseAllowance(poolInfo.poolAddress, _amount);
uint256 balBefore = IERC20(CAKE).balanceOf(address(this));
if (poolInfo.lastHarvestTime + harvestTimeGap > block.timestamp){
IV2Wrapper(poolInfo.poolAddress).deposit(_amount, true);
}
else {
IV2Wrapper(poolInfo.poolAddress).deposit(_amount, false);
poolInfo.lastHarvestTime = block.timestamp;
}
uint256 rewards = IERC20(CAKE).balanceOf(address(this)) - balBefore;
PancakeStakingLib.handleRewards(rewardDistributor, poolInfo.poolAddress, address(CAKE), rewards, poolInfo.rewarder, true, rewards, 0);
IMintableERC20(poolInfo.receiptToken).mint(_for, _amount);
emit NewV2Deposit(_for, poolInfo.poolAddress, _amount, poolInfo.receiptToken, _amount);
}
function withdrawV2LPFor(
address _for,
address _pool,
uint256 _amount
) external nonReentrant whenNotPaused _onlyPoolHelper(pancakeV2LPHelper) {
Pool storage poolInfo = pools[_pool];
uint256 balBefore = IERC20(CAKE).balanceOf(address(this));
if (poolInfo.lastHarvestTime + harvestTimeGap > block.timestamp){
IV2Wrapper(poolInfo.poolAddress).withdraw(_amount, true);
}
else {
IV2Wrapper(poolInfo.poolAddress).withdraw(_amount, false);
poolInfo.lastHarvestTime = block.timestamp;
}
uint256 rewards = IERC20(CAKE).balanceOf(address(this)) - balBefore;
PancakeStakingLib.handleRewards(rewardDistributor, poolInfo.poolAddress, address(CAKE), rewards, poolInfo.rewarder, true, rewards, 0);
IMintableERC20(poolInfo.receiptToken).burn(_for, _amount);
IERC20(poolInfo.depositToken).safeTransfer(_for, _amount);
emit NewAMLV2Withdraw(_for, poolInfo.poolAddress, _amount, poolInfo.receiptToken, _amount);
}
function depositAMLFor(
address _for,
address _pool,
uint256 _amount0,
uint256 _amount1
) external nonReentrant whenNotPaused _onlyPoolHelper(pancakeAMLHelper) {
Pool storage poolInfo = pools[_pool];
uint256 balBefore = IERC20(CAKE).balanceOf(address(this));
(uint256 _liquidityBefore, ) = IALMWrapper(poolInfo.poolAddress).userInfo(address(this));
// For single-sided AML pools, only one of _amount0 or _amount1 will be non-zero,
// depending on which token is accepted as the deposit token.
_depositTokens(_for, poolInfo, _amount0, _amount1);
(uint256 _liquidityAfter, ) = IALMWrapper(poolInfo.poolAddress).userInfo(address(this));
uint256 rewards = IERC20(CAKE).balanceOf(address(this)) - balBefore;
PancakeStakingLib.handleRewards(rewardDistributor, poolInfo.poolAddress, address(CAKE), rewards, poolInfo.rewarder, true, rewards, 0);
IMintableERC20(poolInfo.receiptToken).mint(_for, _liquidityAfter - _liquidityBefore);
emit NewAMLV3Deposit(
_for,
_pool,
_amount0,
_amount1,
poolInfo.receiptToken,
_liquidityAfter - _liquidityBefore
);
}
function withdrawAMLFor(
address _for,
address _pool,
uint256 _amount
) external nonReentrant whenNotPaused _onlyPoolHelper(pancakeAMLHelper) {
Pool memory poolInfo = pools[_pool];
address _adpaterAddress = IALMWrapper(poolInfo.poolAddress).adapterAddr();
address token0 = IAdapter(_adpaterAddress).token0();
address token1 = IAdapter(_adpaterAddress).token1();
(uint256[] memory minRecTotalMCake, address[] memory poolAddressed) = PancakeStakingLib.toArray(0, address(poolInfo.poolAddress));
// We have to harvest first since CAKE token can be reward or liquidity
_harvestLP(poolAddressed, false, minRecTotalMCake);
PancakeStakingLib.handleWithdrawAML(_for, poolInfo.poolAddress, _amount, token0, token1);
IMintableERC20(poolInfo.receiptToken).burn(_for, _amount);
emit NewAMLV3Withdraw(_for, poolInfo.poolAddress, _amount, poolInfo.receiptToken, _amount);
}
function harvestV3(
address _for,
uint256[] memory _tokenIds
) external whenNotPaused nonReentrant _onlyPoolHelper(pancakeV3Helper) {
PancakeStakingLib.harvestV3(_for, _tokenIds, address(CAKE), masterChefV3, rewardDistributor);
}
function harvestV3PoolFees(
address _for,
uint256[] memory _tokenIds
) external whenNotPaused nonReentrant _onlyPoolHelper(pancakeV3Helper) {
PancakeStakingLib.harvestV3PoolFees(_for, _tokenIds, masterChefV3, nonfungiblePositionManager);
}
function harvestV2LP(address[] memory _pool, uint256[] memory _minRecTotalMCake) external whenNotPaused nonReentrant {
_harvestLP(_pool, true, _minRecTotalMCake);
}
function harvestAML(address[] memory _pool, uint256[] memory _minRecTotalMCake) external whenNotPaused nonReentrant {
_harvestLP(_pool, false, _minRecTotalMCake);
}
function genericHarvest(address _pool) external whenNotPaused nonReentrant {
Pool memory poolInfo = pools[_pool];
address[] memory poolsToHarvest = new address[](1);
poolsToHarvest[0] = _pool;
uint256[] memory minRecTotalMCake = new uint256[](1);
minRecTotalMCake[0] = 0;
if (poolInfo.poolType == V3Type) revert InvalidPoolType();
else if (poolInfo.poolType == V2Type || poolInfo.poolType == StableSwapType) _harvestLP(poolsToHarvest, true, minRecTotalMCake);
else if (poolInfo.poolType == AMLType) _harvestLP(poolsToHarvest, false, minRecTotalMCake);
else revert InvalidPoolType();
}
/* ============ Admin Functions ============ */
function pause() public onlyOwner {
_pause();
}
function unpause() public onlyOwner {
_unpause();
}
function registerPool(
address _poolAddress, // can be V3, V2 or AML Wrapper
uint256 _allocPoints, // only for V2 and AML
address _depositToken, // for V2, it's LP, for AML it's single side token, not applicable for V3
uint256 _poolType,
string memory _name,
string memory _symbol,
bool _isAmount0, // only applicable for AML
bool _isNative
) external onlyOwner {
if (pools[_poolAddress].isActive != false) revert PoolOccupied();
if (_poolType != V3Type && _poolType != V2Type && _poolType != AMLType && _poolType != StableSwapType)
revert InvalidPoolType();
IERC20 newToken;
address rewarder;
if (_poolType != V3Type) {
newToken = IERC20(
ERC20FactoryLib.createReceipt(
_poolAddress,
address(masterCakepie),
address(this),
_name,
_symbol
)
);
rewarder = masterCakepie.createRewarder(
address(newToken),
address(CAKE),
address(rewardDistributor)
);
}
// for v3 pool, we just registered the token address
IMasterCakepie(masterCakepie).add(
_poolType == V3Type ? 0 : _allocPoints,
address(_poolAddress),
address(newToken),
address(rewarder),
_poolType == V3Type ? true : false
);
pools[_poolAddress] = Pool({
poolAddress: _poolAddress,
depositToken: _poolType == V3Type ? address(0) : _depositToken,
rewarder: address(rewarder),
receiptToken: address(newToken),
lastHarvestTime: block.timestamp,
v3Liquidity: 0,
poolType: _poolType,
isAmount0: _isAmount0,
isNative: _isNative,
isActive: true
});
poolList.push(_poolAddress);
poolLength += 1;
emit PoolAdded(_poolAddress, address(rewarder), address(newToken));
}
function setPool(
address _poolAddress, // can be V3, V2 or AML Wrapper
uint256 _allocPoints, // only for V2 and AML
address _depositToken, // for V2, it's LP, for AML it's single side token, not applicable for V3
uint256 _poolType,
bool _isAmount0, // only applicable for AML
bool _isNative,
address _rewarder
) external onlyOwner {
Pool storage pool = pools[_poolAddress];
pool.depositToken = _depositToken;
pool.poolType = _poolType;
pool.isAmount0 = _isAmount0;
pool.isNative = _isNative;
pool.rewarder = _rewarder;
IMasterCakepie(masterCakepie).set(
_poolAddress,
_allocPoints,
_rewarder
);
}
function setHarvestTimeGap(uint256 _period) external onlyOwner {
if (_period > 4 hours) revert TimeGapTooMuch();
harvestTimeGap = _period;
emit HarvestTimeGapSet(harvestTimeGap);
}
function config(
address _masterChefV3,
address _masterCakepie,
address _nonfungiblePositionManager,
address _rewardDistributor,
address _pancakeV3Helper,
address _pancakeV2LPHelper,
address _pancakeAMLHelper
) external onlyOwner {
masterChefV3 = IMasterChefV3(_masterChefV3);
masterCakepie = IMasterCakepie(_masterCakepie);
nonfungiblePositionManager = INonfungiblePositionManager(_nonfungiblePositionManager);
rewardDistributor = IRewardDistributor(_rewardDistributor);
pancakeV3Helper = _pancakeV3Helper;
pancakeV2LPHelper = _pancakeV2LPHelper;
pancakeAMLHelper = _pancakeAMLHelper;
V3Type = 1;
V2Type = 2;
AMLType = 3;
StableSwapType = 0;
emit ConfigSet(_masterChefV3, _masterCakepie, _nonfungiblePositionManager, _rewardDistributor, _pancakeV3Helper, _pancakeV2LPHelper, _pancakeAMLHelper);
}
function setVoteManager(address _newVoteManager) external onlyOwner {
address oldVoteManager = voteManager;
voteManager = _newVoteManager;
emit VoteManagerSet(oldVoteManager, _newVoteManager);
}
function setAllowedOperator(address _operator, bool _active) external onlyOwner {
allowedOperator[_operator] = _active;
emit AllowedOperatorSet(_operator, _active);
}
/* ============ Internal Functions ============ */
// this function is shared by V2,StableSwap and AML pools
function _harvestLP(address[] memory poolAddresses, bool _isV2, uint256[] memory minRecTotalMCake) internal {
if (poolAddresses.length != minRecTotalMCake.length) revert LengthMismatch();
for (uint256 i = 0; i < poolAddresses.length; i++) {
Pool storage poolInfo = pools[poolAddresses[i]];
if (!poolInfo.isActive) continue;
if (poolInfo.lastHarvestTime + harvestTimeGap > block.timestamp) return;
poolInfo.lastHarvestTime = block.timestamp;
uint256 balBefore = IERC20(CAKE).balanceOf(address(this));
if (_isV2) IV2Wrapper(poolInfo.poolAddress).deposit(0, false);
else IALMWrapper(poolInfo.poolAddress).deposit(0, false);
uint256 rewards = IERC20(CAKE).balanceOf(address(this)) - balBefore;
PancakeStakingLib.handleRewards(rewardDistributor, poolInfo.poolAddress, address(CAKE), rewards, poolInfo.rewarder, true, rewards, minRecTotalMCake[i]);
}
}
function _depositTokens(
address _for,
Pool storage _poolInfo,
uint256 _amount0,
uint256 _amount1
) internal {
address adapterAddress = IALMWrapper(_poolInfo.poolAddress).adapterAddr();
if (_amount0 > 0) {
address token0 = IAdapter(adapterAddress).token0();
IERC20(token0).safeTransferFrom(_for, address(this), _amount0);
IERC20(token0).safeIncreaseAllowance(_poolInfo.poolAddress, _amount0);
}
if (_amount1 > 0) {
address token1 = IAdapter(adapterAddress).token1();
IERC20(token1).safeTransferFrom(_for, address(this), _amount1);
IERC20(token1).safeIncreaseAllowance(_poolInfo.poolAddress, _amount1);
}
if (_poolInfo.lastHarvestTime + harvestTimeGap > block.timestamp){
IALMWrapper(_poolInfo.poolAddress).mintThenDeposit(_amount0, _amount1, true, "");
}
else {
IALMWrapper(_poolInfo.poolAddress).mintThenDeposit(_amount0, _amount1, false, "");
_poolInfo.lastHarvestTime = block.timestamp;
}
}
}
IAngelMerkl.sol 11 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
interface IAngelMerkl {
function claim(
address[] calldata users,
address[] calldata tokens,
uint256[] calldata amounts,
bytes32[][] calldata proofs
) external;
}
IIFOV8.sol 75 lines
// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;
/** @title IIFOV6.
* @notice It is an interface for IFOV6.sol
*/
interface IIFOV8 {
struct VestingSchedule {
bool isVestingInitialized;
address beneficiary;
uint8 pid;
uint256 amountTotal;
uint256 released;
}
function addresses(uint256 index) external view returns (address);
function totalTokensOffered() external view returns (uint256);
function endTimestamp() external view returns (uint256);
function startTimestamp() external view returns (uint256);
function depositPool(uint256 _amount, uint8 _pid) external;
function harvestPool(uint8 _pid) external;
function viewPoolTaxRateOverflow(uint8 _pid) external view returns (uint256);
function viewUserAllocationPools(
address _user,
uint8[] calldata _pids
) external view returns (uint256[] memory);
function viewUserInfo(
address _user,
uint8[] calldata _pids
) external view returns (uint256[] memory, bool[] memory);
function viewUserOfferingAndRefundingAmountsForPools(
address _user,
uint8[] calldata _pids
) external view returns (uint256[3][] memory);
function release(bytes32 _vestingScheduleId) external;
function viewPoolVestingInformation(
uint256 _pid
) external view returns (uint256, uint256, uint256, uint256);
function computeVestingScheduleIdForAddressAndPid(
address _holder,
uint8 _pid
) external view returns (bytes32);
function computeReleasableAmount(bytes32 _vestingScheduleId) external view returns (uint256);
function viewPoolInformation(
uint256 _pid
)
external
view
returns (
uint256 raisingAmountPool,
uint256 offeringAmountPool,
uint256 limitPerUserInLP,
bool hasTax,
uint256 totalAmountPool,
uint256 sumTaxesOverflow,
bool isSpecialSale
);
function getVestingSchedule(bytes32 _vestingScheduleId) external view returns (VestingSchedule memory);
}
IICake.sol 15 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
interface IICake {
struct DelegatorConfig {
address VECakeUser;
address delegator;
}
function getUserCreditWithIfoAddr(address _user, address _ifo) external view returns (uint256);
function approveToVECakeUser(address _VECakeUser) external;
function setDelegators(DelegatorConfig[] calldata _delegatorConfigs) external;
}
IPancakeIFOHelper.sol 29 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
interface IPancakeIFOHelper {
function queueNewTokens(uint256 _amountReward, address _rewardToken) external returns (bool);
function getDepositNOfferingToken()
external
view
returns (address _depositToken, address _offeredToken);
function isHarvestFromPancake() external view returns (bool);
function pid() external view returns (uint8);
function setMultiplier(uint256 _multiplier, uint256 _lpMultiplier) external;
function setlpContributionLimit(uint256 _lpDepositLimit) external;
function updateStatus() external;
function pause() external;
function unpause() external;
error DepositExceed();
error UserMaxCapReached();
error IFOMaxCapReached();
}
PancakeStakingLib.sol 398 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import { IERC20, ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { IMasterChefV3 } from "../../interfaces/pancakeswap/IMasterChefV3.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { INonfungiblePositionManager } from "../../interfaces/pancakeswap/INonfungiblePositionManager.sol";
import { INonfungiblePositionManagerStruct } from "../../interfaces/pancakeswap/INonfungiblePositionManagerStruct.sol";
import { IPancakeV3PoolImmutables } from "../../interfaces/pancakeswap/IPancakeV3PoolImmutables.sol";
import { IMintableERC20 } from "../../interfaces/common/IMintableERC20.sol";
import { IRewardDistributor } from "../../interfaces/cakepie/IRewardDistributor.sol";
import { IALMWrapper } from "../../interfaces/pancakeswap/IALMWrapper.sol";
import { IV2Wrapper } from "../../interfaces/pancakeswap/IV2Wrapper.sol";
import { IAdapter } from "../../interfaces/pancakeswap/IAdapter.sol";
import {IPancakeVeSender} from "../../interfaces/pancakeswap/IPancakeVeSender.sol";
import {IIFOV8} from "../../interfaces/pancakeswap/IIFOV8.sol";
import {IPancakeIFOHelper} from "../../interfaces/cakepie/IPancakeIFOHelper.sol";
library PancakeStakingLib {
using SafeERC20 for IERC20;
event V3PoolFeesPaidTo(
address indexed _user,
uint256 _positionId,
address _token,
uint256 _feeAmount
);
event NewTokenStaked(
address indexed _user,
address indexed _poolAddress,
uint256 _tokenID,
uint256 _liquidity
);
event NewTokenUnstaked(
address indexed _user,
address indexed _poolAddress,
uint256 _tokenID,
uint256 _liquidity
);
event BroadcastedVeCakeToChain(uint32 indexed _destChainId);
event VestedIFORewardClaimed(
address indexed pancakeIFOHelper,
address _for,
uint256 claimedAmount,
address rewardToken
);
event IFORewardHarvested(
address indexed pancakeIFOHelper,
address _for,
address rewardToken,
uint256 harvestedAmount,
address refundToken,
uint256 refundAmount
);
event DepositedIntoIFO(address indexed pancakeIFOHelper, uint8 pid, uint256 amount);
error AddressZero();
error TransferFailed();
function depositV3For(
address _for,
address _pool,
uint256 _tokenId,
IMasterChefV3 masterChefV3,
INonfungiblePositionManager nonfungiblePositionManager
) external {
INonfungiblePositionManager.PositionsParams memory params = nonfungiblePositionManager.positions(_tokenId);
nonfungiblePositionManager.safeTransferFrom(_for, address(this), _tokenId);
nonfungiblePositionManager.safeTransferFrom(address(this), address(masterChefV3), _tokenId);
emit NewTokenStaked(_for, _pool, _tokenId, params.liquidity);
}
function withdrawV3For(
address _for,
address _pool,
uint256 _tokenId,
address cake,
IMasterChefV3 masterChefV3,
IRewardDistributor rewardDistributor,
INonfungiblePositionManager nonfungiblePositionManager
) external {
(uint256[] memory tokenId, ) = toArray(_tokenId, address(0));
harvestV3PoolFees(_for, tokenId, masterChefV3, nonfungiblePositionManager);
uint256 balBefore = IERC20(cake).balanceOf(address(this));
IMasterChefV3.UserPositionInfo memory userPositionInfo = masterChefV3.userPositionInfos(
_tokenId
);
masterChefV3.withdraw(_tokenId, address(this));
uint256 boostedRewardShare = (((IERC20(cake).balanceOf(address(this)) - balBefore) *
(userPositionInfo.boostMultiplier - masterChefV3.BOOST_PRECISION())) /
userPositionInfo.boostMultiplier);
handleRewards(
rewardDistributor,
_pool,
cake,
IERC20(cake).balanceOf(address(this)) - balBefore,
_for,
false,
boostedRewardShare,
0
);
INonfungiblePositionManager(nonfungiblePositionManager).safeTransferFrom(
address(this),
_for,
_tokenId
);
emit NewTokenUnstaked(_for, _pool, _tokenId, userPositionInfo.liquidity);
}
function increaseLiquidityV3For(
address _for,
address _pool,
IMasterChefV3 masterChefV3,
IMasterChefV3.IncreaseLiquidityParams calldata params
) external {
address token0 = IPancakeV3PoolImmutables(_pool).token0();
address token1 = IPancakeV3PoolImmutables(_pool).token1();
(uint256 balBeforeToken0, uint256 balBeforeToken1) = checkTokenBalances(token0, token1);
IERC20(token0).safeTransferFrom(msg.sender, address(this), params.amount0Desired);
IERC20(token0).safeIncreaseAllowance(address(masterChefV3), params.amount0Desired);
IERC20(token1).safeTransferFrom(msg.sender, address(this), params.amount1Desired);
IERC20(token1).safeIncreaseAllowance(address(masterChefV3), params.amount1Desired);
masterChefV3.increaseLiquidity(params);
refund(token0, _for, balBeforeToken0);
refund(token1, _for, balBeforeToken1);
}
function decreaseLiquidityV3For(
address _for,
IMasterChefV3 masterChefV3,
INonfungiblePositionManager nonfungiblePositionManager,
IMasterChefV3.DecreaseLiquidityParams calldata params
) external {
(uint256[] memory tokenId, ) = toArray(params.tokenId, address(0));
masterChefV3.decreaseLiquidity(params);
harvestV3PoolFees(_for, tokenId, masterChefV3, nonfungiblePositionManager);
}
function harvestV3(
address _for,
uint256[] memory _tokenIds,
address cake,
IMasterChefV3 masterChefV3,
IRewardDistributor rewardDistributor
) external {
uint256 baseBoostPrecision = masterChefV3.BOOST_PRECISION();
for (uint256 i = 0; i < _tokenIds.length; i++) {
IMasterChefV3.UserPositionInfo memory userPositionInfo = masterChefV3.userPositionInfos(
_tokenIds[i]
);
(, address _pool, , , , , ) = masterChefV3.poolInfo(userPositionInfo.pid);
uint256 balBefore = IERC20(cake).balanceOf(address(this));
masterChefV3.harvest(_tokenIds[i], address(this));
uint256 boostedRewardShare = (((IERC20(cake).balanceOf(address(this)) - balBefore) *
(userPositionInfo.boostMultiplier - baseBoostPrecision)) /
userPositionInfo.boostMultiplier);
handleRewards(
rewardDistributor,
_pool,
address(cake),
IERC20(cake).balanceOf(address(this)) - balBefore,
_for,
false,
boostedRewardShare,
0
);
}
}
function harvestV3PoolFees(
address _for,
uint256[] memory _tokenIds,
IMasterChefV3 masterChefV3,
INonfungiblePositionManager nonfungiblePositionManager
) public {
for (uint256 i = 0; i < _tokenIds.length; i++) {
INonfungiblePositionManager.PositionsParams memory positionParams = nonfungiblePositionManager.positions(_tokenIds[i]);
(uint256 token0BalBefore, uint256 token1BalBefore) = checkTokenBalances(
positionParams.token0,
positionParams.token1
);
INonfungiblePositionManagerStruct.CollectParams
memory params = INonfungiblePositionManagerStruct.CollectParams({
tokenId: _tokenIds[i],
recipient: address(this),
amount0Max: 340282366920938463463374607431768211455,
amount1Max: 340282366920938463463374607431768211455
});
masterChefV3.collect(params);
(uint256 token0BalAfter, uint256 token1BalAfter) = checkTokenBalances(positionParams.token0, positionParams.token1);
// Since fee is not boosted, simply transfer to owner
uint256 diff0 = token0BalAfter - token0BalBefore;
if (diff0 > 0) {
IERC20(positionParams.token0).safeTransfer(_for, diff0);
emit V3PoolFeesPaidTo(_for, _tokenIds[i], positionParams.token0, diff0);
}
uint256 diff1 = token1BalAfter - token1BalBefore;
if (diff1 > 0) {
IERC20(positionParams.token1).safeTransfer(_for, diff1);
emit V3PoolFeesPaidTo(_for, _tokenIds[i], positionParams.token1, diff1);
}
}
}
function handleWithdrawAML(
address _for,
address _pool,
uint256 _amount,
address _token0,
address _token1
) external {
(uint256 balBeforeToken0, uint256 balBeforeToken1) = checkTokenBalances(_token0, _token1);
IALMWrapper(_pool).withdrawThenBurn(_amount, false, "");
(uint256 balAfterToken0, uint256 balAfterToken1) = checkTokenBalances(_token0, _token1);
IERC20(_token0).safeTransfer(_for, balAfterToken0 - balBeforeToken0);
IERC20(_token1).safeTransfer(_for, balAfterToken1 - balBeforeToken1);
}
function handleRewards(
IRewardDistributor rewardDistributor,
address _poolAddress,
address _rewardToken,
uint256 _pendingRewards,
address _to,
bool _isRewarder,
uint256 _boostedRewardShare,
uint256 _minRecTotalMCake
) public {
if (_pendingRewards > 0) {
IERC20(_rewardToken).safeIncreaseAllowance(address(rewardDistributor), _pendingRewards);
IRewardDistributor.RewardParams memory rewardParams = IRewardDistributor.RewardParams({
poolAddress: _poolAddress,
rewardToken: _rewardToken,
finalDestination: _to,
amount: _pendingRewards,
isRewarder: _isRewarder,
boostedRewardShare: _boostedRewardShare,
minRecTotalMCake: _minRecTotalMCake
});
IRewardDistributor(rewardDistributor).sendRewards(
rewardParams
);
}
}
function refund(address _token, address _dustTo, uint256 _balBeforeToken) public {
uint256 dustTokenAmt = IERC20(_token).balanceOf(address(this)) - _balBeforeToken;
if (dustTokenAmt > 0) IERC20(_token).safeTransfer(_dustTo, dustTokenAmt);
}
function checkTokenBalances(
address _token0,
address _token1
) public view returns (uint256, uint256) {
uint256 balBeforeToken0 = IERC20(_token0).balanceOf(address(this));
uint256 balBeforeToken1 = IERC20(_token1).balanceOf(address(this));
return (balBeforeToken0, balBeforeToken1);
}
function toArray(
uint256 _tokenId,
address _poolAddress
) public pure returns (uint256[] memory tokenId, address[] memory poolAddress) {
tokenId = new uint256[](1);
tokenId[0] = _tokenId;
poolAddress = new address[](1);
poolAddress[0] = _poolAddress;
}
function depositIFO(
address _pancakeIFOHelper,
address _pancakeIFO,
uint8 _pid,
address _depositToken,
address _for,
uint256 _amount
) external {
IERC20(_depositToken).safeTransferFrom(_for, address(this), _amount);
IERC20(_depositToken).safeIncreaseAllowance(_pancakeIFO, _amount);
IIFOV8(_pancakeIFO).depositPool(_amount, _pid);
emit DepositedIntoIFO(_pancakeIFOHelper, _pid, _amount);
}
function harvestIFO(
address _pancakeIFOHelper,
address _pancakeIFO,
uint8 _pid,
address _depositToken,
address _rewardToken
) external {
(uint256 balBeforedepositToken, uint256 balBeforeRewardToken) = checkTokenBalances(
_depositToken,
_rewardToken
);
IIFOV8(_pancakeIFO).harvestPool(_pid);
uint256 refundAmt = IERC20(_depositToken).balanceOf(address(this)) - balBeforedepositToken;
uint256 harvestedTokenAmt = IERC20(_rewardToken).balanceOf(address(this)) -
balBeforeRewardToken;
if (refundAmt > 0) {
IERC20(_depositToken).safeIncreaseAllowance(_pancakeIFOHelper, refundAmt);
IPancakeIFOHelper(_pancakeIFOHelper).queueNewTokens(refundAmt, _depositToken);
}
if (harvestedTokenAmt > 0) {
IERC20(_rewardToken).safeIncreaseAllowance(_pancakeIFOHelper, harvestedTokenAmt);
IPancakeIFOHelper(_pancakeIFOHelper).queueNewTokens(harvestedTokenAmt, _rewardToken);
}
emit IFORewardHarvested(
_pancakeIFOHelper,
address(this),
_rewardToken,
harvestedTokenAmt,
_depositToken,
refundAmt
);
}
function releaseIFO(
address _pancakeIFOHelper,
address _pancakeIFO,
bytes32 _vestingScheduleId,
address _rewardToken
) external {
uint256 balBefore = IERC20(_rewardToken).balanceOf(address(this));
IIFOV8(_pancakeIFO).release(_vestingScheduleId);
uint256 earnedVestedReward = IERC20(_rewardToken).balanceOf(address(this)) - balBefore;
if (earnedVestedReward > 0) {
IERC20(_rewardToken).safeIncreaseAllowance(_pancakeIFOHelper, earnedVestedReward);
IPancakeIFOHelper(_pancakeIFOHelper).queueNewTokens(earnedVestedReward, _rewardToken);
}
emit VestedIFORewardClaimed(
_pancakeIFOHelper,
address(this),
earnedVestedReward,
_rewardToken
);
}
function broadcastVeCake(
address _pancakeVeSender,
uint32 _dstChainId,
uint128 _gasForDest,
address owner
) external {
if (_pancakeVeSender == address(0)) revert AddressZero();
IPancakeVeSender(_pancakeVeSender).sendSyncMsg{ value: msg.value }(
_dstChainId,
address(this),
true,
true,
_gasForDest
);
uint256 refundedAmount = address(this).balance;
if (refundedAmount > 0) {
(bool success, ) = payable(owner).call{value: refundedAmount, gas: 5000}("");
if(!success)
revert TransferFailed();
}
emit BroadcastedVeCakeToChain(_dstChainId);
}
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
IERC20Metadata.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
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;
}
}
draft-IERC20Permit.sol 60 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
OwnableUpgradeable.sol 95 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.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 OwnableUpgradeable is Initializable, ContextUpgradeable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
function __Ownable_init() internal onlyInitializing {
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal onlyInitializing {
_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 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);
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}
Initializable.sol 165 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: setting the version to 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized < type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Internal function that returns the initialized version. Returns `_initialized`
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Internal function that returns the initialized version. Returns `_initializing`
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}
ReentrancyGuardUpgradeable.sol 81 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @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 ReentrancyGuardUpgradeable is Initializable {
// 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;
function __ReentrancyGuard_init() internal onlyInitializing {
__ReentrancyGuard_init_unchained();
}
function __ReentrancyGuard_init_unchained() internal onlyInitializing {
_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 This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}
PausableUpgradeable.sol 117 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
function __Pausable_init() internal onlyInitializing {
__Pausable_init_unchained();
}
function __Pausable_init_unchained() internal onlyInitializing {
_paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
require(paused(), "Pausable: not paused");
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}
IERC721ReceiverUpgradeable.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (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 IERC721ReceiverUpgradeable {
/**
* @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 `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
IMasterCakepie.sol 133 lines
// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
interface IMasterCakepie {
function poolLength() external view returns (uint256);
function setPoolManagerStatus(address _address, bool _bool) external;
function add(
uint256 _allocPoint,
address _stakingTokenToken,
address _receiptToken,
address _rewarder,
bool _isV3Pool
) external;
function set(
address _stakingToken,
uint256 _allocPoint,
address _rewarder
) external;
function createRewarder(
address _stakingTokenToken,
address mainRewardToken,
address rewardDistributor
) external returns (address);
// View function to see pending GMPs on frontend.
function getPoolInfo(
address token
)
external
view
returns (uint256 emission, uint256 allocpoint, uint256 sizeOfPool, uint256 totalPoint);
function pendingTokens(
address _stakingToken,
address _user,
address token
)
external
view
returns (
uint256 _pendingGMP,
address _bonusTokenAddress,
string memory _bonusTokenSymbol,
uint256 _pendingBonusToken
);
// function allPendingTokensWithBribe(
// address _stakingToken,
// address _user,
// IBribeRewardDistributor.Claim[] calldata _proof
// )
// external
// view
// returns (
// uint256 pendingCakepie,
// address[] memory bonusTokenAddresses,
// string[] memory bonusTokenSymbols,
// uint256[] memory pendingBonusRewards
// );
function allPendingTokens(
address _stakingToken,
address _user
)
external
view
returns (
uint256 pendingCakepie,
address[] memory bonusTokenAddresses,
string[] memory bonusTokenSymbols,
uint256[] memory pendingBonusRewards
);
function massUpdatePools() external;
function updatePool(address _stakingToken) external;
function deposit(address _stakingToken, uint256 _amount) external;
function depositFor(address _stakingToken, address _for, uint256 _amount) external;
function withdraw(address _stakingToken, uint256 _amount) external;
function beforeReceiptTokenTransfer(address _from, address _to, uint256 _amount) external;
function afterReceiptTokenTransfer(address _from, address _to, uint256 _amount) external;
function depositVlCakepieFor(uint256 _amount, address sender) external;
function withdrawVlCakepieFor(uint256 _amount, address sender) external;
function depositMCakeSVFor(uint256 _amount, address sender) external;
function withdrawMCakeSVFor(uint256 _amount, address sender) external;
function multiclaimFor(
address[] calldata _stakingTokens,
address[][] calldata _rewardTokens,
address user_address
) external;
function multiclaimMCake(
address[] calldata _stakingTokens,
address[][] calldata _rewardTokens,
address user_address,
uint256 _minRecMCake
) external;
function multiclaimOnBehalf(
address[] memory _stakingTokens,
address[][] calldata _rewardTokens,
address user_address
) external;
function multiclaim(address[] calldata _stakingTokens) external;
function emergencyWithdraw(address _stakingToken, address sender) external;
function updateEmissionRate(uint256 _gmpPerSec) external;
function stakingInfo(
address _stakingToken,
address _user
) external view returns (uint256 depositAmount, uint256 availableAmount);
function cakeRewardToMcake(address _stakingToken) external view returns (bool);
}
INonfungiblePositionManager.sol 194 lines
// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
/// @title Non-fungible token for positions
/// @notice Wraps PancakeSwap V3 positions in a non-fungible token interface which allows for them to be transferred
/// and authorized.
interface INonfungiblePositionManager is IERC721Metadata, IERC721Enumerable {
/// @notice Emitted when liquidity is increased for a position NFT
/// @dev Also emitted when a token is minted
/// @param tokenId The ID of the token for which liquidity was increased
/// @param liquidity The amount by which liquidity for the NFT position was increased
/// @param amount0 The amount of token0 that was paid for the increase in liquidity
/// @param amount1 The amount of token1 that was paid for the increase in liquidity
event IncreaseLiquidity(
uint256 indexed tokenId,
uint128 liquidity,
uint256 amount0,
uint256 amount1
);
/// @notice Emitted when liquidity is decreased for a position NFT
/// @param tokenId The ID of the token for which liquidity was decreased
/// @param liquidity The amount by which liquidity for the NFT position was decreased
/// @param amount0 The amount of token0 that was accounted for the decrease in liquidity
/// @param amount1 The amount of token1 that was accounted for the decrease in liquidity
event DecreaseLiquidity(
uint256 indexed tokenId,
uint128 liquidity,
uint256 amount0,
uint256 amount1
);
/// @notice Emitted when tokens are collected for a position NFT
/// @dev The amounts reported may not be exactly equivalent to the amounts transferred, due to rounding behavior
/// @param tokenId The ID of the token for which underlying tokens were collected
/// @param recipient The address of the account that received the collected tokens
/// @param amount0 The amount of token0 owed to the position that was collected
/// @param amount1 The amount of token1 owed to the position that was collected
event Collect(uint256 indexed tokenId, address recipient, uint256 amount0, uint256 amount1);
/**
* @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;
struct PositionsParams {
uint96 nonce;
address operator;
address token0;
address token1;
uint24 fee;
int24 tickLower;
int24 tickUpper;
uint128 liquidity;
uint256 feeGrowthInside0LastX128;
uint256 feeGrowthInside1LastX128;
uint128 tokensOwed0;
uint128 tokensOwed1;
}
function positions(
uint256 tokenId
) external view returns (
PositionsParams memory params
);
struct MintParams {
address token0;
address token1;
uint24 fee;
int24 tickLower;
int24 tickUpper;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
address recipient;
uint256 deadline;
}
/// @notice Creates a new position wrapped in a NFT
/// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized
/// a method does not exist, i.e. the pool is assumed to be initialized.
/// @param params The params necessary to mint a position, encoded as `MintParams` in calldata
/// @return tokenId The ID of the token that represents the minted position
/// @return liquidity The amount of liquidity for this position
/// @return amount0 The amount of token0
/// @return amount1 The amount of token1
function mint(
MintParams calldata params
)
external
payable
returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
struct IncreaseLiquidityParams {
uint256 tokenId;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
/// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender`
/// @param params tokenId The ID of the token for which liquidity is being increased,
/// amount0Desired The desired amount of token0 to be spent,
/// amount1Desired The desired amount of token1 to be spent,
/// amount0Min The minimum amount of token0 to spend, which serves as a slippage check,
/// amount1Min The minimum amount of token1 to spend, which serves as a slippage check,
/// deadline The time by which the transaction must be included to effect the change
/// @return liquidity The new liquidity amount as a result of the increase
/// @return amount0 The amount of token0 to acheive resulting liquidity
/// @return amount1 The amount of token1 to acheive resulting liquidity
function increaseLiquidity(
IncreaseLiquidityParams calldata params
) external payable returns (uint128 liquidity, uint256 amount0, uint256 amount1);
struct DecreaseLiquidityParams {
uint256 tokenId;
uint128 liquidity;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
/// @notice Decreases the amount of liquidity in a position and accounts it to the position
/// @param params tokenId The ID of the token for which liquidity is being decreased,
/// amount The amount by which liquidity will be decreased,
/// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,
/// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,
/// deadline The time by which the transaction must be included to effect the change
/// @return amount0 The amount of token0 accounted to the position's tokens owed
/// @return amount1 The amount of token1 accounted to the position's tokens owed
function decreaseLiquidity(
DecreaseLiquidityParams calldata params
) external payable returns (uint256 amount0, uint256 amount1);
struct CollectParams {
uint256 tokenId;
address recipient;
uint128 amount0Max;
uint128 amount1Max;
}
/// @notice Collects up to a maximum amount of fees owed to a specific position to the recipient
/// @param params tokenId The ID of the NFT for which tokens are being collected,
/// recipient The account that should receive the tokens,
/// amount0Max The maximum amount of token0 to collect,
/// amount1Max The maximum amount of token1 to collect
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collect(
CollectParams calldata params
) external payable returns (uint256 amount0, uint256 amount1);
/// @notice Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens
/// must be collected first.
/// @param tokenId The ID of the token that is being burned
function burn(uint256 tokenId) external payable;
function isApproved(uint256 tokenId) external view returns (address);
}
IMasterChefV3.sol 108 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.8.19;
import { INonfungiblePositionManagerStruct } from "./INonfungiblePositionManagerStruct.sol";
interface IMasterChefV3 is INonfungiblePositionManagerStruct {
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);
struct UserPositionInfo {
uint128 liquidity;
uint128 boostLiquidity;
int24 tickLower;
int24 tickUpper;
uint256 rewardGrowthInside;
uint256 reward;
address user;
uint256 pid;
uint256 boostMultiplier;
}
function userPositionInfos(
uint256 tokenId
)
external
view
returns (
UserPositionInfo memory
);
function updateLiquidity(uint256 _tokenId) external;
function updatePools(uint256[] memory _pids) external;
/// @notice Withdraw LP tokens from pool.
/// @param _tokenId Token Id of NFT to deposit.
/// @param _to Address to which NFT token to withdraw.
/// @return reward Cake reward.
function withdraw(uint256 _tokenId, address _to) external returns (uint256 reward);
function balanceOf(address account) external view returns (uint256);
/// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender`
/// @param params tokenId The ID of the token for which liquidity is being increased,
/// amount0Desired The desired amount of token0 to be spent,
/// amount1Desired The desired amount of token1 to be spent,
/// amount0Min The minimum amount of token0 to spend, which serves as a slippage check,
/// amount1Min The minimum amount of token1 to spend, which serves as a slippage check,
/// deadline The time by which the transaction must be included to effect the change
/// @return liquidity The new liquidity amount as a result of the increase
/// @return amount0 The amount of token0 to acheive resulting liquidity
/// @return amount1 The amount of token1 to acheive resulting liquidity
function increaseLiquidity(
IncreaseLiquidityParams memory params
) external payable returns (uint128 liquidity, uint256 amount0, uint256 amount1);
/// @notice Decreases the amount of liquidity in a position and accounts it to the position
/// @param params tokenId The ID of the token for which liquidity is being decreased,
/// amount The amount by which liquidity will be decreased,
/// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,
/// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,
/// deadline The time by which the transaction must be included to effect the change
/// @return amount0 The amount of token0 accounted to the position's tokens owed
/// @return amount1 The amount of token1 accounted to the position's tokens owed
function decreaseLiquidity(
DecreaseLiquidityParams memory params
) external returns (uint256 amount0, uint256 amount1);
function pendingCake(uint256 _tokenId) external view returns (uint256 reward);
/// @notice harvest cake from pool.
/// @param _tokenId Token Id of NFT.
/// @param _to Address to.
/// @return reward Cake reward.
function harvest(uint256 _tokenId, address _to) external returns (uint256 reward);
function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);
function unwrapWETH9(uint256 amountMinimum, address recipient) external;
function sweepToken(address token, uint256 amountMinimum, address recipient) external;
function collect(
CollectParams memory params
) external returns (uint256 amount0, uint256 amount1);
function poolInfo(
uint256 poolId
)
external
view
returns (
uint256 allocPoint,
address v3Pool,
address token0,
address token1,
uint24 fee,
uint256 totalLiquidity,
uint256 totalBoostLiquidity
);
function v3PoolAddressPid(address pool) external view returns (uint256 pid);
function WETH() external view returns (address weth);
function totalAllocPoint() external view returns (uint256 value);
function latestPeriodCakePerSecond() external view returns (uint256 value);
function poolLength() external view returns (uint256);
function FARM_BOOSTER() external view returns (address);
function BOOST_PRECISION() external view returns (uint256);
}
IALMWrapper.sol 46 lines
// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;
interface IALMWrapper {
/*
* @notice Deposit staked tokens and collect reward tokens (if any)
* @param _amount: amount to deposit (in stakeToken)
*/
function deposit(uint256 _amount, bool _noHarvest) external;
/*
* @notice Withdraw staked tokens and collect reward tokens
* @param _amount: amount to withdraw (in rewardToken)
*/
function withdraw(uint256 _amount) external;
/*
* @notice Mint then deposit staked tokens and collect reward tokens (if any)
* @param _amount0: token0 amount to deposit (in token0)
* @param _amount1: token0 amount to deposit (in token1)
* @param _data: payload data from FE side
*/
function mintThenDeposit(uint256 _amount0, uint _amount1, bool _noHarvest, bytes calldata _data) external;
/*
* @notice Withdraw then burn staked tokens and collect reward tokens
* @param _amount: amount to withdraw (in rewardToken)
* @param _data: payload data from FE side
*/
function withdrawThenBurn(uint256 _amount, bool _noHarvest, bytes calldata _data) external;
function pendingReward(address _user) external view returns (uint256);
// TODO will have to update userInfo struct when new AMLWrapper deployed
function userInfo(
address userAddress
) external view returns (
uint256 amount, // How many staked tokens the user has provided
uint256 rewardDebt
// uint256 boostMultiplier, // currently active multiplier
// uint256 boostedAmount, // combined boosted amount
// uint256 unsettledRewards // rewards haven't been transferred to users but already accounted in rewardDebt
);
function adapterAddr() external view returns (address);
}
IAdapter.sol 32 lines
// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;
interface IAdapter {
function token0() external view returns (address);
function token1() external view returns (address);
function deposit(
uint256 _amount0,
uint256 _amount1,
address _user,
bytes calldata _data
) external returns (uint256 _share);
function withdraw(
uint256 _share,
address _user,
bytes calldata _data
) external returns (uint256 _amount0, uint256 _amount1);
function initialize(
address _wrapper,
address _vault,
address _token0,
address _token1,
address _lpToken,
address _admin
) external;
function wrapper() external returns (address);
}
IV2Wrapper.sol 20 lines
// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;
interface IV2Wrapper {
struct UserInfo {
uint256 amount; // How many staked tokens the user has provided
uint256 rewardDebt;
uint256 boostMultiplier; // currently active multiplier
uint256 boostedAmount; // combined boosted amount
uint256 unsettledRewards; // rewards haven't been transferred to users but already accounted in rewardDebt
}
function deposit(uint256 _amount, bool _noHarvest) external;
function withdraw(uint256 _amount, bool _noHarvest) external;
function pendingReward(address _userAddress) external view returns (uint256);
function userInfo(address _userAddress) external view returns (UserInfo memory);
}
ERC20FactoryLib.sol 31 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma experimental ABIEncoderV2;
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { CakepieReceiptToken } from "../../cakepie/tokens/CakepieReceiptToken.sol";
import { BaseRewardPoolV3 } from "../../cakepie/rewards/BaseRewardPoolV3.sol";
library ERC20FactoryLib {
function createReceipt(address _stakeToken, address _masterCakepie, address _pancakeStaking, string memory _name, string memory _symbol) public returns(address)
{
ERC20 token = new CakepieReceiptToken(_stakeToken, _masterCakepie, _pancakeStaking, _name, _symbol);
return address(token);
}
function createRewarder(
address _receiptToken,
address mainRewardToken,
address _masterCakepie,
address _rewardQueuer
) external returns (address) {
BaseRewardPoolV3 _rewarder = new BaseRewardPoolV3(
_receiptToken,
mainRewardToken,
_masterCakepie,
_rewardQueuer
);
return address(_rewarder);
}
}
IMintableERC20.sol 92 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)
pragma solidity =0.8.19;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IMintableERC20 {
/**
* @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);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
/**
* @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);
function mint(address, uint256) external;
function faucet(uint256) external;
function burn(address, uint256) external;
/**
* @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);
}
IRewardDistributor.sol 41 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
interface IRewardDistributor {
error minReceivedNotMet();
struct Fees {
uint256 value; // allocation denominated by DENOMINATOR
address to;
bool isMCAKE;
bool isAddress;
bool isActive;
}
struct RewardParams {
address poolAddress;
address rewardToken;
address finalDestination;
uint256 amount;
bool isRewarder;
uint256 boostedRewardShare;
uint256 minRecTotalMCake;
}
function pancakeFeeInfos(uint256 index) external view returns (Fees memory);
function sendRewards(
RewardParams memory _params
) external;
function sendVeReward(
address _rewardSource,
address _rewardToken,
uint256 _amount,
bool _isVeCake,
uint256 _minRec
) external;
function CKPRatio() external view returns (uint256);
}
IPancakeV3Helper.sol 8 lines
// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;
interface IPancakeV3Helper {
function tokenToPool(uint256 _tokenId) external view returns (address);
function harvestRewardAndFeeFor(address _for, uint256[] memory _tokenId) external;
}
IBaseRewardPool.sol 37 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
interface IBaseRewardPool {
function stakingDecimals() external view returns (uint256);
function totalStaked() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function rewardPerToken(address token) external view returns (uint256);
function rewardTokenInfos()
external
view
returns (address[] memory bonusTokenAddresses, string[] memory bonusTokenSymbols);
function earned(address account, address token) external view returns (uint256);
function allEarned(
address account
) external view returns (uint256[] memory pendingBonusRewards);
function queueNewRewards(uint256 _rewards, address token) external returns (bool);
function getReward(address _account, address _receiver) external returns (bool);
function getRewards(
address _account,
address _receiver,
address[] memory _rewardTokens
) external;
function updateFor(address account) external;
function updateRewardQueuer(address _rewardManager, bool _allowed) external;
}
INonfungiblePositionManagerStruct.sol 28 lines
// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;
interface INonfungiblePositionManagerStruct {
struct IncreaseLiquidityParams {
uint256 tokenId;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
struct DecreaseLiquidityParams {
uint256 tokenId;
uint128 liquidity;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
struct CollectParams {
uint256 tokenId;
address recipient;
uint128 amount0Max;
uint128 amount1Max;
}
}
IPancakeV3PoolImmutables.sol 29 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.8.19;
/// @title Pool state that never changes
/// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values
interface IPancakeV3PoolImmutables {
/// @notice The contract that deployed the pool, which must adhere to the IPancakeV3Factory interface
/// @return The contract address
function factory() external view returns (address);
/// @notice The first of the two tokens of the pool, sorted by address
/// @return The token contract address
function token0() external view returns (address);
/// @notice The second of the two tokens of the pool, sorted by address
/// @return The token contract address
function token1() external view returns (address);
/// @notice The pool's fee in hundredths of a bip, i.e. 1e-6
/// @return The fee
function fee() external view returns (uint24);
/// @notice The pool tick spacing
/// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive
/// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ...
/// This value is an int24 to avoid casting even though it is always positive.
/// @return The tick spacing
function tickSpacing() external view returns (int24);
}
IPancakeVeSender.sol 23 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
interface IPancakeVeSender {
struct MessagingFee {
uint256 nativeFee;
uint256 lzTokenFee;
}
function sendSyncMsg(
uint32 _dstChainId,
address _user,
bool _syncVeCake,
bool _syncProfile,
uint128 _gasForDest
) external payable;
function getEstimateGasFees(
uint32 _dstChainId,
uint128 _gasForDest
) external view returns (MessagingFee memory fee);
}
ContextUpgradeable.sol 37 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @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 ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}
AddressUpgradeable.sol 219 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
IERC721Metadata.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}
IERC721Enumerable.sol 29 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
IERC721.sol 145 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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);
}
CakepieReceiptToken.sol 77 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/ERC20.sol)
pragma solidity ^0.8.19;
import { ERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { IMasterCakepie } from "../../interfaces/cakepie/IMasterCakepie.sol";
import { IPancakeStaking } from "../../interfaces/cakepie/IPancakeStaking.sol";
/// @title CakepieReceiptToken is to represent a Pancake pools deposited to cakepie posistion. CakepieReceiptToken is minted to user who deposited pools token
/// on Pancake staking to increase defi lego
///
/// Reward from Magpie and on BaseReward should be updated upon every transfer.
///
/// @author Magpie Team
/// @notice Mater cakepie emit `CKP` reward token based on Time. For a pool,
contract CakepieReceiptToken is ERC20, Ownable {
using SafeERC20 for IERC20Metadata;
using SafeERC20 for IERC20;
address public underlying; // pool address if a pancake pool, underlying otken if a masterCakepie pool
address public immutable masterCakepie;
address public immutable pancakeStaking; // pancakStaking none zero address, means the receipt token represents a LP staked on cakepie getting boosted yield
/* ============ Constructor ============ */
constructor(address _underlying, address _masterCakepie, address _pancakeStaking, string memory name, string memory symbol) ERC20(name, symbol) {
underlying = _underlying;
masterCakepie = _masterCakepie;
pancakeStaking = _pancakeStaking;
}
// should only be called by 1. pancakestaking for Pancake pools deposits 2. masterCakepie for other general staking token such as mCAKEOFT or CKP Lp tokens
function mint(address account, uint256 amount) external virtual onlyOwner {
_mint(account, amount);
}
// should only be called by 1. pancakestaking for Pancake pools deposits 2. masterCakepie for other general staking token such as mCAKEOFT or CKP Lp tokens
function burn(address account, uint256 amount) external virtual onlyOwner {
_burn(account, amount);
}
/* ============ Internal Functions ============ */
// rewards are calculated based on user's receipt token balance, so reward should be updated on master cakepie before transfer
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal override {
// no need to harvest again if mint or burn (trigger upon deposit or withdraw)
if (from != address(0) && to != address(0)) _checkHarvestPancake();
IMasterCakepie(masterCakepie).beforeReceiptTokenTransfer(from, to, amount);
}
// rewards are calculated based on user's receipt token balance, so balance should be updated on master cakepie before transfer
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal override {
// no need to harvest again if mint or burn (trigger upon deposit or withdraw)
if (from != address(0) && to != address(0)) _checkHarvestPancake();
IMasterCakepie(masterCakepie).afterReceiptTokenTransfer(from, to, amount);
}
function _checkHarvestPancake() internal {
if (pancakeStaking != address(0)) {
IPancakeStaking(pancakeStaking).genericHarvest(underlying);
}
}
}
BaseRewardPoolV3.sol 331 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import { IMasterCakepie } from "../../interfaces/cakepie/IMasterCakepie.sol";
import { IBaseRewardPool } from "../../interfaces/cakepie/IBaseRewardPool.sol";
/// @title A contract for managing rewards for a pool
/// @author Magpie Team
/// @notice You can use this contract for getting informations about rewards for a specific pools
contract BaseRewardPoolV3 is Ownable, IBaseRewardPool, ReentrancyGuard {
using SafeERC20 for IERC20Metadata;
using SafeERC20 for IERC20;
/* ============ State Variables ============ */
uint256 public constant DENOMINATOR = 10 ** 12;
address public immutable receiptToken;
address public immutable operator; // master Cakepie
uint256 public immutable receiptTokenDecimals;
address[] public rewardTokens;
struct Reward {
uint256 rewardPerTokenStored; // will apply a DENOMINATOR to prevent underflow
uint256 queuedRewards;
}
struct UserInfo {
uint256 userRewardPerTokenPaid;
uint256 userRewards;
}
mapping(address => Reward) public rewards; // [rewardToken]
// amount by [rewardToken][account],
mapping(address => mapping(address => UserInfo)) public userInfos;
mapping(address => bool) public isRewardToken;
mapping(address => bool) public rewardQueuers;
/* ============ Events ============ */
event RewardAdded(uint256 _reward, address indexed _token);
event Staked(address indexed _user, uint256 _amount);
event Withdrawn(address indexed _user, uint256 _amount);
event RewardPaid(
address indexed _user,
address indexed _receiver,
uint256 _reward,
address indexed _token
);
event RewardQueuerUpdated(address indexed _manager, bool _allowed);
event EmergencyWithdrawn(address indexed _to, uint256 _amount);
/* ============ Errors ============ */
error OnlyRewardQueuer();
error OnlyMasterCakepie();
error NotAllowZeroAddress();
error MustBeRewardToken();
/* ============ Constructor ============ */
constructor(
address _receiptToken,
address _rewardToken,
address _masterCakepie,
address _rewardQueuer
) {
if (
_receiptToken == address(0) ||
_masterCakepie == address(0) ||
_rewardQueuer == address(0)
) revert NotAllowZeroAddress();
receiptToken = _receiptToken;
receiptTokenDecimals = IERC20Metadata(receiptToken).decimals();
operator = _masterCakepie;
if (_rewardToken != address(0)) {
rewards[_rewardToken] = Reward({ rewardPerTokenStored: 0, queuedRewards: 0 });
rewardTokens.push(_rewardToken);
isRewardToken[_rewardToken] = true;
}
rewardQueuers[_rewardQueuer] = true;
}
/* ============ Modifiers ============ */
modifier onlyRewardQueuer() {
if (!rewardQueuers[msg.sender]) revert OnlyRewardQueuer();
_;
}
modifier onlyMasterCakepie() {
if (msg.sender != operator) revert OnlyMasterCakepie();
_;
}
modifier updateReward(address _account) {
_updateFor(_account);
_;
}
modifier updateRewards(address _account, address[] memory _rewards) {
uint256 length = _rewards.length;
uint256 userShare = balanceOf(_account);
for (uint256 index = 0; index < length; ++index) {
address rewardToken = _rewards[index];
UserInfo storage userInfo = userInfos[rewardToken][_account];
// if a reward stopped queuing, no need to recalculate to save gas fee
if (userInfo.userRewardPerTokenPaid == rewardPerToken(rewardToken)) continue;
userInfo.userRewards = _earned(_account, rewardToken, userShare);
userInfo.userRewardPerTokenPaid = rewardPerToken(rewardToken);
}
_;
}
/* ============ External Getters ============ */
/// @notice Returns current amount of staked tokens
/// @return Returns current amount of staked tokens
function totalStaked() public view virtual override returns (uint256) {
return IERC20(receiptToken).totalSupply();
}
/// @notice Returns amount of staked tokens in master Cakepie by account
/// @param _account Address account
/// @return Returns amount of staked tokens by account
function balanceOf(address _account) public view virtual override returns (uint256) {
return IERC20(receiptToken).balanceOf(_account);
}
function stakingDecimals() external view virtual override returns (uint256) {
return receiptTokenDecimals;
}
/// @notice Returns amount of reward token per staking tokens in pool in 10**12
/// @param _rewardToken Address reward token
/// @return Returns amount of reward token per staking tokens in pool in 10**12
function rewardPerToken(address _rewardToken) public view override returns (uint256) {
return rewards[_rewardToken].rewardPerTokenStored;
}
function rewardTokenInfos()
external
view
override
returns (address[] memory bonusTokenAddresses, string[] memory bonusTokenSymbols)
{
uint256 rewardTokensLength = rewardTokens.length;
bonusTokenAddresses = new address[](rewardTokensLength);
bonusTokenSymbols = new string[](rewardTokensLength);
for (uint256 i; i < rewardTokensLength; i++) {
bonusTokenAddresses[i] = rewardTokens[i];
bonusTokenSymbols[i] = IERC20Metadata(address(bonusTokenAddresses[i])).symbol();
}
}
/// @notice Returns amount of reward token earned by a user
/// @param _account Address account
/// @param _rewardToken Address reward token
/// @return Returns amount of reward token earned by a user
function earned(address _account, address _rewardToken) public view override returns (uint256) {
return _earned(_account, _rewardToken, balanceOf(_account));
}
/// @notice Returns amount of all reward tokens
/// @param _account Address account
/// @return pendingBonusRewards as amounts of all rewards.
function allEarned(
address _account
) external view override returns (uint256[] memory pendingBonusRewards) {
uint256 length = rewardTokens.length;
pendingBonusRewards = new uint256[](length);
for (uint256 i = 0; i < length; i++) {
pendingBonusRewards[i] = earned(_account, rewardTokens[i]);
}
return pendingBonusRewards;
}
function getRewardLength() external view returns (uint256) {
return rewardTokens.length;
}
/* ============ External Functions ============ */
/// @notice Updates the reward information for one account
/// @param _account Address account
function updateFor(address _account) external override nonReentrant {
_updateFor(_account);
}
function getReward(
address _account,
address _receiver
) public nonReentrant onlyMasterCakepie updateReward(_account) returns (bool) {
uint256 length = rewardTokens.length;
for (uint256 index = 0; index < length; ++index) {
address rewardToken = rewardTokens[index];
uint256 reward = userInfos[rewardToken][_account].userRewards; // updated during updateReward modifier
if (reward > 0) {
_sendReward(rewardToken, _account, _receiver, reward);
}
}
return true;
}
function getRewards(
address _account,
address _receiver,
address[] memory _rewardTokens
) external override nonReentrant onlyMasterCakepie updateRewards(_account, _rewardTokens) {
uint256 length = _rewardTokens.length;
for (uint256 index = 0; index < length; ++index) {
address rewardToken = _rewardTokens[index];
uint256 reward = userInfos[rewardToken][_account].userRewards; // updated during updateReward modifier
if (reward > 0) {
_sendReward(rewardToken, _account, _receiver, reward);
}
}
}
/// @notice Sends new rewards to be distributed to the users staking. Only possible to donate already registered token
/// @param _amountReward Amount of reward token to be distributed
/// @param _rewardToken Address reward token
function donateRewards(uint256 _amountReward, address _rewardToken) external nonReentrant {
if (!isRewardToken[_rewardToken]) revert MustBeRewardToken();
_provisionReward(_amountReward, _rewardToken);
}
/* ============ Admin Functions ============ */
function updateRewardQueuer(address _rewardManager, bool _allowed) external onlyOwner {
rewardQueuers[_rewardManager] = _allowed;
emit RewardQueuerUpdated(_rewardManager, rewardQueuers[_rewardManager]);
}
/// @notice Sends new rewards to be distributed to the users staking. Only callable by manager
/// @param _amountReward Amount of reward token to be distributed
/// @param _rewardToken Address reward token
function queueNewRewards(
uint256 _amountReward,
address _rewardToken
) external override nonReentrant onlyRewardQueuer returns (bool) {
if (!isRewardToken[_rewardToken]) {
rewards[_rewardToken] = Reward({ rewardPerTokenStored: 0, queuedRewards: 0 });
rewardTokens.push(_rewardToken);
isRewardToken[_rewardToken] = true;
}
_provisionReward(_amountReward, _rewardToken);
return true;
}
function emergencyWithdraw(address _rewardToken, address _to) external nonReentrant onlyMasterCakepie {
uint256 amount = IERC20(_rewardToken).balanceOf(address(this));
IERC20(_rewardToken).safeTransfer(_to, amount);
emit EmergencyWithdrawn(_to, amount);
}
/* ============ Internal Functions ============ */
function _provisionReward(uint256 _amountReward, address _rewardToken) internal {
IERC20(_rewardToken).safeTransferFrom(msg.sender, address(this), _amountReward);
Reward storage rewardInfo = rewards[_rewardToken];
uint256 totalStake = totalStaked();
if (totalStake == 0) {
rewardInfo.queuedRewards += _amountReward;
} else {
if (rewardInfo.queuedRewards > 0) {
_amountReward += rewardInfo.queuedRewards;
rewardInfo.queuedRewards = 0;
}
rewardInfo.rewardPerTokenStored =
rewardInfo.rewardPerTokenStored +
(_amountReward * 10 ** receiptTokenDecimals * DENOMINATOR) /
totalStake;
}
emit RewardAdded(_amountReward, _rewardToken);
}
function _earned(
address _account,
address _rewardToken,
uint256 _userShare
) internal view returns (uint256) {
UserInfo storage userInfo = userInfos[_rewardToken][_account];
return
((_userShare * (rewardPerToken(_rewardToken) - userInfo.userRewardPerTokenPaid)) /
(10 ** receiptTokenDecimals * DENOMINATOR)) + userInfo.userRewards;
}
function _sendReward(
address _rewardToken,
address _account,
address _receiver,
uint256 _amount
) internal {
userInfos[_rewardToken][_account].userRewards = 0;
IERC20(_rewardToken).safeTransfer(_receiver, _amount);
emit RewardPaid(_account, _receiver, _amount, _rewardToken);
}
function _updateFor(address _account) internal {
uint256 length = rewardTokens.length;
for (uint256 index = 0; index < length; ++index) {
address rewardToken = rewardTokens[index];
UserInfo storage userInfo = userInfos[rewardToken][_account];
// if a reward stopped queuing, no need to recalculate to save gas fee
if (userInfo.userRewardPerTokenPaid == rewardPerToken(rewardToken)) continue;
userInfo.userRewards = earned(_account, rewardToken);
userInfo.userRewardPerTokenPaid = rewardPerToken(rewardToken);
}
}
}
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);
}
Ownable.sol 83 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.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 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);
}
}
IPancakeStaking.sol 101 lines
// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;
import "../pancakeswap/IMasterChefV3.sol";
interface IPancakeStaking {
function increaseLock(uint256 amount) external;
function veCake() external returns (address);
function pools(
address _poolAddress
)
external
view
returns (
address poolAddress,
address depositToken,
address rewarder,
address receiptToken,
uint256 lastHarvestTime,
uint256 poolType,
uint256 v3Liquidity,
bool isAmount0,
bool isNative,
bool isActive
);
function depositV3For(address _for, address _v3Pool, uint256 _tokenId) external;
function withdrawV3For(address _for, address _v3Pool, uint256 _tokenId) external;
function increaseLiquidityV3For(
address _for,
address _v3Pool,
IMasterChefV3.IncreaseLiquidityParams calldata params
) external;
function decreaseLiquidityV3For(
address _for,
address _v3Pool,
IMasterChefV3.DecreaseLiquidityParams calldata params
) external;
function harvestV3(address _for, uint256[] memory tokenIds) external;
function harvestV3PoolFees(address _for, uint256[] memory tokenIds) external payable;
function depositV2LPFor(address _for, address _poolAddress, uint256 _amount) external;
function withdrawV2LPFor(address _for, address _poolAddress, uint256 _amount) external;
function harvestV2LP(address[] memory poolAddress, uint256[] memory minRecTotalMCake) external;
function depositAMLFor(address _for, address _poolAddress, uint256 _amount0, uint256 _amount1) external;
function withdrawAMLFor(address _for, address _poolAddress, uint256 _amount) external;
function castVote(
address[] memory _pools,
uint256[] memory _weights,
uint256[] memory _chainIds
) external;
function harvestAML(address[] memory poolAddress, uint256[] memory minRecTotalMCake) external;
function genericHarvest(address poolAddress) external;
function poolLength() external returns (uint256);
function depositIFO(
address _pancakeIFOHelper,
address _pancakeIFO,
uint8 _pid,
address _depsoitToken,
address _for,
uint256 _amount
) external;
function harvestIFO(
address _pancakeIFOHelper,
address _pancakeIFO,
uint8 _pid,
address _depositToken,
address _rewardToken
) external;
function releaseIFO(
address _pancakeIFOHelper,
address _pancakeIFO,
bytes32 _vestingScheduleId,
address _rewardToken
) external;
function allowedOperator(address _account) external returns (bool);
function V3Type() external returns (uint256);
function V2Type() external returns (uint256);
function AMLType() external returns (uint256);
function StableSwapType() external returns (uint256);
}
ReentrancyGuard.sol 69 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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;
}
}
Read Contract
AMLType 0x6a81d9d8 → uint256
CAKE 0x4ca6ef28 → address
StableSwapType 0xe7a25f87 → uint256
V2Type 0x75da8421 → uint256
V3Type 0xf0b77709 → uint256
allowedOperator 0xfc1be7d5 → bool
cakepieIFOManager 0x45a6805d → address
harvestTimeGap 0xefbd9060 → uint256
mCake 0x0dae33e1 → address
mCakeConvertorSideChain 0x6b73e957 → address
masterCakepie 0xb4c341e5 → address
masterChefV3 0xcb65b5b5 → address
nonfungiblePositionManager 0xb44a2722 → address
owner 0x8da5cb5b → address
pancakeAMLHelper 0x2cfbbfec → address
pancakeV2LPHelper 0x41302c22 → address
pancakeV3Helper 0x164af9dd → address
paused 0x5c975abb → bool
poolLength 0x081e3eda → uint256
poolList 0x2a48235b → address
pools 0xa4063dbc → address, address, address, address, uint256, uint256, uint256, bool, bool, bool
rewardDistributor 0xacc2166a → address
voteManager 0x42c1e587 → address
Write Contract 33 functions
These functions modify contract state and require a wallet transaction to execute.
__PancakeStakingBaseUpg_init 0x27d8258d
address _CAKE
address _mCake
address _masterCakepie
__PancakeStakingSideChain_init 0xefe7f82f
address _CAKE
address _mCake
address _masterCakepie
approveToLocker 0x58bf14a0
address _iCake
address _veCakeUser
claimArbFromMerkl 0x4f8a7468
uint256[] _amount
bytes32[][] _proofs
address _rewardToken
address _angleMerkleDistributor
address _arbRewardDistributor
config 0x62a2416b
address _masterChefV3
address _masterCakepie
address _nonfungiblePositionManager
address _rewardDistributor
address _pancakeV3Helper
address _pancakeV2LPHelper
address _pancakeAMLHelper
decreaseLiquidityV3For 0xa0e10783
address _for
address _v3Pool
tuple params
depositAMLFor 0x48ded71c
address _for
address _pool
uint256 _amount0
uint256 _amount1
depositIFO 0x400d592b
address _pancakeIFOHelper
address _pancakeIFO
uint8 _pid
address _depositToken
address _for
uint256 _amount
depositV2LPFor 0x963978f2
address _for
address _pool
uint256 _amount
depositV3For 0xdbdf526b
address _for
address _v3Pool
uint256 _tokenId
genericHarvest 0x7fab32aa
address _pool
harvestAML 0xcdcaf956
address[] _pool
uint256[] _minRecTotalMCake
harvestIFO 0xd6e28c49
address _pancakeIFOHelper
address _pancakeIFO
uint8 _pid
address _depositToken
address _rewardToken
harvestV2LP 0x6839f9d8
address[] _pool
uint256[] _minRecTotalMCake
harvestV3 0xd74e95df
address _for
uint256[] _tokenIds
harvestV3PoolFees 0x8d9f387d
address _for
uint256[] _tokenIds
increaseLiquidityV3For 0x2c855e54
address _for
address _v3Pool
tuple params
onERC721Received 0x150b7a02
address
address from
uint256 tokenId
bytes
returns: bytes4
pause 0x8456cb59
No parameters
registerPool 0x103edada
address _poolAddress
uint256 _allocPoints
address _depositToken
uint256 _poolType
string _name
string _symbol
bool _isAmount0
bool _isNative
releaseIFO 0x1a4707ed
address _pancakeIFOHelper
address _pancakeIFO
bytes32 _vestingScheduleId
address _rewardToken
renounceOwnership 0x715018a6
No parameters
setAllowedOperator 0x8afc7cb3
address _operator
bool _active
setCakepieIFOManager 0x8617c377
address _cakepieIFOManager
setHarvestTimeGap 0x3043fed0
uint256 _period
setMCakeConvertorSideChain 0x8f8d7a55
address _mCakeConvertoSideChain
setPool 0x19849038
address _poolAddress
uint256 _allocPoints
address _depositToken
uint256 _poolType
bool _isAmount0
bool _isNative
address _rewarder
setVoteManager 0xb67b6df3
address _newVoteManager
transferOwnership 0xf2fde38b
address newOwner
unpause 0x3f4ba83a
No parameters
withdrawAMLFor 0x642c4894
address _for
address _pool
uint256 _amount
withdrawV2LPFor 0x9b5f94dc
address _for
address _pool
uint256 _amount
withdrawV3For 0x2e095a35
address _for
address _v3Pool
uint256 _tokenId
Recent Transactions
No transactions found for this address