Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

enable flat portion option on swaps #149

Merged
merged 2 commits into from
Sep 27, 2023
Merged

enable flat portion option on swaps #149

merged 2 commits into from
Sep 27, 2023

Conversation

ewilz
Copy link
Member

@ewilz ewilz commented Sep 25, 2023

it can be difficult to use PAY_PORTION with exactOut trades to be able to get a clean output amount for the swapper, since we're always taking a percentage of total amount out (exact + fee %). So we must work backwards from that total amount, and since bips don't have very high precision, it becomes very hard to get the swapper their exactOut wihtout imprecision.

This PR allows taking a flat fee to accomplish clean numbers on exactOut trades.

@ewilz ewilz requested review from zhongeric and marktoda September 27, 2023 16:36
@@ -107,6 +115,25 @@ export class UniswapTrade implements Command {
}
}

// If there is a flat fee, that absolute amount is sent to the fee recipient
// In the case where ETH is the output currency, the fee is taken in WETH (for gas reasons)
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, so the fee transfer happens after the swap but before the unwrap?

@@ -251,6 +251,23 @@ describe('Uniswap', () => {
expect(methodParameters.value).to.eq(methodParametersV2.value)
})

it('encodes a single exactOutput ETH->USDC swap, with a flat fee', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe can add an exactOut, eth out test since we have that edge case where the fee is taken in WETH just to make sure its working with unwrap logic

@ewilz ewilz merged commit e928378 into main Sep 27, 2023
3 checks passed
@ewilz ewilz deleted the flat_fee branch September 27, 2023 22:54
@marktoda marktoda changed the title enable flat fee option on swaps enable flat portion option on swaps Oct 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants