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

properly handle pre swap fixed costs #173

Merged
merged 4 commits into from
Jul 3, 2023

Conversation

marktoda
Copy link
Collaborator

@marktoda marktoda commented Jun 28, 2023

  • feat: properly handle pre-swap fixed costs
  • fix: add tests

Pre-swap fixed costs like wrapping ETH should be factored into startAmounts instead of endAmounts

This commit also cleans up the gas adjustment logic to use gasNative / gasQuote from classic over a fixed number of gas units, rather than automatically including the original gas units.

Costs such as the user wrapping ETH into WETH before a gouda swap should
not be handled like other gas adjustments since they are _required_ to
be paid by the user up-front. They should be factored into the
startAmount and used in the decision making process between gouda and
classic
@marktoda marktoda force-pushed the properly-handle-pre-swap-fixed-costs branch from c207fe3 to eb5669d Compare June 28, 2023 22:29
@marktoda marktoda force-pushed the properly-handle-pre-swap-fixed-costs branch from eb5669d to 4215d7e Compare June 28, 2023 22:30
test/utils/fixtures.ts Show resolved Hide resolved
return DutchQuote.getGasAdjustedAmounts(
amounts,
// apply both the gouda gas adjustment and the routing gas adjustment
gasAdjustment.add(classicQuote.toJSON().gasUseEstimate),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Kind of confused here, so in this case we're passing in the GOUDA_BASE overhead, plus the original gas use estimation from routing-api into the gasAdjustment param. Isn't the gas from routing-api already factored into the amounts, thus this would be double counting it? I guess I may also be getting thrown off by the param names since imo gasAdjustment is strictly anything additional we are adding here

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we are using the non-gasAdjusted amounts from the routing API. So in that case we aren't double counting.

I believe we are only using the gasAdjustment param here to calculate a ratio of how much more/less quote token we get when we account for gouda gas overhead. See line 298.
cc: @marktoda at least I think so

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh that makes sense then if we are using quote

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we're actually using the gasAdjustment value.. i think eric is right; we're double counting :D

Copy link
Contributor

@rileydcampbell rileydcampbell left a comment

Choose a reason for hiding this comment

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

lgtm, after we clear up Eric's comment

lib/entities/quote/DutchQuote.ts Outdated Show resolved Hide resolved
lib/entities/quote/DutchQuote.ts Outdated Show resolved Hide resolved
return DutchQuote.getGasAdjustedAmounts(
amounts,
// apply both the gouda gas adjustment and the routing gas adjustment
gasAdjustment.add(classicQuote.toJSON().gasUseEstimate),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we are using the non-gasAdjusted amounts from the routing API. So in that case we aren't double counting.

I believe we are only using the gasAdjustment param here to calculate a ratio of how much more/less quote token we get when we account for gouda gas overhead. See line 298.
cc: @marktoda at least I think so

@marktoda marktoda merged commit 37b5b62 into main Jul 3, 2023
4 checks passed
@marktoda marktoda deleted the properly-handle-pre-swap-fixed-costs branch July 3, 2023 17:20
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.

None yet

3 participants