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
  • Tokenomics
    • ๐Ÿš‡FLX Token
    • ๐ŸšŠxFLX Governance Token
  • CONTRACT
    • ๐Ÿ“„GenesiX Farming
    • ๐Ÿ“„Swap
  • ๐Ÿ”ฆGuide
    • How to add Liquidity V3
  • REFERENCES
    • ๐Ÿ›ก๏ธAudit
    • ๐Ÿ–ผ๏ธMedia Kit
    • ๐ŸคPartners
    • ๐ŸงฐSDK
    • ๐Ÿ–ฅ๏ธAggregator Widget
  • ARCHIVED
    • Claim Token
    • ๐ŸงชGenesiX Farming
  • 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
  • Privacy & Terms
    • Risk Disclaimer
    • Terms of Service
  • Social
    • Website
    • Twitter
    • Telegram Channel
    • Discord
Powered by GitBook
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 11 days ago

Was this helpful?