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: taker fee share #8310

Merged
merged 105 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
c2ab91a
initial push
czarcas7ic May 24, 2024
f79a1c1
Generated protofile changes
invalid-email-address May 24, 2024
24e89d5
grpc query gen
czarcas7ic May 24, 2024
f4b917b
Generated protofile changes
invalid-email-address May 24, 2024
e0f3d78
merge main
czarcas7ic May 24, 2024
d46f95c
main
czarcas7ic May 24, 2024
171ea68
Generated protofile changes
invalid-email-address May 24, 2024
d8d6a65
add changelog entry
czarcas7ic May 24, 2024
7794b99
iteration
czarcas7ic May 28, 2024
9b0114a
Merge branch 'main' into adam/taker-fee-share
czarcas7ic May 28, 2024
56be948
add message server tests
czarcas7ic May 28, 2024
72ccd22
quick lint fix
czarcas7ic May 28, 2024
a774d9a
check the extra return in router_test.go
czarcas7ic May 28, 2024
258df2b
fix some tests from including new pool type in test suite
czarcas7ic May 28, 2024
efc318c
msgs_test.go for newly added txs
czarcas7ic May 28, 2024
05bec2a
add store_test.go
czarcas7ic May 29, 2024
cc878fa
add some clarity to comments
czarcas7ic May 29, 2024
ae8bf49
more performant cache check
czarcas7ic May 29, 2024
0f9c54a
taker fee skim test
czarcas7ic May 29, 2024
b00bb68
test begin block
czarcas7ic May 29, 2024
bd12634
lint
czarcas7ic May 29, 2024
28db07c
endBlock test, remove twap changed pools
czarcas7ic May 29, 2024
1a37a0b
remove twap keeper
czarcas7ic May 29, 2024
f2d9b04
clear taker fee share accumulator test
czarcas7ic May 29, 2024
2da5245
modify afterEpochEnd test in txfees
czarcas7ic May 29, 2024
1de7c64
simplify test suite
czarcas7ic May 29, 2024
66fb5ec
further test suite simplifications
czarcas7ic May 30, 2024
cf85e76
add proto comments
czarcas7ic May 30, 2024
b8cbed0
rename maps to map
czarcas7ic May 30, 2024
d20cb0e
add array to name
czarcas7ic May 30, 2024
cab64d2
format errors
czarcas7ic May 30, 2024
15b38a3
spelling fix
czarcas7ic May 30, 2024
ca530e9
event emission for txs
czarcas7ic May 30, 2024
f67da0c
define errors
czarcas7ic May 30, 2024
e6b70ec
add comments and by pool ID query
czarcas7ic May 30, 2024
e1f49e2
perf changes in store, for retrieving pool via id
czarcas7ic May 30, 2024
94bff70
more godocs
czarcas7ic May 30, 2024
88e86ff
minor cleanup
czarcas7ic May 30, 2024
12d00be
add normalization factor tests
czarcas7ic May 30, 2024
54db624
remove legacy tier verbiage
czarcas7ic May 30, 2024
d7e8046
test cleanup
czarcas7ic May 30, 2024
bf0eb0e
test cleanup
czarcas7ic May 30, 2024
97636ef
test cleanup
czarcas7ic May 30, 2024
9bf4bb0
more test clarity
czarcas7ic May 30, 2024
e6f0cdf
add readme
czarcas7ic May 30, 2024
9b21e2d
more test cleanups
czarcas7ic May 30, 2024
1836cdf
regen proto
czarcas7ic May 30, 2024
4c3aff1
readme fix
czarcas7ic May 30, 2024
da1a478
inc alloyedAssetCompositionUpdateRate to 700
czarcas7ic May 30, 2024
0e821a3
comment
czarcas7ic May 30, 2024
307be1b
more comments
czarcas7ic May 30, 2024
f916494
comments
czarcas7ic May 30, 2024
a9e811e
comments
czarcas7ic May 30, 2024
a3b6815
hooks test cleanup
czarcas7ic May 30, 2024
68c1763
add comment
czarcas7ic May 30, 2024
3f0a8cf
change expected keeper input var name
czarcas7ic May 30, 2024
33d0854
comment change
czarcas7ic May 30, 2024
9cf4f85
return errors instead of using mustGet
czarcas7ic Jun 1, 2024
5b88a8a
handle error
czarcas7ic Jun 1, 2024
0a79fcb
add to readme about fee share greater than 1
czarcas7ic Jun 1, 2024
d63ce03
more descriptive error handling in GetAllRegisteredAlloyedPoolsIdArray
czarcas7ic Jun 1, 2024
6b754a2
improve error handling in getAlloyedDenomFromPoolId
czarcas7ic Jun 1, 2024
e73ee09
add edge case testing for IncreaseTakerFeeShareDenomsToAccruedValue
czarcas7ic Jun 1, 2024
8fb3e00
lint
czarcas7ic Jun 1, 2024
d373528
combine errors
czarcas7ic Jun 1, 2024
d08e736
error consistency
czarcas7ic Jun 1, 2024
7107983
simplify taker fee skim by using multiple methods
czarcas7ic Jun 1, 2024
10887ad
simplify snapshotTakerFeeShareAlloyComposition logic
czarcas7ic Jun 2, 2024
b519660
Merge branch 'main' into adam/taker-fee-share
czarcas7ic Jun 12, 2024
12272ae
Merge branch 'main' into adam/taker-fee-share
czarcas7ic Jun 16, 2024
556a0a0
Merge branch 'main' into adam/taker-fee-share
PaddyMc Jul 9, 2024
efec77e
fix: add signer directive to takerfee msgs, refactor function for pro…
PaddyMc Jul 15, 2024
6aa358b
use pointer for keeper in appModule (ensure this is safe)
czarcas7ic Jul 15, 2024
7eaf1bf
fix normalization
czarcas7ic Jul 15, 2024
ab50e85
test fixes
czarcas7ic Jul 15, 2024
df42c79
fix cache call from hook
czarcas7ic Jul 17, 2024
dc6b622
explicitly mark public cache methods as unsafe
czarcas7ic Jul 17, 2024
966db4f
use point to use cache for querier (confirm safe)
czarcas7ic Jul 19, 2024
6780271
Merge branch 'main' into adam/taker-fee-share
czarcas7ic Jul 19, 2024
f05a9ae
add poolid query
czarcas7ic Jul 19, 2024
d449a8a
add better example for the query commands
czarcas7ic Jul 19, 2024
81a8120
comment typo
czarcas7ic Jul 25, 2024
bdad94e
Update x/poolmanager/store.go
p0mvn Jul 25, 2024
4cbec3d
return all tier agreements, reguardless if they will be used or not
czarcas7ic Jul 25, 2024
2aaefc9
remove registered alloyed pool IDs cache
czarcas7ic Jul 25, 2024
37a1f36
preparePool to prepareTransmuterPool
czarcas7ic Jul 25, 2024
25e0e6d
add comment
czarcas7ic Jul 25, 2024
2388611
add comment on 1000000000
czarcas7ic Jul 25, 2024
1ea10fe
spelling
czarcas7ic Jul 25, 2024
160580a
fix up changelog
czarcas7ic Jul 25, 2024
4becc24
use AddMut for percentageOfTakerFeeToSkim
czarcas7ic Jul 25, 2024
dc495b2
Merge branch 'main' into adam/taker-fee-share
czarcas7ic Jul 25, 2024
a636a89
define get and set cache trackers in export_test
czarcas7ic Jul 25, 2024
a3ec53f
move event emission
czarcas7ic Jul 25, 2024
a792b3b
Update x/poolmanager/store.go
czarcas7ic Jul 25, 2024
e6d85e0
add begin block comment
czarcas7ic Jul 25, 2024
2a983cf
Merge branch 'main' into adam/taker-fee-share
czarcas7ic Jul 25, 2024
a238932
move v3 instantiateMsg proto to golang struct
czarcas7ic Jul 25, 2024
af288bd
precompute zero and one dec in poolmanager
czarcas7ic Jul 25, 2024
a0a126e
add sentence on how we propagate the knowledge of what taker fees are…
czarcas7ic Jul 25, 2024
bb2903c
add documentation on caches
czarcas7ic Jul 25, 2024
f5e9506
remove unnecessary wrapper
czarcas7ic Jul 25, 2024
ab5c9e4
move event to message server
czarcas7ic Jul 26, 2024
5d1b260
exit early if there are no share agreements
czarcas7ic Jul 26, 2024
d8e759b
length check on alloyedAssetShareAgreements
czarcas7ic Jul 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#8375](https://github.com/osmosis-labs/osmosis/pull/8375) Enforce sub-authenticator to be greater than 1
* [#8509](https://github.com/osmosis-labs/osmosis/pull/8509) Change LiquidityNetInDirection return type to sdk math
* [#8535](https://github.com/osmosis-labs/osmosis/pull/8535) Prevent Setting Invalid Before Send Hook
* [#8310](https://github.com/osmosis-labs/osmosis/pull/8310) Taker fee share
* [#8494](https://github.com/osmosis-labs/osmosis/pull/8494) Add additional events in x/lockup, x/superfluid, x/concentratedliquidity

### State Compatible
Expand Down
112 changes: 108 additions & 4 deletions app/apptesting/cosmwasmpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
DefaultTransmuterDenomANormFactor = 1
DefaultTransmuterDenomB = "gravusdc"
DefaultTransmuterDenomBNormFactor = 100
DefaultTransmuterDenomC = "nbtc"
DefaultAlloyedSubDenom = "allusdc"
DefaultAlloyedDenomNormFactor = 1000

Expand All @@ -37,6 +38,14 @@ const (
osmosisRepoTransmuterPath = "x/cosmwasmpool/bytecode"
)

type InstantiateMsg struct {
PoolAssetConfigs []AssetConfig `json:"pool_asset_configs"`
AlloyedAssetSubdenom string `json:"alloyed_asset_subdenom"`
AlloyedAssetNormalizationFactor string `json:"alloyed_asset_normalization_factor"`
Admin string `json:"admin"`
Moderator string `json:"moderator"`
}

type AssetConfig struct {
Denom string `json:"denom"`
NormalizationFactor osmomath.Int `json:"normalization_factor"`
Expand Down Expand Up @@ -70,17 +79,48 @@ func (s *KeeperTestHelper) PrepareCustomTransmuterPool(owner sdk.AccAddress, den
// Gives flexibility for the helper to be reused outside of the Osmosis repository by providing custom
// project name and bytecode path.
func (s *KeeperTestHelper) PrepareCustomTransmuterPoolCustomProject(owner sdk.AccAddress, denoms []string, projectName, byteCodePath string) cosmwasmpooltypes.CosmWasmExtension {
return s.PrepareTransmuterPool(owner, denoms, nil, projectName, byteCodePath, TransmuterContractName, s.GetTransmuterInstantiateMsgBytes)
}

// PrepareCustomTransmuterPoolV3 sets up a transmuter pool with the custom parameters for version 3 of the transmuter contract (alloyed assets).
// It initializes the pool with the provided ratio for the given denoms, using a default normalization factor of "1" for each denom.
func (s *KeeperTestHelper) PrepareCustomTransmuterPoolV3(owner sdk.AccAddress, denoms []string, ratio []uint16) cosmwasmpooltypes.CosmWasmExtension {
normalizationFactors := make([]string, len(denoms))
for i := range normalizationFactors {
normalizationFactors[i] = "1"
}
return s.PrepareCustomTransmuterPoolV3WithNormalization(owner, denoms, normalizationFactors, ratio)
}

// PrepareCustomTransmuterPoolV3WithNormalization sets up a transmuter pool with the custom parameters for version 3 of the transmuter contract (alloyed assets).
// It initializes the pool with the provided ratio for the given denoms and their respective normalization factors.
func (s *KeeperTestHelper) PrepareCustomTransmuterPoolV3WithNormalization(owner sdk.AccAddress, denoms []string, normalizationFactors []string, ratio []uint16) cosmwasmpooltypes.CosmWasmExtension {
pool := s.PrepareTransmuterPool(owner, denoms, normalizationFactors, osmosisRepository, osmosisRepoTransmuterPath, TransmuterV3ContractName, s.GetTransmuterInstantiateMsgBytesV3)
s.AddRatioFundsToTransmuterPool(s.TestAccs[0], denoms, ratio, pool.GetId())
pool, err := s.App.CosmwasmPoolKeeper.GetPoolById(s.Ctx, pool.GetId())
s.Require().NoError(err)
return pool
}

// PrepareTransmuterPool sets up a transmuter pool with the custom parameters and optional normalization factors.
func (s *KeeperTestHelper) PrepareTransmuterPool(owner sdk.AccAddress, denoms []string, normalizationFactors []string, projectName, byteCodePath, contractName string, getInstantiateMsgBytes func([]string, []string, sdk.AccAddress) []byte) cosmwasmpooltypes.CosmWasmExtension {
// Mint some assets to the account.
s.FundAcc(s.TestAccs[0], DefaultAcctFunds)

// Set the supply of the denoms, since the contract fails if the denom doesn't exist on chain.
for _, denom := range denoms {
err := s.App.BankKeeper.Supply.Set(s.Ctx, denom, osmomath.NewInt(100000000000000))
s.Require().NoError(err)
}

// Upload contract code and get the code id.
codeId := s.StoreCosmWasmPoolContractCodeCustomProject(TransmuterContractName, projectName, byteCodePath)
codeId := s.StoreCosmWasmPoolContractCodeCustomProject(contractName, projectName, byteCodePath)

// Add code id to the whitelist.
s.App.CosmwasmPoolKeeper.WhitelistCodeId(s.Ctx, codeId)

// Generate instantiate message bytes.
instantiateMsgBz := s.GetTransmuterInstantiateMsgBytes(denoms)
instantiateMsgBz := getInstantiateMsgBytes(denoms, normalizationFactors, owner)

// Generate msg create pool.
validCWPoolMsg := model.NewMsgCreateCosmWasmPool(codeId, owner, instantiateMsgBz)
Expand All @@ -96,15 +136,51 @@ func (s *KeeperTestHelper) PrepareCustomTransmuterPoolCustomProject(owner sdk.Ac
return pool
}

// AddRatioFundsToTransmuterPool adds funds to a transmuter pool based on the provided ratio of denoms.
// The number of tokens minted is equal to 1000000000 times the ratio.
// (i.e. if the ratio is 2,3,5, then the number of tokens minted for each denom will be 2000000000, 3000000000, 5000000000)
//
// Parameters:
// - owner: The account address that will own the funds.
// - denoms: A list of denominations to be added to the pool.
// - ratioOfDenoms: A list of ratios corresponding to each denom. Must be the same length as denoms.
// - poolId: The ID of the pool to which the funds will be added.
//
// Panics if the length of denoms and ratioOfDenoms are not equal.
func (s *KeeperTestHelper) AddRatioFundsToTransmuterPool(owner sdk.AccAddress, denoms []string, ratioOfDenoms []uint16, poolId uint64) {
if ratioOfDenoms == nil {
return
}

if len(denoms) != len(ratioOfDenoms) {
panic("denoms and ratioOfDenoms must be of equal length")
}

var poolCoins sdk.Coins
for i, denom := range denoms {
// 1000000000 is chosen randomly, we just want a set of coins that is equal to the ratio,
// but not so small that test cases won't have enough tokens to work with.
amount := osmomath.NewInt(int64(ratioOfDenoms[i])).Mul(osmomath.NewInt(1000000000))
if amount.IsZero() {
continue
}
poolCoins = append(poolCoins, sdk.NewCoin(denom, amount))
}

// Add funds to the pool
s.FundAcc(owner, poolCoins)
s.JoinTransmuterPool(s.TestAccs[0], poolId, poolCoins)
}

// GetDefaultTransmuterInstantiateMsgBytes returns the default instantiate message for the transmuter contract
// with DefaultTransmuterDenomA and DefaultTransmuterDenomB as the pool asset denoms.
func (s *KeeperTestHelper) GetDefaultTransmuterInstantiateMsgBytes() []byte {
return s.GetTransmuterInstantiateMsgBytes([]string{DefaultTransmuterDenomA, DefaultTransmuterDenomB})
return s.GetTransmuterInstantiateMsgBytes([]string{DefaultTransmuterDenomA, DefaultTransmuterDenomB}, nil, sdk.AccAddress{})
}

// GetTransmuterInstantiateMsgBytes returns the instantiate message for the transmuter contract with the
// given pool asset denoms.
func (s *KeeperTestHelper) GetTransmuterInstantiateMsgBytes(poolAssetDenoms []string) []byte {
func (s *KeeperTestHelper) GetTransmuterInstantiateMsgBytes(poolAssetDenoms []string, normalizationFactors []string, owner sdk.AccAddress) []byte {
instantiateMsg := msg.InstantiateMsg{
PoolAssetDenoms: poolAssetDenoms,
}
Expand All @@ -115,6 +191,34 @@ func (s *KeeperTestHelper) GetTransmuterInstantiateMsgBytes(poolAssetDenoms []st
return instantiateMsgBz
}

// GetTransmuterInstantiateMsgBytesV3 returns the instantiate message for the transmuter contract with the
// given pool asset denoms and their respective normalization factors.
func (s *KeeperTestHelper) GetTransmuterInstantiateMsgBytesV3(poolAssetDenoms []string, normalizationFactors []string, owner sdk.AccAddress) []byte {
var assetConfigs []AssetConfig
for i, denom := range poolAssetDenoms {
normalizationFactor, ok := osmomath.NewIntFromString(normalizationFactors[i])
s.Require().True(ok)

assetConfigs = append(assetConfigs, AssetConfig{
Denom: denom,
NormalizationFactor: normalizationFactor,
})
}

instantiateMsg := InstantiateMsg{
PoolAssetConfigs: assetConfigs,
AlloyedAssetSubdenom: DefaultAlloyedSubDenom,
AlloyedAssetNormalizationFactor: "1",
Admin: owner.String(),
Moderator: owner.String(),
}

instantiateMsgBz, err := json.Marshal(instantiateMsg)
s.Require().NoError(err)

return instantiateMsgBz
}

// StoreCosmWasmPoolContractCode stores the cosmwasm pool contract code in the wasm keeper and returns the code id.
// contractName is the name of the contract file in the x/cosmwasmpool/bytecode directory without the .wasm extension.
func (s *KeeperTestHelper) StoreCosmWasmPoolContractCode(contractName string) uint64 {
Expand Down
5 changes: 5 additions & 0 deletions app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type SupportedPoolAndGaugeInfo struct {
BalancerPoolID uint64
StableSwapPoolID uint64
CosmWasmPoolID uint64
AlloyedPoolID uint64

ConcentratedGaugeID uint64
BalancerGaugeID uint64
Expand Down Expand Up @@ -184,12 +185,16 @@ func (s *KeeperTestHelper) PrepareAllSupportedPoolsCustomProject(projectName, tr
stableswapPoolID = s.PrepareBasicStableswapPool()
cosmWasmPool = s.PrepareCustomTransmuterPoolCustomProject(s.TestAccs[0], []string{DefaultTransmuterDenomA, DefaultTransmuterDenomB}, projectName, transmuterPath)
cosmWasmPoolID = cosmWasmPool.GetId()
alloyedPool = s.PrepareCustomTransmuterPoolV3(s.TestAccs[0], []string{DefaultTransmuterDenomA, DefaultTransmuterDenomB}, []uint16{1, 1})
alloyedPoolID = alloyedPool.GetId()
)

return SupportedPoolAndGaugeInfo{
ConcentratedPoolID: concentratedPoolID,
BalancerPoolID: balancerPoolID,
StableSwapPoolID: stableswapPoolID,
CosmWasmPoolID: cosmWasmPoolID,
AlloyedPoolID: alloyedPoolID,

// Define expected gauge IDs:

Expand Down
2 changes: 2 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appKeepers.DistrKeeper,
appKeepers.StakingKeeper,
appKeepers.ProtoRevKeeper,
appKeepers.WasmKeeper,
)
appKeepers.PoolManagerKeeper.SetStakingKeeper(appKeepers.StakingKeeper)
appKeepers.GAMMKeeper.SetPoolManager(appKeepers.PoolManagerKeeper)
Expand Down Expand Up @@ -598,6 +599,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
)
appKeepers.WasmKeeper = &wasmKeeper
appKeepers.CosmwasmPoolKeeper.SetWasmKeeper(appKeepers.WasmKeeper)
appKeepers.PoolManagerKeeper.SetWasmKeeper(appKeepers.WasmKeeper)

// Pass the contract keeper to all the structs (generally ICS4Wrappers for ibc middlewares) that need it
appKeepers.ContractKeeper = wasmkeeper.NewDefaultPermissionKeeper(appKeepers.WasmKeeper)
Expand Down
6 changes: 3 additions & 3 deletions app/upgrades/v24/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ func (s *UpgradeTestSuite) TestUpgrade() {
// TWAP records indexed by pool ID should be untouched.
twapRecords, err = s.App.TwapKeeper.GetAllHistoricalPoolIndexedTWAPsForPoolId(s.Ctx, twapRecord1.PoolId)
s.Require().NoError(err)
s.Require().Len(twapRecords, 6)
s.Require().Equal(twapRecord1, twapRecords[4])
s.Require().Equal(twapRecord2, twapRecords[5])
s.Require().Len(twapRecords, 8)
s.Require().Equal(twapRecord1, twapRecords[6])
s.Require().Equal(twapRecord2, twapRecords[7])

// PROTOREV Tests
//
Expand Down
2 changes: 1 addition & 1 deletion ingest/common/domain/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type PoolManagerKeeper interface {
tokenIn sdk.Coin,
tokenOutDenom string,
tokenOutMinAmount osmomath.Int,
) (tokenOutAmount osmomath.Int, err error)
) (tokenOutAmount osmomath.Int, takerFeeTotal sdk.Coin, err error)

RouteGetPoolDenoms(
ctx sdk.Context,
Expand Down
38 changes: 38 additions & 0 deletions proto/osmosis/cosmwasmpool/v1beta1/model/v3/pool_query_msg.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
syntax = "proto3";
package osmosis.cosmwasmpool.v1beta1.model.v3;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/osmosis-labs/osmosis/v25/x/cosmwasmpool/cosmwasm/msg/v3";

// ===================== ShareDenomResponse
message ShareDenomResponse {
// share_denom is the share denomination.
string share_denom = 1;
}

// ===================== TotalPoolLiquidityResponse
message TotalPoolLiquidityResponse {
// total_pool_liquidity is the total liquidity in the pool denominated in
// coins.
repeated cosmos.base.v1beta1.Coin total_pool_liquidity = 1 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}

// ===================== AssetConfig
message AssetConfig {
// denom is the asset denomination.
string denom = 1;

// normalization_factor is the normalization factor for the asset.
string normalization_factor = 2;
}

// ===================== ListAssetConfigsResponse
message ListAssetConfigsResponse {
// asset_configs is the list of asset configurations.
repeated AssetConfig asset_configs = 1 [ (gogoproto.nullable) = false ];
}
Loading