Skip to content

Commit

Permalink
Move cw_vault_extension msgs to quasar-types (#849)
Browse files Browse the repository at this point in the history
This PR moves the code from quasar-finance/cw-vault-extension into the
quasar-types package
  • Loading branch information
lubkoll authored Sep 10, 2024
1 parent fda2ffb commit 41add93
Show file tree
Hide file tree
Showing 22 changed files with 1,844 additions and 45 deletions.
1 change: 0 additions & 1 deletion smart-contracts/osmosis/contracts/cl-vault/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ cw2 = { workspace = true }
num_enum = { workspace = true }
apollo-cw-asset = { workspace = true }
dex-router-osmosis = {workspace = true}
cw-vault-multi-standard = {git = "https://github.com/quasar-finance/cw-vault-standard", branch ="master", features = ["lockup", "force-unlock"]}
osmosis-test-tube = { workspace = true, optional = true }
quasar-types = { workspace = true }

Expand Down
78 changes: 38 additions & 40 deletions smart-contracts/osmosis/contracts/cl-vault/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use crate::helpers::prepend::prepend_claim_msg;
use crate::instantiate::{
handle_create_denom_reply, handle_instantiate, handle_instantiate_create_position_reply,
};
use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, ModifyRangeMsg, QueryMsg};
use crate::msg::{
ClQueryMsg, ExecuteMsg, ExtensionExecuteMsg, ExtensionQueryMsg, InstantiateMsg, MigrateMsg,
ModifyRangeMsg, QueryMsg,
};
use crate::query::{
query_assets_from_shares, query_dex_router, query_info, query_metadata, query_pool,
query_position, query_total_assets, query_total_vault_token_supply, query_user_assets,
Expand Down Expand Up @@ -40,6 +43,7 @@ use cosmwasm_std::{
};
use cw2::set_contract_version;
use cw_storage_plus::{Item, Map};
use quasar_types::cw_vault_multi_standard::{VaultStandardExecuteMsg, VaultStandardQueryMsg};
// version info for migration info
const CONTRACT_NAME: &str = "crates.io:cl-vault";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
Expand All @@ -63,32 +67,32 @@ pub fn execute(
msg: ExecuteMsg,
) -> Result<Response, ContractError> {
match msg {
cw_vault_multi_standard::VaultStandardExecuteMsg::AnyDeposit {
VaultStandardExecuteMsg::AnyDeposit {
recipient,
max_slippage,
.. // asset and amount fields are not used in this implementation, they are for CW20 tokens
} => execute_any_deposit(deps, env, info, recipient, max_slippage),
cw_vault_multi_standard::VaultStandardExecuteMsg::ExactDeposit { recipient } => {
VaultStandardExecuteMsg::ExactDeposit { recipient } => {
execute_exact_deposit(deps, env, info, recipient)
}
cw_vault_multi_standard::VaultStandardExecuteMsg::Redeem { recipient, amount } => {
VaultStandardExecuteMsg::Redeem { recipient, amount } => {
prepend_claim_msg(
&env,
execute_withdraw(deps, &env, info, recipient, amount.into())?,
)
}
cw_vault_multi_standard::VaultStandardExecuteMsg::VaultExtension(vault_msg) => {
VaultStandardExecuteMsg::VaultExtension(vault_msg) => {
match vault_msg {
crate::msg::ExtensionExecuteMsg::Admin(admin_msg) => {
ExtensionExecuteMsg::Admin(admin_msg) => {
execute_admin(deps, info, admin_msg)
}
crate::msg::ExtensionExecuteMsg::Merge(msg) => {
ExtensionExecuteMsg::Merge(msg) => {
execute_merge_position(deps, env, info, msg)
}
crate::msg::ExtensionExecuteMsg::Autocompound {} => {
ExtensionExecuteMsg::Autocompound {} => {
prepend_claim_msg(&env, execute_autocompound(deps, &env, info)?)
}
crate::msg::ExtensionExecuteMsg::ModifyRange(ModifyRangeMsg {
ExtensionExecuteMsg::ModifyRange(ModifyRangeMsg {
lower_price,
upper_price,
max_slippage,
Expand All @@ -111,11 +115,11 @@ pub fn execute(
claim_after,
)?,
),
crate::msg::ExtensionExecuteMsg::SwapNonVaultFunds {
ExtensionExecuteMsg::SwapNonVaultFunds {
swap_operations,
twap_window_seconds,
} => execute_swap_non_vault_funds(deps, env, info, swap_operations, twap_window_seconds),
crate::msg::ExtensionExecuteMsg::CollectRewards {} => {
ExtensionExecuteMsg::CollectRewards {} => {
execute_collect_rewards(deps, env)
}
}
Expand All @@ -126,52 +130,46 @@ pub fn execute(
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result<Binary, ContractError> {
match msg {
cw_vault_multi_standard::VaultStandardQueryMsg::VaultStandardInfo {} => todo!(),
cw_vault_multi_standard::VaultStandardQueryMsg::Info {} => {
Ok(to_json_binary(&query_info(deps)?)?)
VaultStandardQueryMsg::VaultStandardInfo {} => {
todo!()
}
cw_vault_multi_standard::VaultStandardQueryMsg::PreviewDeposit { assets: _ } => todo!(),
cw_vault_multi_standard::VaultStandardQueryMsg::DepositRatio => todo!(),
cw_vault_multi_standard::VaultStandardQueryMsg::PreviewRedeem { amount: shares } => Ok(
to_json_binary(&query_assets_from_shares(deps, env, shares)?)?,
),
cw_vault_multi_standard::VaultStandardQueryMsg::TotalAssets {} => {
VaultStandardQueryMsg::Info {} => Ok(to_json_binary(&query_info(deps)?)?),
VaultStandardQueryMsg::PreviewDeposit { assets: _ } => todo!(),
VaultStandardQueryMsg::DepositRatio => todo!(),
VaultStandardQueryMsg::PreviewRedeem { amount: shares } => Ok(to_json_binary(
&query_assets_from_shares(deps, env, shares)?,
)?),
VaultStandardQueryMsg::TotalAssets {} => {
Ok(to_json_binary(&query_total_assets(deps, env)?)?)
}
cw_vault_multi_standard::VaultStandardQueryMsg::TotalVaultTokenSupply {} => {
VaultStandardQueryMsg::TotalVaultTokenSupply {} => {
Ok(to_json_binary(&query_total_vault_token_supply(deps)?)?)
}
cw_vault_multi_standard::VaultStandardQueryMsg::ConvertToShares { amount: _ } => todo!(),
cw_vault_multi_standard::VaultStandardQueryMsg::ConvertToAssets { amount: shares } => Ok(
to_json_binary(&query_assets_from_shares(deps, env, shares)?)?,
),
cw_vault_multi_standard::VaultStandardQueryMsg::VaultExtension(msg) => match msg {
crate::msg::ExtensionQueryMsg::Metadata {} => {
Ok(to_json_binary(&query_metadata(deps)?)?)
}
crate::msg::ExtensionQueryMsg::DexRouter {} => {
Ok(to_json_binary(&query_dex_router(deps)?)?)
}
crate::msg::ExtensionQueryMsg::Balances(msg) => match msg {
VaultStandardQueryMsg::ConvertToShares { amount: _ } => todo!(),
VaultStandardQueryMsg::ConvertToAssets { amount: shares } => Ok(to_json_binary(
&query_assets_from_shares(deps, env, shares)?,
)?),
VaultStandardQueryMsg::VaultExtension(msg) => match msg {
ExtensionQueryMsg::Metadata {} => Ok(to_json_binary(&query_metadata(deps)?)?),
ExtensionQueryMsg::DexRouter {} => Ok(to_json_binary(&query_dex_router(deps)?)?),
ExtensionQueryMsg::Balances(msg) => match msg {
crate::msg::UserBalanceQueryMsg::UserSharesBalance { user } => {
Ok(to_json_binary(&query_user_balance(deps, user)?)?)
}
crate::msg::UserBalanceQueryMsg::UserAssetsBalance { user } => {
Ok(to_json_binary(&query_user_assets(deps, env, user)?)?)
}
},
crate::msg::ExtensionQueryMsg::ConcentratedLiquidity(msg) => match msg {
crate::msg::ClQueryMsg::Pool {} => Ok(to_json_binary(&query_pool(deps)?)?),
crate::msg::ClQueryMsg::Position {} => Ok(to_json_binary(&query_position(deps)?)?),
crate::msg::ClQueryMsg::RangeAdmin {} => {
ExtensionQueryMsg::ConcentratedLiquidity(msg) => match msg {
ClQueryMsg::Pool {} => Ok(to_json_binary(&query_pool(deps)?)?),
ClQueryMsg::Position {} => Ok(to_json_binary(&query_position(deps)?)?),
ClQueryMsg::RangeAdmin {} => {
let range_admin = get_range_admin(deps)?;
Ok(to_json_binary(&RangeAdminResponse {
address: range_admin.to_string(),
})?)
}
crate::msg::ClQueryMsg::VerifyTickCache => {
Ok(to_json_binary(&query_verify_tick_cache(deps)?)?)
}
ClQueryMsg::VerifyTickCache => Ok(to_json_binary(&query_verify_tick_cache(deps)?)?),
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion smart-contracts/osmosis/contracts/cl-vault/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Addr, Decimal};
use cw_vault_multi_standard::{VaultStandardExecuteMsg, VaultStandardQueryMsg};
use osmosis_std::types::osmosis::poolmanager::v1beta1::SwapAmountInRoute;
use quasar_types::cw_vault_multi_standard::{VaultStandardExecuteMsg, VaultStandardQueryMsg};

#[cfg(not(target_arch = "wasm32"))]
use crate::query::{
Expand Down
2 changes: 1 addition & 1 deletion smart-contracts/osmosis/contracts/cl-vault/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::vault::concentrated_liquidity::get_position;
use crate::ContractError;
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{coin, Coin, Decimal, Deps, Env, Uint128};
use cw_vault_multi_standard::VaultInfoResponse;
use osmosis_std::types::cosmos::bank::v1beta1::BankQuerier;
use quasar_types::cw_vault_multi_standard::VaultInfoResponse;

#[cw_serde]
pub struct MetadataResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ use cl_vault::query::{
};
use cosmwasm_std::assert_approx_eq;
use cosmwasm_std::{Coin, Uint128};
use cw_vault_multi_standard::VaultStandardQueryMsg::VaultExtension;
use osmosis_std::types::cosmos::bank::v1beta1::MsgSend;
use osmosis_std::types::cosmos::base::v1beta1::Coin as OsmoCoin;
use osmosis_std::types::osmosis::poolmanager::v1beta1::SwapAmountInRoute;
use osmosis_test_tube::{Account, Bank, Module, Wasm};
use quasar_types::cw_vault_multi_standard::VaultStandardQueryMsg::VaultExtension;

const DENOM_REWARD_AMOUNT: u128 = 100_000_000_000;
const APPROX_EQ_FACTOR: &str = "0.00005";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use cl_vault::{
query::PoolResponse,
};
use cosmwasm_std::{Coin, Decimal};
use cw_vault_multi_standard::VaultInfoResponse;
use osmosis_std::types::{
cosmos::base::v1beta1,
osmosis::{
Expand All @@ -22,6 +21,7 @@ use osmosis_test_tube::{
cosmrs::proto::traits::Message, Account, ConcentratedLiquidity, Module, PoolManager,
TokenFactory, Wasm,
};
use quasar_types::cw_vault_multi_standard::VaultInfoResponse;
use std::str::FromStr;

#[test]
Expand Down
5 changes: 5 additions & 0 deletions smart-contracts/osmosis/packages/quasar-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ name = "quasar-types"
version = "0.1.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["lockup", "force-unlock"]
lockup = []
force-unlock = []

[dependencies]
cosmwasm-std = { workspace = true }
osmosis-std = { workspace = true }
osmosis-std-derive = { workspace = true }
cosmwasm-schema = { workspace = true }
cw-storage-plus ={ workspace = true }
cw-utils ={ workspace = true }
schemars ={ workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }
Expand Down
Loading

0 comments on commit 41add93

Please sign in to comment.