Skip to content

Commit

Permalink
fix ibc modules export for unset params issue & genesis for accumulat…
Browse files Browse the repository at this point in the history
…ors in liquiditypool module, build issue in testutil
  • Loading branch information
jununifi committed Jul 5, 2024
1 parent 9038cb1 commit 894b23a
Show file tree
Hide file tree
Showing 19 changed files with 1,058 additions and 347 deletions.
297 changes: 222 additions & 75 deletions api/sunrise/liquiditypool/accumulator.pulsar.go

Large diffs are not rendered by default.

528 changes: 419 additions & 109 deletions api/sunrise/liquiditypool/genesis.pulsar.go

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions app/abci_check_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (app *App) CheckTx(req *abci.RequestCheckTx) (*abci.ResponseCheckTx, error)
return sdkerrors.ResponseCheckTxWithEvents(blobtypes.ErrNoBlobs, 0, 0, []abci.Event{}, false), blobtypes.ErrNoBlobs
}
// don't do anything special if we have a normal transaction
return app.checkTxHandler(req)
return app.CheckTxHandler(req)
}

switch req.Type {
Expand All @@ -48,10 +48,10 @@ func (app *App) CheckTx(req *abci.RequestCheckTx) (*abci.ResponseCheckTx, error)
}

req.Tx = btx.Tx
return app.checkTxHandler(req)
return app.CheckTxHandler(req)
}

// SetCheckTx sets the checkTxHandler for the app.
// SetCheckTx sets the CheckTxHandler for the app.
func (app *App) SetCheckTx(handler checktx.CheckTx) {
app.checkTxHandler = handler
app.CheckTxHandler = handler
}
2 changes: 1 addition & 1 deletion app/abci_prepare_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (app *App) PrepareProposal(req *abci.RequestPrepareProposal) (*abci.Respons
ante.DefaultSigVerificationGasConsumer,
app.IBCKeeper,
app.AuctionKeeper,
app.mevLane,
app.MevLane,
app.txConfig.TxEncoder(),
)

