IERC20 public stablecoin;
IERC20 public INT;
uint public exchangeRate;
address public contractAddress;
mapping(address => bool) public authorizedAddresses;
event Exchange(address indexed user, uint stblAmount, uint intAmount);
event AuthorizationChanged(address indexed authorizedAddress, bool isAuthorized);
constructor(
IERC20 _stablecoin,
IERC20 _INT,
uint _initialRate,
address _ownerAddress,
address _contractAddress
) {
stablecoin = _stablecoin;
INT = _INT;
exchangeRate = _initialRate;
contractAddress = _contractAddress;
authorizedAddresses[_ownerAddress] = true;
}
modifier onlyAuthorized() {
require(authorizedAddresses[msg.sender], "Unauthorized");
_;
}
function setExchangeRate(uint newRate) external onlyOwner {
exchangeRate = newRate;
}
function authorizeAddress(address _address, bool _isAuthorized) external onlyOwner {
authorizedAddresses[_address] = _isAuthorized;
emit AuthorizationChanged(_address, _isAuthorized);
}
function exchangeStablecoinForINT(uint stblAmount) external onlyAuthorized {
uint intAmount = (stblAmount * exchangeRate) / 10**18;
require(intAmount > 0, "Amount too low to exchange");
stablecoin.safeTransferFrom(msg.sender, contractAddress, stblAmount);
INT.safeTransfer(msg.sender, intAmount);
emit Exchange(msg.sender, stblAmount, intAmount);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract LTVexchange is Ownable {
using SafeERC20 for IERC20;
}