KyberSwap Docs
  • Introduction to KyberSwap
  • Getting Started
    • Quickstart
      • FAQ
    • Supported Exchanges And Networks
    • Foundational Topics
      • Decentralized Finance
        • Tokens
        • Stablecoins
        • DEX/DeFi Aggregator
        • Slippage
        • Price Impact
        • Zap
        • Maximal Extractable Value (MEV)
      • Decentralized Technologies
        • Wallets
        • Dapps
        • RPC
        • Oracles
        • On-Chain vs Off-Chain Data
      • Other Valuable Resources
  • KyberSwap Solutions
    • KyberSwap Interface
      • User Guides
        • Connect Your Wallet
        • Switching Networks
        • Instantly Swap At Superior Rates
        • Swap At Your Preferred Rates
        • Add Your Favourite Tokens
        • Get Crypto With Fiat
        • Bridge Your Assets Across Multiple Chains
        • Swap Between Different Tokens Across Chains
      • Profiles
        • Profile Creation
        • Profile Customization
        • Sync Profile Across Devices
      • Notifications
        • Notification Center
    • KyberSwap Aggregator
      • Concepts
        • Dynamic Trade Routing
      • User Guides
        • Instantly Swap At Superior Rates
      • Developer Guides
        • Execute A Swap With The Aggregator API
        • Upgrading To APIv1
      • Aggregator API Specification
        • EVM Swaps
        • Permit
      • Contracts
        • Aggregator Contract Addresses
      • DEX IDs
      • Subgraphs
      • FAQ
    • KyberSwap Zap as a Service
      • KyberSwap Zap as a Service (ZaaS) API
        • ZaaS HTTP API
        • ZaaS GRPC API
      • KyberSwap Zap Liquidity Widget
      • Zap Fee Model
      • Zap's Supported Chains/Dexes
      • Zap's Deployed Contract Addresses
      • Zap's DEX IDs
    • KyberSwap Widget
      • Developer Guides
        • Integrating The KyberSwap Widget
        • Customizing The KyberSwap Widget
      • iFrame Alternative
      • Widget/iFrame Fee
    • KyberSwap Liquidity Widget
      • Integrating The KyberSwap Liquidity Widget
    • Limit Order
      • Concepts
        • Off-Chain Relay, On-Chain Settlement
        • Gasless Cancellation
      • User Guides
        • Swap At Your Preferred Rates
        • Update Limit Orders
        • Cancel Limit Orders
      • Developer Guides
        • Create Limit Order
        • Gasless Cancel
        • Hard Cancel
        • Fill Limit Order
      • Contracts
        • Limit Order Contract Addresses
      • Limit Order API Specification
        • General APIs
        • Maker APIs
        • Taker APIs
      • FAQ
    • KyberSwap OnChain Price Service
    • Fee Schedule
  • Governance
    • KyberDAO
      • User Guides
        • Participating in KyberDAO
        • Staking
        • Voting
        • Stake KNC And Enjoy Gas Savings
      • Fees to KyberDAO
      • KyberDAO Operator MultiSig
      • Contracts
        • KyberDAO Contract Repo
        • KyberDAO Contract Addresses
      • FAQ - Others
    • KNC Token
      • KNC Tokenomics & Utility
      • Gas Refund Program
      • KNC Contract Addresses
  • Security
    • Audits
  • Reference
    • Legacy
      • KyberSwap Classic
        • Concepts
          • Programmable Pricing Curves
          • Dynamic Auto-Adjusting Fees
          • Virtual Balances
          • Protocol Fees
        • Contracts
          • Classic Contract Repo
          • Classic Contract Addresses
          • Classic Contract Farming Addresses
      • KyberSwap Elastic
        • Concepts
          • Concentrated Liquidity
          • Reinvestment Curve
          • Tick-Range Mechanism
          • Pool Process Flows
          • Anti-Sniping Mechanism
          • Tick-Based Farming
          • Elastic Zap
          • TWAP Oracle
          • Elastic APR Calculations
        • Contracts
          • Elastic Contract Repo
          • Elastic Contract Addresses
          • Elastic Farming Contract Addresses
          • Elastic Zap Contract Addresses
          • Elastic Core Contracts
          • Elastic Core Libraries
          • Elastic Periphery Core Contracts
          • Elastic Peripheral Library Contracts
          • Elastic Peripheral Base Contracts
        • Subgraphs
      • Whitepapers
      • Audits
      • KyberAI
        • KyberScore
        • Concepts
        • On-Chain Indicators
          • Number Of Trades
          • Trading Volume
          • Netflow To Whale Wallets
          • Netflow To CEX
          • Number Of Transfers
          • Volume Of Transfers
          • Number Of Holders
          • Top Holders
        • Technical Indicators
          • Live Charts
          • Support & Resistance Levels
          • Live Trades
          • Funding Rate On CEX
          • Liquidations On CEX
        • Liquidity Analysis
      • Elastic Legacy
        • Elastic Legacy Contract Repo
        • Elastic Legacy Contract Addresses
        • Elastic Legacy Farming Contract Addresses
        • Remove Elastic Legacy Liquidity
      • Protocol
        • Overview
        • Smart Contract Architecture
        • Trust and Security Model
      • Integrations
        • Getting Started
        • Use Cases
        • Integration Types
        • Smart Contracts
        • Ethers JS
        • RESTful API
        • Slippage Rate Protection
        • Price Feed Security
        • Contract Events
        • Platform Fees
      • Reserves
        • Getting Started
          • Overview
          • Why Develop On Kyber
          • Create New Reserve
          • Existing Reserves
          • Customising Existing Reserves
        • Development Guides
          • Fed Price Reserve
          • Automated Price Reserve
          • Reserves with Ganache
          • Orderbook Reserve
        • Operations
          • Listing Policies
          • Reserve IDs
          • Reserve Rebates
          • Sanity Rates
      • Addresses
        • Introduction
        • Mainnet
        • Kovan
        • Rinkeby
        • Ropsten
      • API/ABI
        • Introduction
        • RESTful API
          • RESTful API Overview
          • RESTful API
        • Core Smart Contracts
          • IKyberNetworkProxy
          • KyberNetworkProxy
          • IKyberNetwork
          • ISimpleKyberProxy
          • IKyberMatchingEngine
          • KyberMatchingEngine
          • IKyberHint
          • KyberHintHandler
          • IKyberHintHandler
          • IKyberFeeHandler
          • IKyberStaking
          • KyberStaking
          • IKyberDao
          • KyberDao
          • IKyberStorage
          • KyberStorage
          • IKyberHistory
          • KyberHistory
          • IKyberReserve
          • KyberReserve
          • ConversionRates
          • LiquidityConversionRates
          • EpochUtils
          • IEpochUtils
          • KyberFeeHandler
        • Contract ABIs
          • ABIs
        • Code Snippets
          • Token Quantity Conversion
        • Misc Contracts
          • KyberNetwork
          • ConversionRatesInterface
          • PermissionGroups
          • SanityRates
          • Withdrawable
          • OrderbookReserveInterface
          • OrderbookReserveLister
    • KyberSwap Operator MultiSig
    • Permitable Tokens
    • Third-Party Integrations
    • KyberSwap Analytics
    • KyberSwap App
    • GitHub
    • KyberSwap Analytics
    • KyberSwap Blog
    • Kyber Network Press Kit
  • Socials
    • X
    • Discord
    • Telegram
    • LinkedIn
    • Reddit
    • Instagram
    • Tik Tok
  • Support
    • KyberSwap Help Center
    • Complaints Handling Process