Expand Down
2 changes: 1 addition & 1 deletion app/abci_process_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (app *App) ProcessProposal(req *abci.RequestProcessProposal) (retResp *abci
ante.DefaultSigVerificationGasConsumer,
app.IBCKeeper,
app.AuctionKeeper,
app.mevLane,
app.MevLane,
app.txConfig.TxEncoder(),
)
sdkCtx := app.NewProposalContext(cmtproto.Header{
Expand Down
6 changes: 3 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ type App struct {
sm *module.SimulationManager

// custom structure for skip-mev protection
mevLane *mevlane.MEVLane
checkTxHandler checktx.CheckTx
MevLane *mevlane.MEVLane
CheckTxHandler checktx.CheckTx
}

func init() {
Expand Down Expand Up @@ -423,7 +423,7 @@ func New(
opt...,
)

app.mevLane = mevLane
app.MevLane = mevLane

// Step 6: Create the proposal handler and set it on the app. Now the application
// will build and verify proposals using the Block SDK!
Expand Down
5 changes: 3 additions & 2 deletions cmd/sunrised/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ func NewRootCmd() *cobra.Command {
// manually register the modules on the client side.
// This needs to be removed after IBC supports App Wiring.
ibcModules := app.RegisterIBC(clientCtx.InterfaceRegistry)
for name, module := range ibcModules {
autoCliOpts.Modules[name] = module
for name, mod := range ibcModules {
moduleBasicManager[name] = module.CoreAppModuleBasicAdaptor(name, mod)
autoCliOpts.Modules[name] = mod
}
initRootCmd(rootCmd, clientCtx.TxConfig, moduleBasicManager)

Expand Down
8 changes: 5 additions & 3 deletions proto/sunrise/liquiditypool/accumulator.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ message AccumulatorObject {
}

message AccumulatorPosition {
string num_shares = 1 [
string name = 1;
string index = 2;
string num_shares = 3 [
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
repeated cosmos.base.v1beta1.DecCoin accum_value_per_share = 2 [
repeated cosmos.base.v1beta1.DecCoin accum_value_per_share = 4 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins",
(gogoproto.nullable) = false
];
repeated cosmos.base.v1beta1.DecCoin unclaimed_rewards_total = 3 [
repeated cosmos.base.v1beta1.DecCoin unclaimed_rewards_total = 5 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins",
(gogoproto.nullable) = false
];
Expand Down
17 changes: 10 additions & 7 deletions proto/sunrise/liquiditypool/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ import "gogoproto/gogo.proto";
import "sunrise/liquiditypool/params.proto";
import "sunrise/liquiditypool/pool.proto";
import "sunrise/liquiditypool/position.proto";
import "sunrise/liquiditypool/accumulator.proto";

option go_package = "github.com/sunriselayer/sunrise/x/liquiditypool/types";

// GenesisState defines the liquiditypool module's genesis state.
message GenesisState {

// params defines all the parameters of the module.
Params params = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
repeated Pool poolList = 2 [(gogoproto.nullable) = false] ;
uint64 poolCount = 3;
repeated Position positionList = 4 [(gogoproto.nullable) = false] ;
uint64 positionCount = 5;
Params params = 1
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
repeated Pool pools = 2 [ (gogoproto.nullable) = false ];
uint64 poolCount = 3;
repeated Position positions = 4 [ (gogoproto.nullable) = false ];
uint64 positionCount = 5;
repeated AccumulatorObject accumulators = 6 [ (gogoproto.nullable) = false ];
repeated AccumulatorPosition accumulatorPositions = 7
[ (gogoproto.nullable) = false ];
}

3 changes: 3 additions & 0 deletions test/util/malicious/out_of_order_prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func (a *App) OutOfOrderPrepareProposal(req abci.RequestPrepareProposal) (*abci.
a.GetTxConfig().SignModeHandler(),
ante.DefaultSigVerificationGasConsumer,
a.IBCKeeper,
a.AuctionKeeper,
a.MevLane,
a.GetTxConfig().TxEncoder(),
)

txs := app.FilterTxs(a.Logger(), sdkCtx, handler, a.GetTxConfig(), req.Txs)
Expand Down
37 changes: 37 additions & 0 deletions x/liquiditypool/keeper/accumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import (
"errors"
"fmt"

"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/gogoproto/proto"
"github.com/sunriselayer/sunrise/x/liquiditypool/types"

"cosmossdk.io/math"
"cosmossdk.io/store/prefix"
storetypes "cosmossdk.io/store/types"
)

func (k Keeper) InitAccumulator(ctx context.Context, accumName string) error {
Expand Down Expand Up @@ -48,6 +51,22 @@ func (k Keeper) GetAccumulator(ctx context.Context, accumName string) (types.Acc
return accumulator, nil
}

func (k Keeper) GetAllAccumulators(ctx context.Context) (list []types.AccumulatorObject) {
storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.KeyAccumPrefix))
iterator := storetypes.KVStorePrefixIterator(store, []byte{})

defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {
var val types.AccumulatorObject
k.cdc.MustUnmarshal(iterator.Value(), &val)
list = append(list, val)
}

return
}

func (k Keeper) SetAccumulator(ctx context.Context, accumulator types.AccumulatorObject) error {
bz, err := proto.Marshal(&accumulator)
if err != nil {
Expand Down Expand Up @@ -84,8 +103,26 @@ func (k Keeper) GetAccumulatorPosition(ctx context.Context, accumName, name stri
return position, nil
}

func (k Keeper) GetAllAccumulatorPositions(ctx context.Context) (list []types.AccumulatorPosition) {
storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
store := prefix.NewStore(storeAdapter, types.KeyPrefix(types.KeyAccumulatorPositionPrefix))
iterator := storetypes.KVStorePrefixIterator(store, []byte{})

defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {
var val types.AccumulatorPosition
k.cdc.MustUnmarshal(iterator.Value(), &val)
list = append(list, val)
}

return
}

func (k Keeper) SetAccumulatorPosition(ctx context.Context, accumName string, accumulatorValuePerShare sdk.DecCoins, index string, numShareUnits math.LegacyDec, unclaimedRewardsTotal sdk.DecCoins) {
position := types.AccumulatorPosition{
Name: accumName,
Index: index,
NumShares: numShareUnits,
AccumValuePerShare: accumulatorValuePerShare,
UnclaimedRewardsTotal: unclaimedRewardsTotal,
Expand Down
28 changes: 20 additions & 8 deletions x/liquiditypool/module/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,29 @@ import (
// InitGenesis initializes the module's state from a provided genesis state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) {
// Set all the pool
for _, elem := range genState.PoolList {
k.SetPoolCount(ctx, genState.PoolCount)
for _, elem := range genState.Pools {
k.SetPool(ctx, elem)
}

// Set pool count
k.SetPoolCount(ctx, genState.PoolCount)
// Set all the position
for _, elem := range genState.PositionList {
k.SetPositionCount(ctx, genState.PositionCount)
for _, elem := range genState.Positions {
k.SetPosition(ctx, elem)
}

// Set position count
k.SetPositionCount(ctx, genState.PositionCount)
// Set all accumulators
for _, elem := range genState.Accumulators {
err := k.SetAccumulator(ctx, elem)
if err != nil {
panic(err)
}
}
// Set all accumulator positions
for _, elem := range genState.AccumulatorPositions {
k.SetAccumulatorPosition(ctx, elem.Name, elem.AccumValuePerShare, elem.Index, elem.NumShares, elem.UnclaimedRewardsTotal)
}

// this line is used by starport scaffolding # genesis/module/init
if err := k.SetParams(ctx, genState.Params); err != nil {
panic(err)
Expand All @@ -34,10 +44,12 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
genesis := types.DefaultGenesis()
genesis.Params = k.GetParams(ctx)

genesis.PoolList = k.GetAllPools(ctx)
genesis.Pools = k.GetAllPools(ctx)
genesis.PoolCount = k.GetPoolCount(ctx)
genesis.PositionList = k.GetAllPositions(ctx)
genesis.Positions = k.GetAllPositions(ctx)
genesis.PositionCount = k.GetPositionCount(ctx)
genesis.Accumulators = k.GetAllAccumulators(ctx)
genesis.AccumulatorPositions = k.GetAllAccumulatorPositions(ctx)
// this line is used by starport scaffolding # genesis/module/export

return genesis
Expand Down
9 changes: 4 additions & 5 deletions x/liquiditypool/module/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import (
func TestGenesis(t *testing.T) {
genesisState := types.GenesisState{
Params: types.DefaultParams(),

PoolList: []types.Pool{
Pools: []types.Pool{
{
Id: 0,
},
Expand All @@ -23,7 +22,7 @@ func TestGenesis(t *testing.T) {
},
},
PoolCount: 2,
PositionList: []types.Position{
Positions: []types.Position{
{
Id: 0,
},
Expand All @@ -43,9 +42,9 @@ func TestGenesis(t *testing.T) {
nullify.Fill(&genesisState)
nullify.Fill(got)

require.ElementsMatch(t, genesisState.PoolList, got.PoolList)
require.ElementsMatch(t, genesisState.Pools, got.Pools)
require.Equal(t, genesisState.PoolCount, got.PoolCount)
require.ElementsMatch(t, genesisState.PositionList, got.PositionList)
require.ElementsMatch(t, genesisState.Positions, got.Positions)
require.Equal(t, genesisState.PositionCount, got.PositionCount)
// this line is used by starport scaffolding # genesis/test/assert
}
4 changes: 2 additions & 2 deletions x/liquiditypool/module/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
}
liquiditypoolGenesis := types.GenesisState{
Params: types.DefaultParams(),
PoolList: []types.Pool{
Pools: []types.Pool{
{
Id: 0,
},
Expand All @@ -71,7 +71,7 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
},
},
PoolCount: 2,
PositionList: []types.Position{
Positions: []types.Position{
{
Id: 0,
Address: sample.AccAddress(),
Expand Down
Loading

0 comments on commit 894b23a

Please sign in to comment.