Open 123456788940 opened 1 year ago
LTVexchange is a Solidity smart contract that allows users to exchange a stablecoin (STBL) for a custom token (INT) at a predefined exchange rate. The contract is designed to be owned by an external account (EOA) and allows for authorization of specific addresses to perform token exchanges.
Before using LTVexchange, ensure you have the following:
Deploy LTVexchange by specifying the following constructor parameters:
_stablecoin
: The address of the STBL token contract (IERC20)._INT
: The address of the INT token contract (IERC20)._initialRate
: The initial exchange rate (1 STBL to X INT)._ownerAddress
: The address of the contract owner (EOA)._contractAddress
: The address of the deployed contract.Once deployed, the owner address specified during deployment will be automatically authorized to perform redemptions.
setExchangeRate
function. This allows for adjusting the conversion rate between STBL and INT as needed.authorizeAddress
function.exchangeStablecoinForINT
function to exchange STBL for INT:
stblAmount
of STBL tokens you wish to exchange.intAmount
is greater than zero.Exchange
event will be emitted, indicating the successful token exchange.Exchange
: Triggered when tokens are exchanged, providing details of the exchange.AuthorizationChanged
: Fired when an address is authorized or unauthorized.This contract is released under the MIT License. See the SPDX-License-Identifier in the contract file for details.
Feel free to customize and expand this README document to include additional details or instructions specific to your project or use case.
// 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 RedeemContract 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 intAmount, uint stableAmount);
event AuthorizationChanged(address indexed authorizedAddress, bool isAuthorized);
constructor(
IERC20 _stablecoin,
IERC20 _INT,
uint256 _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(uint256 newRate) external onlyOwner {
exchangeRate = newRate;
}
function authorizeAddress(address _address, bool _isAuthorized) external onlyOwner {
authorizedAddresses[_address] = _isAuthorized;
emit AuthorizationChanged(_address, _isAuthorized);
}
function redeemSTBL(uint256 intAmount) external onlyAuthorized {
uint256 stblAmount = (intAmount * exchangeRate) / 10**18;
require(stblAmount > 0, "Amount too low");
INT.safeTransferFrom(msg.sender, contractAddress, intAmount);
stablecoin.safeTransfer(msg.sender, stblAmount);
emit Exchange(msg.sender, intAmount, stblAmount);
}
}
RedeemContract is a Solidity smart contract that facilitates the exchange of a custom token (INT) for a stablecoin (STBL) at a predefined exchange rate. The contract is designed to be owned by an external account (EOA) and allows for authorization of specific addresses to perform token redemptions.
Before using RedeemContract, ensure you have the following:
Deploy RedeemContract by specifying the following constructor parameters:
_stablecoin
: The address of the STBL token contract (IERC20)._INT
: The address of the INT token contract (IERC20)._initialRate
: The initial exchange rate (1 STBL to X INT)._ownerAddress
: The address of the contract owner (EOA)._contractAddress
: The address of the deployed contract.Once deployed, the owner address specified during deployment will be automatically authorized to perform redemptions.
setExchangeRate
function. This allows for adjusting the conversion rate between STBL and INT as needed.authorizeAddress
function.redeemSTBL
function to exchange INT for STBL:
intAmount
of INT tokens you wish to exchange.stblAmount
is greater than zero.Exchange
event will be emitted, indicating the successful token exchange.Exchange
: Triggered when tokens are exchanged, providing details of the exchange.AuthorizationChanged
: Fired when an address is authorized or unauthorized.This contract is released under the MIT License. See the SPDX-License-Identifier in the contract file for details.
Feel free to customize and expand this README document to include additional details or instructions specific to your project or use case.
// SPDX-License-Identifier: MIT pragma solidity ^0.8; import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract lockBINT { mapping(address => bool) public isLocked; mapping(address => uint) public lockPeriods; IERC20 public bINT;
address public owner;
constructor(address _tokenAddress) {
bINT = IERC20(_tokenAddress);
owner = msg.sender;
}
modifier onlyOwner(){
require(msg.sender == owner, "Only owner can call this function");
_;
}
function lock() external {
isLocked[msg.sender] = !isLocked[msg.sender];
}
function setLockPeriods(uint period) external {
require(period >= 1 && period <= 6, "The period should come as per the logic");
lockPeriods[msg.sender] = period;
}
function distribute() external onlyOwner {
uint lockMultiplier = lockPeriods[msg.sender];
require(lockMultiplier > 0, "lockMultiplier is not set");
// Calculate the multiplier-adjusted token amount
uint tokenBalance = bINT.balanceOf(address(this)); // Get the contract's token balance
uint initialTokenAmount = 100; // Initial token amount
uint multiplier = lockMultiplier; // Use lockMultiplier as the multiplier
// Calculate the total tokens to distribute with the multiplier
uint totalTokensToDistribute = initialTokenAmount * multiplier;
// Ensure the contract has enough tokens to distribute
require(tokenBalance >= totalTokensToDistribute, "Insufficient tokens in the contract");
// Transfer the tokens to the owner with the multiplier adjustment
require(bINT.transfer(msg.sender, totalTokensToDistribute), "Transfer failed");
}
}
Introduction
Functions
lock()
setLockPeriods(uint period)
distribute()
Usage
Modifiers
onlyOwner()
Example Scenario
Considerations
Installation and Deployment
Security Considerations
Conclusion
The lockBINT
smart contract is designed to provide token locking functionality with multipliers based on lock periods. Users can lock their tokens for a specified duration, and when distributing tokens, they receive an amount of bINT
tokens with a multiplier applied.
The contract interacts with the bINT
token, which should be provided during contract deployment.
The contract owner, initially set as the deployer of the contract, has control over the distribution of tokens.
lock()
setLockPeriods(uint period)
distribute()
Users can lock and unlock their tokens by calling the lock()
function.
Users can set their desired lock period using the setLockPeriods(uint period)
function.
The contract owner can call the distribute()
function to receive tokens with a multiplier based on their lock period.
onlyOwner()
This modifier restricts certain functions to be called only by the contract owner.
Suppose a user sets a lock period of 4 and calls distribute()
. They will receive 400 bINT
tokens (4 times the initial amount) based on the lock period multiplier.
The multiplier for token conversion is based on the lock period. Ensure that users understand the multiplier logic.
The lock period should be within the range of 1 to 6. Users must adhere to this constraint.
Deploy the contract by providing the address of the bINT
token.
Users can interact with the contract by calling the functions described above.
Ensure that the contract owner's address is secure, as they have control over token distribution.
Consider implementing a reentrancy guard in the contract to prevent reentrancy attacks.
The lockBINT
smart contract provides a flexible token locking mechanism with multipliers based on lock periods, enabling users to participate in governance or other activities within the ecosystem.
This document provides an overview of the lockBINT
smart contract, its functions, usage, considerations, and deployment instructions. It is essential to review and understand the contract's behavior before interacting with it.
// 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;
}