Split trading
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.
const { MoroBestRate } = require('@moromoro/moro-sdk')
const { ethers } = require('ethers')
async function splitTradeExample() {
const provider = new ethers.providers.JsonRpcProvider(
'https://rpc.hyperliquid.xyz/evm'
)
const signer = new ethers.Wallet(process.env.PRIVATE_KEY, provider)
const moroClient = new MoroBestRate(provider, 'hyperevm')
const HYPE = '0x5555555555555555555555555555555555555555'
const USDT = '0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb'
const amountIn = ethers.utils.parseUnits('100', 18) // Large amount
const gasPrice = ethers.BigNumber.from('5000000000')
// Get quote with split enabled
const quote = await moroClient.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 path
quote.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 trade
const minOut = ethers.BigNumber.from(quote.amountOut).mul(99).div(100)
const tx = await moroClient.swap(
signer,
HYPE,
USDT,
amountIn,
minOut,
quote
)
await tx.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.
Handling Split Trade Failures
Error handling specific to split trades.
Analyzing Split Efficiency
Analyze whether split trading provides value.
When to Use Split Trading
General guidelines:
See Also
Simple Swap Examples
Multi-Chain Examples