Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

Commit

Permalink
Merge branch 'main' into kenta-elys-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmic-vagabond authored Dec 19, 2023
2 parents 97b42ad + 3c53474 commit 526b314
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 38 deletions.
42 changes: 21 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "trade_shield_contract"
version = "0.12.0"
version = "0.12.2"
edition = "2021"

[lib]
Expand All @@ -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" }
21 changes: 18 additions & 3 deletions src/action/execute/exit_amm_pool_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,36 @@ use cosmwasm_std::{Uint128, Coin};

pub fn exit_amm_pool_request(
info: MessageInfo,
_deps: DepsMut<ElysQuery>,
deps: DepsMut<ElysQuery>,
pool_id: u64,
min_amounts_out: Vec<Coin>,
share_amount_in: Uint128,
token_out_denom: String,
) -> Result<Response<ElysMsg>, 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)
}
22 changes: 19 additions & 3 deletions src/action/execute/join_amm_pool_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,37 @@ use cosmwasm_std::{Uint128, Coin};

pub fn join_amm_pool_request(
info: MessageInfo,
_deps: DepsMut<ElysQuery>,
deps: DepsMut<ElysQuery>,
pool_id: u64,
max_amounts_in: Vec<Coin>,
share_amount_out: Uint128,
no_remaining: bool,
) -> Result<Response<ElysMsg>, 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)
}
10 changes: 6 additions & 4 deletions src/action/execute/stake_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ pub fn stake_request(
) -> Result<Response<ElysMsg>, 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 {
Expand All @@ -23,9 +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)
}
9 changes: 6 additions & 3 deletions src/action/execute/unstake_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use cosmwasm_std::Int128;

pub fn unstake_request(
info: MessageInfo,
_deps: DepsMut<ElysQuery>,
deps: DepsMut<ElysQuery>,
// the amount to be staked in base denomination.
amount: u64,
// The asset to be staked
Expand All @@ -12,14 +12,17 @@ pub fn unstake_request(
// uelys.
validator_address: Option<String>,
) -> Result<Response<ElysMsg>, 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)
}

0 comments on commit 526b314

Please sign in to comment.