|
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. |