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(spike): taker fee #6034

Merged
merged 94 commits into from
Aug 28, 2023
Merged

feat(spike): taker fee #6034

merged 94 commits into from
Aug 28, 2023

Conversation

czarcas7ic
Copy link
Member

@czarcas7ic czarcas7ic commented Aug 14, 2023

Closes: #XXX

What is the purpose of the change

This feature adds taker fee logic to poolmanager when making a swap. It is important to note that all swap logic messages are routed through poolmanager. This means that if you call a swap method directly in GAMM or CL (and not via the message), taker fees will not be charged.

There are two txfees module accounts that taker fees accrue and get swapped in: An account for staking rewards and an account for community pool.

If the taker fee is in osmo:

  • the parameterized community pool percent goes directly to the community pool
  • the parameterized staking rewards percent goes to the txfees staking rewards module account, and is sent to the actual staking rewards module account at epoch.

If the taker fee is non osmo but a whitelisted quote asset:

  • the parameterized community pool percent goes directly to the community pool
  • the parameterized staking rewards percent goes to the txfees staking rewards module account, is swapped to OSMO at epoch, then sent to the actual staking rewards module account.

If the taker fee is non osmo and non whitelisted quote asset:

  • the parameterized community pool percent goes to the txfees community pool module account and is swapped to the parameterized asset (defaults to USDC) at epoch, then is sent to the actual community pool module account
  • the parameterized staking rewards percent goes to the txfees staking rewards module account, is swapped to OSMO at epoch, then sent to the actual staking rewards module account.

hooks.go, taker_fee.go, and router.go will be the ones to pay the most attention to.

Pre v19 Release:

  • Add all missing tests for hooks.go
  • Add all missing tests for taker_fee.go
  • Add all missing tests for upgrades.go
  • Add an E2E test for this. The CL test indirectly tested this properly, so we really just need a test that checks the module accounts and ensures the epoch swaps and distributes properly
  • In upgrade handler, set default taker fee to 0
  • Backport v18 upgrade handler to main

Post v19 Release:

  • Make issue to remove whitelisted quote denoms in CL module in v20
  • Have skip change the takerFee to non zero in their test suite so they can confirm the number changes

Testing and Verifying

TBD

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes?
  • Changelog entry added to Unreleased section of CHANGELOG.md?

Where is the change documented?

  • Specification (x/{module}/README.md)
  • Osmosis documentation site
  • Code comments?
  • N/A

@github-actions github-actions bot added the C:x/gamm Changes, features and bugs related to the gamm module. label Aug 14, 2023
@github-actions github-actions bot added the C:simulator Edits simulator or simulations label Aug 17, 2023
@czarcas7ic
Copy link
Member Author

devbot help

@devbot-wizard
Copy link
Collaborator

Hi! I'm DevBot, a bot that helps with common tasks in the development process. Commands:

  • devbot fix: Fix basic errors in the PR. (e.g. imports, changelog conflicts, go mod conflicts)
  • devbot merge base: Merge the base branch into the PR branch.
  • devbot add changelog [misc/feat/bug/api/sec] [message]: Add a changelog entry to the PR. (e.g. devbot add changelog feat Added a new feature)
    • If message is blank, defaults to PR title.
  • devbot re-pr: Re-PR the PR, useful for external contributors where we have no edit perms.

@czarcas7ic
Copy link
Member Author

devbot add changelog feat

@czarcas7ic czarcas7ic added the V:state/breaking State machine breaking PR label Aug 17, 2023
),
})

return &types.MsgSetDenomPairTakerFeeResponse{Success: true}, nil
Copy link
Member

Choose a reason for hiding this comment

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

Why do we have a success field in response, should we just remove this?

(not returning an error => success, right)

Copy link
Member Author

Choose a reason for hiding this comment

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

Follows the same format as other messages with no important return values. If we decide this, we should remove it from all of them at a single time imo.

Copy link
Member

Choose a reason for hiding this comment

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

I'm unaware of us doing this convention. I at least think we shouldn't introduce the design pattern more, unless this is replicated in the SDK

}
}

func TestDenomPairTakerFeeProposal_ValidateBasic(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to come back to this later, where I feel like we can make some more general method to get these guarantees

Comment on lines +50 to +51
TakerFeeParams: TakerFeeParams{
DefaultTakerFee: sdk.MustNewDecFromStr("0.0015"), // 0.15%
Copy link
Member

Choose a reason for hiding this comment

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

I think we should be setting the precise param we want in the upgrade handler, and not have so many denoms in defaults

Comment on lines +63 to +68
AuthorizedQuoteDenoms: []string{
"uosmo",
"ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", // ATOM
"ibc/0CD3A0285E1341859B5E86B6AB7682F023D03E97607CCC1DC95706411D866DF7", // DAI
"ibc/D189335C6E4A68B513C10AB227BF1C1D38C746766278BA3EEB4FB14124F1D858", // USDC
},
Copy link
Member

Choose a reason for hiding this comment

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

(For testnets) we may want it s.t. if this list is blank, it allows anything.

That can be done in a mainnet non-breaking way, so can be done later.

@ValarDragon
Copy link
Member

I propose we get pool-manager side in a state were proud of as one PR, and then txfees as second

Copy link
Contributor

@AlpinYukseloglu AlpinYukseloglu left a comment

Choose a reason for hiding this comment

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

Core logic LGTM, nice work. Approving to get this base PR in, understanding that there are potential changes that will need to be done in follow up PRs as discussed on call

@github-actions github-actions bot added the T:CI label Aug 28, 2023
@czarcas7ic czarcas7ic merged commit 5c8fd80 into main Aug 28, 2023
1 check passed
@czarcas7ic czarcas7ic deleted the adam/taker-fee-feat branch August 28, 2023 17:11
mergify bot pushed a commit that referenced this pull request Aug 28, 2023
* add taker fee determination and extraction

* remove osmo multi hop logic

* route to both community pool and staking rewards

* fix a handfull of tests

* assign taker fee to pool at time of creation

* pull taker fee direct from pool struct

* fix more tests

* fix tests, set back up osmo multi hop discount

* correct taker fee extraction

* regen mocks

* abstract taker fee to pool manager (highest lvl)

* fix extract cmd

* update changelog

* tidy

* remove param that no longer exists

* add extra params to genesis logic

* add back osmo multihop tests

* add comment

* fix e2e keeping prints

* fixes

* more test fixes

* remove prints

* more naive approach to determining taker fee

* fix e2e

* re-enable disabled test

* minor cleaning

* simplify params

* not nullable

* clean up

* add whitelist set message denom pair taker fees

* use real addresses

* add gov prop for denom pair taker fee update

* clean

* move logic to its own taker_fee.go file

* add CLI for gov prop for denomPairTakerFee

* add admin address denomPairTakerFee cli msg

* clean and simplifications

* use authorized quote denoms from poolmanger

* remove stableswap taker fee

* sim msg change

* add test for CLI

* msg server tests

* add route_test test

* add gov_test.go

* add msgs_test.go

* remove print line

* change from v18 to v19

* Update upgrades.go

* set default taker fee to zero in upgrade handler

* conflicts

* Update proto/osmosis/poolmanager/v1beta1/genesis.proto

* Update proto/osmosis/poolmanager/v1beta1/genesis.proto

* Update x/poolmanager/taker_fee.go

* Generated protofile changes

* rename extractTakerFeeAndDistribute to chargeTakerFee

* clean up

* comment

* rename

* godoc for NonNativeFeeCollectorForCommunityPoolName

* baseDenom to defaultFeesDenom name change

* fix upgrade handler

* fix AfterEpochEnd order of denoms when getting pools; reduce code dupl; tests

* fix track volume

* add key separator for pool manager

* add comment to denom pair route

* add basic lexicographical key test

* update chargeTakerFee godoc

* set the default taker fee back to non zero for e2e

* change PoolMangerGetParams API to  GetAuthorizedQuoteDenoms (same for setters)

* update txfees & poolmanager READMEs with takerFee

* fix merge main

* add comment to denom pair taker fee

* de-dup taker fee param validation

* Update x/poolmanager/types/msgs.go

* Apply suggestions from code review

* Update x/poolmanager/taker_fee.go

* remove unneeded setup test

* get pool creation free from previous

* take non native out of name

* undo param pull instead of default

* use current pool creation fee

* use default

* e2e

---------

Co-authored-by: devbot-wizard <141283918+devbot-wizard@users.noreply.github.com>
Co-authored-by: Roman <roman@osmosis.team>
Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: alpo <yukseloglua@berkeley.edu>
Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
Co-authored-by: Dev Ojha <dojha@berkeley.edu>
(cherry picked from commit 5c8fd80)

# Conflicts:
#	CHANGELOG.md
#	tests/e2e/e2e_test.go
#	x/poolmanager/export_test.go
#	x/poolmanager/router.go
#	x/poolmanager/types/keys.go
czarcas7ic added a commit that referenced this pull request Aug 29, 2023
* feat(spike): taker fee (#6034)

* add taker fee determination and extraction

* remove osmo multi hop logic

* route to both community pool and staking rewards

* fix a handfull of tests

* assign taker fee to pool at time of creation

* pull taker fee direct from pool struct

* fix more tests

* fix tests, set back up osmo multi hop discount

* correct taker fee extraction

* regen mocks

* abstract taker fee to pool manager (highest lvl)

* fix extract cmd

* update changelog

* tidy

* remove param that no longer exists

* add extra params to genesis logic

* add back osmo multihop tests

* add comment

* fix e2e keeping prints

* fixes

* more test fixes

* remove prints

* more naive approach to determining taker fee

* fix e2e

* re-enable disabled test

* minor cleaning

* simplify params

* not nullable

* clean up

* add whitelist set message denom pair taker fees

* use real addresses

* add gov prop for denom pair taker fee update

* clean

* move logic to its own taker_fee.go file

* add CLI for gov prop for denomPairTakerFee

* add admin address denomPairTakerFee cli msg

* clean and simplifications

* use authorized quote denoms from poolmanger

* remove stableswap taker fee

* sim msg change

* add test for CLI

* msg server tests

* add route_test test

* add gov_test.go

* add msgs_test.go

* remove print line

* change from v18 to v19

* Update upgrades.go

* set default taker fee to zero in upgrade handler

* conflicts

* Update proto/osmosis/poolmanager/v1beta1/genesis.proto

* Update proto/osmosis/poolmanager/v1beta1/genesis.proto

* Update x/poolmanager/taker_fee.go

* Generated protofile changes

* rename extractTakerFeeAndDistribute to chargeTakerFee

* clean up

* comment

* rename

* godoc for NonNativeFeeCollectorForCommunityPoolName

* baseDenom to defaultFeesDenom name change

* fix upgrade handler

* fix AfterEpochEnd order of denoms when getting pools; reduce code dupl; tests

* fix track volume

* add key separator for pool manager

* add comment to denom pair route

* add basic lexicographical key test

* update chargeTakerFee godoc

* set the default taker fee back to non zero for e2e

* change PoolMangerGetParams API to  GetAuthorizedQuoteDenoms (same for setters)

* update txfees & poolmanager READMEs with takerFee

* fix merge main

* add comment to denom pair taker fee

* de-dup taker fee param validation

* Update x/poolmanager/types/msgs.go

* Apply suggestions from code review

* Update x/poolmanager/taker_fee.go

* remove unneeded setup test

* get pool creation free from previous

* take non native out of name

* undo param pull instead of default

* use current pool creation fee

* use default

* e2e

---------

Co-authored-by: devbot-wizard <141283918+devbot-wizard@users.noreply.github.com>
Co-authored-by: Roman <roman@osmosis.team>
Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: alpo <yukseloglua@berkeley.edu>
Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
Co-authored-by: Dev Ojha <dojha@berkeley.edu>
(cherry picked from commit 5c8fd80)

# Conflicts:
#	CHANGELOG.md
#	tests/e2e/e2e_test.go
#	x/poolmanager/export_test.go
#	x/poolmanager/router.go
#	x/poolmanager/types/keys.go

* fix merge conflicts

* change json

* inc num heights to wait

* Update .github/workflows/test.yml

* test with v18 init image

* removed old upgrade logic

---------

Co-authored-by: Adam Tucker <adam@osmosis.team>
Co-authored-by: Adam Tucker <adamleetucker@outlook.com>
Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
nicolaslara pushed a commit that referenced this pull request Aug 31, 2023
* add taker fee determination and extraction

* remove osmo multi hop logic

* route to both community pool and staking rewards

* fix a handfull of tests

* assign taker fee to pool at time of creation

* pull taker fee direct from pool struct

* fix more tests

* fix tests, set back up osmo multi hop discount

* correct taker fee extraction

* regen mocks

* abstract taker fee to pool manager (highest lvl)

* fix extract cmd

* update changelog

* tidy

* remove param that no longer exists

* add extra params to genesis logic

* add back osmo multihop tests

* add comment

* fix e2e keeping prints

* fixes

* more test fixes

* remove prints

* more naive approach to determining taker fee

* fix e2e

* re-enable disabled test

* minor cleaning

* simplify params

* not nullable

* clean up

* add whitelist set message denom pair taker fees

* use real addresses

* add gov prop for denom pair taker fee update

* clean

* move logic to its own taker_fee.go file

* add CLI for gov prop for denomPairTakerFee

* add admin address denomPairTakerFee cli msg

* clean and simplifications

* use authorized quote denoms from poolmanger

* remove stableswap taker fee

* sim msg change

* add test for CLI

* msg server tests

* add route_test test

* add gov_test.go

* add msgs_test.go

* remove print line

* change from v18 to v19

* Update upgrades.go

* set default taker fee to zero in upgrade handler

* conflicts

* Update proto/osmosis/poolmanager/v1beta1/genesis.proto

* Update proto/osmosis/poolmanager/v1beta1/genesis.proto

* Update x/poolmanager/taker_fee.go

* Generated protofile changes

* rename extractTakerFeeAndDistribute to chargeTakerFee

* clean up

* comment

* rename

* godoc for NonNativeFeeCollectorForCommunityPoolName

* baseDenom to defaultFeesDenom name change

* fix upgrade handler

* fix AfterEpochEnd order of denoms when getting pools; reduce code dupl; tests

* fix track volume

* add key separator for pool manager

* add comment to denom pair route

* add basic lexicographical key test

* update chargeTakerFee godoc

* set the default taker fee back to non zero for e2e

* change PoolMangerGetParams API to  GetAuthorizedQuoteDenoms (same for setters)

* update txfees & poolmanager READMEs with takerFee

* fix merge main

* add comment to denom pair taker fee

* de-dup taker fee param validation

* Update x/poolmanager/types/msgs.go

* Apply suggestions from code review

* Update x/poolmanager/taker_fee.go

* remove unneeded setup test

* get pool creation free from previous

* take non native out of name

* undo param pull instead of default

* use current pool creation fee

* use default

* e2e

---------

Co-authored-by: devbot-wizard <141283918+devbot-wizard@users.noreply.github.com>
Co-authored-by: Roman <roman@osmosis.team>
Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: alpo <yukseloglua@berkeley.edu>
Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
Co-authored-by: Dev Ojha <dojha@berkeley.edu>
@p0mvn p0mvn mentioned this pull request Sep 1, 2023
@github-actions github-actions bot mentioned this pull request Mar 15, 2024
@github-actions github-actions bot mentioned this pull request May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:backport/v19.x backport patches to v19.x branch C:app-wiring Changes to the app folder C:CLI C:docs Improvements or additions to documentation C:simulator Edits simulator or simulations C:x/concentrated-liquidity C:x/gamm Changes, features and bugs related to the gamm module. C:x/poolmanager C:x/superfluid C:x/twap Changes to the twap module C:x/txfees T:CI V:state/breaking State machine breaking PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants