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

Rename CoinList::find_coin to CoinList::coin and use &str as argument #812

Merged
merged 1 commit into from
Aug 26, 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
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ impl CoinList {
CoinList(coins)
}

pub fn find_coin(&self, denom: String) -> Coin {
pub fn find(&self, denom: &str) -> Coin {
self.0
.iter()
.find(|c| c.denom == denom)
.cloned()
.unwrap_or(Coin {
denom,
denom: denom.to_string(),
amount: 0u128.into(),
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,10 @@ pub fn get_unused_pair_balances(
env: &Env,
pool_config: &PoolConfig,
) -> Result<Vec<Coin>, ContractError> {
// Get unused balances from the contract. This is the amount of tokens that are not currently in a position.
// This amount already includes the withdrawn amounts from previous steps as in this reply those funds already compose the contract balance.
let unused_balances = get_unused_balances(&deps.querier, env)?;

// Use the unused balances to get the token0 and token1 amounts that we can use to create a new position
let base = unused_balances.find_coin(pool_config.token0.clone());
let quote = unused_balances.find_coin(pool_config.token1.clone());
let base = unused_balances.find(&pool_config.token0);
let quote = unused_balances.find(&pool_config.token1);

Ok(vec![base, quote])
}
Expand Down
4 changes: 2 additions & 2 deletions smart-contracts/osmosis/contracts/cl-vault/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub fn query_total_assets(deps: Deps, env: Env) -> Result<TotalAssetsResponse, C
denom: token0.denom.clone(),
amount: token0
.amount
.checked_add(unused_balance.find_coin(token0.denom).amount)?,
.checked_add(unused_balance.find(&token0.denom).amount)?,
};

let mut token1 = position
Expand All @@ -203,7 +203,7 @@ pub fn query_total_assets(deps: Deps, env: Env) -> Result<TotalAssetsResponse, C
denom: token1.denom.clone(),
amount: token1
.amount
.checked_add(unused_balance.find_coin(token1.denom).amount)?,
.checked_add(unused_balance.find(&token1.denom).amount)?,
};

Ok(TotalAssetsResponse { token0, token1 })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ pub fn execute_withdraw(
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 dust0: Uint256 = unused_balances
.find_coin(pool_config.token0.clone())
.amount
.into();
let dust1: Uint256 = unused_balances.find_coin(pool_config.token1).amount.into();
let dust0: Uint256 = unused_balances.find(&pool_config.token0).amount.into();
let dust1: Uint256 = unused_balances.find(&pool_config.token1).amount.into();

let user_dust0: Uint128 = dust0
.checked_mul(shares_to_withdraw)?
Expand Down
Loading