LogoLogo
  • Welcome to FlowX Finance
    • 🔮Protocol Overview
    • 🕶️Our Advantages
    • 🚩Getting Started
    • 🗺️Roadmap
  • PROTOCOL
    • ⚖️Swap
    • 🛞DEX Aggregator
    • 🎰Lucky Swap
    • ⚗️Liquidity Pools
    • 🎚️Position Management
    • 🪣Farming as a Service
    • 💰Earning Protocol Fee
    • 🏁Trading Competition
    • 💬Referral
  • REFERENCES
    • 🛡️Audit
    • 🖼️Media Kit
    • 🤝Partners
    • 🧰SDK
    • 🖥️Aggregator Widget
  • Developer
    • Overview
    • FlowX SDK
      • Getting Started
      • Retrieve coin
      • Swap Aggregator
      • AMM Management
        • Pool Management
        • Position Management
      • CLMM Management
        • Pool Management
        • Position Management
      • Auto Invest
      • Limit Order
    • FlowX Widget
  • Tokenomics
    • 🚇FLX Token
    • 🚊xFLX Governance Token
  • 🔦Guide
    • How to add Liquidity V3
  • Privacy & Terms
    • Risk Disclaimer
    • Terms of Service
Powered by GitBook

App

  • Aggregator
  • Liquidity Hub
  • Stake

Connect with us

  • X
  • Discord
  • Telegram Group

Find us

  • DefiLlama
  • Dexscreener
  • Coingecko

© 2025 FlowX Finance

On this page
  • Get Swap Router
  • Build Transaction for aggregator swap

Was this helpful?

  1. Developer
  2. FlowX SDK

Swap Aggregator

Get Swap Router

WARNING: amountOut FROM QUOTE WHEN USE WITH COMMISSION ONLY FOR DISPLAY, NOT FOR CALCULATE ONCHAIN.

To find best route for swap

const quoter = new AggregatorQuoter('mainnet');
const params: AggregatorQuoterQueryParams = {
  tokenIn: '0x2::sui::SUI',
  tokenOut: '0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN',
  amountIn: '1000000000',
  includeSources: null, //optional
  excludeSources: null, //optional
  commission: null, //optional, and will be explain later
  maxHops: null, //optional: default and max is 3
  splitDistributionPercent: null, //optional: default 1 and max 100
  excludePools: null, //optional: list pool you want excude example: 0xpool1,0xpool2 
};

const routes = await quoter.getRoutes(params);

Build Transaction for aggregator swap

Normal case if you want fast swap

const tradeBuilder = new TradeBuilder(NETWORK.MAINNET, routes); //routes get from quoter
const tx = tradeBuilder
  .sender('0xSenderAddress') //Optional if you want pass coin later
  .slippage((1 / 100) * 1e6) // Slippage 1%
  .commission(null) // Optional: commission will be explain later
  .build()
  .buildTransaction({ client });

Return coin for later use

const tradeBuilder = new TradeBuilder(NETWORK.MAINNET, routes); //routes get from quoter
const tx = new Transaction();
const trade = tradeBuilder
  .sender('0xSenderAddress') //Optional if you want pass coin later
  .slippage((1 / 100) * 1e6) // Slippage 1%
  .commission(null) // Optional: commission will be explain later
  .build();
const coinOut = trade.swap({ client, tx }) 

Commission

The Commission class represents a commission configuration for transactions, defining the partner, commission type, and value. It includes methods for computing the commission amount based on the specified type.

const commission = new Commission('0xPartnerAddress', new Coin('0x2::sui:SUI'), CommissionType.PERCENTAGE, '500', true);

if CommissionType.PERCENTAGE then value should be input 1/100 * 1e6 it is example of 1% if CommissionType.FLAT then value should be the amount of token you want to fee include decimals Then you should pass commission variable to both tradeBuilder and getRoutes for exact values

if directTransfer= true then commission will transfer directly to partner address, else you need go to contract and claim partner fee later

The coinpass in commission that mean coin you want collect fee in transaction, for example, if you pass SUI is coin collect fee, when you swap SUI -> USDC or USDC->SUI you will collect SUI is a fee, but if you swap FLX->USDC and USDC->FLX you receive nothing and coin is SUI, then you SHOULD NOT pass commission to TradeBuilder

Usage

If const routes = await quoter.getRoutes(params)include commssion then amount will return amount that include commission

if trade = tradeBuilder.commission(commission) then the transaction will include commission, if not pass commission in tradeBuilder then transaction will execute without commission

PreviousRetrieve coinNextAMM Management

Last updated 1 month ago

Was this helpful?