Skip to content

Commit

Permalink
Merge pull request #2 from Hipo/fix-internal-swap-quotes
Browse files Browse the repository at this point in the history
Fix internal swap quotes
  • Loading branch information
gokselcoban authored Dec 15, 2022
2 parents d441b33 + b8252de commit c1dee89
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
4 changes: 2 additions & 2 deletions tinyman/v2/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@


def get_pool_logicsig(
validator_app_id: int, asset_1_id: int, asset_2_id: int
validator_app_id: int, asset_a_id: int, asset_b_id: int
) -> LogicSigAccount:
assets = [asset_1_id, asset_2_id]
assets = [asset_a_id, asset_b_id]
asset_1_id = max(assets)
asset_2_id = min(assets)

Expand Down
34 changes: 19 additions & 15 deletions tinyman/v2/pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,21 +411,25 @@ def fetch_flexible_add_liquidity_quote(
asset_2_amount=amount_2.amount,
)

internal_swap_quote = InternalSwapQuote(
amount_in=AssetAmount(
self.asset_1 if swap_from_asset_1_to_asset_2 else self.asset_2,
swap_in_amount,
),
amount_out=AssetAmount(
self.asset_2 if swap_from_asset_1_to_asset_2 else self.asset_1,
swap_out_amount,
),
swap_fees=AssetAmount(
self.asset_1 if swap_from_asset_1_to_asset_2 else self.asset_2,
swap_total_fee_amount,
),
price_impact=swap_price_impact,
)
if not swap_out_amount:
# There is no output amount, ignore the integer roundings looks like a swap.
internal_swap_quote = None
else:
internal_swap_quote = InternalSwapQuote(
amount_in=AssetAmount(
self.asset_1 if swap_from_asset_1_to_asset_2 else self.asset_2,
swap_in_amount,
),
amount_out=AssetAmount(
self.asset_2 if swap_from_asset_1_to_asset_2 else self.asset_1,
swap_out_amount,
),
swap_fees=AssetAmount(
self.asset_1 if swap_from_asset_1_to_asset_2 else self.asset_2,
swap_total_fee_amount,
),
price_impact=swap_price_impact,
)

quote = FlexibleAddLiquidityQuote(
amounts_in={
Expand Down

0 comments on commit c1dee89

Please sign in to comment.