Frequently Used Messages

Transaction

Provide Liquidity / Withdraw

As the swap ratio is stated here, the size of a pool is related to its swap ratio. The ratio will get stable if the size of the pool increases, and vice versa. Otherwise, liquidity providers need more tokens to adjust the price in a bigger pool and it means that the market loses elasticity. The providers adjust their markets by providing and withdrawing liquidity within a trade-off.

Provide Liquidity

Contribute to the pool by sending a pair of tokens. The transaction increases the pool size.

Execute this message by the Pair contract address!

If you are trying to provide cw20 token, increase your allowance first. Execute IncreaseAllowance

{
  "provide_liquidity": {
    "assets": [
      {
        "info" : {
            "token": {
                "contract_addr": "<Addr>"
            }
        },
        "amount": "10"
      },
      {
        "info" : {
            "native_token": {
                "denom": "uluna"
            }
        },
        "amount": "10"
      }
    ],
    "deadline": 1686903051, // optional, unix epoch
    "slippage_tolerance": "0.005" // optional
  }
}

Withdraw

Withdraw your tokens and decrease the size of the pool.

Execute the below message via the Liquidity token contract address! Not token contract, nor pair contract!

{
  "send": {
    "contract": "<PairContractAddress>",
    "amount": 123,
    "msg": "<base64-encodedStringOfWithdrawMsg>"
  },
}

In send.msg, you may decode this JSON string into base64 encoding.

{
  "withdraw_liquidity": {
    "min_assets": [
      {
        "info" : {
          "token": {
            "contract_addr": "<Addr>"
          }
        },
        "amount": "10"
      },
      {
        "info" : {
          "native_token": {
            "denom": "uluna"
          }
        },
        "amount": "10"
      }
    ], // optional
    "deadline": 1686903051 // optional, unix epoch
  }
}

As a result, the contract calculates the portion of your liquidity token compared to the total supply, and withdraws them.

Query

Pool

The pool query message returns the amount of the tokens in the pool from the given pair contract address.

{
  "pool":{}
}

Response:

{
  "data": {
    "assets": [
      {
        "info": {
          "token": {
            "contract_addr": "terra1cl0kw9axzpzkw58snj6cy0hfp0xp8xh9tudpw2exvzuupn3fafwqqhjc24"
          }
        },
        "amount": "81695"
      },
      {
        "info": {
          "native_token": {
            "denom": "uluna"
          }
        },
        "amount": "40774785"
      }
    ],
    "total_share": "1814863"
  }
}
  • ex) LUNA <> DELIGHT https://pisco-lcd.terra.dev/cosmwasm/wasm/v1/contract/terra12gyq86zdaef9hafs6a6y24xqxgjyzh4m5a224tenlchj2ekgf5tsv94gwj/smart/eyJwb29sIjp7fX0=

Simulation / Reverse Simulation

Simulation works for guessing how much you will get by swapping with your token.

In case of you want to know how much the target token will be given from the source token, use simulation. Likewise, reverse_simulation can let you derive the number of source token from the number of target token.

Simulation Request

{
  "simulation": {
    "offer_asset": {
      "amount":"1000000",
      "info": {
        "native_token": {
          "denom":"uluna"
        }
      }
    }
  }
}

Simulation Response

{
  "data": {
    "return_amount": "1950",
    "spread_amount": "48",
    "commission_amount": "5"
  }
}
  • ex) LUNA <> DELIGHT https://pisco-lcd.terra.dev/cosmwasm/wasm/v1/contract/terra12gyq86zdaef9hafs6a6y24xqxgjyzh4m5a224tenlchj2ekgf5tsv94gwj/smart/ewogICJzaW11bGF0aW9uIjogewogICAgIm9mZmVyX2Fzc2V0IjogewogICAgICAiYW1vdW50IjoiMTAwMDAwMCIsCiAgICAgICJpbmZvIjogewogICAgICAgICJuYXRpdmVfdG9rZW4iOiB7CiAgICAgICAgICAiZGVub20iOiJ1bHVuYSIKICAgICAgICB9CiAgICAgIH0KICAgIH0KICB9Cn0=

Reverse Simulation Request

{
  "reverse_simulation":{
    "ask_asset": {
      "amount":"1000000",
      "info": {
        "native_token": {
          "denom": "uluna"
        }
      }
    }
  }
}

Reverse Simulation Response

{
  "data": {
    "offer_amount": "2060",
    "spread_amount": "25157",
    "commission_amount": "3009"
  }
}
  • ex) LUNA <> DELIGHT https://pisco-lcd.terra.dev/cosmwasm/wasm/v1/contract/terra12gyq86zdaef9hafs6a6y24xqxgjyzh4m5a224tenlchj2ekgf5tsv94gwj/smart/ewogICJyZXZlcnNlX3NpbXVsYXRpb24iOnsKICAgICJhc2tfYXNzZXQiOiB7CiAgICAgICJhbW91bnQiOiIxMDAwMDAwIiwKICAgICAgImluZm8iOiB7CiAgICAgICAgIm5hdGl2ZV90b2tlbiI6IHsKICAgICAgICAgICJkZW5vbSI6ICJ1bHVuYSIKICAgICAgICB9CiAgICAgIH0KICAgIH0KICB9Cn0=