Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
50 changes: 25 additions & 25 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-socket-osmosis"
version = "0.1.2-b.5"
name = "andromeda-osmosis-socket"
version = "0.1.2-b.6"
edition = "2021"
rust-version = "1.86.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ use cosmwasm_std::{
use cw2::set_contract_version;
use cw_utils::one_coin;

use osmosis_std::types::osmosis::concentratedliquidity::poolmodel::concentrated::v1beta1::MsgCreateConcentratedPoolResponse;
use osmosis_std::types::osmosis::cosmwasmpool::v1beta1::MsgCreateCosmWasmPoolResponse;
use osmosis_std::types::osmosis::gamm::poolmodels::balancer::v1beta1::MsgCreateBalancerPoolResponse;
use osmosis_std::types::osmosis::gamm::poolmodels::stableswap::v1beta1::MsgCreateStableswapPoolResponse;
use osmosis_std::types::osmosis::gamm::v1beta1::MsgExitPool;
use osmosis_std::types::{
cosmos::base::v1beta1::Coin as OsmosisCoin,
osmosis::{
concentratedliquidity::poolmodel::concentrated::v1beta1::MsgCreateConcentratedPool,
cosmwasmpool::v1beta1::MsgCreateCosmWasmPool,
gamm::poolmodels::{
balancer::v1beta1::MsgCreateBalancerPool, stableswap::v1beta1::MsgCreateStableswapPool,
concentratedliquidity::poolmodel::concentrated::v1beta1::{
MsgCreateConcentratedPool, MsgCreateConcentratedPoolResponse,
},
cosmwasmpool::v1beta1::{MsgCreateCosmWasmPool, MsgCreateCosmWasmPoolResponse},
gamm::{
poolmodels::{
balancer::v1beta1::{MsgCreateBalancerPool, MsgCreateBalancerPoolResponse},
stableswap::v1beta1::{MsgCreateStableswapPool, MsgCreateStableswapPoolResponse},
},
v1beta1::MsgExitPool,
},
},
};
Expand All @@ -37,7 +38,7 @@ use crate::osmosis::{
OSMOSIS_MSG_CREATE_COSM_WASM_POOL_ID, OSMOSIS_MSG_CREATE_STABLE_POOL_ID,
OSMOSIS_MSG_WITHDRAW_POOL_ID,
};
use crate::state::{WithdrawState, SPENDER, WITHDRAW, WITHDRAW_STATE};
use crate::state::{WithdrawState, POOLS_CREATED, SPENDER_AND_PARAMS, WITHDRAW, WITHDRAW_STATE};
use crate::{
osmosis::{
execute_swap_osmosis_msg, handle_osmosis_swap_reply, query_get_route,
Expand All @@ -47,10 +48,11 @@ use crate::{
};

use andromeda_socket::osmosis::{
ExecuteMsg, InstantiateMsg, Pool, QueryMsg, Slippage, SwapAmountInRoute,
ExecuteMsg, InstantiateMsg, Pool, PoolIdAndParams, PoolsCreatedResponse, QueryMsg, Slippage,
SpenderAndParams, SwapAmountInRoute,
};

const CONTRACT_NAME: &str = "crates.io:andromeda-socket-osmosis";
const CONTRACT_NAME: &str = "crates.io:andromeda-osmosis-socket";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg_attr(not(feature = "library"), entry_point)]
Expand Down Expand Up @@ -163,7 +165,13 @@ pub fn execute_create_pool(

let contract_address: String = env.contract.address.into();

SPENDER.save(deps.storage, &info.sender.to_string())?;
SPENDER_AND_PARAMS.save(
deps.storage,
&SpenderAndParams {
spender: info.sender.to_string(),
params: pool_type.clone(),
},
)?;

let msg: SubMsg = match pool_type {
Pool::Balancer {
Expand Down Expand Up @@ -247,6 +255,7 @@ fn execute_withdraw_pool(
.ok_or(ContractError::Std(StdError::generic_err(
"Pool ID not found".to_string(),
)))?
.pool_id
.parse::<u64>()
.map_err(|e| {
ContractError::Std(StdError::generic_err(format!(
Expand Down Expand Up @@ -306,6 +315,28 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result<Binary, ContractErro
from_denom,
to_denom,
} => encode_binary(&query_get_route(deps, from_denom, to_denom)?),
QueryMsg::PoolInfo { creator } => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to store pool info using factory denoms pair as 1 creator can create multiple pools

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One creator can also create multiple pools using the same denoms pair. I'm thinking a state of pool_id to pool info would be best.
And if the user forgot the pool's id, he can check using the PoolsCreated query

let pool_info = WITHDRAW
.may_load(deps.storage, creator)?
.ok_or(ContractError::Std(StdError::generic_err(
"Pool info not found".to_string(),
)))?;
let pool_info_response = PoolIdAndParams {
pool_id: pool_info.pool_id,
params: pool_info.params,
};
encode_binary(&pool_info_response)
}
QueryMsg::PoolsCreated { creator } => {
let pools_created = POOLS_CREATED
.load(deps.storage, creator)
.unwrap_or_default();
let pools_created_response = PoolsCreatedResponse {
pools: pools_created,
};
encode_binary(&pools_created_response)
}

_ => ADOContract::default().query(deps, env, msg),
}
}
Expand Down Expand Up @@ -355,23 +386,42 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr
// Query the contract's lp token balance
let lp_token = deps.querier.query_balance(env.contract.address, denom)?;

let spender = SPENDER.load(deps.storage)?;
SPENDER.remove(deps.storage);
let spender_and_params = SPENDER_AND_PARAMS.load(deps.storage)?;
SPENDER_AND_PARAMS.remove(deps.storage);
// Tranfer lp token to original sender
let msg = CosmosMsg::Bank(BankMsg::Send {
to_address: spender.clone(),
to_address: spender_and_params.spender.clone(),
amount: vec![lp_token.clone()],
});

WITHDRAW.save(deps.storage, spender.clone(), &pool_id.to_string())?;
let pool_id_and_params = PoolIdAndParams {
pool_id: pool_id.to_string(),
params: spender_and_params.params,
};

WITHDRAW.save(
deps.storage,
spender_and_params.spender.clone(),
&pool_id_and_params,
)?;

let mut pools = POOLS_CREATED
.may_load(deps.storage, spender_and_params.spender.clone())?
.unwrap_or_default();
pools.push(pool_id_and_params);
POOLS_CREATED.save(deps.storage, spender_and_params.spender.clone(), &pools)?;

Ok(Response::default().add_message(msg).add_attributes(vec![
attr("action", "balancer_pool_created"),
attr("lp_token", lp_token.denom.clone()),
attr("spender", spender.clone()),
attr("spender", spender_and_params.spender.clone()),
attr("amount", lp_token.amount.to_string()),
attr("pool_id", pool_id.to_string()),
attr("andr_osmosis_pool", pool_id.to_string()),
attr(format!("andr_{}_sender", pool_id), spender),
attr(
format!("andr_{}_sender", pool_id),
spender_and_params.spender.clone(),
),
]))
} else {
Err(ContractError::Std(StdError::generic_err(format!(
Expand All @@ -390,13 +440,16 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr
})?;

let pool_id = res.pool_id.to_string();
let spender = SPENDER.load(deps.storage)?;
SPENDER.remove(deps.storage);
let spender_and_params = SPENDER_AND_PARAMS.load(deps.storage)?;
SPENDER_AND_PARAMS.remove(deps.storage);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the pool types will add the states to Pools Created and PoolQuery

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on this?

Ok(Response::default().add_attributes(vec![
attr("action", "stable_pool_created"),
attr("andr_osmosis_pool", pool_id.clone()),
attr(format!("andr_{}_sender", pool_id), spender),
attr(
format!("andr_{}_sender", pool_id),
spender_and_params.spender.clone(),
),
]))
} else {
Err(ContractError::Std(StdError::generic_err(format!(
Expand All @@ -415,13 +468,16 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr
})?;

let pool_id = res.pool_id.to_string();
let spender = SPENDER.load(deps.storage)?;
SPENDER.remove(deps.storage);
let spender_and_params = SPENDER_AND_PARAMS.load(deps.storage)?;
SPENDER_AND_PARAMS.remove(deps.storage);

Ok(Response::default().add_attributes(vec![
attr("action", "concentrated_pool_created"),
attr("andr_osmosis_pool", pool_id.clone()),
attr(format!("andr_{}_sender", pool_id), spender),
attr(
format!("andr_{}_sender", pool_id),
spender_and_params.spender.clone(),
),
]))
} else {
Err(ContractError::Std(StdError::generic_err(format!(
Expand All @@ -440,13 +496,16 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr
})?;

let pool_id = res.pool_id.to_string();
let spender = SPENDER.load(deps.storage)?;
SPENDER.remove(deps.storage);
let spender_and_params = SPENDER_AND_PARAMS.load(deps.storage)?;
SPENDER_AND_PARAMS.remove(deps.storage);

Ok(Response::default().add_attributes(vec![
attr("action", "cosmwasm_pool_created"),
attr("andr_osmosis_pool", pool_id.clone()),
attr(format!("andr_{}_sender", pool_id), spender),
attr(
format!("andr_{}_sender", pool_id),
spender_and_params.spender.clone(),
),
]))
} else {
Err(ContractError::Std(StdError::generic_err(format!(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use andromeda_socket::osmosis::{ExecuteMsg, InstantiateMsg, QueryMsg};
use andromeda_std::{ado_base::MigrateMsg, contract_interface, deploy::ADOMetadata};

pub const CONTRACT_ID: &str = "socket-osmosis";
pub const CONTRACT_ID: &str = "osmosis-socket";

contract_interface!(
SocketOsmosisContract,
OsmosisSocketContract,
CONTRACT_ID,
"andromeda_socket_osmosis.wasm"
"andromeda_osmosis_socket.wasm"
);
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ pub mod state;
mod interface;

#[cfg(not(target_arch = "wasm32"))]
pub use crate::interface::SocketOsmosisContract;
pub use crate::interface::OsmosisSocketContract;
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use andromeda_socket::osmosis::{PoolIdAndParams, SpenderAndParams};
use andromeda_std::amp::{messages::AMPCtx, AndrAddr, Recipient};
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, Uint128};
Expand Down Expand Up @@ -25,7 +26,8 @@ pub const SWAP_ROUTER: Item<AndrAddr> = Item::new("swap_router");

pub const PREV_BALANCE: Item<Uint128> = Item::new("prev_balance");

pub const SPENDER: Item<String> = Item::new("spender");
// Spender's address and the pool's parameters
pub const SPENDER_AND_PARAMS: Item<SpenderAndParams> = Item::new("spender_and_params");

#[cw_serde]
pub struct WithdrawState {
Expand All @@ -36,5 +38,8 @@ pub struct WithdrawState {
// Store withdrawal state for reply handling
pub const WITHDRAW_STATE: Item<WithdrawState> = Item::new("withdraw_state");

// pool creator to pool id (keeping for backward compatibility)
pub const WITHDRAW: Map<String, String> = Map::new("withdraw");
// pool creator to pool id and the pool's parameters (keeping for backward compatibility)
pub const WITHDRAW: Map<String, PoolIdAndParams> = Map::new("withdraw");

// pool creator to pool id and the pool's parameters
pub const POOLS_CREATED: Map<String, Vec<PoolIdAndParams>> = Map::new("pools_created");
Loading
Loading