๐ Exchange
Contract Interface #
DODO provides a unified DODOV2Proxy
interface that encapsulates all DODO pools in an underlying layer, allowing for seamless multi-stage trading at the upper layer. Developers can access DODOV2Proxy
by means of contracts, and likewise specify DODO liquidity pools to connect to their contracts for trading purposes.
If traders wish to directly connect to the underlying pool for trading, they need to distinguish between DODO V1 and DODO V2 pools (see here for the pool addresses on each chain).โ
Access to Trading Information on DODO V2#
For the DODO V2 pools, the functions are defined uniformly, exposing two functions for developers to use: sellBase
and sellQuote
function sellBase(address to) external returns (uint256 receiveQuoteAmount);
sellBase
allows you to sell base tokens and receive quote tokens, and requires the trader to construct a trade with two actions. The first action is to transfer the base token to be exchanged to the current pool subcontract, and the second one is to trigger sellBase
with the receiving address of the exchange as an argument.
It is recommended that traders perform a balance check on receiveQuoteAmount
before closing to ensure the safe execution of the trade.
function sellQuote(address to) external returns (uint256 receiveBaseAmount);
Similarly, sellQuote
can be implemented to sell a quote token and receive a base token. This function also requires the trader to construct a transaction with two actions - the first being to transfer the quote token to be exchanged to the current pool subcontract, and the second being to trigger sellQuote
with the receiving address of the exchange as an argument.
It is recommended that traders perform a balance check on receiveBaseAmount
before closing to ensure the safe execution of the trade.
DODO V2 will also provide a preview of the results of the above two functions. The preview function can be called without executing a trade, helping traders to estimate the price in order to save gas fees.
Note: trader
is the public key address of the initiating trader.
function querySellBase(
address trader,
uint256 payBaseAmount
) external view returns (uint256 receiveQuoteAmount,uint256 mtFee);
function querySellQuote(
address trader,
uint256 payQuoteAmount
) external view returns (uint256 receiveBaseAmount,uint256 mtFee);
Access to Trading Information on DODO V1#
For DODO V1 pool, the two exposed functions are sellBaseToken
and buyBaseToken
โ
function sellBaseToken(
uint256 amount,
uint256 minReceiveQuote,
bytes calldata data
) external returns (uint256 receiveQuoteAmount);
This function requires the trader to construct a transaction with two actions, the first being to authorize the baseToken
to be sold to the pool, and the second being to execute the sellBaseToken
function.
It is recommended that traders perform a balance check on receiveQuoteAmount
before closing to ensure the safe execution of the trade.
function buyBaseToken(
uint256 amount,
uint256 maxPayQuote,
bytes calldata data
) external returns (uint256 payQuoteAmount);
buyBaseToken
can be used to buy base tokens by selling quote tokens, but the difference is that the amount
parameter of the contract needs to be passed the amount of base tokens to be purchased. This value needs to be calculated beforehand using maxPayQuote
, which is the number of quote tokens to be sold in the second parameter of the contract.
DODO provides helper contracts for each chain, allowing developers to call the querySellQuoteToken
interface function to quickly get the base token amount that can be bought by passing in the quote token amount they want to sell and specifying the DODO V1 pool address. This way, they get all the information necessary to trigger the buyBaseToken
function.
The interface for the helper contracts is described as follows:
function querySellQuoteToken(
address dodoV1Pool,
uint256 quoteAmount
) public view returns (uint256 receiveBaseAmount);l
function querySellBaseToken(
address dodoV1Pool,
uint256 baseAmount
) public view returns (uint256 receiveQuoteAmount);
Similarly, for DODO V1, developers can use the querySellQuoteToken
and querySellBaseToken
functions of the above helper contracts to preview the transaction result .
Note: The DODO V1 pool address and helper contract address of each chain can be found on the contract deployment details page.
Access to DODOV2Proxy Transactions #
Developers can also directly access DODOV2Proxy
to implement transactions against DODOV2 or DODOV1, as well as to implement multi-hop transactions by constructing parameters. For more details on how to access it, see the following code sample DODOProxyIntegrate.sol
Finally, whether on DODO V1 or DODO V2 pools, the PMM algorithm is used behind the scenes to determine the buying and selling prices of tokens in these pools. When developers need to calculate the pool prices and the buying and selling quantities of the pools off-chain, they can refer to the following script, which implements the PMM algorithm and can be used directly off-chain: pmmOffchainCalc.ts.
Liquidity Pool Registry #
Developers can get all the pool addresses that have been created by the platform from the factory contracts (DPPFactory
&&DVMFactory
&& DSPFactory
need to be called separately) for functions such as pool address display.
function getDODOPool(
address baseToken,
address quoteToken
) external view returns (address[] memory pools)
function getDODOPoolBidirection(
address token0,
address token1
) external view returns (address[] memory baseToken0Pool, address[] memory baseToken1Pool)
function getDODOPoolByUser(
address user
) external view returns (address[] memory pools)
The difference between getDODOPool
and getDODOPoolBidirection
is that the former needs to distinguish base and quote tokens to be passed as parameters in order, while the latter does not need to distinguish base and quote tokens. The result of calling getDODOPoolBidirection
consists of two arrays, corresponding to the pool list with token0 as the base token, and the pool list with token1 as the base token. The last search function takes the creator's address as a parameter and returns a list of pools created by the account.
In addition, we provide real-time monitoring of pool creation and removal events on the DODO platform, making it easier to maintain the latest pool list on the platform.
event NewDVM(address baseToken,address quoteToken,address creator,address dvm);
event RemoveDVM(address dvm);
event NewDPP(address baseToken,address quoteToken,address creator,address dpp);
event RemoveDPP(address dpp);
event NewDSP(address baseToken,address quoteToken,address creator,address dsp);
event RemoveDSP(address dsp);
NewDVM
and RemoveDVM
are events in the DVMFactory, NewDPP
and RemoveDPP
are events in the DPPFactory, and NewDSP
and RemoveDSP
are events in the DSPFactory
.