The Ribe Token Standard

Information for developers building on the platform

A Ribe Token contract keeps track of fungible tokens just like an ERC20 token: any one token is exactly equal to any other token; no tokens have special rights or behavior associated with them. However, any token using the Ribe Token Standard can benefit from the Ribe Swap features such as anti MEV bots mechanisms, built-in DAI and ETH buyback and more.

This page provides a Ribe Token example and the API Reference. On the API Reference you’ll find detailed information on their properties and usage.

// SPDX-License-Identifier: MIT
pragma solidity 0.8.14;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

abstract contract RibeToken is ERC20
{
    constructor(string memory name, string memory symbol) ERC20(name, symbol){}
    function buyFeePercentage() external view virtual returns(uint);
    function onBuyFeeCollected(address tokenAddress, uint amount) external virtual;
    function sellFeePercentage() external view virtual returns(uint);
    function onSellFeeCollected(address tokenAddress, uint amount) external virtual;
}

contract MyToken is RibeToken
{
    uint public buyFee = 150;
    uint public sellFee = 200;
    address feeCollector;

    constructor (string memory name, string memory symbol, address _feeCollector) RibeToken(name, symbol)
    {
        _mint(msg.sender, 1_000_000 ether);
        feeCollector = _feeCollector;
    }

    function buyFeePercentage() external view override returns(uint)
    {
        return buyFee;
    }

    function sellFeePercentage() external view override returns(uint)
    {
        return sellFee;
    }

    function onBuyFeeCollected(address tokenAddress, uint amount) external override
    {
        IERC20(tokenAddress).transfer(feeCollector, amount);
    }

    function onSellFeeCollected(address tokenAddress, uint amount) external override
    {
        IERC20(tokenAddress).transfer(feeCollector, amount);
    }
}

Notice that we set a 1.5% buy fee and a 2% sell fee. Also in this case, the token recipient is the deployer but all of this can be edited on the override functions.

And that's it! Your token is ready to be traded on Ribe Swap.

All the RibeToken interface functions are virtual so you can implement your token with your own features fully compatible with Ribe Swap.

API Reference

  • buyFeePercentage()

    Returns a uint256 representing the buy fee percentage with two decimal order (example: 15 means 0.15% buy fee)

  • sellFeePercentage()

    Returns a uint256 representing the sell fee percentage with two decimal order (example: 15 means 0.15% sell fee)

  • onBuyFeeCollected(address tokenAddress, uint amount)

    Callback returning the address and the amount of the base tokens collected as a result of a buy. The base tokens can be DAI and wETH but more can be added on the future. This function is a good place to distribute all the funds to a wallet or a contract able to retrieve the funds.

  • onSellFeeCollected(address tokenAddress, uint amount)

    Callback returning the address and the amount of the base tokens collected as a result of a sell. The base tokens can be DAI and wETH but more can be added on the future. This function is a good place to distribute all the funds to a wallet or a contract able to retrieve the funds.

Remember to transfer all the recieved amount from onBuyFeeCollected and onSellFeeCollected to a normal wallet (not a contract) or to a contract able to retrive generic ERC20 tokens.

Last updated