MoroRouterV2

The Moromoro Router is the main smart contract for executing swaps on supported networks.

Contract Addresses

HyperEVM

MoroRouter 2.0

Contract Interface

The router contract provides the following main functions:

swap()

Executes a token swap based on the quote provided by the SDK.

Function Signature:

function swap(
    address swapAddress,
    bytes calldata data,
    address depositAddress,
    address srcToken,
    uint256 amountIn,
    address destToken,
    uint256 minAmountOut,
    address receiver,
    uint256 partnerId,
    uint256 metadata
) external payable returns (uint256 amountOut)

Parameters:

  • swapAddress: The DEX wrapper contract address to execute the swap

  • data: Encoded swap data from the quote

  • depositAddress: The deposit address for the specific DEX

  • srcToken: Source token address (0x5555...5555 for native HYPE)

  • amountIn: Amount of source tokens to swap

  • destToken: Destination token address

  • minAmountOut: Minimum acceptable output amount (for slippage protection)

  • receiver: Address to receive the output tokens

  • partnerId: Partner ID for profit sharing (use 0 if not applicable)

  • metadata: Reserved for future use (use 0)

Returns:

  • amountOut: Actual amount of destination tokens received

Usage Example

JavaScript/TypeScript

const { MoroBestRate } = require('@moromoro/moro-sdk')
const { ethers } = require('ethers')

// Import the router ABI
const moroRouterAbi = require('./MoroRouter_2_0.abi.json')
const MORO_ROUTER_ADDRESS = '0x3195cAd938d417703312246e376342C553FD4cC2'

// Setup provider and signer
const provider = new ethers.providers.JsonRpcProvider('https://rpc.hyperliquid.xyz/evm')
const signer = new ethers.Wallet(YOUR_PRIVATE_KEY, provider)

// Initialize SDK
const moroClient = new MoroBestRate(provider, 'hyperevm')

// Get quote
const src = '0x5555555555555555555555555555555555555555' // HYPE
const dest = '0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb' // USDT0
const amountIn = ethers.utils.parseUnits('10', 18)
const gasFee = ethers.BigNumber.from('5000000000')

const quote = await moroClient.getQuote(src, dest, amountIn, gasFee, { enableSplit: false })

// Add 1% slippage tolerance
const minAmountOut = ethers.BigNumber.from(quote.amountOut).mul(99).div(100)

// Create router contract instance
const moroContract = new ethers.Contract(MORO_ROUTER_ADDRESS, moroRouterAbi, signer)

// Execute swap
const swapTx = await moroContract.swap(
    quote.swapAddress,
    quote.data,
    quote.depositAddress,
    src,
    amountIn,
    dest,
    minAmountOut,
    signer.address,
    0, // Partner ID
    0  // Metadata
)

console.log(`Swap transaction: ${swapTx.hash}`)
await swapTx.wait()

Using SDK Helper Methods

const { MoroBestRate } = require('@moromoro/moro-sdk')
const { ethers } = require('ethers')

const provider = new ethers.providers.JsonRpcProvider('https://rpc.hyperliquid.xyz/evm')
const signer = new ethers.Wallet(YOUR_PRIVATE_KEY, provider)
const moroClient = new MoroBestRate(provider, 'hyperevm')

const src = '0x5555555555555555555555555555555555555555'
const dest = '0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb'
const amountIn = ethers.utils.parseUnits('10', 18)
const gasFee = ethers.BigNumber.from('5000000000')

// Get quote
const quote = await moroClient.getQuote(src, dest, amountIn, gasFee)

// Approve token if needed (skip for native token)
if (src !== '0x5555555555555555555555555555555555555555') {
    const approveTx = await moroClient.approve(signer, src, amountIn)
    await approveTx.wait()
}

// Execute swap with SDK helper
const minAmountOut = ethers.BigNumber.from(quote.amountOut).mul(99).div(100)
const swapTx = await moroClient.swap(
    signer,
    src,
    dest,
    amountIn,
    minAmountOut,
    quote
)

console.log(`Swap completed: ${swapTx.hash}`)

Slippage Protection

Always set an appropriate minAmountOut to protect against slippage:

// 1% slippage tolerance
const minAmountOut = quote.amountOut.mul(99).div(100)

// 0.5% slippage tolerance
const minAmountOut = quote.amountOut.mul(995).div(1000)

// 2% slippage tolerance
const minAmountOut = quote.amountOut.mul(98).div(100)

Gas Considerations

HyperEVM

Default gas price on HyperEVM is typically 5 gwei:

const gasFee = ethers.BigNumber.from('5000000000') // 5 gwei

Token Addresses

Native Token

On HyperEVM, the native token (HYPE) uses a special address:

const HYPE = '0x5555555555555555555555555555555555555555'

When swapping FROM native token, send the value with the transaction:

await moroContract.swap(...params, { value: amountIn })

Events

The router contract emits events for tracking swaps. Check the contract ABI for specific event signatures.

Security

  • Always verify the router contract address before interacting

  • Use appropriate slippage protection

  • Test with small amounts first

  • Ensure you understand the gas costs involved

Getting the ABI

1

From HyperEVM Scan

Find the ABI on the contract page on HyperEVM Scan: https://hyperevmscan.io/address/0x3195cAd938d417703312246e376342C553FD4cC2#code

2

From the contract repository

Look for the ABI in the contract repository (if available).

3

Download from the block explorer

Download the ABI directly from the block explorer.

See Also