Powered by GitBook
On this page
  • Overview
  • Swap flow: Non-versioned vs V1
  • Non-versioned API swap flow
  • APIv1 swap flow
  • Field mappings
  • Request
  • Response

Was this helpful?

  1. KyberSwap Solutions
  2. KyberSwap Aggregator
  3. Developer Guides

Upgrading To APIv1

More Performant Routing And Encoding

PreviousExecute A Swap With The Aggregator APINextAggregator API Specification

Last updated 1 month ago

Was this helpful?

Overview

Following feedback on the initial non-versioned API, KyberSwap has implemented a more performant APIv1 which improves the response time for getting a route via offloading encoding requirements to a separate post method. With this upgrade, APIv1 brings the following improvements:

  • Reduced latency which enables gas estimation calculations to be more accurate

  • Reduces the risk of stale encoded data which could potentially lead to failed transactions on the UI

  • Functional separation which enables more precise data handling and compute

Swap flow: Non-versioned vs V1

As part of the APIv1 upgrade, querying of the route data and the encoded data has been separated into their own respective calls. This stands in contrast to the non-versioned API whereby both the route and encoded data are returned in a single query.

Due to this functional separation, applications have more flexibility when handling route refreshes prior to user confirming the swap route. For example, if rates need to be refreshed, the application will just have to query the APIv1 endpoint which will return just the route summary. As the encoded data does not have to be processed at this stage, responses are much faster and redundant encodings are avoided.

