Skip to content

Commit

Permalink
feat: wip, done(keeper, query, msg_server)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeseung-bae committed Apr 25, 2024
1 parent fd4945a commit 435c7f4
Show file tree
Hide file tree
Showing 33 changed files with 903 additions and 376 deletions.
19 changes: 4 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,14 @@ require (
)

require (
cosmossdk.io/api v0.7.0 // indirect
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/core v0.10.0 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/Workiva/go-datastructures v1.1.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd v0.22.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.1 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cockroachdb/errors v1.10.0 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v0.0.0-20230525220056-bb4fc9527b3b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cosmos/cosmos-db v1.0.0 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.3 // indirect
github.com/cosmos/gorocksdb v1.2.0 // indirect
github.com/creachadair/taskgroup v0.6.1 // indirect
github.com/danieljoos/wincred v1.0.2 // indirect
Expand All @@ -85,9 +74,11 @@ require (
github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/getsentry/sentry-go v0.23.0 // indirect
github.com/gin-gonic/gin v1.8.1 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-playground/validator/v10 v10.11.1 // indirect
github.com/goccy/go-json v0.9.11 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.2 // indirect
Expand All @@ -103,17 +94,15 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/linxGnu/grocksdb v1.7.16 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/onsi/gomega v1.20.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
Expand Down
69 changes: 24 additions & 45 deletions go.sum

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions proto/lbm/fswap/v1/fswap.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 "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];
}
16 changes: 16 additions & 0 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ 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"
fswapconfig "github.com/Finschia/finschia-sdk/x/fswap/config"
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 +142,7 @@ var (
vesting.AppModuleBasic{},
tokenmodule.AppModuleBasic{},
collectionmodule.AppModuleBasic{},
fswap.AppModuleBasic{},
)

// module account permissions
Expand All @@ -150,6 +155,7 @@ var (
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
fswaptypes.ModuleName: {authtypes.Burner, authtypes.Minter},
}

// module accounts that are allowed to receive tokens
Expand Down Expand Up @@ -197,6 +203,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 +257,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 +360,9 @@ func NewSimApp(
// If evidence needs to be handled for the app, set routes in router here and seal
app.EvidenceKeeper = *evidenceKeeper

cfg := fswapconfig.DefaultConfig()
app.FswapKeeper = fswapkeeper.NewKeeper(appCodec, keys[fswaptypes.StoreKey], cfg, app.AccountKeeper, app.BankKeeper)

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

// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
Expand Down Expand Up @@ -383,6 +394,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 +422,7 @@ func NewSimApp(
vestingtypes.ModuleName,
token.ModuleName,
collection.ModuleName,
fswaptypes.ModuleName,
)
app.mm.SetOrderEndBlockers(
crisistypes.ModuleName,
Expand All @@ -431,6 +444,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 +472,7 @@ func NewSimApp(
vestingtypes.ModuleName,
token.ModuleName,
collection.ModuleName,
fswaptypes.ModuleName,
)

// Uncomment if you want to set a custom migration order here.
Expand Down Expand Up @@ -722,6 +737,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(foundation.ModuleName)
paramsKeeper.Subspace(fswaptypes.ModuleName)

return paramsKeeper
}
2 changes: 1 addition & 1 deletion x/foundation/keeper/internal/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
sdk "github.com/Finschia/finschia-sdk/types"
authtypes "github.com/Finschia/finschia-sdk/x/auth/types"
"github.com/Finschia/finschia-sdk/x/foundation"
keeper "github.com/Finschia/finschia-sdk/x/foundation/keeper"
"github.com/Finschia/finschia-sdk/x/foundation/keeper"
"github.com/Finschia/finschia-sdk/x/foundation/keeper/internal"
govtypes "github.com/Finschia/finschia-sdk/x/gov/types"
minttypes "github.com/Finschia/finschia-sdk/x/mint/types"
Expand Down
53 changes: 53 additions & 0 deletions x/fswap/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package config

import (
"math/big"

"github.com/Finschia/finschia-sdk/types"
)

type FswapConfig interface {
OldDenom() string
NewDenom() string
SwapCap() types.Int
SwapMultiple() types.Int
}

func DefaultConfig() *Config {
oldDenom := "cony"
newDenom := "peb"
defaultCap, _ := big.NewInt(0).SetString("1151185567094084523856000000", 10)
swapCap := types.NewIntFromBigInt(defaultCap)
num, _ := big.NewInt(0).SetString("148079656000000", 10)
swapMultiple := types.NewIntFromBigInt(num)

return &Config{
oldDenom,
newDenom,
swapCap,
swapMultiple,
}
}

type Config struct {
oldDenom string
newDenom string
swapCap types.Int
swapMultiple types.Int
}

func (c Config) OldDenom() string {
return c.oldDenom
}

func (c Config) NewDenom() string {
return c.newDenom
}

func (c Config) SwapCap() types.Int {
return c.swapCap
}

func (c Config) SwapMultiple() types.Int {
return c.swapMultiple
}
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.

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

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

// InitGenesis initializes the module's state accWithOldCoin 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 {
params, err := k.GetParams(ctx)
if err != nil {
panic(err)
}
swapped, err := k.GetSwapped(ctx)
if err != nil {
panic(err)
}
return &types.GenesisState{
Params: params,
Swapped: swapped,
}
}
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.ctx, *types.DefaultGenesis())
got := s.keeper.ExportGenesis(s.ctx)
s.Require().NotNil(got)
s.Require().Equal(types.DefaultParams(), got.Params)
s.Require().Equal(types.DefaultSwapped(), got.Swapped)
}
30 changes: 23 additions & 7 deletions x/fswap/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,33 @@ package keeper
import (
"context"

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

var _ types.QueryServer = Keeper{}
var _ types.QueryServer = QueryServer{}

// Swapped implements types.QueryServer.
func (k Keeper) Swapped(context.Context, *types.QuerySwappedRequest) (*types.QuerySwappedResponse, error) {
panic("unimplemented")
type QueryServer struct {
Keeper
}

// TotalNewCurrencySwapLimit implements types.QueryServer.
func (k Keeper) TotalNewCurrencySwapLimit(context.Context, *types.QueryTotalSwappableAmountRequest) (*types.QueryTotalSwappableAmountResponse, error) {
panic("unimplemented")
func NewQueryServer(keeper Keeper) *QueryServer {
return &QueryServer{
keeper,
}
}

func (s QueryServer) Swapped(ctx context.Context, _ *types.QuerySwappedRequest) (*types.QuerySwappedResponse, error) {
c := sdk.UnwrapSDKContext(ctx)
swapped, err := s.Keeper.GetSwapped(c)
if err != nil {
return nil, err
}
return &types.QuerySwappedResponse{Swapped: swapped}, nil
}

func (s QueryServer) TotalNewCurrencySwapLimit(ctx context.Context, _ *types.QueryTotalSwappableAmountRequest) (*types.QueryTotalSwappableAmountResponse, error) {
//c := sdk.UnwrapSDKContext(ctx)

Check failure on line 32 in x/fswap/keeper/grpc_query.go

View workflow job for this annotation

GitHub Actions / golangci-lint

commentFormatting: put a space between `//` and comment text (gocritic)
//s.Keeper.GetSwappableNewCoinAmount()
return nil, nil
}
1 change: 0 additions & 1 deletion x/fswap/keeper/grpc_query_params_test.go

This file was deleted.

Loading

0 comments on commit 435c7f4

Please sign in to comment.