Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LTV #45

Open
123456788940 opened this issue Sep 7, 2023 · 5 comments
Open

LTV #45

123456788940 opened this issue Sep 7, 2023 · 5 comments
Labels
review Review is used by var/core contributor in order to finalise it before even deploytestnet function

Comments

@123456788940
Copy link
Collaborator

123456788940 commented Sep 7, 2023

// 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
Copy link
Collaborator Author

123456788940 commented Sep 7, 2023

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

  • Exchange STBL tokens for INT tokens at a specified exchange rate.
  • Only authorized addresses can redeem tokens.
  • The owner can update the exchange rate and authorize/unauthorize addresses.

Prerequisites

Before using LTVexchange, ensure you have the following:

  • Ethereum wallet with access to both STBL and INT tokens.
  • Knowledge of the current exchange rate (1 STBL to X INT).

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

  • Only the owner can update the exchange rate using the setExchangeRate function. This allows for adjusting the conversion rate between STBL and INT as needed.

Authorizing Addresses

  • The owner can authorize or unauthorize addresses to perform token redemptions using the authorizeAddress function.

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

  • The contract emits two events for transparency:
    1. Exchange: Triggered when tokens are exchanged, providing details of the exchange.
    2. AuthorizationChanged: Fired when an address is authorized or unauthorized.

Security Considerations

  • Ensure that only trusted addresses are authorized to perform redemptions.
  • Be cautious when updating the exchange rate, as it affects the conversion value.

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 123456788940 added the review Review is used by var/core contributor in order to finalise it before even deploytestnet function label Sep 7, 2023
@123456788940
Copy link
Collaborator Author

123456788940 commented Sep 11, 2023

// 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
Copy link
Collaborator Author

123456788940 commented Sep 11, 2023

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

  • Exchange INT tokens for STBL tokens at a specified exchange rate.
  • Only authorized addresses can redeem tokens.
  • The owner can update the exchange rate and authorize/unauthorize addresses.

Prerequisites

Before using RedeemContract, ensure you have the following:

  • Ethereum wallet with access to both INT and STBL tokens.
  • Knowledge of the current exchange rate (1 STBL to X INT).

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

  • Only the owner can update the exchange rate using the setExchangeRate function. This allows for adjusting the conversion rate between STBL and INT as needed.

Authorizing Addresses

  • The owner can authorize or unauthorize addresses to perform token redemptions using the authorizeAddress function.

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

  • The contract emits two events for transparency:
    1. Exchange: Triggered when tokens are exchanged, providing details of the exchange.
    2. AuthorizationChanged: Fired when an address is authorized or unauthorized.

Security Considerations

  • Ensure that only trusted addresses are authorized to perform redemptions.
  • Be cautious when updating the exchange rate, as it affects the conversion value.

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
Copy link
Collaborator Author

123456788940 commented Sep 11, 2023

// 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
Copy link
Collaborator Author

123456788940 commented Sep 11, 2023

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()

  • Allows users to toggle the lock status of their address, locking and unlocking tokens.

setLockPeriods(uint period)

  • Allows users to set the lock period for their address. The lock period should be between 1 and 6.

distribute()

  • Can only be called by the contract owner.
  • Calculates the total tokens to distribute based on the user's lock period.
  • Transfers tokens with a multiplier to the owner's address.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review Review is used by var/core contributor in order to finalise it before even deploytestnet function
Projects
None yet
Development

No branches or pull requests

1 participant