Betarena / bta_smart

BTA Bitarena Smart Contract
GNU General Public License v3.0
0 stars 0 forks source link

BTA Manage fees amount #6

Closed jonsnowpt closed 3 days ago

jonsnowpt commented 1 year ago

๐Ÿ“ Issue Description

Add a function to the smart contract that allows for changing the total amount for the buy and sell fees, and convert them in real-time using an Oracle like Chainlink on the Polygon Network.


Transaction Fees

Transaction fees are currently set at a fixed rate, but will be updated to allow for changing the total amount for the buy and sell fees.

Action Transaction Fees
Buy Fixed fee $0.50
Sell Fixed fee $1.00

Transaction fees will be sent to the BTA Owner's address. Project addresses are excluded from fees.


Chainlink Oracle

A Chainlink Oracle will be used to convert the value of fees from BTA to MATIC in real-time.


Code Example

The following code snippet shows how to add a function to change the total amount for the buy and sell fees, and convert them in real-time using a Chainlink Oracle:



import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

contract MyContract is ERC20 {
    uint256 public buyFeeAmount;
    uint256 public sellFeeAmount;
    address public oracle;
    AggregatorV3Interface internal priceFeed;

    constructor() {
        // Set up Chainlink Oracle
        oracle = 0x8A753747A1Fa494EC906cE90E9f37563A8AF630e;
        priceFeed = AggregatorV3Interface(oracle);

        // Set initial buy and sell fees
        buyFeeAmount = 100; // 1 BTA = 0.01 MATIC
        sellFeeAmount = 200; // 1 BTA = 0.02 MATIC
    }

    function setBuyFeeAmount(uint256 _buyFeeAmount) external onlyOwner {
        buyFeeAmount = _buyFeeAmount;
    }

    function setSellFeeAmount(uint256 _sellFeeAmount) external onlyOwner {
        sellFeeAmount = _sellFeeAmount;
    }

    function getMaticPrice() public view returns (uint256) {
        (, int256 price, , , ) = priceFeed.latestRoundData();
        return uint256(price) * 10 ** 10; // Chainlink returns price in 18 decimal places, we need 10 decimal places
    }

    function calculateFee(uint256 amount) internal view returns (uint256) {
        uint256 maticPrice = getMaticPrice();
        uint256 btaPrice = 10 ** 18 / maticPrice;
        return amount * btaPrice * (buyFeeAmount + sellFeeAmount) / 10000; // Calculate fees in MATIC
    }

    function transfer(address recipient, uint256 amount) public override returns (bool) {
        uint256 fee = calculateFee(amount);
        _transfer(_msgSender(), recipient, amount - fee);
        _transfer(_msgSender(), owner(), fee);
        return true;
    }
}

In this code example, the setBuyFeeAmount and setSellFeeAmount functions allow for changing the total amount for the buy and sell fees. The getMaticPrice function uses the Chainlink Oracle to get the current price of MATIC in USD. The calculateFee function converts the BTA fees to MATIC using the current price of MATIC in USD. Finally,

migbash commented 2 months ago

๐ŸŸง UPDATE

Discontinued use of chainlink in favour of the fiat based liquidity pool.