├── README.md ├── gravity-dex.md └── osmosis.md /README.md: -------------------------------------------------------------------------------- 1 | # Arbitrage Bot Guide 2 | 3 | This guide intends to provide basic information for arbitrageurs to get familiar with [Gravity DEX](https://cosmos.network/gravity-dex/) and [Osmosis](https://medium.com/osmosis/osmosis-a-hub-amm-c4c12788f94c). 4 | 5 | # Guides 6 | 7 | - [gravity-dex.md](gravity-dex.md) 8 | - [osmosis.md](osmosis.md) 9 | -------------------------------------------------------------------------------- /gravity-dex.md: -------------------------------------------------------------------------------- 1 | # Gravity DEX 2 | 3 | ## Table Of Contents 4 | 5 | * [Basic Node Operation](Basic-Node-Operation) 6 | * [Resources](#Resources) 7 | * [Hardware Requirements](#Hardware-Requirements) 8 | * [Install Go](#Install-Go) 9 | * [Install gaiad from source](#Install-gaiad-from-source) 10 | * [Setup](#Setup) 11 | * [Query Information](#Query-Information) 12 | * [Pool](#Pool) 13 | * [Pools](#Pools) 14 | * [Batch](#Batch) 15 | * [Deposit](#Deposit) 16 | * [Deposits](#Deposits) 17 | * [Withdraw](#Withdraw) 18 | * [Withdraws](#Withdraws) 19 | * [Swap](#Swap) 20 | * [Swaps](#Swaps) 21 | * [Error Codes](#Error-codes) 22 | * [Find blocks through endblock_events](#Find-blocks-through-endblock_events) 23 | * [REST API](#REST-API) 24 | * [Transaction Information](#Transaction-Information) 25 | * [MsgCreatePool](#MsgCreatePool) 26 | * [MsgDepositWithinBatch](#MsgDepositWithinBatch) 27 | * [MsgWithdrawWithinBatch](#MsgWithdrawWithinBatch) 28 | * [MsgSwapWithinBatch](#MsgSwapWithinBatch) 29 | * [Error Codes](#Error-codes) 30 | * [Broadcast tx through REST API](#Broadcast-tx-through-REST-API) 31 | * [Calculations](Calculations) 32 | * [Pool Price](#Pool-Price) 33 | * [Expected Swap Price](#Expected-Swap-Price) 34 | * [Expected Swap Amount](#Expected-Swap-Amount) 35 | * [Liquidity Params](Liquidity-Params) 36 | * [Current parameter value for the mainnet](#Current-parameter-value-for-themainnet) 37 | * [MinInitDepositAmount](#MinInitDepositAmount) 38 | * [InitPoolCoinMintAmount](#InitPoolCoinMintAmount) 39 | * [MaxReserveCoinAmount](#MaxReserveCoinAmount) 40 | * [PoolCreationFee](#PoolCreationFee) 41 | * [SwapFeeRate](#SwapFeeRate) 42 | * [WithdrawFeeRate](#WithdrawFeeRate) 43 | * [MaxOrderAmountRatio](#MaxOrderAmountRatio) 44 | * [UnitBatchSize](#UnitBatchSize) 45 | * [CircuitBreakerEnabled](#CircuitBreakerEnabled) 46 | * [References](References) 47 | * [Sample Project](#Sample-Project) 48 | 49 | 50 | ## Basic Node Operation 51 | 52 | ### Resources 53 | 54 | - [Official Repository](https://github.com/cosmos/gaia) 55 | - [The latest release version of gaia](https://github.com/cosmos/gaia/releases) (currently [v5.0.5](https://github.com/cosmos/gaia/releases/tag/v5.0.5)) 56 | - [Genesis file](https://github.com/cosmos/mainnet/raw/master/genesis.cosmoshub-4.json.gz) (genesis.cosmoshub-4.json) 57 | - [Official documenation: Join the Cosmos Hub Mainnet](https://hub.cosmos.network/main/gaia-tutorials/join-mainnet.html) 58 | - [Gaia Basic tutorials](https://hub.cosmos.network/main/resources/service-providers.html) 59 | - [Cosmos Hub Mainnet ggithub repository](https://github.com/cosmos/mainnet) 60 | - [Discord channel](https://discord.gg/vcExX9T) 61 | - [Peers and seed nodes](https://hackmd.io/@KFEZk8oMTz6vBlwADz0M4A/BkKEUOsZu#) 62 | - [Performance Testing for Liquidity module(Gravity DEX)](https://github.com/tendermint/liquidity/blob/develop/doc/Performance%20Testing%20for%20Liquidity%20Module.pdf) 63 | ### Hardware Requirements 64 | 65 | Minimum requirements 66 | 67 | - 2 Core CPU 68 | - 8GB RAM 69 | - SSD 70 | - ex) AWS m5.Large 71 | 72 | Recommended spec 73 | 74 | - 4 Core CPU 75 | - 16GB RAM 76 | - Provisioned IOPS SSD 77 | 78 | ### Install Go 79 | 80 | Minimum requirements 81 | 82 | - 2 Core CPU 83 | - 8GB RAM 84 | - SSD 85 | - ex) AWS m5.Large 86 | 87 | Recommended spec 88 | 89 | - 4 Core CPU 90 | - 16GB RAM 91 | - Provisioned IOPS SSD 92 | 93 | Go 1.16+ or later is required for the Cosmos SDK. 94 | 95 | In this example, we will be installing Go on Ubuntu 18.04.2 LTS: 96 | 97 | ```bash 98 | # First remove any existing old Go installation 99 | sudo rm -rf /usr/local/go 100 | 101 | # Install the latest version of Go using this helpful script 102 | curl https://raw.githubusercontent.com/canha/golang-tools-install-script/master/goinstall.sh | bash 103 | 104 | # Update environment variables to include go 105 | cat <<'EOF' >>$HOME/.profile 106 | export GOROOT=/usr/local/go 107 | export GOPATH=$HOME/go 108 | export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin 109 | EOF 110 | 111 | source $HOME/.profile 112 | 113 | # Verify that Go is installed 114 | # Should return go version go1.16.4 linux/amd64 115 | go version 116 | ``` 117 | 118 | ### Install `gaiad` from source 119 | 120 | ```bash 121 | # Clone mainnet version of the project 122 | git clone -b v5.0.5 https://github.com/cosmos/gaia.git 123 | cd gaia 124 | make install 125 | 126 | # Verify the osmosisd version 127 | gaiad version 128 | -> v5.0.5 129 | ``` 130 | 131 | ### Setup 132 | 133 | 1. Initialize the chain with the config files. 134 | 135 | ```bash 136 | # (Recommend) Save chain id in gaiad config 137 | gaiad config chain-id cosmoshub-4 138 | 139 | # Initialize chain 140 | # Replace for the public alias of your node 141 | # (you can also edit moniker later) 142 | # Example: gaiad init testnode --chain-id cosmoshub-4 143 | gaiad init --chain-id=cosmoshub-4 144 | 145 | # This will create a new $HOME/.gaiad folder in your HOME directory. 146 | ``` 147 | 148 | 2. Fetch the mainnet's [genesis](https://github.com/cosmos/mainnet/blob/master/genesis.cosmoshub-4.json.gz) file 149 | 150 | ```bash 151 | wget https://github.com/cosmos/mainnet/raw/master/genesis.cosmoshub-4.json.gz 152 | gzip -d genesis.cosmoshub-4.json.gz 153 | mv genesis.cosmoshub-4.json $HOME/.gaia/config/genesis.json 154 | ``` 155 | 156 | ### Basic Configuration Setup 157 | 158 | 1. Manually add the below peers list in your `$HOME/.gaia/config/config.toml` file. Since IBC and swap state transactions are very large, it is suggested to increase the timeout for a transaction to be committed and maximum size of request body and header. Without configuring those values, you may experience the node to stop from time to time when your node receives too many requests. 159 | 160 | ```bash 161 | # Comma separated list of seed nodes to connect to 162 | seeds = "45f1fe6187a92cdabc7e52e6f65f743ad72c1ba1@157.230.116.241:26656,bf8328b66dceb4987e5cd94430af66045e59899f@public-seed.cosmos.vitwit.com:26656,cfd785a4224c7940e9a10f6c1ab24c343e923bec@164.68.107.188:26656,d72b3011ed46d783e369fdf8ae2055b99a1e5074@173.249.50.25:26656,ba3bacc714817218562f743178228f23678b2873@public-seed-node.cosmoshub.certus.one:26656,3c7cad4154967a294b3ba1cc752e40e8779640ad@84.201.128.115:26656,366ac852255c3ac8de17e11ae9ec814b8c68bddb@51.15.94.196:26656" 163 | 164 | # Comma separated list of nodes to keep persistent connections to 165 | persistent_peers = "45f1fe6187a92cdabc7e52e6f65f743ad72c1ba1@157.230.116.241:26656,bf8328b66dceb4987e5cd94430af66045e59899f@public-seed.cosmos.vitwit.com:26656,cfd785a4224c7940e9a10f6c1ab24c343e923bec@164.68.107.188:26656,d72b3011ed46d783e369fdf8ae2055b99a1e5074@173.249.50.25:26656,ba3bacc714817218562f743178228f23678b2873@public-seed-node.cosmoshub.certus.one:26656,3c7cad4154967a294b3ba1cc752e40e8779640ad@84.201.128.115:26656,366ac852255c3ac8de17e11ae9ec814b8c68bddb@51.15.94.196:26656" 166 | 167 | # The ibc and swap state are very large, causing the node itself 168 | # to stop on excessive queries. Therefore, we customize the rpc configuration 169 | # as above. 170 | 171 | # How long to wait for a tx to be committed during /broadcast_tx_commit. 172 | # WARNING: Using a value larger than 10s will result in increasing the 173 | # global HTTP write timeout, which applies to all connections and endpoints. 174 | # See https://github.com/tendermint/tendermint/issues/3435 175 | timeout_broadcast_tx_commit = "600s" 176 | 177 | # Maximum size of request body, in bytes 178 | max_body_bytes = 10000000 179 | 180 | # Maximum size of request header, in bytes 181 | max_header_bytes = 10485760 182 | ``` 183 | 184 | Note: If your node is unable to connect to any of the seeds listed here, you can find seeds and peers in [this document](https://hackmd.io/@KFEZk8oMTz6vBlwADz0M4A/BkKEUOsZu#) maintained by community members, and at [Atlas](https://atlas.cosmos.network/nodes), which is automatically generated by crawling the network. You can also join [Discord channel](https://discord.gg/vcExX9T) to reach out to any Cosmos community members to get help on this. 185 | 186 | 2. Replace necessary configuration 187 | 188 | ```bash 189 | sed -i '' 's#"tcp://127.0.0.1:26657"#"tcp://0.0.0.0:26657"#g' $HOME/.gaia/config/config.toml 190 | sed -i '' 's/enable = false/enable = true/g' $HOME/.gaia/config/config.toml 191 | sed -i '' 's/swagger = false/swagger = true/g' $HOME/.gaia/config/config.toml 192 | ``` 193 | 194 | ### State sync 195 | 196 | State sync allows a new node to join a network by fetching a snapshot of the application state at a recent height instead of fetching and replaying all historical blocks. This can reduce the time needed to sync with the network from days to minutes. Reference [this article](https://blog.cosmos.network/cosmos-sdk-state-sync-guide-99e4cf43be2f) to know more about Cosmos SDK state sync. 197 | 198 | **Option 1. Setup using state synced data dump** 199 | 200 | - The data that is state sync based on A height is about 1 gigabyte, so it can be set lighter and faster, but there is no index for past blocks. 201 | - Download one of the download links below. 202 | - [cosmoshub-4_state_synced_7271293.tar](https://ipfs.io/ipfs/QmZqGwAQh9QHurbg3YvJJSkQd7T6tg35cFVD1FRF4bAm8J?filename=cosmoshub-4_state_synced_7271293.tar) (IPFS) 203 | - [cosmoshub-4_state_synced_7271293.tar](https://drive.google.com/file/d/1ku0HZ8xXrG4UDPe0ywdG4NQHve1iZ4tP/view?usp=sharing) [](https://ipfs.io/ipfs/QmZqGwAQh9QHurbg3YvJJSkQd7T6tg35cFVD1FRF4bAm8J?filename=cosmoshub-4_state_synced_7271293.tar)(Google Drive) 204 | - Unzip 205 | 206 | `tar xvzf cosmoshub-4_state_synced_7271293.tar` 207 | 208 | - Rename the gaia data files 209 | 210 | `mv gaia_synced ~/.gaia` 211 | 212 | - Start node and sync 213 | 214 | `gaiad start` 215 | 216 | **Option 2. State sync via snapshot supply nodes** 217 | 218 | 1. snapshot supply nodes (2 node setting- Block must be at the latest height) 219 | 220 | Manually add the below setting in `$HOME/.gaiad/config/app.toml` file. 221 | 222 | ```bash 223 | [state-sync] 224 | 225 | # snapshot-interval specifies the block interval at which local state sync snapshots are 226 | # taken (0 to disable). Must be a multiple of pruning-keep-every. 227 | snapshot-interval = 100 228 | 229 | # snapshot-keep-recent specifies the number of recent snapshots to keep and serve (0 to keep all). 230 | snapshot-keep-recent = 2 231 | ``` 232 | 233 | 2. Node to receive snapshot (1 node that needs to sync) 234 | 235 | Manually add the below setting in `$HOME/.gaiad/config/config.toml` file. 236 | 237 | (Set the peers list as well.) 238 | 239 | `#"snapshot-interval = 100, snapshot-keep-recent = 2" → lastblock - 100 = trust_height` 240 | 241 | ```bash 242 | curl -s http:///block?height=7270300 | jq -r '.result.block.header.height + "\n" + .result.block_id.hash' 243 | ``` 244 | 245 | ```bash 246 | [statesync] 247 | # State sync rapidly bootstraps a new node by discovering, fetching, and restoring a state machine 248 | # snapshot from peers instead of fetching and replaying historical blocks. Requires some peers in 249 | # the network to take and serve state machine snapshots. State sync is not attempted if the node 250 | # has any local state (LastBlockHeight > 0). The node will have a truncated block history, 251 | # starting from the height of the snapshot. 252 | enable = true 253 | 254 | # RPC servers (comma-separated) for light client verification of the synced state machine and 255 | # retrieval of state data for node bootstrapping. Also needs a trusted height and corresponding 256 | # header hash obtained from a trusted source, and a period during which validators can be trusted. 257 | # 258 | # For Cosmos SDK-based chains, trust_period should usually be about 2/3 of the unbonding time (~2 259 | # weeks) during which they can be financially punished (slashed) for misbehavior. 260 | rpc_servers = "http://,http://" 261 | trust_height = 7270300 262 | trust_hash = "7115EDFC7ADD3A71F6685584DF9669600E8B8D0C8514A0089C66956F355FA027" 263 | trust_period = "336h" 264 | 265 | # Time to spend discovering snapshots before initiating a restore. 266 | discovery_time = "15s" 267 | 268 | # Temporary directory for state sync snapshot chunks, defaults to the OS tempdir (typically /tmp). 269 | # Will create a new, randomly named directory within, and remove it when done. 270 | temp_dir = "" 271 | ``` 272 | 273 | - `gaiad start` 274 | 275 | If you see log like this, it's going well. 276 | 277 | ```bash 278 | 7:11PM INF Fetching snapshot chunk chunk=7 format=1 height=7271000 module=statesync total=33 279 | 7:11PM INF Applied snapshot chunk to ABCI app chunk=3 format=1 height=7271000 module=statesync total=33 280 | 281 | ... 282 | 283 | 7:15PM INF executed block height=7271024 module=state num_invalid_txs=0 num_valid_txs=0 284 | 7:15PM INF commit synced commit=436F6D6D697449447B5B313130203439203133392031353420313336203235342032303620313439203134203230352031323420313033203134322031392039392032303020313536203130372032392031343520313137203232362036342033372031333220343320323433203834203131392032313320323331203133355D3A3645463237307D 285 | 7:15PM INF committed state app_hash=6E318B9A88FECE950ECD7C678E1363C89C6B1D9175E24025842BF35477D5E787 height=7271024 module=state num_txs=0 286 | 7:15PM INF indexed block height=7271024 module=txindex 287 | 7:15PM INF minted coins from module account amount=4453682uatom from=mint module=x/bank 288 | 7:15PM INF executed block height=7271025 module=state num_invalid_txs=0 num_valid_txs=0 289 | 7:15PM INF commit synced commit=436F6D6D697449447B5B3233312039372032333720313738203230392031333020323435203431203234332039203139362032343620313036203231392031393920393120343220313732203234372031313120313632203238203738203631203232392033312036322035352032333620363420323237203233335D3A3645463237317D 290 | 7:15PM INF committed state app_hash=E761EDB2D182F529F309C4F66ADBC75B2AACF76FA21C4E3DE51F3E37EC40E3E9 height=7271025 module=state num_txs=0 291 | 7:15PM INF indexed block height=7271025 module=txindex 292 | ``` 293 | 294 | - When the sync is complete, set it up as follows: 295 | 296 | ```bash 297 | [statesync] 298 | # State sync rapidly bootstraps a new node by discovering, fetching, and restoring a state machine 299 | # snapshot from peers instead of fetching and replaying historical blocks. Requires some peers in 300 | # the network to take and serve state machine snapshots. State sync is not attempted if the node 301 | # has any local state (LastBlockHeight > 0). The node will have a truncated block history, 302 | # starting from the height of the snapshot. 303 | enable = false 304 | ``` 305 | 306 | Query, tx are available when synchronization is up to the latest height. 307 | 308 | Details are available [here](https://hub.cosmos.network/main/gaia-tutorials/join-mainnet.html). 309 | ## Query Information 310 | 311 | ### Pool 312 | 313 | > Query details of a liquidity pool 314 | 315 | Example `pool` query command using `pool-id` argument: 316 | 317 | ```bash 318 | gaiad query liquidity pool 1 319 | ``` 320 | 321 | Result: 322 | 323 | ```yaml 324 | pool: 325 | id: "1" 326 | pool_coin_denom: pool96EF6EA6E5AC828ED87E8D07E7AE2A8180570ADD212117B2DA6F0B75D17A6295 327 | reserve_account_address: cosmos1jmhkafh94jpgakr735r70t32sxq9wzkayzs9we 328 | reserve_coin_denoms: 329 | - uatom 330 | - uusd 331 | type_id: 1 332 | ``` 333 | 334 | Example `pool` query command using `--pool-coin-denom` flag: 335 | 336 | ```bash 337 | gaiad query liquidity pool --pool-coin-denom=pool96EF6EA6E5AC828ED87E8D07E7AE2A8180570ADD212117B2DA6F0B75D17A6295 338 | ``` 339 | 340 | Result: 341 | 342 | ```yaml 343 | pool: 344 | id: "1" 345 | pool_coin_denom: pool96EF6EA6E5AC828ED87E8D07E7AE2A8180570ADD212117B2DA6F0B75D17A6295 346 | reserve_account_address: cosmos1jmhkafh94jpgakr735r70t32sxq9wzkayzs9we 347 | reserve_coin_denoms: 348 | - uatom 349 | - uusd 350 | type_id: 1 351 | ``` 352 | 353 | Example `pool` query command using `--reserve-acc` flag: 354 | 355 | ```bash 356 | gaiad query liquidity pool --reserve-acc=cosmos1jmhkafh94jpgakr735r70t32sxq9wzkayzs9we 357 | ``` 358 | 359 | Result: 360 | 361 | ```yaml 362 | pool: 363 | id: "1" 364 | pool_coin_denom: pool96EF6EA6E5AC828ED87E8D07E7AE2A8180570ADD212117B2DA6F0B75D17A6295 365 | reserve_account_address: cosmos1jmhkafh94jpgakr735r70t32sxq9wzkayzs9we 366 | reserve_coin_denoms: 367 | - uatom 368 | - uusd 369 | type_id: 1 370 | 371 | ``` 372 | 373 | Query reserve coins of the pool: 374 | 375 | ```bash 376 | gaiad query bank balances cosmos1jmhkafh94jpgakr735r70t32sxq9wzkayzs9we 377 | ``` 378 | 379 | Result: 380 | 381 | ```yaml 382 | balances: 383 | - amount: "999003494" 384 | denom: uatom 385 | - amount: "50050075000" 386 | denom: uusd 387 | pagination: 388 | next_key: null 389 | total: "0" 390 | ``` 391 | 392 | Query total supply of the pool coin 393 | 394 | ```bash 395 | gaiad query bank total --denom=pool96EF6EA6E5AC828ED87E8D07E7AE2A8180570ADD212117B2DA6F0B75D17A6295 396 | ``` 397 | 398 | Result: 399 | 400 | ```yaml 401 | amount: "1000000" 402 | denom: pool96EF6EA6E5AC828ED87E8D07E7AE2A8180570ADD212117B2DA6F0B75D17A6295 403 | ``` 404 | ### Pools 405 | 406 | > Query for all liquidity pools 407 | 408 | Example `pools` query command: 409 | 410 | ```bash 411 | gaiad query liquidity pools 412 | ``` 413 | 414 | Result: 415 | 416 | ```yaml 417 | pagination: 418 | next_key: null 419 | total: "2" 420 | pools: 421 | - id: "1" 422 | pool_coin_denom: pool96EF6EA6E5AC828ED87E8D07E7AE2A8180570ADD212117B2DA6F0B75D17A6295 423 | reserve_account_address: cosmos1jmhkafh94jpgakr735r70t32sxq9wzkayzs9we 424 | reserve_coin_denoms: 425 | - uatom 426 | - uusd 427 | type_id: 1 428 | - id: "2" 429 | pool_coin_denom: poolA4648A10F8D43B8EE4D915A35CB292618215D9F60CE3E2E29216489CF1FAE049 430 | reserve_account_address: cosmos153jg5y8c6sacaexezk34ev5jvxpptk0kscrx0x 431 | reserve_coin_denoms: 432 | - stake 433 | - uusd 434 | type_id: 1 435 | ``` 436 | 437 | ### Batch 438 | 439 | > Query details of a liquidity pool batch 440 | 441 | Example `batch` query command: 442 | 443 | ```bash 444 | gaiad query liquidity batch 1 445 | ``` 446 | 447 | Result: 448 | 449 | ```yaml 450 | batch: 451 | begin_height: "563" 452 | deposit_msg_index: "2" 453 | executed: false 454 | index: "3" 455 | pool_id: "1" 456 | swap_msg_index: "2" 457 | withdraw_msg_index: "2" 458 | 459 | ``` 460 | 461 | ### Deposit 462 | 463 | > Query for the deposit message on the batch of the liquidity pool 464 | 465 | Example `deposit` query command: 466 | 467 | ```bash 468 | gaiad query liquidity deposit 1 1 469 | ``` 470 | 471 | Result: 472 | 473 | ```yaml 474 | deposit: 475 | executed: true 476 | msg: 477 | deposit_coins: 478 | - amount: "1000000000" 479 | denom: uatom 480 | - amount: "50000000000" 481 | denom: uusd 482 | depositor_address: cosmos1le0a8y0ha99txx0ngsh0qhyyx7cwnjmmju52ed 483 | pool_id: "1" 484 | msg_height: "35" 485 | msg_index: "2" 486 | succeeded: true 487 | to_be_deleted: true 488 | ``` 489 | 490 | ### Deposits 491 | 492 | > Query for all deposit messages on the batch of the liquidity pool 493 | 494 | Example `deposits` query command: 495 | 496 | ```bash 497 | gaiad query liquidity deposits 1 498 | ``` 499 | 500 | Result: 501 | 502 | ```yaml 503 | deposits: 504 | - executed: true 505 | msg: 506 | deposit_coins: 507 | - amount: "100000000" 508 | denom: uatom 509 | - amount: "5000000000" 510 | denom: uusd 511 | depositor_address: cosmos1h6ht09xx0ue0fqmezk7msgqcc9k20a5x5ynvc3 512 | pool_id: "1" 513 | msg_height: "458" 514 | msg_index: "1" 515 | succeeded: true 516 | to_be_deleted: true 517 | pagination: 518 | next_key: null 519 | total: "1" 520 | ``` 521 | 522 | ### Withdraw 523 | 524 | > Query for the withdraw message on the batch of the liquidity pool 525 | 526 | Example `withdraw` query command: 527 | 528 | ```bash 529 | gaiad query liquidity withdraws 1 2 530 | ``` 531 | 532 | Result: 533 | 534 | ```yaml 535 | pagination: 536 | next_key: null 537 | total: "1" 538 | withdraws: 539 | - executed: true 540 | msg: 541 | pool_coin: 542 | amount: "10000" 543 | denom: pool96EF6EA6E5AC828ED87E8D07E7AE2A8180570ADD212117B2DA6F0B75D17A6295 544 | pool_id: "1" 545 | withdrawer_address: cosmos1h6ht09xx0ue0fqmezk7msgqcc9k20a5x5ynvc3 546 | msg_height: "562" 547 | msg_index: "1" 548 | succeeded: true 549 | to_be_deleted: true 550 | ``` 551 | 552 | ### Withdraws 553 | 554 | > Query for all withdraw messages on the batch of the liquidity pool 555 | 556 | Example `withdraws` query command 557 | 558 | ```bash 559 | gaiad query liquidity withdraws 1 560 | ``` 561 | 562 | Result: 563 | 564 | ```yaml 565 | pagination: 566 | next_key: null 567 | total: "1" 568 | withdraws: 569 | - executed: true 570 | msg: 571 | pool_coin: 572 | amount: "10000" 573 | denom: pool96EF6EA6E5AC828ED87E8D07E7AE2A8180570ADD212117B2DA6F0B75D17A6295 574 | pool_id: "1" 575 | withdrawer_address: cosmos1h6ht09xx0ue0fqmezk7msgqcc9k20a5x5ynvc3 576 | msg_height: "562" 577 | msg_index: "1" 578 | succeeded: true 579 | to_be_deleted: true 580 | ``` 581 | 582 | ### Swap 583 | 584 | > Query for the swap message on the batch of the liquidity pool 585 | 586 | Example `swap` query command: 587 | 588 | ```bash 589 | gaiad query liquidity swaps 1 2 590 | ``` 591 | 592 | Result: 593 | 594 | ```json 595 | pagination: 596 | next_key: null 597 | total: "1" 598 | swaps: 599 | - exchanged_offer_coin: 600 | amount: "50000000" 601 | denom: uusd 602 | executed: true 603 | msg: 604 | demand_coin_denom: uatom 605 | offer_coin: 606 | amount: "50000000" 607 | denom: uusd 608 | offer_coin_fee: 609 | amount: "75000" 610 | denom: uusd 611 | order_price: "0.019000000000000000" 612 | pool_id: "1" 613 | swap_requester_address: cosmos1h6ht09xx0ue0fqmezk7msgqcc9k20a5x5ynvc3 614 | swap_type_id: 1 615 | msg_height: "178" 616 | msg_index: "1" 617 | order_expiry_height: "178" 618 | remaining_offer_coin: 619 | amount: "0" 620 | denom: uusd 621 | reserved_offer_coin_fee: 622 | amount: "0" 623 | denom: uusd 624 | succeeded: true 625 | to_be_deleted: true 626 | ``` 627 | 628 | ### Swaps 629 | 630 | > Query for all swap messages on the batch of the liquidity pool 631 | 632 | Example `swaps` query command: 633 | 634 | ```bash 635 | gaiad query liquidity swaps 1 636 | ``` 637 | 638 | Result: 639 | 640 | ```yaml 641 | pagination: 642 | next_key: null 643 | total: "1" 644 | swaps: 645 | - exchanged_offer_coin: 646 | amount: "50000000" 647 | denom: uusd 648 | executed: true 649 | msg: 650 | demand_coin_denom: uatom 651 | offer_coin: 652 | amount: "50000000" 653 | denom: uusd 654 | offer_coin_fee: 655 | amount: "75000" 656 | denom: uusd 657 | order_price: "0.019000000000000000" 658 | pool_id: "1" 659 | swap_requester_address: cosmos1h6ht09xx0ue0fqmezk7msgqcc9k20a5x5ynvc3 660 | swap_type_id: 1 661 | msg_height: "178" 662 | msg_index: "1" 663 | order_expiry_height: "178" 664 | remaining_offer_coin: 665 | amount: "0" 666 | denom: uusd 667 | reserved_offer_coin_fee: 668 | amount: "0" 669 | denom: uusd 670 | succeeded: true 671 | to_be_deleted: true 672 | ``` 673 | 674 | ### Error Codes 675 | 676 | For error codes with the description, see [errors.go](https://github.com/tendermint/liquidity/blob/develop/x/liquidity/types/errors.go). 677 | 678 | ### Find blocks through endblock_events 679 | 680 | - `curl "78.46.243.107:26657/block_search?query=\"swap_transacted.success='success'\""` 681 | - http://78.46.243.107:26657/block_search?query=%22swap_transacted.success=%27success%27%20AND%20swap_transacted.pool_id=%271%27%22 682 | - http://78.46.243.107:26657/block_search?query=%22swap_transacted.success=%27success%27%20AND%20swap_transacted.pool_id=%271%27%22 683 | - http://78.46.243.107:26657/block_results?height=7342649 684 | 685 | ### REST API 686 | 687 | A node exposes the REST server default port of 1317. Configure the port in [api] section of the app.toml file located in your $HOME/.liquidityd/config/ directory. When swagger param is set to true, you can open up your browser and check out the Swagger documentation in http://localhost:1317/swagger-liquidity/. You can also reference the public api documentation in [this link](https://app.swaggerhub.com/apis-docs/bharvest/cosmos-sdk_liquidity_module_rest_and_g_rpc_gateway_docs/). 688 | 689 | REST API Specs (swagger) 690 | 691 | - [Cosmos SDK](https://v1.cosmos.network/rpc/v0.42.6) 692 | - [Gravity DEX](https://v1.cosmos.network/rpc/gravity-dex) 693 | - [IBC](https://v1.cosmos.network/rpc/ibc) 694 | 695 | ## Transaction Information 696 | 697 | With the exception of creating the liquidity pool, all commands are implemented to execute on the batch. 698 | 699 | ### MsgCreatePool 700 | 701 | > Create liquidity pool 702 | 703 | Example `create-pool` tx command: 704 | 705 | ```bash 706 | gaiad tx liquidity create-pool 1 1000000000uatom,50000000000uusd --from user1 --keyring-backend test --chain-id testing -y 707 | ``` 708 | 709 | JSON Structure: 710 | 711 | ```json 712 | { 713 | "body": { 714 | "messages": [ 715 | { 716 | "@type": "/tendermint.liquidity.MsgCreatePool", 717 | "pool_creator_address": "cosmos1s6cjfm4djg95jkzsfe490yfc9k6wazx6culyft", 718 | "pool_type_id": 1, 719 | "deposit_coins": [ 720 | { 721 | "denom": "uatom", 722 | "amount": "1000000000" 723 | }, 724 | { 725 | "denom": "uusd", 726 | "amount": "50000000000" 727 | } 728 | ] 729 | } 730 | ], 731 | "memo": "", 732 | "timeout_height": "0", 733 | "extension_options": [], 734 | "non_critical_extension_options": [] 735 | }, 736 | "auth_info": { 737 | "signer_infos": [], 738 | "fee": { 739 | "amount": [], 740 | "gas_limit": "200000", 741 | "payer": "", 742 | "granter": "" 743 | } 744 | }, 745 | "signatures": [] 746 | } 747 | 748 | ``` 749 | 750 | Result 751 | 752 | ```json 753 | { 754 | "height": "5", 755 | "txhash": "C326C06CFB50589F72CBACD6F0028EE00B94F259C869D55653CEE11208531496", 756 | "codespace": "", 757 | "code": 0, 758 | "data": "0A0D0A0B6372656174655F706F6F6C", 759 | "raw_log": "...", 760 | "logs": [ 761 | { 762 | "msg_index": 0, 763 | "log": "", 764 | "events": [ 765 | { 766 | "type": "create_pool", 767 | "attributes": [ 768 | { 769 | "key": "pool_id", 770 | "value": "1" 771 | }, 772 | { 773 | "key": "pool_type_id", 774 | "value": "1" 775 | }, 776 | { 777 | "key": "pool_name", 778 | "value": "uatom/uusd/1" 779 | }, 780 | { 781 | "key": "reserve_account", 782 | "value": "cosmos1jmhkafh94jpgakr735r70t32sxq9wzkayzs9we" 783 | }, 784 | { 785 | "key": "deposit_coins", 786 | "value": "1000000000uatom,50000000000uusd" 787 | }, 788 | { 789 | "key": "pool_coin_denom", 790 | "value": "pool96EF6EA6E5AC828ED87E8D07E7AE2A8180570ADD212117B2DA6F0B75D17A6295" 791 | } 792 | ] 793 | }, 794 | { 795 | "type": "message", 796 | "attributes": [ 797 | { 798 | "key": "action", 799 | "value": "create_pool" 800 | }, 801 | { 802 | "key": "sender", 803 | "value": "cosmos1s6cjfm4djg95jkzsfe490yfc9k6wazx6culyft" 804 | }, 805 | { 806 | "key": "sender", 807 | "value": "cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962" 808 | }, 809 | { 810 | "key": "sender", 811 | "value": "cosmos1s6cjfm4djg95jkzsfe490yfc9k6wazx6culyft" 812 | }, 813 | { 814 | "key": "module", 815 | "value": "liquidity" 816 | } 817 | ] 818 | }, 819 | { 820 | "type": "transfer", 821 | "attributes": [ 822 | { 823 | "key": "recipient", 824 | "value": "cosmos1jmhkafh94jpgakr735r70t32sxq9wzkayzs9we" 825 | }, 826 | { 827 | "key": "amount", 828 | "value": "1000000000uatom,50000000000uusd" 829 | }, 830 | { 831 | "key": "recipient", 832 | "value": "cosmos1s6cjfm4djg95jkzsfe490yfc9k6wazx6culyft" 833 | }, 834 | { 835 | "key": "amount", 836 | "value": "1000000pool96EF6EA6E5AC828ED87E8D07E7AE2A8180570ADD212117B2DA6F0B75D17A6295" 837 | }, 838 | { 839 | "key": "recipient", 840 | "value": "cosmos1jv65s3grqf6v6jl3dp4t6c9t9rk99cd88lyufl" 841 | }, 842 | { 843 | "key": "sender", 844 | "value": "cosmos1s6cjfm4djg95jkzsfe490yfc9k6wazx6culyft" 845 | }, 846 | { 847 | "key": "amount", 848 | "value": "100000000stake" 849 | } 850 | ] 851 | } 852 | ] 853 | } 854 | ], 855 | "info": "", 856 | "gas_wanted": "200000", 857 | "gas_used": "163716", 858 | "tx": null, 859 | "timestamp": "" 860 | } 861 | ``` 862 | 863 | ### MsgDepositWithinBatch 864 | 865 | > Deposit to the liquidity pool batch 866 | 867 | Example `deposit` tx command: 868 | 869 | ```bash 870 | gaiad tx liquidity deposit 1 100000000uatom,5000000000uusd --from validator --keyring-backend test --chain-id testing -y 871 | ``` 872 | 873 | JSON Structure: 874 | 875 | ```json 876 | { 877 | "body": { 878 | "messages": [ 879 | { 880 | "@type": "/tendermint.liquidity.MsgDepositWithinBatch", 881 | "depositor_address": "cosmos1h6ht09xx0ue0fqmezk7msgqcc9k20a5x5ynvc3", 882 | "pool_id": "1", 883 | "deposit_coins": [ 884 | { 885 | "denom": "uatom", 886 | "amount": "100000000" 887 | }, 888 | { 889 | "denom": "uusd", 890 | "amount": "5000000000" 891 | } 892 | ] 893 | } 894 | ], 895 | "memo": "", 896 | "timeout_height": "0", 897 | "extension_options": [], 898 | "non_critical_extension_options": [] 899 | }, 900 | "auth_info": { 901 | "signer_infos": [], 902 | "fee": { 903 | "amount": [], 904 | "gas_limit": "200000", 905 | "payer": "", 906 | "granter": "" 907 | } 908 | }, 909 | "signatures": [] 910 | } 911 | ``` 912 | 913 | Result: 914 | 915 | ```json 916 | { 917 | "height": "458", 918 | "txhash": "8D8FA31125AB2A984D28F362ADC05946208C0E7927B13F984D9AD6E8E5327782", 919 | "codespace": "", 920 | "code": 0, 921 | "data": "0A160A146465706F7369745F77697468696E5F6261746368", 922 | "raw_log": "...", 923 | "logs": [ 924 | { 925 | "msg_index": 0, 926 | "log": "", 927 | "events": [ 928 | { 929 | "type": "deposit_within_batch", 930 | "attributes": [ 931 | { 932 | "key": "pool_id", 933 | "value": "1" 934 | }, 935 | { 936 | "key": "batch_index", 937 | "value": "1" 938 | }, 939 | { 940 | "key": "msg_index", 941 | "value": "1" 942 | }, 943 | { 944 | "key": "deposit_coins", 945 | "value": "100000000uatom,5000000000uusd" 946 | } 947 | ] 948 | }, 949 | { 950 | "type": "message", 951 | "attributes": [ 952 | { 953 | "key": "action", 954 | "value": "deposit_within_batch" 955 | }, 956 | { 957 | "key": "sender", 958 | "value": "cosmos1h6ht09xx0ue0fqmezk7msgqcc9k20a5x5ynvc3" 959 | }, 960 | { 961 | "key": "module", 962 | "value": "liquidity" 963 | } 964 | ] 965 | }, 966 | { 967 | "type": "transfer", 968 | "attributes": [ 969 | { 970 | "key": "recipient", 971 | "value": "cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962" 972 | }, 973 | { 974 | "key": "sender", 975 | "value": "cosmos1h6ht09xx0ue0fqmezk7msgqcc9k20a5x5ynvc3" 976 | }, 977 | { 978 | "key": "amount", 979 | "value": "100000000uatom,5000000000uusd" 980 | } 981 | ] 982 | } 983 | ] 984 | } 985 | ], 986 | "info": "", 987 | "gas_wanted": "200000", 988 | "gas_used": "79385", 989 | "tx": null, 990 | "timestamp": "" 991 | } 992 | ``` 993 | 994 | ### MsgWithdrawWithinBatch 995 | 996 | > Withdraw pool coin from the liquidity pool 997 | 998 | Example `withdraw` tx command: 999 | 1000 | ```bash 1001 | gaiad tx liquidity withdraw 1 10000pool96EF6EA6E5AC828ED87E8D07E7AE2A8180570ADD212117B2DA6F0B75D17A6295 --from validator --chain-id testing --keyring-backend test -y 1002 | ``` 1003 | 1004 | JSON Structure 1005 | 1006 | ```json 1007 | { 1008 | "body": { 1009 | "messages": [ 1010 | { 1011 | "@type": "/tendermint.liquidity.MsgWithdrawWithinBatch", 1012 | "withdrawer_address": "cosmos1h6ht09xx0ue0fqmezk7msgqcc9k20a5x5ynvc3", 1013 | "pool_id": "1", 1014 | "pool_coin": { 1015 | "denom": "pool96EF6EA6E5AC828ED87E8D07E7AE2A8180570ADD212117B2DA6F0B75D17A6295", 1016 | "amount": "10000" 1017 | } 1018 | } 1019 | ], 1020 | "memo": "", 1021 | "timeout_height": "0", 1022 | "extension_options": [], 1023 | "non_critical_extension_options": [] 1024 | }, 1025 | "auth_info": { 1026 | "signer_infos": [], 1027 | "fee": { 1028 | "amount": [], 1029 | "gas_limit": "200000", 1030 | "payer": "", 1031 | "granter": "" 1032 | } 1033 | }, 1034 | "signatures": [] 1035 | } 1036 | 1037 | ``` 1038 | 1039 | Result: 1040 | 1041 | ```json 1042 | { 1043 | "height": "562", 1044 | "txhash": "BE8827F69E8BC5909A0FFC713B6D267606A91A1CFA07552E69020638E9E1D563", 1045 | "codespace": "", 1046 | "code": 0, 1047 | "data": "0A170A1577697468647261775F77697468696E5F6261746368", 1048 | "raw_log": "...", 1049 | "logs": [ 1050 | { 1051 | "msg_index": 0, 1052 | "log": "", 1053 | "events": [ 1054 | { 1055 | "type": "message", 1056 | "attributes": [ 1057 | { 1058 | "key": "action", 1059 | "value": "withdraw_within_batch" 1060 | }, 1061 | { 1062 | "key": "sender", 1063 | "value": "cosmos1h6ht09xx0ue0fqmezk7msgqcc9k20a5x5ynvc3" 1064 | }, 1065 | { 1066 | "key": "module", 1067 | "value": "liquidity" 1068 | } 1069 | ] 1070 | }, 1071 | { 1072 | "type": "transfer", 1073 | "attributes": [ 1074 | { 1075 | "key": "recipient", 1076 | "value": "cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962" 1077 | }, 1078 | { 1079 | "key": "sender", 1080 | "value": "cosmos1h6ht09xx0ue0fqmezk7msgqcc9k20a5x5ynvc3" 1081 | }, 1082 | { 1083 | "key": "amount", 1084 | "value": "10000pool96EF6EA6E5AC828ED87E8D07E7AE2A8180570ADD212117B2DA6F0B75D17A6295" 1085 | } 1086 | ] 1087 | }, 1088 | { 1089 | "type": "withdraw_within_batch", 1090 | "attributes": [ 1091 | { 1092 | "key": "pool_id", 1093 | "value": "1" 1094 | }, 1095 | { 1096 | "key": "batch_index", 1097 | "value": "2" 1098 | }, 1099 | { 1100 | "key": "msg_index", 1101 | "value": "1" 1102 | }, 1103 | { 1104 | "key": "pool_coin_denom", 1105 | "value": "pool96EF6EA6E5AC828ED87E8D07E7AE2A8180570ADD212117B2DA6F0B75D17A6295" 1106 | }, 1107 | { 1108 | "key": "pool_coin_amount", 1109 | "value": "10000" 1110 | } 1111 | ] 1112 | } 1113 | ] 1114 | } 1115 | ], 1116 | "info": "", 1117 | "gas_wanted": "200000", 1118 | "gas_used": "67701", 1119 | "tx": null, 1120 | "timestamp": "" 1121 | } 1122 | ``` 1123 | 1124 | ### MsgSwapWithinBatch 1125 | 1126 | > Swap offer coin with demand coin from the liquidity pool with the given order price 1127 | 1128 | Example `swap` tx command: 1129 | 1130 | ```bash 1131 | gaiad tx liquidity swap 1 1 50000000uusd uatom 0.019 0.003 --from validator --chain-id testing --keyring-backend test -y 1132 | ``` 1133 | 1134 | JSON Structure: 1135 | 1136 | ```json 1137 | { 1138 | "body": { 1139 | "messages": [ 1140 | { 1141 | "@type": "/tendermint.liquidity.MsgSwapWithinBatch", 1142 | "swap_requester_address": "cosmos1h6ht09xx0ue0fqmezk7msgqcc9k20a5x5ynvc3", 1143 | "pool_id": "1", 1144 | "swap_type_id": 1, 1145 | "offer_coin": { 1146 | "denom": "uusd", 1147 | "amount": "50000000" 1148 | }, 1149 | "demand_coin_denom": "uatom", 1150 | "offer_coin_fee": { 1151 | "denom": "uusd", 1152 | "amount": "75000" 1153 | }, 1154 | "order_price": "0.019000000000000000" 1155 | } 1156 | ], 1157 | "memo": "", 1158 | "timeout_height": "0", 1159 | "extension_options": [], 1160 | "non_critical_extension_options": [] 1161 | }, 1162 | "auth_info": { 1163 | "signer_infos": [], 1164 | "fee": { 1165 | "amount": [], 1166 | "gas_limit": "200000", 1167 | "payer": "", 1168 | "granter": "" 1169 | } 1170 | }, 1171 | "signatures": [] 1172 | } 1173 | ``` 1174 | 1175 | Result: 1176 | 1177 | ```json 1178 | { 1179 | "height": "178", 1180 | "txhash": "AA9A3A50D9AC639730F61824AA2BD3BA9EBCCEA7E52147353C0E680041F21243", 1181 | "codespace": "", 1182 | "code": 0, 1183 | "data": "0A130A11737761705F77697468696E5F6261746368", 1184 | "raw_log": "...", 1185 | "logs": [ 1186 | { 1187 | "msg_index": 0, 1188 | "log": "", 1189 | "events": [ 1190 | { 1191 | "type": "message", 1192 | "attributes": [ 1193 | { 1194 | "key": "action", 1195 | "value": "swap_within_batch" 1196 | }, 1197 | { 1198 | "key": "sender", 1199 | "value": "cosmos1h6ht09xx0ue0fqmezk7msgqcc9k20a5x5ynvc3" 1200 | }, 1201 | { 1202 | "key": "sender", 1203 | "value": "cosmos1h6ht09xx0ue0fqmezk7msgqcc9k20a5x5ynvc3" 1204 | }, 1205 | { 1206 | "key": "module", 1207 | "value": "liquidity" 1208 | } 1209 | ] 1210 | }, 1211 | { 1212 | "type": "swap_within_batch", 1213 | "attributes": [ 1214 | { 1215 | "key": "pool_id", 1216 | "value": "1" 1217 | }, 1218 | { 1219 | "key": "batch_index", 1220 | "value": "1" 1221 | }, 1222 | { 1223 | "key": "msg_index", 1224 | "value": "1" 1225 | }, 1226 | { 1227 | "key": "swap_type_id", 1228 | "value": "1" 1229 | }, 1230 | { 1231 | "key": "offer_coin_denom", 1232 | "value": "uusd" 1233 | }, 1234 | { 1235 | "key": "offer_coin_amount", 1236 | "value": "50000000" 1237 | }, 1238 | { 1239 | "key": "offer_coin_fee_amount", 1240 | "value": "75000" 1241 | }, 1242 | { 1243 | "key": "demand_coin_denom", 1244 | "value": "uatom" 1245 | }, 1246 | { 1247 | "key": "order_price", 1248 | "value": "0.019000000000000000" 1249 | } 1250 | ] 1251 | }, 1252 | { 1253 | "type": "transfer", 1254 | "attributes": [ 1255 | { 1256 | "key": "recipient", 1257 | "value": "cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962" 1258 | }, 1259 | { 1260 | "key": "sender", 1261 | "value": "cosmos1h6ht09xx0ue0fqmezk7msgqcc9k20a5x5ynvc3" 1262 | }, 1263 | { 1264 | "key": "amount", 1265 | "value": "50000000uusd" 1266 | }, 1267 | { 1268 | "key": "recipient", 1269 | "value": "cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962" 1270 | }, 1271 | { 1272 | "key": "sender", 1273 | "value": "cosmos1h6ht09xx0ue0fqmezk7msgqcc9k20a5x5ynvc3" 1274 | }, 1275 | { 1276 | "key": "amount", 1277 | "value": "75000uusd" 1278 | } 1279 | ] 1280 | } 1281 | ] 1282 | } 1283 | ], 1284 | "info": "", 1285 | "gas_wanted": "200000", 1286 | "gas_used": "95327", 1287 | "tx": null, 1288 | "timestamp": "" 1289 | } 1290 | ``` 1291 | 1292 | ### Error codes 1293 | 1294 | For error codes with the description, see [errors.go](https://github.com/tendermint/liquidity/blob/develop/x/liquidity/types/errors.go). 1295 | 1296 | ### Broadcast tx through REST API 1297 | 1298 | The POST endpoints of the new gGPC-gateway REST are not available. The [Migrating to New REST Endpoints](https://docs.cosmos.network/master/migrations/rest.html#migrating-to-new-rest-endpoints) Cosmos SDK guide suggests to use Protobuf directly. You can use the command line interface or use the temporarily available REST API at `localhost:1317/cosmos/tx/v1beta1/txs`. 1299 | 1300 | For example, to broadcast a transaction by using the [New gRPC-gateway REST Endpoint](https://github.com/cosmos/cosmos-sdk/blob/master/docs/migrations/rest.md#migrating-to-new-rest-endpoints): 1301 | 1302 | ```bash 1303 | curl --header "Content-Type: application/json" --request POST --data '{"tx_bytes":"CoMBCoABCh0vdGVuZGVybWludC5saXF1aWRpdHkuTXNnU3dhcBJfCi1jb3Ntb3MxN3dncHpyNGd2YzN1aHBmcnUyNmVhYTJsc203NzJlMnEydjBtZXgQAhgBIAEqDQoFc3Rha2USBDEwMDAyBGF0b206EzExNTAwMDAwMDAwMDAwMDAwMDASWApQCkYKHy9jb3Ntb3MuY3J5cHRvLnNlY3AyNTZrMS5QdWJLZXkSIwohAqzfoAEi0cFg0zqwBuGNvHml4XJNS3EQuVti8/yGH88NEgQKAgh/GAgSBBDAmgwaQGTRN67x2WYF/L5DsRD3ZY1Kt9cVpg3rW+YbXtihxcB6bJWhMxuFr0u9SnGkCuAgOuLH9YU8ROFUo1gGS1RpTz0=","mode":1}' localhost:1317/cosmos/tx/v1beta1/txs 1304 | ``` 1305 | 1306 | ## Calculations 1307 | 1308 | ### Pool Price 1309 | 1310 | Each pair of tokens in a pool has a pool price defined by the reserves of that pair of tokens. 1311 | 1312 | ![pool price gravity dex](https://user-images.githubusercontent.com/20435620/129909416-38f133e9-bdbe-4a0d-971e-9c73f88c7da2.png) 1313 | 1314 | Example 1315 | 1316 | Let's get pool 1 information 1317 | 1318 | [http://116.202.170.226:1317/cosmos/liquidity/v1beta1/pools/1](http://116.202.170.226:1317/cosmos/liquidity/v1beta1/pools/1) 1319 | 1320 | ```json 1321 | { 1322 | "pool": { 1323 | "id": "1", 1324 | "type_id": 1, 1325 | "reserve_coin_denoms": [ 1326 | "ibc/14F9BC3E44B8A9C1BE1FB08980FAB87034C9905EF17CF2F5008FC085218811CC", 1327 | "uatom" 1328 | ], 1329 | "reserve_account_address": "cosmos1m7uyxn26sz6w4755k6rch4dc2fj6cmzajkszvn", 1330 | "pool_coin_denom": "poolDFB8434D5A80B4EAFA94B6878BD5B85265AC6C5D37204AB899B1C3C52543DA7E" 1331 | } 1332 | } 1333 | ``` 1334 | 1335 | Use the reserve_account_address to get reserve coin amounts 1336 | 1337 | [http://116.202.170.226:1317/cosmos/bank/v1beta1/balances/cosmos1m7uyxn26sz6w4755k6rch4dc2fj6cmzajkszvn](http://116.202.170.226:1317/cosmos/bank/v1beta1/balances/cosmos1m7uyxn26sz6w4755k6rch4dc2fj6cmzajkszvn) 1338 | 1339 | ```json 1340 | { 1341 | "balances": [ 1342 | { 1343 | "denom": "ibc/14F9BC3E44B8A9C1BE1FB08980FAB87034C9905EF17CF2F5008FC085218811CC", 1344 | "amount": "60727676783" 1345 | }, 1346 | { 1347 | "denom": "uatom", 1348 | "amount": "9018280896" 1349 | } 1350 | ], 1351 | "pagination": { 1352 | "next_key": null, 1353 | "total": "2" 1354 | } 1355 | } 1356 | ``` 1357 | 1358 | ### Expected Swap Price 1359 | 1360 | When users swap tokens in the pool, they want to know how much the expected swap price is. Here, the expected swap price is the price considering slippage. (swap fees are not considered) 1361 | 1362 | ![Expected Swap Price Gravity DEX](https://user-images.githubusercontent.com/20435620/129909554-f514ba87-4957-437a-9310-66437c757a3f.png) 1363 | 1364 | ### Expected Swap Amount 1365 | 1366 | For practical purposes, users also would like to know what amount of tokens they will receive at a specific price. 1367 | 1368 | - If users want to swap X token to Y token, the swap price has to be higher than current pool price. The amount of X token they will provide to pool and the amount of Y token they will receive are below. 1369 | 1370 | ![Expected Swap Amount Gravity DEX 1](https://user-images.githubusercontent.com/20435620/129909665-09271783-2077-49e2-a369-8fe677b407b5.png) 1371 | 1372 | 1373 | - Reversely, if users want to swap Y token to X token, the swap price has to be lower than current pool price. The amount of Y token they will provide to pool and the amount of X token they will receive are below. 1374 | 1375 | ![Expected Swap Amount Gravity DEX 2](https://user-images.githubusercontent.com/20435620/129909752-fa24fae5-8ade-49fd-acff-988d33af500f.png) 1376 | 1377 | ## 5. Liquidity Params 1378 | 1379 | Query liquidity parameters using cli 1380 | 1381 | ```bash 1382 | gaiad query liquidity params --output json 1383 | ``` 1384 | 1385 | Query liquidity parameters using REST API 1386 | 1387 | - {API-SERVER}/cosmos/liquidity/v1beta1/params 1388 | - ex) [http://116.202.170.226:1317/cosmos/liquidity/v1beta1/params](http://116.202.170.226:1317/cosmos/liquidity/v1beta1/params) 1389 | 1390 | ### Current parameter value for the mainnet 1391 | 1392 | (cosmoshub-4, height 7,270,000) 1393 | 1394 | ```json 1395 | { 1396 | "params": { 1397 | "pool_types": [ 1398 | { 1399 | "id": 1, 1400 | "name": "StandardLiquidityPool", 1401 | "min_reserve_coin_num": 2, 1402 | "max_reserve_coin_num": 2, 1403 | "description": "Standard liquidity pool with pool price function X/Y, ESPM constraint, and two kinds of reserve coins" 1404 | } 1405 | ], 1406 | "min_init_deposit_amount": "1000000", 1407 | "init_pool_coin_mint_amount": "1000000", 1408 | "max_reserve_coin_amount": "0", 1409 | "pool_creation_fee": [ 1410 | { 1411 | "denom": "uatom", 1412 | "amount": "40000000" 1413 | } 1414 | ], 1415 | "swap_fee_rate": "0.003000000000000000", 1416 | "withdraw_fee_rate": "0.000000000000000000", 1417 | "max_order_amount_ratio": "0.100000000000000000", 1418 | "unit_batch_height": 1, 1419 | "circuit_breaker_enabled": false 1420 | } 1421 | } 1422 | ``` 1423 | 1424 | ### MinInitDepositAmount 1425 | 1426 | Minimum number of coins to be deposited to the liquidity pool upon pool creation. 1427 | 1428 | ### InitPoolCoinMintAmount 1429 | 1430 | Initial mint amount of pool coin on pool creation. 1431 | 1432 | ### MaxReserveCoinAmount 1433 | 1434 | Limit the size of each liquidity pool. The deposit transaction fails if the total reserve coin amount after the deposit is larger than the reserve coin amount. 1435 | 1436 | The default value of zero means no limit. 1437 | 1438 | Note: Especially in the early phases of liquidity module adoption, set `MaxReserveCoinAmount` to a non-zero value to minimize risk on error or exploitation. 1439 | 1440 | ### PoolCreationFee 1441 | 1442 | Fee paid for to create a LiquidityPool creation. This fee prevents spamming and is collected in in the community pool of the distribution module. 1443 | 1444 | ### SwapFeeRate 1445 | 1446 | Swap fee rate for every executed swap. When a swap is requested, the swap fee is reserved: 1447 | 1448 | - Half reserved as `OfferCoinFee` 1449 | - Half reserved as `ExchangedCoinFee` 1450 | 1451 | The swap fee is collected when a batch is executed. 1452 | 1453 | ### WithdrawFeeRate 1454 | 1455 | Reserve coin withdrawal with less proportion by `WithdrawFeeRate`. This fee prevents attack vectors from repeated deposit/withdraw transactions. 1456 | 1457 | ### MaxOrderAmountRatio 1458 | 1459 | Maximum ratio of reserve coins that can be ordered at a swap order. 1460 | 1461 | ### UnitBatchHeight 1462 | 1463 | The smallest unit batch size for every liquidity pool. 1464 | 1465 | ### CircuitBreakerEnabled 1466 | 1467 | The intention of circuit breaker is to have a contingency plan for a running network which maintains network liveness. This parameter enables or disables all transaction message types in liquidity module. 1468 | 1469 | ## 6. Reference 1470 | 1471 | ### Sample Project 1472 | 1473 | - https://github.com/allinbits/gravity-dex-stats 1474 | 1475 | -------------------------------------------------------------------------------- /osmosis.md: -------------------------------------------------------------------------------- 1 | # Osmosis 2 | 3 | ## Table Of Contents 4 | 5 | * [Basic Node Operation](Basic-Node-Operation) 6 | * [Resources](#Resources) 7 | * [Hardware Requirements](#Hardware-Requirements) 8 | * [Install Go](#Install-Go) 9 | * [Install osmosisd from source](#Install-osmosisd-from-source) 10 | * [Setup](#Setup) 11 | * [Basic Configuration](#Basic-Configuration) 12 | * [State Sync](#State-Sync) 13 | * [Start](#Start) 14 | * [Calculations](Calculations) 15 | * [Pool Price](#Pool-Price) 16 | * [Expected Swap Price](#Expected-Swap-Price) 17 | * [Expected Swap Amount](#Expected-Swap-Amount) 18 | * [Find Arbitrage Opportunity](Find-Arbitrage-Opportunity) 19 | * [Global Price](#Global-Price) 20 | * [Pool Price](#Pool-Price) 21 | * [Expected Swap Price](#Expected-Swap-Price) 22 | * [Osmosis Params](Osmosis-Params) 23 | * [SwapFee](#SwapFee) 24 | * [ExitFee](#ExitFee) 25 | * [MinPoolAssets](#MinPoolAssets) 26 | * [MaxPoolAssets](#MaxPoolAssets) 27 | * [InitPoolSharesSupply](#InitPoolSharesSupply) 28 | * [References](References) 29 | * [Command-line Interface](#Command-line-Interface) 30 | 31 | ## Basic Node Operation 32 | 33 | ### Resources 34 | 35 | - [Official Repository](https://github.com/osmosis-labs/osmosis) 36 | - [Genesis file](https://github.com/osmosis-labs/networks/blob/main/osmosis-1/genesis.json) 37 | - [Setting Up a Genesis Osmosis Validator Guide](https://github.com/osmosis-labs/networks/blob/main/genesis-validators.md) 38 | - [Peers](https://github.com/osmosis-labs/networks/blob/main/peers.md) (Mainnet) 39 | 40 | ### Hardware Requirements 41 | 42 | At the time of writing this documentation, this is the recommended server specs by osmosis team. As the usage of the blockchain grows, the server requirements may increase as well. 43 | 44 | - 4 or more physical CPU cores 45 | - At least 500GB of SSD disk storage 46 | - At least 16GB of memory 47 | - At least 100mbps network bandwidth 48 | 49 | ### Install Go 50 | 51 | Osmosis is built using Go and requires Go version 1.15+. 52 | 53 | In this example, we will be installing Go on Ubuntu 18.04.2 LTS: 54 | 55 | ```bash 56 | # First remove any existing old Go installation 57 | sudo rm -rf /usr/local/go 58 | 59 | # Install the latest version of Go using this helpful script 60 | curl https://raw.githubusercontent.com/canha/golang-tools-install-script/master/goinstall.sh | bash 61 | 62 | # Update environment variables to include go 63 | cat <<'EOF' >>$HOME/.profile 64 | export GOROOT=/usr/local/go 65 | export GOPATH=$HOME/go 66 | export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin 67 | EOF 68 | 69 | source $HOME/.profile 70 | 71 | # Verify that Go is installed 72 | # Should return go version go1.16.4 linux/amd64 73 | go version 74 | ``` 75 | 76 | ### Install `osmosisd` from source 77 | 78 | ```bash 79 | # Clone the project 80 | # At the time of writing this guide, mainnet uses 3.1.0 version 81 | git clone -b v3.1.0 https://github.com/osmosis-labs/osmosis.git 82 | cd osmosis 83 | go mod tidy 84 | 85 | # Build osmosis node software "osmosisd" 86 | # This command will install the executable osmosis node daemon to your GOPATH 87 | make install 88 | 89 | # Verify the osmosisd version 90 | osmosisd version --long 91 | -> 92 | name: osmosis 93 | server_name: osmosisd 94 | version: 3.1.0 95 | commit: 13916d1e10bca718b6ea7f4b84715710bc319e6d 96 | build_tags: netgo,ledger 97 | go: go version go1.16.3 linux/amd64 98 | ``` 99 | 100 | ### Setup 101 | 102 | 1. Initialize the chain 103 | 104 | ```bash 105 | # (Recommend) Save chain id in osmosisd config 106 | # 107 | # This command will save the chain id into your client.toml which is located 108 | # in your home directory (default: $HOME/.osmosisd/config/client.toml) 109 | osmosisd config chain-id osmosis-1 110 | 111 | # Initialize chain 112 | # 113 | # Replace for the public alias of your node (you can edit moniker later) 114 | # Example: osmosisd init testnode --chain-id osmosis-1 115 | # This will create a new $HOME/.osmosisd folder in your HOME directory 116 | osmosisd init --chain-id=osmosis-1 117 | ``` 118 | 119 | 2. Fetch the mainnet's genesis file 120 | 121 | [https://github.com/osmosis-labs/networks/blob/main/osmosis-1/genesis.json](https://github.com/osmosis-labs/networks/blob/main/osmosis-1/genesis.json) 122 | 123 | ```bash 124 | wget -O $HOME/.osmosisd/config/genesis.json https://github.com/osmosis-labs/networks/raw/main/osmosis-1/genesis.json 125 | ``` 126 | 127 | ### Basic Configuration 128 | 129 | 1. Manually add the below peers list in your `$HOME/.osmosisd/config/config.toml` file. You can find the peers list in [this link](https://github.com/osmosis-labs/networks/blob/main/peers.md). Since IBC and swap state transactions are very large, it is suggested to increase the timeout for a transaction to be committed and maximum size of request body and header. Without configuring those values, you may experience the node to stop from time to time when your node receives too many requests. 130 | 131 | ```bash 132 | seeds = "8f67a2fcdd7ade970b1983bf1697111d35dfdd6f@52.79.199.137:26656,00c328a33578466c711874ec5ee7ada75951f99a@35.82.201.64:26656,cfb6f2d686014135d4a6034aa6645abd0020cac6@52.79.88.57:26656,8d9967d5f865c68f6fe2630c0f725b0363554e77@134.255.252.173:26656,785bc83577e3980545bac051de8f57a9fd82695f@194.233.164.146:26656,778fdedf6effe996f039f22901a3360bc838b52e@161.97.187.189:36657,64d36f3a186a113c02db0cf7c588c7c85d946b5b@209.97.132.170:26656,4d9ac3510d9f5cfc975a28eb2a7b8da866f7bc47@37.187.38.191:26656,2115945f074ddb038de5d835e287fa03e32f0628@95.217.43.85:26656,bf2c480eff178d2647ba1adfeee8ced568fe752c@91.65.128.44:26656,2f9c16151400d8516b0f58c030b3595be20b804c@37.120.245.167:26656,bada684070727cb3dda430bcc79b329e93399665@173.212.240.91:26656,83adaa38d1c15450056050fd4c9763fcc7e02e2c@ec2-44-234-84-104.us-west-2.compute.amazonaws.com:26656,23142ab5d94ad7fa3433a889dcd3c6bb6d5f247d@95.217.193.163:26656,f82d1a360dc92d4e74fdc2c8e32f4239e59aebdf@95.217.121.243:26656,e437756a853061cc6f1639c2ac997d9f7e84be67@144.76.183.180:26656,3fea02d121cb24503d5fbc53216a527257a9ab55@143.198.145.208:26656,7024d1ca024d5e33e7dc1dcb5ed08349768220b9@134.122.42.20:26656,d326ad6dffa7763853982f334022944259b4e7f4@143.110.212.33:26656,e7916387e05acd53d1b8c0f842c13def365c7bb6@176.9.64.212:26666,55eea69c21b46000c1594d8b4a448563b075d9e3@34.107.19.235:26656,9faf468b90a3b2b85ffd88645a15b3715f68bb0b@195.201.122.100:26656,ffc82412c0261a94df122b9cc0ce1de81da5246b@15.222.240.16:26656,5b90a530464885fd28c31f698c81694d0b4a1982@35.183.238.70:26656,7b6689cb18d625bbc069aa99d9d5521293db442c@51.158.97.192:26656,fda06dcebe2acd17857a6c9e9a7b365da3771ceb@52.206.252.176:26656,b4592eea84652e565b464cada03279dc4aac618c@177.66.42.189:26656" 133 | 134 | # The ibc and swap state are very large, causing the node itself 135 | # to stop on excessive queries. Therefore, we customize the rpc configuration 136 | # as above. 137 | 138 | # How long to wait for a tx to be committed during /broadcast_tx_commit. 139 | # WARNING: Using a value larger than 10s will result in increasing the 140 | # global HTTP write timeout, which applies to all connections and endpoints. 141 | # See https://github.com/tendermint/tendermint/issues/3435 142 | timeout_broadcast_tx_commit = "600s" 143 | 144 | # Maximum size of request body, in bytes 145 | max_body_bytes = 10000000 146 | 147 | # Maximum size of request header, in bytes 148 | max_header_bytes = 10485760 149 | ``` 150 | 151 | 2. Replace necessary configuration 152 | 153 | ```bash 154 | sed -i '' 's#"tcp://127.0.0.1:26657"#"tcp://0.0.0.0:26657"#g' $HOME/.osmosisd/config/config.toml 155 | sed -i '' 's/enable = false/enable = true/g' $HOME/.osmosisd/config/config.toml 156 | sed -i '' 's/swagger = false/swagger = true/g' $HOME/.osmosisd/config/config.toml 157 | ``` 158 | 159 | ### State Sync 160 | 161 | State sync allows a new node to join a network by fetching a snapshot of the application state at a recent height instead of fetching and replaying all historical blocks. This can reduce the time needed to sync with the network from days to minutes. Reference [this article](https://blog.cosmos.network/cosmos-sdk-state-sync-guide-99e4cf43be2f) to know more about Cosmos SDK state sync. 162 | 163 | **Option 1. Setup using state synced data dump** 164 | 165 | - You can follow [this guide](https://osmosis.quicksync.io/) operated by ChainLayer 166 | 167 | **Option 2. State sync via snapshot supply nodes** 168 | 169 | 1. snapshot supply nodes (2 node setting- Block must be at the latest height) 170 | 171 | Manually add the below setting in `$HOME/.osmosisd/config/app.toml` file. 172 | 173 | ```bash 174 | ############################################################################### 175 | ### State Sync Configuration ### 176 | ############################################################################### 177 | 178 | # State sync snapshots allow other nodes to rapidly join the network without replaying historical 179 | # blocks, instead downloading and applying a snapshot of the application state at a given height. 180 | [state-sync] 181 | 182 | # snapshot-interval specifies the block interval at which local state sync snapshots are 183 | # taken (0 to disable). Must be a multiple of pruning-keep-every. 184 | snapshot-interval = 100 185 | 186 | # snapshot-keep-recent specifies the number of recent snapshots to keep and serve (0 to keep all). 187 | snapshot-keep-recent = 2 188 | ``` 189 | 190 | 2. Node to receive snapshot (1 node that needs to sync) 191 | 192 | Manually change the state sync values in your `$HOME/.osmosisd/config/app.toml` file. 193 | 194 | (Set the peers list as well) 195 | 196 | `#"snapshot-interval = 100, snapshot-keep-recent = 2" → lastblock - 100 = trust_height` 197 | 198 | ```bash 199 | curl -s http:///block?height=7270300 | jq -r '.result.block.header.height + "\n" + .result.block_id.hash' 200 | ``` 201 | 202 | ```bash 203 | [statesync] 204 | # State sync rapidly bootstraps a new node by discovering, fetching, and restoring a state machine 205 | # snapshot from peers instead of fetching and replaying historical blocks. Requires some peers in 206 | # the network to take and serve state machine snapshots. State sync is not attempted if the node 207 | # has any local state (LastBlockHeight > 0). The node will have a truncated block history, 208 | # starting from the height of the snapshot. 209 | enable = true 210 | 211 | # RPC servers (comma-separated) for light client verification of the synced state machine and 212 | # retrieval of state data for node bootstrapping. Also needs a trusted height and corresponding 213 | # header hash obtained from a trusted source, and a period during which validators can be trusted. 214 | # 215 | # For Cosmos SDK-based chains, trust_period should usually be about 2/3 of the unbonding time (~2 216 | # weeks) during which they can be financially punished (slashed) for misbehavior. 217 | rpc_servers = "http://,http://" 218 | trust_height = 7270300 219 | trust_hash = "" 220 | trust_period = "336h" 221 | 222 | # Time to spend discovering snapshots before initiating a restore. 223 | discovery_time = "15s" 224 | 225 | # Temporary directory for state sync snapshot chunks, defaults to the OS tempdir (typically /tmp). 226 | # Will create a new, randomly named directory within, and remove it when done. 227 | temp_dir = "" 228 | ``` 229 | 230 | - `osmosisd start` 231 | 232 | If you see log like this, it's going well. 233 | 234 | ```bash 235 | 7:11PM INF Fetching snapshot chunk chunk=7 format=1 height=7271000 module=statesync total=33 236 | 7:11PM INF Applied snapshot chunk to ABCI app chunk=3 format=1 height=7271000 module=statesync total=33 237 | 238 | ... 239 | 240 | 7:15PM INF executed block height=7271024 module=state num_invalid_txs=0 num_valid_txs=0 241 | 7:15PM INF commit synced commit=436F6D6D697449447B5B313130203439203133392031353420313336203235342032303620313439203134203230352031323420313033203134322031392039392032303020313536203130372032392031343520313137203232362036342033372031333220343320323433203834203131392032313320323331203133355D3A3645463237307D 242 | 7:15PM INF committed state app_hash=6E318B9A88FECE950ECD7C678E1363C89C6B1D9175E24025842BF35477D5E787 height=7271024 module=state num_txs=0 243 | 7:15PM INF indexed block height=7271024 module=txindex 244 | 7:15PM INF minted coins from module account amount=4453682uatom from=mint module=x/bank 245 | 7:15PM INF executed block height=7271025 module=state num_invalid_txs=0 num_valid_txs=0 246 | 7:15PM INF commit synced commit=436F6D6D697449447B5B3233312039372032333720313738203230392031333020323435203431203234332039203139362032343620313036203231392031393920393120343220313732203234372031313120313632203238203738203631203232392033312036322035352032333620363420323237203233335D3A3645463237317D 247 | 7:15PM INF committed state app_hash=E761EDB2D182F529F309C4F66ADBC75B2AACF76FA21C4E3DE51F3E37EC40E3E9 height=7271025 module=state num_txs=0 248 | 7:15PM INF indexed block height=7271025 module=txindex 249 | ``` 250 | 251 | - When the sync is complete, set it up as follows: 252 | 253 | ```bash 254 | [statesync] 255 | # State sync rapidly bootstraps a new node by discovering, fetching, and restoring a state machine 256 | # snapshot from peers instead of fetching and replaying historical blocks. Requires some peers in 257 | # the network to take and serve state machine snapshots. State sync is not attempted if the node 258 | # has any local state (LastBlockHeight > 0). The node will have a truncated block history, 259 | # starting from the height of the snapshot. 260 | enable = false 261 | ``` 262 | ### Start 263 | 264 | Wait for at least 10 minutes to connect with peers. If you continue to see dialing peers in logs, then there may not be a single node that accepts connection. You need to find working peers by joining Osmosis [Discord](https://discord.com/invite/osmosis) and ask for it. 265 | 266 | Simple way to start 267 | 268 | ```bash 269 | osmosisd start 270 | ``` 271 | 272 | Use `systemd service` to start 273 | 274 | ```json 275 | sudo tee /etc/systemd/system/osmosisd.service > /dev/null < 550 | 551 | ```bash 552 | # Command-line Interface 553 | osmosisd q gamm pool 1 --output json | jq 554 | 555 | # REST API 556 | http://localhost:1317/osmosis/gamm/v1beta1/pools/1 557 | ``` 558 | 559 | ```json 560 | { 561 | "pools": [ 562 | { 563 | "@type": "/osmosis.gamm.v1beta1.Pool", 564 | "address": "osmo1500hy75krs9e8t50aav6fahk8sxhajn9ctp40qwvvn8tcprkk6wszun4a5", 565 | "id": "1", 566 | "poolParams": { 567 | "swapFee": "0.003000000000000000", 568 | "exitFee": "0.000000000000000000", 569 | "smoothWeightChangeParams": null 570 | }, 571 | "future_pool_governor": "24h", 572 | "totalShares": { 573 | "denom": "gamm/pool/1", 574 | "amount": "110000000000000000000" 575 | }, 576 | "poolAssets": [ 577 | { 578 | "token": { 579 | "denom": "uatom", 580 | "amount": "5503000000" 581 | }, 582 | "weight": "5368709120" 583 | }, 584 | { 585 | "token": { 586 | "denom": "uosmo", 587 | "amount": "10994021257" 588 | }, 589 | "weight": "5368709120" 590 | } 591 | ], 592 | "totalWeight": "10737418240" 593 | } 594 | ], 595 | "pagination": { 596 | "next_key": null, 597 | "total": "2" 598 | } 599 | } 600 | ``` 601 | 602 | - pool-params 603 | 604 | ```bash 605 | # Command-line Interface 606 | osmosisd q gamm pool-params 1 --output json | jq 607 | 608 | # REST API 609 | /osmosis/gamm/v1beta1/pools/1/params 610 | ``` 611 | 612 | ```json 613 | { 614 | "params": { 615 | "swapFee": "0.003000000000000000", 616 | "exitFee": "0.000000000000000000", 617 | "smoothWeightChangeParams": null 618 | } 619 | } 620 | ``` 621 | 622 | - pool-assets 623 | 624 | ```bash 625 | osmosisd q gamm pool-assets 1 --output json | jq 626 | 627 | http://localhost:1317/osmosis/gamm/v1beta1/pools/1/tokens 628 | ``` 629 | 630 | ```json 631 | { 632 | "poolAssets": [ 633 | { 634 | "token": { 635 | "denom": "uatom", 636 | "amount": "5503000000" 637 | }, 638 | "weight": "5368709120" 639 | }, 640 | { 641 | "token": { 642 | "denom": "uosmo", 643 | "amount": "10994021257" 644 | }, 645 | "weight": "5368709120" 646 | } 647 | ] 648 | } 649 | ``` 650 | 651 | - spot-price 652 | 653 | ```bash 654 | # Command-line Interface 655 | # Calculation: (B_in / W_in) / (B_out / W_out) 656 | # swap fee flag does not exist in cli whereas codebase deals with it 657 | osmosisd q gamm spot-price 1 uatom uosmo --output json | jq 658 | osmosisd q gamm spot-price 1 uosmo uatom --output json | jq 659 | 660 | # REST API Not Available 661 | ``` 662 | 663 | ```json 664 | { 665 | "spotPrice": "0.500000000000000000" 666 | } 667 | ``` 668 | 669 | - total-liquidity 670 | 671 | ```bash 672 | # Command-line Interface 673 | osmosisd q gamm total-liquidity --output json | jq 674 | 675 | http://localhost:1317/osmosis/gamm/v1beta1/total_liquidity 676 | ``` 677 | 678 | ```json 679 | { 680 | "liquidity": [ 681 | { 682 | "denom": "uatom", 683 | "amount": "10000000000" 684 | }, 685 | { 686 | "denom": "uosmo", 687 | "amount": "20000000000" 688 | } 689 | ] 690 | } 691 | ``` 692 | 693 | - total-share 694 | 695 | ```bash 696 | # Command-line Interface 697 | # initial pool shares is 10^18 * 100 (100000000000000000000) 698 | osmosisd q gamm total-share 1 --output json | jq 699 | 700 | # NOT WORKING 701 | http://localhost:1317/osmosis/gamm/v1beta1/pools/1/total_share 702 | ``` 703 | 704 | ```json 705 | { 706 | "totalShares": { 707 | "denom": "gamm/pool/1", 708 | "amount": "110000000000000000000" 709 | } 710 | } 711 | ``` 712 | 713 | - estimate-swap-exact-amount-in 714 | 715 | ```bash 716 | # Command-line Interface 717 | osmosisd q gamm estimate-swap-exact-amount-in 1 osmo185fflsvwrz0cx46w6qada7mdy92m6kx4qm4l9k 1000000uatom \ 718 | --swap-route-denoms uosmo \ 719 | --swap-route-pool-ids 1 \ 720 | --output json | jq 721 | 722 | # REST API (Not working, need to dig more) 723 | http://localhost:1317/osmosis/gamm/v1beta1/1/estimate/swap_exact_amount_in?poolId=1&sender=osmo185fflsvwrz0cx46w6qada7mdy92m6kx4qm4l9k&tokenIn=1000000uatom 724 | ``` 725 | 726 | ```json 727 | { 728 | "tokenOutAmount": "1993602" 729 | } 730 | ``` 731 | 732 | - estimate-swap-exact-amount-out 733 | 734 | ```bash 735 | # Command-line Interface 736 | osmosisd q gamm estimate-swap-exact-amount-out 1 osmo185fflsvwrz0cx46w6qada7mdy92m6kx4qm4l9k 1000000uatom \ 737 | --swap-route-denoms uosmo \ 738 | --swap-route-pool-ids 1 \ 739 | --output json | jq 740 | 741 | osmosisd q gamm estimate-swap-exact-amount-out 1 osmo185fflsvwrz0cx46w6qada7mdy92m6kx4qm4l9k 1000000uosmo \ 742 | --swap-route-denoms uatom \ 743 | --swap-route-pool-ids 1 \ 744 | --output json | jq 745 | 746 | ``` 747 | 748 | ```json 749 | { 750 | "tokenInAmount": "2005618" 751 | } 752 | ``` 753 | 754 | **Transaction commands for the `gamm` module** 755 | 756 | ```json 757 | Available Commands: 758 | create-pool create a new pool and provide the liquidity to it 759 | exit-pool exit a new pool and withdraw the liquidity from it 760 | exit-swap-extern-amount-out exit swap extern amount out 761 | exit-swap-share-amount-in exit swap share amount in 762 | join-pool join a new pool and provide the liquidity to it 763 | join-swap-extern-amount-in join swap extern amount in 764 | join-swap-share-amount-out join swap share amount out 765 | swap-exact-amount-in swap exact amount in 766 | swap-exact-amount-out swap exact amount out 767 | ``` 768 | 769 | - create-pool 770 | 771 | > create a new pool and provide the liquidity to it 772 | 773 | An example of `plan.json` file. 774 | 775 | ```json 776 | { 777 | "weights": "5uatom,5uosmo", 778 | "initial-deposit": "5000000000uatom,10000000000uosmo", 779 | "swap-fee": "0.003", 780 | "exit-fee": "0.00", 781 | "future-governor": "24h" 782 | } 783 | ``` 784 | 785 | ```bash 786 | osmosisd tx gamm create-pool \ 787 | --chain-id localnet \ 788 | --pool-file="pool.json" \ 789 | --from user2 \ 790 | --keyring-backend test \ 791 | --broadcast-mode block \ 792 | --gas 500000 \ 793 | --yes 794 | ``` 795 | 796 | - join-pool 797 | 798 | > join a new pool and provide the liquidity to it 799 | 800 | ```bash 801 | # --share-amount-out: shareRatio is the desired number of shares 802 | # divided by the total number of shares currently in the pool. 803 | # 804 | # http://localhost:1317/osmosis/gamm/v1beta1/pools 805 | # 806 | osmosisd tx gamm join-pool \ 807 | --chain-id localnet \ 808 | --from user2 \ 809 | --keyring-backend test \ 810 | --broadcast-mode block \ 811 | --pool-id 1 \ 812 | --share-amount-out 10000000000000000000 \ 813 | --max-amounts-in 500000000uatom \ 814 | --max-amounts-in 1000000000uosmo \ 815 | --yes 816 | ``` 817 | 818 | - exit-pool 819 | 820 | > exit a new pool and withdraw the liquidity from it 821 | 822 | ```bash 823 | osmosisd tx gamm exit-pool \ 824 | --chain-id localnet \ 825 | --from user2 \ 826 | --keyring-backend test \ 827 | --broadcast-mode block \ 828 | --pool-id 1 \ 829 | --share-amount-in 1000000000000000000 \ 830 | --min-amounts-out 50000000uatom \ 831 | --min-amounts-out 100000000uosmo \ 832 | --yes 833 | ``` 834 | 835 | - swap-exact-amount-in 836 | 837 | ```bash 838 | # Command-line Interface 839 | osmosisd tx gamm swap-exact-amount-in 1000000uatom 1993602 \ 840 | --chain-id localnet \ 841 | --from user2 \ 842 | --keyring-backend test \ 843 | --broadcast-mode block \ 844 | --swap-route-pool-ids 1 \ 845 | --swap-route-denoms uosmo \ 846 | --yes 847 | ``` 848 | 849 | - swap-exact-amount-out 850 | 851 | ```bash 852 | osmosisd tx gamm swap-exact-amount-out 1000000uatom 2005618 \ 853 | --chain-id localnet \ 854 | --from user2 \ 855 | --keyring-backend test \ 856 | --broadcast-mode block \ 857 | --swap-route-pool-ids 1 \ 858 | --swap-route-denoms uosmo \ 859 | --yes 860 | ``` 861 | 862 | --------------------------------------------------------------------------------