Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xc2F44Bc508b6b50047a2F3AfB1984eD105070bE1
Balance 0 ETH
Nonce 1
Code Size 9714 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

9714 bytes
0x6080604052600436106101ae5760003560e01c80637267994e116100ed578063ce9d16fe11610090578063ce9d16fe14610532578063db2e21bc14610552578063df1fb71314610567578063ebde5ee61461059b578063ec2fc051146105cf578063f2fde38b14610603578063f40f0f5214610623578063f7c618c114610643578063fc9768271461067757600080fd5b80637267994e146103eb578063736c0d5b146103fe5780638337c3c01461043e5780638da1a403146104545780638da5cb5b14610488578063b9bd4730146104aa578063c031a66f146104de578063ca90c8c6146104fe57600080fd5b8063350b236911610155578063350b23691461030d5780633ccfd60b1461032d5780633e8ff57b146103425780634641257d1461037657806363b201171461038b57806365267139146103a15780636df5ee2b146103c1578063715018a6146103d657600080fd5b8063055ad42e146101b35780630917e776146101e35780630a122c8a14610206578063194bf5541461023a5780631959a002146102515780631c9b1736146102ad5780632ce9785f146102e157806330188ee8146102f7575b600080fd5b3480156101bf57600080fd5b506002546101cd9060ff1681565b6040516101da919061212d565b60405180910390f35b3480156101ef57600080fd5b506101f86106ab565b6040519081526020016101da565b34801561021257600080fd5b506101f87f0000000000000000000000000000000000000000000000000000000000fc950881565b34801561024657600080fd5b5061024f61070e565b005b34801561025d57600080fd5b5061029061026c366004612171565b60086020526000908152604090208054600182015460029092015490919060ff1683565b6040805193845260208401929092521515908201526060016101da565b3480156102b957600080fd5b506101f87f000000000000000000000000000000000000000000000000000000000023b4a081565b3480156102ed57600080fd5b506101f860065481565b34801561030357600080fd5b506101f860055481565b34801561031957600080fd5b5061024f610328366004612239565b61081c565b34801561033957600080fd5b5061024f610a04565b34801561034e57600080fd5b506101f87f00000000000000000000000000000000000000000000000000000000000003e881565b34801561038257600080fd5b5061024f610b5f565b34801561039757600080fd5b506101f860045481565b3480156103ad57600080fd5b5061024f6103bc36600461229d565b610cab565b3480156103cd57600080fd5b5061024f610e70565b3480156103e257600080fd5b5061024f611085565b61024f6103f93660046122b6565b6110c0565b34801561040a57600080fd5b5061042e610419366004612171565b60076020526000908152604090205460ff1681565b60405190151581526020016101da565b34801561044a57600080fd5b506101f860035481565b34801561046057600080fd5b506101f87f00000000000000000000000000000000000000000000005150ae84a8cdf0000081565b34801561049457600080fd5b5061049d6113c2565b6040516101da91906122f1565b3480156104b657600080fd5b506101f87f00000000000000000000000000000000000000000000032d26d12e980b60000081565b3480156104ea57600080fd5b506101f86104f9366004612171565b6113d1565b34801561050a57600080fd5b506101f87f000000000000000000000000000000000000000000000000000000000002f9b881565b34801561053e57600080fd5b506101f861054d366004612305565b6113e2565b34801561055e57600080fd5b5061024f611443565b34801561057357600080fd5b506101f87f00000000000000000000000000000000000000000000000014d1120d7b16000081565b3480156105a757600080fd5b5061049d7f0000000000000000000000001e4ede388cbc9f4b5c79681b7f94d36a11abebc981565b3480156105db57600080fd5b506101f87f0000000000000000000000000000000000000000000000000000000000d8e06881565b34801561060f57600080fd5b5061024f61061e366004612171565b61162b565b34801561062f57600080fd5b506101f861063e366004612171565b6116cb565b34801561064f57600080fd5b5061049d7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b34801561068357600080fd5b506101f87f0000000000000000000000000000000000000000000c685fa11e01ec6f00000081565b60007f0000000000000000000000000000000000000000000000000000000000d8e06843101580156106fc57507f0000000000000000000000000000000000000000000000000000000000fc950843105b15610708575060045490565b50600090565b336107176113c2565b6001600160a01b0316146107465760405162461bcd60e51b815260040161073d9061233a565b60405180910390fd5b600260015414156107695760405162461bcd60e51b815260040161073d9061236f565b600260019081556002805460ff169081111561078757610787612117565b146107d45760405162461bcd60e51b815260206004820152601d60248201527f4f776e65723a205068617365206d7573742062652053616c654f766572000000604482015260640161073d565b6002805460ff1916811781556040517f31f72b44f546d9e7eaec13f65636997665e15f134a81c82924f568f5c0d07b939161080e9161212d565b60405180910390a160018055565b336108256113c2565b6001600160a01b03161461084b5760405162461bcd60e51b815260040161073d9061233a565b60005b82518110156109295760016007600085848151811061086f5761086f6123a6565b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a81548160ff0219169083151502179055507fc648f6265408cc54c0dc26d24ba51dfc9f35ce1a63baa2228f65d93aaf11cc678382815181106108e1576108e16123a6565b6020026020010151600060405161090f9291906001600160a01b039290921682521515602082015260400190565b60405180910390a180610921816123d2565b91505061084e565b5060005b81518110156109ff576007600083838151811061094c5761094c6123a6565b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a81549060ff02191690557fc648f6265408cc54c0dc26d24ba51dfc9f35ce1a63baa2228f65d93aaf11cc678282815181106109b7576109b76123a6565b602002602001015160016040516109e59291906001600160a01b039290921682521515602082015260400190565b60405180910390a1806109f7816123d2565b91505061092d565b505050565b60026001541415610a275760405162461bcd60e51b815260040161073d9061236f565b60026001819055805460ff1681811115610a4357610a43612117565b14610a605760405162461bcd60e51b815260040161073d906123ed565b3360009081526008602052604090206002015460ff16610a925760405162461bcd60e51b815260040161073d90612424565b6000610a9d336116e2565b905060008111610abf5760405162461bcd60e51b815260040161073d9061245b565b610ac83361181e565b503360009081526008602052604081208054839290610ae8908490612492565b90915550610b2290506001600160a01b037f0000000000000000000000001e4ede388cbc9f4b5c79681b7f94d36a11abebc91633836118e4565b60405181815233907f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a9424364906020015b60405180910390a25060018055565b60026001541415610b825760405162461bcd60e51b815260040161073d9061236f565b60026001819055805460ff1681811115610b9e57610b9e612117565b14610beb5760405162461bcd60e51b815260206004820152601e60248201527f486172766573743a205068617365206d757374206265205374616b696e670000604482015260640161073d565b3360009081526008602052604090206002015460ff16610c4d5760405162461bcd60e51b815260206004820152601a60248201527f486172766573743a2055736572206e6f7420656c696769626c65000000000000604482015260640161073d565b6000610c583361181e565b11610ca55760405162461bcd60e51b815260206004820152601a60248201527f486172766573743a204e6f2070656e64696e6720726577617264000000000000604482015260640161073d565b60018055565b33610cb46113c2565b6001600160a01b031614610cda5760405162461bcd60e51b815260040161073d9061233a565b60026001541415610cfd5760405162461bcd60e51b815260040161073d9061236f565b6002600155610d4c7f000000000000000000000000000000000000000000000000000000000002f9b87f0000000000000000000000000000000000000000000000000000000000fc9508612492565b4311610da45760405162461bcd60e51b815260206004820152602160248201527f4f776e65723a207374616b696e672068617665206e6f7420656e6465642079656044820152601d60fa1b606482015260840161073d565b60008111610dea5760405162461bcd60e51b815260206004820152601360248201527204f776e65723a207769746864726177203e203606c1b604482015260640161073d565b8060066000828254610dfc9190612492565b90915550610e3690506001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc21633836118e4565b6040518181527ff1b96db22d7f3eb7ef19d9ddbc4d63be139f5d014216d4e42107e10cfd4ff16c9060200160405180910390a15060018055565b33610e796113c2565b6001600160a01b031614610e9f5760405162461bcd60e51b815260040161073d9061233a565b60026001541415610ec25760405162461bcd60e51b815260040161073d9061236f565b600260015560006002805460ff1690811115610ee057610ee0612117565b14610f295760405162461bcd60e51b81526020600482015260196024820152784f776e65723a205068617365206d7573742062652053616c6560381b604482015260640161073d565b47610f343382611936565b60007f00000000000000000000000000000000000000000000032d26d12e980b600000600354610f6491906124aa565b6040516370a0823160e01b81526001600160a01b037f0000000000000000000000001e4ede388cbc9f4b5c79681b7f94d36a11abebc916906370a0823190610fb09030906004016122f1565b602060405180830381865afa158015610fcd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ff191906124c9565b610ffb91906124e2565b90508015611037576110376001600160a01b037f0000000000000000000000001e4ede388cbc9f4b5c79681b7f94d36a11abebc91633836118e4565b6002805460ff191660019081179091556040517f31f72b44f546d9e7eaec13f65636997665e15f134a81c82924f568f5c0d07b93916110759161212d565b60405180910390a1505060018055565b3361108e6113c2565b6001600160a01b0316146110b45760405162461bcd60e51b815260040161073d9061233a565b6110be6000611a4f565b565b600260015414156110e35760405162461bcd60e51b815260040161073d9061236f565b600260015560006002805460ff169081111561110157611101612117565b1461114e5760405162461bcd60e51b815260206004820152601b60248201527f4465706f7369743a205068617365206d7573742062652053616c650000000000604482015260640161073d565b3360009081526008602052604090206002015460ff16156111aa5760405162461bcd60e51b815260206004820152601660248201527511195c1bdcda5d0e8812185cc819195c1bdcda5d195960521b604482015260640161073d565b7f00000000000000000000000000000000000000000000000014d1120d7b16000034146112115760405162461bcd60e51b815260206004820152601560248201527411195c1bdcda5d0e8815dc9bdb99c8185b5bdd5b9d605a1b604482015260640161073d565b7f00000000000000000000000000000000000000000000000000000000000003e8600354106112825760405162461bcd60e51b815260206004820152601c60248201527f4465706f7369743a204e6f742072616973696e6720616e796d6f726500000000604482015260640161073d565b60006112b63360405160200161129891906122f1565b60405160208183030381529060405280519060200120858585611a9f565b6001600160a01b03811660009081526007602052604090205490915060ff1661131c5760405162461bcd60e51b81526020600482015260186024820152772232b837b9b4ba1d1029b4b3b730ba3ab9329032b93937b960411b604482015260640161073d565b336000908152600860205260408120600201805460ff19166001908117909155600380549192909161134f908490612492565b925050819055507f00000000000000000000000000000000000000000000032d26d12e980b600000600460008282546113889190612492565b909155505060405133907f8ce0bd46ec50cf39f0d0ea8686a686eb226af5796dcda4231b26fb84b5ef123490600090a25050600180555050565b6000546001600160a01b031690565b60006113dc826116e2565b92915050565b60008060005b835181101561143c57600080611416868481518110611409576114096123a6565b6020026020010151611ac7565b90925090506114258285612492565b935050508080611434906123d2565b9150506113e8565b5092915050565b600260015414156114665760405162461bcd60e51b815260040161073d9061236f565b60026001557f0000000000000000000000000000000000000000000000000000000000fc95084310156114d15760405162461bcd60e51b815260206004820152601360248201527257697468647261773a20546f6f206561726c7960681b604482015260640161073d565b6002805460ff16818111156114e8576114e8612117565b146115055760405162461bcd60e51b815260040161073d906123ed565b3360009081526008602052604090206002015460ff166115375760405162461bcd60e51b815260040161073d90612424565b33600090815260086020526040812054611571907f00000000000000000000000000000000000000000000032d26d12e980b6000006124e2565b9050600081116115935760405162461bcd60e51b815260040161073d9061245b565b6115c76001600160a01b037f0000000000000000000000001e4ede388cbc9f4b5c79681b7f94d36a11abebc91633836118e4565b33600081815260086020526040908190207f00000000000000000000000000000000000000000000032d26d12e980b6000009055517f5fafa99d0643513820be26656b45130b01e1c03062e1266bf36f88cbd3bd969590610b509084815260200190565b336116346113c2565b6001600160a01b03161461165a5760405162461bcd60e51b815260040161073d9061233a565b6001600160a01b0381166116bf5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161073d565b6116c881611a4f565b50565b60008060006116d984611ac7565b50949350505050565b6001600160a01b0381166000908152600860205260408120547f0000000000000000000000000000000000000000000000000000000000d8e06843101561172c5750600092915050565b7f0000000000000000000000000000000000000000000000000000000000fc950843106117845761177d817f00000000000000000000000000000000000000000000032d26d12e980b6000006124e2565b9392505050565b60006117b07f0000000000000000000000000000000000000000000000000000000000d8e068436124e2565b905060007f000000000000000000000000000000000000000000000000000000000023b4a06117ff837f00000000000000000000000000000000000000000000032d26d12e980b6000006124aa565b61180991906124f9565b905061181583826124e2565b95945050505050565b600080600061182c84611ac7565b9092509050811561143c5781600560008282546118499190612492565b90915550506001600160a01b03808516600090815260086020526040902060010182905561189a907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc21685846118e4565b836001600160a01b03167fc9695243a805adb74c91f28311176c65b417e842d5699893cef56d18bfa48cba836040516118d591815260200190565b60405180910390a25092915050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526109ff908490611b85565b804710156119865760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e6365000000604482015260640161073d565b6000826001600160a01b03168260405160006040518083038185875af1925050503d80600081146119d3576040519150601f19603f3d011682016040523d82523d6000602084013e6119d8565b606091505b50509050806109ff5760405162461bcd60e51b815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d61792068617665207265766572746564000000000000606482015260840161073d565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000806000611ab087878787611c57565b91509150611abd81611d3a565b5095945050505050565b6000806000611ad4611ef0565b6001600160a01b03851660009081526008602052604081206001810154905492935091611b21907f00000000000000000000000000000000000000000000032d26d12e980b6000006124e2565b9050600060035484611b3391906124f9565b905060007f00000000000000000000000000000000000000000000032d26d12e980b60000083611b6386856124e2565b611b6d91906124aa565b611b7791906124f9565b989197509095505050505050565b6000611bda826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316611f9f9092919063ffffffff16565b8051909150156109ff5780806020019051810190611bf8919061251b565b6109ff5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161073d565b6000806fa2a8918ca85bafe22016d0b997e4df60600160ff1b03831115611c845750600090506003611d31565b8460ff16601b14158015611c9c57508460ff16601c14155b15611cad5750600090506004611d31565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015611d01573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116611d2a57600060019250925050611d31565b9150600090505b94509492505050565b6000816004811115611d4e57611d4e612117565b1415611d575750565b6001816004811115611d6b57611d6b612117565b1415611db45760405162461bcd60e51b815260206004820152601860248201527745434453413a20696e76616c6964207369676e617475726560401b604482015260640161073d565b6002816004811115611dc857611dc8612117565b1415611e165760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e67746800604482015260640161073d565b6003816004811115611e2a57611e2a612117565b1415611e835760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b606482015260840161073d565b6004816004811115611e9757611e97612117565b14156116c85760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c604482015261756560f01b606482015260840161073d565b6040516370a0823160e01b81526000906001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216906370a0823190611f3f9030906004016122f1565b602060405180830381865afa158015611f5c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f8091906124c9565b600554600654611f909190612492565b611f9a9190612492565b905090565b6060611fae8484600085611fb6565b949350505050565b6060824710156120175760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161073d565b843b6120655760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161073d565b600080866001600160a01b03168587604051612081919061256d565b60006040518083038185875af1925050503d80600081146120be576040519150601f19603f3d011682016040523d82523d6000602084013e6120c3565b606091505b50915091506120d38282866120de565b979650505050505050565b606083156120ed57508161177d565b8251156120fd5782518084602001fd5b8160405162461bcd60e51b815260040161073d9190612589565b634e487b7160e01b600052602160045260246000fd5b602081016003831061214f57634e487b7160e01b600052602160045260246000fd5b91905290565b80356001600160a01b038116811461216c57600080fd5b919050565b60006020828403121561218357600080fd5b61177d82612155565b634e487b7160e01b600052604160045260246000fd5b600082601f8301126121b357600080fd5b8135602067ffffffffffffffff808311156121d0576121d061218c565b8260051b604051601f19603f830116810181811084821117156121f5576121f561218c565b60405293845285810183019383810192508785111561221357600080fd5b83870191505b848210156120d35761222a82612155565b83529183019190830190612219565b6000806040838503121561224c57600080fd5b823567ffffffffffffffff8082111561226457600080fd5b612270868387016121a2565b9350602085013591508082111561228657600080fd5b50612293858286016121a2565b9150509250929050565b6000602082840312156122af57600080fd5b5035919050565b6000806000606084860312156122cb57600080fd5b833560ff811681146122dc57600080fd5b95602085013595506040909401359392505050565b6001600160a01b0391909116815260200190565b60006020828403121561231757600080fd5b813567ffffffffffffffff81111561232e57600080fd5b611fae848285016121a2565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60006000198214156123e6576123e66123bc565b5060010190565b6020808252601f908201527f57697468647261773a205068617365206d757374206265205374616b696e6700604082015260600190565b6020808252601b908201527f57697468647261773a2055736572206e6f7420656c696769626c650000000000604082015260600190565b6020808252601a908201527f57697468647261773a204e6f2070656e64696e6720746f6b656e000000000000604082015260600190565b600082198211156124a5576124a56123bc565b500190565b60008160001904831182151516156124c4576124c46123bc565b500290565b6000602082840312156124db57600080fd5b5051919050565b6000828210156124f4576124f46123bc565b500390565b60008261251657634e487b7160e01b600052601260045260246000fd5b500490565b60006020828403121561252d57600080fd5b8151801515811461177d57600080fd5b60005b83811015612558578181015183820152602001612540565b83811115612567576000848401525b50505050565b6000825161257f81846020870161253d565b9190910192915050565b60208152600082518060208401526125a881604085016020870161253d565b601f01601f1916919091016040019291505056fea26469706673582212200156799ca4c281d83cfb56358298509d08fafcf9b6a142c89452a450c118d3be64736f6c634300080b0033

