From 8558e7e54181f5d0516939be20dad9c2f9a27489 Mon Sep 17 00:00:00 2001 From: Adrian Thompson Date: Fri, 15 Nov 2024 15:31:27 -0500 Subject: [PATCH] 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 --- .../13.cosmwasm-by-example/9.amm-product.md | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/content/2.developers/3.guides/13.cosmwasm-by-example/9.amm-product.md b/content/2.developers/3.guides/13.cosmwasm-by-example/9.amm-product.md index bfb0ed35..9e7c4d71 100644 --- a/content/2.developers/3.guides/13.cosmwasm-by-example/9.amm-product.md +++ b/content/2.developers/3.guides/13.cosmwasm-by-example/9.amm-product.md @@ -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. @@ -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 @@ -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 @@ -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, @@ -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,