Split trading allows the SDK to split your trade across multiple DEXs to achieve better rates. This is particularly useful for large trades where a single DEX might not have sufficient liquidity.
Basic Split Trade
Enable split trading for potentially better rates.
basic-split.js
const{MoroBestRate}=require('@moromoro/moro-sdk')const{ethers}=require('ethers')asyncfunctionsplitTradeExample(){constprovider=newethers.providers.JsonRpcProvider('https://rpc.hyperliquid.xyz/evm' )constsigner=newethers.Wallet(process.env.PRIVATE_KEY,provider)constmoroClient=newMoroBestRate(provider,'hyperevm')constHYPE='0x5555555555555555555555555555555555555555'constUSDT='0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb'constamountIn=ethers.utils.parseUnits('100',18) // Large amountconstgasPrice=ethers.BigNumber.from('5000000000') // Get quote with split enabledconstquote=awaitmoroClient.getQuote(HYPE,USDT,amountIn,gasPrice,{enableSplit:true}// Enable split trading )console.log('Quote type:',quote.type)if (quote.type==='split') {console.log('Trade will be split across',quote.paths.length,'paths')console.log('Volume distribution:',quote.volumns) // Display each pathquote.paths.forEach((path,i)=>{console.log(`\nPath ${i+1}:`)console.log('- Volume:',quote.volumns[i] +'%')console.log('- Routes:',path.routes.map(r=>r.name).join(' -> '))console.log('- Tokens:',path.tokens.length)})} // Execute split tradeconstminOut=ethers.BigNumber.from(quote.amountOut).mul(99).div(100)consttx=awaitmoroClient.swap(signer,HYPE,USDT,amountIn,minOut,quote )awaittx.wait()console.log('✓ Split trade completed')}splitTradeExample()
Comparing Single vs Split Trade
Compare rates between single path and split trading.
Inspecting Split Paths
Detailed inspection of split trade paths.
Large Trade with Split
Example of a large trade benefiting from split trading.
Optimal Split Configuration
Customize split trading parameters for better performance.