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

feat: add swap-baby swap adapter #143

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

fdymylja
Copy link

@fdymylja fdymylja commented Oct 4, 2024

No description provided.

Comment on lines +236 to +251
let mut hops = vec![first_hop];
// we omit the last swap operation
// since that is already the coin_out
operations.pop();
// if it is not empty, we fill the other left operations.
if !operations.is_empty() {
hops.extend(operations.into_iter().map(|op| Hop {
pool: op.pool,
denom: op.denom_out,
}));
}

let query_msg = swap_baby::QueryMsg::SimulateSwapExactAmountOutWithHops {
want_out: coin_out,
hops,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the first_hop here added twice? since only the last element is popped and then the rest of operations extend the vec (which still has the first hop)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is this intended?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is intended and it's more of a forward compatibility thing.

fundamentally swap baby does not route based on pools but routes based on assets (although it has a notion of pool)

example:

swap op is BTC->USDT->ETH (so I put BTC and want ETH out)

then the swap ops are two:

  • BTC for USDT
  • USDT for ETH

but the swap baby hops are actually three: BTC -> USDT -> ETH (the asset out) that's why the first pool is used twice, because it contains the initial input.

use cosmwasm_std::{to_json_binary, Coin, CosmosMsg, Decimal, StdResult, Uint128, WasmMsg};

#[cw_serde]
pub enum ExecuteMsg {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question to learn: Does swap baby plan to be open sourced / in a GH repo we can link to instead of copying over the types, or is this the best way forward (no plans to release the code)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soon to be open sourced!

Copy link
Member

@NotJeremyLiu NotJeremyLiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some comments, feel free to request a re-review once answered/addressed, great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants