-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(CL): swaprouter types and barebones keeper (merge to
main
#2)
- Loading branch information
Showing
27 changed files
with
1,222 additions
and
19 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
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
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,9 @@ | ||
package swaprouter | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func (k Keeper) GetNextPoolIdAndIncrement(ctx sdk.Context) uint64 { | ||
return k.getNextPoolIdAndIncrement(ctx) | ||
} |
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,110 @@ | ||
package swaprouter | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
gogotypes "github.com/gogo/protobuf/types" | ||
|
||
"github.com/osmosis-labs/osmosis/v13/osmoutils" | ||
"github.com/osmosis-labs/osmosis/v13/x/swaprouter/types" | ||
|
||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
) | ||
|
||
type Keeper struct { | ||
storeKey sdk.StoreKey | ||
|
||
gammKeeper types.SwapI | ||
concentratedKeeper types.SwapI | ||
poolIncentivesKeeper types.PoolIncentivesKeeperI | ||
bankKeeper types.BankI | ||
accountKeeper types.AccountI | ||
communityPoolKeeper types.CommunityPoolI | ||
|
||
poolCreationListeners types.PoolCreationListeners | ||
|
||
routes map[types.PoolType]types.SwapI | ||
|
||
paramSpace paramtypes.Subspace | ||
} | ||
|
||
func NewKeeper(storeKey sdk.StoreKey, paramSpace paramtypes.Subspace, gammKeeper types.SwapI, concentratedKeeper types.SwapI, bankKeeper types.BankI, accountKeeper types.AccountI, communityPoolKeeper types.CommunityPoolI) *Keeper { | ||
// set KeyTable if it has not already been set | ||
if !paramSpace.HasKeyTable() { | ||
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) | ||
} | ||
|
||
routes := map[types.PoolType]types.SwapI{ | ||
types.Balancer: gammKeeper, | ||
types.StableSwap: gammKeeper, | ||
types.Concentrated: concentratedKeeper, | ||
} | ||
|
||
return &Keeper{storeKey: storeKey, paramSpace: paramSpace, gammKeeper: gammKeeper, concentratedKeeper: concentratedKeeper, bankKeeper: bankKeeper, accountKeeper: accountKeeper, communityPoolKeeper: communityPoolKeeper, routes: routes} | ||
} | ||
|
||
// GetParams returns the total set of swaprouter parameters. | ||
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { | ||
k.paramSpace.GetParamSet(ctx, ¶ms) | ||
return params | ||
} | ||
|
||
// SetParams sets the total set of swaprouter parameters. | ||
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { | ||
k.paramSpace.SetParamSet(ctx, ¶ms) | ||
} | ||
|
||
// InitGenesis initializes the swaprouter module's state from a provided genesis | ||
// state. | ||
func (k Keeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) { | ||
k.SetNextPoolId(ctx, genState.NextPoolId) | ||
if err := genState.Validate(); err != nil { | ||
panic(err) | ||
} | ||
|
||
k.SetParams(ctx, genState.Params) | ||
} | ||
|
||
// ExportGenesis returns the swaprouter module's exported genesis. | ||
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { | ||
return &types.GenesisState{ | ||
Params: k.GetParams(ctx), | ||
NextPoolId: k.GetNextPoolId(ctx), | ||
} | ||
} | ||
|
||
// GetNextPoolId returns the next pool id. | ||
func (k Keeper) GetNextPoolId(ctx sdk.Context) uint64 { | ||
store := ctx.KVStore(k.storeKey) | ||
nextPoolId := gogotypes.UInt64Value{} | ||
osmoutils.MustGet(store, types.KeyNextGlobalPoolId, &nextPoolId) | ||
return nextPoolId.Value | ||
} | ||
|
||
// SetPoolCreationListeners sets the pool creation listeners. | ||
func (k *Keeper) SetPoolCreationListeners(listeners types.PoolCreationListeners) *Keeper { | ||
if k.poolCreationListeners != nil { | ||
panic("cannot set pool creation listeners twice") | ||
} | ||
|
||
k.poolCreationListeners = listeners | ||
|
||
return k | ||
} | ||
|
||
// SetNextPoolId sets next pool Id. | ||
func (k Keeper) SetNextPoolId(ctx sdk.Context, poolId uint64) { | ||
store := ctx.KVStore(k.storeKey) | ||
osmoutils.MustSet(store, types.KeyNextGlobalPoolId, &gogotypes.UInt64Value{Value: poolId}) | ||
} | ||
|
||
// SetPoolIncentivesKeeper sets pool incentives keeper | ||
func (k *Keeper) SetPoolIncentivesKeeper(poolIncentivesKeeper types.PoolIncentivesKeeperI) { | ||
k.poolIncentivesKeeper = poolIncentivesKeeper | ||
} | ||
|
||
// getNextPoolIdAndIncrement returns the next pool Id, and increments the corresponding state entry. | ||
func (k Keeper) getNextPoolIdAndIncrement(ctx sdk.Context) uint64 { | ||
nextPoolId := k.GetNextPoolId(ctx) | ||
k.SetNextPoolId(ctx, nextPoolId+1) | ||
return nextPoolId | ||
} |
Oops, something went wrong.