Contract Interface

DODO provides a unified DODOV2Proxy that encapsulates the pools for the underlying layer, allowing for continuous multi-hop pool trading at the upper layer. Developers can access DODOV2Proxyby means of contracts, and likewise specify DODO liquidity pools to dock to contracts for trading.
If traders wish to directly dock to the underlying pool for trading, they need to distinguish between DODOV1 and DODOV2 pools (see the contract deployment page for information on DODOV1 pool addresses for each chain).

Access to DODOV2 transactions

First of all, for the DODOV2 pool, we have defined it 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 token and get quote token.This function requires the trader to construct a trade with two actions, the first one 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 onreceiveQuoteAmount before closing to ensure 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. Before closing, traders are advised to perform a balance check on receiveBaseAmountto ensure safe execution of the transaction.
DODO V2 will also provide a preview of the results of the above two functions. The preview function can be executed without sending a trade, helping traders to estimate the price in order to save gas fees. Note: The trader passed in 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 DODOV1 transactions

DODOV1 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 sold baseToken to the pool, and the second being to trigger the sellBaseToken. Before closing, it is recommended that traders perform a balance check on receiveQuoteAmount to ensure 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 Token by selling quote Token, but the difference is that the first parameter of the contract needs to be passed the base amount to be bought, and this value needs to be calculated beforehand by passing maxPayQuote, which is the number of quote Token to be sold in the second parameter of the contract. DODO provides Helper contracts in each chain, so developers can call querySellQuoteToken to quickly get the base amount that can be bought by passing in the quote amount they want to sell and specifying the pool address of DODOV1. This way they get all the parameters to trigger the buyBaseToken function. The interface to the Helper contract 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 && querySellBaseToken functions of the above Helper contracts to preview the transaction results .
Note: The DODOV1 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 it is DODOV1 or DODOV2, the PMM algorithm is used behind the scenes to support the buying and selling prices of the pools. Therefore, when developers need to calculate the pool prices off-chain 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 with pmmOffchainCalc.ts

Mobility 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 retrieval displayi
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 to be passed as parameters in order, while the latter does not need to distinguish base and quote, and the retrieved result consists of two arrays, corresponding to the pool list with token0 as base, and the pool list with token1 as base for base and token1 for base. The last retrieval function takes the address of the creator as an argument and gets the list of pools created under his account.
At the same time, we provide real-time listening to the DODO platform to create and remove pools, so that it is easier to maintain the latest pool list in real-time.
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.