diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md
index 16831e12a1..183452dd62 100644
--- a/docs/core/proto-docs.md
+++ b/docs/core/proto-docs.md
@@ -860,8 +860,9 @@
- [EventSwapCoins](#lbm.fswap.v1.EventSwapCoins)
- [lbm/fswap/v1/fswap.proto](#lbm/fswap/v1/fswap.proto)
- - [SwapInit](#lbm.fswap.v1.SwapInit)
- - [SwapInitProposal](#lbm.fswap.v1.SwapInitProposal)
+ - [Swap](#lbm.fswap.v1.Swap)
+ - [SwapProposal](#lbm.fswap.v1.SwapProposal)
+ - [SwapStats](#lbm.fswap.v1.SwapStats)
- [Swapped](#lbm.fswap.v1.Swapped)
- [lbm/fswap/v1/genesis.proto](#lbm/fswap/v1/genesis.proto)
@@ -12750,9 +12751,9 @@ Msg defines the foundation Msg service.
-
+
-### SwapInit
+### Swap
@@ -12768,9 +12769,9 @@ Msg defines the foundation Msg service.
-
+
-### SwapInitProposal
+### SwapProposal
From cosmos-sdk 0.46.0 they deprecated this way, but currently finschia-sdk based on 0.45.10
@@ -12778,7 +12779,22 @@ From cosmos-sdk 0.46.0 they deprecated this way, but currently finschia-sdk base
| ----- | ---- | ----- | ----------- |
| `title` | [string](#string) | | |
| `description` | [string](#string) | | |
-| `swap_init` | [SwapInit](#lbm.fswap.v1.SwapInit) | | |
+| `swap` | [Swap](#lbm.fswap.v1.Swap) | | |
+
+
+
+
+
+
+
+
+### SwapStats
+
+
+
+| Field | Type | Label | Description |
+| ----- | ---- | ----- | ----------- |
+| `swap_count` | [int32](#int32) | | |
@@ -12825,8 +12841,9 @@ GenesisState defines the fswap module's genesis state.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
-| `swap_init` | [SwapInit](#lbm.fswap.v1.SwapInit) | repeated | |
-| `swapped` | [Swapped](#lbm.fswap.v1.Swapped) | repeated | |
+| `swaps` | [Swap](#lbm.fswap.v1.Swap) | repeated | |
+| `swap_stats` | [SwapStats](#lbm.fswap.v1.SwapStats) | | |
+| `swappeds` | [Swapped](#lbm.fswap.v1.Swapped) | repeated | |
@@ -12855,6 +12872,12 @@ GenesisState defines the fswap module's genesis state.
+| Field | Type | Label | Description |
+| ----- | ---- | ----- | ----------- |
+| `fromDenom` | [string](#string) | | |
+| `toDenom` | [string](#string) | | |
+
+
@@ -12881,6 +12904,12 @@ GenesisState defines the fswap module's genesis state.
+| Field | Type | Label | Description |
+| ----- | ---- | ----- | ----------- |
+| `fromDenom` | [string](#string) | | |
+| `toDenom` | [string](#string) | | |
+
+
diff --git a/proto/lbm/fswap/v1/fswap.proto b/proto/lbm/fswap/v1/fswap.proto
index 1216ceca57..d771b253b7 100644
--- a/proto/lbm/fswap/v1/fswap.proto
+++ b/proto/lbm/fswap/v1/fswap.proto
@@ -6,7 +6,7 @@ option go_package = "github.com/Finschia/finschia-sdk/x/fswap/types";
import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
-message SwapInit {
+message Swap {
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;
@@ -18,14 +18,21 @@ message SwapInit {
[(gogoproto.customtype) = "github.com/Finschia/finschia-sdk/types.Int", (gogoproto.nullable) = false];
}
+message SwapStats {
+ option (gogoproto.equal) = true;
+ option (gogoproto.goproto_stringer) = false;
+
+ int32 swap_count = 1;
+}
+
// From cosmos-sdk 0.46.0 they deprecated this way, but currently finschia-sdk based on 0.45.10
-message SwapInitProposal {
+message SwapProposal {
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;
- string title = 1;
- string description = 2;
- SwapInit swap_init = 3 [(gogoproto.nullable) = false];
+ string title = 1;
+ string description = 2;
+ Swap swap = 3 [(gogoproto.nullable) = false];
}
message Swapped {
diff --git a/proto/lbm/fswap/v1/genesis.proto b/proto/lbm/fswap/v1/genesis.proto
index 539454bc2c..c001741269 100644
--- a/proto/lbm/fswap/v1/genesis.proto
+++ b/proto/lbm/fswap/v1/genesis.proto
@@ -8,6 +8,7 @@ import "lbm/fswap/v1/fswap.proto";
// GenesisState defines the fswap module's genesis state.
message GenesisState {
- repeated SwapInit swap_init = 1 [(gogoproto.nullable) = false];
- repeated Swapped swapped = 2 [(gogoproto.nullable) = false];
+ repeated Swap swaps = 1 [(gogoproto.nullable) = false];
+ SwapStats swap_stats = 2 [(gogoproto.nullable) = false];
+ repeated Swapped swappeds = 3 [(gogoproto.nullable) = false];
}
diff --git a/proto/lbm/fswap/v1/query.proto b/proto/lbm/fswap/v1/query.proto
index 3502013229..825d66ad30 100644
--- a/proto/lbm/fswap/v1/query.proto
+++ b/proto/lbm/fswap/v1/query.proto
@@ -21,7 +21,10 @@ service Query {
}
}
-message QuerySwappedRequest {}
+message QuerySwappedRequest {
+ string fromDenom = 1;
+ string toDenom = 2;
+}
message QuerySwappedResponse {
cosmos.base.v1beta1.Coin from_coin_amount = 1
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
@@ -29,7 +32,10 @@ message QuerySwappedResponse {
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
}
-message QueryTotalSwappableToCoinAmountRequest {}
+message QueryTotalSwappableToCoinAmountRequest {
+ string fromDenom = 1;
+ string toDenom = 2;
+}
message QueryTotalSwappableToCoinAmountResponse {
cosmos.base.v1beta1.Coin swappable_amount = 1
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
diff --git a/simapp/app.go b/simapp/app.go
index 237c7e049e..49885f9ec3 100644
--- a/simapp/app.go
+++ b/simapp/app.go
@@ -326,9 +326,7 @@ func NewSimApp(
app.ClassKeeper = classkeeper.NewKeeper(appCodec, keys[class.StoreKey])
app.TokenKeeper = tokenkeeper.NewKeeper(appCodec, keys[token.StoreKey], app.ClassKeeper)
app.CollectionKeeper = collectionkeeper.NewKeeper(appCodec, keys[collection.StoreKey], app.ClassKeeper)
-
- /**** Phase 1 ****/
- app.FswapKeeper = fswapkeeper.NewKeeper(appCodec, keys[fswaptypes.StoreKey], app.AccountKeeper, app.BankKeeper)
+ app.FswapKeeper = fswapkeeper.NewKeeper(appCodec, keys[fswaptypes.StoreKey], fswaptypes.DefaultConfig(), app.AccountKeeper, app.BankKeeper)
// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
@@ -345,7 +343,7 @@ func NewSimApp(
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(foundation.RouterKey, foundationkeeper.NewFoundationProposalsHandler(app.FoundationKeeper)).
- AddRoute(fswaptypes.RouterKey, fswap.NewSwapInitHandler(app.FswapKeeper))
+ AddRoute(fswaptypes.RouterKey, fswap.NewSwapHandler(app.FswapKeeper))
govKeeper := govkeeper.NewKeeper(
appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
diff --git a/x/fswap/client/cli/query.go b/x/fswap/client/cli/query.go
index feddf7dc1f..d5b1a60778 100644
--- a/x/fswap/client/cli/query.go
+++ b/x/fswap/client/cli/query.go
@@ -14,7 +14,7 @@ import (
func GetQueryCmd(queryRoute string) *cobra.Command {
// Group fswap queries under a subcommand
cmd := &cobra.Command{
- Use: types.ModuleName,
+ Use: queryRoute,
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
diff --git a/x/fswap/client/cli/tx.go b/x/fswap/client/cli/tx.go
index 0ab9c915ec..8baec3f747 100644
--- a/x/fswap/client/cli/tx.go
+++ b/x/fswap/client/cli/tx.go
@@ -183,13 +183,13 @@ func parseArgsToContent(cmd *cobra.Command) (gov.Content, error) {
return nil, err
}
- swapInit := types.SwapInit{
+ swapInit := types.Swap{
FromDenom: from_denom,
ToDenom: to_denom,
AmountCapForToDenom: sdk.NewInt(amount_limit),
SwapMultiple: sdk.NewInt(swap_rate),
}
- content := types.NewSwapInitProposal(title, description, swapInit)
+ content := types.NewSwapProposal(title, description, swapInit)
return content, nil
}
diff --git a/x/fswap/handler.go b/x/fswap/handler.go
index d8dfaac2f6..8c0a4f7114 100644
--- a/x/fswap/handler.go
+++ b/x/fswap/handler.go
@@ -26,13 +26,13 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
}
}
-// NewSwapInitHandler creates a governance handler to manage new proposal types.
-// It enables SwapInit to propose an fswap init
-func NewSwapInitHandler(k keeper.Keeper) govtypes.Handler {
+// NewSwapHandler creates a governance handler to manage new proposal types.
+// It enables Swap to propose a swap init
+func NewSwapHandler(k keeper.Keeper) govtypes.Handler {
return func(ctx sdk.Context, content govtypes.Content) error {
switch c := content.(type) {
- case *types.SwapInitProposal:
- return handleSwapInit(ctx, k, c)
+ case *types.SwapProposal:
+ return handleSwap(ctx, k, c)
default:
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized sawp proposal content type: %T", c)
@@ -40,6 +40,6 @@ func NewSwapInitHandler(k keeper.Keeper) govtypes.Handler {
}
}
-func handleSwapInit(ctx sdk.Context, k keeper.Keeper, p *types.SwapInitProposal) error {
- return k.SwapInit(ctx, p.SwapInit)
+func handleSwap(ctx sdk.Context, k keeper.Keeper, p *types.SwapProposal) error {
+ return k.MakeSwap(ctx, p.Swap)
}
diff --git a/x/fswap/keeper/genesis.go b/x/fswap/keeper/genesis.go
index 39ef32bf68..20b01e3656 100644
--- a/x/fswap/keeper/genesis.go
+++ b/x/fswap/keeper/genesis.go
@@ -7,29 +7,45 @@ import (
// InitGenesis initializes the module's state from a provided genesis state.
func (k Keeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) error {
- if len(genState.GetSwapInit()) > 1 {
- return types.ErrSwapCanNotBeInitializedTwice.Wrap("cannot initialize genesis state, there are more than 1 swapInit")
+ if err := genState.Validate(); err != nil {
+ return err
}
- if len(genState.GetSwapped()) > 1 {
- return types.ErrSwapCanNotBeInitializedTwice.Wrap("cannot initialize genesis state, there are more than 1 swapped")
+
+ if len(genState.GetSwaps()) > k.config.MaxSwaps && !k.isUnlimited() {
+ return types.ErrCanNotHaveMoreSwap.Wrapf("cannot initialize genesis state, there are more than %d swapInits", k.config.MaxSwaps)
+ }
+
+ if len(genState.GetSwappeds()) > k.config.MaxSwaps && !k.isUnlimited() {
+ return types.ErrCanNotHaveMoreSwap.Wrapf("cannot initialize genesis state, there are more than %d swapped", k.config.MaxSwaps)
}
- for _, swapInit := range genState.GetSwapInit() {
- if err := k.setSwapInit(ctx, swapInit); err != nil {
+
+ for _, swap := range genState.GetSwaps() {
+ if err := k.MakeSwap(ctx, swap); err != nil {
panic(err)
}
}
- for _, swapped := range genState.GetSwapped() {
- if err := swapped.Validate(); err != nil {
+
+ for _, swapped := range genState.GetSwappeds() {
+ if err := swapped.ValidateBasic(); err != nil {
panic(err)
}
}
return nil
}
+func (k Keeper) isUnlimited() bool {
+ return k.config.MaxSwaps == 0
+}
+
// ExportGenesis returns the module's exported genesis.
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
+ stats, err := k.getSwapStats(ctx)
+ if err != nil {
+ panic(err)
+ }
return &types.GenesisState{
- SwapInit: k.getAllSwapInits(ctx),
- Swapped: k.getAllSwapped(ctx),
+ Swaps: k.getAllSwaps(ctx),
+ SwapStats: stats,
+ Swappeds: k.getAllSwapped(ctx),
}
}
diff --git a/x/fswap/keeper/genesis_test.go b/x/fswap/keeper/genesis_test.go
index d57f9a24f8..c4fa1a0e99 100644
--- a/x/fswap/keeper/genesis_test.go
+++ b/x/fswap/keeper/genesis_test.go
@@ -1,6 +1,8 @@
package keeper_test
import (
+ "fmt"
+
"github.com/Finschia/finschia-sdk/x/fswap/types"
)
@@ -11,7 +13,9 @@ func (s *KeeperTestSuite) TestInitAndExportGenesis() {
s.Require().NoError(err)
exportGenesis := s.keeper.ExportGenesis(ctx)
+ fmt.Println(len(exportGenesis.GetSwaps()))
s.Require().Equal(defaultGenesis, exportGenesis)
- s.Require().Equal(defaultGenesis.GetSwapInit(), exportGenesis.GetSwapInit())
- s.Require().Equal(defaultGenesis.GetSwapped(), exportGenesis.GetSwapped())
+ s.Require().Equal(defaultGenesis.GetSwaps(), exportGenesis.GetSwaps())
+ s.Require().Equal(defaultGenesis.GetSwapStats(), exportGenesis.GetSwapStats())
+ s.Require().Equal(defaultGenesis.GetSwappeds(), exportGenesis.GetSwappeds())
}
diff --git a/x/fswap/keeper/grpc_query.go b/x/fswap/keeper/grpc_query.go
index 44ce360b82..1a47467cff 100644
--- a/x/fswap/keeper/grpc_query.go
+++ b/x/fswap/keeper/grpc_query.go
@@ -19,10 +19,10 @@ func NewQueryServer(keeper Keeper) *QueryServer {
}
}
-func (s QueryServer) Swapped(ctx context.Context, _ *types.QuerySwappedRequest) (*types.QuerySwappedResponse, error) {
+func (s QueryServer) Swapped(ctx context.Context, req *types.QuerySwappedRequest) (*types.QuerySwappedResponse, error) {
c := sdk.UnwrapSDKContext(ctx)
- swapped, err := s.Keeper.getSwapped(c)
+ swapped, err := s.Keeper.getSwapped(c, req.GetFromDenom(), req.GetToDenom())
if err != nil {
return nil, err
}
@@ -33,10 +33,10 @@ func (s QueryServer) Swapped(ctx context.Context, _ *types.QuerySwappedRequest)
}, nil
}
-func (s QueryServer) TotalSwappableToCoinAmount(ctx context.Context, _ *types.QueryTotalSwappableToCoinAmountRequest) (*types.QueryTotalSwappableToCoinAmountResponse, error) {
+func (s QueryServer) TotalSwappableToCoinAmount(ctx context.Context, req *types.QueryTotalSwappableToCoinAmountRequest) (*types.QueryTotalSwappableToCoinAmountResponse, error) {
c := sdk.UnwrapSDKContext(ctx)
- amount, err := s.Keeper.getSwappableNewCoinAmount(c)
+ amount, err := s.Keeper.getSwappableNewCoinAmount(c, req.GetFromDenom(), req.GetToDenom())
if err != nil {
return &types.QueryTotalSwappableToCoinAmountResponse{}, err
}
diff --git a/x/fswap/keeper/keeper.go b/x/fswap/keeper/keeper.go
index 7706d5780c..008e7c6330 100644
--- a/x/fswap/keeper/keeper.go
+++ b/x/fswap/keeper/keeper.go
@@ -17,16 +17,24 @@ type Keeper struct {
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
+ config types.Config
+
AccountKeeper
BankKeeper
+
+ swaps []types.Swap
+ swappedSlice []types.Swapped
}
-func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, ak AccountKeeper, bk BankKeeper) Keeper {
+func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, config types.Config, ak AccountKeeper, bk BankKeeper) Keeper {
return Keeper{
- cdc: cdc,
- storeKey: storeKey,
- AccountKeeper: ak,
- BankKeeper: bk,
+ cdc,
+ storeKey,
+ config,
+ ak,
+ bk,
+ make([]types.Swap, config.MaxSwaps),
+ make([]types.Swapped, config.MaxSwaps),
}
}
@@ -34,49 +42,72 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}
-func (k Keeper) SwapInit(ctx sdk.Context, swapInit types.SwapInit) error {
- if err := swapInit.ValidateBasic(); err != nil {
+func (k Keeper) MakeSwap(ctx sdk.Context, swap types.Swap) error {
+ if err := swap.ValidateBasic(); err != nil {
return err
}
- if k.hasBeenInitialized(ctx) {
- return types.ErrSwapCanNotBeInitializedTwice
+
+ isNewSwap := true
+ if _, err := k.getSwap(ctx, swap.ToDenom, swap.FromDenom); err == nil {
+ return sdkerrors.ErrInvalidRequest.Wrap("there is already a swap in reverse way, only one way swap allowed")
+ }
+
+ if _, err := k.getSwap(ctx, swap.FromDenom, swap.ToDenom); err == nil {
+ isNewSwap = false
}
- if err := k.setSwapInit(ctx, swapInit); err != nil {
+
+ if !isNewSwap && !k.config.UpdateAllowed {
+ return sdkerrors.ErrInvalidRequest.Wrap("update existing swap not allowed")
+ }
+
+ if err := k.increaseSwapCount(ctx); err != nil {
return err
}
- swapped := types.Swapped{
- FromCoinAmount: sdk.Coin{
- Denom: swapInit.GetFromDenom(),
- Amount: sdk.ZeroInt(),
- },
- ToCoinAmount: sdk.Coin{
- Denom: swapInit.GetToDenom(),
- Amount: sdk.ZeroInt(),
- },
- }
- if err := k.setSwapped(ctx, swapped); err != nil {
+
+ key := swapKey(swap.FromDenom, swap.ToDenom)
+ bz, err := k.cdc.Marshal(&swap)
+ if err != nil {
return err
}
+
+ store := ctx.KVStore(k.storeKey)
+ store.Set(key, bz)
+
+ if isNewSwap {
+ swapped := types.Swapped{
+ FromCoinAmount: sdk.Coin{
+ Denom: swap.GetFromDenom(),
+ Amount: sdk.ZeroInt(),
+ },
+ ToCoinAmount: sdk.Coin{
+ Denom: swap.GetToDenom(),
+ Amount: sdk.ZeroInt(),
+ },
+ }
+ if err := k.setSwapped(ctx, swap.GetFromDenom(), swap.GetToDenom(), swapped); err != nil {
+ return err
+ }
+ }
return nil
}
func (k Keeper) Swap(ctx sdk.Context, addr sdk.AccAddress, fromCoinAmount sdk.Coin, toDenom string) error {
- swapInit, err := k.swapInit(ctx)
+ swap, err := k.getSwap(ctx, fromCoinAmount.Denom, toDenom)
if err != nil {
return err
}
- if swapInit.GetFromDenom() != fromCoinAmount.GetDenom() {
- return sdkerrors.ErrInvalidRequest.Wrapf("denom mismatch, expected %s, got %s", swapInit.GetFromDenom(), fromCoinAmount.Denom)
+ if swap.GetFromDenom() != fromCoinAmount.GetDenom() {
+ return sdkerrors.ErrInvalidRequest.Wrapf("denom mismatch, expected %s, got %s", swap.GetFromDenom(), fromCoinAmount.Denom)
}
- if swapInit.GetToDenom() != toDenom {
- return sdkerrors.ErrInvalidRequest.Wrapf("denom mismatch, expected %s, got %s", swapInit.GetToDenom(), toDenom)
+ if swap.GetToDenom() != toDenom {
+ return sdkerrors.ErrInvalidRequest.Wrapf("denom mismatch, expected %s, got %s", swap.GetToDenom(), toDenom)
}
- newAmount := fromCoinAmount.Amount.Mul(swapInit.SwapMultiple)
+ newAmount := fromCoinAmount.Amount.Mul(swap.SwapMultiple)
newCoinAmount := sdk.NewCoin(toDenom, newAmount)
- if err := k.checkSwapCap(ctx, newCoinAmount); err != nil {
+ if err := k.checkSwapCap(ctx, swap, newCoinAmount); err != nil {
return err
}
@@ -122,23 +153,17 @@ func (k Keeper) SwapAll(ctx sdk.Context, addr sdk.AccAddress, fromDenom, toDenom
return nil
}
-func (k Keeper) setSwapInit(ctx sdk.Context, swapInit types.SwapInit) error {
- store := ctx.KVStore(k.storeKey)
- bz, err := k.cdc.Marshal(&swapInit)
- if err != nil {
- return err
- }
- store.Set(swapInitKey(swapInit.ToDenom), bz)
- return nil
-}
-
func (k Keeper) getAllSwapped(ctx sdk.Context) []types.Swapped {
- swappedSlice := make([]types.Swapped, 0) // TODO(bjs)
+ idx := 0
k.iterateAllSwapped(ctx, func(swapped types.Swapped) bool {
- swappedSlice = append(swappedSlice, swapped)
+ k.swappedSlice[idx] = swapped
+ idx++
return false
})
- return swappedSlice
+ if idx == 0 {
+ return []types.Swapped{}
+ }
+ return k.swappedSlice
}
func (k Keeper) iterateAllSwapped(ctx sdk.Context, cb func(swapped types.Swapped) (stop bool)) {
@@ -157,14 +182,9 @@ func (k Keeper) iterateAllSwapped(ctx sdk.Context, cb func(swapped types.Swapped
}
}
-func (k Keeper) getSwapped(ctx sdk.Context) (types.Swapped, error) {
- toDenom, err := k.toDenom(ctx)
- if err != nil {
- return types.Swapped{}, err
- }
-
+func (k Keeper) getSwapped(ctx sdk.Context, fromDenom, toDenom string) (types.Swapped, error) {
store := ctx.KVStore(k.storeKey)
- key := swappedKey(toDenom)
+ key := swappedKey(fromDenom, toDenom)
bz := store.Get(key)
if bz == nil {
return types.Swapped{}, types.ErrSwappedNotFound
@@ -177,145 +197,158 @@ func (k Keeper) getSwapped(ctx sdk.Context) (types.Swapped, error) {
return swapped, nil
}
-func (k Keeper) setSwapped(ctx sdk.Context, swapped types.Swapped) error {
- store := ctx.KVStore(k.storeKey)
- key := swappedKey(swapped.ToCoinAmount.Denom)
+func (k Keeper) setSwapped(ctx sdk.Context, fromDenom, toDenom string, swapped types.Swapped) error {
+ key := swappedKey(fromDenom, toDenom)
bz, err := k.cdc.Marshal(&swapped)
if err != nil {
return err
}
+ store := ctx.KVStore(k.storeKey)
store.Set(key, bz)
return nil
}
-func (k Keeper) getAllSwapInits(ctx sdk.Context) []types.SwapInit {
- swapInits := make([]types.SwapInit, 0)
- k.iterateAllSwapInits(ctx, func(swapInit types.SwapInit) bool {
- swapInits = append(swapInits, swapInit)
+func (k Keeper) getAllSwaps(ctx sdk.Context) []types.Swap {
+ idx := 0
+ k.iterateAllSwaps(ctx, func(swap types.Swap) bool {
+ k.swaps[idx] = swap
+ idx++
return false
})
- return swapInits
+ if idx == 0 {
+ return []types.Swap{}
+ }
+ return k.swaps
}
-func (k Keeper) iterateAllSwapInits(ctx sdk.Context, cb func(swapped types.SwapInit) (stop bool)) {
+func (k Keeper) iterateAllSwaps(ctx sdk.Context, cb func(swapped types.Swap) (stop bool)) {
store := ctx.KVStore(k.storeKey)
- swapInitDataStore := prefix.NewStore(store, swapInitPrefix)
+ swapDataStore := prefix.NewStore(store, swapPrefix)
- iterator := swapInitDataStore.Iterator(nil, nil)
+ iterator := swapDataStore.Iterator(nil, nil)
defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
- swapInit := types.SwapInit{}
- k.cdc.MustUnmarshal(iterator.Value(), &swapInit)
- if cb(swapInit) {
+ swap := types.Swap{}
+ k.cdc.MustUnmarshal(iterator.Value(), &swap)
+ if cb(swap) {
break
}
}
}
-func (k Keeper) getSwappableNewCoinAmount(ctx sdk.Context) (sdk.Coin, error) {
- swapCap, err := k.swapCap(ctx)
+func (k Keeper) getSwappableNewCoinAmount(ctx sdk.Context, fromDenom, toDenom string) (sdk.Coin, error) {
+ swap, err := k.getSwap(ctx, fromDenom, toDenom)
if err != nil {
return sdk.Coin{}, err
}
- swapped, err := k.getSwapped(ctx)
- if err != nil {
- return sdk.Coin{}, err
- }
- denom, err := k.toDenom(ctx)
+
+ swapped, err := k.getSwapped(ctx, fromDenom, toDenom)
if err != nil {
return sdk.Coin{}, err
}
+ swapCap := swap.AmountCapForToDenom
remainingAmount := swapCap.Sub(swapped.GetToCoinAmount().Amount)
- return sdk.NewCoin(denom, remainingAmount), nil
+ return sdk.NewCoin(toDenom, remainingAmount), nil
}
-func (k Keeper) fromDenom(ctx sdk.Context) (string, error) {
- swapInit, err := k.swapInit(ctx)
- if err != nil {
- return "", err
+func (k Keeper) getSwap(ctx sdk.Context, fromDenom, toDenom string) (types.Swap, error) {
+ store := ctx.KVStore(k.storeKey)
+ key := swapKey(fromDenom, toDenom)
+ bz := store.Get(key)
+ if bz == nil {
+ return types.Swap{}, sdkerrors.ErrNotFound.Wrap("swap not found")
+ }
+
+ swap := types.Swap{}
+ if err := k.cdc.Unmarshal(bz, &swap); err != nil {
+ return types.Swap{}, err
}
- return swapInit.FromDenom, nil
+ return swap, nil
}
-func (k Keeper) toDenom(ctx sdk.Context) (string, error) {
- swapInit, err := k.swapInit(ctx)
+func (k Keeper) updateSwapped(ctx sdk.Context, fromAmount, toAmount sdk.Coin) error {
+ prevSwapped, err := k.getSwapped(ctx, fromAmount.Denom, toAmount.Denom)
if err != nil {
- return "", err
+ return err
}
- return swapInit.GetToDenom(), nil
-}
+ updatedSwapped := &types.Swapped{
+ FromCoinAmount: fromAmount.Add(prevSwapped.FromCoinAmount),
+ ToCoinAmount: toAmount.Add(prevSwapped.ToCoinAmount),
+ }
-func (k Keeper) swapMultiple(ctx sdk.Context) (sdk.Int, error) {
- swapInit, err := k.swapInit(ctx)
+ key := swappedKey(fromAmount.Denom, toAmount.Denom)
+ bz, err := k.cdc.Marshal(updatedSwapped)
if err != nil {
- return sdk.Int{}, err
+ return err
}
- return swapInit.SwapMultiple, nil
+ store := ctx.KVStore(k.storeKey)
+ store.Set(key, bz)
+ return nil
}
-func (k Keeper) swapCap(ctx sdk.Context) (sdk.Int, error) {
- swapInit, err := k.swapInit(ctx)
+func (k Keeper) checkSwapCap(ctx sdk.Context, swap types.Swap, newCoinAmount sdk.Coin) error {
+ swapped, err := k.getSwapped(ctx, swap.GetFromDenom(), swap.GetToDenom())
if err != nil {
- return sdk.Int{}, err
+ return err
}
- return swapInit.AmountCapForToDenom, nil
-}
-
-func (k Keeper) swapInit(ctx sdk.Context) (types.SwapInit, error) {
- swapInits := k.getAllSwapInits(ctx)
- if len(swapInits) == 0 {
- return types.SwapInit{}, types.ErrSwapNotInitialized
+ swapCap := swap.AmountCapForToDenom
+ if swapCap.LT(swapped.ToCoinAmount.Add(newCoinAmount).Amount) {
+ return types.ErrExceedSwappableToCoinAmount
}
+ return nil
+}
- return swapInits[0], nil
+func (k Keeper) allowUpdate() bool {
+ return k.config.UpdateAllowed
}
-func (k Keeper) updateSwapped(ctx sdk.Context, fromAmount, toAmount sdk.Coin) error {
- prevSwapped, err := k.getSwapped(ctx)
+func (k Keeper) increaseSwapCount(ctx sdk.Context) error {
+ stats, err := k.getSwapStats(ctx)
if err != nil {
return err
}
- updatedSwapped := &types.Swapped{
- FromCoinAmount: fromAmount.Add(prevSwapped.FromCoinAmount),
- ToCoinAmount: toAmount.Add(prevSwapped.ToCoinAmount),
+ prev := stats.SwapCount
+ stats.SwapCount += 1
+ if stats.SwapCount < prev {
+ return types.ErrInvalidState.Wrap("overflow detected")
}
- store := ctx.KVStore(k.storeKey)
- bz, err := k.cdc.Marshal(updatedSwapped)
- if err != nil {
+
+ if err := k.setSwapStats(ctx, stats); err != nil {
return err
}
-
- key := swappedKey(toAmount.Denom)
- store.Set(key, bz)
return nil
}
-func (k Keeper) checkSwapCap(ctx sdk.Context, newCoinAmount sdk.Coin) error {
- swapped, err := k.getSwapped(ctx)
+func (k Keeper) getSwapStats(ctx sdk.Context) (types.SwapStats, error) {
+ store := ctx.KVStore(k.storeKey)
+ bz := store.Get(swapStatsKey)
+ if bz == nil {
+ return types.SwapStats{}, nil
+ }
+
+ stats := types.SwapStats{}
+ err := k.cdc.Unmarshal(bz, &stats)
if err != nil {
- return err
+ return types.SwapStats{}, err
}
+ return stats, nil
+}
- swapCap, err := k.swapCap(ctx)
+func (k Keeper) setSwapStats(ctx sdk.Context, stats types.SwapStats) error {
+ bz, err := k.cdc.Marshal(&stats)
if err != nil {
return err
}
- if swapCap.LT(swapped.ToCoinAmount.Add(newCoinAmount).Amount) {
- return types.ErrExceedSwappableToCoinAmount
- }
+ store := ctx.KVStore(k.storeKey)
+ store.Set(swapStatsKey, bz)
return nil
}
-
-func (k Keeper) hasBeenInitialized(ctx sdk.Context) bool {
- inits := k.getAllSwapInits(ctx)
- return len(inits) > 0
-}
diff --git a/x/fswap/keeper/keeper_test.go b/x/fswap/keeper/keeper_test.go
index 9880b13e17..8457f227ad 100644
--- a/x/fswap/keeper/keeper_test.go
+++ b/x/fswap/keeper/keeper_test.go
@@ -30,7 +30,7 @@ type KeeperTestSuite struct {
accWithToCoin sdk.AccAddress
initBalance sdk.Int
- swapInit types.SwapInit
+ swap types.Swap
}
func (s *KeeperTestSuite) createRandomAccounts(n int) []sdk.AccAddress {
@@ -64,7 +64,7 @@ func (s *KeeperTestSuite) SetupTest() {
numAcc := int64(2)
s.initBalance = sdk.NewInt(123456789)
- s.swapInit = types.SwapInit{
+ s.swap = types.Swap{
FromDenom: "fromdenom",
ToDenom: "todenom",
AmountCapForToDenom: s.initBalance.Mul(sdk.NewInt(1000).Mul(sdk.NewInt(numAcc))),
@@ -83,11 +83,11 @@ func (s *KeeperTestSuite) createAccountsWithInitBalance(app *simapp.SimApp) {
*addresses[i] = address
}
minter := app.AccountKeeper.GetModuleAccount(s.ctx, minttypes.ModuleName).GetAddress()
- fromAmount := sdk.NewCoins(sdk.NewCoin(s.swapInit.GetFromDenom(), s.initBalance))
+ fromAmount := sdk.NewCoins(sdk.NewCoin(s.swap.GetFromDenom(), s.initBalance))
s.Require().NoError(app.BankKeeper.MintCoins(s.ctx, minttypes.ModuleName, fromAmount))
s.Require().NoError(app.BankKeeper.SendCoins(s.ctx, minter, s.accWithFromCoin, fromAmount))
- toAmount := sdk.NewCoins(sdk.NewCoin(s.swapInit.GetToDenom(), s.initBalance))
+ toAmount := sdk.NewCoins(sdk.NewCoin(s.swap.GetToDenom(), s.initBalance))
s.Require().NoError(app.BankKeeper.MintCoins(s.ctx, minttypes.ModuleName, toAmount))
s.Require().NoError(app.BankKeeper.SendCoins(s.ctx, minter, s.accWithToCoin, toAmount))
}
@@ -107,40 +107,40 @@ func (s *KeeperTestSuite) TestSwap() {
}{
"swap some": {
s.accWithFromCoin,
- sdk.NewCoin(s.swapInit.GetFromDenom(), sdk.NewInt(100)),
- s.swapInit.GetToDenom(),
+ sdk.NewCoin(s.swap.GetFromDenom(), sdk.NewInt(100)),
+ s.swap.GetToDenom(),
sdk.NewInt(100),
false,
nil,
},
"swap all the balance": {
s.accWithFromCoin,
- sdk.NewCoin(s.swapInit.GetFromDenom(), s.initBalance),
- s.swapInit.GetToDenom(),
+ sdk.NewCoin(s.swap.GetFromDenom(), s.initBalance),
+ s.swap.GetToDenom(),
s.initBalance,
false,
nil,
},
"swap without holding enough balance": {
s.accWithFromCoin,
- sdk.NewCoin(s.swapInit.GetFromDenom(), sdk.OneInt().Add(s.initBalance)),
- s.swapInit.GetToDenom(),
+ sdk.NewCoin(s.swap.GetFromDenom(), sdk.OneInt().Add(s.initBalance)),
+ s.swap.GetToDenom(),
sdk.ZeroInt(),
true,
sdkerrors.ErrInsufficientFunds,
},
"account holding new coin only": {
s.accWithToCoin,
- sdk.NewCoin(s.swapInit.GetFromDenom(), sdk.NewInt(100)),
- s.swapInit.GetToDenom(),
+ sdk.NewCoin(s.swap.GetFromDenom(), sdk.NewInt(100)),
+ s.swap.GetToDenom(),
sdk.ZeroInt(),
true,
sdkerrors.ErrInsufficientFunds,
},
"swap with the same from-denom and to-denom": {
s.accWithFromCoin,
- sdk.NewCoin(s.swapInit.GetToDenom(), s.initBalance),
- s.swapInit.GetToDenom(),
+ sdk.NewCoin(s.swap.GetToDenom(), s.initBalance),
+ s.swap.GetToDenom(),
sdk.ZeroInt(),
true,
sdkerrors.ErrInvalidRequest,
@@ -149,7 +149,7 @@ func (s *KeeperTestSuite) TestSwap() {
for name, tc := range testCases {
s.Run(name, func() {
ctx, _ := s.ctx.CacheContext()
- err := s.keeper.SwapInit(ctx, s.swapInit)
+ err := s.keeper.MakeSwap(ctx, s.swap)
s.Require().NoError(err)
err = s.keeper.Swap(ctx, tc.from, tc.amountToSwap, tc.toDenom)
@@ -159,8 +159,8 @@ func (s *KeeperTestSuite) TestSwap() {
}
s.Require().NoError(err)
- actualAmount := s.keeper.GetBalance(ctx, tc.from, s.swapInit.GetToDenom()).Amount
- expectedAmount := tc.expectedBalanceWithoutMultiply.Mul(s.swapInit.SwapMultiple)
+ actualAmount := s.keeper.GetBalance(ctx, tc.from, s.swap.GetToDenom()).Amount
+ expectedAmount := tc.expectedBalanceWithoutMultiply.Mul(s.swap.SwapMultiple)
s.Require().Equal(expectedAmount, actualAmount)
})
}
@@ -177,16 +177,16 @@ func (s *KeeperTestSuite) TestSwapAll() {
}{
"account holding from coin": {
s.accWithFromCoin,
- s.swapInit.GetFromDenom(),
- s.swapInit.GetToDenom(),
+ s.swap.GetFromDenom(),
+ s.swap.GetToDenom(),
s.initBalance,
false,
nil,
},
"account holding to coin only": {
s.accWithToCoin,
- s.swapInit.GetFromDenom(),
- s.swapInit.GetToDenom(),
+ s.swap.GetFromDenom(),
+ s.swap.GetToDenom(),
s.initBalance,
true,
sdkerrors.ErrInsufficientFunds,
@@ -195,7 +195,7 @@ func (s *KeeperTestSuite) TestSwapAll() {
for name, tc := range testCases {
s.Run(name, func() {
ctx, _ := s.ctx.CacheContext()
- err := s.keeper.SwapInit(ctx, s.swapInit)
+ err := s.keeper.MakeSwap(ctx, s.swap)
s.Require().NoError(err)
err = s.keeper.SwapAll(ctx, tc.from, tc.fromDenom, tc.toDenom)
@@ -205,8 +205,8 @@ func (s *KeeperTestSuite) TestSwapAll() {
}
s.Require().NoError(err)
- actualAmount := s.keeper.GetBalance(ctx, tc.from, s.swapInit.GetToDenom()).Amount
- expectedAmount := tc.expectedBalanceWithoutMultiply.Mul(s.swapInit.SwapMultiple)
+ actualAmount := s.keeper.GetBalance(ctx, tc.from, s.swap.GetToDenom()).Amount
+ expectedAmount := tc.expectedBalanceWithoutMultiply.Mul(s.swap.SwapMultiple)
s.Require().Equal(expectedAmount, actualAmount)
})
}
@@ -214,12 +214,12 @@ func (s *KeeperTestSuite) TestSwapAll() {
func (s *KeeperTestSuite) TestSwapInit() {
testCases := map[string]struct {
- req types.SwapInit
+ req types.Swap
shouldThrowError bool
expectedError error
}{
- "valid swapInit": {
- types.SwapInit{
+ "valid getSwapInit": {
+ types.Swap{
FromDenom: "fromD",
ToDenom: "toD",
AmountCapForToDenom: sdk.OneInt(),
@@ -229,7 +229,7 @@ func (s *KeeperTestSuite) TestSwapInit() {
nil,
},
"invalid empty from-denom": {
- types.SwapInit{
+ types.Swap{
FromDenom: "",
ToDenom: "toD",
AmountCapForToDenom: sdk.OneInt(),
@@ -239,7 +239,7 @@ func (s *KeeperTestSuite) TestSwapInit() {
sdkerrors.ErrInvalidRequest,
},
"invalid empty to-denom": {
- types.SwapInit{
+ types.Swap{
FromDenom: "fromD",
ToDenom: "",
AmountCapForToDenom: sdk.OneInt(),
@@ -249,7 +249,7 @@ func (s *KeeperTestSuite) TestSwapInit() {
sdkerrors.ErrInvalidRequest,
},
"invalid zero amount cap for to-denom": {
- types.SwapInit{
+ types.Swap{
FromDenom: "fromD",
ToDenom: "toD",
AmountCapForToDenom: sdk.ZeroInt(),
@@ -259,7 +259,7 @@ func (s *KeeperTestSuite) TestSwapInit() {
sdkerrors.ErrInvalidRequest,
},
"invalid zero swap-rate": {
- types.SwapInit{
+ types.Swap{
FromDenom: "fromD",
ToDenom: "toD",
AmountCapForToDenom: sdk.OneInt(),
@@ -269,7 +269,7 @@ func (s *KeeperTestSuite) TestSwapInit() {
sdkerrors.ErrInvalidRequest,
},
"invalid the same from-denom and to-denom": {
- types.SwapInit{
+ types.Swap{
FromDenom: "same",
ToDenom: "same",
AmountCapForToDenom: sdk.OneInt(),
@@ -282,7 +282,7 @@ func (s *KeeperTestSuite) TestSwapInit() {
for name, tc := range testCases {
s.Run(name, func() {
ctx, _ := s.ctx.CacheContext()
- err := s.keeper.SwapInit(ctx, tc.req)
+ err := s.keeper.MakeSwap(ctx, tc.req)
if tc.shouldThrowError {
s.Require().ErrorIs(err, tc.expectedError)
return
diff --git a/x/fswap/keeper/keys.go b/x/fswap/keeper/keys.go
index b3b652723f..04e36660f8 100644
--- a/x/fswap/keeper/keys.go
+++ b/x/fswap/keeper/keys.go
@@ -1,16 +1,19 @@
package keeper
var (
- swapInitPrefix = []byte{0x01}
- swappedKeyPrefix = []byte{0x02}
+ swapPrefix = []byte{0x01}
+ swapStatsKey = []byte{0x02}
+ swappedKeyPrefix = []byte{0x03}
)
-// swapInitKey key(prefix + toDenom)
-func swapInitKey(toDenom string) []byte {
- return append(swapInitPrefix, toDenom...)
+// swapKey key(prefix + fromDenom + toDenom)
+func swapKey(fromDenom, toDenom string) []byte {
+ key := append(swapPrefix, fromDenom...)
+ return append(key, toDenom...)
}
-// swappedKey key(prefix + toDenom)
-func swappedKey(toDenom string) []byte {
- return append(swappedKeyPrefix, toDenom...)
+// swappedKey key(prefix + fromDenom + toDenom)
+func swappedKey(fromDenom, toDenom string) []byte {
+ key := append(swappedKeyPrefix, fromDenom...)
+ return append(key, toDenom...)
}
diff --git a/x/fswap/keeper/msg_server_test.go b/x/fswap/keeper/msg_server_test.go
index dc0e4093f9..499ccff16f 100644
--- a/x/fswap/keeper/msg_server_test.go
+++ b/x/fswap/keeper/msg_server_test.go
@@ -16,8 +16,8 @@ func (s *KeeperTestSuite) TestMsgSwap() {
"swap some": {
&types.MsgSwap{
FromAddress: s.accWithFromCoin.String(),
- FromCoinAmount: sdk.NewCoin(s.swapInit.GetFromDenom(), sdk.NewInt(100)),
- ToDenom: s.swapInit.GetToDenom(),
+ FromCoinAmount: sdk.NewCoin(s.swap.GetFromDenom(), sdk.NewInt(100)),
+ ToDenom: s.swap.GetToDenom(),
},
sdk.NewInt(100),
false,
@@ -26,8 +26,8 @@ func (s *KeeperTestSuite) TestMsgSwap() {
"swap all the balance": {
&types.MsgSwap{
FromAddress: s.accWithFromCoin.String(),
- FromCoinAmount: sdk.NewCoin(s.swapInit.GetFromDenom(), s.initBalance),
- ToDenom: s.swapInit.GetToDenom(),
+ FromCoinAmount: sdk.NewCoin(s.swap.GetFromDenom(), s.initBalance),
+ ToDenom: s.swap.GetToDenom(),
},
s.initBalance,
false,
@@ -36,8 +36,8 @@ func (s *KeeperTestSuite) TestMsgSwap() {
"account holding new coin only": {
&types.MsgSwap{
FromAddress: s.accWithToCoin.String(),
- FromCoinAmount: sdk.NewCoin(s.swapInit.GetFromDenom(), sdk.NewInt(100)),
- ToDenom: s.swapInit.GetToDenom(),
+ FromCoinAmount: sdk.NewCoin(s.swap.GetFromDenom(), sdk.NewInt(100)),
+ ToDenom: s.swap.GetToDenom(),
},
s.initBalance,
true,
@@ -47,7 +47,7 @@ func (s *KeeperTestSuite) TestMsgSwap() {
for name, tc := range testCases {
s.Run(name, func() {
ctx, _ := s.ctx.CacheContext()
- err := s.keeper.SwapInit(ctx, s.swapInit)
+ err := s.keeper.MakeSwap(ctx, s.swap)
s.Require().NoError(err)
swapResponse, err := s.msgServer.Swap(sdk.WrapSDKContext(ctx), tc.request)
@@ -61,7 +61,7 @@ func (s *KeeperTestSuite) TestMsgSwap() {
from, err := sdk.AccAddressFromBech32(tc.request.FromAddress)
s.Require().NoError(err)
actualAmount := s.keeper.GetBalance(ctx, from, tc.request.GetToDenom()).Amount
- expectedAmount := tc.expectedBalanceWithoutMultiply.Mul(s.swapInit.SwapMultiple)
+ expectedAmount := tc.expectedBalanceWithoutMultiply.Mul(s.swap.SwapMultiple)
s.Require().Equal(expectedAmount, actualAmount)
})
}
@@ -77,8 +77,8 @@ func (s *KeeperTestSuite) TestMsgSwapAll() {
"swapAll": {
&types.MsgSwapAll{
FromAddress: s.accWithFromCoin.String(),
- FromDenom: s.swapInit.GetFromDenom(),
- ToDenom: s.swapInit.GetToDenom(),
+ FromDenom: s.swap.GetFromDenom(),
+ ToDenom: s.swap.GetToDenom(),
},
s.initBalance,
false,
@@ -87,8 +87,8 @@ func (s *KeeperTestSuite) TestMsgSwapAll() {
"account holding new coin only": {
&types.MsgSwapAll{
FromAddress: s.accWithToCoin.String(),
- FromDenom: s.swapInit.GetFromDenom(),
- ToDenom: s.swapInit.GetToDenom(),
+ FromDenom: s.swap.GetFromDenom(),
+ ToDenom: s.swap.GetToDenom(),
},
s.initBalance,
true,
@@ -98,7 +98,7 @@ func (s *KeeperTestSuite) TestMsgSwapAll() {
for name, tc := range testCases {
s.Run(name, func() {
ctx, _ := s.ctx.CacheContext()
- err := s.keeper.SwapInit(ctx, s.swapInit)
+ err := s.keeper.MakeSwap(ctx, s.swap)
s.Require().NoError(err)
swapResponse, err := s.msgServer.SwapAll(sdk.WrapSDKContext(ctx), tc.request)
@@ -112,7 +112,7 @@ func (s *KeeperTestSuite) TestMsgSwapAll() {
from, err := sdk.AccAddressFromBech32(tc.request.FromAddress)
s.Require().NoError(err)
actualAmount := s.keeper.GetBalance(ctx, from, tc.request.GetToDenom()).Amount
- expectedAmount := tc.expectedBalanceWithoutMultiply.Mul(s.swapInit.SwapMultiple)
+ expectedAmount := tc.expectedBalanceWithoutMultiply.Mul(s.swap.SwapMultiple)
s.Require().Equal(expectedAmount, actualAmount)
})
}
diff --git a/x/fswap/module.go b/x/fswap/module.go
index 280ba8f091..9ee61a12cb 100644
--- a/x/fswap/module.go
+++ b/x/fswap/module.go
@@ -28,7 +28,7 @@ var (
// AppModuleBasic
// ----------------------------------------------------------------------------
-// AppModuleBasic implements the AppModuleBasic interface for the capability module.
+// AppModuleBasic implements the AppModuleBasic interface for the fswap module.
type AppModuleBasic struct {
cdc codec.BinaryCodec
}
@@ -37,7 +37,7 @@ func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic {
return AppModuleBasic{cdc: cdc}
}
-// Name returns the capability module's name.
+// Name returns the fswap module's name.
func (AppModuleBasic) Name() string {
return types.ModuleName
}
@@ -55,12 +55,12 @@ func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) {
types.RegisterInterfaces(reg)
}
-// DefaultGenesis returns the capability module's default genesis state.
+// DefaultGenesis returns the fswap module's default genesis state.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesis())
}
-// ValidateGenesis performs genesis state validation for the capability module.
+// ValidateGenesis performs genesis state validation for the fswap module.
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error {
var genState types.GenesisState
if err := cdc.UnmarshalJSON(bz, &genState); err != nil {
@@ -74,12 +74,12 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r
// this line is used by starport scaffolding # 2
}
-// GetTxCmd returns the capability module's root tx command.
+// GetTxCmd returns the fswap module's root tx command.
func (a AppModuleBasic) GetTxCmd() *cobra.Command {
return cli.GetTxCmd()
}
-// GetQueryCmd returns the capability module's root query command.
+// GetQueryCmd returns the fswap module's root query command.
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd(types.StoreKey)
}
@@ -88,7 +88,7 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command {
// AppModule
// ----------------------------------------------------------------------------
-// AppModule implements the AppModule interface for the capability module.
+// AppModule implements the AppModule interface for the fswap module.
type AppModule struct {
AppModuleBasic
@@ -111,20 +111,20 @@ func NewAppModule(
}
}
-// Name returns the capability module's name.
+// Name returns the fswap module's name.
func (am AppModule) Name() string {
return am.AppModuleBasic.Name()
}
-// Route returns the capability module's message routing key.
+// Route returns the fswap module's message routing key.
func (am AppModule) Route() sdk.Route {
return sdk.NewRoute(types.RouterKey, NewHandler(am.keeper))
}
-// QuerierRoute returns the capability module's query routing key.
+// QuerierRoute returns the fswap module's query routing key.
func (AppModule) QuerierRoute() string { return types.QuerierRoute }
-// LegacyQuerierHandler returns the capability module's Querier.
+// LegacyQuerierHandler returns the fswap module's Querier.
func (am AppModule) LegacyQuerierHandler(_ *codec.LegacyAmino) sdk.Querier {
return nil
}
@@ -136,10 +136,10 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServer(am.keeper))
}
-// RegisterInvariants registers the capability module's invariants.
+// RegisterInvariants registers the fswap module's invariants.
func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
-// InitGenesis performs the capability module's genesis initialization It returns
+// InitGenesis performs the fswap module's genesis initialization It returns
// no validator updates.
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate {
genState := types.GenesisState{}
@@ -151,7 +151,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.Ra
return []abci.ValidatorUpdate{}
}
-// ExportGenesis returns the capability module's exported genesis state as raw JSON bytes.
+// ExportGenesis returns the fswap module's exported genesis state as raw JSON bytes.
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
genState := am.keeper.ExportGenesis(ctx)
return cdc.MustMarshalJSON(genState)
@@ -160,10 +160,10 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
// ConsensusVersion implements ConsensusVersion.
func (AppModule) ConsensusVersion() uint64 { return 1 }
-// BeginBlock executes all ABCI BeginBlock logic respective to the capability module.
+// BeginBlock executes all ABCI BeginBlock logic respective to the fswap module.
func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}
-// EndBlock executes all ABCI EndBlock logic respective to the capability module. It
+// EndBlock executes all ABCI EndBlock logic respective to the fswap module. It
// returns no validator updates.
func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
return []abci.ValidatorUpdate{}
diff --git a/x/fswap/types/codec.go b/x/fswap/types/codec.go
index bcf91a9869..09ded16639 100644
--- a/x/fswap/types/codec.go
+++ b/x/fswap/types/codec.go
@@ -17,7 +17,7 @@ func RegisterCodec(cdc *codec.LegacyAmino) {
}
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
- cdc.RegisterConcrete(&SwapInitProposal{}, "finschia-sdk/FswapInitProposal", nil)
+ cdc.RegisterConcrete(&SwapProposal{}, "finschia-sdk/SwapProposal", nil)
}
func RegisterInterfaces(registry types.InterfaceRegistry) {
@@ -26,7 +26,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
registry.RegisterImplementations(
(*govtypes.Content)(nil),
- &SwapInitProposal{},
+ &SwapProposal{},
)
}
diff --git a/x/fswap/types/config.go b/x/fswap/types/config.go
new file mode 100644
index 0000000000..071a0cab1f
--- /dev/null
+++ b/x/fswap/types/config.go
@@ -0,0 +1,13 @@
+package types
+
+type Config struct {
+ MaxSwaps int
+ UpdateAllowed bool
+}
+
+func DefaultConfig() Config {
+ return Config{
+ MaxSwaps: 1,
+ UpdateAllowed: false,
+ }
+}
diff --git a/x/fswap/types/errors.go b/x/fswap/types/errors.go
index ba1fe96aff..ee4e52bf1a 100644
--- a/x/fswap/types/errors.go
+++ b/x/fswap/types/errors.go
@@ -8,8 +8,8 @@ import (
// x/fswap module sentinel errors
var (
- ErrSwapNotInitialized = sdkerrors.Register(ModuleName, 1100, "swap not initialized")
- ErrSwapCanNotBeInitializedTwice = sdkerrors.Register(ModuleName, 1101, "swap cannot be initialized twice")
- ErrSwappedNotFound = sdkerrors.Register(ModuleName, 1102, "swapped does not exist")
- ErrExceedSwappableToCoinAmount = sdkerrors.Register(ModuleName, 1103, "exceed swappable to-coin amount")
+ ErrInvalidState = sdkerrors.Register(ModuleName, 1100, "swap module invalid state")
+ ErrCanNotHaveMoreSwap = sdkerrors.Register(ModuleName, 1101, "no more swap allowed")
+ ErrSwappedNotFound = sdkerrors.Register(ModuleName, 1102, "swapped does not exist")
+ ErrExceedSwappableToCoinAmount = sdkerrors.Register(ModuleName, 1103, "exceed swappable to-coin amount")
)
diff --git a/x/fswap/types/fswap.go b/x/fswap/types/fswap.go
index 64f5133060..7692f09af3 100644
--- a/x/fswap/types/fswap.go
+++ b/x/fswap/types/fswap.go
@@ -7,38 +7,45 @@ import (
sdkerrors "github.com/Finschia/finschia-sdk/types/errors"
)
-// NewSwapped creates a new Swapped instance
-func NewSwapped(
- oldCoinAmount sdk.Coin,
- newCoinAmount sdk.Coin,
-) Swapped {
- return Swapped{
- FromCoinAmount: oldCoinAmount,
- ToCoinAmount: newCoinAmount,
+// ValidateBasic validates the set of Swap
+func (s *Swap) ValidateBasic() error {
+ if s.FromDenom == "" {
+ return sdkerrors.ErrInvalidRequest.Wrap("from denomination cannot be empty")
+ }
+ if s.ToDenom == "" {
+ return sdkerrors.ErrInvalidRequest.Wrap("to denomination cannot be empty")
}
+ if s.FromDenom == s.ToDenom {
+ return sdkerrors.ErrInvalidRequest.Wrap("from denomination cannot be equal to to denomination")
+ }
+ if s.AmountCapForToDenom.LT(sdk.OneInt()) {
+ return sdkerrors.ErrInvalidRequest.Wrap("amount cannot be less than one")
+ }
+ if s.SwapMultiple.LT(sdk.OneInt()) {
+ return sdkerrors.ErrInvalidRequest.Wrap("swap multiple cannot be less than one")
+ }
+ return nil
}
-// DefaultSwapped returns an initial Swapped object
-func DefaultSwapped() Swapped {
- return NewSwapped(sdk.Coin{}, sdk.Coin{})
+func (s *Swap) String() string {
+ out, _ := yaml.Marshal(s)
+ return string(out)
}
-func validateCoinAmount(i interface{}) error {
- v, ok := i.(sdk.Coin)
- if !ok {
- return sdkerrors.ErrInvalidCoins.Wrapf("invalid coin amount: %T", i)
- }
- if v.IsNil() {
- return sdkerrors.ErrInvalidCoins.Wrap("coin amount must be not nil")
- }
- if err := v.Validate(); err != nil {
- return sdkerrors.ErrInvalidCoins.Wrap(err.Error())
+func (s *SwapStats) ValidateBasic() error {
+ if s.SwapCount < 0 {
+ return ErrInvalidState.Wrap("swap count cannot be negative")
}
return nil
}
-// Validate validates the set of Swapped
-func (s *Swapped) Validate() error {
+func (s *SwapStats) String() string {
+ out, _ := yaml.Marshal(s)
+ return string(out)
+}
+
+// ValidateBasic validates the set of Swapped
+func (s *Swapped) ValidateBasic() error {
if err := validateCoinAmount(s.FromCoinAmount); err != nil {
return err
}
@@ -48,50 +55,22 @@ func (s *Swapped) Validate() error {
return nil
}
-// String implements the Stringer interface.
-func (s *Swapped) String() string {
- out, _ := yaml.Marshal(s)
- return string(out)
-}
-
-// ValidateBasic validates the set of SwapInit
-func (s *SwapInit) ValidateBasic() error {
- if s.FromDenom == "" {
- return sdkerrors.ErrInvalidRequest.Wrap("from denomination cannot be empty")
- }
- if s.ToDenom == "" {
- return sdkerrors.ErrInvalidRequest.Wrap("to denomination cannot be empty")
- }
- if s.FromDenom == s.ToDenom {
- return sdkerrors.ErrInvalidRequest.Wrap("from denomination cannot be equal to to denomination")
+func validateCoinAmount(i interface{}) error {
+ v, ok := i.(sdk.Coin)
+ if !ok {
+ return sdkerrors.ErrInvalidCoins.Wrapf("invalid coin amount: %T", i)
}
- if s.AmountCapForToDenom.LT(sdk.OneInt()) {
- return sdkerrors.ErrInvalidRequest.Wrap("amount cannot be less than one")
+ if v.IsNil() {
+ return sdkerrors.ErrInvalidCoins.Wrap("coin amount must be not nil")
}
- if s.SwapMultiple.LT(sdk.OneInt()) {
- return sdkerrors.ErrInvalidRequest.Wrap("swap multiple cannot be less than one")
+ if err := v.Validate(); err != nil {
+ return sdkerrors.ErrInvalidCoins.Wrap(err.Error())
}
return nil
}
// String implements the Stringer interface.
-func (s *SwapInit) String() string {
+func (s *Swapped) String() string {
out, _ := yaml.Marshal(s)
return string(out)
}
-
-func (s *SwapInit) IsEmpty() bool {
- if s.FromDenom == "" {
- return true
- }
- if s.ToDenom == "" {
- return true
- }
- if s.AmountCapForToDenom.IsZero() {
- return true
- }
- if s.SwapMultiple.IsZero() {
- return true
- }
- return false
-}
diff --git a/x/fswap/types/fswap.pb.go b/x/fswap/types/fswap.pb.go
index f406f4dc63..edf25acb93 100644
--- a/x/fswap/types/fswap.pb.go
+++ b/x/fswap/types/fswap.pb.go
@@ -25,24 +25,24 @@ var _ = math.Inf
// proto package needs to be updated.
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
-type SwapInit struct {
+type Swap struct {
FromDenom string `protobuf:"bytes,1,opt,name=from_denom,json=fromDenom,proto3" json:"from_denom,omitempty"`
ToDenom string `protobuf:"bytes,2,opt,name=to_denom,json=toDenom,proto3" json:"to_denom,omitempty"`
AmountCapForToDenom github_com_Finschia_finschia_sdk_types.Int `protobuf:"bytes,3,opt,name=amount_cap_for_to_denom,json=amountCapForToDenom,proto3,customtype=github.com/Finschia/finschia-sdk/types.Int" json:"amount_cap_for_to_denom"`
SwapMultiple github_com_Finschia_finschia_sdk_types.Int `protobuf:"bytes,4,opt,name=swap_multiple,json=swapMultiple,proto3,customtype=github.com/Finschia/finschia-sdk/types.Int" json:"swap_multiple"`
}
-func (m *SwapInit) Reset() { *m = SwapInit{} }
-func (*SwapInit) ProtoMessage() {}
-func (*SwapInit) Descriptor() ([]byte, []int) {
+func (m *Swap) Reset() { *m = Swap{} }
+func (*Swap) ProtoMessage() {}
+func (*Swap) Descriptor() ([]byte, []int) {
return fileDescriptor_42ca60eaf37a2b67, []int{0}
}
-func (m *SwapInit) XXX_Unmarshal(b []byte) error {
+func (m *Swap) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
-func (m *SwapInit) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+func (m *Swap) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
- return xxx_messageInfo_SwapInit.Marshal(b, m, deterministic)
+ return xxx_messageInfo_Swap.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
@@ -52,50 +52,93 @@ func (m *SwapInit) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return b[:n], nil
}
}
-func (m *SwapInit) XXX_Merge(src proto.Message) {
- xxx_messageInfo_SwapInit.Merge(m, src)
+func (m *Swap) XXX_Merge(src proto.Message) {
+ xxx_messageInfo_Swap.Merge(m, src)
}
-func (m *SwapInit) XXX_Size() int {
+func (m *Swap) XXX_Size() int {
return m.Size()
}
-func (m *SwapInit) XXX_DiscardUnknown() {
- xxx_messageInfo_SwapInit.DiscardUnknown(m)
+func (m *Swap) XXX_DiscardUnknown() {
+ xxx_messageInfo_Swap.DiscardUnknown(m)
}
-var xxx_messageInfo_SwapInit proto.InternalMessageInfo
+var xxx_messageInfo_Swap proto.InternalMessageInfo
-func (m *SwapInit) GetFromDenom() string {
+func (m *Swap) GetFromDenom() string {
if m != nil {
return m.FromDenom
}
return ""
}
-func (m *SwapInit) GetToDenom() string {
+func (m *Swap) GetToDenom() string {
if m != nil {
return m.ToDenom
}
return ""
}
-// From cosmos-sdk 0.46.0 they deprecated this way, but currently finschia-sdk based on 0.45.10
-type SwapInitProposal struct {
- Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"`
- Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"`
- SwapInit SwapInit `protobuf:"bytes,3,opt,name=swap_init,json=swapInit,proto3" json:"swap_init"`
+type SwapStats struct {
+ SwapCount int32 `protobuf:"varint,1,opt,name=swap_count,json=swapCount,proto3" json:"swap_count,omitempty"`
}
-func (m *SwapInitProposal) Reset() { *m = SwapInitProposal{} }
-func (*SwapInitProposal) ProtoMessage() {}
-func (*SwapInitProposal) Descriptor() ([]byte, []int) {
+func (m *SwapStats) Reset() { *m = SwapStats{} }
+func (*SwapStats) ProtoMessage() {}
+func (*SwapStats) Descriptor() ([]byte, []int) {
return fileDescriptor_42ca60eaf37a2b67, []int{1}
}
-func (m *SwapInitProposal) XXX_Unmarshal(b []byte) error {
+func (m *SwapStats) XXX_Unmarshal(b []byte) error {
+ return m.Unmarshal(b)
+}
+func (m *SwapStats) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+ if deterministic {
+ return xxx_messageInfo_SwapStats.Marshal(b, m, deterministic)
+ } else {
+ b = b[:cap(b)]
+ n, err := m.MarshalToSizedBuffer(b)
+ if err != nil {
+ return nil, err
+ }
+ return b[:n], nil
+ }
+}
+func (m *SwapStats) XXX_Merge(src proto.Message) {
+ xxx_messageInfo_SwapStats.Merge(m, src)
+}
+func (m *SwapStats) XXX_Size() int {
+ return m.Size()
+}
+func (m *SwapStats) XXX_DiscardUnknown() {
+ xxx_messageInfo_SwapStats.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_SwapStats proto.InternalMessageInfo
+
+func (m *SwapStats) GetSwapCount() int32 {
+ if m != nil {
+ return m.SwapCount
+ }
+ return 0
+}
+
+// From cosmos-sdk 0.46.0 they deprecated this way, but currently finschia-sdk based on 0.45.10
+type SwapProposal struct {
+ Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"`
+ Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"`
+ Swap Swap `protobuf:"bytes,3,opt,name=swap,proto3" json:"swap"`
+}
+
+func (m *SwapProposal) Reset() { *m = SwapProposal{} }
+func (*SwapProposal) ProtoMessage() {}
+func (*SwapProposal) Descriptor() ([]byte, []int) {
+ return fileDescriptor_42ca60eaf37a2b67, []int{2}
+}
+func (m *SwapProposal) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
-func (m *SwapInitProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+func (m *SwapProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
- return xxx_messageInfo_SwapInitProposal.Marshal(b, m, deterministic)
+ return xxx_messageInfo_SwapProposal.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
@@ -105,37 +148,37 @@ func (m *SwapInitProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, er
return b[:n], nil
}
}
-func (m *SwapInitProposal) XXX_Merge(src proto.Message) {
- xxx_messageInfo_SwapInitProposal.Merge(m, src)
+func (m *SwapProposal) XXX_Merge(src proto.Message) {
+ xxx_messageInfo_SwapProposal.Merge(m, src)
}
-func (m *SwapInitProposal) XXX_Size() int {
+func (m *SwapProposal) XXX_Size() int {
return m.Size()
}
-func (m *SwapInitProposal) XXX_DiscardUnknown() {
- xxx_messageInfo_SwapInitProposal.DiscardUnknown(m)
+func (m *SwapProposal) XXX_DiscardUnknown() {
+ xxx_messageInfo_SwapProposal.DiscardUnknown(m)
}
-var xxx_messageInfo_SwapInitProposal proto.InternalMessageInfo
+var xxx_messageInfo_SwapProposal proto.InternalMessageInfo
-func (m *SwapInitProposal) GetTitle() string {
+func (m *SwapProposal) GetTitle() string {
if m != nil {
return m.Title
}
return ""
}
-func (m *SwapInitProposal) GetDescription() string {
+func (m *SwapProposal) GetDescription() string {
if m != nil {
return m.Description
}
return ""
}
-func (m *SwapInitProposal) GetSwapInit() SwapInit {
+func (m *SwapProposal) GetSwap() Swap {
if m != nil {
- return m.SwapInit
+ return m.Swap
}
- return SwapInit{}
+ return Swap{}
}
type Swapped struct {
@@ -146,7 +189,7 @@ type Swapped struct {
func (m *Swapped) Reset() { *m = Swapped{} }
func (*Swapped) ProtoMessage() {}
func (*Swapped) Descriptor() ([]byte, []int) {
- return fileDescriptor_42ca60eaf37a2b67, []int{2}
+ return fileDescriptor_42ca60eaf37a2b67, []int{3}
}
func (m *Swapped) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
@@ -190,55 +233,57 @@ func (m *Swapped) GetToCoinAmount() types.Coin {
}
func init() {
- proto.RegisterType((*SwapInit)(nil), "lbm.fswap.v1.SwapInit")
- proto.RegisterType((*SwapInitProposal)(nil), "lbm.fswap.v1.SwapInitProposal")
+ proto.RegisterType((*Swap)(nil), "lbm.fswap.v1.Swap")
+ proto.RegisterType((*SwapStats)(nil), "lbm.fswap.v1.SwapStats")
+ proto.RegisterType((*SwapProposal)(nil), "lbm.fswap.v1.SwapProposal")
proto.RegisterType((*Swapped)(nil), "lbm.fswap.v1.Swapped")
}
func init() { proto.RegisterFile("lbm/fswap/v1/fswap.proto", fileDescriptor_42ca60eaf37a2b67) }
var fileDescriptor_42ca60eaf37a2b67 = []byte{
- // 465 bytes of a gzipped FileDescriptorProto
- 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x53, 0x3d, 0x6f, 0x13, 0x41,
- 0x10, 0xf5, 0x19, 0x43, 0xec, 0xb5, 0x89, 0xa2, 0x23, 0x02, 0x27, 0x12, 0x77, 0x51, 0x2a, 0x04,
- 0x62, 0x57, 0x76, 0x2a, 0xd2, 0xe1, 0xa0, 0x88, 0x14, 0x48, 0xc8, 0x20, 0x21, 0xd1, 0x9c, 0xf6,
- 0xce, 0x67, 0x7b, 0xc5, 0xdd, 0xce, 0xea, 0x76, 0xec, 0x84, 0x5f, 0x01, 0x74, 0x94, 0xa9, 0xf9,
- 0x25, 0x29, 0x53, 0x22, 0x8a, 0x80, 0xec, 0x86, 0x7f, 0x01, 0xda, 0x8f, 0x80, 0xa9, 0x40, 0x48,
- 0xe9, 0x66, 0xe7, 0xcd, 0xbd, 0x37, 0xfb, 0xde, 0x2d, 0xe9, 0x16, 0x69, 0xc9, 0xc6, 0xfa, 0x98,
- 0x2b, 0x36, 0xef, 0xb9, 0x82, 0xaa, 0x0a, 0x10, 0xc2, 0x4e, 0x91, 0x96, 0xd4, 0x35, 0xe6, 0xbd,
- 0xed, 0xcd, 0x09, 0x4c, 0xc0, 0x02, 0xcc, 0x54, 0x6e, 0x66, 0x3b, 0xca, 0x40, 0x97, 0xa0, 0x59,
- 0xca, 0x75, 0xce, 0xe6, 0xbd, 0x34,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 0xb0, 0xcb,
+ 0xdc, 0x32, 0x30, 0x5c, 0x06, 0xd6, 0x2c, 0x03, 0x1b, 0x81, 0xac, 0x86, 0x87, 0x28, 0xfb, 0xe1,
+ 0x73, 0x74, 0xf7, 0x0f, 0x23, 0xc4, 0x43, 0xf1, 0x36, 0xfa, 0x60, 0xf5, 0xd0, 0xba, 0x50, 0x43,
+ 0xb6, 0x0d, 0xfc, 0xe2, 0xdb, 0xfa, 0x27, 0xbe, 0x5d, 0x03, 0x3f, 0x5d, 0x8f, 0x02, 0x4c, 0x61,
+ 0xf8, 0xf8, 0x62, 0x19, 0xfa, 0x97, 0xcb, 0xd0, 0xff, 0xb2, 0x0c, 0xfd, 0x77, 0xab, 0xd0, 0xbb,
+ 0x5c, 0x85, 0xde, 0xc7, 0x55, 0xe8, 0xbd, 0x64, 0xbf, 0x95, 0x3e, 0x6b, 0x9e, 0x97, 0xb5, 0x48,
+ 0xff, 0xb7, 0x0f, 0xe3, 0xf0, 0x7b, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9a, 0x24, 0xaa, 0x02, 0x78,
+ 0x03, 0x00, 0x00,
}
-func (this *SwapInit) Equal(that interface{}) bool {
+func (this *Swap) Equal(that interface{}) bool {
if that == nil {
return this == nil
}
- that1, ok := that.(*SwapInit)
+ that1, ok := that.(*Swap)
if !ok {
- that2, ok := that.(SwapInit)
+ that2, ok := that.(Swap)
if ok {
that1 = &that2
} else {
@@ -264,14 +309,38 @@ func (this *SwapInit) Equal(that interface{}) bool {
}
return true
}
-func (this *SwapInitProposal) Equal(that interface{}) bool {
+func (this *SwapStats) Equal(that interface{}) bool {
if that == nil {
return this == nil
}
- that1, ok := that.(*SwapInitProposal)
+ that1, ok := that.(*SwapStats)
if !ok {
- that2, ok := that.(SwapInitProposal)
+ that2, ok := that.(SwapStats)
+ if ok {
+ that1 = &that2
+ } else {
+ return false
+ }
+ }
+ if that1 == nil {
+ return this == nil
+ } else if this == nil {
+ return false
+ }
+ if this.SwapCount != that1.SwapCount {
+ return false
+ }
+ return true
+}
+func (this *SwapProposal) Equal(that interface{}) bool {
+ if that == nil {
+ return this == nil
+ }
+
+ that1, ok := that.(*SwapProposal)
+ if !ok {
+ that2, ok := that.(SwapProposal)
if ok {
that1 = &that2
} else {
@@ -289,12 +358,12 @@ func (this *SwapInitProposal) Equal(that interface{}) bool {
if this.Description != that1.Description {
return false
}
- if !this.SwapInit.Equal(&that1.SwapInit) {
+ if !this.Swap.Equal(&that1.Swap) {
return false
}
return true
}
-func (m *SwapInit) Marshal() (dAtA []byte, err error) {
+func (m *Swap) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
@@ -304,12 +373,12 @@ func (m *SwapInit) Marshal() (dAtA []byte, err error) {
return dAtA[:n], nil
}
-func (m *SwapInit) MarshalTo(dAtA []byte) (int, error) {
+func (m *Swap) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
-func (m *SwapInit) MarshalToSizedBuffer(dAtA []byte) (int, error) {
+func (m *Swap) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
@@ -351,7 +420,35 @@ func (m *SwapInit) MarshalToSizedBuffer(dAtA []byte) (int, error) {
return len(dAtA) - i, nil
}
-func (m *SwapInitProposal) Marshal() (dAtA []byte, err error) {
+func (m *SwapStats) Marshal() (dAtA []byte, err error) {
+ size := m.Size()
+ dAtA = make([]byte, size)
+ n, err := m.MarshalToSizedBuffer(dAtA[:size])
+ if err != nil {
+ return nil, err
+ }
+ return dAtA[:n], nil
+}
+
+func (m *SwapStats) MarshalTo(dAtA []byte) (int, error) {
+ size := m.Size()
+ return m.MarshalToSizedBuffer(dAtA[:size])
+}
+
+func (m *SwapStats) MarshalToSizedBuffer(dAtA []byte) (int, error) {
+ i := len(dAtA)
+ _ = i
+ var l int
+ _ = l
+ if m.SwapCount != 0 {
+ i = encodeVarintFswap(dAtA, i, uint64(m.SwapCount))
+ i--
+ dAtA[i] = 0x8
+ }
+ return len(dAtA) - i, nil
+}
+
+func (m *SwapProposal) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
@@ -361,18 +458,18 @@ func (m *SwapInitProposal) Marshal() (dAtA []byte, err error) {
return dAtA[:n], nil
}
-func (m *SwapInitProposal) MarshalTo(dAtA []byte) (int, error) {
+func (m *SwapProposal) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
-func (m *SwapInitProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) {
+func (m *SwapProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
{
- size, err := m.SwapInit.MarshalToSizedBuffer(dAtA[:i])
+ size, err := m.Swap.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
@@ -452,7 +549,7 @@ func encodeVarintFswap(dAtA []byte, offset int, v uint64) int {
dAtA[offset] = uint8(v)
return base
}
-func (m *SwapInit) Size() (n int) {
+func (m *Swap) Size() (n int) {
if m == nil {
return 0
}
@@ -473,7 +570,19 @@ func (m *SwapInit) Size() (n int) {
return n
}
-func (m *SwapInitProposal) Size() (n int) {
+func (m *SwapStats) Size() (n int) {
+ if m == nil {
+ return 0
+ }
+ var l int
+ _ = l
+ if m.SwapCount != 0 {
+ n += 1 + sovFswap(uint64(m.SwapCount))
+ }
+ return n
+}
+
+func (m *SwapProposal) Size() (n int) {
if m == nil {
return 0
}
@@ -487,7 +596,7 @@ func (m *SwapInitProposal) Size() (n int) {
if l > 0 {
n += 1 + l + sovFswap(uint64(l))
}
- l = m.SwapInit.Size()
+ l = m.Swap.Size()
n += 1 + l + sovFswap(uint64(l))
return n
}
@@ -511,7 +620,7 @@ func sovFswap(x uint64) (n int) {
func sozFswap(x uint64) (n int) {
return sovFswap(uint64((x << 1) ^ uint64((int64(x) >> 63))))
}
-func (m *SwapInit) Unmarshal(dAtA []byte) error {
+func (m *Swap) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
@@ -534,10 +643,10 @@ func (m *SwapInit) Unmarshal(dAtA []byte) error {
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
- return fmt.Errorf("proto: SwapInit: wiretype end group for non-group")
+ return fmt.Errorf("proto: Swap: wiretype end group for non-group")
}
if fieldNum <= 0 {
- return fmt.Errorf("proto: SwapInit: illegal tag %d (wire type %d)", fieldNum, wire)
+ return fmt.Errorf("proto: Swap: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
@@ -693,7 +802,76 @@ func (m *SwapInit) Unmarshal(dAtA []byte) error {
}
return nil
}
-func (m *SwapInitProposal) Unmarshal(dAtA []byte) error {
+func (m *SwapStats) Unmarshal(dAtA []byte) error {
+ l := len(dAtA)
+ iNdEx := 0
+ for iNdEx < l {
+ preIndex := iNdEx
+ var wire uint64
+ for shift := uint(0); ; shift += 7 {
+ if shift >= 64 {
+ return ErrIntOverflowFswap
+ }
+ if iNdEx >= l {
+ return io.ErrUnexpectedEOF
+ }
+ b := dAtA[iNdEx]
+ iNdEx++
+ wire |= uint64(b&0x7F) << shift
+ if b < 0x80 {
+ break
+ }
+ }
+ fieldNum := int32(wire >> 3)
+ wireType := int(wire & 0x7)
+ if wireType == 4 {
+ return fmt.Errorf("proto: SwapStats: wiretype end group for non-group")
+ }
+ if fieldNum <= 0 {
+ return fmt.Errorf("proto: SwapStats: illegal tag %d (wire type %d)", fieldNum, wire)
+ }
+ switch fieldNum {
+ case 1:
+ if wireType != 0 {
+ return fmt.Errorf("proto: wrong wireType = %d for field SwapCount", wireType)
+ }
+ m.SwapCount = 0
+ for shift := uint(0); ; shift += 7 {
+ if shift >= 64 {
+ return ErrIntOverflowFswap
+ }
+ if iNdEx >= l {
+ return io.ErrUnexpectedEOF
+ }
+ b := dAtA[iNdEx]
+ iNdEx++
+ m.SwapCount |= int32(b&0x7F) << shift
+ if b < 0x80 {
+ break
+ }
+ }
+ default:
+ iNdEx = preIndex
+ skippy, err := skipFswap(dAtA[iNdEx:])
+ if err != nil {
+ return err
+ }
+ if (skippy < 0) || (iNdEx+skippy) < 0 {
+ return ErrInvalidLengthFswap
+ }
+ if (iNdEx + skippy) > l {
+ return io.ErrUnexpectedEOF
+ }
+ iNdEx += skippy
+ }
+ }
+
+ if iNdEx > l {
+ return io.ErrUnexpectedEOF
+ }
+ return nil
+}
+func (m *SwapProposal) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
@@ -716,10 +894,10 @@ func (m *SwapInitProposal) Unmarshal(dAtA []byte) error {
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
- return fmt.Errorf("proto: SwapInitProposal: wiretype end group for non-group")
+ return fmt.Errorf("proto: SwapProposal: wiretype end group for non-group")
}
if fieldNum <= 0 {
- return fmt.Errorf("proto: SwapInitProposal: illegal tag %d (wire type %d)", fieldNum, wire)
+ return fmt.Errorf("proto: SwapProposal: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
@@ -788,7 +966,7 @@ func (m *SwapInitProposal) Unmarshal(dAtA []byte) error {
iNdEx = postIndex
case 3:
if wireType != 2 {
- return fmt.Errorf("proto: wrong wireType = %d for field SwapInit", wireType)
+ return fmt.Errorf("proto: wrong wireType = %d for field Swap", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
@@ -815,7 +993,7 @@ func (m *SwapInitProposal) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
- if err := m.SwapInit.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
+ if err := m.Swap.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
diff --git a/x/fswap/types/genesis.go b/x/fswap/types/genesis.go
index 624a54ce5d..2c2d4c2ab0 100644
--- a/x/fswap/types/genesis.go
+++ b/x/fswap/types/genesis.go
@@ -1,41 +1,30 @@
package types
-import (
- sdkerrors "github.com/Finschia/finschia-sdk/types/errors"
-)
-
// DefaultGenesis returns the default Capability genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{
- SwapInit: []SwapInit{},
- Swapped: []Swapped{},
+ Swaps: []Swap{},
+ SwapStats: SwapStats{},
+ Swappeds: []Swapped{},
}
}
-// Validate performs basic genesis state validation returning an error upon any
-// failure.
-// need confirm: should we validate? Since it may nil
-func (gs GenesisState) Validate() error {
- if len(gs.GetSwapInit()) == 0 && len(gs.GetSwapped()) == 0 {
- return nil
- }
- if len(gs.GetSwapInit()) > 1 {
- return sdkerrors.Wrap(ErrSwapCanNotBeInitializedTwice, "cannot have more than one swapInit")
- }
- if len(gs.GetSwapped()) > 1 {
- return sdkerrors.Wrap(ErrSwapCanNotBeInitializedTwice, "cannot have more than one swapped")
+// Validate performs basic genesis state validation returning an error upon any failure.
+func (gs *GenesisState) Validate() error {
+ for _, swap := range gs.GetSwaps() {
+ if err := swap.ValidateBasic(); err != nil {
+ return err
+ }
}
- swapInit := gs.GetSwapInit()[0]
- if err := swapInit.ValidateBasic(); err != nil {
- return err
- }
- swapped := gs.GetSwapped()[0]
- if err := swapped.Validate(); err != nil {
+
+ if err := gs.SwapStats.ValidateBasic(); err != nil {
return err
}
- if swapInit.AmountCapForToDenom.LT(swapped.GetToCoinAmount().Amount) {
- return ErrExceedSwappableToCoinAmount
+ for _, swapped := range gs.GetSwappeds() {
+ if err := swapped.ValidateBasic(); err != nil {
+ return err
+ }
}
return nil
}
diff --git a/x/fswap/types/genesis.pb.go b/x/fswap/types/genesis.pb.go
index 9846807217..89415e9484 100644
--- a/x/fswap/types/genesis.pb.go
+++ b/x/fswap/types/genesis.pb.go
@@ -25,8 +25,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
// GenesisState defines the fswap module's genesis state.
type GenesisState struct {
- SwapInit []SwapInit `protobuf:"bytes,1,rep,name=swap_init,json=swapInit,proto3" json:"swap_init"`
- Swapped []Swapped `protobuf:"bytes,2,rep,name=swapped,proto3" json:"swapped"`
+ Swaps []Swap `protobuf:"bytes,1,rep,name=swaps,proto3" json:"swaps"`
+ SwapStats SwapStats `protobuf:"bytes,2,opt,name=swap_stats,json=swapStats,proto3" json:"swap_stats"`
+ Swappeds []Swapped `protobuf:"bytes,3,rep,name=swappeds,proto3" json:"swappeds"`
}
func (m *GenesisState) Reset() { *m = GenesisState{} }
@@ -62,16 +63,23 @@ func (m *GenesisState) XXX_DiscardUnknown() {
var xxx_messageInfo_GenesisState proto.InternalMessageInfo
-func (m *GenesisState) GetSwapInit() []SwapInit {
+func (m *GenesisState) GetSwaps() []Swap {
if m != nil {
- return m.SwapInit
+ return m.Swaps
}
return nil
}
-func (m *GenesisState) GetSwapped() []Swapped {
+func (m *GenesisState) GetSwapStats() SwapStats {
if m != nil {
- return m.Swapped
+ return m.SwapStats
+ }
+ return SwapStats{}
+}
+
+func (m *GenesisState) GetSwappeds() []Swapped {
+ if m != nil {
+ return m.Swappeds
}
return nil
}
@@ -83,22 +91,23 @@ func init() {
func init() { proto.RegisterFile("lbm/fswap/v1/genesis.proto", fileDescriptor_94e309cb1db27661) }
var fileDescriptor_94e309cb1db27661 = []byte{
- // 232 bytes of a gzipped FileDescriptorProto
+ // 255 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xca, 0x49, 0xca, 0xd5,
0x4f, 0x2b, 0x2e, 0x4f, 0x2c, 0xd0, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c,
0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0xc9, 0x49, 0xca, 0xd5, 0x03, 0xcb, 0xe9, 0x95,
0x19, 0x4a, 0x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ff, 0x4f, 0x1a, 0xa2, 0xb3, 0x64, 0x01, 0x00, 0x00,
}
func (m *GenesisState) Marshal() (dAtA []byte, err error) {
@@ -121,10 +130,10 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) {
_ = i
var l int
_ = l
- if len(m.Swapped) > 0 {
- for iNdEx := len(m.Swapped) - 1; iNdEx >= 0; iNdEx-- {
+ if len(m.Swappeds) > 0 {
+ for iNdEx := len(m.Swappeds) - 1; iNdEx >= 0; iNdEx-- {
{
- size, err := m.Swapped[iNdEx].MarshalToSizedBuffer(dAtA[:i])
+ size, err := m.Swappeds[iNdEx].MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
@@ -132,13 +141,23 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i = encodeVarintGenesis(dAtA, i, uint64(size))
}
i--
- dAtA[i] = 0x12
+ dAtA[i] = 0x1a
+ }
+ }
+ {
+ size, err := m.SwapStats.MarshalToSizedBuffer(dAtA[:i])
+ if err != nil {
+ return 0, err
}
+ i -= size
+ i = encodeVarintGenesis(dAtA, i, uint64(size))
}
- if len(m.SwapInit) > 0 {
- for iNdEx := len(m.SwapInit) - 1; iNdEx >= 0; iNdEx-- {
+ i--
+ dAtA[i] = 0x12
+ if len(m.Swaps) > 0 {
+ for iNdEx := len(m.Swaps) - 1; iNdEx >= 0; iNdEx-- {
{
- size, err := m.SwapInit[iNdEx].MarshalToSizedBuffer(dAtA[:i])
+ size, err := m.Swaps[iNdEx].MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
@@ -169,14 +188,16 @@ func (m *GenesisState) Size() (n int) {
}
var l int
_ = l
- if len(m.SwapInit) > 0 {
- for _, e := range m.SwapInit {
+ if len(m.Swaps) > 0 {
+ for _, e := range m.Swaps {
l = e.Size()
n += 1 + l + sovGenesis(uint64(l))
}
}
- if len(m.Swapped) > 0 {
- for _, e := range m.Swapped {
+ l = m.SwapStats.Size()
+ n += 1 + l + sovGenesis(uint64(l))
+ if len(m.Swappeds) > 0 {
+ for _, e := range m.Swappeds {
l = e.Size()
n += 1 + l + sovGenesis(uint64(l))
}
@@ -221,7 +242,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error {
switch fieldNum {
case 1:
if wireType != 2 {
- return fmt.Errorf("proto: wrong wireType = %d for field SwapInit", wireType)
+ return fmt.Errorf("proto: wrong wireType = %d for field Swaps", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
@@ -248,14 +269,47 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
- m.SwapInit = append(m.SwapInit, SwapInit{})
- if err := m.SwapInit[len(m.SwapInit)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
+ m.Swaps = append(m.Swaps, Swap{})
+ if err := m.Swaps[len(m.Swaps)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 2:
if wireType != 2 {
- return fmt.Errorf("proto: wrong wireType = %d for field Swapped", wireType)
+ return fmt.Errorf("proto: wrong wireType = %d for field SwapStats", wireType)
+ }
+ var msglen int
+ for shift := uint(0); ; shift += 7 {
+ if shift >= 64 {
+ return ErrIntOverflowGenesis
+ }
+ if iNdEx >= l {
+ return io.ErrUnexpectedEOF
+ }
+ b := dAtA[iNdEx]
+ iNdEx++
+ msglen |= int(b&0x7F) << shift
+ if b < 0x80 {
+ break
+ }
+ }
+ if msglen < 0 {
+ return ErrInvalidLengthGenesis
+ }
+ postIndex := iNdEx + msglen
+ if postIndex < 0 {
+ return ErrInvalidLengthGenesis
+ }
+ if postIndex > l {
+ return io.ErrUnexpectedEOF
+ }
+ if err := m.SwapStats.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
+ return err
+ }
+ iNdEx = postIndex
+ case 3:
+ if wireType != 2 {
+ return fmt.Errorf("proto: wrong wireType = %d for field Swappeds", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
@@ -282,8 +336,8 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
- m.Swapped = append(m.Swapped, Swapped{})
- if err := m.Swapped[len(m.Swapped)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
+ m.Swappeds = append(m.Swappeds, Swapped{})
+ if err := m.Swappeds[len(m.Swappeds)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
diff --git a/x/fswap/types/proposal.go b/x/fswap/types/proposal.go
index c90c190d36..302d7e98c2 100644
--- a/x/fswap/types/proposal.go
+++ b/x/fswap/types/proposal.go
@@ -7,38 +7,38 @@ import (
)
const (
- ProposalTypeSwapInit string = "SwapInit"
+ ProposalTypeSwap string = "Swap"
)
-// NewSwapInitProposal creates a new SwapInitProposal instance.
+// NewSwapProposal creates a new SwapProposal instance.
// Deprecated: this proposal is considered legacy and is deprecated in favor of
-// Msg-based gov proposals. See MsgSwapInit.
-func NewSwapInitProposal(title, description string, swapInit SwapInit) *SwapInitProposal {
- return &SwapInitProposal{title, description, swapInit}
+// Msg-based gov proposals. See MsgSwap.
+func NewSwapProposal(title, description string, swap Swap) *SwapProposal {
+ return &SwapProposal{title, description, swap}
}
// Implements Proposal Interface
-var _ gov.Content = &SwapInitProposal{}
+var _ gov.Content = &SwapProposal{}
func init() {
- gov.RegisterProposalType(ProposalTypeSwapInit)
+ gov.RegisterProposalType(ProposalTypeSwap)
}
// ProposalRoute gets the proposal's router key
-func (m *SwapInitProposal) ProposalRoute() string { return RouterKey }
+func (m *SwapProposal) ProposalRoute() string { return RouterKey }
-// ProposalType is "SwapInit"
-func (m *SwapInitProposal) ProposalType() string { return ProposalTypeSwapInit }
+// ProposalType is "Swap"
+func (m *SwapProposal) ProposalType() string { return ProposalTypeSwap }
// String implements the Stringer interface.
-func (m *SwapInitProposal) String() string {
+func (m *SwapProposal) String() string {
out, _ := yaml.Marshal(m)
return string(out)
}
// ValidateBasic validates the proposal
-func (m *SwapInitProposal) ValidateBasic() error {
- if err := m.SwapInit.ValidateBasic(); err != nil {
+func (m *SwapProposal) ValidateBasic() error {
+ if err := m.Swap.ValidateBasic(); err != nil {
return err
}
return gov.ValidateAbstract(m)
diff --git a/x/fswap/types/query.pb.go b/x/fswap/types/query.pb.go
index 4a13541bf4..286ad93a32 100644
--- a/x/fswap/types/query.pb.go
+++ b/x/fswap/types/query.pb.go
@@ -31,6 +31,8 @@ var _ = math.Inf
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
type QuerySwappedRequest struct {
+ FromDenom string `protobuf:"bytes,1,opt,name=fromDenom,proto3" json:"fromDenom,omitempty"`
+ ToDenom string `protobuf:"bytes,2,opt,name=toDenom,proto3" json:"toDenom,omitempty"`
}
func (m *QuerySwappedRequest) Reset() { *m = QuerySwappedRequest{} }
@@ -66,6 +68,20 @@ func (m *QuerySwappedRequest) XXX_DiscardUnknown() {
var xxx_messageInfo_QuerySwappedRequest proto.InternalMessageInfo
+func (m *QuerySwappedRequest) GetFromDenom() string {
+ if m != nil {
+ return m.FromDenom
+ }
+ return ""
+}
+
+func (m *QuerySwappedRequest) GetToDenom() string {
+ if m != nil {
+ return m.ToDenom
+ }
+ return ""
+}
+
type QuerySwappedResponse struct {
FromCoinAmount types.Coin `protobuf:"bytes,1,opt,name=from_coin_amount,json=fromCoinAmount,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"from_coin_amount"`
ToCoinAmount types.Coin `protobuf:"bytes,2,opt,name=to_coin_amount,json=toCoinAmount,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"to_coin_amount"`
@@ -119,6 +135,8 @@ func (m *QuerySwappedResponse) GetToCoinAmount() types.Coin {
}
type QueryTotalSwappableToCoinAmountRequest struct {
+ FromDenom string `protobuf:"bytes,1,opt,name=fromDenom,proto3" json:"fromDenom,omitempty"`
+ ToDenom string `protobuf:"bytes,2,opt,name=toDenom,proto3" json:"toDenom,omitempty"`
}
func (m *QueryTotalSwappableToCoinAmountRequest) Reset() {
@@ -156,6 +174,20 @@ func (m *QueryTotalSwappableToCoinAmountRequest) XXX_DiscardUnknown() {
var xxx_messageInfo_QueryTotalSwappableToCoinAmountRequest proto.InternalMessageInfo
+func (m *QueryTotalSwappableToCoinAmountRequest) GetFromDenom() string {
+ if m != nil {
+ return m.FromDenom
+ }
+ return ""
+}
+
+func (m *QueryTotalSwappableToCoinAmountRequest) GetToDenom() string {
+ if m != nil {
+ return m.ToDenom
+ }
+ return ""
+}
+
type QueryTotalSwappableToCoinAmountResponse struct {
SwappableAmount types.Coin `protobuf:"bytes,1,opt,name=swappable_amount,json=swappableAmount,proto3,castrepeated=github.com/Finschia/finschia-sdk/types.Coin" json:"swappable_amount"`
}
@@ -212,35 +244,37 @@ func init() {
func init() { proto.RegisterFile("lbm/fswap/v1/query.proto", fileDescriptor_01deae9da7816d6a) }
var fileDescriptor_01deae9da7816d6a = []byte{
- // 446 bytes of a gzipped FileDescriptorProto
- 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0xbf, 0x8e, 0xd3, 0x40,
- 0x10, 0xc6, 0x6d, 0x4b, 0x80, 0xb4, 0x9c, 0x8e, 0xd3, 0x72, 0x27, 0x0e, 0x0b, 0x7c, 0xe0, 0x02,
- 0x4e, 0x02, 0x76, 0xe5, 0xbb, 0xe3, 0x01, 0x08, 0x12, 0xa2, 0x25, 0xa4, 0xa2, 0x89, 0xd6, 0xce,
- 0xc6, 0xb1, 0xb0, 0x77, 0x9c, 0xec, 0x3a, 0x7f, 0x5a, 0x0a, 0x6a, 0x24, 0x5e, 0x81, 0x8a, 0x47,
- 0xa0, 0xa1, 0x4d, 0x19, 0x89, 0x86, 0x0a, 0x50, 0xc2, 0x83, 0x20, 0xaf, 0x37, 0x24, 0x96, 0x02,
- 0xd1, 0x15, 0xe9, 0x46, 0x3b, 0xdf, 0xe4,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17, 0x8c, 0x4c, 0x0c, 0x68, 0xc5, 0x6e, 0x05, 0xbe, 0x45, 0x66, 0x57, 0x9e, 0xcc, 0xd9,
+ 0x40, 0x3f, 0xfc, 0x57, 0x49, 0xfd, 0x5b, 0xe1, 0x8d, 0xb7, 0x5f, 0x7f, 0x7d, 0xf0, 0xae, 0xe1,
+ 0xab, 0xb4, 0xb1, 0xdf, 0xd2, 0x52, 0xbe, 0xb8, 0xc8, 0xff, 0xbb, 0x39, 0x78, 0x6f, 0x0e, 0x61,
+ 0xe1, 0xb8, 0xfc, 0x87, 0xff, 0xd9, 0x65, 0xa5, 0xee, 0x19, 0xa9, 0x04, 0xdf, 0x6f, 0x4a, 0x55,
+ 0xba, 0xb3, 0x33, 0x9d, 0x4d, 0x73, 0x53, 0xf7, 0x9f, 0x9d, 0x8d, 0x02, 0x77, 0x38, 0x0a, 0xdc,
+ 0x9f, 0xa3, 0xc0, 0x7d, 0x3f, 0x0e, 0x9c, 0xe1, 0x38, 0x70, 0xbe, 0x8d, 0x03, 0xe7, 0x15, 0x59,
+ 0x38, 0x94, 0x53, 0x4b, 0x31, 0xc3, 0x89, 0x2f, 0x9a, 0xe7, 0xbe, 0xfb, 0x3b, 0x00, 0x00, 0xff,
+ 0xff, 0x4e, 0x71, 0x07, 0xdd, 0x86, 0x04, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
@@ -385,6 +419,20 @@ func (m *QuerySwappedRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) {
_ = i
var l int
_ = l
+ if len(m.ToDenom) > 0 {
+ i -= len(m.ToDenom)
+ copy(dAtA[i:], m.ToDenom)
+ i = encodeVarintQuery(dAtA, i, uint64(len(m.ToDenom)))
+ i--
+ dAtA[i] = 0x12
+ }
+ if len(m.FromDenom) > 0 {
+ i -= len(m.FromDenom)
+ copy(dAtA[i:], m.FromDenom)
+ i = encodeVarintQuery(dAtA, i, uint64(len(m.FromDenom)))
+ i--
+ dAtA[i] = 0xa
+ }
return len(dAtA) - i, nil
}
@@ -451,6 +499,20 @@ func (m *QueryTotalSwappableToCoinAmountRequest) MarshalToSizedBuffer(dAtA []byt
_ = i
var l int
_ = l
+ if len(m.ToDenom) > 0 {
+ i -= len(m.ToDenom)
+ copy(dAtA[i:], m.ToDenom)
+ i = encodeVarintQuery(dAtA, i, uint64(len(m.ToDenom)))
+ i--
+ dAtA[i] = 0x12
+ }
+ if len(m.FromDenom) > 0 {
+ i -= len(m.FromDenom)
+ copy(dAtA[i:], m.FromDenom)
+ i = encodeVarintQuery(dAtA, i, uint64(len(m.FromDenom)))
+ i--
+ dAtA[i] = 0xa
+ }
return len(dAtA) - i, nil
}
@@ -504,6 +566,14 @@ func (m *QuerySwappedRequest) Size() (n int) {
}
var l int
_ = l
+ l = len(m.FromDenom)
+ if l > 0 {
+ n += 1 + l + sovQuery(uint64(l))
+ }
+ l = len(m.ToDenom)
+ if l > 0 {
+ n += 1 + l + sovQuery(uint64(l))
+ }
return n
}
@@ -526,6 +596,14 @@ func (m *QueryTotalSwappableToCoinAmountRequest) Size() (n int) {
}
var l int
_ = l
+ l = len(m.FromDenom)
+ if l > 0 {
+ n += 1 + l + sovQuery(uint64(l))
+ }
+ l = len(m.ToDenom)
+ if l > 0 {
+ n += 1 + l + sovQuery(uint64(l))
+ }
return n
}
@@ -575,6 +653,70 @@ func (m *QuerySwappedRequest) Unmarshal(dAtA []byte) error {
return fmt.Errorf("proto: QuerySwappedRequest: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
+ case 1:
+ if wireType != 2 {
+ return fmt.Errorf("proto: wrong wireType = %d for field FromDenom", wireType)
+ }
+ var stringLen uint64
+ for shift := uint(0); ; shift += 7 {
+ if shift >= 64 {
+ return ErrIntOverflowQuery
+ }
+ if iNdEx >= l {
+ return io.ErrUnexpectedEOF
+ }
+ b := dAtA[iNdEx]
+ iNdEx++
+ stringLen |= uint64(b&0x7F) << shift
+ if b < 0x80 {
+ break
+ }
+ }
+ intStringLen := int(stringLen)
+ if intStringLen < 0 {
+ return ErrInvalidLengthQuery
+ }
+ postIndex := iNdEx + intStringLen
+ if postIndex < 0 {
+ return ErrInvalidLengthQuery
+ }
+ if postIndex > l {
+ return io.ErrUnexpectedEOF
+ }
+ m.FromDenom = string(dAtA[iNdEx:postIndex])
+ iNdEx = postIndex
+ case 2:
+ if wireType != 2 {
+ return fmt.Errorf("proto: wrong wireType = %d for field ToDenom", wireType)
+ }
+ var stringLen uint64
+ for shift := uint(0); ; shift += 7 {
+ if shift >= 64 {
+ return ErrIntOverflowQuery
+ }
+ if iNdEx >= l {
+ return io.ErrUnexpectedEOF
+ }
+ b := dAtA[iNdEx]
+ iNdEx++
+ stringLen |= uint64(b&0x7F) << shift
+ if b < 0x80 {
+ break
+ }
+ }
+ intStringLen := int(stringLen)
+ if intStringLen < 0 {
+ return ErrInvalidLengthQuery
+ }
+ postIndex := iNdEx + intStringLen
+ if postIndex < 0 {
+ return ErrInvalidLengthQuery
+ }
+ if postIndex > l {
+ return io.ErrUnexpectedEOF
+ }
+ m.ToDenom = string(dAtA[iNdEx:postIndex])
+ iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipQuery(dAtA[iNdEx:])
@@ -741,6 +883,70 @@ func (m *QueryTotalSwappableToCoinAmountRequest) Unmarshal(dAtA []byte) error {
return fmt.Errorf("proto: QueryTotalSwappableToCoinAmountRequest: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
+ case 1:
+ if wireType != 2 {
+ return fmt.Errorf("proto: wrong wireType = %d for field FromDenom", wireType)
+ }
+ var stringLen uint64
+ for shift := uint(0); ; shift += 7 {
+ if shift >= 64 {
+ return ErrIntOverflowQuery
+ }
+ if iNdEx >= l {
+ return io.ErrUnexpectedEOF
+ }
+ b := dAtA[iNdEx]
+ iNdEx++
+ stringLen |= uint64(b&0x7F) << shift
+ if b < 0x80 {
+ break
+ }
+ }
+ intStringLen := int(stringLen)
+ if intStringLen < 0 {
+ return ErrInvalidLengthQuery
+ }
+ postIndex := iNdEx + intStringLen
+ if postIndex < 0 {
+ return ErrInvalidLengthQuery
+ }
+ if postIndex > l {
+ return io.ErrUnexpectedEOF
+ }
+ m.FromDenom = string(dAtA[iNdEx:postIndex])
+ iNdEx = postIndex
+ case 2:
+ if wireType != 2 {
+ return fmt.Errorf("proto: wrong wireType = %d for field ToDenom", wireType)
+ }
+ var stringLen uint64
+ for shift := uint(0); ; shift += 7 {
+ if shift >= 64 {
+ return ErrIntOverflowQuery
+ }
+ if iNdEx >= l {
+ return io.ErrUnexpectedEOF
+ }
+ b := dAtA[iNdEx]
+ iNdEx++
+ stringLen |= uint64(b&0x7F) << shift
+ if b < 0x80 {
+ break
+ }
+ }
+ intStringLen := int(stringLen)
+ if intStringLen < 0 {
+ return ErrInvalidLengthQuery
+ }
+ postIndex := iNdEx + intStringLen
+ if postIndex < 0 {
+ return ErrInvalidLengthQuery
+ }
+ if postIndex > l {
+ return io.ErrUnexpectedEOF
+ }
+ m.ToDenom = string(dAtA[iNdEx:postIndex])
+ iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipQuery(dAtA[iNdEx:])
diff --git a/x/fswap/types/query.pb.gw.go b/x/fswap/types/query.pb.gw.go
index ea06d0652c..0ff5b16232 100644
--- a/x/fswap/types/query.pb.gw.go
+++ b/x/fswap/types/query.pb.gw.go
@@ -31,10 +31,21 @@ var _ = runtime.String
var _ = utilities.NewDoubleArray
var _ = descriptor.ForMessage
+var (
+ filter_Query_Swapped_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
+)
+
func request_Query_Swapped_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QuerySwappedRequest
var metadata runtime.ServerMetadata
+ if err := req.ParseForm(); err != nil {
+ return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
+ }
+ if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Swapped_0); err != nil {
+ return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
+ }
+
msg, err := client.Swapped(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
@@ -44,15 +55,33 @@ func local_request_Query_Swapped_0(ctx context.Context, marshaler runtime.Marsha
var protoReq QuerySwappedRequest
var metadata runtime.ServerMetadata
+ if err := req.ParseForm(); err != nil {
+ return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
+ }
+ if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Swapped_0); err != nil {
+ return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
+ }
+
msg, err := server.Swapped(ctx, &protoReq)
return msg, metadata, err
}
+var (
+ filter_Query_TotalSwappableToCoinAmount_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
+)
+
func request_Query_TotalSwappableToCoinAmount_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq QueryTotalSwappableToCoinAmountRequest
var metadata runtime.ServerMetadata
+ if err := req.ParseForm(); err != nil {
+ return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
+ }
+ if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_TotalSwappableToCoinAmount_0); err != nil {
+ return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
+ }
+
msg, err := client.TotalSwappableToCoinAmount(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
@@ -62,6 +91,13 @@ func local_request_Query_TotalSwappableToCoinAmount_0(ctx context.Context, marsh
var protoReq QueryTotalSwappableToCoinAmountRequest
var metadata runtime.ServerMetadata
+ if err := req.ParseForm(); err != nil {
+ return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
+ }
+ if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_TotalSwappableToCoinAmount_0); err != nil {
+ return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
+ }
+
msg, err := server.TotalSwappableToCoinAmount(ctx, &protoReq)
return msg, metadata, err