Skip to content

Instantly share code, notes, and snippets.

@inspexAuditor
Created March 31, 2022 03:54
Show Gist options
  • Save inspexAuditor/0fdf0ffff136296317137f82f9ecfe61 to your computer and use it in GitHub Desktop.
Save inspexAuditor/0fdf0ffff136296317137f82f9ecfe61 to your computer and use it in GitHub Desktop.
//SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "./GOVToken.sol";
import "./Vault.sol";
contract ICOGov is ReentrancyGuard {
GOVToken public newToken;
Vault public vault;
address treasury;
uint256 public tokenPrice;
constructor(GOVToken _newToken, Vault _vault, address _treasury, uint256 _tokenPricePerToken) {
newToken = _newToken;
vault = _vault;
treasury = _treasury;
tokenPrice = _tokenPricePerToken; // price / token
}
function buyToken(uint256 _vaultTokenAmount) external nonReentrant {
// Get token value from share
uint256 value = vault.shareToAmount(_vaultTokenAmount);
// Get number of token from value
uint256 tokenAmount = value / tokenPrice;
vault.transferFrom(msg.sender, treasury, _vaultTokenAmount);
newToken.mint(msg.sender, tokenAmount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment