Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more descriptive comments for the ratio of assets in the pool and the swap price #431

Open
2 of 4 tasks
jaybxyz opened this issue Jul 14, 2021 · 0 comments
Open
2 of 4 tasks
Labels
client rest or cli improvements documentation Improvements or additions to documentation
Milestone

Comments

@jaybxyz
Copy link
Contributor

jaybxyz commented Jul 14, 2021

Summary

There is a demand for more descriptive comments for the ratio of assets in the pool and the swap price. Developers who just start to play with the liquidity module may not have much knowledge about the DEX pricing calculation. For them, it will be helpful to have more descriptive comments around how to calculate order price when creating a swap transaction and how to obtain the swap price.

Proposal

I propose to write more descriptive comments in both swap cli command and sample swap script.

func NewSwapWithinBatchCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "swap [pool-id] [swap-type] [offer-coin] [demand-coin-denom] [order-price] [swap-fee-rate]",
Args: cobra.ExactArgs(6),
Short: "Swap offer coin with demand coin from the liquidity pool with the given order price",
Long: strings.TrimSpace(
fmt.Sprintf(`Swap offer coin with demand coin from the liquidity pool with the given order price.
This swap request is not processed immediately since it is accumulated in the liquidity pool batch.
All requests in a batch are treated equally and executed at the same swap price.
The order of swap requests is ignored since the universal swap price is calculated in every batch to prevent front running.
The requested swap is executed with a swap price that is calculated from the given swap price function of the pool, the other swap requests, and the liquidity pool coin reserve status.
Swap orders are executed only when the execution swap price is equal to or greater than the submitted order price of the swap order.
Example:
$ %s tx %s swap 1 1 50000000uusd uatom 0.019 0.003 --from mykey
For this example, imagine that an existing liquidity pool has with 1000000000uatom and 50000000000uusd.
This example request swaps 50000000uusd for at least 950000uatom with the order price of 0.019 and swap fee rate of 0.003.
A sufficient balance of half of the swap-fee-rate of the offer coin is required to reserve the offer coin fee.
The order price is the exchange ratio of X/Y, where X is the amount of the first coin and Y is the amount of the second coin when their denoms are sorted alphabetically.
Increasing order price reduces the possibility for your request to be processed and results in buying uatom at a lower price than the pool price.
For explicit calculations, The swap fee rate must be the value that set as liquidity parameter in the current network.
The only supported swap-type is 1. For the detailed swap algorithm, see https://github.com/tendermint/liquidity
[pool-id]: The pool id of the liquidity pool
[swap-type]: The swap type of the swap message. The only supported swap type is 1 (instant swap).
[offer-coin]: The amount of offer coin to swap
[demand-coin-denom]: The denomination of the coin to exchange with offer coin
[order-price]: The limit order price for the swap order. The price is the exchange ratio of X/Y where X is the amount of the first coin and Y is the amount of the second coin when their denoms are sorted alphabetically
[swap-fee-rate]: The swap fee rate to pay for swap that is proportional to swap amount. The swap fee rate must be the value that set as liquidity parameter in the current network.

# Ensure the existence of the liquidity pool.
# If there is no liquidity pool created then use create-pool script to create liquidity pool.
# liquidityd tx liquidity swap 1 1 79000stake token 0.99 0.003 --home ./data/localnet --chain-id localnet --from user1 --keyring-backend test --yes
echo "-> Swapping coins from the liquidity pool 1..."
$BINARY tx liquidity swap 1 1 79000stake token 0.99 0.003 \
--home $CHAIN_DIR/$CHAIN_ID \
--chain-id $CHAIN_ID \
--from user1 \
--keyring-backend test \
--yes


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@jaybxyz jaybxyz added client rest or cli improvements documentation Improvements or additions to documentation labels Jul 14, 2021
@dongsam dongsam added this to the v2 milestone Jul 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client rest or cli improvements documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants