Skip to content

Commit

Permalink
feat: fswap module's basic functionality(MsgSwap, MsgSwapAll, Query, …
Browse files Browse the repository at this point in the history
…Proposal) (#1345)

* refactor: fswap module's proto

Signed-off-by: 170210 <[email protected]>

* refactor: remove config&params and modify genesis

Signed-off-by: 170210 <[email protected]>

* refactor: use gov/proposal to change fswapInit

Signed-off-by: 170210 <[email protected]>

* chore: fix simulation

Signed-off-by: 170210 <[email protected]>

* chore: correct query cli

Signed-off-by: 170210 <[email protected]>

* chore: add query for test

Signed-off-by: 170210 <[email protected]>

* chore: lint fix

* chore: fix for tx cli

* chore: update proto

* chore: update genesis logic

* chore: add basic tx and queries

* chore: rename fswap to swap

* chore: change old/new to from/to

* chore: clean-up

* chore: clean errors and rename

* chore: update proto

* chore: clean unnecessary member variables

* chore: update proto, introduce config, clean code

* chore: remove redundant denom validation

* chore: remove cache-like operation, rename swap proposal in proto, errors start with number 2

* chore: apply feedbacks

* chore: fix some

* chore: fix for initGenesis

* chore: apply feedbacks

* chore: update changelog

* chore: remove redundant logic

* chore: update error doc

* chore: update proto and logic to accept bank.Metadata

* chore: add query to get all the swaps

* chore: change swap_multiple to swap_rate

* chore: disallow updating existing denom metadata with different values

* chore: fix for calcSwap logic

* chore: extract CalcSwap to function

* chore: add missing query cmd

* chore: fix for proposal cli

* chore: fix for init timing

* chore: fix query cli

* chore: fix to prevent generating swap more than MaxSwaps

* fix: add missing call validateBasic for proposal

* fix:

* chore: change error type for temporal test-pass

* chore: fix for make-swap-proposal update

* chore: fix to check swap count after increase in order not to make more than limit

* chore: prevent any proposal with different denom

* chore: change amount cap type

* chore: fix codec-related parts

* chore: minor change for convert to-coin-amount-cap

---------

Signed-off-by: 170210 <[email protected]>
Co-authored-by: jaeseung.bae <[email protected]>
  • Loading branch information
170210 and jaeseung-bae authored May 3, 2024
1 parent 8d79d25 commit 956d7a6
Show file tree
Hide file tree
Showing 58 changed files with 4,137 additions and 1,371 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/fbridge) [\#1340](https://github.com/Finschia/finschia-sdk/pull/1340) Initialize fbridge module
* (x/fbridge) [\#1347](https://github.com/Finschia/finschia-sdk/pull/1347) Implement bridge transfer feature (sending side)
* (x/fbridge) [\#1351](https://github.com/Finschia/finschia-sdk/pull/1351) Map a sequence to block number for every bridge request (sending side)
* (x/fswap) [\#1345](https://github.com/Finschia/finschia-sdk/pull/1345) Implement fswap's basic functionality(MsgSwap, MsgSwapAll, Query, Proposal)

### Improvements
* (docs) [\#1120](https://github.com/Finschia/finschia-sdk/pull/1120) Update links in x/foundation README.md
Expand Down
164 changes: 117 additions & 47 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -943,26 +943,28 @@
- [EventSwapCoins](#lbm.fswap.v1.EventSwapCoins)

- [lbm/fswap/v1/fswap.proto](#lbm/fswap/v1/fswap.proto)
- [MakeSwapProposal](#lbm.fswap.v1.MakeSwapProposal)
- [Swap](#lbm.fswap.v1.Swap)
- [SwapStats](#lbm.fswap.v1.SwapStats)
- [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)

- [lbm/fswap/v1/query.proto](#lbm/fswap/v1/query.proto)
- [QuerySwappedRequest](#lbm.fswap.v1.QuerySwappedRequest)
- [QuerySwappedResponse](#lbm.fswap.v1.QuerySwappedResponse)
- [QueryTotalSwappableAmountRequest](#lbm.fswap.v1.QueryTotalSwappableAmountRequest)
- [QueryTotalSwappableAmountResponse](#lbm.fswap.v1.QueryTotalSwappableAmountResponse)
- [QuerySwapsRequest](#lbm.fswap.v1.QuerySwapsRequest)
- [QuerySwapsResponse](#lbm.fswap.v1.QuerySwapsResponse)
- [QueryTotalSwappableToCoinAmountRequest](#lbm.fswap.v1.QueryTotalSwappableToCoinAmountRequest)
- [QueryTotalSwappableToCoinAmountResponse](#lbm.fswap.v1.QueryTotalSwappableToCoinAmountResponse)

- [Query](#lbm.fswap.v1.Query)

- [lbm/fswap/v1/tx.proto](#lbm/fswap/v1/tx.proto)
- [MsgSwapAllRequest](#lbm.fswap.v1.MsgSwapAllRequest)
- [MsgSwap](#lbm.fswap.v1.MsgSwap)
- [MsgSwapAll](#lbm.fswap.v1.MsgSwapAll)
- [MsgSwapAllResponse](#lbm.fswap.v1.MsgSwapAllResponse)
- [MsgSwapRequest](#lbm.fswap.v1.MsgSwapRequest)
- [MsgSwapResponse](#lbm.fswap.v1.MsgSwapResponse)

- [Msg](#lbm.fswap.v1.Msg)
Expand Down Expand Up @@ -13928,8 +13930,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 |
| `from_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | from-coin amount |
| `to_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | to-coin amount |



Expand All @@ -13952,47 +13954,67 @@ Msg defines the foundation Msg service.



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

### Swapped
### MakeSwapProposal
From cosmos-sdk 0.46.0 they deprecated this way, but currently finschia-sdk based on 0.45.10


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `title` | [string](#string) | | |
| `description` | [string](#string) | | |
| `swap` | [Swap](#lbm.fswap.v1.Swap) | | |
| `to_denom_metadata` | [cosmos.bank.v1beta1.Metadata](#cosmos.bank.v1beta1.Metadata) | | |






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

### Swap



| 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_rate` | [string](#string) | | |





<!-- end messages -->

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

<!-- end HasExtensions -->
### SwapStats

<!-- end services -->


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `swap_count` | [int32](#int32) | | |

<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.Params"></a>

### Params
Params defines the parameters for the module.
<a name="lbm.fswap.v1.Swapped"></a>

### Swapped



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



Expand Down Expand Up @@ -14023,8 +14045,9 @@ GenesisState defines the fswap module's genesis state.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `params` | [Params](#lbm.fswap.v1.Params) | | |
| `swapped` | [Swapped](#lbm.fswap.v1.Swapped) | | |
| `swaps` | [Swap](#lbm.fswap.v1.Swap) | repeated | |
| `swap_stats` | [SwapStats](#lbm.fswap.v1.SwapStats) | | |
| `swappeds` | [Swapped](#lbm.fswap.v1.Swapped) | repeated | |



Expand Down Expand Up @@ -14053,6 +14076,12 @@ GenesisState defines the fswap module's genesis state.



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `fromDenom` | [string](#string) | | |
| `toDenom` | [string](#string) | | |





Expand All @@ -14065,33 +14094,70 @@ 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) | | |
| `from_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |
| `to_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |






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

### QuerySwapsRequest



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `pagination` | [cosmos.base.query.v1beta1.PageRequest](#cosmos.base.query.v1beta1.PageRequest) | | |






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

### QuerySwapsResponse



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `swaps` | [Swap](#lbm.fswap.v1.Swap) | repeated | |
| `pagination` | [cosmos.base.query.v1beta1.PageResponse](#cosmos.base.query.v1beta1.PageResponse) | | |






<a name="lbm.fswap.v1.QueryTotalSwappableAmountRequest"></a>
<a name="lbm.fswap.v1.QueryTotalSwappableToCoinAmountRequest"></a>

### QueryTotalSwappableAmountRequest
### QueryTotalSwappableToCoinAmountRequest



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `fromDenom` | [string](#string) | | |
| `toDenom` | [string](#string) | | |





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

### QueryTotalSwappableAmountResponse
<a name="lbm.fswap.v1.QueryTotalSwappableToCoinAmountResponse"></a>

### QueryTotalSwappableToCoinAmountResponse



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



Expand All @@ -14111,8 +14177,9 @@ 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 from-coin and a minted amount of to-coin. | GET|/lbm/fswap/v1/swapped|
| `TotalSwappableToCoinAmount` | [QueryTotalSwappableToCoinAmountRequest](#lbm.fswap.v1.QueryTotalSwappableToCoinAmountRequest) | [QueryTotalSwappableToCoinAmountResponse](#lbm.fswap.v1.QueryTotalSwappableToCoinAmountResponse) | TotalSwappableToCoinAmount queries the current swappable amount for to-coin. | GET|/lbm/fswap/v1/total_swappable_to_coin_amount|
| `Swaps` | [QuerySwapsRequest](#lbm.fswap.v1.QuerySwapsRequest) | [QuerySwapsResponse](#lbm.fswap.v1.QuerySwapsResponse) | Swaps queries all the swap that registered | GET|/lbm/fswap/v1/swaps|

<!-- end services -->

Expand All @@ -14125,41 +14192,44 @@ GenesisState defines the fswap module's genesis state.



<a name="lbm.fswap.v1.MsgSwapAllRequest"></a>
<a name="lbm.fswap.v1.MsgSwap"></a>

### MsgSwapAllRequest
### MsgSwap



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `from_address` | [string](#string) | | holder's address |
| `from_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | from-coin amount |
| `to_denom` | [string](#string) | | |






<a name="lbm.fswap.v1.MsgSwapAllResponse"></a>
<a name="lbm.fswap.v1.MsgSwapAll"></a>

### MsgSwapAllResponse
### MsgSwapAll



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `from_address` | [string](#string) | | holder's address |
| `from_denom` | [string](#string) | | |
| `to_denom` | [string](#string) | | |




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

### MsgSwapRequest

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

### MsgSwapAllResponse

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `from_address` | [string](#string) | | holder's address |
| `amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | amount of old currency |



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

| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `Swap` | [MsgSwapRequest](#lbm.fswap.v1.MsgSwapRequest) | [MsgSwapResponse](#lbm.fswap.v1.MsgSwapResponse) | | |
| `SwapAll` | [MsgSwapAllRequest](#lbm.fswap.v1.MsgSwapAllRequest) | [MsgSwapAllResponse](#lbm.fswap.v1.MsgSwapAllResponse) | | |
| `Swap` | [MsgSwap](#lbm.fswap.v1.MsgSwap) | [MsgSwapResponse](#lbm.fswap.v1.MsgSwapResponse) | | |
| `SwapAll` | [MsgSwapAll](#lbm.fswap.v1.MsgSwapAll) | [MsgSwapAllResponse](#lbm.fswap.v1.MsgSwapAllResponse) | | |

<!-- end services -->

Expand Down
8 changes: 4 additions & 4 deletions proto/lbm/fswap/v1/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import "cosmos/base/v1beta1/coin.proto";
message EventSwapCoins {
// holder's address
string address = 1;
// amount of the old currency
cosmos.base.v1beta1.Coin old_coin = 2
// from-coin amount
cosmos.base.v1beta1.Coin from_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
// to-coin amount
cosmos.base.v1beta1.Coin to_coin_amount = 3
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
}
40 changes: 37 additions & 3 deletions proto/lbm/fswap/v1/fswap.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,43 @@ 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";
import "cosmos/bank/v1beta1/bank.proto";

message Swapped {
message Swap {
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 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_rate = 4
[(gogoproto.customtype) = "github.com/Finschia/finschia-sdk/types.Dec", (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 MakeSwapProposal {
option (gogoproto.goproto_stringer) = false;

string title = 1;
string description = 2;
Swap swap = 3 [(gogoproto.nullable) = false];
cosmos.bank.v1beta1.Metadata to_denom_metadata = 4
[(gogoproto.moretags) = "yaml:\"denom_metadata\"", (gogoproto.nullable) = false];
}

message Swapped {
option (gogoproto.goproto_stringer) = false;
cosmos.base.v1beta1.Coin from_coin_amount = 1
[(gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin", (gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin to_coin_amount = 2
[(gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin", (gogoproto.nullable) = false];
}
6 changes: 3 additions & 3 deletions proto/lbm/fswap/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ 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 Swap swaps = 1 [(gogoproto.nullable) = false];
SwapStats swap_stats = 2 [(gogoproto.nullable) = false];
repeated Swapped swappeds = 3 [(gogoproto.nullable) = false];
}
Loading

0 comments on commit 956d7a6

Please sign in to comment.