Verified Source Code Full Match

Compiler: v0.8.11+commit.d7f03943 EVM: london Optimization: Yes (100 runs)
Presale.sol 269 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;
pragma abicoder v2;

import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/security/ReentrancyGuard.sol';
import '@openzeppelin/contracts/utils/cryptography/ECDSA.sol';
import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import './ITokenStaked.sol';

contract Presale is Ownable, ReentrancyGuard, ITokenStaked {
    using SafeERC20 for IERC20;

    enum SalePhase {
        Sale,
        SaleOver,
        Staking
    }

    struct UserInfo {
        uint256 tokensClaimed;
        uint256 rewardDebt;
        bool hasShare;
    }

    uint256 public immutable safetyBufferInBlocks;

    IERC20 public immutable x2y2Token; // x2y2
    IERC20 public immutable rewardToken; // weth

    // staking period in blocks
    uint256 public immutable STAKING_PERIOD_IN_BLOCKS;
    uint256 public immutable stakingStartBlock;
    uint256 public immutable stakingEndBlock;

    uint256 public immutable TOTAL_TOKEN_AMOUNT;
    uint256 public immutable TOTAL_RAISING_AMOUNT;
    uint256 public immutable MAX_SHARES;
    uint256 public immutable PRICE_PER_SHARE;
    uint256 public immutable TOKENS_PER_SHARE;

    SalePhase public currentPhase;

    // total shares sold (length of userInfo)
    uint256 public totalShareSold;
    // share * TOKENS_PER_SHARE
    uint256 public totalTokensSold;

    // weth harvested by user
    uint256 public totalRewardDistributed;
    // withdrawn reward token
    uint256 public tokenRewardTreasuryWithdrawn;

    mapping(address => bool) public signers;
    mapping(address => UserInfo) public userInfo;

    event SignerUpdate(address signer, bool isRemoval);
    event Deposit(address indexed user);
    event Harvest(address indexed user, uint256 amount);
    event NewPhase(SalePhase newSalePhase);
    event Withdraw(address indexed user, uint256 amount);
    event EmergencyWithdraw(address indexed user, uint256 amount);
    event TreasuryWithdraw(uint256 amount);

    constructor(
        IERC20 _x2y2Token,
        IERC20 _rewardToken,
        uint256 _stakingStartBlock,
        uint256 _stakingEndBlock,
        address[] memory _signers
    ) {
        x2y2Token = (_x2y2Token);
        rewardToken = (_rewardToken);

        for (uint256 i = 0; i < _signers.length; i++) {
            signers[_signers[i]] = true;
            emit SignerUpdate(_signers[i], false);
        }

        // 15M token presale
        TOTAL_TOKEN_AMOUNT = 15_000_000 ether;
        TOTAL_RAISING_AMOUNT = 1500 ether;
        MAX_SHARES = 1000;
        PRICE_PER_SHARE = TOTAL_RAISING_AMOUNT / MAX_SHARES;
        TOKENS_PER_SHARE = TOTAL_TOKEN_AMOUNT / MAX_SHARES;

        STAKING_PERIOD_IN_BLOCKS = _stakingEndBlock - _stakingStartBlock;
        stakingStartBlock = _stakingStartBlock;
        stakingEndBlock = _stakingEndBlock;

        currentPhase = SalePhase.Sale;
        safetyBufferInBlocks = 30 * 6500; // ~ 1 month
    }

    function getTotalStaked() external view override returns (uint256) {
        if (block.number >= stakingStartBlock && block.number < stakingEndBlock) {
            return totalTokensSold;
        }
        return 0;
    }

    function updateSigners(address[] memory toAdd, address[] memory toRemove) public onlyOwner {
        for (uint256 i = 0; i < toAdd.length; i++) {
            signers[toAdd[i]] = true;
            emit SignerUpdate(toAdd[i], false);
        }
        for (uint256 i = 0; i < toRemove.length; i++) {
            delete signers[toRemove[i]];
            emit SignerUpdate(toRemove[i], true);
        }
    }

    function deposit(
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external payable nonReentrant {
        require(currentPhase == SalePhase.Sale, 'Deposit: Phase must be Sale');
        require(!userInfo[msg.sender].hasShare, 'Deposit: Has deposited');
        require(msg.value == PRICE_PER_SHARE, 'Deposit: Wrong amount');
        require(totalShareSold < MAX_SHARES, 'Deposit: Not raising anymore');

        address signer = ECDSA.recover(keccak256(abi.encode(msg.sender)), v, r, s);
        require(signers[signer], 'Deposit: Signature error');

        userInfo[msg.sender].hasShare = true;

        totalShareSold += 1;
        totalTokensSold += TOKENS_PER_SHARE;

        emit Deposit(msg.sender);
    }

    function _totalReward() internal view returns (uint256) {
        return
            tokenRewardTreasuryWithdrawn +
            totalRewardDistributed +
            rewardToken.balanceOf(address(this));
    }

    function _pendingReward(address user) internal view returns (uint256, uint256) {
        uint256 totalReward = _totalReward();
        uint256 userDebt = userInfo[user].rewardDebt;
        uint256 userTokensLeft = TOKENS_PER_SHARE - userInfo[user].tokensClaimed;

        uint256 theoreticalReward = totalReward / totalShareSold;
        uint256 userReward = ((theoreticalReward - userDebt) * userTokensLeft) / TOKENS_PER_SHARE;

        return (userReward, theoreticalReward);
    }

    function pendingRewards(address[] memory users) external view returns (uint256) {
        uint256 total;
        for (uint256 i = 0; i < users.length; i++) {
            (uint256 pending, uint256 _debt) = _pendingReward(users[i]);
            total += pending;
        }
        return total;
    }

    function pendingReward(address user) external view returns (uint256) {
        (uint256 _amount, uint256 _debt) = _pendingReward(user);
        return _amount;
    }

    function _pendingTokens(address user) internal view returns (uint256) {
        uint256 claimed = userInfo[user].tokensClaimed;

        if (block.number < stakingStartBlock) {
            return 0;
        } else if (block.number >= stakingEndBlock) {
            return TOKENS_PER_SHARE - claimed;
        }

        uint256 passingBlocks = block.number - stakingStartBlock;
        uint256 unlockedAmount = (TOKENS_PER_SHARE * passingBlocks) / STAKING_PERIOD_IN_BLOCKS;

        return unlockedAmount - claimed;
    }

    function pendingTokens(address user) external view returns (uint256) {
        return _pendingTokens(user);
    }

    function _harvest(address user) internal returns (uint256) {
        (uint256 _pending, uint256 _debt) = _pendingReward(user);

        if (_pending > 0) {
            totalRewardDistributed += _pending;
            userInfo[user].rewardDebt = _debt;
            rewardToken.safeTransfer(user, _pending);
            emit Harvest(user, _pending);
        }
        return _pending;
    }

    function harvest() external nonReentrant {
        require(currentPhase == SalePhase.Staking, 'Harvest: Phase must be Staking');
        require(userInfo[msg.sender].hasShare, 'Harvest: User not eligible');

        require(_harvest(msg.sender) > 0, 'Harvest: No pending reward');
    }

    function withdraw() external nonReentrant {
        require(currentPhase == SalePhase.Staking, 'Withdraw: Phase must be Staking');
        require(userInfo[msg.sender].hasShare, 'Withdraw: User not eligible');

        uint256 pending = _pendingTokens(msg.sender);

        require(pending > 0, 'Withdraw: No pending token');

        _harvest(msg.sender);

        userInfo[msg.sender].tokensClaimed += pending;
        x2y2Token.safeTransfer(msg.sender, pending);

        emit Withdraw(msg.sender, pending);
    }

    function emergencyWithdraw() external nonReentrant {
        require(block.number >= stakingEndBlock, 'Withdraw: Too early');
        require(currentPhase == SalePhase.Staking, 'Withdraw: Phase must be Staking');
        require(userInfo[msg.sender].hasShare, 'Withdraw: User not eligible');

        uint256 amount = TOKENS_PER_SHARE - userInfo[msg.sender].tokensClaimed;
        require(amount > 0, 'Withdraw: No pending token');

        x2y2Token.safeTransfer(msg.sender, amount);
        userInfo[msg.sender].tokensClaimed = TOKENS_PER_SHARE;
        emit EmergencyWithdraw(msg.sender, amount);
    }

    // withdraw presale ETH & remaining token, update to saleover
    function withdrawPresale() external onlyOwner nonReentrant {
        require(currentPhase == SalePhase.Sale, 'Owner: Phase must be Sale');

        uint256 balance = address(this).balance;
        Address.sendValue(payable(msg.sender), balance);

        uint256 returnAmount = x2y2Token.balanceOf(address(this)) -
            totalShareSold *
            TOKENS_PER_SHARE;
        if (returnAmount > 0) {
            x2y2Token.safeTransfer(msg.sender, returnAmount);
        }

        currentPhase = SalePhase.SaleOver;
        emit NewPhase(SalePhase.SaleOver);
    }

    function updatePhaseToStaking() external onlyOwner nonReentrant {
        require(currentPhase == SalePhase.SaleOver, 'Owner: Phase must be SaleOver');
        currentPhase = SalePhase.Staking;
        emit NewPhase(SalePhase.Staking);
    }

    function treasuryWithdraw(uint256 amount) external onlyOwner nonReentrant {
        require(
            block.number > stakingEndBlock + safetyBufferInBlocks,
            'Owner: staking have not ended yet'
        );
        require(amount > 0, 'Owner: withdraw > 0');

        tokenRewardTreasuryWithdrawn += amount;
        rewardToken.safeTransfer(msg.sender, amount);
        emit TreasuryWithdraw(amount);
    }
}
ITokenStaked.sol 6 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface ITokenStaked {
    function getTotalStaked() external view returns (uint256);
}
Address.sol 217 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Address.sol)

