Skip to content

Commit 8558e7e

Browse files
authored
Addition of required dependencies and updates to QueryMsg state to make sure the QueryResponses trait is implemented (#547)
Addition of required dependencies and updates to QueryMsg state to make sure the QueryResponses trait is imlemented
1 parent 024b116 commit 8558e7e

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

content/2.developers/3.guides/13.cosmwasm-by-example/9.amm-product.md

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ parentSectionPath: /developers
77
---
88

99
# Constant Product Automatic Market Maker (AMM)
10+
1011
## Explanation
1112
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.
1213

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

390391
## Example
391392

392-
## Example
393393
To create an AMM with CosmWasm, you can create the following files:
394394
lib.rs
395395
integration_tests.rs
@@ -398,6 +398,17 @@ msg.rs
398398
error.rs
399399
state.rs
400400

401+
## Cargo.toml
402+
403+
The following dependencies should be added to the `Cargo.toml` file:
404+
405+
```
406+
cw20-base = { version = "0.16", features = ["library"] }
407+
cw20 = { version = "0.16" }
408+
```
409+
410+
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.
411+
401412
### lib.rs
402413

403414
::highlight-card
@@ -1532,6 +1543,8 @@ use cosmwasm_std::{Decimal, Uint128};
15321543

15331544
use cw20::{Denom, Expiration};
15341545

1546+
use cosmwasm_schema::QueryResponses;
1547+
15351548
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
15361549
pub struct InstantiateMsg {
15371550
pub token1_denom: Denom,
@@ -1582,22 +1595,25 @@ pub enum ExecuteMsg {
15821595
},
15831596
}
15841597

1585-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
1598+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, QueryResponses)]
15861599
#[serde(rename_all = "snake_case")]
15871600
pub enum QueryMsg {
1588-
/// Implements CW20. Returns the current balance of the given address, 0 if unset.
1589-
Balance {
1590-
address: String,
1591-
},
1601+
#[returns(cw20::BalanceResponse)]
1602+
Balance { address: String },
1603+
1604+
#[returns(InfoResponse)]
15921605
Info {},
1593-
Token1ForToken2Price {
1594-
token1_amount: Uint128,
1595-
},
1596-
Token2ForToken1Price {
1597-
token2_amount: Uint128,
1598-
},
1606+
1607+
#[returns(Token1ForToken2PriceResponse)]
1608+
Token1ForToken2Price { token1_amount: Uint128 },
1609+
1610+
#[returns(Token2ForToken1PriceResponse)]
1611+
Token2ForToken1Price { token2_amount: Uint128 },
1612+
1613+
#[returns(FeeResponse)]
15991614
Fee {},
16001615
}
1616+
16011617
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
16021618
pub struct MigrateMsg {
16031619
pub owner: Option<String>,

0 commit comments

Comments
 (0)