LogoLogo
  • CrossCurve MetaLayer
    • βš™οΈWhat is CrossCurve MetaLayer
      • CrossCurve Consensus bridge
      • CrossCurve Pools v2
    • πŸ—ΊοΈRoadmap
      • 2024
  • 🏒CrossCurve DAO
    • Overview of CrossCurve DAO
    • Voting
    • Obtaining veEYWA and Calculating the Boost
    • Staking mechanics
    • NFTs
      • CrossCurve DAO NFT
      • EYWA NFT Collection
  • πŸ’ΌEarn with CrossCurve
    • Staking in CrossCurve
    • Providing Liquidity to CrossCurve Pools
    • Voting for Incentives
  • πŸ“–user documentation
    • πŸ›ΈMigration to Sonic
      • Why are we moving to Sonic
      • Sonic Upgrade Stages
      • Liquidity transfer from Fantom to Sonic
      • Sonic Incentives on CrossCurve MetaLayer
    • πŸ”ƒSwap interface
      • How to trade
      • Slippage settings
      • Routing
    • 🌊Liquidity Interface
      • Easy mode
      • via Curve (Balanced)
      • Liquidity provision use cases
        • Deposit
          • Easy mode (Imbalanced)
          • via Curve (Balanced)
        • Withdraw
          • Easy mode (Imbalanced)
          • via Curve (Balanced)
        • Curve Knowledge Database
          • Balanced liquidity provision
          • Guide to transferring CRV from Fantom chain to Ethereum mainnet
          • Disclamer
    • 🏒DAO
      • Locker Interface
      • Vote Interface
      • Incentives Interface
      • Working with the EYWA Locker contract in Arbiscan.
    • 🌾Yield
      • Farms Interface
        • Staking liquidity and earning rewards
      • APR Calculator
    • πŸ’ΌVesting
      • Claim portal interface
      • Early farming program interface
    • EYWA NFT
      • Bridge interface in the Aurora chain
      • Merge interface in the Arbitrum chain
      • EYWA NFT Manager interface
      • Dashboard interface
    • Leaderboard
    • ❄️Outdated
      • Early farming program
  • πŸ“–Developer documentation
    • Pools/asset contracts
      • Hubchain Pools and Assets
      • πŸ’±Supported tokens
    • πŸ”—CrossCurve smart contracts
    • πŸ’»Guide for Developers
      • Technical Documentation for CrossCurve DAO Smart Contracts
        • CalldataHelperV1
        • DelegationManagerV1
        • DelegationConditionValidatorV1
        • EmissionManagerV1
        • EscrowManager
        • EscrowVoteManagerV1
        • GaugeFactoryV1
        • GaugeV1
        • IncentiveRewardsDistributor
        • LockHolderFactoryV1
        • LockHolderV1
        • ProposalManager
        • RebaseRewardsDistributorV1
        • RewardsDistributorFactoryV1
        • Treasury
      • πŸ”ƒMake cross-chain swap
      • πŸ”¦Tracking cross-chain swap
      • πŸ“”Pusher API Reference
      • πŸ“Glossary
      • API Specification
  • πŸ“£About CrossCurve
    • πŸ›‘οΈSecurity audits
    • 🧠Team
    • Project History
    • Website
    • Telegram
    • Twitter
    • Medium
    • Discord
    • YouTube
    • LinkedIn
    • GitHub
Powered by GitBook
On this page
  • 1. Routing construction
  • 2. Making a route estimate
  • 3. Forming data for sending the transaction
  • 4. Sending the transaction
Export as PDF
  1. Developer documentation
  2. Guide for Developers

Make cross-chain swap

Performing a cross-chain swap consists of 4 steps:

  1. Routing construction

  2. Estimating cross-chain operations

  3. Forming data for the transaction

  4. Sending the transaction

1. Routing construction

Request routing for the specified tokens and networks

Copy

const requestRoutingParams = {
    params: {
         chainIdIn": 1, // Ethereum
         chainIdOut: 250, // Fantom
         tokenIn: "0xdac17f958d2ee523a2206206994597c13d831ec7", // USDT
         tokenOut: "0xe71286fc887189c562410af12ed521c8e58e5fa3", // s3crypto_e
         amountIn: "100000000", // 100 USDT
    },
    slippage: 1, // 1%
}

const response = await fetch('https://api.crosscurve.fi/routing/scan', {
    method: 'POST',
    body: JSON.stringify(requestRoutingParams),
    headers: {
        "Content-Type": "application/json",
    },
})

const routing = await response.json()

2. Making a route estimate

From the obtained array of routes, take the first route (which is the most profitable for swapping) and send it for estimation

Copy

const bestRoute = routing[0]

const response = await fetch('https://api.crosscurve.fi/estimate', {
    method: 'POST',
    body: JSON.stringify(bestRoute),
    headers: {
        "Content-Type": "application/json",
    },
})

const estimate = await response.json()

3. Forming data for sending the transaction

Copy

const txCreateParams = {
    from: '0x...', // sender
    recipient: '0x...', // recipient
    routing,
    estimate,
}

const response = await fetch('https://api.crosscurve.fi/tx/create', {
    method: 'POST',
    body: JSON.stringify(txCreateParams),
    headers: {
        "Content-Type": "application/json",
    },
})

const rawTx = await response.json()

4. Sending the transaction

Copy

import { Contract, JsonRpcProvider } from 'ethers'
 
const provider = new JsonRpcProvider('RPC_URL_HERE')
const signer = new Wallet(process.env.PRIVATE_KEY, provider)

const router = new Contract(rawTx.to, [rawTx.abi], signer)

const args = [
  rawTx.args[0],
  rawTx.args[1],
  [
    rawTx.args[2].executionPrice,
    rawTx.args[2].deadline,
    rawTx.args[2].v,
    rawTx.args[2].r,
    rawTx.args[2].s,
  ],
]

const value = BigInt(rawTx.value) + BigInt(estimate.executionPrice)

const tx = await router.start(...args, { value })
const receipt = await tx.wait()
PreviousTreasuryNextTracking cross-chain swap

Last updated 29 days ago

πŸ“–
πŸ’»
πŸ”ƒ