WeuFoundDev / Governance-token-contracts

Governance contract of INPUT (INT) | A development based minting tokens for developers and researchers ecosystem.
GNU General Public License v3.0
2 stars 0 forks source link

LTV #45

Open 123456788940 opened 1 year ago

123456788940 commented 1 year ago

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

}

123456788940 commented 1 year ago

LTVexchange

Overview

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.

Key Features

Prerequisites

Before using LTVexchange, ensure you have the following:

Usage

Deployment

  1. 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.
  2. Once deployed, the owner address specified during deployment will be automatically authorized to perform redemptions.

Updating Exchange Rate

Authorizing Addresses

Token Exchange

  1. Ensure your address is authorized by the contract owner.
  2. Use the exchangeStablecoinForINT function to exchange STBL for INT:
    • Input the stblAmount of STBL tokens you wish to exchange.
    • Ensure that the calculated intAmount is greater than zero.
    • The contract will transfer STBL tokens from your address to the contract and transfer INT tokens to your address.
    • An Exchange event will be emitted, indicating the successful token exchange.

Events

Security Considerations

License

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.

123456788940 commented 1 year ago

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

}

123456788940 commented 1 year ago

RedeemContract

Overview

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.

Key Features

Prerequisites

Before using RedeemContract, ensure you have the following:

Usage

Deployment

  1. 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.
  2. Once deployed, the owner address specified during deployment will be automatically authorized to perform redemptions.

Updating Exchange Rate

Authorizing Addresses

Token Redemption

  1. Ensure your address is authorized by the contract owner.
  2. Use the redeemSTBL function to exchange INT for STBL:
    • Input the intAmount of INT tokens you wish to exchange.
    • Ensure that the calculated stblAmount is greater than zero.
    • The contract will transfer INT tokens from your address to the contract and transfer STBL tokens to your address.
    • An Exchange event will be emitted, indicating the successful token exchange.

Events

Security Considerations

License

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.

123456788940 commented 1 year ago

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

}

123456788940 commented 1 year ago

Smart Contract Documentation: lockBINT

Table of Contents

  1. Introduction

    • Contract Purpose
    • Token Interaction
    • Contract Owner
  2. Functions

    • lock()
    • setLockPeriods(uint period)
    • distribute()
  3. Usage

    • Locking and Unlocking Tokens
    • Setting Lock Periods
    • Distributing Tokens
  4. Modifiers

    • onlyOwner()
  5. Example Scenario

    • Locking Tokens for a Lock Period
  6. Considerations

    • Token Conversion Multiplier
    • Lock Period Range
  7. Installation and Deployment

    • Contract Deployment
    • Interacting with the Contract
  8. Security Considerations

    • Ownership Control
    • Reentrancy Guard
  9. Conclusion


1. Introduction

Contract Purpose

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.

Token Interaction

The contract interacts with the bINT token, which should be provided during contract deployment.

Contract Owner

The contract owner, initially set as the deployer of the contract, has control over the distribution of tokens.

2. Functions

lock()

setLockPeriods(uint period)

distribute()

3. Usage

Locking and Unlocking Tokens

Users can lock and unlock their tokens by calling the lock() function.

Setting Lock Periods

Users can set their desired lock period using the setLockPeriods(uint period) function.

Distributing Tokens

The contract owner can call the distribute() function to receive tokens with a multiplier based on their lock period.

4. Modifiers

onlyOwner()

This modifier restricts certain functions to be called only by the contract owner.

5. Example Scenario

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.

6. Considerations

Token Conversion Multiplier

The multiplier for token conversion is based on the lock period. Ensure that users understand the multiplier logic.

Lock Period Range

The lock period should be within the range of 1 to 6. Users must adhere to this constraint.

7. Installation and Deployment

Contract Deployment

Deploy the contract by providing the address of the bINT token.

Interacting with the Contract

Users can interact with the contract by calling the functions described above.

8. Security Considerations

Ownership Control

Ensure that the contract owner's address is secure, as they have control over token distribution.

Reentrancy Guard

Consider implementing a reentrancy guard in the contract to prevent reentrancy attacks.

9. Conclusion

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.