Moreover, given the reduced latency for each call in APIv1, this reduces the likelihood that the returned data will be stale hence mitigating transaction failure risks. Routes are secured (i.e. "locked-in") via the APIv1 which returns the encoded data to be sent to the contract.

Non-versioned API swap flow

Route and encoded data returned in single GET call.

APIv1 swap flow

Route summary returned in GET response and encoded data returned in POST response.

Field mappings

As part of this upgrade, some of the parameters have also been modified to make it more intuitive. The table below maps the relevant changes for avoidance of doubt.

Request

API GET
APIv1 GET
APIv1 POST

tokenIn*

tokenIn*

-

tokenOut*

tokenOut*

-

amountIn*

amountIn*

-

saveGas

saveGas

-

slippageTolerance

-

slippageTolerance

isInBps

isInBps

-

chargeFeeBy

chargeFeeBy

-

feeReceiver

feeReceiver

-

feeAmount

feeAmount

-

deadline

-

deadline

to*

-

recipient*

clientData

-

source

referral

-

referral

permit

-

permit

dexes

includedSources

-

-

excludedSources

-

gasInclude

gasInclude

-

gasPrice

gasPrice

-

-

-

routeSummary*

-

-

sender*

-

-

enableGasEstimation

Response

The response parameters have been slightly altered in the [V1]POST API. The relevant parameter keys are provided below ( non-versioned -> [V1]):

  • inputAmount -> amountIn

  • encodedSwapData -> data

API GET
APIv1 GET
APIv1 POST

inputAmount

amountIn

amountIn

outputAmount

amountOut

amountOut

totalGas

gas

gas

gasPriceGwei

gasPrice

gasUsd

gasUsd

gasUsd

amountInUsd

amountInUsd

amountInUsd

amountOutUsd

amountOutUsd

amountOutUsd

receiveUsd

-

-

swaps

route

-

pool

pool

-

tokenIn

tokenIn

-

tokenOut

tokenOut

-

swapAmount

swapAmount

-

amountOut

amountOut

-

limitReturnAmount

limitReturnAmount

-

maxPrice

-

-

exchange

exchange

-

poolLength

poolLength

-

poolType

poolType

-

tokens

-

-

address

-

-

symbol

-

-

name

-

-

price

-

-

decimals

-

-

encodedSwapData

-

data

routerAddress

routerAddress

routerAddress

-

code

code

-

message

message

-

data

data

-

routeSummary

-

-

extraFee

-

-

feeAmount

-

-

chargeFeeBy

-

-

isInBps

-

-

feeReceiver

-

Non-versioned API GET:

APIv1 GET:

APIv1 POST:

MetaAggregationRouterV2
/{chain}/route/encode
/{chain}/api/v1/routes
/{chain}/api/v1/route/build
GET
GET
POST
Non-Versioned API sequence diagram
APIv1 sequence diagram