API Response Field Description#

fieldjson typedescription
resAmountnumberThe amount of tokens received after the inquiry (floating point number, with decimal point)
resPricePerToTokennumberRatio of the amount of tokens being sold to the amount of tokens being purchased
resPricePerFromTokennumberRatio of the amount of tokens being purchased to the amount of tokens being sold
priceImpactnumberAlso known as the price deviation. Convert this number to a percentage by multiplying by 100. A high price deviation is caused by low liquidity in the pools where the prices are quoted from.
useSourcestringSource identification of inquiry results
targetDecimalsnumberDecimal amount of tokens to be received
targetApproveAddrstringUser need give authorization for the DODOApprove contract to access their tokens before swapping. If the token being sold is a gas token such as ETH (on BNB or MATIC), this parameter will be empty.
tostringThe DODORouteProxy address
datastringABI Data, can be used directly
routeDatastringThe path details of the transaction execution

Mock Response#

{
    "status": 200,
    "data": {
        "resAmount": 41.777131132002744,
        "resPricePerToToken": 2.3936540707888985,
        "resPricePerFromToken": 0.4177713113200274,
        "priceImpact": 0.0032237773057670273,
        "useSource": "dodoV1AndV2AndUni",
        "targetDecimals": 18,
        "targetApproveAddr": "0x6D310348d5c12009854DFCf72e0DF9027e8cb4f4",
        "to": "0x39E3e49C99834C9573c9FC7Ff5A4B226cD7B0E63",
        "data": "...",
        "msgError": "",
        "routeData": "{\"subRouteTotalPart\":100,\"subRoute\":[{\"midPathPart\":100,\"midPath\":[{\"fromToken\":\"0xe06bd4f5aac8d0aa337d13ec88db6defc6eaeefe\",\"toToken\":\"0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270\",\"oneSplitTotalPart\":100,\"poolDetails\":[{\"poolName\":\"SushiSwap V2\",\"pool\":\"0x014ac2a53aa6fba4dcd93fde6d3c787b79a1a6e6\",\"poolPart\":100}]}]}]}",
        "value": "0",
        "id": "252046ac3d000a61571aca9eee9f3509",
        "rpcCounter": 6
    }
}

Developers need to pay attention#

When priceImpact is too large, it is necessary to prompt the user or restrict user transactions.

Detailed explanation of priceImpact principle#

Assuming a certain amount of token0 (token0Amount) can be exchanged for token1Amount of token1, the price of each token0 (token0Price) is calculated as token1Amount / token0Amount.

Different paths have varying depths of liquidity; some paths have good depth, while others do not.

As the token0Amount increases, the requirement for path depth also increases, leading to a decrease in token0Price. This deviation in price decrease is known as the priceImpact.

When the path has exceptionally good depth, the change in token0Price can be negligible, such as a priceImpact of 0.00001. Conversely, when the path depth is poor, the change in token0Price can be significant, exemplified by a priceImpact of 0.9.

DODO Frontend Best Practices#

Price Impact Warning#

A price impact greater than 5% (0.05) triggers a warning to the user, and a price impact greater than 15% (0.15) triggers an error message to the user.

Pre-execution Handling#

Before sending a transaction, a pre-execution with eth_estimateGas is performed to improve the success rate of transactions being added to the blockchain, and to display any error messages.

How to Obtain Transaction Results#

Obtain the transaction execution status via RPC method.

Retrieve order details and historical orders using DODO's subgraph service.