-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: track and query protocol rev across all modules (#6804)
* implement query to get protocol rev across all modules * add cli cmd * Auto: update go.mod after push to adam/all-protocol-rev-query that modified dependencies locally * add changelog * fix txfees tests * add upgrade test * fix remaining test * change from uint to int * int * dont recalc values at epoch hook call * fix upgrade test * clean up * merge taker fees into single struct * add default value for tests * add genesis test * remove old portion of test * fix test * fix tests * Auto: update go.mod after push to adam/all-protocol-rev-query that modified dependencies locally --------- Co-authored-by: github-actions <[email protected]>
- Loading branch information
1 parent
80ed7e5
commit 56d665b
Showing
54 changed files
with
3,309 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package apptesting | ||
|
||
import ( | ||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" | ||
"github.com/cosmos/cosmos-sdk/testutil/testdata" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" | ||
"github.com/cosmos/cosmos-sdk/x/bank/testutil" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
|
||
clienttx "github.com/cosmos/cosmos-sdk/client/tx" | ||
|
||
"github.com/osmosis-labs/osmosis/osmomath" | ||
"github.com/osmosis-labs/osmosis/v20/x/txfees/keeper" | ||
"github.com/osmosis-labs/osmosis/v20/x/txfees/types" | ||
) | ||
|
||
var baseGas = uint64(10000) | ||
|
||
func (s *KeeperTestHelper) ExecuteUpgradeFeeTokenProposal(feeToken string, poolId uint64) error { | ||
upgradeProp := types.NewUpdateFeeTokenProposal( | ||
"Test Proposal", | ||
"test", | ||
[]types.FeeToken{ | ||
{ | ||
Denom: feeToken, | ||
PoolID: poolId, | ||
}, | ||
}, | ||
) | ||
return s.App.TxFeesKeeper.HandleUpdateFeeTokenProposal(s.Ctx, &upgradeProp) | ||
} | ||
|
||
func (s *KeeperTestHelper) SetupTxFeeAnteHandlerAndChargeFee(clientCtx client.Context, minGasPrices sdk.DecCoins, gasRequested uint64, isCheckTx, isSimulate bool, txFee sdk.Coins) error { | ||
mempoolFeeOpts := types.NewDefaultMempoolFeeOptions() | ||
mempoolFeeOpts.MinGasPriceForHighGasTx = osmomath.MustNewDecFromStr("0.0025") | ||
|
||
uionPoolId := s.PrepareBalancerPoolWithCoins( | ||
sdk.NewInt64Coin(sdk.DefaultBondDenom, 500), | ||
sdk.NewInt64Coin("uion", 500), | ||
) | ||
err := s.ExecuteUpgradeFeeTokenProposal("uion", uionPoolId) | ||
s.Require().NoError(err) | ||
|
||
if gasRequested == 0 { | ||
gasRequested = baseGas | ||
} | ||
s.Ctx = s.Ctx.WithIsCheckTx(isCheckTx).WithMinGasPrices(minGasPrices) | ||
|
||
// TODO: Cleanup this code. | ||
// TxBuilder components reset for every test case | ||
txBuilder := clientCtx.TxConfig.NewTxBuilder() | ||
priv0, _, addr0 := testdata.KeyTestPubAddr() | ||
acc1 := s.App.AccountKeeper.NewAccountWithAddress(s.Ctx, addr0) | ||
s.App.AccountKeeper.SetAccount(s.Ctx, acc1) | ||
msgs := []sdk.Msg{testdata.NewTestMsg(addr0)} | ||
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv0}, []uint64{0}, []uint64{0} | ||
signerData := authsigning.SignerData{ | ||
ChainID: s.Ctx.ChainID(), | ||
AccountNumber: accNums[0], | ||
Sequence: accSeqs[0], | ||
} | ||
|
||
gasLimit := gasRequested | ||
sigV2, _ := clienttx.SignWithPrivKey( | ||
1, | ||
signerData, | ||
txBuilder, | ||
privs[0], | ||
clientCtx.TxConfig, | ||
accSeqs[0], | ||
) | ||
|
||
err = testutil.FundAccount(s.App.BankKeeper, s.Ctx, addr0, txFee) | ||
s.Require().NoError(err) | ||
|
||
tx := s.BuildTx(txBuilder, msgs, sigV2, "", txFee, gasLimit) | ||
|
||
mfd := keeper.NewMempoolFeeDecorator(*s.App.TxFeesKeeper, mempoolFeeOpts) | ||
dfd := keeper.NewDeductFeeDecorator(*s.App.TxFeesKeeper, *s.App.AccountKeeper, s.App.BankKeeper, nil) | ||
antehandlerMFD := sdk.ChainAnteDecorators(mfd, dfd) | ||
_, err = antehandlerMFD(s.Ctx, tx, isSimulate) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package v21_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
|
||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
|
||
v21 "github.com/osmosis-labs/osmosis/v20/app/upgrades/v21" | ||
|
||
abci "github.com/cometbft/cometbft/abci/types" | ||
|
||
"github.com/osmosis-labs/osmosis/osmomath" | ||
"github.com/osmosis-labs/osmosis/v20/app/apptesting" | ||
"github.com/osmosis-labs/osmosis/v20/x/protorev/types" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
poolmanagertypes "github.com/osmosis-labs/osmosis/v20/x/poolmanager/types" | ||
) | ||
|
||
const ( | ||
v21UpgradeHeight = int64(10) | ||
) | ||
|
||
type UpgradeTestSuite struct { | ||
apptesting.KeeperTestHelper | ||
} | ||
|
||
func TestUpgradeTestSuite(t *testing.T) { | ||
suite.Run(t, new(UpgradeTestSuite)) | ||
} | ||
|
||
func (s *UpgradeTestSuite) TestUpgrade() { | ||
s.SetupWithCustomChainId(v21.TestingChainId) | ||
dummyUpgrade(s) | ||
s.Require().NotPanics(func() { | ||
s.App.BeginBlocker(s.Ctx, abci.RequestBeginBlock{}) | ||
}) | ||
|
||
// Psuedo collect cyclic arb profits | ||
cyclicArbProfits := sdk.NewCoins(sdk.NewCoin(types.OsmosisDenomination, osmomath.NewInt(9000)), sdk.NewCoin("Atom", osmomath.NewInt(3000))) | ||
err := s.App.AppKeepers.ProtoRevKeeper.UpdateStatistics(s.Ctx, poolmanagertypes.SwapAmountInRoutes{}, cyclicArbProfits[0].Denom, cyclicArbProfits[0].Amount) | ||
s.Require().NoError(err) | ||
err = s.App.AppKeepers.ProtoRevKeeper.UpdateStatistics(s.Ctx, poolmanagertypes.SwapAmountInRoutes{}, cyclicArbProfits[1].Denom, cyclicArbProfits[1].Amount) | ||
s.Require().NoError(err) | ||
|
||
allProtocolRevenue := s.App.ProtoRevKeeper.GetAllProtocolRevenue(s.Ctx) | ||
// Check all accounting start heights should be the same height as the upgrade | ||
s.Require().Equal(v21UpgradeHeight, allProtocolRevenue.CyclicArbTracker.HeightAccountingStartsFrom) | ||
s.Require().Equal(v21UpgradeHeight, allProtocolRevenue.TakerFeesTracker.HeightAccountingStartsFrom) | ||
s.Require().Equal(v21UpgradeHeight, allProtocolRevenue.TxFeesTracker.HeightAccountingStartsFrom) | ||
// All values should be nill except for the cyclic arb profits, which should start at the value it was at time of upgrade | ||
s.Require().Equal(sdk.Coins(nil), allProtocolRevenue.TakerFeesTracker.TakerFeesToCommunityPool) | ||
s.Require().Equal(sdk.Coins(nil), allProtocolRevenue.TakerFeesTracker.TakerFeesToStakers) | ||
s.Require().Equal(sdk.Coins(nil), allProtocolRevenue.TxFeesTracker.TxFees) | ||
s.Require().Equal(cyclicArbProfits, allProtocolRevenue.CyclicArbTracker.CyclicArb) | ||
|
||
} | ||
|
||
func dummyUpgrade(s *UpgradeTestSuite) { | ||
s.Ctx = s.Ctx.WithBlockHeight(v21UpgradeHeight - 1) | ||
plan := upgradetypes.Plan{Name: "v21", Height: v21UpgradeHeight} | ||
err := s.App.UpgradeKeeper.ScheduleUpgrade(s.Ctx, plan) | ||
s.Require().NoError(err) | ||
_, exists := s.App.UpgradeKeeper.GetUpgradePlan(s.Ctx) | ||
s.Require().True(exists) | ||
|
||
s.Ctx = s.Ctx.WithBlockHeight(v21UpgradeHeight) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.