pragma solidity ^0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}
Strings.sol 67 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _HEX_SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }
}
Ownable.sol 76 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);
}
ReentrancyGuard.sol 63 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}
ECDSA.sol 234 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.0;

import "../Strings.sol";

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    enum RecoverError {
        NoError,
        InvalidSignature,
        InvalidSignatureLength,
        InvalidSignatureS,
        InvalidSignatureV
    }

    function _throwError(RecoverError error) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert("ECDSA: invalid signature");
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert("ECDSA: invalid signature length");
        } else if (error == RecoverError.InvalidSignatureS) {
            revert("ECDSA: invalid signature 's' value");
        } else if (error == RecoverError.InvalidSignatureV) {
            revert("ECDSA: invalid signature 'v' value");
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature` or error string. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
        // Check the signature length
        // - case 65: r,s,v signature (standard)
        // - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else if (signature.length == 64) {
            bytes32 r;
            bytes32 vs;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            assembly {
                r := mload(add(signature, 0x20))
                vs := mload(add(signature, 0x40))
            }
            return tryRecover(hash, r, vs);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength);
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, signature);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address, RecoverError) {
        bytes32 s;
        uint8 v;
        assembly {
            s := and(vs, 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
            v := add(shr(255, vs), 27)
        }
        return tryRecover(hash, v, r, s);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
     *
     * _Available since v4.2._
     */
    function recover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, r, vs);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address, RecoverError) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
            return (address(0), RecoverError.InvalidSignatureS);
        }
        if (v != 27 && v != 28) {
            return (address(0), RecoverError.InvalidSignatureV);
        }

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        if (signer == address(0)) {
            return (address(0), RecoverError.InvalidSignature);
        }

        return (signer, RecoverError.NoError);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, v, r, s);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from a `hash`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
        // 32 is the length in bytes of hash,
        // enforced by the type signature above
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from `s`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
    }

    /**
     * @dev Returns an Ethereum Signed Typed Data, created from a
     * `domainSeparator` and a `structHash`. This produces hash corresponding
     * to the one signed with the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
     * JSON-RPC method as part of EIP-712.
     *
     * See {recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
    }
}
SafeERC20.sol 99 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

Read Contract

MAX_SHARES 0x3e8ff57b → uint256
PRICE_PER_SHARE 0xdf1fb713 → uint256
STAKING_PERIOD_IN_BLOCKS 0x1c9b1736 → uint256
TOKENS_PER_SHARE 0xb9bd4730 → uint256
TOTAL_RAISING_AMOUNT 0x8da1a403 → uint256
TOTAL_TOKEN_AMOUNT 0xfc976827 → uint256
currentPhase 0x055ad42e → uint8
getTotalStaked 0x0917e776 → uint256
owner 0x8da5cb5b → address
pendingReward 0xf40f0f52 → uint256
pendingRewards 0xce9d16fe → uint256
pendingTokens 0xc031a66f → uint256
rewardToken 0xf7c618c1 → address
safetyBufferInBlocks 0xca90c8c6 → uint256
signers 0x736c0d5b → bool
stakingEndBlock 0x0a122c8a → uint256
stakingStartBlock 0xec2fc051 → uint256
tokenRewardTreasuryWithdrawn 0x2ce9785f → uint256
totalRewardDistributed 0x30188ee8 → uint256
totalShareSold 0x8337c3c0 → uint256
totalTokensSold 0x63b20117 → uint256
userInfo 0x1959a002 → uint256, uint256, bool
x2y2Token 0xebde5ee6 → address

Write Contract 10 functions

These functions modify contract state and require a wallet transaction to execute.

deposit 0x7267994e
uint8 v
bytes32 r
bytes32 s
emergencyWithdraw 0xdb2e21bc
No parameters
harvest 0x4641257d
No parameters
renounceOwnership 0x715018a6
No parameters
transferOwnership 0xf2fde38b
address newOwner
treasuryWithdraw 0x65267139
uint256 amount
updatePhaseToStaking 0x194bf554
No parameters
updateSigners 0x350b2369
address[] toAdd
address[] toRemove
withdraw 0x3ccfd60b
No parameters
withdrawPresale 0x6df5ee2b
No parameters

Recent Transactions

No transactions found for this address