-
Notifications
You must be signed in to change notification settings - Fork 608
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
Twap: Add twapkeeper wiring #2193
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,3 +96,21 @@ func (s *KeeperTestHelper) PrepareBalancerPoolWithPoolAsset(assets []balancer.Po | |
s.NoError(err) | ||
return poolId | ||
} | ||
|
||
func (s *KeeperTestHelper) RunBasicSwap(poolId uint64) { | ||
denoms, err := s.App.GAMMKeeper.GetPoolDenoms(s.Ctx, poolId) | ||
s.Require().NoError(err) | ||
|
||
swapIn := sdk.NewCoins(sdk.NewCoin(denoms[0], sdk.NewInt(1000))) | ||
s.FundAcc(s.TestAccs[0], swapIn) | ||
|
||
msg := gammtypes.MsgSwapExactAmountIn{ | ||
Sender: string(s.TestAccs[0]), | ||
Routes: []gammtypes.SwapAmountInRoute{{PoolId: poolId, TokenOutDenom: denoms[1]}}, | ||
TokenIn: swapIn[0], | ||
TokenOutMinAmount: sdk.ZeroInt(), | ||
} | ||
// TODO: switch to message | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's create an issue for this please |
||
_, err = s.App.GAMMKeeper.SwapExactAmountIn(s.Ctx, s.TestAccs[0], poolId, msg.TokenIn, denoms[1], msg.TokenOutMinAmount) | ||
s.Require().NoError(err) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,8 @@ import ( | |
epochskeeper "github.com/osmosis-labs/osmosis/v10/x/epochs/keeper" | ||
epochstypes "github.com/osmosis-labs/osmosis/v10/x/epochs/types" | ||
gammkeeper "github.com/osmosis-labs/osmosis/v10/x/gamm/keeper" | ||
"github.com/osmosis-labs/osmosis/v10/x/gamm/twap" | ||
twaptypes "github.com/osmosis-labs/osmosis/v10/x/gamm/twap/types" | ||
gammtypes "github.com/osmosis-labs/osmosis/v10/x/gamm/types" | ||
incentiveskeeper "github.com/osmosis-labs/osmosis/v10/x/incentives/keeper" | ||
incentivestypes "github.com/osmosis-labs/osmosis/v10/x/incentives/types" | ||
|
@@ -98,6 +100,7 @@ type AppKeepers struct { | |
TransferKeeper *ibctransferkeeper.Keeper | ||
EvidenceKeeper *evidencekeeper.Keeper | ||
GAMMKeeper *gammkeeper.Keeper | ||
TwapKeeper *twap.Keeper | ||
LockupKeeper *lockupkeeper.Keeper | ||
EpochsKeeper *epochskeeper.Keeper | ||
IncentivesKeeper *incentiveskeeper.Keeper | ||
|
@@ -241,6 +244,12 @@ func (appKeepers *AppKeepers) InitNormalKeepers( | |
appKeepers.AccountKeeper, appKeepers.BankKeeper, appKeepers.DistrKeeper) | ||
appKeepers.GAMMKeeper = &gammKeeper | ||
|
||
appKeepers.TwapKeeper = twap.NewKeeper( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Asking to learn - since TWAP has its own keeper why would we not have a separate module for it? Isn't this inconsistent with the cosmos-sdk conventions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah we can move it to its own module, the way its written this is really just a folder move |
||
appKeepers.keys[twaptypes.StoreKey], | ||
appKeepers.tkeys[twaptypes.TransientStoreKey], | ||
appKeepers.GetSubspace(twaptypes.ModuleName), | ||
appKeepers.GAMMKeeper) | ||
|
||
appKeepers.LockupKeeper = lockupkeeper.NewKeeper( | ||
appCodec, | ||
appKeepers.keys[lockuptypes.StoreKey], | ||
|
@@ -454,6 +463,7 @@ func (appKeepers *AppKeepers) SetupHooks() { | |
gammtypes.NewMultiGammHooks( | ||
// insert gamm hooks receivers here | ||
appKeepers.PoolIncentivesKeeper.Hooks(), | ||
appKeepers.TwapKeeper.GammHooks(), | ||
), | ||
) | ||
|
||
|
@@ -512,6 +522,7 @@ func KVStoreKeys() []string { | |
ibctransfertypes.StoreKey, | ||
capabilitytypes.StoreKey, | ||
gammtypes.StoreKey, | ||
twaptypes.StoreKey, | ||
lockuptypes.StoreKey, | ||
incentivestypes.StoreKey, | ||
epochstypes.StoreKey, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,8 @@ import ( | |
"github.com/osmosis-labs/osmosis/v10/x/epochs" | ||
epochstypes "github.com/osmosis-labs/osmosis/v10/x/epochs/types" | ||
"github.com/osmosis-labs/osmosis/v10/x/gamm" | ||
"github.com/osmosis-labs/osmosis/v10/x/gamm/twap" | ||
twaptypes "github.com/osmosis-labs/osmosis/v10/x/gamm/twap/types" | ||
gammtypes "github.com/osmosis-labs/osmosis/v10/x/gamm/types" | ||
"github.com/osmosis-labs/osmosis/v10/x/incentives" | ||
incentivestypes "github.com/osmosis-labs/osmosis/v10/x/incentives/types" | ||
|
@@ -121,6 +123,7 @@ func appModules( | |
params.NewAppModule(*app.ParamsKeeper), | ||
app.TransferModule, | ||
gamm.NewAppModule(appCodec, *app.GAMMKeeper, app.AccountKeeper, app.BankKeeper), | ||
twap.NewAppModule(*app.TwapKeeper), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something cool is that with the structure of keeper and module.go being defined in the same file, no other keepers need to be passed in. Also AppCodec isn't needed in modules that don't serialize interfaces |
||
txfees.NewAppModule(appCodec, *app.TxFeesKeeper), | ||
incentives.NewAppModule(appCodec, *app.IncentivesKeeper, app.AccountKeeper, app.BankKeeper, app.EpochsKeeper), | ||
lockup.NewAppModule(appCodec, *app.LockupKeeper, app.AccountKeeper, app.BankKeeper), | ||
|
@@ -165,7 +168,7 @@ func orderBeginBlockers(allModuleNames []string) []string { | |
// OrderEndBlockers returns EndBlockers (crisis, govtypes, staking) with no relative order. | ||
func OrderEndBlockers(allModuleNames []string) []string { | ||
ord := partialord.NewPartialOrdering(allModuleNames) | ||
// only Osmosis modules with endblock code are: crisis, govtypes, staking | ||
// only Osmosis modules with endblock code are: twap, crisis, govtypes, staking | ||
// we don't care about the relative ordering between them. | ||
return ord.TotalOrdering() | ||
} | ||
|
@@ -190,6 +193,7 @@ func OrderInitGenesis(allModuleNames []string) []string { | |
ibchost.ModuleName, | ||
icatypes.ModuleName, | ||
gammtypes.ModuleName, | ||
twaptypes.ModuleName, | ||
txfeestypes.ModuleName, | ||
genutiltypes.ModuleName, | ||
evidencetypes.ModuleName, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
|
||
"github.com/osmosis-labs/osmosis/v10/osmoutils" | ||
"github.com/osmosis-labs/osmosis/v10/x/gamm/pool-models/balancer" | ||
"github.com/osmosis-labs/osmosis/v10/x/gamm/pool-models/stableswap" | ||
"github.com/osmosis-labs/osmosis/v10/x/gamm/types" | ||
|
@@ -197,6 +198,12 @@ func (k Keeper) DeletePool(ctx sdk.Context, poolId uint64) error { | |
// return nil | ||
// } | ||
|
||
func (k Keeper) GetPoolDenoms(ctx sdk.Context, poolId uint64) ([]string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. godoc please There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, let's make a test for this please with a success and an error case |
||
pool, err := k.GetPoolAndPoke(ctx, poolId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. err check |
||
denoms := osmoutils.CoinsDenoms(pool.GetTotalPoolLiquidity(ctx)) | ||
return denoms, err | ||
} | ||
|
||
// setNextPoolNumber sets next pool number. | ||
func (k Keeper) setNextPoolNumber(ctx sdk.Context, poolNumber uint64) { | ||
store := ctx.KVStore(k.storeKey) | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,27 @@ | ||
package twap | ||
|
||
import sdk "github.com/cosmos/cosmos-sdk/types" | ||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
type twapkeeper struct { | ||
// storeKey sdk.StoreKey | ||
transientKey sdk.TransientStoreKey | ||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
|
||
"github.com/osmosis-labs/osmosis/v10/x/gamm/twap/types" | ||
) | ||
|
||
type Keeper struct { | ||
storeKey sdk.StoreKey | ||
transientKey *sdk.TransientStoreKey | ||
|
||
paramSpace paramtypes.Subspace | ||
|
||
ammkeeper types.AmmInterface | ||
} | ||
|
||
func NewKeeper(storeKey sdk.StoreKey, transientKey *sdk.TransientStoreKey, paramSpace paramtypes.Subspace, ammKeeper types.AmmInterface) *Keeper { | ||
return &Keeper{storeKey: storeKey, transientKey: transientKey, paramSpace: paramSpace, ammkeeper: ammKeeper} | ||
} | ||
|
||
// TODO: make this read from a parameter, or hardcode it. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make an issue please |
||
func (k *Keeper) PruneEpochIdentifier(ctx sdk.Context) string { | ||
return "daily" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it be "day" and not "daily" according to the epochs parameter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh woops, yeah it should |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it would be useful to have these as parameters so that the caller can customize them?
I find that frequently in GAMM tests, we have to hard code some parameters because such test helpers are not customizable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could let it take
MsgSwapExactAmountIn
for full control over how the caller wants the swap to behave?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point of this one was to not have to think about anything, I think a second helper that does that would be helpful