Skip to content

Instantly share code, notes, and snippets.

@ilamanov
Created May 6, 2022 10:15
Show Gist options
  • Save ilamanov/a95434b08430a5137daef3f2c3878c4f to your computer and use it in GitHub Desktop.
Save ilamanov/a95434b08430a5137daef3f2c3878c4f to your computer and use it in GitHub Desktop.
contract BuyOptionForUNIToken {
address public constant UNIERC20Address = "0x....";
uint public price;
uint public endPeriod;
address public contractHolder;
constructor(uint _price, uint _endPeriod, address _contractHolder) {
price = _price;
endPeriod = _endPeriod;
contractHolder = _contractHolder;
}
function buy(uint amount) {
require(msg.sender == contractHolder, "You are not the contract holder");
require(msg.value >= (amount * price), "Not enough ETH");
require(block.timestamp < endPeriod, "Contract expired");
ERC20(UNIERC20Address).transfer(msg.sender, amount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment