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(volume-fee): free some assets from fee #5180

Merged
merged 8 commits into from
Dec 17, 2024
Merged

Conversation

shoom3301
Copy link
Collaborator

@shoom3301 shoom3301 commented Dec 11, 2024

Summary

In order to make some assets free from volume fees, we added a new list in CMS.
The list is fetched from CMS as /api/tax-free-assets. There is a limit on items count - 500 (for all networks).
The list might contain two types of items:

  1. { chainId: "MAINNET", tokenIds: "0xae7ab96520de3a18e5e111b5eaab095312d7fe84,0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" }
    When two tokenIds are specified, then only this specific pair will be free from fees. In this example it is stETH/ETH and ETH/stETH trades

  2. { chainId: "MAINNET", tokenIds: "0xdef1ca1fb7fbcdc777520aa7f396b4e015f497ab" }
    When only one tokenId is specified, then all trades with this token will be free from fees. In this example it is */COW and COW/* trades

When a rule works, then you should see Tax free trade detected message in console (debug level).

To Test

For testing I added two rules in Sepolia (you can change it in CMS in Tax Free Assets collection):

  • GNO/COW
  • WETH
  1. Add a rule in tax-free-assets collection in CMS
  2. Make sure that the data cache is updated in CoW Swap. The data is cached for one hour, in order to revalidate the cache you need to delete taxFreeAssetsUpdateTime localStorage key and reload the page. Then you should see /api/tax-free-assets request in network.
  3. Specify a trade which satisfies the rule
  • "Tax free trade detected" message should be displayed in logs
  • the trade should be free from fees
  • other trades should be taxed following the existing rules
  • widget partner fee should not be affected by this feature

@shoom3301 shoom3301 requested review from a team December 11, 2024 08:01
@shoom3301 shoom3301 self-assigned this Dec 11, 2024
Copy link

vercel bot commented Dec 11, 2024

Deployment failed with the following error:

You don't have permission to create a Preview Deployment for this project.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

Copy link

vercel bot commented Dec 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
cosmos ✅ Ready (Inspect) Visit Preview Dec 13, 2024 9:16am
cowfi ✅ Ready (Inspect) Visit Preview Dec 13, 2024 9:16am
explorer-dev ✅ Ready (Inspect) Visit Preview Dec 13, 2024 9:16am
sdk-tools ✅ Ready (Inspect) Visit Preview Dec 13, 2024 9:16am
swap-dev ✅ Ready (Inspect) Visit Preview Dec 13, 2024 9:16am
widget-configurator ✅ Ready (Inspect) Visit Preview Dec 13, 2024 9:16am

const shouldSkipFee = get(shouldSkipFeeAtom)

if (!widgetPartnerFee && shouldSkipFee) {
console.debug('Tax free trade detected', tradeState)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove the log after testing

Copy link

@elena-zh elena-zh left a comment

Choose a reason for hiding this comment

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

Looks good,
It would be great to make this field mandatory in the cms, and add a multiple choice there :)
image

@anxolin anxolin added the RELEASE Included in the release that is being closed label Dec 17, 2024
Copy link
Contributor

@anxolin anxolin left a comment

Choose a reason for hiding this comment

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

Soft approve. I think is good enough, but the CMS design wouldn't be my first choice

We can actually make a registry with 2 fields, one mandatory, one optional
This is easier to maintain in the CMS and simpler to use

setTaxFreeAssets(state)
},
SWR_CONFIG,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel we have many updaters with a very similar logic. Just different fetch function and local storage var. Maybe we should make it more homogeneous at some point

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I would think that the logic of the "last check" is something SWR does for you. If serves a local cached data if it hasn't been invalidated

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe we should make it more homogeneous at some point

Good idea!
I will try to add a factory for this case next time

Copy link
Collaborator Author

@shoom3301 shoom3301 Dec 17, 2024

Choose a reason for hiding this comment

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

"last check" is something SWR does for you

It works within the current session, but if you reload the page it will reset, so we have to add localStorage state

@shoom3301 shoom3301 merged commit 362c9a5 into develop Dec 17, 2024
12 of 13 checks passed
@shoom3301 shoom3301 deleted the feat/tax-free-assets branch December 17, 2024 11:17
@github-actions github-actions bot locked and limited conversation to collaborators Dec 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
RELEASE Included in the release that is being closed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants