Skip to content

Commit

Permalink
twap_window_seconds in vault_config struct
Browse files Browse the repository at this point in the history
  • Loading branch information
magiodev committed Aug 26, 2024
1 parent 0654332 commit 9e23567
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions smart-contracts/osmosis/contracts/cl-vault/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result<Response, Co
swap_max_slippage: old_vault_config.swap_max_slippage,
dex_router: old_vault_config.dex_router,
swap_admin: msg.swap_admin,
twap_window_seconds: msg.twap_window_seconds,
},
)?;

Expand Down Expand Up @@ -314,6 +315,7 @@ mod tests {
env,
MigrateMsg {
swap_admin: Addr::unchecked("swap_admin"),
twap_window_seconds: 24u64,
},
)
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions smart-contracts/osmosis/contracts/cl-vault/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,5 @@ pub struct InstantiateMsg {
#[cw_serde]
pub struct MigrateMsg {
pub swap_admin: Addr,
pub twap_window_seconds: u64,
}
1 change: 1 addition & 0 deletions smart-contracts/osmosis/contracts/cl-vault/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct VaultConfig {
pub swap_max_slippage: Decimal,
pub dex_router: Addr,
pub swap_admin: Addr,
pub twap_window_seconds: u64,
}

pub const VAULT_CONFIG: Item<VaultConfig> = Item::new("vault_config");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ pub fn mock_deps_with_querier_with_balance(
swap_max_slippage: Decimal::from_ratio(1u128, 20u128),
dex_router: Addr::unchecked("dex_router"),
swap_admin: Addr::unchecked("swap_admin"),
twap_window_seconds: 24u64,
},
)
.unwrap();
Expand Down Expand Up @@ -320,6 +321,7 @@ pub fn mock_deps_with_querier(
swap_max_slippage: Decimal::from_ratio(1u128, 20u128),
dex_router: Addr::unchecked("dex_router"),
swap_admin: Addr::unchecked("swap_admin"),
twap_window_seconds: 24u64,
},
)
.unwrap();
Expand Down
7 changes: 7 additions & 0 deletions smart-contracts/osmosis/contracts/cl-vault/src/vault/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ mod tests {
swap_max_slippage: Decimal::from_ratio(1u128, 100u128),
dex_router: Addr::unchecked("old_dex_router"),
swap_admin: Addr::unchecked("old_swap_admin"),
twap_window_seconds: 0u64,
};
let mut deps = mock_dependencies();
ADMIN_ADDRESS.save(deps.as_mut().storage, &admin).unwrap();
Expand All @@ -346,6 +347,7 @@ mod tests {
swap_max_slippage: Decimal::from_ratio(1u128, 100u128),
dex_router: Addr::unchecked("new_dex_router"),
swap_admin: Addr::unchecked("new_swap_admin"),
twap_window_seconds: 24u64,
};
let info_admin: MessageInfo = mock_info("admin", &[]);

Expand All @@ -365,6 +367,7 @@ mod tests {
swap_max_slippage: Decimal::from_ratio(1u128, 100u128),
dex_router: Addr::unchecked("old_dex_router"),
swap_admin: Addr::unchecked("old_swap_admin"),
twap_window_seconds: 0u64,
};
let mut deps = mock_dependencies();
ADMIN_ADDRESS.save(deps.as_mut().storage, &admin).unwrap();
Expand All @@ -378,6 +381,7 @@ mod tests {
swap_max_slippage: Decimal::from_ratio(1u128, 100u128),
dex_router: Addr::unchecked("new_dex_router"),
swap_admin: Addr::unchecked("new_swap_admin"),
twap_window_seconds: 24u64,
};
let info_not_admin = mock_info("not_admin", &[]);

Expand All @@ -397,6 +401,7 @@ mod tests {
swap_max_slippage: Decimal::from_ratio(1u128, 100u128),
dex_router: Addr::unchecked("old_dex_router"),
swap_admin: Addr::unchecked("old_swap_admin"),
twap_window_seconds: 0u64,
};
let mut deps = mock_dependencies();
ADMIN_ADDRESS.save(deps.as_mut().storage, &admin).unwrap();
Expand All @@ -410,6 +415,7 @@ mod tests {
swap_max_slippage: Decimal::from_ratio(1u128, 100u128),
dex_router: Addr::unchecked("new_dex_router"),
swap_admin: Addr::unchecked("new_swap_admin"),
twap_window_seconds: 24u64,
};

let info_admin_with_funds = mock_info("admin", &[coin(1, "token")]);
Expand All @@ -427,6 +433,7 @@ mod tests {
swap_max_slippage: Decimal::from_ratio(1u128, 100u128),
dex_router: Addr::unchecked("old_dex_router"),
swap_admin: Addr::unchecked("old_swap_admin"),
twap_window_seconds: 24u64,
};
let mut deps = mock_dependencies();
ADMIN_ADDRESS.save(deps.as_mut().storage, &admin).unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
},
query::{query_total_assets, query_total_vault_token_supply},
reply::Replies,
state::{CURRENT_SWAP_ANY_DEPOSIT, DEX_ROUTER, POOL_CONFIG, SHARES, VAULT_DENOM},
state::{CURRENT_SWAP_ANY_DEPOSIT, DEX_ROUTER, POOL_CONFIG, SHARES, VAULT_CONFIG, VAULT_DENOM},
vault::{
concentrated_liquidity::{get_cl_pool_info, get_position},
swap::{estimate_swap_min_out_amount, swap_msg},
Expand Down Expand Up @@ -60,10 +60,11 @@ pub(crate) fn execute_any_deposit(
return execute_deposit(&mut deps, env, recipient, deposit_info);
}

let vault_config = VAULT_CONFIG.load(deps.storage)?;
let twap_price = get_twap_price(
&deps.querier,
env.block.time,
24u64,
vault_config.twap_window_seconds,
pool_config.pool_id,
pool_config.clone().token0,
pool_config.clone().token1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn prepare_swap_msg(
let twap_price = get_twap_price(
&deps.querier,
env.block.time,
twap_window_seconds.unwrap_or(24u64),
twap_window_seconds.unwrap_or(vault_config.twap_window_seconds),
pool_id,
token_in.denom.to_string(),
token_out_denom.to_string(),
Expand Down

0 comments on commit 9e23567

Please sign in to comment.