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 17 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
100 changes: 53 additions & 47 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -860,26 +860,25 @@
- [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)
- [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)
- [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 @@ -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 |
| `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 @@ -12751,47 +12750,51 @@ Msg defines the foundation Msg service.



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

### Swapped
### SwapInit



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

<!-- end HasExtensions -->
### SwapInitProposal
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) | | |
| `swap_init` | [SwapInit](#lbm.fswap.v1.SwapInit) | | |



<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) | | |
| `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 @@ -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) | | |
| `swap_init` | [SwapInit](#lbm.fswap.v1.SwapInit) | repeated | |
| `swapped` | [Swapped](#lbm.fswap.v1.Swapped) | repeated | |



Expand Down Expand Up @@ -12864,33 +12867,33 @@ 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.QueryTotalSwappableAmountRequest"></a>
<a name="lbm.fswap.v1.QueryTotalSwappableToCoinAmountRequest"></a>

### QueryTotalSwappableAmountRequest
### QueryTotalSwappableToCoinAmountRequest







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

### QueryTotalSwappableAmountResponse
### 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 @@ -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 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|

<!-- end services -->

Expand All @@ -12924,41 +12927,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 @@ -12988,8 +12994,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"];
}
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 SwapInit {
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 SwapInitProposal {
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;
SwapInit swap_init = 3 [(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];
}
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 SwapInit swap_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.

18 changes: 11 additions & 7 deletions proto/lbm/fswap/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,28 @@ 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 from-coin and a minted amount of
// to-coin.
rpc Swapped(QuerySwappedRequest) returns (QuerySwappedResponse) {
option (google.api.http).get = "/lbm/fswap/v1/swapped";
}
rpc TotalNewCurrencySwapLimit(QueryTotalSwappableAmountRequest) returns (QueryTotalSwappableAmountResponse) {
option (google.api.http).get = "/lbm/fswap/v1/swappable_new_coin_amount";
// TotalSwappableToCoinAmount queries the current swappable amount for to-coin.
rpc TotalSwappableToCoinAmount(QueryTotalSwappableToCoinAmountRequest)
returns (QueryTotalSwappableToCoinAmountResponse) {
option (google.api.http).get = "/lbm/fswap/v1/total_swappable_to_coin_amount";
}
}

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

message QueryTotalSwappableAmountRequest {}
message QueryTotalSwappableAmountResponse {
cosmos.base.v1beta1.Coin swappable_new_coin = 1
message QueryTotalSwappableToCoinAmountRequest {}
message QueryTotalSwappableToCoinAmountResponse {
cosmos.base.v1beta1.Coin swappable_amount = 1
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
}
15 changes: 9 additions & 6 deletions proto/lbm/fswap/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,26 @@ import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";

service Msg {
rpc Swap(MsgSwapRequest) returns (MsgSwapResponse);
rpc SwapAll(MsgSwapAllRequest) returns (MsgSwapAllResponse);
rpc Swap(MsgSwap) returns (MsgSwapResponse);
rpc SwapAll(MsgSwapAll) returns (MsgSwapAllResponse);
}

message MsgSwapRequest {
message MsgSwap {
// holder's address
string from_address = 1;
// amount of old currency
cosmos.base.v1beta1.Coin amount = 2
// from-coin amount
cosmos.base.v1beta1.Coin from_coin_amount = 2
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
string to_denom = 3;
}

message MsgSwapResponse {}

message MsgSwapAllRequest {
message MsgSwapAll {
// holder's address
string from_address = 1;
string from_denom = 2;
string to_denom = 3;
}

message MsgSwapAllResponse {}
Loading
Loading