Skip to content
Open
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
4 changes: 2 additions & 2 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "andromeda-osmosis-token-factory"
version = "0.1.1-b.3"
version = "0.1.1-b.4"
edition = "2021"
rust-version = "1.86.0"

Expand Down
2 changes: 1 addition & 1 deletion contracts/socket/andromeda-socket-astroport/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "andromeda-socket-astroport"
version = "0.1.8-b.5"
version = "0.1.8-b.6"
edition = "2021"
rust-version = "1.86.0"

Expand Down
83 changes: 53 additions & 30 deletions contracts/socket/andromeda-socket-astroport/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use cosmwasm_std::{
attr, entry_point, from_json, wasm_execute, Binary, Decimal, Deps, DepsMut, Env, MessageInfo,
Reply, Response, StdError, Uint128,
};
use cosmwasm_std::{CosmosMsg, SubMsg};
use cosmwasm_std::{CosmosMsg, Event, SubMsg};

use cw2::set_contract_version;
use cw20::{Cw20ExecuteMsg, Cw20ReceiveMsg};
Expand All @@ -36,9 +36,9 @@ use crate::{
};

use andromeda_socket::astroport::{
transform_asset_info, AssetEntry, AssetInfo, AssetInfoAstroport, Cw20HookMsg, ExecuteMsg,
InstantiateMsg, PairExecuteMsg, PairType, QueryMsg, SimulateSwapOperationResponse,
SwapOperation,
transform_asset_entry, transform_asset_entry_info, transform_asset_info, AndromedaAssetEntry,
AssetEntry, AssetInfo, AssetInfoAstroport, Cw20HookMsg, ExecuteMsg, InstantiateMsg,
PairExecuteMsg, PairType, QueryMsg, SimulateSwapOperationResponse, SwapOperation,
};

