Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate DEX-related asset FT queries and messages for the WASM. #1031

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2366,7 +2366,7 @@ DEXSettings defines the token settings of the dex.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `unified_ref_amount` | [string](#string) | | `unified_ref_amount is the approximate amount you need to by 1USD, used to define the price tick size` |
| `unified_ref_amount` | [string](#string) | | `unified_ref_amount is the approximate amount you need to buy 1USD, used to define the price tick size` |
| `whitelisted_denoms` | [string](#string) | repeated | `whitelisted_denoms is the list of denoms to trade with.` |


Expand Down Expand Up @@ -2795,7 +2795,7 @@ MsgIssue defines message to issue new fungible token.
| ----- | ---- | ----- | ----------- |
| `sender` | [string](#string) | | |
| `denom` | [string](#string) | | |
| `unified_ref_amount` | [string](#string) | | `unified_ref_amount is the approximate amount you need to by 1USD, used to define the price tick size` |
| `unified_ref_amount` | [string](#string) | | `unified_ref_amount is the approximate amount you need to buy 1USD, used to define the price tick size` |



Expand Down Expand Up @@ -4917,7 +4917,7 @@ Params keeps gov manageable parameters.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `default_unified_ref_amount` | [string](#string) | | `default_unified_ref_amount is the default approximate amount you need to by 1USD, used to for tokens without custom value` |
| `default_unified_ref_amount` | [string](#string) | | `default_unified_ref_amount is the default approximate amount you need to buy 1USD, used to for tokens without custom value` |
| `price_tick_exponent` | [int32](#int32) | | `price_tick_exponent is the exponent used for the price tick calculation` |
| `max_orders_per_denom` | [uint64](#uint64) | | `max_orders_per_denom is the maximum number of orders per denom the user can have` |
| `order_reserve` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | `order_reserve is the reserve required to save the order in the order book` |
Expand Down
4 changes: 2 additions & 2 deletions docs/static/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -9592,7 +9592,7 @@
"properties": {
"unified_ref_amount": {
"type": "string",
"title": "unified_ref_amount is the approximate amount you need to by 1USD, used to define the price tick size"
"title": "unified_ref_amount is the approximate amount you need to buy 1USD, used to define the price tick size"
},
"whitelisted_denoms": {
"type": "array",
Expand Down Expand Up @@ -10178,7 +10178,7 @@
"properties": {
"default_unified_ref_amount": {
"type": "string",
"title": "default_unified_ref_amount is the default approximate amount you need to by 1USD, used to for tokens without custom value"
"title": "default_unified_ref_amount is the default approximate amount you need to buy 1USD, used to for tokens without custom value"
},
"price_tick_exponent": {
"type": "integer",
Expand Down
72 changes: 70 additions & 2 deletions integration-tests/contracts/modules/dex/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use coreum_wasm_sdk::types::coreum::asset::ft::v1::MsgIssue;
use coreum_wasm_sdk::types::coreum::asset::ft::v1::{MsgIssue, MsgUpdateDexUnifiedRefAmount, MsgUpdateDexWhitelistedDenoms, QueryBalanceRequest, QueryBalanceResponse, QueryDexSettingsRequest, QueryDexSettingsResponse};
use coreum_wasm_sdk::types::coreum::dex::v1::{
MsgCancelOrder, MsgCancelOrdersByDenom, MsgPlaceOrder, Order, OrderType,
MsgCancelOrder, MsgCancelOrdersByDenom, MsgPlaceOrder, OrderType,
QueryAccountDenomOrdersCountRequest, QueryAccountDenomOrdersCountResponse,
QueryOrderBookOrdersRequest, QueryOrderBookOrdersResponse, QueryOrderBooksRequest,
QueryOrderBooksResponse, QueryOrderRequest, QueryOrderResponse, QueryOrdersRequest,
QueryOrdersResponse, QueryParamsRequest, QueryParamsResponse, Side, TimeInForce,
};

use coreum_wasm_sdk::types::cosmos::base::query::v1beta1::PageRequest;
use cosmwasm_std::{entry_point, to_json_binary, Binary, CosmosMsg, Deps, StdError, StdResult};
use cosmwasm_std::{DepsMut, Env, MessageInfo, Response};
Expand Down Expand Up @@ -70,6 +71,13 @@ pub fn execute(
ExecuteMsg::CancelOrdersByDenom { account, denom } => {
cancel_orders_by_denom(env, account, denom)
}
ExecuteMsg::UpdateDEXUnifiedRefAmount { denom, amount } => {
update_dex_unified_ref_amount(env, denom, amount)
}
ExecuteMsg::UpdateDEXWhitelistedDenoms {
denom,
whitelisted_denoms,
} => update_dex_whitelisted_denoms(env, denom, whitelisted_denoms),
}
}

Expand Down Expand Up @@ -169,6 +177,43 @@ fn cancel_orders_by_denom(
.add_message(CosmosMsg::Any(cancel_orders_by_denom.to_any())))
}

fn update_dex_unified_ref_amount(
env: Env,
denom: String,
amount: String,
) -> Result<Response, ContractError> {
let dex_unified_ref_amount = MsgUpdateDexUnifiedRefAmount {
sender: env.contract.address.to_string(),
denom: denom.clone(),
unified_ref_amount: amount.clone(),
};

Ok(Response::new()
.add_attribute("method", "dex_unified_ref_amount")
.add_attribute("sender", env.contract.address.to_string())
.add_attribute("unified_ref_amount", amount)
.add_message(CosmosMsg::Any(dex_unified_ref_amount.to_any())))
}

fn update_dex_whitelisted_denoms(
env: Env,
denom: String,
whitelisted_denoms: Vec<String>,
) -> Result<Response, ContractError> {
let update_dex_whitelisted_denoms = MsgUpdateDexWhitelistedDenoms {
sender: env.contract.address.to_string(),
denom: denom.clone(),
whitelisted_denoms: whitelisted_denoms.clone(),
};

Ok(Response::new()
.add_attribute("method", "update_dex_whitelisted_denoms")
.add_attribute("sender", env.contract.address.to_string())
.add_attribute("account", denom)
.add_attribute("whitelisted_denoms", whitelisted_denoms.join(","))
.add_message(CosmosMsg::Any(update_dex_whitelisted_denoms.to_any())))
}

// ********** Queries **********
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
Expand All @@ -190,6 +235,12 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
QueryMsg::AccountDenomOrdersCount { account, denom } => {
to_json_binary(&query_account_denom_orders_count(deps, account, denom)?)
}
QueryMsg::DEXSettings { denom } => {
to_json_binary(&query_dex_settings(deps, denom)?)
}
QueryMsg::Balance { account, denom } => {
to_json_binary(&query_balance(deps, account, denom)?)
}
}
}

Expand Down Expand Up @@ -311,3 +362,20 @@ fn query_account_denom_orders_count(
let request = QueryAccountDenomOrdersCountRequest { account, denom };
request.query(&deps.querier)
}

fn query_dex_settings(
deps: Deps,
denom: String,
) -> StdResult<QueryDexSettingsResponse> {
let request = QueryDexSettingsRequest { denom };
request.query(&deps.querier)
}

fn query_balance(
deps: Deps,
account: String,
denom: String,
) -> StdResult<QueryBalanceResponse> {
let request = QueryBalanceRequest { account, denom };
request.query(&deps.querier)
}
33 changes: 29 additions & 4 deletions integration-tests/contracts/modules/dex/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use coreum_wasm_sdk::types::coreum::asset::ft::v1::{DexSettings, ExtensionIssueSettings};
use coreum_wasm_sdk::types::coreum::dex::v1::{MsgPlaceOrder, Order};
use coreum_wasm_sdk::types::coreum::dex::v1::MsgPlaceOrder;
use cosmwasm_schema::cw_serde;
use cosmwasm_std::Uint128;

Expand All @@ -21,9 +21,26 @@ pub struct InstantiateMsg {

#[cw_serde]
pub enum ExecuteMsg {
PlaceOrder { order: MsgPlaceOrder },
CancelOrder { order_id: String },
CancelOrdersByDenom { account: String, denom: String },
PlaceOrder {
order: MsgPlaceOrder,
},
CancelOrder {
order_id: String,
},
CancelOrdersByDenom {
account: String,
denom: String,
},
#[serde(rename = "update_dex_unified_ref_amount")]
UpdateDEXUnifiedRefAmount {
denom: String,
amount: String,
},
#[serde(rename = "update_dex_whitelisted_denoms")]
UpdateDEXWhitelistedDenoms {
denom: String,
whitelisted_denoms: Vec<String>,
},
}

#[cw_serde]
Expand All @@ -46,4 +63,12 @@ pub enum QueryMsg {
account: String,
denom: String,
},
#[serde(rename = "dex_settings")]
DEXSettings {
denom: String,
},
Balance {
account: String,
denom: String,
},
}
Loading