How to Get a FewToken Address via FewFactory

📘 Example Guide: How to Get a FewToken Address via FewFactory

In Ring Swap, all tokens used in liquidity pools and swaps are wrapped tokens (FewTokens). To maintain compatibility with Uniswap V2 across multiple blockchain networks, Ring Protocol introduces a wrapping layer called Few Protocol. This layer ensures that all original ERC20 tokens are wrapped into their respective FewToken counterparts before being added to liquidity pools or used in swaps.


🧩 Why FewTokens?

  • All tokens in Ring Swap are wrapped ERC20 tokens (FewTokens).

  • When quoting token prices or building a swap path, you must use the FewToken address, not the original token.

  • Before using any token with Ring Swap, you must either:

    • Wrap the original token into its FewToken version, or

    • Fetch the FewToken address from FewFactory.


🔍 How to Fetch FewToken Address Using FewFactory

📘 FewFactory Interface

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

interface IFewFactory {
    event WrappedTokenCreated(address indexed originalToken, address wrappedToken, uint);

    function getWrappedToken(address originalToken) external view returns (address wrappedToken);
    function allWrappedTokens(uint) external view returns (address wrappedToken);
    function parameter() external view returns (address);
    function allWrappedTokensLength() external view returns (uint);
    function paused() external view returns (bool);
    function createToken(address originalToken) external returns (address wrappedToken);
}

🛠 Example: Solidity Code to Query FewToken

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

interface IFewFactory {
    function getWrappedToken(address originalToken) external view returns (address);
}

contract FewTokenHelper {
    address public fewFactory;

    constructor(address _fewFactory) {
        fewFactory = _fewFactory;
    }

    function getFewTokenAddress(address originalToken) external view returns (address wrappedToken) {
        return IFewFactory(fewFactory).getWrappedToken(originalToken);
    }
}

🧪 Use Case: Building a Swap Path

Suppose you want to swap from tokenA → USDC → tokenB via Ring Swap:

  1. Query FewTokens for each token:

fwTokenA = FewFactory.getWrappedToken(tokenA);
fwUSDC = FewFactory.getWrappedToken(USDC);
fwTokenB = FewFactory.getWrappedToken(tokenB);
  1. Construct the path:

path = [fwTokenA, fwUSDC, fwTokenB];
  1. Use the path with the Ring Swap router:

function swapExactTokensForTokens(
    uint amountIn,
    uint amountOutMin,
    address[] calldata path, // must be FewTokens
    address to,
    uint deadline
) external returns (uint[] memory amounts);

✅ Summary

  • Always use FewToken addresses in any interaction with Ring Swap (swaps, quotes, liquidity).

  • Use FewFactory to resolve the FewToken address of any original ERC20 token.

Last updated