Skip to content

Commit

Permalink
append event attributes sender and receiver for all handlers, and pre…
Browse files Browse the repository at this point in the history
…vent zero share returned at providing liquidity
  • Loading branch information
yun-yeo committed Aug 12, 2021
1 parent c8cbfb3 commit 191c1fb
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion contracts/terraswap_factory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ overflow-checks = true
backtraces = ["cosmwasm-std/backtraces"]

[dependencies]
terraswap = { path = "../../packages/terraswap", default-features = false, version = "2.4.0"}
terraswap = { path = "../../packages/terraswap", default-features = false, version = "2.4.1"}
cosmwasm-std = { version = "0.16.0" }
cw-storage-plus = { version = "0.8.0" }
schemars = "0.8.1"
Expand Down
2 changes: 1 addition & 1 deletion contracts/terraswap_pair/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ serde = { version = "1.0.103", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.20" }
protobuf = { version = "2", features = ["with-bytes"] }
cosmwasm-bignumber = "2.2.0"
terraswap = { path = "../../packages/terraswap", default-features = false, version = "2.4.0"}
terraswap = { path = "../../packages/terraswap", default-features = false, version = "2.4.1"}

[dev-dependencies]
cosmwasm-schema = "0.16.0"
Expand Down
20 changes: 17 additions & 3 deletions contracts/terraswap_pair/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,21 +269,29 @@ pub fn provide_liquidity(
)
};

// prevent providing free token
if share.is_zero() {
return Err(ContractError::InvalidZeroAmount{});
}

// mint LP token to sender
let receiver = receiver.unwrap_or_else(|| info.sender.to_string());
messages.push(CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: deps
.api
.addr_humanize(&pair_info.liquidity_token)?
.to_string(),
msg: to_binary(&Cw20ExecuteMsg::Mint {
recipient: receiver.unwrap_or_else(|| info.sender.to_string()),
recipient: receiver.to_string(),
amount: share,
})?,
funds: vec![],
}));

Ok(Response::new().add_messages(messages).add_attributes(vec![
("action", "provide_liquidity"),
("sender", info.sender.as_str()),
("receiver", receiver.as_str()),
("assets", &format!("{}, {}", assets[0], assets[1])),
("share", &share.to_string()),
]))
Expand Down Expand Up @@ -317,7 +325,9 @@ pub fn withdraw_liquidity(
refund_assets[0]
.clone()
.into_msg(&deps.querier, sender.clone())?,
refund_assets[1].clone().into_msg(&deps.querier, sender)?,
refund_assets[1]
.clone()
.into_msg(&deps.querier, sender.clone())?,
// burn liquidity token
CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: deps
Expand All @@ -330,6 +340,7 @@ pub fn withdraw_liquidity(
])
.add_attributes(vec![
("action", "withdraw_liquidity"),
("sender", sender.as_str()),
("withdrawn_share", &amount.to_string()),
(
"refund_assets",
Expand Down Expand Up @@ -397,13 +408,16 @@ pub fn swap(
};

let tax_amount = return_asset.compute_tax(&deps.querier)?;
let receiver = to.unwrap_or(sender.clone());

// 1. send collateral token from the contract to a user
// 2. send inactive commission to collector
Ok(Response::new()
.add_message(return_asset.into_msg(&deps.querier, to.unwrap_or(sender))?)
.add_message(return_asset.into_msg(&deps.querier, receiver.clone())?)
.add_attributes(vec![
("action", "swap"),
("sender", sender.as_str()),
("receiver", receiver.as_str()),
("offer_asset", &offer_asset.info.to_string()),
("ask_asset", &ask_pool.info.to_string()),
("offer_amount", &offer_amount.to_string()),
Expand Down
2 changes: 1 addition & 1 deletion contracts/terraswap_router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ backtraces = ["cosmwasm-std/backtraces"]
[dependencies]
cw20 = { version = "0.8.0" }
cosmwasm-std = { version = "0.16.0" }
terraswap = { path = "../../packages/terraswap", version = "2.4.0" }
terraswap = { path = "../../packages/terraswap", version = "2.4.1" }
terra-cosmwasm = "2.2.0"
cw-storage-plus = { version = "0.8.0"}
integer-sqrt = "0.1.5"
Expand Down
2 changes: 1 addition & 1 deletion contracts/terraswap_token/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cosmwasm-std = { version = "0.16.0" }
schemars = "0.8.1"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.20" }
terraswap = { path = "../../packages/terraswap", version = "2.4.0" }
terraswap = { path = "../../packages/terraswap", version = "2.4.1" }

[dev-dependencies]
# we only need to enable this if we use integration tests
Expand Down
2 changes: 1 addition & 1 deletion packages/terraswap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "terraswap"
version = "2.4.0"
version = "2.4.1"
authors = ["Terraform Labs, PTE."]
edition = "2018"
description = "Common terraswap types"
Expand Down

0 comments on commit 191c1fb

Please sign in to comment.