Skip to content

Commit

Permalink
Addition of required dependencies and updates to QueryMsg state to ma…
Browse files Browse the repository at this point in the history
…ke sure the QueryResponses trait is implemented (#547)

Addition of required dependencies and updates to QueryMsg state to make sure the QueryResponses trait is imlemented
  • Loading branch information
emperorjm authored Nov 15, 2024
1 parent 024b116 commit 8558e7e
Showing 1 changed file with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ parentSectionPath: /developers
---

# Constant Product Automatic Market Maker (AMM)

## Explanation
This contract is an Constant Product Automated Market Maker (AMM) for CosmWasm. This contract allows you to swap tokens. Liquidity providers can add liquidity to the market and receive a certain fee on every transaction that is set on instantiation. The code also includes various error handling and validation checks to ensure the correctness and security of the operations.

Expand Down Expand Up @@ -389,7 +390,6 @@ The owner can freeze deposits to the AMM by calling the execute_freeze_deposits

## Example

## Example
To create an AMM with CosmWasm, you can create the following files:
lib.rs
integration_tests.rs
Expand All @@ -398,6 +398,17 @@ msg.rs
error.rs
state.rs

## Cargo.toml

The following dependencies should be added to the `Cargo.toml` file:

```
cw20-base = { version = "0.16", features = ["library"] }
cw20 = { version = "0.16" }
```

Make sure `cw20-base` is added as a `library` using `features = ["library"]` so as to prevent any issues with adding the `instantiate`, `execute` and `query` entrypoints to the contract.

### lib.rs

::highlight-card
Expand Down Expand Up @@ -1532,6 +1543,8 @@ use cosmwasm_std::{Decimal, Uint128};

use cw20::{Denom, Expiration};

use cosmwasm_schema::QueryResponses;

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct InstantiateMsg {
pub token1_denom: Denom,
Expand Down Expand Up @@ -1582,22 +1595,25 @@ pub enum ExecuteMsg {
},
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, QueryResponses)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
/// Implements CW20. Returns the current balance of the given address, 0 if unset.
Balance {
address: String,
},
#[returns(cw20::BalanceResponse)]
Balance { address: String },

#[returns(InfoResponse)]
Info {},
Token1ForToken2Price {
token1_amount: Uint128,
},
Token2ForToken1Price {
token2_amount: Uint128,
},

#[returns(Token1ForToken2PriceResponse)]
Token1ForToken2Price { token1_amount: Uint128 },

#[returns(Token2ForToken1PriceResponse)]
Token2ForToken1Price { token2_amount: Uint128 },

#[returns(FeeResponse)]
Fee {},
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct MigrateMsg {
pub owner: Option<String>,
Expand Down

0 comments on commit 8558e7e

Please sign in to comment.