Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fswap module's basic functionality(MsgSwap, MsgSwapAll, Query, Proposal) #1345

Merged
merged 49 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
c4ff578
refactor: fswap module's proto
170210 Apr 26, 2024
93a97a6
refactor: remove config&params and modify genesis
170210 Apr 26, 2024
5a8dd65
refactor: use gov/proposal to change fswapInit
170210 Apr 26, 2024
df7355d
chore: fix simulation
170210 Apr 26, 2024
4c8a928
chore: correct query cli
170210 Apr 26, 2024
015c224
chore: add query for test
170210 Apr 26, 2024
4701f3e
chore: lint fix
jaeseung-bae Apr 26, 2024
a139b67
chore: fix for tx cli
jaeseung-bae Apr 28, 2024
60d0112
chore: update proto
jaeseung-bae Apr 29, 2024
f1e6811
chore: update genesis logic
jaeseung-bae Apr 29, 2024
427da10
chore: add basic tx and queries
jaeseung-bae Apr 30, 2024
9b26d2f
chore: rename fswap to swap
jaeseung-bae Apr 30, 2024
6aecac6
chore: change old/new to from/to
jaeseung-bae Apr 30, 2024
5195f88
chore: clean-up
jaeseung-bae Apr 30, 2024
6151a0c
chore: clean errors and rename
jaeseung-bae Apr 30, 2024
be5f723
chore: update proto
jaeseung-bae Apr 30, 2024
e2ac84c
chore: clean unnecessary member variables
jaeseung-bae Apr 30, 2024
8b1afaf
chore: update proto, introduce config, clean code
jaeseung-bae May 2, 2024
edc1df6
chore: remove redundant denom validation
jaeseung-bae May 2, 2024
f59a2c3
chore: remove cache-like operation, rename swap proposal in proto, er…
jaeseung-bae May 2, 2024
8e3e634
chore: apply feedbacks
jaeseung-bae May 2, 2024
17eeffd
chore: fix some
jaeseung-bae May 2, 2024
cb736ad
chore: fix for initGenesis
jaeseung-bae May 2, 2024
f48ffbc
chore: apply feedbacks
jaeseung-bae May 2, 2024
ea9c027
Merge remote-tracking branch 'origin/pjdp1' into fswap_refactor
jaeseung-bae May 2, 2024
44caeee
chore: update changelog
jaeseung-bae May 2, 2024
15ed1c9
chore: remove redundant logic
jaeseung-bae May 2, 2024
607d94a
chore: update error doc
jaeseung-bae May 2, 2024
a0ca4d3
chore: update proto and logic to accept bank.Metadata
jaeseung-bae May 2, 2024
0f5de19
chore: add query to get all the swaps
jaeseung-bae May 2, 2024
4847746
chore: change swap_multiple to swap_rate
jaeseung-bae May 2, 2024
badefa5
chore: disallow updating existing denom metadata with different values
jaeseung-bae May 2, 2024
1d1a0ce
chore: fix for calcSwap logic
jaeseung-bae May 3, 2024
c4996b3
chore: extract CalcSwap to function
jaeseung-bae May 3, 2024
4cdde22
chore: add missing query cmd
jaeseung-bae May 3, 2024
d00a3d1
chore: fix for proposal cli
jaeseung-bae May 3, 2024
47d684f
chore: fix for init timing
jaeseung-bae May 3, 2024
d15f3e5
chore: fix query cli
jaeseung-bae May 3, 2024
54cce5a
chore: fix to prevent generating swap more than MaxSwaps
jaeseung-bae May 3, 2024
c0950b6
fix: add missing call validateBasic for proposal
jaeseung-bae May 3, 2024
4b49115
fix:
jaeseung-bae May 3, 2024
7ef5b3f
chore: change error type for temporal test-pass
jaeseung-bae May 3, 2024
f3d7632
chore: fix for make-swap-proposal update
jaeseung-bae May 3, 2024
9854cf3
chore: fix to check swap count after increase in order not to make mo…
jaeseung-bae May 3, 2024
472d5b4
chore: prevent any proposal with different denom
jaeseung-bae May 3, 2024
3ac87ab
Merge remote-tracking branch 'origin/pjdp1' into fswap_refactor
jaeseung-bae May 3, 2024
70f9499
chore: change amount cap type
jaeseung-bae May 3, 2024
ebefc77
chore: fix codec-related parts
jaeseung-bae May 3, 2024
99f9193
chore: minor change for convert to-coin-amount-cap
jaeseung-bae May 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 29 additions & 26 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -860,11 +860,10 @@
- [EventSwapCoins](#lbm.fswap.v1.EventSwapCoins)

- [lbm/fswap/v1/fswap.proto](#lbm/fswap/v1/fswap.proto)
- [FswapInit](#lbm.fswap.v1.FswapInit)
- [FswapInitProposal](#lbm.fswap.v1.FswapInitProposal)
- [Swapped](#lbm.fswap.v1.Swapped)

- [lbm/fswap/v1/params.proto](#lbm/fswap/v1/params.proto)
- [Params](#lbm.fswap.v1.Params)

- [lbm/fswap/v1/genesis.proto](#lbm/fswap/v1/genesis.proto)
- [GenesisState](#lbm.fswap.v1.GenesisState)

Expand Down Expand Up @@ -12727,8 +12726,8 @@ Msg defines the foundation Msg service.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `address` | [string](#string) | | holder's address |
| `old_coin` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | amount of the old currency |
| `new_coin` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | amount of the new currency |
| `old_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | amount of the old currency |
| `new_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | amount of the new currency |



Expand All @@ -12751,47 +12750,51 @@ Msg defines the foundation Msg service.



<a name="lbm.fswap.v1.Swapped"></a>
<a name="lbm.fswap.v1.FswapInit"></a>

### Swapped
### FswapInit



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `old_coin_amount` | [string](#string) | | |
| `new_coin_amount` | [string](#string) | | |
| `from_denom` | [string](#string) | | |
| `to_denom` | [string](#string) | | |
| `amount_cap_for_to_denom` | [string](#string) | | |
| `swap_multiple` | [string](#string) | | |





<!-- end messages -->

<!-- end enums -->
<a name="lbm.fswap.v1.FswapInitProposal"></a>

<!-- end HasExtensions -->
### FswapInitProposal
From cosmos-sdk 0.46.0 they deprecated this way, but currently finschia-sdk based on 0.45.10

<!-- end services -->

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `title` | [string](#string) | | |
| `description` | [string](#string) | | |
| `fswap_init` | [FswapInit](#lbm.fswap.v1.FswapInit) | | |



<a name="lbm/fswap/v1/params.proto"></a>
<p align="right"><a href="#top">Top</a></p>

## lbm/fswap/v1/params.proto


<a name="lbm.fswap.v1.Swapped"></a>

<a name="lbm.fswap.v1.Params"></a>
### Swapped

### Params
Params defines the parameters for the module.


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



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

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `params` | [Params](#lbm.fswap.v1.Params) | | |
| `swapped` | [Swapped](#lbm.fswap.v1.Swapped) | | |
| `fswap_init` | [FswapInit](#lbm.fswap.v1.FswapInit) | repeated | |
| `swapped` | [Swapped](#lbm.fswap.v1.Swapped) | repeated | |



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

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



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

| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `Swapped` | [QuerySwappedRequest](#lbm.fswap.v1.QuerySwappedRequest) | [QuerySwappedResponse](#lbm.fswap.v1.QuerySwappedResponse) | | GET|/lbm/fswap/v1/swapped|
| `TotalNewCurrencySwapLimit` | [QueryTotalSwappableAmountRequest](#lbm.fswap.v1.QueryTotalSwappableAmountRequest) | [QueryTotalSwappableAmountResponse](#lbm.fswap.v1.QueryTotalSwappableAmountResponse) | | GET|/lbm/fswap/v1/swappable_new_coin_amount|
| `Swapped` | [QuerySwappedRequest](#lbm.fswap.v1.QuerySwappedRequest) | [QuerySwappedResponse](#lbm.fswap.v1.QuerySwappedResponse) | Swapped queries the current swapped status that includes a burnt amount of old coin and a minted amount of new coin. | GET|/lbm/fswap/v1/swapped|
| `TotalSwappableAmount` | [QueryTotalSwappableAmountRequest](#lbm.fswap.v1.QueryTotalSwappableAmountRequest) | [QueryTotalSwappableAmountResponse](#lbm.fswap.v1.QueryTotalSwappableAmountResponse) | TotalSwappableAmount queries the current swappable amount for new coin. | GET|/lbm/fswap/v1/swappable_new_coin_amount|

<!-- end services -->

Expand Down
4 changes: 2 additions & 2 deletions proto/lbm/fswap/v1/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ message EventSwapCoins {
// holder's address
string address = 1;
// amount of the old currency
cosmos.base.v1beta1.Coin old_coin = 2
cosmos.base.v1beta1.Coin old_coin_amount = 2
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
// amount of the new currency
cosmos.base.v1beta1.Coin new_coin = 3
cosmos.base.v1beta1.Coin new_coin_amount = 3
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
}
31 changes: 28 additions & 3 deletions proto/lbm/fswap/v1/fswap.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,34 @@ 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 {
message FswapInit {
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;

string from_denom = 1;
string to_denom = 2;
string amount_cap_for_to_denom = 3
[(gogoproto.customtype) = "github.com/Finschia/finschia-sdk/types.Int", (gogoproto.nullable) = false];
string swap_multiple = 4
[(gogoproto.customtype) = "github.com/Finschia/finschia-sdk/types.Int", (gogoproto.nullable) = false];
}

// From cosmos-sdk 0.46.0 they deprecated this way, but currently finschia-sdk based on 0.45.10
message FswapInitProposal {
option (gogoproto.equal) = true;
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];

string title = 1;
string description = 2;
FswapInit fswap_init = 3 [(gogoproto.nullable) = false];
}

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

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

// GenesisState defines the fswap module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
Swapped swapped = 2 [(gogoproto.nullable) = false];
repeated FswapInit fswap_init = 1 [(gogoproto.nullable) = false];
repeated Swapped swapped = 2 [(gogoproto.nullable) = false];
}
12 changes: 0 additions & 12 deletions proto/lbm/fswap/v1/params.proto

This file was deleted.

9 changes: 6 additions & 3 deletions proto/lbm/fswap/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ import "cosmos/base/v1beta1/coin.proto";
import "lbm/fswap/v1/fswap.proto";

service Query {
// Swapped queries the current swapped status that includes a burnt amount of old coin and a minted amount of new
// coin.
rpc Swapped(QuerySwappedRequest) returns (QuerySwappedResponse) {
option (google.api.http).get = "/lbm/fswap/v1/swapped";
}
rpc TotalNewCurrencySwapLimit(QueryTotalSwappableAmountRequest) returns (QueryTotalSwappableAmountResponse) {
// TotalSwappableAmount queries the current swappable amount for new coin.
rpc TotalSwappableAmount(QueryTotalSwappableAmountRequest) returns (QueryTotalSwappableAmountResponse) {
option (google.api.http).get = "/lbm/fswap/v1/swappable_new_coin_amount";
}
}

message QuerySwappedRequest {}
message QuerySwappedResponse {
cosmos.base.v1beta1.Coin old_coin = 1
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 = 2
cosmos.base.v1beta1.Coin new_coin_amount = 2
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
}

Expand Down
13 changes: 8 additions & 5 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import (
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"
fswapclient "github.com/Finschia/finschia-sdk/x/fswap/client"
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"
Expand Down Expand Up @@ -130,6 +131,7 @@ var (
upgradeclient.ProposalHandler,
upgradeclient.CancelProposalHandler,
foundationclient.ProposalHandler,
fswapclient.FswapInitHandler,
),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
Expand All @@ -154,6 +156,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 @@ -324,6 +327,9 @@ func NewSimApp(
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)

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.StakingKeeper = *stakingKeeper.SetHooks(
Expand All @@ -338,7 +344,8 @@ func NewSimApp(
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(foundation.RouterKey, foundationkeeper.NewFoundationProposalsHandler(app.FoundationKeeper))
AddRoute(foundation.RouterKey, foundationkeeper.NewFoundationProposalsHandler(app.FoundationKeeper)).
AddRoute(fswaptypes.RouterKey, fswap.NewFswapInitHandler(app.FswapKeeper))

govKeeper := govkeeper.NewKeeper(
appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
Expand All @@ -358,10 +365,6 @@ func NewSimApp(
// If evidence needs to be handled for the app, set routes in router here and seal
app.EvidenceKeeper = *evidenceKeeper

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

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

// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
Expand Down
2 changes: 1 addition & 1 deletion x/ERRORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@

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

Expand Down
6 changes: 3 additions & 3 deletions x/fswap/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command {

func CmdQuerySwapped() *cobra.Command {
cmd := &cobra.Command{
Use: "fswap swapped",
Use: "swapped",
Short: "shows the current swap status, including both old and new coin amount",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -55,7 +55,7 @@ func CmdQuerySwapped() *cobra.Command {

func CmdQueryTotalSwappableAmount() *cobra.Command {
cmd := &cobra.Command{
Use: "fswap total-swappable-amount",
Use: "total-swappable-amount",
Short: "shows the current total amount of new coin that're swappable",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -65,7 +65,7 @@ func CmdQueryTotalSwappableAmount() *cobra.Command {
}
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.TotalNewCurrencySwapLimit(cmd.Context(), &types.QueryTotalSwappableAmountRequest{})
res, err := queryClient.TotalSwappableAmount(cmd.Context(), &types.QueryTotalSwappableAmountRequest{})
if err != nil {
return err
}
Expand Down
Loading
Loading