Skip to content

feat: cow affiliate fees#6621

Merged
gomesalexandre merged 13 commits intodevelopfrom
feat_cow_affiliate
Apr 4, 2024
Merged

feat: cow affiliate fees#6621
gomesalexandre merged 13 commits intodevelopfrom
feat_cow_affiliate

Conversation

@gomesalexandre
Copy link
Copy Markdown
Contributor

@gomesalexandre gomesalexandre commented Apr 2, 2024

Description

This PR:

  • Calculates the amount after fees including affiliate fees
  • Ensure the buyAmount in appData is first affiliate-fee deducted (if applicable) before being slippage deducted
  • Constructs appData with recipient and bps as a percentage (0-100) according to CoW's AppData spec

Pull Request Type

  • 🐛 Bug fix (Non-breaking Change: Fixes an issue)
  • 🛠️ Chore (Non-breaking Change: Doc updates, pkg upgrades, typos, etc..)
  • 💅 New Feature (Breaking/Non-breaking Change)

Issue (if applicable)

closes #6610

Risk

High Risk PRs Require 2 approvals

Low, though if we get this wrong, solvers won't process the order and it may be stuck forever

What protocols, transaction types or contract interactions might be affected by this PR?

Testing

  • CoW orders are still happy without affiliate fees
  • CoW quotes now have affiliate fees if applicable (higher than the minimum no-fees threshold, and not enough FOX held for full fees waiving)
  • Fees are deducted at receive amount time (compare against prod with a similar quote)
  • CoW orders with fees still execute properly

Engineering

  • ☝🏽
  • Test with the monkey patch below to get fees even on smaller swaps
diff --git a/src/lib/fees/parameters/swapper.ts b/src/lib/fees/parameters/swapper.ts
index 00c8e46ce1..a65bdc854d 100644
--- a/src/lib/fees/parameters/swapper.ts
+++ b/src/lib/fees/parameters/swapper.ts
@@ -2,7 +2,7 @@ import type { FeeCurveParameters } from './types'
 
 const FEE_CURVE_MAX_FEE_BPS = 49 // basis points
 const FEE_CURVE_MIN_FEE_BPS = 10 // basis points
-const FEE_CURVE_NO_FEE_THRESHOLD_USD = 1_000 // usd
+const FEE_CURVE_NO_FEE_THRESHOLD_USD = 1 // usd
 const FEE_CURVE_FOX_MAX_DISCOUNT_THRESHOLD = 300_000 // fox
 const FEE_CURVE_MIDPOINT_USD = 150_000 // usd
 const FEE_CURVE_STEEPNESS_K = 40_000 // unitless

Operations

Screenshots (if applicable)

Prod (left) vs this diff (right)

Bigly swap

image

Note this now makes the protocol fee actually correct - 0bps previously should obviously be 0$

Smallish swap

image

Notice no difference against prod here since affiliate fees are waived by small trade threshold

E2E swap with the monkey-patch above

image image image image image

https://explorer.cow.fi/gc/orders/0x9c3f70e49560ec1868754b30061de1cdea6872462bf7328e75d0d615f32f62225daf465a9ccf64deb146eeae9e7bd40d6761c986660d5420?tab=overview
https://gnosisscan.io/tx/0x5db39bc658e7e66f21a3a5a4212227bc6d86f43b5b67c58c28942e4995081602

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @gomesalexandre and the rest of your teammates on Graphite Graphite

Comment thread src/lib/swapper/swappers/CowSwapper/utils/helpers/helpers.ts
@gomesalexandre gomesalexandre marked this pull request as ready for review April 3, 2024 12:38
@gomesalexandre gomesalexandre requested a review from a team as a code owner April 3, 2024 12:38
Comment thread src/lib/swapper/swappers/CowSwapper/utils/helpers/helpers.ts Outdated
Comment thread src/lib/swapper/swappers/CowSwapper/utils/helpers/helpers.ts Outdated
Comment thread src/lib/swapper/swappers/CowSwapper/types.ts Outdated
Comment thread src/lib/swapper/swappers/CowSwapper/endpoints.ts
@kaladinlight
Copy link
Copy Markdown
Contributor

