Skip to content

Commit

Permalink
Merge pull request #26 from apollodao/dev/remove-sender-arg
Browse files Browse the repository at this point in the history
fix: Remove sender arg in simulate swap
  • Loading branch information
apollo-sturdy authored Aug 14, 2023
2 parents f0c572a + 556dcff commit 924c494
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 62 deletions.
134 changes: 93 additions & 41 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 2 additions & 13 deletions src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,22 +332,14 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
QueryMsg::SimulateSwapOperations {
offer_amount,
operations,
sender,
} => to_binary(&simulate_swap_operations(
deps,
offer_amount,
operations,
sender,
)?),
} => to_binary(&simulate_swap_operations(deps, offer_amount, operations)?),
QueryMsg::SimulateBasketLiquidate {
offer_assets,
receive_asset,
sender,
} => to_binary(&simulate_basket_liquidate(
deps,
offer_assets,
receive_asset,
sender,
)?),
QueryMsg::PathForPair {
offer_asset,
Expand All @@ -370,7 +362,6 @@ pub fn simulate_swap_operations(
deps: Deps,
mut offer_amount: Uint128,
operations: SwapOperationsListUnchecked,
sender: Option<String>,
) -> Result<Uint128, ContractError> {
let operations = operations.check(deps)?;

Expand All @@ -391,7 +382,6 @@ pub fn simulate_basket_liquidate(
deps: Deps,
offer_assets: AssetListUnchecked,
receive_asset: AssetInfoUnchecked,
sender: Option<String>,
) -> Result<Uint128, ContractError> {
let offer_assets = offer_assets.check(deps.api)?;
let receive_asset = receive_asset.check(deps.api)?;
Expand All @@ -411,8 +401,7 @@ pub fn simulate_basket_liquidate(

// Loop over paths and simulate swap operations
for (asset, path) in paths {
receive_amount +=
simulate_swap_operations(deps, asset.amount, path.into(), sender.clone())?;
receive_amount += simulate_swap_operations(deps, asset.amount, path.into())?;
}

Ok(receive_amount)
Expand Down
4 changes: 0 additions & 4 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,12 @@ impl CwDexRouter {
querier: &QuerierWrapper,
offer_amount: Uint128,
operations: &SwapOperationsList,
sender: Option<String>,
) -> StdResult<Uint128> {
querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
contract_addr: self.0.to_string(),
msg: to_binary(&QueryMsg::SimulateSwapOperations {
offer_amount,
operations: operations.into(),
sender,
})?,
}))
}
Expand All @@ -183,14 +181,12 @@ impl CwDexRouter {
querier: &QuerierWrapper,
offer_assets: AssetList,
receive_asset: &AssetInfo,
sender: Option<String>,
) -> StdResult<Uint128> {
querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
contract_addr: self.0.to_string(),
msg: to_binary(&QueryMsg::SimulateBasketLiquidate {
offer_assets: offer_assets.into(),
receive_asset: receive_asset.to_owned().into(),
sender,
})?,
}))
}
Expand Down
4 changes: 0 additions & 4 deletions src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,12 @@ pub enum QueryMsg {
SimulateSwapOperations {
offer_amount: Uint128,
operations: SwapOperationsListUnchecked,
// For some reason osmosis requires this to simulate a swap...
sender: Option<String>,
},

#[returns(Uint128)]
SimulateBasketLiquidate {
offer_assets: AssetListUnchecked,
receive_asset: AssetInfoUnchecked,
// For some reason osmosis requires this to simulate a swap...
sender: Option<String>,
},

/// Returns all the current path for a given (offer_asset, ask_asset) pair.
Expand Down

0 comments on commit 924c494

Please sign in to comment.