Address Contract Verified
Address
0x408400515B7C1835442D1DF99346BA64C5ec4f48
Balance
0 ETH
Nonce
1
Code Size
11777 bytes
Creator
0xE74ad543...E75e at tx 0x4ebaace0...9251b9
Indexed Transactions
0
Contract Bytecode
11777 bytes
0x608060405234801561001057600080fd5b506004361061014c5760003560e01c80639010d07c116100c3578063c09558db1161007c578063c09558db146102b8578063c4d66de8146102cb578063ca15c873146102de578063ced3a403146102f1578063d547741f14610306578063f7e7d1fd1461031957600080fd5b80639010d07c1461022957806391d14854146102545780639ac1c4ad14610277578063a15f74a21461028a578063a217fddf1461029d578063b39e12cf146102a557600080fd5b80632e64cec1116101155780632e64cec1146101d55780632f2ff15d146101dd57806336568abe146101f0578063485cc9551461020357806375ab97821461015157806376d07f6b1461021657600080fd5b806223de291461015157806312d0e65a1461016657806321eb585914610179578063248a9ca31461018c57806327e5455a146101c2575b600080fd5b61016461015f366004612903565b61032c565b005b6101646101743660046129b4565b610408565b6101646101873660046129d8565b61059b565b6101af61019a366004612a39565b60009081526065602052604090206002015490565b6040519081526020015b60405180910390f35b6101646101d0366004612a39565b6108b4565b610164610bbe565b6101646101eb366004612a52565b611120565b6101646101fe366004612a52565b6111ae565b610164610211366004612a82565b611228565b610164610224366004612a52565b61146e565b61023c610237366004612ab0565b61179a565b6040516001600160a01b0390911681526020016101b9565b610267610262366004612a52565b6117bb565b60405190151581526020016101b9565b610164610285366004612a39565b6117d3565b610164610298366004612a39565b611aaa565b6101af600081565b60975461023c906001600160a01b031681565b6101646102c63660046129b4565b611baa565b6101646102d93660046129b4565b6121f1565b6101af6102ec366004612a39565b612268565b6101af600080516020612dac83398151915281565b610164610314366004612a52565b61227f565b6101646103273660046129b4565b612300565b604080518082018252600a81526929b5b0b632aa37b5b2b760b11b60208201526097549151633581777360e01b8152909133916001600160a01b039091169063358177739061037f908590600401612ad2565b602060405180830381865afa15801561039c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103c09190612b27565b6001600160a01b031614806103d857506103d861236f565b6103fd5760405162461bcd60e51b81526004016103f490612b44565b60405180910390fd5b505050505050505050565b604080518082018252600981526820b63637b1b0ba37b960b91b60208201526097549151633581777360e01b8152909133916001600160a01b039091169063358177739061045a908590600401612ad2565b602060405180830381865afa158015610477573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061049b9190612b27565b6001600160a01b031614806104b357506104b361236f565b6104cf5760405162461bcd60e51b81526004016103f490612b44565b6001600160a01b0382166105315760405162461bcd60e51b8152602060048201526024808201527f42656e65666963696172792061646472657373206d757374206e6f74206265206044820152637a65726f60e01b60648201526084016103f4565b609854604080516001600160a01b03928316815291841660208301527fe72eaf6addaa195f3c83095031dd08f3a96808dcf047babed1fe4e4f69d6c622910160405180910390a150609880546001600160a01b0319166001600160a01b0392909216919091179055565b6098546001600160a01b0316336001600160a01b031614806105d057506105d0600080516020612dac833981519152336117bb565b6105ec5760405162461bcd60e51b81526004016103f490612b7b565b609754604051633581777360e01b81526000916001600160a01b03169063358177739061061b90600401612bc3565b602060405180830381865afa158015610638573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061065c9190612b27565b609854604051630cb86e1160e11b81526001600160a01b039182166004820152919250821690631970dc2290602401602060405180830381865afa1580156106a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106cc9190612be6565b6107185760405162461bcd60e51b815260206004820152601960248201527f44656c65676174696f6e206973206e6f7420616c6c6f7765640000000000000060448201526064016103f4565b609854604051630388890d60e41b81526001600160a01b0391821660048201529082169063388890d090602401602060405180830381865afa158015610762573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107869190612be6565b6107d25760405162461bcd60e51b815260206004820152601960248201527f42656e6566696369617279206973206e6f74204163746976650000000000000060448201526064016103f4565b609754604051633581777360e01b81526000916001600160a01b03169063358177739061080190600401612c08565b602060405180830381865afa15801561081e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108429190612b27565b6040516321eb585960e01b81529091506001600160a01b038216906321eb585990610879908a908a908a908a908a90600401612c36565b600060405180830381600087803b15801561089357600080fd5b505af11580156108a7573d6000803e3d6000fd5b5050505050505050505050565b609754604051633581777360e01b81526000916001600160a01b0316906335817773906108e390600401612bc3565b602060405180830381865afa158015610900573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109249190612b27565b609854604051630388890d60e41b81526001600160a01b03918216600482015291925082169063388890d090602401602060405180830381865afa158015610970573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109949190612be6565b156109ef576098546001600160a01b0316336001600160a01b031614806109ce57506109ce600080516020612dac833981519152336117bb565b6109ea5760405162461bcd60e51b81526004016103f490612b7b565b610aeb565b806001600160a01b03166391d14854826001600160a01b031663b8664dca6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a3c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a609190612c7a565b336040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152604401602060405180830381865afa158015610aab573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610acf9190612be6565b610aeb5760405162461bcd60e51b81526004016103f490612c93565b609754604051633581777360e01b81526000916001600160a01b031690633581777390610b1a90600401612c08565b602060405180830381865afa158015610b37573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b5b9190612b27565b6040516313f2a2ad60e11b8152600481018590529091506001600160a01b038216906327e5455a906024015b600060405180830381600087803b158015610ba157600080fd5b505af1158015610bb5573d6000803e3d6000fd5b50505050505050565b6098546001600160a01b0316336001600160a01b03161480610bf35750610bf3600080516020612dac833981519152336117bb565b610c0f5760405162461bcd60e51b81526004016103f490612b7b565b609754604051633581777360e01b81526000916001600160a01b031690633581777390610c3e90600401612bc3565b602060405180830381865afa158015610c5b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c7f9190612b27565b609754604051633581777360e01b815260206004820152600a602482015269546f6b656e537461746560b01b60448201529192506000916001600160a01b0390911690633581777390606401602060405180830381865afa158015610ce8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d0c9190612b27565b609854604051630388890d60e41b81526001600160a01b0391821660048201529192506000919084169063388890d090602401602060405180830381865afa158015610d5c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d809190612be6565b15610dfd576098546040516001622fca6b60e11b031981526001600160a01b0391821660048201529084169063ffa06b2a90602401602060405180830381865afa158015610dd2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610df69190612c7a565b9050610e02565b506099545b609754604051633581777360e01b81526000916001600160a01b031690633581777390610e3190600401612cc8565b602060405180830381865afa158015610e4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e729190612b27565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015610eb8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610edc9190612c7a565b60985460405163bc52911b60e01b81526001600160a01b039182166004820152919250600091610fcf9185919088169063bc52911b90602401602060405180830381865afa158015610f32573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f569190612c7a565b610f609190612cec565b604051630b97599160e01b81523060048201526001600160a01b03871690630b975991906024016020604051808303816000875af1158015610fa6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fca9190612c7a565b612380565b90508082111561111957609754604051633581777360e01b81526001600160a01b039091169063358177739061100790600401612cc8565b602060405180830381865afa158015611024573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110489190612b27565b6098546001600160a01b039182169163a9059cbb91166110688486612cec565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526044016020604051808303816000875af11580156110b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110d79190612be6565b6111195760405162461bcd60e51b8152602060048201526013602482015272115c9c9bdc881bd9881d1bdad95b881cd95b99606a1b60448201526064016103f4565b5050505050565b60008281526065602052604090206002015461113c90336117bb565b6111a05760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e60448201526e0818591b5a5b881d1bc819dc985b9d608a1b60648201526084016103f4565b6111aa8282612397565b5050565b6001600160a01b038116331461121e5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084016103f4565b6111aa82826123f0565b60006112346001612449565b9050801561124c576000805461ff0019166101001790555b6001600160a01b0382166112a25760405162461bcd60e51b815260206004820152601e60248201527f42656e65666963696172792061646472657373206973206e6f7420736574000060448201526064016103f4565b6112ab836121f1565b609854604080516001600160a01b03928316815291841660208301527fe72eaf6addaa195f3c83095031dd08f3a96808dcf047babed1fe4e4f69d6c622910160405180910390a1609880546001600160a01b03199081166001600160a01b03851617909155609a8054731820a4b7618bde71dce8cdc73aab6c95905fad249216821790556040516329965a1d60e01b815230600482018190527fb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b602483015260448201526329965a1d90606401600060405180830381600087803b15801561139257600080fd5b505af11580156113a6573d6000803e3d6000fd5b5050609a546040516329965a1d60e01b815230600482018190527f29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895602483015260448201526001600160a01b0390911692506329965a1d9150606401600060405180830381600087803b15801561141c57600080fd5b505af1158015611430573d6000803e3d6000fd5b505050508015611469576000805461ff001916905560405160018152600080516020612d8c833981519152906020015b60405180910390a15b505050565b609754604051633581777360e01b81526000916001600160a01b03169063358177739061149d90600401612bc3565b602060405180830381865afa1580156114ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114de9190612b27565b609854604051630388890d60e41b81526001600160a01b03918216600482015291925082169063388890d090602401602060405180830381865afa15801561152a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061154e9190612be6565b156115a9576098546001600160a01b0316336001600160a01b031614806115885750611588600080516020612dac833981519152336117bb565b6115a45760405162461bcd60e51b81526004016103f490612b7b565b6116a5565b806001600160a01b03166391d14854826001600160a01b031663b8664dca6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156115f6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061161a9190612c7a565b336040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152604401602060405180830381865afa158015611665573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116899190612be6565b6116a55760405162461bcd60e51b81526004016103f490612c93565b609754604051633581777360e01b815260206004820152600b60248201526a2234b9ba3934b13aba37b960a91b60448201526000916001600160a01b031690633581777390606401602060405180830381865afa15801561170a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061172e9190612b27565b6040516376d07f6b60e01b8152600481018690526001600160a01b038581166024830152919250908216906376d07f6b90604401600060405180830381600087803b15801561177c57600080fd5b505af1158015611790573d6000803e3d6000fd5b5050505050505050565b60008281526065602052604081206117b290836124d1565b90505b92915050565b60008281526065602052604081206117b290836124dd565b609754604051633581777360e01b81526000916001600160a01b03169063358177739061180290600401612bc3565b602060405180830381865afa15801561181f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118439190612b27565b609854604051630388890d60e41b81526001600160a01b03918216600482015291925082169063388890d090602401602060405180830381865afa15801561188f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118b39190612be6565b1561190e576098546001600160a01b0316336001600160a01b031614806118ed57506118ed600080516020612dac833981519152336117bb565b6119095760405162461bcd60e51b81526004016103f490612b7b565b611a0a565b806001600160a01b03166391d14854826001600160a01b031663b8664dca6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561195b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061197f9190612c7a565b336040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152604401602060405180830381865afa1580156119ca573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119ee9190612be6565b611a0a5760405162461bcd60e51b81526004016103f490612c93565b609754604051633581777360e01b81526000916001600160a01b031690633581777390611a3990600401612c08565b602060405180830381865afa158015611a56573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a7a9190612b27565b604051639ac1c4ad60e01b8152600481018590529091506001600160a01b03821690639ac1c4ad90602401610b87565b604080518082018252600981526820b63637b1b0ba37b960b91b60208201526097549151633581777360e01b8152909133916001600160a01b0390911690633581777390611afc908590600401612ad2565b602060405180830381865afa158015611b19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b3d9190612b27565b6001600160a01b03161480611b555750611b5561236f565b611b715760405162461bcd60e51b81526004016103f490612b44565b6040518281527fd148b0dd94807c97b817d5020a2f49c1908f919b9a57633081d9d6d11ba99be09060200160405180910390a150609955565b609754604051633581777360e01b81526000916001600160a01b031690633581777390611bd990600401612bc3565b602060405180830381865afa158015611bf6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c1a9190612b27565b9050806001600160a01b03166391d14854826001600160a01b031663b8664dca6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611c69573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c8d9190612c7a565b336040516001600160e01b031960e085901b16815260048101929092526001600160a01b03166024820152604401602060405180830381865afa158015611cd8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cfc9190612be6565b611d585760405162461bcd60e51b815260206004820152602760248201527f4d6573736167652073656e646572206973206e6f7420612076657374696e672060448201526636b0b730b3b2b960c91b60648201526084016103f4565b609754604051633581777360e01b81526000916001600160a01b031690633581777390611d8790600401612bc3565b602060405180830381865afa158015611da4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dc89190612b27565b609754604051633581777360e01b815260206004820152600a602482015269546f6b656e537461746560b01b60448201529192506000916001600160a01b0390911690633581777390606401602060405180830381865afa158015611e31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e559190612b27565b90506001600160a01b038416611ead5760405162461bcd60e51b815260206004820152601e60248201527f44657374696e6174696f6e2061646472657373206973206e6f7420736574000060448201526064016103f4565b609854604051630388890d60e41b81526001600160a01b0391821660048201529083169063388890d090602401602060405180830381865afa158015611ef7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f1b9190612be6565b15611f5c5760405162461bcd60e51b815260206004820152601160248201527056657374696e672069732061637469766560781b60448201526064016103f4565b609754604051633581777360e01b81526000916001600160a01b031690633581777390611f8b90600401612cc8565b602060405180830381865afa158015611fa8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fcc9190612b27565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015612012573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120369190612c7a565b604051637d46d65d60e11b81523060048201529091506000906001600160a01b0384169063fa8dacba906024016020604051808303816000875af1158015612082573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120a69190612c7a565b9050808211156121e957609754604051633581777360e01b81526001600160a01b03909116906335817773906120de90600401612cc8565b602060405180830381865afa1580156120fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061211f9190612b27565b6001600160a01b031663a9059cbb876121388486612cec565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526044016020604051808303816000875af1158015612183573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121a79190612be6565b6121e95760405162461bcd60e51b8152602060048201526013602482015272115c9c9bdc881bd9881d1bdad95b881cd95b99606a1b60448201526064016103f4565b505050505050565b60006121fd6001612449565b90508015612215576000805461ff0019166101001790555b61221d6124ff565b6122286000336111a0565b6122318261256b565b80156111aa576000805461ff001916905560405160018152600080516020612d8c8339815191529060200160405180910390a15050565b60008181526065602052604081206117b590612645565b60008281526065602052604090206002015461229b90336117bb565b61121e5760405162461bcd60e51b815260206004820152603060248201527f416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e60448201526f2061646d696e20746f207265766f6b6560801b60648201526084016103f4565b6002600061230d82612449565b90508015612325576000805461ff0019166101001790555b61233d600080516020612dac833981519152846111a0565b8015611469576000805461ff001916905560405160ff83168152600080516020612d8c83398151915290602001611460565b600061237b81336117bb565b905090565b60008183101561239057816117b2565b5090919050565b60008281526065602052604090206123af908261264f565b156111aa5760405133906001600160a01b0383169084907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d90600090a45050565b60008281526065602052604090206124089082612664565b156111aa5760405133906001600160a01b0383169084907ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b90600090a45050565b60008054610100900460ff1615612490578160ff16600114801561246c5750303b155b6124885760405162461bcd60e51b81526004016103f490612d11565b506000919050565b60005460ff8084169116106124b75760405162461bcd60e51b81526004016103f490612d11565b506000805460ff191660ff92909216919091179055600190565b60006117b28383612679565b6001600160a01b038116600090815260018301602052604081205415156117b2565b600061250b6001612449565b90508015612523576000805461ff0019166101001790555b61252b6126a3565b612533612710565b8015612568576000805461ff001916905560405160018152600080516020612d8c833981519152906020015b60405180910390a15b50565b6001600160a01b0381166125cc5760405162461bcd60e51b815260206004820152602260248201527f436f6e74726163744d616e616765722061646472657373206973206e6f742073604482015261195d60f21b60648201526084016103f4565b6001600160a01b0381163b6126235760405162461bcd60e51b815260206004820152601760248201527f41646472657373206973206e6f7420636f6e747261637400000000000000000060448201526064016103f4565b609780546001600160a01b0319166001600160a01b0392909216919091179055565b60006117b5825490565b60006117b2836001600160a01b038416612763565b60006117b2836001600160a01b0384166127b2565b600082600001828154811061269057612690612d5f565b9060005260206000200154905092915050565b600054610100900460ff1661270e5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b60648201526084016103f4565b565b600061271c6001612449565b90508015612533576000805461ff0019166101001790558015612568576000805461ff001916905560405160018152600080516020612d8c8339815191529060200161255f565b60008181526001830160205260408120546127aa575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556117b5565b5060006117b5565b6000818152600183016020526040812054801561289b5760006127d6600183612cec565b85549091506000906127ea90600190612cec565b905081811461284f57600086600001828154811061280a5761280a612d5f565b906000526020600020015490508087600001848154811061282d5761282d612d5f565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061286057612860612d75565b6001900381819060005260206000200160009055905585600101600086815260200190815260200160002060009055600193505050506117b5565b60009150506117b5565b6001600160a01b038116811461256857600080fd5b60008083601f8401126128cc57600080fd5b50813567ffffffffffffffff8111156128e457600080fd5b6020830191508360208285010111156128fc57600080fd5b9250929050565b60008060008060008060008060c0898b03121561291f57600080fd5b883561292a816128a5565b9750602089013561293a816128a5565b9650604089013561294a816128a5565b955060608901359450608089013567ffffffffffffffff8082111561296e57600080fd5b61297a8c838d016128ba565b909650945060a08b013591508082111561299357600080fd5b506129a08b828c016128ba565b999c989b5096995094979396929594505050565b6000602082840312156129c657600080fd5b81356129d1816128a5565b9392505050565b6000806000806000608086880312156129f057600080fd5b853594506020860135935060408601359250606086013567ffffffffffffffff811115612a1c57600080fd5b612a28888289016128ba565b969995985093965092949392505050565b600060208284031215612a4b57600080fd5b5035919050565b60008060408385031215612a6557600080fd5b823591506020830135612a77816128a5565b809150509250929050565b60008060408385031215612a9557600080fd5b8235612aa0816128a5565b91506020830135612a77816128a5565b60008060408385031215612ac357600080fd5b50508035926020909101359150565b600060208083528351808285015260005b81811015612aff57858101830151858201604001528201612ae3565b81811115612b11576000604083870101525b50601f01601f1916929092016040019392505050565b600060208284031215612b3957600080fd5b81516129d1816128a5565b60208082526019908201527f4d6573736167652073656e64657220697320696e76616c696400000000000000604082015260600190565b60208082526028908201527f4d6573736167652073656e646572206973206e6f74206120706c616e2062656e604082015267656669636961727960c01b606082015260800190565b60208082526009908201526820b63637b1b0ba37b960b91b604082015260600190565b600060208284031215612bf857600080fd5b815180151581146129d157600080fd5b6020808252601490820152732232b632b3b0ba34b7b721b7b73a3937b63632b960611b604082015260600190565b85815284602082015283604082015260806060820152816080820152818360a0830137600081830160a090810191909152601f909201601f19160101949350505050565b600060208284031215612c8c57600080fd5b5051919050565b6020808252818101527f4d6573736167652073656e646572206973206e6f7420617574686f72697a6564604082015260600190565b6020808252600a908201526929b5b0b632aa37b5b2b760b11b604082015260600190565b600082821015612d0c57634e487b7160e01b600052601160045260246000fd5b500390565b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052603160045260246000fdfe7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498c8a41221bcd7fcf2c225f5a9265e1d4d39949d89197159d59e5f4b87b62c419ea2646970667358221220cdfb3d65342afa1c76afd157529e42cdc387d62dd57d583a58e6bc303cdf2bc464736f6c634300080b0033
Verified Source Code Full Match
Compiler: v0.8.11+commit.d7f03943
EVM: london
Optimization: Yes (200 runs)
IEscrow.sol 41 lines
// SPDX-License-Identifier: AGPL-3.0-only
/*
IEscrow.sol - SKALE Allocator
Copyright (C) 2020-Present SKALE Labs
@author Artem Payvin
@author Dmytro Stebaiev
SKALE Allocator is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SKALE Allocator is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with SKALE Allocator. If not, see <https://www.gnu.org/licenses/>.
*/
pragma solidity >=0.8.11 <0.9.0;
interface IEscrow {
function reinitialize(address beneficiary) external;
function initialize(address contractManagerAddress, address beneficiary) external;
function changeBeneficiaryAddress(address beneficiary) external;
function retrieve() external;
function retrieveAfterTermination(address destination) external;
function delegate(
uint256 validatorId,
uint256 amount,
uint256 delegationPeriod,
string calldata info
) external;
function requestUndelegation(uint256 delegationId) external;
function cancelPendingDelegation(uint delegationId) external;
function withdrawBounty(uint256 validatorId, address to) external;
function cancelVesting(uint256 vestedAmount) external;
}
ProxyAdmin.sol 81 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/transparent/ProxyAdmin.sol)
pragma solidity ^0.8.0;
import "./TransparentUpgradeableProxy.sol";
import "../../access/Ownable.sol";
/**
* @dev This is an auxiliary contract meant to be assigned as the admin of a {TransparentUpgradeableProxy}. For an
* explanation of why you would want to use this see the documentation for {TransparentUpgradeableProxy}.
*/
contract ProxyAdmin is Ownable {
/**
* @dev Returns the current implementation of `proxy`.
*
* Requirements:
*
* - This contract must be the admin of `proxy`.
*/
function getProxyImplementation(TransparentUpgradeableProxy proxy) public view virtual returns (address) {
// We need to manually run the static call since the getter cannot be flagged as view
// bytes4(keccak256("implementation()")) == 0x5c60da1b
(bool success, bytes memory returndata) = address(proxy).staticcall(hex"5c60da1b");
require(success);
return abi.decode(returndata, (address));
}
/**
* @dev Returns the current admin of `proxy`.
*
* Requirements:
*
* - This contract must be the admin of `proxy`.
*/
function getProxyAdmin(TransparentUpgradeableProxy proxy) public view virtual returns (address) {
// We need to manually run the static call since the getter cannot be flagged as view
// bytes4(keccak256("admin()")) == 0xf851a440
(bool success, bytes memory returndata) = address(proxy).staticcall(hex"f851a440");
require(success);
return abi.decode(returndata, (address));
}
/**
* @dev Changes the admin of `proxy` to `newAdmin`.
*
* Requirements:
*
* - This contract must be the current admin of `proxy`.
*/
function changeProxyAdmin(TransparentUpgradeableProxy proxy, address newAdmin) public virtual onlyOwner {
proxy.changeAdmin(newAdmin);
}
/**
* @dev Upgrades `proxy` to `implementation`. See {TransparentUpgradeableProxy-upgradeTo}.
*
* Requirements:
*
* - This contract must be the admin of `proxy`.
*/
function upgrade(TransparentUpgradeableProxy proxy, address implementation) public virtual onlyOwner {
proxy.upgradeTo(implementation);
}
/**
* @dev Upgrades `proxy` to `implementation` and calls a function on the new implementation. See
* {TransparentUpgradeableProxy-upgradeToAndCall}.
*
* Requirements:
*
* - This contract must be the admin of `proxy`.
*/
function upgradeAndCall(
TransparentUpgradeableProxy proxy,
address implementation,
bytes memory data
) public payable virtual onlyOwner {
proxy.upgradeToAndCall{value: msg.value}(implementation, data);
}
}
Escrow.sol 302 lines
// SPDX-License-Identifier: AGPL-3.0-only
/*
Escrow.sol - SKALE Allocator
Copyright (C) 2020-Present SKALE Labs
@author Artem Payvin
@author Dmytro Stebaiev
SKALE Allocator is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SKALE Allocator is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with SKALE Allocator. If not, see <https://www.gnu.org/licenses/>.
*/
pragma solidity 0.8.11;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/utils/introspection/IERC1820Registry.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";
import "@openzeppelin/contracts/token/ERC777/IERC777Sender.sol";
import "@openzeppelin/contracts/token/ERC777/IERC777Recipient.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@skalenetwork/skale-manager-interfaces/delegation/IDelegationController.sol";
import "@skalenetwork/skale-manager-interfaces/delegation/IDistributor.sol";
import "@skalenetwork/skale-manager-interfaces/delegation/ILocker.sol";
import "./interfaces/IEscrow.sol";
import "./Allocator.sol";
import "./Permissions.sol";
/**
* @title Escrow
* @dev This contract manages funds locked by the Allocator contract.
*/
contract Escrow is IERC777Recipient, IERC777Sender, IEscrow, Permissions {
address internal _beneficiary;
uint256 private _availableAmountAfterTermination;
IERC1820Registry private _erc1820;
bytes32 public constant BENEFICIARY_ROLE = keccak256("BENEFICIARY_ROLE");
event BeneficiaryUpdated(
address oldValue,
address newValue
);
event VestingCanceled(uint vestedAmount);
modifier onlyBeneficiary() virtual {
require(
_msgSender() == _beneficiary ||
hasRole(BENEFICIARY_ROLE, _msgSender()),
"Message sender is not a plan beneficiary"
);
_;
}
modifier onlyVestingManager() {
Allocator allocator = Allocator(contractManager.getContract("Allocator"));
require(
allocator.hasRole(allocator.VESTING_MANAGER_ROLE(), _msgSender()),
"Message sender is not a vesting manager"
);
_;
}
modifier onlyActiveBeneficiaryOrVestingManager() virtual {
Allocator allocator = Allocator(contractManager.getContract("Allocator"));
if (allocator.isVestingActive(_beneficiary)) {
require(
_msgSender() == _beneficiary ||
hasRole(BENEFICIARY_ROLE, _msgSender()),
"Message sender is not a plan beneficiary"
);
} else {
require(
allocator.hasRole(allocator.VESTING_MANAGER_ROLE(), _msgSender()),
"Message sender is not authorized"
);
}
_;
}
function reinitialize(address beneficiary) external override reinitializer(2) {
_setupRole(BENEFICIARY_ROLE, beneficiary);
}
function initialize(address contractManagerAddress, address beneficiary) external override initializer {
require(beneficiary != address(0), "Beneficiary address is not set");
Permissions.initialize(contractManagerAddress);
emit BeneficiaryUpdated(_beneficiary, beneficiary);
_beneficiary = beneficiary;
_erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777TokensRecipient"), address(this));
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777TokensSender"), address(this));
}
function changeBeneficiaryAddress(address beneficiary) external override allow("Allocator") {
require(beneficiary != address(0), "Beneficiary address must not be zero");
emit BeneficiaryUpdated(_beneficiary, beneficiary);
_beneficiary = beneficiary;
}
function tokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes calldata userData,
bytes calldata operatorData
)
external
override
allow("SkaleToken")
// solhint-disable-next-line no-empty-blocks
{
}
function tokensToSend(
address,
address,
address to,
uint256,
bytes calldata,
bytes calldata
)
external
override
allow("SkaleToken")
// solhint-disable-next-line no-empty-blocks
{
}
/**
* @dev Allows Beneficiary to retrieve vested tokens from the Escrow contract.
*
* IMPORTANT: Slashed tokens are non-transferable.
*/
function retrieve() external override onlyBeneficiary {
Allocator allocator = Allocator(contractManager.getContract("Allocator"));
ILocker tokenState = ILocker(contractManager.getContract("TokenState"));
uint256 vestedAmount = 0;
if (allocator.isVestingActive(_beneficiary)) {
vestedAmount = allocator.calculateVestedAmount(_beneficiary);
} else {
vestedAmount = _availableAmountAfterTermination;
}
uint256 escrowBalance = IERC20(contractManager.getContract("SkaleToken")).balanceOf(address(this));
uint256 locked = Math.max(
allocator.getFullAmount(_beneficiary) - vestedAmount,
tokenState.getAndUpdateForbiddenForDelegationAmount(address(this))
);
if (escrowBalance > locked) {
require(
IERC20(contractManager.getContract("SkaleToken")).transfer(
_beneficiary,
escrowBalance - locked
),
"Error of token send"
);
}
}
/**
* @dev Allows Vesting Manager to retrieve remaining transferrable escrow balance
* after beneficiary's termination.
*
* IMPORTANT: Slashed tokens are non-transferable.
*
* Requirements:
*
* - Allocator must be active.
*/
function retrieveAfterTermination(address destination) external override onlyVestingManager {
Allocator allocator = Allocator(contractManager.getContract("Allocator"));
ILocker tokenState = ILocker(contractManager.getContract("TokenState"));
require(destination != address(0), "Destination address is not set");
require(!allocator.isVestingActive(_beneficiary), "Vesting is active");
uint256 escrowBalance = IERC20(contractManager.getContract("SkaleToken")).balanceOf(address(this));
uint256 forbiddenToSend = tokenState.getAndUpdateLockedAmount(address(this));
if (escrowBalance > forbiddenToSend) {
require(
IERC20(contractManager.getContract("SkaleToken")).transfer(
destination,
escrowBalance - forbiddenToSend
),
"Error of token send"
);
}
}
/**
* @dev Allows Beneficiary to propose a delegation to a validator.
*
* Requirements:
*
* - Beneficiary must be active.
* - Beneficiary must have sufficient delegatable tokens.
* - If trusted list is enabled, validator must be a member of the trusted
* list.
*/
function delegate(
uint256 validatorId,
uint256 amount,
uint256 delegationPeriod,
string calldata info
)
external
override
onlyBeneficiary
{
Allocator allocator = Allocator(contractManager.getContract("Allocator"));
require(allocator.isDelegationAllowed(_beneficiary), "Delegation is not allowed");
require(allocator.isVestingActive(_beneficiary), "Beneficiary is not Active");
IDelegationController delegationController = IDelegationController(
contractManager.getContract("DelegationController")
);
delegationController.delegate(validatorId, amount, delegationPeriod, info);
}
/**
* @dev Allows Beneficiary and Vesting manager to request undelegation. Only
* Vesting manager can request undelegation after beneficiary is deactivated
* (after beneficiary termination).
*
* Requirements:
*
* - Beneficiary and Vesting manager must be `msg.sender`.
*/
function requestUndelegation(uint256 delegationId) external override onlyActiveBeneficiaryOrVestingManager {
IDelegationController delegationController = IDelegationController(
contractManager.getContract("DelegationController")
);
delegationController.requestUndelegation(delegationId);
}
/**
* @dev Allows Beneficiary and Vesting manager to cancel a delegation proposal. Only
* Vesting manager can request undelegation after beneficiary is deactivated
* (after beneficiary termination).
*
* Requirements:
*
* - Beneficiary and Vesting manager must be `msg.sender`.
*/
function cancelPendingDelegation(uint delegationId) external override onlyActiveBeneficiaryOrVestingManager {
IDelegationController delegationController = IDelegationController(
contractManager.getContract("DelegationController")
);
delegationController.cancelPendingDelegation(delegationId);
}
/**
* @dev Allows Beneficiary and Vesting manager to withdraw earned bounty. Only
* Vesting manager can withdraw bounty to Allocator contract after beneficiary
* is deactivated.
*
* IMPORTANT: Withdraws are only possible after 90 day initial network lock.
*
* Requirements:
*
* - Beneficiary or Vesting manager must be `msg.sender`.
* - Beneficiary must be active when Beneficiary is `msg.sender`.
*/
function withdrawBounty(
uint256 validatorId,
address to
)
external
override
onlyActiveBeneficiaryOrVestingManager
{
IDistributor distributor = IDistributor(contractManager.getContract("Distributor"));
distributor.withdrawBounty(validatorId, to);
}
/**
* @dev Allows Allocator contract to cancel vesting of a Beneficiary. Cancel
* vesting is performed upon termination.
*/
function cancelVesting(uint256 vestedAmount) external override allow("Allocator") {
emit VestingCanceled(vestedAmount);
_availableAmountAfterTermination = vestedAmount;
}
}
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);
}
Permissions.sol 73 lines
// SPDX-License-Identifier: AGPL-3.0-only
/*
Permissions.sol - SKALE Allocator
Copyright (C) 2020-Present SKALE Labs
@author Artem Payvin
SKALE Allocator is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SKALE Allocator is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with SKALE Allocator. If not, see <https://www.gnu.org/licenses/>.
*/
pragma solidity 0.8.11;
import "@skalenetwork/skale-manager-interfaces/IContractManager.sol";
import "@skalenetwork/skale-manager-interfaces/IPermissions.sol";
import "./thirdparty/AccessControlUpgradeableLegacy.sol";
/**
* @title Permissions - connected module for Upgradeable approach, knows ContractManager
* @author Artem Payvin
*/
contract Permissions is AccessControlUpgradeableLegacy, IPermissions {
using AddressUpgradeable for address;
IContractManager public contractManager;
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_isOwner(), "Caller is not the owner");
_;
}
/**
* @dev allow - throws if called by any account and contract other than the owner
* or `contractName` contract
*/
modifier allow(string memory contractName) {
require(
contractManager.getContract(contractName) == msg.sender || _isOwner(),
"Message sender is invalid");
_;
}
function initialize(address contractManagerAddress) public virtual override initializer {
AccessControlUpgradeableLegacy.__AccessControl_init();
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
_setContractManager(contractManagerAddress);
}
function _isOwner() internal view returns (bool) {
return hasRole(DEFAULT_ADMIN_ROLE, msg.sender);
}
function _setContractManager(address contractManagerAddress) private {
require(contractManagerAddress != address(0), "ContractManager address is not set");
require(contractManagerAddress.isContract(), "Address is not contract");
contractManager = IContractManager(contractManagerAddress);
}
}
IPermissions.sol 26 lines
// SPDX-License-Identifier: AGPL-3.0-only
/*
IPermissions.sol - SKALE Manager
Copyright (C) 2018-Present SKALE Labs
@author Artem Payvin
SKALE Manager is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SKALE Manager is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with SKALE Manager. If not, see <https://www.gnu.org/licenses/>.
*/
pragma solidity >=0.6.10 <0.9.0;
interface IPermissions {
function initialize(address contractManagerAddress) external;
}
Initializable.sol 149 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.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. Equivalent to `reinitializer(1)`.
*/
modifier initializer() {
bool isTopLevelCall = _setInitializedVersion(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.
*
* `initializer` is equivalent to `reinitializer(1)`, so 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.
*
* 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.
*/
modifier reinitializer(uint8 version) {
bool isTopLevelCall = _setInitializedVersion(version);
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_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.
*/
function _disableInitializers() internal virtual {
_setInitializedVersion(type(uint8).max);
}
function _setInitializedVersion(uint8 version) private returns (bool) {
// If the contract is initializing we ignore whether _initialized is set in order to support multiple
// inheritance patterns, but we only do this in the context of a constructor, and for the lowest level
// of initializers, because in other contexts the contract may have been reentered.
if (_initializing) {
require(
version == 1 && !AddressUpgradeable.isContract(address(this)),
"Initializable: contract is already initialized"
);
return false;
} else {
require(_initialized < version, "Initializable: contract is already initialized");
_initialized = version;
return true;
}
}
}
IDelegationController.sol 120 lines
// SPDX-License-Identifier: AGPL-3.0-only
/*
IDelegationController.sol - SKALE Manager
Copyright (C) 2018-Present SKALE Labs
@author Artem Payvin
SKALE Manager is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SKALE Manager is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with SKALE Manager. If not, see <https://www.gnu.org/licenses/>.
*/
pragma solidity >=0.6.10 <0.9.0;
interface IDelegationController {
enum State {
PROPOSED,
ACCEPTED,
CANCELED,
REJECTED,
DELEGATED,
UNDELEGATION_REQUESTED,
COMPLETED
}
struct Delegation {
address holder; // address of token owner
uint validatorId;
uint amount;
uint delegationPeriod;
uint created; // time of delegation creation
uint started; // month when a delegation becomes active
uint finished; // first month after a delegation ends
string info;
}
/**
* @dev Emitted when validator was confiscated.
*/
event Confiscated(
uint indexed validatorId,
uint amount
);
/**
* @dev Emitted when validator was confiscated.
*/
event SlashesProcessed(
address indexed holder,
uint limit
);
/**
* @dev Emitted when a delegation is proposed to a validator.
*/
event DelegationProposed(
uint delegationId
);
/**
* @dev Emitted when a delegation is accepted by a validator.
*/
event DelegationAccepted(
uint delegationId
);
/**
* @dev Emitted when a delegation is cancelled by the delegator.
*/
event DelegationRequestCanceledByUser(
uint delegationId
);
/**
* @dev Emitted when a delegation is requested to undelegate.
*/
event UndelegationRequested(
uint delegationId
);
function getAndUpdateDelegatedToValidatorNow(uint validatorId) external returns (uint);
function getAndUpdateDelegatedAmount(address holder) external returns (uint);
function getAndUpdateEffectiveDelegatedByHolderToValidator(address holder, uint validatorId, uint month)
external
returns (uint effectiveDelegated);
function delegate(
uint validatorId,
uint amount,
uint delegationPeriod,
string calldata info
)
external;
function cancelPendingDelegation(uint delegationId) external;
function acceptPendingDelegation(uint delegationId) external;
function requestUndelegation(uint delegationId) external;
function confiscate(uint validatorId, uint amount) external;
function getAndUpdateEffectiveDelegatedToValidator(uint validatorId, uint month) external returns (uint);
function getAndUpdateDelegatedByHolderToValidatorNow(address holder, uint validatorId) external returns (uint);
function processSlashes(address holder, uint limit) external;
function processAllSlashes(address holder) external;
function getEffectiveDelegatedValuesByValidator(uint validatorId) external view returns (uint[] memory);
function getEffectiveDelegatedToValidator(uint validatorId, uint month) external view returns (uint);
function getDelegatedToValidator(uint validatorId, uint month) external view returns (uint);
function getDelegation(uint delegationId) external view returns (Delegation memory);
function getFirstDelegationMonth(address holder, uint validatorId) external view returns(uint);
function getDelegationsByValidatorLength(uint validatorId) external view returns (uint);
function getDelegationsByHolderLength(address holder) external view returns (uint);
function getState(uint delegationId) external view returns (State state);
function getLockedInPendingDelegations(address holder) external view returns (uint);
function hasUnprocessedSlashes(address holder) external view returns (bool);
}
ILocker.sol 39 lines
// SPDX-License-Identifier: AGPL-3.0-only
/*
ILocker.sol - SKALE Manager
Copyright (C) 2019-Present SKALE Labs
@author Dmytro Stebaiev
SKALE Manager is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SKALE Manager is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with SKALE Manager. If not, see <https://www.gnu.org/licenses/>.
*/
pragma solidity >=0.6.10 <0.9.0;
/**
* @dev Interface of the Locker functions.
*/
interface ILocker {
/**
* @dev Returns and updates the total amount of locked tokens of a given
* `holder`.
*/
function getAndUpdateLockedAmount(address wallet) external returns (uint);
/**
* @dev Returns and updates the total non-transferrable and un-delegatable
* amount of a given `holder`.
*/
function getAndUpdateForbiddenForDelegationAmount(address wallet) external returns (uint);
}
ITimeHelpers.sol 33 lines
// SPDX-License-Identifier: AGPL-3.0-only
/*
ITimeHelpers.sol - SKALE Manager
Copyright (C) 2018-Present SKALE Labs
@author Artem Payvin
SKALE Manager is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SKALE Manager is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with SKALE Manager. If not, see <https://www.gnu.org/licenses/>.
*/
pragma solidity >=0.6.10 <0.9.0;
interface ITimeHelpers {
function calculateProofOfUseLockEndTime(uint month, uint lockUpPeriodDays) external view returns (uint timestamp);
function getCurrentMonth() external view returns (uint);
function timestampToYear(uint timestamp) external view returns (uint);
function timestampToMonth(uint timestamp) external view returns (uint);
function monthToTimestamp(uint month) external view returns (uint timestamp);
function addDays(uint fromTimestamp, uint n) external pure returns (uint);
function addMonths(uint fromTimestamp, uint n) external pure returns (uint);
function addYears(uint fromTimestamp, uint n) external pure returns (uint);
}
ERC1967Proxy.sol 33 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/ERC1967/ERC1967Proxy.sol)
pragma solidity ^0.8.0;
import "../Proxy.sol";
import "./ERC1967Upgrade.sol";
/**
* @dev This contract implements an upgradeable proxy. It is upgradeable because calls are delegated to an
* implementation address that can be changed. This address is stored in storage in the location specified by
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967], so that it doesn't conflict with the storage layout of the
* implementation behind the proxy.
*/
contract ERC1967Proxy is Proxy, ERC1967Upgrade {
/**
* @dev Initializes the upgradeable proxy with an initial implementation specified by `_logic`.
*
* If `_data` is nonempty, it's used as data in a delegate call to `_logic`. This will typically be an encoded
* function call, and allows initializating the storage of the proxy like a Solidity constructor.
*/
constructor(address _logic, bytes memory _data) payable {
assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1));
_upgradeToAndCall(_logic, _data, false);
}
/**
* @dev Returns the current implementation address.
*/
function _implementation() internal view virtual override returns (address impl) {
return ERC1967Upgrade._getImplementation();
}
}
IBeacon.sol 16 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.0;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeacon {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {BeaconProxy} will check that this address is a contract.
*/
function implementation() external view returns (address);
}
Ownable.sol 76 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Address.sol 222 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.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 functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
IERC777Recipient.sol 35 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC777/IERC777Recipient.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC777TokensRecipient standard as defined in the EIP.
*
* Accounts can be notified of {IERC777} tokens being sent to them by having a
* contract implement this interface (contract holders can be their own
* implementer) and registering it on the
* https://eips.ethereum.org/EIPS/eip-1820[ERC1820 global registry].
*
* See {IERC1820Registry} and {ERC1820Implementer}.
*/
interface IERC777Recipient {
/**
* @dev Called by an {IERC777} token contract whenever tokens are being
* moved or created into a registered account (`to`). The type of operation
* is conveyed by `from` being the zero address or not.
*
* This call occurs _after_ the token contract's state is updated, so
* {IERC777-balanceOf}, etc., can be used to query the post-operation state.
*
* This function may revert to prevent the operation from being executed.
*/
function tokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes calldata userData,
bytes calldata operatorData
) external;
}
IDistributor.sol 60 lines
// SPDX-License-Identifier: AGPL-3.0-only
/*
IDistributor.sol - SKALE Manager
Copyright (C) 2018-Present SKALE Labs
@author Artem Payvin
SKALE Manager is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SKALE Manager is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with SKALE Manager. If not, see <https://www.gnu.org/licenses/>.
*/
pragma solidity >=0.6.10 <0.9.0;
interface IDistributor {
/**
* @dev Emitted when bounty is withdrawn.
*/
event WithdrawBounty(
address holder,
uint validatorId,
address destination,
uint amount
);
/**
* @dev Emitted when a validator fee is withdrawn.
*/
event WithdrawFee(
uint validatorId,
address destination,
uint amount
);
/**
* @dev Emitted when bounty is distributed.
*/
event BountyWasPaid(
uint validatorId,
uint amount
);
function getAndUpdateEarnedBountyAmount(uint validatorId) external returns (uint earned, uint endMonth);
function withdrawBounty(uint validatorId, address to) external;
function withdrawFee(address to) external;
function getAndUpdateEarnedBountyAmountOf(address wallet, uint validatorId)
external
returns (uint earned, uint endMonth);
function getEarnedFeeAmount() external view returns (uint earned, uint endMonth);
function getEarnedFeeAmountOf(uint validatorId) external view returns (uint earned, uint endMonth);
}
TransparentUpgradeableProxy.sol 125 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/transparent/TransparentUpgradeableProxy.sol)
pragma solidity ^0.8.0;
import "../ERC1967/ERC1967Proxy.sol";
/**
* @dev This contract implements a proxy that is upgradeable by an admin.
*
* To avoid https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357[proxy selector
* clashing], which can potentially be used in an attack, this contract uses the
* https://blog.openzeppelin.com/the-transparent-proxy-pattern/[transparent proxy pattern]. This pattern implies two
* things that go hand in hand:
*
* 1. If any account other than the admin calls the proxy, the call will be forwarded to the implementation, even if
* that call matches one of the admin functions exposed by the proxy itself.
* 2. If the admin calls the proxy, it can access the admin functions, but its calls will never be forwarded to the
* implementation. If the admin tries to call a function on the implementation it will fail with an error that says
* "admin cannot fallback to proxy target".
*
* These properties mean that the admin account can only be used for admin actions like upgrading the proxy or changing
* the admin, so it's best if it's a dedicated account that is not used for anything else. This will avoid headaches due
* to sudden errors when trying to call a function from the proxy implementation.
*
* Our recommendation is for the dedicated account to be an instance of the {ProxyAdmin} contract. If set up this way,
* you should think of the `ProxyAdmin` instance as the real administrative interface of your proxy.
*/
contract TransparentUpgradeableProxy is ERC1967Proxy {
/**
* @dev Initializes an upgradeable proxy managed by `_admin`, backed by the implementation at `_logic`, and
* optionally initialized with `_data` as explained in {ERC1967Proxy-constructor}.
*/
constructor(
address _logic,
address admin_,
bytes memory _data
) payable ERC1967Proxy(_logic, _data) {
assert(_ADMIN_SLOT == bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1));
_changeAdmin(admin_);
}
/**
* @dev Modifier used internally that will delegate the call to the implementation unless the sender is the admin.
*/
modifier ifAdmin() {
if (msg.sender == _getAdmin()) {
_;
} else {
_fallback();
}
}
/**
* @dev Returns the current admin.
*
* NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyAdmin}.
*
* TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the
* https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
* `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
*/
function admin() external ifAdmin returns (address admin_) {
admin_ = _getAdmin();
}
/**
* @dev Returns the current implementation.
*
* NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyImplementation}.
*
* TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the
* https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
* `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc`
*/
function implementation() external ifAdmin returns (address implementation_) {
implementation_ = _implementation();
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {AdminChanged} event.
*
* NOTE: Only the admin can call this function. See {ProxyAdmin-changeProxyAdmin}.
*/
function changeAdmin(address newAdmin) external virtual ifAdmin {
_changeAdmin(newAdmin);
}
/**
* @dev Upgrade the implementation of the proxy.
*
* NOTE: Only the admin can call this function. See {ProxyAdmin-upgrade}.
*/
function upgradeTo(address newImplementation) external ifAdmin {
_upgradeToAndCall(newImplementation, bytes(""), false);
}
/**
* @dev Upgrade the implementation of the proxy, and then call a function from the new implementation as specified
* by `data`, which should be an encoded function call. This is useful to initialize new storage variables in the
* proxied contract.
*
* NOTE: Only the admin can call this function. See {ProxyAdmin-upgradeAndCall}.
*/
function upgradeToAndCall(address newImplementation, bytes calldata data) external payable ifAdmin {
_upgradeToAndCall(newImplementation, data, true);
}
/**
* @dev Returns the current admin.
*/
function _admin() internal view virtual returns (address) {
return _getAdmin();
}
/**
* @dev Makes sure the admin cannot access the fallback function. See {Proxy-_beforeFallback}.
*/
function _beforeFallback() internal virtual override {
require(msg.sender != _getAdmin(), "TransparentUpgradeableProxy: admin cannot fallback to proxy target");
super._beforeFallback();
}
}
IAllocator.sol 101 lines
// SPDX-License-Identifier: AGPL-3.0-only
/*
IAllocator.sol - SKALE Allocator
Copyright (C) 2020-Present SKALE Labs
@author Artem Payvin
@author Dmytro Stebaiev
SKALE Allocator is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SKALE Allocator is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with SKALE Allocator. If not, see <https://www.gnu.org/licenses/>.
*/
pragma solidity >=0.8.11 <0.9.0;
pragma experimental ABIEncoderV2;
interface IAllocator {
enum TimeUnit {
DAY,
MONTH,
YEAR
}
enum BeneficiaryStatus {
UNKNOWN,
CONFIRMED,
ACTIVE,
TERMINATED
}
struct Plan {
uint256 totalVestingDuration; // months
uint256 vestingCliff; // months
TimeUnit vestingIntervalTimeUnit;
uint256 vestingInterval; // amount of days/months/years
bool isDelegationAllowed;
bool isTerminatable;
}
struct Beneficiary {
BeneficiaryStatus status;
uint256 planId;
uint256 startMonth;
uint256 fullAmount;
uint256 amountAfterLockup;
address requestedAddress;
}
event PlanCreated(
uint256 id
);
event VersionUpdated(
string oldVersion,
string newVersion
);
function startVesting(address beneficiary) external;
function addPlan(
uint256 vestingCliff, // months
uint256 totalVestingDuration, // months
TimeUnit vestingIntervalTimeUnit, // 0 - day 1 - month 2 - year
uint256 vestingInterval, // months or days or years
bool canDelegate, // can beneficiary delegate all un-vested tokens
bool isTerminatable
) external;
function connectBeneficiaryToPlan(
address beneficiary,
uint256 planId,
uint256 startMonth,
uint256 fullAmount,
uint256 lockupAmount
) external;
function stopVesting(address beneficiary) external;
function setVersion(string calldata newVersion) external;
function changeBeneficiaryAddress(address newBeneficiaryAddress) external;
function confirmBeneficiaryAddress(address oldBeneficiaryAddress) external;
function getStartMonth(address beneficiary) external view returns (uint);
function getFinishVestingTime(address beneficiary) external view returns (uint);
function getVestingCliffInMonth(address beneficiary) external view returns (uint);
function isVestingActive(address beneficiary) external view returns (bool);
function isBeneficiaryRegistered(address beneficiary) external view returns (bool);
function isDelegationAllowed(address beneficiary) external view returns (bool);
function getFullAmount(address beneficiary) external view returns (uint);
function getEscrowAddress(address beneficiary) external view returns (address);
function getLockupPeriodEndTimestamp(address beneficiary) external view returns (uint);
function getTimeOfNextVest(address beneficiary) external view returns (uint);
function getPlan(uint256 planId) external view returns (Plan memory);
function getBeneficiaryPlanParams(address beneficiary) external view returns (Beneficiary memory);
function calculateVestedAmount(address wallet) external view returns (uint256 vestedAmount);
}
draft-IERC1822.sol 20 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.0;
/**
* @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822Proxiable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}
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;
}
}
AddressUpgradeable.sol 195 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.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 functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
Math.sol 43 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a / b + (a % b == 0 ? 0 : 1);
}
}
IERC777Sender.sol 35 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC777/IERC777Sender.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC777TokensSender standard as defined in the EIP.
*
* {IERC777} Token holders can be notified of operations performed on their
* tokens by having a contract implement this interface (contract holders can be
* their own implementer) and registering it on the
* https://eips.ethereum.org/EIPS/eip-1820[ERC1820 global registry].
*
* See {IERC1820Registry} and {ERC1820Implementer}.
*/
interface IERC777Sender {
/**
* @dev Called by an {IERC777} token contract whenever a registered holder's
* (`from`) tokens are about to be moved or destroyed. The type of operation
* is conveyed by `to` being the zero address or not.
*
* This call occurs _before_ the token contract's state is updated, so
* {IERC777-balanceOf}, etc., can be used to query the pre-operation state.
*
* This function may revert to prevent the operation from being executed.
*/
function tokensToSend(
address operator,
address from,
address to,
uint256 amount,
bytes calldata userData,
bytes calldata operatorData
) external;
}
ERC1967Upgrade.sol 185 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (proxy/ERC1967/ERC1967Upgrade.sol)
pragma solidity ^0.8.2;
import "../beacon/IBeacon.sol";
import "../../interfaces/draft-IERC1822.sol";
import "../../utils/Address.sol";
import "../../utils/StorageSlot.sol";
/**
* @dev This abstract contract provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
*
* _Available since v4.1._
*
* @custom:oz-upgrades-unsafe-allow delegatecall
*/
abstract contract ERC1967Upgrade {
// This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev Emitted when the implementation is upgraded.
*/
event Upgraded(address indexed implementation);
/**
* @dev Returns the current implementation address.
*/
function _getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Perform implementation upgrade
*
* Emits an {Upgraded} event.
*/
function _upgradeTo(address newImplementation) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
/**
* @dev Perform implementation upgrade with additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCall(
address newImplementation,
bytes memory data,
bool forceCall
) internal {
_upgradeTo(newImplementation);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(newImplementation, data);
}
}
/**
* @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCallUUPS(
address newImplementation,
bytes memory data,
bool forceCall
) internal {
// Upgrades from old implementations will perform a rollback test. This test requires the new
// implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
// this special case will break upgrade paths from old UUPS implementation to new ones.
if (StorageSlot.getBooleanSlot(_ROLLBACK_SLOT).value) {
_setImplementation(newImplementation);
} else {
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");
} catch {
revert("ERC1967Upgrade: new implementation is not UUPS");
}
_upgradeToAndCall(newImplementation, data, forceCall);
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Returns the current admin.
*/
function _getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(_ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
require(newAdmin != address(0), "ERC1967: new admin is the zero address");
StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {AdminChanged} event.
*/
function _changeAdmin(address newAdmin) internal {
emit AdminChanged(_getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
*/
bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Emitted when the beacon is upgraded.
*/
event BeaconUpgraded(address indexed beacon);
/**
* @dev Returns the current beacon.
*/
function _getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(_BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the EIP1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
require(Address.isContract(newBeacon), "ERC1967: new beacon is not a contract");
require(
Address.isContract(IBeacon(newBeacon).implementation()),
"ERC1967: beacon implementation is not a contract"
);
StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon;
}
/**
* @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
* not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
*
* Emits a {BeaconUpgraded} event.
*/
function _upgradeBeaconToAndCall(
address newBeacon,
bytes memory data,
bool forceCall
) internal {
_setBeacon(newBeacon);
emit BeaconUpgraded(newBeacon);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
}
}
}
AccessControlUpgradeableLegacy.sol 194 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol";
import "@skalenetwork/skale-manager-interfaces/thirdparty/openzeppelin/IAccessControlUpgradeableLegacy.sol";
import "./InitializableWithGap.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```
* function foo() public {
* require(hasRole(MY_ROLE, _msgSender()));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*/
abstract contract AccessControlUpgradeableLegacy is InitializableWithGap, ContextUpgradeable, IAccessControlUpgradeableLegacy {
function __AccessControl_init() internal initializer {
__Context_init_unchained();
__AccessControl_init_unchained();
}
function __AccessControl_init_unchained() internal initializer {
}
using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet;
struct RoleData {
EnumerableSetUpgradeable.AddressSet members;
bytes32 adminRole;
}
mapping (bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view override returns (bool) {
return _roles[role].members.contains(account);
}
/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) public view override returns (uint256) {
return _roles[role].members.length();
}
/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) public view override returns (address) {
return _roles[role].members.at(index);
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view override returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) public virtual override {
require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to grant");
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) public virtual override {
require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to revoke");
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
_roles[role].adminRole = adminRole;
}
function _grantRole(bytes32 role, address account) private {
if (_roles[role].members.add(account)) {
emit RoleGranted(role, account, _msgSender());
}
}
function _revokeRole(bytes32 role, address account) private {
if (_roles[role].members.remove(account)) {
emit RoleRevoked(role, account, _msgSender());
}
}
uint256[49] private __gap;
}
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;
}
Proxy.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (proxy/Proxy.sol)
pragma solidity ^0.8.0;
/**
* @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
* instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
* be specified by overriding the virtual {_implementation} function.
*
* Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
* different contract through the {_delegate} function.
*
* The success and return data of the delegated call will be returned back to the caller of the proxy.
*/
abstract contract Proxy {
/**
* @dev Delegates the current call to `implementation`.
*
* This function does not return to its internal call site, it will return directly to the external caller.
*/
function _delegate(address implementation) internal virtual {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
/**
* @dev This is a virtual function that should be overridden so it returns the address to which the fallback function
* and {_fallback} should delegate.
*/
function _implementation() internal view virtual returns (address);
/**
* @dev Delegates the current call to the address returned by `_implementation()`.
*
* This function does not return to its internal call site, it will return directly to the external caller.
*/
function _fallback() internal virtual {
_beforeFallback();
_delegate(_implementation());
}
/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
* function in the contract matches the call data.
*/
fallback() external payable virtual {
_fallback();
}
/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data
* is empty.
*/
receive() external payable virtual {
_fallback();
}
/**
* @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback`
* call, or as part of the Solidity `fallback` or `receive` functions.
*
* If overridden should call `super._beforeFallback()`.
*/
function _beforeFallback() internal virtual {}
}
IAccessControlUpgradeableLegacy.sol 49 lines
// SPDX-License-Identifier: AGPL-3.0-only
/*
IAccessControlUpgradeableLegacy.sol - SKALE Manager
Copyright (C) 2018-Present SKALE Labs
@author Artem Payvin
SKALE Manager is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SKALE Manager is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with SKALE Manager. If not, see <https://www.gnu.org/licenses/>.
*/
pragma solidity >=0.6.10 <0.9.0;
interface IAccessControlUpgradeableLegacy {
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
function grantRole(bytes32 role, address account) external;
function revokeRole(bytes32 role, address account) external;
function renounceRole(bytes32 role, address account) external;
function hasRole(bytes32 role, address account) external view returns (bool);
function getRoleMemberCount(bytes32 role) external view returns (uint256);
function getRoleMember(bytes32 role, uint256 index) external view returns (address);
function getRoleAdmin(bytes32 role) external view returns (bytes32);
}
IERC1820Registry.sol 116 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (utils/introspection/IERC1820Registry.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the global ERC1820 Registry, as defined in the
* https://eips.ethereum.org/EIPS/eip-1820[EIP]. Accounts may register
* implementers for interfaces in this registry, as well as query support.
*
* Implementers may be shared by multiple accounts, and can also implement more
* than a single interface for each account. Contracts can implement interfaces
* for themselves, but externally-owned accounts (EOA) must delegate this to a
* contract.
*
* {IERC165} interfaces can also be queried via the registry.
*
* For an in-depth explanation and source code analysis, see the EIP text.
*/
interface IERC1820Registry {
event InterfaceImplementerSet(address indexed account, bytes32 indexed interfaceHash, address indexed implementer);
event ManagerChanged(address indexed account, address indexed newManager);
/**
* @dev Sets `newManager` as the manager for `account`. A manager of an
* account is able to set interface implementers for it.
*
* By default, each account is its own manager. Passing a value of `0x0` in
* `newManager` will reset the manager to this initial state.
*
* Emits a {ManagerChanged} event.
*
* Requirements:
*
* - the caller must be the current manager for `account`.
*/
function setManager(address account, address newManager) external;
/**
* @dev Returns the manager for `account`.
*
* See {setManager}.
*/
function getManager(address account) external view returns (address);
/**
* @dev Sets the `implementer` contract as ``account``'s implementer for
* `interfaceHash`.
*
* `account` being the zero address is an alias for the caller's address.
* The zero address can also be used in `implementer` to remove an old one.
*
* See {interfaceHash} to learn how these are created.
*
* Emits an {InterfaceImplementerSet} event.
*
* Requirements:
*
* - the caller must be the current manager for `account`.
* - `interfaceHash` must not be an {IERC165} interface id (i.e. it must not
* end in 28 zeroes).
* - `implementer` must implement {IERC1820Implementer} and return true when
* queried for support, unless `implementer` is the caller. See
* {IERC1820Implementer-canImplementInterfaceForAddress}.
*/
function setInterfaceImplementer(
address account,
bytes32 _interfaceHash,
address implementer
) external;
/**
* @dev Returns the implementer of `interfaceHash` for `account`. If no such
* implementer is registered, returns the zero address.
*
* If `interfaceHash` is an {IERC165} interface id (i.e. it ends with 28
* zeroes), `account` will be queried for support of it.
*
* `account` being the zero address is an alias for the caller's address.
*/
function getInterfaceImplementer(address account, bytes32 _interfaceHash) external view returns (address);
/**
* @dev Returns the interface hash for an `interfaceName`, as defined in the
* corresponding
* https://eips.ethereum.org/EIPS/eip-1820#interface-name[section of the EIP].
*/
function interfaceHash(string calldata interfaceName) external pure returns (bytes32);
/**
* @notice Updates the cache with whether the contract implements an ERC165 interface or not.
* @param account Address of the contract for which to update the cache.
* @param interfaceId ERC165 interface for which to update the cache.
*/
function updateERC165Cache(address account, bytes4 interfaceId) external;
/**
* @notice Checks whether a contract implements an ERC165 interface or not.
* If the result is not cached a direct lookup on the contract address is performed.
* If the result is not cached or the cached value is out-of-date, the cache MUST be updated manually by calling
* {updateERC165Cache} with the contract address.
* @param account Address of the contract to check.
* @param interfaceId ERC165 interface to check.
* @return True if `account` implements `interfaceId`, false otherwise.
*/
function implementsERC165Interface(address account, bytes4 interfaceId) external view returns (bool);
/**
* @notice Checks whether a contract implements an ERC165 interface or not without using nor updating the cache.
* @param account Address of the contract to check.
* @param interfaceId ERC165 interface to check.
* @return True if `account` implements `interfaceId`, false otherwise.
*/
function implementsERC165InterfaceNoCache(address account, bytes4 interfaceId) external view returns (bool);
}
Allocator.sol 543 lines
// SPDX-License-Identifier: AGPL-3.0-only
/*
Allocator.sol - SKALE Allocator
Copyright (C) 2020-Present SKALE Labs
@author Artem Payvin
@author Dmytro Stebaiev
SKALE Allocator is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SKALE Allocator is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with SKALE Allocator. If not, see <https://www.gnu.org/licenses/>.
*/
pragma solidity 0.8.11;
pragma experimental ABIEncoderV2;
import "@openzeppelin/contracts/utils/introspection/IERC1820Registry.sol";
import "@openzeppelin/contracts/token/ERC777/IERC777Recipient.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
import "@skalenetwork/skale-manager-interfaces/delegation/ITimeHelpers.sol";
import "./interfaces/IAllocator.sol";
import "./Escrow.sol";
import "./Permissions.sol";
/**
* @title Allocator
*/
contract Allocator is Permissions, IERC777Recipient, IAllocator {
uint256 constant private _SECONDS_PER_DAY = 24 * 60 * 60;
uint256 constant private _MONTHS_PER_YEAR = 12;
IERC1820Registry private _erc1820;
// array of Plan configs
Plan[] private _plans;
bytes32 public constant VESTING_MANAGER_ROLE = keccak256("VESTING_MANAGER_ROLE");
// beneficiary => beneficiary plan params
mapping (address => Beneficiary) private _beneficiaries;
// beneficiary => Escrow
mapping (address => Escrow) private _beneficiaryToEscrow;
string public version;
modifier onlyVestingManager() {
require(
hasRole(VESTING_MANAGER_ROLE, _msgSender()),
"Message sender is not a vesting manager"
);
_;
}
function tokensReceived(
address operator,
address from,
address to,
uint256 amount,
bytes calldata userData,
bytes calldata operatorData
)
external
override
allow("SkaleToken")
// solhint-disable-next-line no-empty-blocks
{
}
function changeBeneficiaryAddress(address newBeneficiaryAddress) external override {
require(newBeneficiaryAddress != address(0), "Beneficiary address cannot be null");
require(
_beneficiaries[newBeneficiaryAddress].status == BeneficiaryStatus.UNKNOWN,
"New beneficiary address must be clean"
);
_beneficiaries[msg.sender].requestedAddress = newBeneficiaryAddress;
}
function confirmBeneficiaryAddress(address oldBeneficiaryAddress) external override {
require(
msg.sender == _beneficiaries[oldBeneficiaryAddress].requestedAddress,
"Beneficiary address is not allowed to change"
);
_beneficiaries[msg.sender] = Beneficiary({
status: _beneficiaries[oldBeneficiaryAddress].status,
planId: _beneficiaries[oldBeneficiaryAddress].planId,
startMonth: _beneficiaries[oldBeneficiaryAddress].startMonth,
fullAmount: _beneficiaries[oldBeneficiaryAddress].fullAmount,
amountAfterLockup: _beneficiaries[oldBeneficiaryAddress].amountAfterLockup,
requestedAddress: address(0)
});
_beneficiaryToEscrow[msg.sender] = _beneficiaryToEscrow[oldBeneficiaryAddress];
delete _beneficiaries[oldBeneficiaryAddress];
delete _beneficiaryToEscrow[oldBeneficiaryAddress];
_beneficiaryToEscrow[msg.sender].changeBeneficiaryAddress(msg.sender);
}
/**
* @dev Allows Vesting manager to activate a vesting and transfer locked
* tokens from the Allocator contract to the associated Escrow address.
*
* Requirements:
*
* - Beneficiary address must be already confirmed.
*/
function startVesting(address beneficiary) external override onlyVestingManager {
require(
_beneficiaries[beneficiary].status == BeneficiaryStatus.CONFIRMED,
"Beneficiary has inappropriate status"
);
_beneficiaries[beneficiary].status = BeneficiaryStatus.ACTIVE;
require(
IERC20(contractManager.getContract("SkaleToken")).transfer(
address(_beneficiaryToEscrow[beneficiary]),
_beneficiaries[beneficiary].fullAmount
),
"Error of token sending"
);
}
/**
* @dev Allows Vesting manager to define and add a Plan.
*
* Requirements:
*
* - Vesting cliff period must be less than or equal to the full period.
* - Vesting step time unit must be in days, months, or years.
* - Total vesting duration must equal vesting cliff plus entire vesting schedule.
*/
function addPlan(
uint256 vestingCliff, // months
uint256 totalVestingDuration, // months
TimeUnit vestingIntervalTimeUnit, // 0 - day 1 - month 2 - year
uint256 vestingInterval, // months or days or years
bool canDelegate, // can beneficiary delegate all un-vested tokens
bool isTerminatable
)
external
override
onlyVestingManager
{
require(totalVestingDuration > 0, "Vesting duration can't be zero");
require(vestingInterval > 0, "Vesting interval can't be zero");
require(totalVestingDuration >= vestingCliff, "Cliff period exceeds total vesting duration");
// can't check if vesting interval in days is correct because it depends on startMonth
// This check is in connectBeneficiaryToPlan
if (vestingIntervalTimeUnit == TimeUnit.MONTH) {
uint256 vestingDurationAfterCliff = totalVestingDuration - vestingCliff;
require(
vestingDurationAfterCliff % vestingInterval == 0,
"Vesting duration can't be divided into equal intervals"
);
} else if (vestingIntervalTimeUnit == TimeUnit.YEAR) {
uint256 vestingDurationAfterCliff = totalVestingDuration - vestingCliff;
require(
vestingDurationAfterCliff % (vestingInterval * _MONTHS_PER_YEAR) == 0,
"Vesting duration can't be divided into equal intervals"
);
}
_plans.push(Plan({
totalVestingDuration: totalVestingDuration,
vestingCliff: vestingCliff,
vestingIntervalTimeUnit: vestingIntervalTimeUnit,
vestingInterval: vestingInterval,
isDelegationAllowed: canDelegate,
isTerminatable: isTerminatable
}));
emit PlanCreated(_plans.length);
}
/**
* @dev Allows Vesting manager to register a beneficiary to a Plan.
*
* Requirements:
*
* - Plan must already exist.
* - The vesting amount must be less than or equal to the full allocation.
* - The beneficiary address must not already be included in the any other Plan.
*/
function connectBeneficiaryToPlan(
address beneficiary,
uint256 planId,
uint256 startMonth,
uint256 fullAmount,
uint256 lockupAmount
)
external
override
onlyVestingManager
{
require(_plans.length >= planId && planId > 0, "Plan does not exist");
require(fullAmount >= lockupAmount, "Incorrect amounts");
require(_beneficiaries[beneficiary].status == BeneficiaryStatus.UNKNOWN, "Beneficiary is already added");
if (_plans[planId - 1].vestingIntervalTimeUnit == TimeUnit.DAY) {
uint256 vestingDurationInDays = _daysBetweenMonths(
startMonth + _plans[planId - 1].vestingCliff,
startMonth + _plans[planId - 1].totalVestingDuration
);
require(
vestingDurationInDays % _plans[planId - 1].vestingInterval == 0,
"Vesting duration can't be divided into equal intervals"
);
}
_beneficiaries[beneficiary] = Beneficiary({
status: BeneficiaryStatus.CONFIRMED,
planId: planId,
startMonth: startMonth,
fullAmount: fullAmount,
amountAfterLockup: lockupAmount,
requestedAddress: address(0)
});
_beneficiaryToEscrow[beneficiary] = _deployEscrow(beneficiary);
}
/**
* @dev Allows Vesting manager to terminate vesting of a Escrow. Performed when
* a beneficiary is terminated.
*
* Requirements:
*
* - Vesting must be active.
*/
function stopVesting(address beneficiary) external override onlyVestingManager {
require(
_beneficiaries[beneficiary].status == BeneficiaryStatus.ACTIVE,
"Cannot stop vesting for a non active beneficiary"
);
require(
_plans[_beneficiaries[beneficiary].planId - 1].isTerminatable,
"Can't stop vesting for beneficiary with this plan"
);
_beneficiaries[beneficiary].status = BeneficiaryStatus.TERMINATED;
Escrow(_beneficiaryToEscrow[beneficiary]).cancelVesting(calculateVestedAmount(beneficiary));
}
/**
* @dev Sets new version of contracts on schain
*
* Requirements:
*
* - `msg.sender` must be granted DEFAULT_ADMIN_ROLE
*/
function setVersion(string calldata newVersion) external override onlyOwner {
emit VersionUpdated(version, newVersion);
version = newVersion;
}
/**
* @dev Returns vesting start month of the beneficiary's Plan.
*/
function getStartMonth(address beneficiary) external view override returns (uint) {
return _beneficiaries[beneficiary].startMonth;
}
/**
* @dev Returns the final vesting date of the beneficiary's Plan.
*/
function getFinishVestingTime(address beneficiary) external view override returns (uint) {
ITimeHelpers timeHelpers = ITimeHelpers(contractManager.getContract("TimeHelpers"));
Beneficiary memory beneficiaryPlan = _beneficiaries[beneficiary];
Plan memory planParams = _plans[beneficiaryPlan.planId - 1];
return timeHelpers.monthToTimestamp(beneficiaryPlan.startMonth + planParams.totalVestingDuration);
}
/**
* @dev Returns the vesting cliff period in months.
*/
function getVestingCliffInMonth(address beneficiary) external view override returns (uint) {
return _plans[_beneficiaries[beneficiary].planId - 1].vestingCliff;
}
/**
* @dev Confirms whether the beneficiary is active in the Plan.
*/
function isVestingActive(address beneficiary) external view override returns (bool) {
return _beneficiaries[beneficiary].status == BeneficiaryStatus.ACTIVE;
}
/**
* @dev Confirms whether the beneficiary is registered in a Plan.
*/
function isBeneficiaryRegistered(address beneficiary) external view override returns (bool) {
return _beneficiaries[beneficiary].status != BeneficiaryStatus.UNKNOWN;
}
/**
* @dev Confirms whether the beneficiary's Plan allows all un-vested tokens to be
* delegated.
*/
function isDelegationAllowed(address beneficiary) external view override returns (bool) {
return _plans[_beneficiaries[beneficiary].planId - 1].isDelegationAllowed;
}
/**
* @dev Returns the locked and unlocked (full) amount of tokens allocated to
* the beneficiary address in Plan.
*/
function getFullAmount(address beneficiary) external view override returns (uint) {
return _beneficiaries[beneficiary].fullAmount;
}
/**
* @dev Returns the Escrow contract by beneficiary.
*/
function getEscrowAddress(address beneficiary) external view override returns (address) {
return address(_beneficiaryToEscrow[beneficiary]);
}
/**
* @dev Returns the timestamp when vesting cliff ends and periodic vesting
* begins.
*/
function getLockupPeriodEndTimestamp(address beneficiary) external view override returns (uint) {
ITimeHelpers timeHelpers = ITimeHelpers(contractManager.getContract("TimeHelpers"));
Beneficiary memory beneficiaryPlan = _beneficiaries[beneficiary];
Plan memory planParams = _plans[beneficiaryPlan.planId - 1];
return timeHelpers.monthToTimestamp(beneficiaryPlan.startMonth + planParams.vestingCliff);
}
/**
* @dev Returns the time of the next vesting event.
*/
function getTimeOfNextVest(address beneficiary) external view override returns (uint) {
ITimeHelpers timeHelpers = ITimeHelpers(contractManager.getContract("TimeHelpers"));
Beneficiary memory beneficiaryPlan = _beneficiaries[beneficiary];
Plan memory planParams = _plans[beneficiaryPlan.planId - 1];
uint256 firstVestingMonth = beneficiaryPlan.startMonth + planParams.vestingCliff;
uint256 lockupEndTimestamp = timeHelpers.monthToTimestamp(firstVestingMonth);
if (block.timestamp < lockupEndTimestamp) {
return lockupEndTimestamp;
}
require(
block.timestamp < timeHelpers.monthToTimestamp(
beneficiaryPlan.startMonth + planParams.totalVestingDuration
),
"Vesting is over"
);
require(beneficiaryPlan.status != BeneficiaryStatus.TERMINATED, "Vesting was stopped");
uint256 currentMonth = timeHelpers.getCurrentMonth();
if (planParams.vestingIntervalTimeUnit == TimeUnit.DAY) {
// TODO: it may be simplified if TimeHelpers contract in skale-manager is updated
uint daysPassedBeforeCurrentMonth = _daysBetweenMonths(firstVestingMonth, currentMonth);
uint256 currentMonthBeginningTimestamp = timeHelpers.monthToTimestamp(currentMonth);
uint256 daysPassedInCurrentMonth = (block.timestamp - currentMonthBeginningTimestamp) / _SECONDS_PER_DAY;
uint256 daysPassedBeforeNextVest = _calculateNextVestingStep(
daysPassedBeforeCurrentMonth + daysPassedInCurrentMonth,
planParams.vestingInterval
);
return currentMonthBeginningTimestamp +
(daysPassedBeforeNextVest - daysPassedBeforeCurrentMonth) * _SECONDS_PER_DAY;
} else if (planParams.vestingIntervalTimeUnit == TimeUnit.MONTH) {
return timeHelpers.monthToTimestamp(
firstVestingMonth +
_calculateNextVestingStep(currentMonth - firstVestingMonth, planParams.vestingInterval)
);
} else if (planParams.vestingIntervalTimeUnit == TimeUnit.YEAR) {
return timeHelpers.monthToTimestamp(
firstVestingMonth +
_calculateNextVestingStep(
currentMonth - firstVestingMonth,
planParams.vestingInterval * _MONTHS_PER_YEAR
)
);
} else {
revert("Vesting interval timeunit is incorrect");
}
}
/**
* @dev Returns the Plan parameters.
*
* Requirements:
*
* - Plan must already exist.
*/
function getPlan(uint256 planId) external view override returns (Plan memory) {
require(planId > 0 && planId <= _plans.length, "Plan Round does not exist");
return _plans[planId - 1];
}
/**
* @dev Returns the Plan parameters for a beneficiary address.
*
* Requirements:
*
* - Beneficiary address must be registered to an Plan.
*/
function getBeneficiaryPlanParams(address beneficiary) external view override returns (Beneficiary memory) {
require(_beneficiaries[beneficiary].status != BeneficiaryStatus.UNKNOWN, "Plan beneficiary is not registered");
return _beneficiaries[beneficiary];
}
function initialize(address contractManagerAddress) public override initializer {
Permissions.initialize(contractManagerAddress);
_erc1820 = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
_erc1820.setInterfaceImplementer(address(this), keccak256("ERC777TokensRecipient"), address(this));
}
/**
* @dev Calculates and returns the vested token amount.
*/
function calculateVestedAmount(address wallet) public view override returns (uint256 vestedAmount) {
ITimeHelpers timeHelpers = ITimeHelpers(contractManager.getContract("TimeHelpers"));
Beneficiary memory beneficiaryPlan = _beneficiaries[wallet];
Plan memory planParams = _plans[beneficiaryPlan.planId - 1];
vestedAmount = 0;
uint256 currentMonth = timeHelpers.getCurrentMonth();
if (currentMonth >= beneficiaryPlan.startMonth + planParams.vestingCliff) {
vestedAmount = beneficiaryPlan.amountAfterLockup;
if (currentMonth >= beneficiaryPlan.startMonth + planParams.totalVestingDuration) {
vestedAmount = beneficiaryPlan.fullAmount;
} else {
uint256 payment = _getSinglePaymentSize(
wallet,
beneficiaryPlan.fullAmount,
beneficiaryPlan.amountAfterLockup
);
vestedAmount = vestedAmount + payment * _getNumberOfCompletedVestingEvents(wallet);
}
}
}
/**
* @dev Returns the number of vesting events that have completed.
*/
function _getNumberOfCompletedVestingEvents(address wallet) internal view returns (uint) {
ITimeHelpers timeHelpers = ITimeHelpers(contractManager.getContract("TimeHelpers"));
Beneficiary memory beneficiaryPlan = _beneficiaries[wallet];
Plan memory planParams = _plans[beneficiaryPlan.planId - 1];
uint256 firstVestingMonth = beneficiaryPlan.startMonth + planParams.vestingCliff;
if (block.timestamp < timeHelpers.monthToTimestamp(firstVestingMonth)) {
return 0;
} else {
uint256 currentMonth = timeHelpers.getCurrentMonth();
if (planParams.vestingIntervalTimeUnit == TimeUnit.DAY) {
return (_daysBetweenMonths(firstVestingMonth, currentMonth)
+ (block.timestamp - timeHelpers.monthToTimestamp(currentMonth))
/ _SECONDS_PER_DAY)
/ planParams.vestingInterval;
} else if (planParams.vestingIntervalTimeUnit == TimeUnit.MONTH) {
return (currentMonth - firstVestingMonth) / planParams.vestingInterval;
} else if (planParams.vestingIntervalTimeUnit == TimeUnit.YEAR) {
return (currentMonth - firstVestingMonth) / _MONTHS_PER_YEAR / planParams.vestingInterval;
} else {
revert("Unknown time unit");
}
}
}
/**
* @dev Returns the number of total vesting events.
*/
function _getNumberOfAllVestingEvents(address wallet) internal view returns (uint) {
Beneficiary memory beneficiaryPlan = _beneficiaries[wallet];
Plan memory planParams = _plans[beneficiaryPlan.planId - 1];
if (planParams.vestingIntervalTimeUnit == TimeUnit.DAY) {
return _daysBetweenMonths(
beneficiaryPlan.startMonth + planParams.vestingCliff,
beneficiaryPlan.startMonth + planParams.totalVestingDuration
) / planParams.vestingInterval;
} else if (planParams.vestingIntervalTimeUnit == TimeUnit.MONTH) {
return (planParams.totalVestingDuration - planParams.vestingCliff)
/ planParams.vestingInterval;
} else if (planParams.vestingIntervalTimeUnit == TimeUnit.YEAR) {
return (planParams.totalVestingDuration - planParams.vestingCliff)
/ _MONTHS_PER_YEAR
/ planParams.vestingInterval;
} else {
revert("Unknown time unit");
}
}
/**
* @dev Returns the amount of tokens that are unlocked in each vesting
* period.
*/
function _getSinglePaymentSize(
address wallet,
uint256 fullAmount,
uint256 afterLockupPeriodAmount
)
internal
view
returns(uint)
{
return (fullAmount - afterLockupPeriodAmount) / _getNumberOfAllVestingEvents(wallet);
}
function _deployEscrow(address beneficiary) private returns (Escrow) {
address proxyAdmin = contractManager.getContract("ProxyAdmin");
TransparentUpgradeableProxy escrow = TransparentUpgradeableProxy(
payable(contractManager.getContract("Escrow"))
);
address escrowImplementation = ProxyAdmin(proxyAdmin).getProxyImplementation(escrow);
bytes memory initializingData = abi.encodeWithSignature(
"initialize(address,address)", address(contractManager), beneficiary
);
address beneficiaryEscrow = address(new TransparentUpgradeableProxy(
escrowImplementation, proxyAdmin, initializingData
));
return Escrow(beneficiaryEscrow);
}
function _daysBetweenMonths(uint256 beginMonth, uint256 endMonth) private view returns (uint256) {
assert(beginMonth <= endMonth);
ITimeHelpers timeHelpers = ITimeHelpers(contractManager.getContract("TimeHelpers"));
uint256 beginTimestamp = timeHelpers.monthToTimestamp(beginMonth);
uint256 endTimestamp = timeHelpers.monthToTimestamp(endMonth);
uint256 secondsPassed = endTimestamp - beginTimestamp;
require(secondsPassed % _SECONDS_PER_DAY == 0, "Internal error in calendar");
return secondsPassed / _SECONDS_PER_DAY;
}
/**
* @dev returns time of next vest in abstract time units named "step"
* Examples:
* if current step is 5 and vesting interval is 7 function returns 7.
* if current step is 17 and vesting interval is 7 function returns 21.
*/
function _calculateNextVestingStep(uint256 currentStep, uint256 vestingInterval) private pure returns (uint256) {
// slither-disable-next-line weak-prng
return currentStep + vestingInterval - currentStep % vestingInterval;
}
}
StorageSlot.sol 84 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol)
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly {
r.slot := slot
}
}
}
IContractManager.sol 42 lines
// SPDX-License-Identifier: AGPL-3.0-only
/*
IContractManager.sol - SKALE Manager Interfaces
Copyright (C) 2021-Present SKALE Labs
@author Dmytro Stebaeiv
SKALE Manager Interfaces is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SKALE Manager Interfaces is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with SKALE Manager Interfaces. If not, see <https://www.gnu.org/licenses/>.
*/
pragma solidity >=0.6.10 <0.9.0;
interface IContractManager {
/**
* @dev Emitted when contract is upgraded.
*/
event ContractUpgraded(string contractsName, address contractsAddress);
function initialize() external;
function setContractsAddress(string calldata contractsName, address newContractsAddress) external;
function contracts(bytes32 nameHash) external view returns (address);
function getDelegationPeriodManager() external view returns (address);
function getBounty() external view returns (address);
function getValidatorService() external view returns (address);
function getTimeHelpers() external view returns (address);
function getConstantsHolder() external view returns (address);
function getSkaleToken() external view returns (address);
function getTokenState() external view returns (address);
function getPunisher() external view returns (address);
function getContract(string calldata name) external view returns (address);
}
EnumerableSetUpgradeable.sol 357 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (utils/structs/EnumerableSet.sol)
pragma solidity ^0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*/
library EnumerableSetUpgradeable {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastValue;
// Update the index for the moved value
set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
return _values(set._inner);
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
assembly {
result := store
}
return result;
}
}
InitializableWithGap.sol 10 lines
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.11;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
contract InitializableWithGap is Initializable {
uint256[50] private ______gap;
}
Read Contract
BENEFICIARY_ROLE 0xced3a403 → bytes32
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
contractManager 0xb39e12cf → address
getRoleAdmin 0x248a9ca3 → bytes32
getRoleMember 0x9010d07c → address
getRoleMemberCount 0xca15c873 → uint256
hasRole 0x91d14854 → bool
Write Contract 16 functions
These functions modify contract state and require a wallet transaction to execute.
cancelPendingDelegation 0x9ac1c4ad
uint256 delegationId
cancelVesting 0xa15f74a2
uint256 vestedAmount
changeBeneficiaryAddress 0x12d0e65a
address beneficiary
delegate 0x21eb5859
uint256 validatorId
uint256 amount
uint256 delegationPeriod
string info
grantRole 0x2f2ff15d
bytes32 role
address account
initialize 0x485cc955
address contractManagerAddress
address beneficiary
initialize 0xc4d66de8
address contractManagerAddress
reinitialize 0xf7e7d1fd
address beneficiary
renounceRole 0x36568abe
bytes32 role
address account
requestUndelegation 0x27e5455a
uint256 delegationId
retrieve 0x2e64cec1
No parameters
retrieveAfterTermination 0xc09558db
address destination
revokeRole 0xd547741f
bytes32 role
address account
tokensReceived 0x0023de29
address operator
address from
address to
uint256 amount
bytes userData
bytes operatorData
tokensToSend 0x75ab9782
address
address
address to
uint256
bytes
bytes
withdrawBounty 0x76d07f6b
uint256 validatorId
address to
Recent Transactions
No transactions found for this address