And to confirm, this is no longer blocked. The partner fee bps is actually bps (not percent as described in their google doc) and therefore can support our fee params as expected?

@gomesalexandre
Copy link
Copy Markdown
Contributor Author

And to confirm, this is no longer blocked. The partner fee bps is actually bps (not percent as described in their google doc) and therefore can support our fee params as expected?

That's precisely it!

@gomesalexandre gomesalexandre enabled auto-merge (squash) April 4, 2024 18:24
@gomesalexandre gomesalexandre merged commit 4844a2c into develop Apr 4, 2024
@gomesalexandre gomesalexandre deleted the feat_cow_affiliate branch April 4, 2024 18:30
0xApotheosis pushed a commit that referenced this pull request Apr 7, 2024
0xApotheosis added a commit that referenced this pull request Apr 10, 2024
* add watch asset functionality

* feat: regenerate asset data 04/02/2024 (#6620)

* feat: disable sym deposits after RUNE (#6622)

* fix: don't bork asset generation on idle API failures (#6619)

* feat: collect 0x trade surplus (#6625)

* feat: bottom sheet dialog (#6623)

* add bottom sheet dialog

* try out vaul

* hook up send

* Create SubPage.tsx

* adjusting dialog header

* Update DialogCloseButton.tsx

* add new action menu

* updates

* update more height stuff

* use 100dvh instead of vh

* use 100vh

* anchor footer at the bottom of the screen

* update new asset search

* Update SelectAssets.tsx

* add min height for regular modals

* Update MobileNavBar.tsx

* remove extra stuff not needed for PR

* remove more stuff not for this PR

* Update AddressInput.tsx

* Update AddressInput.tsx

* Update Dialog.tsx

* Update SelectAssets.tsx

* fix for dialog height

* Update AssetSearch.tsx

---------

Co-authored-by: gomes <17035424+gomesalexandre@users.noreply.github.com>

* chore: use unchained proxy endpoints over nownodes proxy (#6606)

* feat: use proxy validation endpoint (#6626)

* feat: use proxy validation endpoint

* chore: improve fn name

* update endpoint

* fix: csp

* fix: tests

* chore: use shapeshift proxy csp

* chore: fail open

---------

Co-authored-by: kaladinlight <35275952+kaladinlight@users.noreply.github.com>

* feat: many migrations (#6631)

* fix: remove portal on account dropdown (#6635)

* account down remove portal

* Update StepRow.tsx

* feat: cow affiliate fees (#6621)

* chore: update app translations (#6638)

* chore: invalidate outdated translations

* Translate main.json via GitLocalize

* Translate main.json via GitLocalize

* Translate main.json via GitLocalize

* Translate main.json via GitLocalize

* Translate main.json via GitLocalize

* Translate main.json via GitLocalize

* Translate main.json via GitLocalize

* Translate main.json via GitLocalize

* Translate main.json via GitLocalize

* Translate main.json via GitLocalize

---------

Co-authored-by: Hellhound13 <hellhound13@gmx.at>
Co-authored-by: Jpanam <jorgepana26@hotmail.com>
Co-authored-by: yuki <yuki@beyondclub.xyz>
Co-authored-by: guiribabrb <guilherme.rb.barbosa@gmail.com>
Co-authored-by: Markus Meyer <djarmy@gmail.com>
Co-authored-by: Romko <29romko29@gmail.com>
Co-authored-by: tonyjiang12399 <327904087@qq.com>

* feat: cow quote/unsigned order build cleanup (#6639)

* feat: getFullAppData tests

* feat: cow quote/unsigned order build cleanup

* fix: deep merge opportunities accounts (#6627)

* feat: regenerate asset data 04/04/2024 (#6636)

Co-authored-by: GitHub Action <action@github.com>

* fix: defi aggregated opportunities uniqBy id first (#6628)

* fix: zapperAssetToMaybeAssetId handle base-token as native asset

* fix: filter unique opportunities by id first

* Revert "fix: zapperAssetToMaybeAssetId handle base-token as native asset"

This reverts commit 1ed1a59.

* feat: lending loan summary repayment lock (#6642)

* fix: mobile dashboard routing (#6637)

* feat: thorchain lp disable max deposits (#6645)

* feat: uni-v2 pools static generation (#6629)

* feat: uni-v2 pools static generation

* feat: revert DynamicLpAssets flag

* feat: regen

* feat: cleanup asset upserty bits

* feat: regen

* feat: regenerate asset data 04/08/2024 (#6648)

* feat: thorchain LP charts (#6624)

* add home page

* trigger ci

* Update AssetActions.tsx

* feat: tag foxy as expired opportunity (#6651)

* fix: empty my position pools page (#6656)

Update YourPositions.tsx

* Update src/pages/Home/Home.tsx

Co-authored-by: gomes <17035424+gomesalexandre@users.noreply.github.com>

* Update src/state/slices/preferencesSlice/preferencesSlice.ts

Co-authored-by: gomes <17035424+gomesalexandre@users.noreply.github.com>

* rename to assetIds

* rework the avatar

* more comments

* add top assets default

* feat: naming

---------

Co-authored-by: woodenfurniture <125113430+woodenfurniture@users.noreply.github.com>
Co-authored-by: gomes <17035424+gomesalexandre@users.noreply.github.com>
Co-authored-by: Apotheosis <0xapotheosis@gmail.com>
Co-authored-by: kevin <35275952+kaladinlight@users.noreply.github.com>
Co-authored-by: firebomb1 <88804546+firebomb1@users.noreply.github.com>
Co-authored-by: Hellhound13 <hellhound13@gmx.at>
Co-authored-by: Jpanam <jorgepana26@hotmail.com>
Co-authored-by: yuki <yuki@beyondclub.xyz>
Co-authored-by: guiribabrb <guilherme.rb.barbosa@gmail.com>
Co-authored-by: Markus Meyer <djarmy@gmail.com>
Co-authored-by: Romko <29romko29@gmail.com>
Co-authored-by: tonyjiang12399 <327904087@qq.com>
Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: Apotheosis <97164662+0xApotheosis@users.noreply.github.com>
0xApotheosis added a commit that referenced this pull request Apr 16, 2024
* feat: regenerate asset data 04/02/2024 (#6620)

* feat: disable sym deposits after RUNE (#6622)

* fix: don't bork asset generation on idle API failures (#6619)

* feat: collect 0x trade surplus (#6625)

* feat: bottom sheet dialog (#6623)

* add bottom sheet dialog

* try out vaul

* hook up send

* Create SubPage.tsx

* adjusting dialog header

* Update DialogCloseButton.tsx

* add new action menu

* updates

* update more height stuff

* use 100dvh instead of vh

* use 100vh

* anchor footer at the bottom of the screen

* update new asset search

* Update SelectAssets.tsx

* add min height for regular modals

* Update MobileNavBar.tsx

* remove extra stuff not needed for PR

* remove more stuff not for this PR

* Update AddressInput.tsx

* Update AddressInput.tsx

* Update Dialog.tsx

* Update SelectAssets.tsx

* fix for dialog height

* Update AssetSearch.tsx

---------

Co-authored-by: gomes <17035424+gomesalexandre@users.noreply.github.com>

* chore: use unchained proxy endpoints over nownodes proxy (#6606)

* feat: use proxy validation endpoint (#6626)

* feat: use proxy validation endpoint

* chore: improve fn name

* update endpoint

* fix: csp

* fix: tests

* chore: use shapeshift proxy csp

* chore: fail open

---------

Co-authored-by: kaladinlight <35275952+kaladinlight@users.noreply.github.com>

* feat: many migrations (#6631)

* fix: remove portal on account dropdown (#6635)

* account down remove portal

* Update StepRow.tsx

* feat: cow affiliate fees (#6621)

* chore: update app translations (#6638)

* chore: invalidate outdated translations

* Translate main.json via GitLocalize

* Translate main.json via GitLocalize

* Translate main.json via GitLocalize

* Translate main.json via GitLocalize

* Translate main.json via GitLocalize

* Translate main.json via GitLocalize

* Translate main.json via GitLocalize

* Translate main.json via GitLocalize

* Translate main.json via GitLocalize

* Translate main.json via GitLocalize

---------

Co-authored-by: Hellhound13 <hellhound13@gmx.at>
Co-authored-by: Jpanam <jorgepana26@hotmail.com>
Co-authored-by: yuki <yuki@beyondclub.xyz>
Co-authored-by: guiribabrb <guilherme.rb.barbosa@gmail.com>
Co-authored-by: Markus Meyer <djarmy@gmail.com>
Co-authored-by: Romko <29romko29@gmail.com>
Co-authored-by: tonyjiang12399 <327904087@qq.com>

* feat: cow quote/unsigned order build cleanup (#6639)

* feat: getFullAppData tests

* feat: cow quote/unsigned order build cleanup

* fix: deep merge opportunities accounts (#6627)

* feat: regenerate asset data 04/04/2024 (#6636)

Co-authored-by: GitHub Action <action@github.com>

* fix: defi aggregated opportunities uniqBy id first (#6628)

* fix: zapperAssetToMaybeAssetId handle base-token as native asset

* fix: filter unique opportunities by id first

* Revert "fix: zapperAssetToMaybeAssetId handle base-token as native asset"

This reverts commit 1ed1a59.

* feat: lending loan summary repayment lock (#6642)

* fix: mobile dashboard routing (#6637)

* feat: thorchain lp disable max deposits (#6645)

* feat: uni-v2 pools static generation (#6629)

* feat: uni-v2 pools static generation

* feat: revert DynamicLpAssets flag

* feat: regen

* feat: cleanup asset upserty bits

* feat: regen

* feat: regenerate asset data 04/08/2024 (#6648)

* feat: thorchain LP charts (#6624)

* feat: tag foxy as expired opportunity (#6651)

* fix: empty my position pools page (#6656)

Update YourPositions.tsx

* feat: add first pass WarningAcknowledgement component

* chore: use translations

* chore: wire up savers deposit

* chore: tidy

* feat: use warningAcknowledgement in trade quote confirm

* feat: use warningAcknowledgement in trade quote confirm

* feat: use warningAcknowledgement in trade lp deposit

* fix: trade quote input warning logic

* chore: use dimmed background

* chore: component a little closer to mock

* chore: component tweaks

* chore: style fixes

* chore: use cancel translation

* fix: trade confirm warning

* Update WarningAcknowledgement.tsx

* Update WarningAcknowledgement.tsx

* feat: chart styles and loading state (#6655)

* fix: thor token repayments (#6676)

* fix: don't render back button on modals initial routes (#6675)

* chore: use translations & constants

* chore: address review feedback

* fix: unbork trade widget size

* fix: show minimum trade amount when unsafe

* fix: trade confirm width

* chore: trigger CI

* fix: typo

* chore: extract motion style to constant

* fix: add no min fallback message

---------

Co-authored-by: woodenfurniture <125113430+woodenfurniture@users.noreply.github.com>
Co-authored-by: gomes <17035424+gomesalexandre@users.noreply.github.com>
Co-authored-by: reallybeard <89934888+reallybeard@users.noreply.github.com>
Co-authored-by: kevin <35275952+kaladinlight@users.noreply.github.com>
Co-authored-by: firebomb1 <88804546+firebomb1@users.noreply.github.com>
Co-authored-by: Hellhound13 <hellhound13@gmx.at>
Co-authored-by: Jpanam <jorgepana26@hotmail.com>
Co-authored-by: yuki <yuki@beyondclub.xyz>
Co-authored-by: guiribabrb <guilherme.rb.barbosa@gmail.com>
Co-authored-by: Markus Meyer <djarmy@gmail.com>
Co-authored-by: Romko <29romko29@gmail.com>
Co-authored-by: tonyjiang12399 <327904087@qq.com>
Co-authored-by: GitHub Action <action@github.com>
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.

cow swap fees

2 participants