Skip to content

Commit

Permalink
Rename CoinList::find_coin to CoinList::coin and use &str as argument
Browse files Browse the repository at this point in the history
  • Loading branch information
lubkoll committed Aug 23, 2024
1 parent 761805c commit 49e91e3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
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

0 comments on commit 49e91e3

Please sign in to comment.