const CONTRACT_NAME: &str = "crates.io:andromeda-socket-astroport";
Expand Down Expand Up @@ -126,7 +126,6 @@ pub fn execute(ctx: ExecuteContext, msg: ExecuteMsg) -> Result<Response, Contrac
),
ExecuteMsg::CreatePairAndProvideLiquidity {
pair_type,
asset_infos,
init_params,
assets,
slippage_tolerance,
Expand All @@ -135,7 +134,6 @@ pub fn execute(ctx: ExecuteContext, msg: ExecuteMsg) -> Result<Response, Contrac
} => create_pair_and_provide_liquidity(
ctx,
pair_type,
asset_infos,
init_params,
assets,
slippage_tolerance,
Expand Down Expand Up @@ -368,11 +366,17 @@ fn provide_liquidity(
let provide_wasm_msg = wasm_execute(pair_addr_raw, &provide_liquidity_msg, native_coins)?;
response_msgs = response_msgs.add_message(provide_wasm_msg);

Ok(response_msgs.add_attributes(vec![
attr("action", "provide_liquidity"),
attr("pair_address", pair_address.to_string()),
attr("assets", format!("{:?}", assets)),
]))
Ok(response_msgs
.add_attributes(vec![
attr("action", "provide_liquidity"),
attr("pair_address", pair_address.to_string()),
attr("assets", format!("{:?}", assets)),
])
.add_event(
Event::new("liquidity_provided")
.add_attribute("pair_address", pair_address.to_string())
.add_attribute("assets", format!("{:?}", assets)),
))
}

fn execute_update_swap_router(
Expand All @@ -399,9 +403,8 @@ fn execute_update_swap_router(
fn create_pair_and_provide_liquidity(
ctx: ExecuteContext,
pair_type: PairType,
asset_infos: Vec<AssetInfoAstroport>,
init_parameters: Option<Binary>,
assets: Vec<AssetEntry>,
assets: Vec<AndromedaAssetEntry>,
slippage_tolerance: Option<Decimal>,
auto_stake: Option<bool>,
receiver: Option<AndrAddr>,
Expand All @@ -412,17 +415,17 @@ fn create_pair_and_provide_liquidity(

// Store the liquidity provision parameters for use in the reply handler
let liquidity_state = LiquidityProvisionState {
assets: assets.clone(),
assets: transform_asset_entry(&assets, &deps)?,
slippage_tolerance,
auto_stake,
receiver,
sender: info.sender.to_string(),
};
LIQUIDITY_PROVISION_STATE.save(deps.storage, &liquidity_state)?;

let asset_infos: Vec<AssetInfo> = asset_infos
let asset_infos: Vec<AssetInfo> = assets
.iter()
.map(|asset_info| transform_asset_info(asset_info, &deps))
.map(|asset| transform_asset_entry_info(asset, &deps))
.collect::<Result<Vec<AssetInfo>, ContractError>>()?;

let create_factory_pair_msg = AstroportFactoryExecuteMsg::CreatePair {
Expand Down Expand Up @@ -561,10 +564,15 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr
// Store the pair address
let pair_addr = AndrAddr::from_string(pair_address.clone());

Ok(Response::default().add_attributes(vec![
attr("action", "create_pair_success"),
attr("pair_address", pair_addr),
]))
let pair_addr_attr = pair_addr.to_string();
Ok(Response::default()
.add_attributes(vec![
attr("action", "create_pair_success"),
attr("pair_address", pair_addr_attr.clone()),
])
.add_event(
Event::new("created pool").add_attribute("pool_address", pair_addr_attr),
))
}
ASTROPORT_MSG_CREATE_PAIR_AND_PROVIDE_LIQUIDITY_ID => {
if msg.result.is_err() {
Expand Down Expand Up @@ -660,11 +668,20 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr
response = response.add_message(msg);
}

Ok(response.add_attributes(vec![
attr("action", "create_pair_and_provide_liquidity_success"),
attr("pair_address", pair_address),
attr("liquidity_assets", format!("{:?}", liquidity_state.assets)),
]))
Ok(response
.add_attributes(vec![
attr("action", "create_pair_and_provide_liquidity_success"),
attr("pair_address", pair_address.clone()),
attr(
"liquidity_assets",
format!("{:?}", liquidity_state.assets.clone()),
),
])
.add_event(
Event::new("liquidity_provided")
.add_attribute("pair_address", pair_address)
.add_attribute("assets", format!("{:?}", liquidity_state.assets)),
))
}
ASTROPORT_MSG_PROVIDE_LIQUIDITY_ID => {
if msg.result.is_err() {
Expand All @@ -675,7 +692,8 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr
}

Ok(Response::default()
.add_attributes(vec![attr("action", "provide_liquidity_success")]))
.add_attributes(vec![attr("action", "provide_liquidity_success")])
.add_event(Event::new("liquidity_provided").add_attribute("status", "success")))
}
ASTROPORT_MSG_WITHDRAW_LIQUIDITY_ID => {
if msg.result.is_err() {
Expand Down Expand Up @@ -738,10 +756,15 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr
}
}

Ok(Response::new().add_messages(messages).add_attributes(vec![
attr("action", "withdraw_liquidity_success"),
attr("recipient", withdrawal_state),
]))
Ok(Response::new()
.add_messages(messages)
.add_attributes(vec![
attr("action", "withdraw_liquidity_success"),
attr("recipient", withdrawal_state.clone()),
])
.add_event(
Event::new("liquidity_withdrawn").add_attribute("recipient", withdrawal_state),
))
}
_ => Err(ContractError::Std(StdError::generic_err(
"Invalid Reply ID".to_string(),
Expand Down
65 changes: 48 additions & 17 deletions contracts/socket/andromeda-socket-osmosis/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use andromeda_std::{
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
attr, ensure, BankMsg, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Reply, Response,
StdError, SubMsg, SubMsgResponse, SubMsgResult,
attr, ensure, BankMsg, Binary, CosmosMsg, Deps, DepsMut, Env, Event, MessageInfo, Reply,
Response, StdError, SubMsg, SubMsgResponse, SubMsgResult,
};
use cw2::set_contract_version;
use cw_utils::one_coin;
Expand Down Expand Up @@ -130,14 +130,23 @@ fn execute_swap_and_forward(
route,
)?;

let from_denom_attr = from_denom.clone();
let to_denom_attr = to_denom.clone();
Ok(Response::default()
.add_submessage(swap_msg)
.add_attributes(vec![
attr("from_denom", from_denom),
attr("from_denom", from_denom_attr.clone()),
attr("from_amount", fund.amount),
attr("to_denom", to_denom),
attr("to_denom", to_denom_attr.clone()),
attr("recipient", recipient.get_addr()),
]))
])
.add_event(
Event::new("swap_and_forward")
.add_attribute("from_denom", from_denom_attr)
.add_attribute("from_amount", fund.amount.to_string())
.add_attribute("to_denom", to_denom_attr)
.add_attribute("recipient", recipient.get_addr()),
))
}

pub fn execute_create_pool(
Expand Down Expand Up @@ -229,7 +238,13 @@ pub fn execute_create_pool(
}
};

Ok(Response::default().add_submessage(msg))
Ok(Response::default().add_submessage(msg).add_event(
Event::new("create_pool_requested")
.add_attribute("denom0", denom0.clone())
.add_attribute("amount0", amount0.to_string())
.add_attribute("denom1", denom1.clone())
.add_attribute("amount1", amount1.to_string()),
))
}

fn execute_withdraw_pool(
Expand Down Expand Up @@ -341,13 +356,22 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr
});

WITHDRAW.save(deps.storage, spender.clone(), &pool_id.to_string())?;
Ok(Response::default().add_message(msg).add_attributes(vec![
attr("action", "balancer_pool_created"),
attr("lp_token", lp_token.denom.clone()),
attr("spender", spender),
attr("amount", lp_token.amount.to_string()),
attr("pool_id", pool_id.to_string()),
]))
Ok(Response::default()
.add_message(msg)
.add_attributes(vec![
attr("action", "balancer_pool_created"),
attr("lp_token", lp_token.denom.clone()),
attr("spender", spender),
attr("amount", lp_token.amount.to_string()),
attr("pool_id", pool_id.to_string()),
])
.add_event(
Event::new("pool_created")
.add_attribute("pool_type", "balancer")
.add_attribute("pool_id", pool_id.to_string())
.add_attribute("lp_token", lp_token.denom)
.add_attribute("amount", lp_token.amount.to_string()),
))
} else {
Err(ContractError::Std(StdError::generic_err(format!(
"Osmosis balancer pool creation failed with error: {:?}",
Expand All @@ -362,7 +386,9 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr
msg.result.unwrap_err()
))));
}
Ok(Response::default().add_attributes(vec![attr("action", "stable_pool_created")]))
Ok(Response::default()
.add_attributes(vec![attr("action", "stable_pool_created")])
.add_event(Event::new("pool_created").add_attribute("pool_type", "stable")))
}
OSMOSIS_MSG_CREATE_CONCENTRATED_POOL_ID => {
if msg.result.is_err() {
Expand All @@ -372,7 +398,8 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr
))));
}
Ok(Response::default()
.add_attributes(vec![attr("action", "concentrated_pool_created")]))
.add_attributes(vec![attr("action", "concentrated_pool_created")])
.add_event(Event::new("pool_created").add_attribute("pool_type", "concentrated")))
}
OSMOSIS_MSG_CREATE_COSM_WASM_POOL_ID => {
if msg.result.is_err() {
Expand All @@ -381,7 +408,9 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr
msg.result.unwrap_err()
))));
}
Ok(Response::default().add_attributes(vec![attr("action", "cosmwasm_pool_created")]))
Ok(Response::default()
.add_attributes(vec![attr("action", "cosmwasm_pool_created")])
.add_event(Event::new("pool_created").add_attribute("pool_type", "cosmwasm")))
}
OSMOSIS_MSG_WITHDRAW_POOL_ID => {
if msg.result.is_err() {
Expand All @@ -390,7 +419,9 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr
msg.result.unwrap_err()
))));
}
Ok(Response::default().add_attributes(vec![attr("action", "pool_withdrawn")]))
Ok(Response::default()
.add_attributes(vec![attr("action", "pool_withdrawn")])
.add_event(Event::new("pool_withdrawn").add_attribute("status", "success")))
}
_ => Err(ContractError::Std(StdError::generic_err(
"Invalid Reply ID".to_string(),
Expand Down
Loading
Loading