Skip to content

Commit

Permalink
rebase to latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ajansari95 committed Jul 25, 2024
1 parent d8b21fe commit d518490
Show file tree
Hide file tree
Showing 7 changed files with 379 additions and 422 deletions.
19 changes: 12 additions & 7 deletions smart-contracts/osmosis/contracts/cl-vault/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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::{DepositType, ExecuteMsg, 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 All @@ -32,14 +32,13 @@ use crate::state::{
#[allow(deprecated)]
use crate::state::{Position, OLD_POSITION, POSITION};
use crate::vault::admin::execute_admin;
use crate::vault::any_deposit::{execute_any_deposit, handle_any_deposit_swap_reply};
use crate::vault::autocompound::{
execute_autocompound, execute_migration_step, handle_autocompound_reply,
};
use crate::vault::deposit::{execute_deposit, handle_any_deposit_swap_reply};
use crate::vault::distribution::{
execute_collect_rewards, handle_collect_incentives_reply, handle_collect_spread_rewards_reply,
};
use crate::vault::exact_deposit::execute_exact_deposit;
use crate::vault::merge::{
execute_merge_position, handle_merge_create_position_reply,
handle_merge_withdraw_position_reply,
Expand Down Expand Up @@ -80,9 +79,15 @@ pub fn execute(
asset: _,
recipient,
max_slippage,
} => execute_any_deposit(deps, env, info, recipient, max_slippage),
} => execute_deposit(
deps,
env,
info,
recipient,
DepositType::Any { max_slippage },
),
cw_vault_multi_standard::VaultStandardExecuteMsg::ExactDeposit { recipient } => {
execute_exact_deposit(deps, env, info, recipient)
execute_deposit(deps, env, info, recipient, DepositType::Exact)
}
cw_vault_multi_standard::VaultStandardExecuteMsg::Redeem { recipient, amount } => {
prepend_claim_msg(
Expand All @@ -97,10 +102,10 @@ pub fn execute(
}
crate::msg::ExtensionExecuteMsg::Authz(msg) => match msg {
crate::msg::AuthzExtension::ExactDeposit {} => {
execute_exact_deposit(deps, env, info, None)
execute_deposit(deps, env, info, None, DepositType::Exact)
}
crate::msg::AuthzExtension::AnyDeposit { max_slippage } => {
execute_any_deposit(deps, env, info, None, max_slippage)
execute_deposit(deps, env, info, None, DepositType::Any { max_slippage })
}
crate::msg::AuthzExtension::Redeem { amount } => prepend_claim_msg(
&env,
Expand Down
35 changes: 35 additions & 0 deletions smart-contracts/osmosis/contracts/cl-vault/src/helpers/getters.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::math::tick::tick_to_price;
use crate::state::{PoolConfig, RANGE_ADMIN};
use crate::vault::range::SwapDirection;
use std::str::FromStr;

use osmosis_std::shim::Timestamp as OsmoTimestamp;
Expand Down Expand Up @@ -245,6 +246,40 @@ pub fn get_tokens_provided(
Ok(tokens_provided)
}

pub fn get_swap_amount_and_direction(
balance0: Uint128,
balance1: Uint128,
current_tick: i64,
target_lower_tick: i64,
target_upper_tick: i64,
) -> Result<(Uint128, SwapDirection), ContractError> {
if !balance0.is_zero() {
let token_in_amount = if current_tick > target_upper_tick {
balance0
} else {
get_single_sided_deposit_0_to_1_swap_amount(
balance0,
target_lower_tick,
current_tick,
target_upper_tick,
)?
};
Ok((token_in_amount, SwapDirection::ZeroToOne))
} else {
let token_in_amount = if current_tick < target_lower_tick {
balance1
} else {
get_single_sided_deposit_1_to_0_swap_amount(
balance1,
target_lower_tick,
current_tick,
target_upper_tick,
)?
};
Ok((token_in_amount, SwapDirection::OneToZero))
}
}

#[cfg(test)]
mod tests {
use std::collections::HashMap;
Expand Down
5 changes: 5 additions & 0 deletions smart-contracts/osmosis/contracts/cl-vault/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ pub struct InstantiateMsg {
pub initial_upper_tick: i64,
}

pub enum DepositType {
Exact,
Any { max_slippage: Decimal },
}

#[cw_serde]
pub struct MigrateMsg {
pub dex_router: Addr,
Expand Down
Loading

0 comments on commit d518490

Please sign in to comment.