-
Notifications
You must be signed in to change notification settings - Fork 27
ref: Osmosis socket queries #971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 7 commits
78f73f2
717a352
d728f8c
6c08949
cd1d0be
715b780
cfea38f
eac0eb3
37d9637
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
|---|---|---|
|
|
@@ -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, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
@@ -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, | ||
|
|
@@ -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)] | ||
|
|
@@ -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 { | ||
|
|
@@ -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!( | ||
|
|
@@ -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 } => { | ||
| 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), | ||
| } | ||
| } | ||
|
|
@@ -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!( | ||
|
|
@@ -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); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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!( | ||
|
|
@@ -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!( | ||
|
|
@@ -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!( | ||
|
|
||
| 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" | ||
| ); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
PoolsCreatedquery