Swap
Last updated
Last updated
Dojoswap operates differently from traditional exchanges in terms of how it executes swaps. In centralized exchanges, prices for stocks and cryptocurrencies fluctuate based on bidding and the dynamics of supply and demand, enabling real-time transactions that occur in milliseconds. However, blockchain-based exchanges face challenges due to block times, making immediate transaction execution nearly impossible.
To address this, Dojoswap uses algorithmic pricing, a distinct approach that relies on monitoring the ratio of paired assets within the liquidity pool. This method ensures that swaps occur based on the predetermined ratio of assets in the pool rather than real-time market dynamics. For a more detailed understanding of this approach, you can refer to the mechanism section for comprehensive insights.
Tokens and pairs should be deployed on the chain.
You should know the addresses of tokens and a pair for trade.
All transactions can be executed with the below command:
contract-address
: The pair contract address in a swap transaction
handle-msg
: The method and parameters of the execution, which will be explained following lines
coins
: Transaction execution fee
To learn more about the general rules for handle-msg
, please refer to this link.
swap.offer_asset
represents your source asset. It is mandatory to acknowledge the decimal of the token setting when entering the value of swap.offer_asset.amount
for an accurate transaction you want. For instance, the decimal of INJ is 18, and it implies the value 10
of swap.offer_asset.amount
expresses โ10 x 10^-18in the actual amount. That means you should multiply with the matching value,
10^(decimal)`.
swap.to
is the destination token address. You donโt need to enter the amount to swap into since DojoSwap calculates the price algorithmically.
After filling them out, you may choose to change it into an inline string (not necessary if you can make it with multiline):
This is your handle-msg
. The handle-msg
can be used to complete the CLI command to swap tokens.
Swapping contract-minted token to native token is executed with the same logic as above. However, it requires a different handle-msg
due to the token systemโs difference and implementation. The message looks like:
The method is a little bit tricky. Please keep your concentration on!
In the CLI,
contract-address
: Enter token address
In the message:
send.contract
: Enter pair address
send.amount
: The amount of the origin token to swap from
send.msg.swap
is an optional attribute, which is not required for basic swap executions.
Encode {"swap":{}}
into base64 encoding. It should look something like: eyJzd2FwIjp7fX0=
.
Enter the base64 encoded value for msg
of the JSON:
After then, you may proceed as the above.