From e2842bf20bdaf89abaa5fb875566cb5ec5efe615 Mon Sep 17 00:00:00 2001 From: kenta-elys <130330089+kenta-elys@users.noreply.github.com> Date: Tue, 19 Dec 2023 01:52:49 +0900 Subject: [PATCH 1/2] Feat/asset profile (#68) * fix: conflict * chore: fix conflict * chore: fix conflict * chorre: cargo update --- Cargo.lock | 42 ++++++++++----------- Cargo.toml | 8 ++-- src/action/execute/exit_amm_pool_request.rs | 21 +++++++++-- src/action/execute/join_amm_pool_request.rs | 22 +++++++++-- src/action/execute/stake_request.rs | 8 ++-- src/action/execute/unstake_request.rs | 9 +++-- 6 files changed, 73 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 164a3ad..9d2f0f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -87,9 +87,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "const-oid" -version = "0.9.5" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" [[package]] name = "cosmwasm-crypto" @@ -371,8 +371,8 @@ dependencies = [ [[package]] name = "elys-bindings" -version = "0.10.0" -source = "git+https://github.com/elys-network/bindings?tag=v0.10.0#08d20deca8bf2565387aa5984bd6b1a71539a763" +version = "0.10.1" +source = "git+https://github.com/elys-network/bindings?tag=v0.10.1#5075e89a59890871cae660d545f94480c3d75b8f" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -381,8 +381,8 @@ dependencies = [ [[package]] name = "elys-bindings-test" -version = "0.10.0" -source = "git+https://github.com/elys-network/bindings?tag=v0.10.0#08d20deca8bf2565387aa5984bd6b1a71539a763" +version = "0.10.1" +source = "git+https://github.com/elys-network/bindings?tag=v0.10.1#5075e89a59890871cae660d545f94480c3d75b8f" dependencies = [ "anyhow", "cosmwasm-schema", @@ -480,9 +480,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "k256" @@ -500,9 +500,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.150" +version = "0.2.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" [[package]] name = "once_cell" @@ -594,9 +594,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.15" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" [[package]] name = "schemars" @@ -662,7 +662,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -756,9 +756,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.39" +version = "2.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269" dependencies = [ "proc-macro2", "quote", @@ -767,27 +767,27 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.50" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.50" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] name = "trade_shield_contract" -version = "0.12.0" +version = "0.12.1" dependencies = [ "cosmwasm-schema", "cosmwasm-std", diff --git a/Cargo.toml b/Cargo.toml index a82adf8..f02c3ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "trade_shield_contract" -version = "0.12.0" +version = "0.12.1" edition = "2021" [lib] @@ -14,13 +14,13 @@ thiserror = "1" schemars = "0.8.1" cosmwasm-schema = "1.1.4" cw-utils = "0.13" -elys-bindings = { version = "0.10.0", git = "https://github.com/elys-network/bindings", tag = "v0.10.0" } +elys-bindings = { version = "0.10.1", git = "https://github.com/elys-network/bindings", tag = "v0.10.1" } [dev-dependencies] cw-multi-test = "0.13.4" serde_json = "1.0.107" -elys-bindings = { version = "0.10.0", git = "https://github.com/elys-network/bindings", tag = "v0.10.0", features = [ +elys-bindings = { version = "0.10.1", git = "https://github.com/elys-network/bindings", tag = "v0.10.1", features = [ "testing", ] } -elys-bindings-test = { version = "0.10.0", git = "https://github.com/elys-network/bindings", tag = "v0.10.0" } +elys-bindings-test = { version = "0.10.1", git = "https://github.com/elys-network/bindings", tag = "v0.10.1" } diff --git a/src/action/execute/exit_amm_pool_request.rs b/src/action/execute/exit_amm_pool_request.rs index 6b3787f..8fb829f 100644 --- a/src/action/execute/exit_amm_pool_request.rs +++ b/src/action/execute/exit_amm_pool_request.rs @@ -3,21 +3,36 @@ use cosmwasm_std::{Uint128, Coin}; pub fn exit_amm_pool_request( info: MessageInfo, - _deps: DepsMut, + deps: DepsMut, pool_id: u64, min_amounts_out: Vec, share_amount_in: Uint128, token_out_denom: String, ) -> Result, ContractError> { + let querier = ElysQuerier::new(&deps.querier); + let mut min_amounts_out_real_denom = vec![]; + + // Re-initiate the coin input with the real denom + for coin in min_amounts_out { + let denom_entry = querier.get_asset_profile(coin.denom.clone())?; + let real_denom = denom_entry.entry.denom; + + let real_coin = Coin { + denom: real_denom.clone(), + amount: coin.amount, + }; + + min_amounts_out_real_denom.push(real_coin.clone()); + } + let msg: ElysMsg = ElysMsg::amm_exit_pool( info.sender.into_string(), pool_id, - min_amounts_out, + min_amounts_out_real_denom, share_amount_in, token_out_denom, ); let resp = Response::new().add_message(msg); - Ok(resp) } diff --git a/src/action/execute/join_amm_pool_request.rs b/src/action/execute/join_amm_pool_request.rs index 7e14b94..67fd36e 100644 --- a/src/action/execute/join_amm_pool_request.rs +++ b/src/action/execute/join_amm_pool_request.rs @@ -3,21 +3,37 @@ use cosmwasm_std::{Uint128, Coin}; pub fn join_amm_pool_request( info: MessageInfo, - _deps: DepsMut, + deps: DepsMut, pool_id: u64, max_amounts_in: Vec, share_amount_out: Uint128, no_remaining: bool, ) -> Result, ContractError> { + let querier = ElysQuerier::new(&deps.querier); + let mut max_amounts_in_real_denom = vec![]; + + // Re-initiate the coin input with the real denom + for coin in max_amounts_in { + let denom_entry = querier.get_asset_profile(coin.denom.clone())?; + let real_denom = denom_entry.entry.denom; + + let real_coin = Coin { + denom: real_denom.clone(), + amount: coin.amount, + }; + + max_amounts_in_real_denom.push(real_coin.clone()); + } + + // Construct amm join pool message. let msg: ElysMsg = ElysMsg::amm_join_pool( info.sender.into_string(), pool_id, - max_amounts_in, + max_amounts_in_real_denom, share_amount_out, no_remaining, ); let resp = Response::new().add_message(msg); - Ok(resp) } diff --git a/src/action/execute/stake_request.rs b/src/action/execute/stake_request.rs index 1fdf30e..3e22175 100644 --- a/src/action/execute/stake_request.rs +++ b/src/action/execute/stake_request.rs @@ -14,7 +14,11 @@ pub fn stake_request( ) -> Result, ContractError> { let querier = ElysQuerier::new(&deps.querier); let address = info.sender.into_string(); - let balance = querier.get_balance(address.to_owned(), asset.to_owned())?; + + let denom_entry = querier.get_asset_profile(asset.clone())?; + let real_denom = denom_entry.entry.denom; + + let balance = querier.get_balance(address.to_owned(), real_denom.clone())?; let token_amount: u128 = balance.amount.into(); if token_amount < amount as u128 { return Err(ContractError::InsufficientBalanceError { @@ -24,8 +28,6 @@ pub fn stake_request( } let msg = ElysMsg::stake_token(address, Int128::from(amount), asset, validator_address); - let resp = Response::new().add_message(msg); - Ok(resp) } diff --git a/src/action/execute/unstake_request.rs b/src/action/execute/unstake_request.rs index de03b63..4852dd3 100644 --- a/src/action/execute/unstake_request.rs +++ b/src/action/execute/unstake_request.rs @@ -3,7 +3,7 @@ use cosmwasm_std::Int128; pub fn unstake_request( info: MessageInfo, - _deps: DepsMut, + deps: DepsMut, // the amount to be staked in base denomination. amount: u64, // The asset to be staked @@ -12,14 +12,17 @@ pub fn unstake_request( // uelys. validator_address: Option, ) -> Result, ContractError> { + let querier = ElysQuerier::new(&deps.querier); + let denom_entry = querier.get_asset_profile(asset.clone())?; + let real_denom = denom_entry.entry.denom; + let msg = ElysMsg::unstake_token( info.sender.into_string(), Int128::from(amount), - asset, + real_denom, validator_address, ); let resp = Response::new().add_message(msg); - Ok(resp) } From 3c534748d098ad7e578a284a07aca5d3e3cf95f8 Mon Sep 17 00:00:00 2001 From: kenta-elys <130330089+kenta-elys@users.noreply.github.com> Date: Tue, 19 Dec 2023 16:33:37 +0900 Subject: [PATCH 2/2] Feat/fix denom (#69) * chore: fix denom issue in stake_request * chore: update contract version --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/action/execute/stake_request.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9d2f0f7..a615804 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -787,7 +787,7 @@ dependencies = [ [[package]] name = "trade_shield_contract" -version = "0.12.1" +version = "0.12.2" dependencies = [ "cosmwasm-schema", "cosmwasm-std", diff --git a/Cargo.toml b/Cargo.toml index f02c3ad..00f9914 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "trade_shield_contract" -version = "0.12.1" +version = "0.12.2" edition = "2021" [lib] diff --git a/src/action/execute/stake_request.rs b/src/action/execute/stake_request.rs index 3e22175..eb1a769 100644 --- a/src/action/execute/stake_request.rs +++ b/src/action/execute/stake_request.rs @@ -27,7 +27,7 @@ pub fn stake_request( }); } - let msg = ElysMsg::stake_token(address, Int128::from(amount), asset, validator_address); + let msg = ElysMsg::stake_token(address, Int128::from(amount), real_denom.clone(), validator_address); let resp = Response::new().add_message(msg); Ok(resp) }