Skip to content

Commit

Permalink
Merge pjdp1
Browse files Browse the repository at this point in the history
  • Loading branch information
tkxkd0159 committed Apr 26, 2024
2 parents 9b34eed + 52a3f83 commit 5d8eb42
Show file tree
Hide file tree
Showing 38 changed files with 863 additions and 269 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Features
* (consensus) [\#1178](https://github.com/Finschia/finschia-sdk/pull/1178) change the consensus from Ostracon to Tendermint v0.34.24
* (x/fswap) [\#1336](https://github.com/Finschia/finschia-sdk/pull/1336) Initialize fswap module
* (x/fswap) [\#1339](https://github.com/Finschia/finschia-sdk/pull/1339) Implement fswap module's genesis
* (x/fbridge) [\#1336](https://github.com/Finschia/finschia-sdk/pull/1340) Initialize fbridge module

### Improvements
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ mocks: $(MOCKS_DIR)
mockgen -package mocks -destination tests/mocks/grpc_server.go github.com/gogo/protobuf/grpc Server
mockgen -package mocks -destination tests/mocks/tendermint_tendermint_libs_log_DB.go github.com/tendermint/tendermint/libs/log Logger
mockgen -source=x/stakingplus/expected_keepers.go -package testutil -destination x/stakingplus/testutil/expected_keepers_mocks.go
mockgen -source=x/fswap/types/expected_keepers.go -package testutil -destination x/fswap/testutil/expected_keepers_mocks.go
.PHONY: mocks

$(MOCKS_DIR):
Expand Down
15 changes: 8 additions & 7 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -13778,8 +13778,8 @@ Msg defines the foundation Msg service.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `address` | [string](#string) | | holder's address |
| `old_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | amount of the old currency |
| `new_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | amount of the new currency |
| `old_coin` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | amount of the old currency |
| `new_coin` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | amount of the new currency |



Expand Down Expand Up @@ -13810,8 +13810,8 @@ Msg defines the foundation Msg service.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `old_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |
| `new_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |
| `old_coin_amount` | [string](#string) | | |
| `new_coin_amount` | [string](#string) | | |



Expand Down Expand Up @@ -13842,7 +13842,7 @@ Params defines the parameters for the module.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `new_coin_denom` | [string](#string) | | new denomination for new coin after swap |
| `swappable_new_coin_amount` | [string](#string) | | |



Expand Down Expand Up @@ -13915,7 +13915,8 @@ GenesisState defines the fswap module's genesis state.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `swapped` | [Swapped](#lbm.fswap.v1.Swapped) | | |
| `old_coin` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |
| `new_coin` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |



Expand All @@ -13940,7 +13941,7 @@ GenesisState defines the fswap module's genesis state.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `swappable_new_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |
| `swappable_new_coin` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |



Expand Down
4 changes: 2 additions & 2 deletions proto/lbm/fswap/v1/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ message EventSwapCoins {
// holder's address
string address = 1;
// amount of the old currency
cosmos.base.v1beta1.Coin old_coin_amount = 2
cosmos.base.v1beta1.Coin old_coin = 2
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
// amount of the new currency
cosmos.base.v1beta1.Coin new_coin_amount = 3
cosmos.base.v1beta1.Coin new_coin = 3
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
}
10 changes: 4 additions & 6 deletions proto/lbm/fswap/v1/fswap.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ package lbm.fswap.v1;
option go_package = "github.com/Finschia/finschia-sdk/x/fswap/types";

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

message Swapped{
cosmos.base.v1beta1.Coin old_coin_amount = 1
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
cosmos.base.v1beta1.Coin new_coin_amount = 2
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
message Swapped {
option (gogoproto.goproto_stringer) = false;
string old_coin_amount = 1 [(gogoproto.customtype) = "github.com/Finschia/finschia-sdk/types.Int", (gogoproto.nullable) = false];
string new_coin_amount = 2 [(gogoproto.customtype) = "github.com/Finschia/finschia-sdk/types.Int", (gogoproto.nullable) = false];
}
6 changes: 3 additions & 3 deletions proto/lbm/fswap/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ package lbm.fswap.v1;
option go_package = "github.com/Finschia/finschia-sdk/x/fswap/types";

import "gogoproto/gogo.proto";
import "lbm/fswap/v1/params.proto";
import "lbm/fswap/v1/fswap.proto";
import "lbm/fswap/v1/params.proto";

// GenesisState defines the fswap module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
Swapped swapped =2 [(gogoproto.nullable) = false];
Params params = 1 [(gogoproto.nullable) = false];
Swapped swapped = 2 [(gogoproto.nullable) = false];
}
5 changes: 2 additions & 3 deletions proto/lbm/fswap/v1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ import "gogoproto/gogo.proto";
// Params defines the parameters for the module.
message Params {
option (gogoproto.goproto_stringer) = false;
// new denomination for new coin after swap
string new_coin_denom = 1;
}
string swappable_new_coin_amount = 1 [(gogoproto.customtype) = "github.com/Finschia/finschia-sdk/types.Int", (gogoproto.nullable) = false];
}
7 changes: 5 additions & 2 deletions proto/lbm/fswap/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ service Query {

message QuerySwappedRequest {}
message QuerySwappedResponse {
Swapped swapped = 1 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin old_coin = 1
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
cosmos.base.v1beta1.Coin new_coin = 2
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
}

message QueryTotalSwappableAmountRequest {}
message QueryTotalSwappableAmountResponse {
cosmos.base.v1beta1.Coin swappable_new_coin_amount = 1
cosmos.base.v1beta1.Coin swappable_new_coin = 1
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
}
14 changes: 14 additions & 0 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ import (
foundationclient "github.com/Finschia/finschia-sdk/x/foundation/client"
foundationkeeper "github.com/Finschia/finschia-sdk/x/foundation/keeper"
foundationmodule "github.com/Finschia/finschia-sdk/x/foundation/module"
"github.com/Finschia/finschia-sdk/x/fswap"
fswapkeeper "github.com/Finschia/finschia-sdk/x/fswap/keeper"
fswaptypes "github.com/Finschia/finschia-sdk/x/fswap/types"
"github.com/Finschia/finschia-sdk/x/genutil"
genutiltypes "github.com/Finschia/finschia-sdk/x/genutil/types"
"github.com/Finschia/finschia-sdk/x/gov"
Expand Down Expand Up @@ -138,6 +141,7 @@ var (
vesting.AppModuleBasic{},
tokenmodule.AppModuleBasic{},
collectionmodule.AppModuleBasic{},
fswap.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -197,6 +201,7 @@ type SimApp struct {
ClassKeeper classkeeper.Keeper
TokenKeeper tokenkeeper.Keeper
CollectionKeeper collectionkeeper.Keeper
FswapKeeper fswapkeeper.Keeper

// the module manager
mm *module.Manager
Expand Down Expand Up @@ -250,6 +255,7 @@ func NewSimApp(
token.StoreKey,
collection.StoreKey,
authzkeeper.StoreKey,
fswaptypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
// NOTE: The testingkey is just mounted for testing purposes. Actual applications should
Expand Down Expand Up @@ -352,6 +358,10 @@ func NewSimApp(
// If evidence needs to be handled for the app, set routes in router here and seal
app.EvidenceKeeper = *evidenceKeeper

/**** Phase 1 ****/
fswapConfig := fswaptypes.DefaultConfig()
app.FswapKeeper = fswapkeeper.NewKeeper(appCodec, keys[fswaptypes.StoreKey], app.AccountKeeper, app.BankKeeper, fswapConfig)

/**** Module Options ****/

// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
Expand Down Expand Up @@ -383,6 +393,7 @@ func NewSimApp(
tokenmodule.NewAppModule(appCodec, app.TokenKeeper),
collectionmodule.NewAppModule(appCodec, app.CollectionKeeper),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
fswap.NewAppModule(appCodec, app.FswapKeeper, app.AccountKeeper, app.BankKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand Down Expand Up @@ -410,6 +421,7 @@ func NewSimApp(
vestingtypes.ModuleName,
token.ModuleName,
collection.ModuleName,
fswaptypes.ModuleName,
)
app.mm.SetOrderEndBlockers(
crisistypes.ModuleName,
Expand All @@ -431,6 +443,7 @@ func NewSimApp(
foundation.ModuleName,
token.ModuleName,
collection.ModuleName,
fswaptypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -458,6 +471,7 @@ func NewSimApp(
vestingtypes.ModuleName,
token.ModuleName,
collection.ModuleName,
fswaptypes.ModuleName,
)

// Uncomment if you want to set a custom migration order here.
Expand Down
4 changes: 3 additions & 1 deletion x/ERRORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@

|Error Name|Codespace|Code|Description|
|:-|:-|:-|:-|
|ErrSample|fswap|1100|sample error|
|ErrParamsNotFound|fswap|1100|params does not exist|
|ErrSwappedNotFound|fswap|1101|swapped does not exist|
|ErrExceedSwappable|fswap|1102|exceed swappable coin amount|

>You can also find detailed information in the following Errors.go files:
* [fswap/types/errors.go](fswap/types/errors.go)
Expand Down
24 changes: 0 additions & 24 deletions x/fswap/genesis.go

This file was deleted.

1 change: 0 additions & 1 deletion x/fswap/genesis_test.go

This file was deleted.

30 changes: 30 additions & 0 deletions x/fswap/keeper/fswap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package keeper

import (
sdk "github.com/Finschia/finschia-sdk/types"
"github.com/Finschia/finschia-sdk/x/fswap/types"
)

// GetSwapped get all parameters as types.Swapped
func (k Keeper) GetSwapped(ctx sdk.Context) types.Swapped {
store := ctx.KVStore(k.storeKey)
bz := store.Get([]byte{types.SwappedKey})
var swapped types.Swapped

if bz == nil {
panic(types.ErrSwappedNotFound)
}
k.cdc.MustUnmarshal(bz, &swapped)
return swapped
}

// SetSwapped set the types.Swapped
func (k Keeper) SetSwapped(ctx sdk.Context, swapped types.Swapped) error {
store := ctx.KVStore(k.storeKey)
bz, err := k.cdc.Marshal(&swapped)
if err != nil {
return err
}
store.Set([]byte{types.SwappedKey}, bz)
return nil
}
25 changes: 25 additions & 0 deletions x/fswap/keeper/genesis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package keeper

import (
sdk "github.com/Finschia/finschia-sdk/types"
"github.com/Finschia/finschia-sdk/x/fswap/types"
)

// InitGenesis initializes the module's state from a provided genesis
// state.
func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {
if err := k.SetParams(ctx, genState.Params); err != nil {
panic(err)
}
if err := k.SetSwapped(ctx, genState.Swapped); err != nil {
panic(err)
}
}

// ExportGenesis returns the capability module's exported genesis.
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
return &types.GenesisState{
Params: k.GetParams(ctx),
Swapped: k.GetSwapped(ctx),
}
}
13 changes: 13 additions & 0 deletions x/fswap/keeper/genesis_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package keeper_test

import (
"github.com/Finschia/finschia-sdk/x/fswap/types"
)

func (s *KeeperTestSuite) TestInitAndExportGenesis() {
s.keeper.InitGenesis(s.sdkCtx, *types.DefaultGenesis())
got := s.keeper.ExportGenesis(s.sdkCtx)
s.Require().NotNil(got)
s.Require().Equal(types.DefaultParams(), got.Params)
s.Require().Equal(types.DefaultSwapped(), got.Swapped)
}
9 changes: 6 additions & 3 deletions x/fswap/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,26 @@ import (
type (
Keeper struct {
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
storeKey storetypes.StoreKey
config types.Config
}
)

func NewKeeper(
cdc codec.BinaryCodec,
storeKey storetypes.StoreKey,
ak types.AccountKeeper,
bk types.BankKeeper,
storeKey storetypes.StoreKey,
config types.Config,
) Keeper {
return Keeper{
cdc: cdc,
storeKey: storeKey,
accountKeeper: ak,
bankKeeper: bk,
storeKey: storeKey,
config: config,
}
}

Expand Down
43 changes: 43 additions & 0 deletions x/fswap/keeper/keeper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package keeper_test

import (
"context"
"testing"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/suite"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/Finschia/finschia-sdk/simapp"
sdk "github.com/Finschia/finschia-sdk/types"
"github.com/Finschia/finschia-sdk/x/fswap/keeper"
"github.com/Finschia/finschia-sdk/x/fswap/testutil"
"github.com/Finschia/finschia-sdk/x/fswap/types"
)

type KeeperTestSuite struct {
suite.Suite
sdkCtx sdk.Context
goCtx context.Context
keeper keeper.Keeper
bankKeeper types.BankKeeper

msgServer types.MsgServer
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}

func (s *KeeperTestSuite) SetupTest() {
ctrl := gomock.NewController(s.T())
bankKeeper := testutil.NewMockBankKeeper(ctrl)
s.bankKeeper = bankKeeper
checkTx := false
app := simapp.Setup(checkTx)
s.sdkCtx = app.BaseApp.NewContext(checkTx, tmproto.Header{})
s.goCtx = sdk.WrapSDKContext(s.sdkCtx)
s.keeper = app.FswapKeeper

s.msgServer = keeper.NewMsgServerImpl(s.keeper)
}
Loading

0 comments on commit 5d8eb42

Please sign in to comment.