Skip to content
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

Remove unnecessary dependencies from get_unused_(pair_)balances #825

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 16 additions & 6 deletions smart-contracts/osmosis/contracts/cl-vault/src/helpers/getters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,30 @@ pub fn get_single_sided_deposit_1_to_0_swap_amount(
Ok(swap_amount)
}

pub fn get_unused_balances(querier: &QuerierWrapper, env: &Env) -> Result<CoinList, ContractError> {
pub fn get_unused_balances(
querier: &QuerierWrapper,
addr: &Addr,
) -> Result<CoinList, ContractError> {
Ok(CoinList::from_coins(
querier.query_all_balances(env.contract.address.to_string())?,
querier.query_all_balances(addr.to_string())?,
))
}

pub fn get_unused_pair(
deps: &Deps,
addr: &Addr,
pool_config: &PoolConfig,
) -> Result<PoolPair<Coin, Coin>, ContractError> {
let unused_balances = get_unused_balances(&deps.querier, addr)?;
Ok(get_vault_funds_or_zero(&unused_balances, pool_config))
}

pub fn get_unused_pair_balances(
magiodev marked this conversation as resolved.
Show resolved Hide resolved
deps: &DepsMut,
deps: &Deps,
env: &Env,
pool_config: &PoolConfig,
) -> Result<Vec<Coin>, ContractError> {
let unused_balances = get_unused_balances(&deps.querier, env)?;
let vault_funds = get_vault_funds_or_zero(&unused_balances, pool_config);

let vault_funds = get_unused_pair(deps, &env.contract.address, pool_config)?;
Ok(vec![vault_funds.base, vault_funds.quote])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn handle_instantiate(
}
.into();

let vault_funds = get_unused_pair_balances(&deps, &env, &pool_config)?;
let vault_funds = get_unused_pair_balances(&deps.as_ref(), &env, &pool_config)?;

let create_position_msg = create_position(
deps,
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 @@ -177,7 +177,7 @@ pub fn query_user_balance(
pub fn query_total_assets(deps: Deps, env: Env) -> Result<TotalAssetsResponse, ContractError> {
let position = get_position(deps.storage, &deps.querier)?;
let pool = POOL_CONFIG.load(deps.storage)?;
let unused_balance = get_unused_balances(&deps.querier, &env)?;
let unused_balance = get_unused_balances(&deps.querier, &env.contract.address)?;

// add token0 unused balance to what's in the position
let mut token0 = position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn execute_autocompound(
.ok_or(ContractError::PositionNotFound)?;

let pool = POOL_CONFIG.load(deps.storage)?;
let balance = get_unused_pair_balances(&deps, env, &pool)?;
let balance = get_unused_pair_balances(&deps.as_ref(), env, &pool)?;

let token0 = balance[0].clone();
let token1 = balance[1].clone();
Expand Down
4 changes: 2 additions & 2 deletions smart-contracts/osmosis/contracts/cl-vault/src/vault/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub fn handle_withdraw_position_reply(deps: DepsMut, env: Env) -> Result<Respons
let pool_config = POOL_CONFIG.load(deps.storage)?;
let pool_details = get_cl_pool_info(&deps.querier, pool_config.pool_id)?;

let unused_pair_balances = get_unused_pair_balances(&deps, &env, &pool_config)?;
let unused_pair_balances = get_unused_pair_balances(&deps.as_ref(), &env, &pool_config)?;

let sqrt_pu = tick_to_price(modify_range_state.upper_tick)?.sqrt();
let sqrt_pl = tick_to_price(modify_range_state.lower_tick)?.sqrt();
Expand Down Expand Up @@ -251,7 +251,7 @@ pub fn handle_swap_reply(deps: DepsMut, env: Env) -> Result<Response, ContractEr
let swap_deposit_merge_state = SWAP_DEPOSIT_MERGE_STATE.load(deps.storage)?;
SWAP_DEPOSIT_MERGE_STATE.remove(deps.storage);
let pool_config = POOL_CONFIG.load(deps.storage)?;
let unused_pair_balances = get_unused_pair_balances(&deps, &env, &pool_config)?;
let unused_pair_balances = get_unused_pair_balances(&deps.as_ref(), &env, &pool_config)?;

let create_position_msg = create_position(
deps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn execute_withdraw(
// get the dust amounts belonging to the user
let pool_config = POOL_CONFIG.load(deps.storage)?;
// TODO replace dust with queries for balance
let unused_balances = get_unused_balances(&deps.querier, env)?;
let unused_balances = get_unused_balances(&deps.querier, &env.contract.address)?;
let dust0: Uint256 = unused_balances.find(&pool_config.token0).amount.into();
let dust1: Uint256 = unused_balances.find(&pool_config.token1).amount.into();

Expand Down
Loading