Skip to content

LTV  #45

@123456788940

Description

@123456788940

// 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;

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);
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    reviewReview is used by var/core contributor in order to finalise it before even deploytestnet function

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions