// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract TENETToken {
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
address public owner;
AggregatorV3Interface internal priceFeed;
mapping(address => uint256) public balanceOf;
event Transfer(address indexed from, address indexed to, uint256 value);
event AvaxPriceUpdated(uint256 oldPrice, uint256 newPrice);
constructor() {
name = "Animoca";
symbol = "MOCA";
decimals = 18;
totalSupply = 10000000 * 10**uint256(decimals);
balanceOf[msg.sender] = totalSupply;
owner = msg.sender;
// Chainlink'in AVAX/USD fiyat feed'ini kullan
priceFeed = AggregatorV3Interface(0x0A77230d17318075983913bC2145DB16C7366156);
}
function getLatestAvaxPrice() public view returns (uint256) {
(,int price,,,) = priceFeed.latestRoundData();
// Price is typically in 8 decimal places, so adjust to 2 decimal places
return uint256(price) / 10**6;
}
function transfer(address _to, uint256 _avaxAmount) public returns (bool success) {
uint256 avaxPrice = getLatestAvaxPrice();
uint256 tokenAmount = (_avaxAmount * avaxPrice) / 0.01; // Adjusted for 0.01$
require(balanceOf[msg.sender] >= tokenAmount, "Insufficient balance");
require(_to != address(0), "Invalid address");
balanceOf[msg.sender] -= tokenAmount;
balanceOf[_to] += tokenAmount;
emit Transfer(msg.sender, _to, tokenAmount);
return true;
}
receive() external payable {
require(msg.value > 0, "No AVAX sent");
uint256 avaxPrice = getLatestAvaxPrice();
uint256 tokenAmount = (msg.value * avaxPrice) / 0.01; // Adjusted for 0.01$
require(balanceOf[owner] >= tokenAmount, "Insufficient tokens in contract");
balanceOf[owner] -= tokenAmount;
balanceOf[msg.sender] += tokenAmount;
emit Transfer(owner, msg.sender, tokenAmount);
payable(owner).transfer(msg.value);
}
}