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: add special asset pairs #2150

Merged
merged 47 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
2f1b8bd
feat: add special asset pairs
toteki Jul 17, 2023
cb484f9
Update proto/umee/leverage/v1/leverage.proto
toteki Jul 17, 2023
02b5edf
Merge branch 'main' into adam/special
toteki Jul 18, 2023
07acee1
Merge branch 'main' into adam/special
toteki Jul 20, 2023
9f0f9fe
Merge branch 'main' into adam/special
toteki Jul 21, 2023
286fa0e
line length lint
toteki Jul 21, 2023
e05b997
Merge branch 'main' into adam/special
toteki Jul 21, 2023
5eb3d88
Merge branch 'main' into adam/special
toteki Jul 21, 2023
ea72c67
Update x/leverage/keeper/token.go
toteki Jul 21, 2023
545ee88
Update x/leverage/keeper/token.go
toteki Jul 21, 2023
b3270a8
Update proto/umee/leverage/v1/leverage.proto
toteki Jul 21, 2023
d1819fa
Update proto/umee/leverage/v1/leverage.proto
toteki Jul 21, 2023
73c4b30
Merge branch 'main' into adam/special
toteki Jul 21, 2023
5b7b02d
make proto-all
toteki Jul 21, 2023
55f8153
make proto-all
toteki Jul 21, 2023
97efc7f
fix
toteki Jul 21, 2023
48a9900
Merge branch 'main' into adam/special
toteki Jul 25, 2023
c9c0cdb
remove title + description
toteki Jul 25, 2023
5817edd
group legacy msg interface
toteki Jul 25, 2023
153037e
proposal.go
toteki Jul 25, 2023
c3d39b2
legacy++
toteki Jul 25, 2023
9a22f72
special asset sets in gov message
toteki Jul 26, 2023
11ffd99
pair deletion logic
toteki Jul 26, 2023
5e08485
can query for specific asset
toteki Jul 26, 2023
004a5d5
Update proto/umee/leverage/v1/tx.proto
toteki Jul 26, 2023
0c3440d
make proto-all
toteki Jul 26, 2023
f8cb27f
changelog
toteki Jul 26, 2023
19d5a06
Merge branch 'main' into adam/special
toteki Jul 27, 2023
206c769
lint
toteki Jul 27, 2023
b9b522c
Update proto/umee/leverage/v1/tx.proto
toteki Jul 28, 2023
0075b58
Update proto/umee/leverage/v1/tx.proto
toteki Jul 28, 2023
53b7e4f
proto changes
toteki Jul 28, 2023
7944aae
collateral weight zero deletes sets ad pairs
toteki Jul 28, 2023
fcda085
fix CLI
toteki Jul 28, 2023
ef36cda
test++
toteki Jul 28, 2023
0e46e1a
combine validate functions in genesis
toteki Jul 28, 2023
6f75ab6
Merge branch 'main' into adam/special
toteki Jul 28, 2023
daa5e0a
fix
toteki Jul 28, 2023
f83ab08
fix
toteki Jul 28, 2023
78cd2e7
proto changes
toteki Jul 30, 2023
e48b35c
fix names
toteki Jul 30, 2023
8804ed4
fix names
toteki Jul 30, 2023
31402c5
validation allows empty pairs if sets present instead
toteki Jul 30, 2023
03dcd74
optional arg doc
toteki Jul 30, 2023
cbd2178
Add liquidation threshold to pairs
toteki Jul 30, 2023
39a9994
revert proposal.go
toteki Jul 30, 2023
5e2e948
change stringer
toteki Jul 30, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- [2129](https://github.com/umee-network/umee/pull/2129) Emergency Group x/ugov proto.
- [2146](https://github.com/umee-network/umee/pull/2146) Add store `GetTimeMs` and `SetTimeMs`.
- [2157](https://github.com/umee-network/umee/pull/2157) Add `x/metoken` module.
- [2150](https://github.com/umee-network/umee/pull/2150) Add gov message to create Special Asset Pairs
- [2145](https://github.com/umee-network/umee/pull/2145) Add New `Inflation Parms` to x/ugov proto and added `inflation rate` change logic to umint
- [2159](https://github.com/umee-network/umee/pull/2159) Add hard market cap for token emission.
- [2155](https://github.com/umee-network/umee/pull/2155) `bpmath`: basis points math package.
Expand Down
1 change: 1 addition & 0 deletions proto/umee/leverage/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ message GenesisState {
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
repeated SpecialAssetPair special_pairs = 10 [(gogoproto.nullable) = false];
}

// AdjustedBorrow is a borrow struct used in the leverage module's genesis
Expand Down
39 changes: 39 additions & 0 deletions proto/umee/leverage/v1/leverage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,42 @@ message Token {
(gogoproto.moretags) = "yaml:\"historic_medians\""
];
}

// SpecialAssetPair defines a special (increased) CollateralWeight used when a specified Collateral is used
// to collateralize a specified Borrow. This association is one-way (so it does not work in reverse).
message SpecialAssetPair {
option (gogoproto.equal) = true;

// Collateral base token denom.
string collateral = 1;

// Borrow base token denom.
string borrow = 2;
toteki marked this conversation as resolved.
Show resolved Hide resolved

// Collateral Weight defines what portion of the total value of the asset
// can contribute to a users borrowing power. For special asset pairs, this
// also overrides the borrowed asset's collateral weight when evaluating borrow
// factor. Valid values: 0-1.
string collateral_weight = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

// SpecialAssetSet defines a special (increased) CollateralWeight used when any of a set
// of assets are used to borrow each other (except for looping). It is used in gov proposals
// to create all the pairs that make up a set at once.
message SpecialAssetSet {
option (gogoproto.equal) = true;

// Collateral or borrowed base token denoms.
repeated string assets = 1;

// Collateral Weight defines what portion of the total value of the assets
// can contribute to a users borrowing power, when borrowing within the set.
toteki marked this conversation as resolved.
Show resolved Hide resolved
// Valid values: 0-1.
string collateral_weight = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}
19 changes: 19 additions & 0 deletions proto/umee/leverage/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ service Query {
option (google.api.http).get = "/umee/leverage/v1/registered_tokens";
}

// SpecialAssetPairs queries for all special asset pairs.
rpc SpecialAssetPairs(QuerySpecialAssetPairs)
toteki marked this conversation as resolved.
Show resolved Hide resolved
returns (QuerySpecialAssetPairsResponse) {
option (google.api.http).get = "/umee/leverage/v1/special_asset_pairs";
toteki marked this conversation as resolved.
Show resolved Hide resolved
toteki marked this conversation as resolved.
Show resolved Hide resolved
}

// MarketSummary queries a base asset's current borrowing and supplying conditions.
rpc MarketSummary(QueryMarketSummary)
returns (QueryMarketSummaryResponse) {
Expand Down Expand Up @@ -100,6 +106,19 @@ message QueryRegisteredTokensResponse {
repeated Token registry = 1 [(gogoproto.nullable) = false];
}

// QuerySpecialAssetPairs defines the request structure for the SpecialAssetPairs
// gRPC service handler.
message QuerySpecialAssetPairs {
// denom can be used to query only pairs affecting a specific asset
string denom = 1;
toteki marked this conversation as resolved.
Show resolved Hide resolved
}

// QuerySpecialAssetPairsResponse defines the response structure for the
// SpecialAssetPairs gRPC service handler.
message QuerySpecialAssetPairsResponse {
repeated SpecialAssetPair pairs = 1 [(gogoproto.nullable) = false];
}

// QueryMarketSummary defines the request structure for the MarketSummary gRPC service handler.
message QueryMarketSummary {
string denom = 1;
Expand Down
32 changes: 32 additions & 0 deletions proto/umee/leverage/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ service Msg {
// GovUpdateRegistry adds new tokens to the token registry or
// updates existing tokens with new settings.
rpc GovUpdateRegistry(MsgGovUpdateRegistry) returns (MsgGovUpdateRegistryResponse);

// GovUpdateSpecialAssetPairs adds, updates, or removes special asset pairs. Note that a special asset
// pair can be removed by setting its special collateral weight to negative one. Also allows for the creation
// of sets of assets, where each asset in the set forms a special asset pair with all of the others.
rpc GovUpdateSpecialAssetPairs(MsgGovUpdateSpecialAssetPairs) returns (MsgGovUpdateSpecialAssetPairsResponse);
toteki marked this conversation as resolved.
Show resolved Hide resolved
}

// MsgSupply represents a user's request to supply assets to the module.
Expand Down Expand Up @@ -266,3 +271,30 @@ message MsgGovUpdateRegistry {

// MsgGovUpdateRegistryResponse defines the Msg/GovUpdateRegistry response type.
message MsgGovUpdateRegistryResponse {}

// MsgGovUpdateSpecialAssetPairs defines the Msg/GovUpdateSpecialAssetPairs request type.
message MsgGovUpdateSpecialAssetPairs {
option (gogoproto.equal) = true;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
option (cosmos.msg.v1.signer) = "authority";

// authority is the address of the governance account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// sets are bidirectional groups of special asset pairs. Creating a special asset
// set causes all assets in the set to have a certain collateral weight when borrowing
// against each other (but not looping with themselves). Overrides any existing
// special asset pairs between assets in the set. Using a collateral weight
// of zero will clear all existing special pairs in the set instead.
repeated SpecialAssetSet sets = 2 [(gogoproto.nullable) = false];

// pairs are new or updated special asset pairs. Updating a special asset pair's
// collateral weight to zero deletes the pair instead.
// These pairs will be applied after any sets above when passing a proposal,
// so they can be used for more granular control.
repeated SpecialAssetPair pairs = 3 [(gogoproto.nullable) = false];
toteki marked this conversation as resolved.
Show resolved Hide resolved
}

// MsgGovUpdateSpecialAssetPairsResponse defines the Msg/GovUpdateSpecialAssetPairs response type.
message MsgGovUpdateSpecialAssetPairsResponse {}
138 changes: 138 additions & 0 deletions swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,81 @@ paths:
type: string
tags:
- Query
/umee/leverage/v1/special_asset_pairs:
get:
summary: SpecialAssetPairs queries for all special asset pairs.
operationId: SpecialAssetPairs
responses:
'200':
description: A successful response.
schema:
type: object
properties:
pairs:
type: array
items:
type: object
properties:
collateral:
type: string
description: Collateral base token denom.
borrow:
type: string
description: Borrow base token denom.
collateral_weight:
type: string
description: >-
Collateral Weight defines what portion of the total
value of the asset

can contribute to a users borrowing power. For special
asset pairs, this

also overrides the borrowed asset's collateral weight
when evaluating borrow

factor. Valid values: 0-1.
description: >-
SpecialAssetPair defines a special (increased)
CollateralWeight used when a specified Collateral is used

to collateralize a specified Borrow. This association is
one-way (so it does not work in reverse).
description: >-
QuerySpecialAssetPairsResponse defines the response structure for
the

SpecialAssetPairs gRPC service handler.
default:
description: An unexpected error response.
schema:
type: object
properties:
error:
type: string
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
type_url:
type: string
value:
type: string
format: byte
parameters:
- name: denom
description: denom can be used to query only pairs affecting a specific asset.
in: query
required: false
type: string
tags:
- Query
/umee/historacle/v1/avg_price/{denom}:
get:
summary: QueryAvgPrice returns avg price of a given denom (required).
Expand Down Expand Up @@ -5098,6 +5173,42 @@ definitions:
description: |-
QueryRegisteredTokensResponse defines the response structure for the
RegisteredTokens gRPC service handler.
umee.leverage.v1.QuerySpecialAssetPairsResponse:
type: object
properties:
pairs:
type: array
items:
type: object
properties:
collateral:
type: string
description: Collateral base token denom.
borrow:
type: string
description: Borrow base token denom.
collateral_weight:
type: string
description: >-
Collateral Weight defines what portion of the total value of the
asset

can contribute to a users borrowing power. For special asset
pairs, this

also overrides the borrowed asset's collateral weight when
evaluating borrow

factor. Valid values: 0-1.
description: >-
SpecialAssetPair defines a special (increased) CollateralWeight used
when a specified Collateral is used

to collateralize a specified Borrow. This association is one-way (so
it does not work in reverse).
description: |-
QuerySpecialAssetPairsResponse defines the response structure for the
SpecialAssetPairs gRPC service handler.
umee.leverage.v1.RiskInfo:
type: object
properties:
Expand All @@ -5116,6 +5227,33 @@ definitions:
description: >-
RiskInfo defines a borrower's account health without requiring sdk.Dec
formatting.
umee.leverage.v1.SpecialAssetPair:
type: object
properties:
collateral:
type: string
description: Collateral base token denom.
borrow:
type: string
description: Borrow base token denom.
collateral_weight:
type: string
description: >-
Collateral Weight defines what portion of the total value of the asset

can contribute to a users borrowing power. For special asset pairs,
this

also overrides the borrowed asset's collateral weight when evaluating
borrow

factor. Valid values: 0-1.
description: >-
SpecialAssetPair defines a special (increased) CollateralWeight used when
a specified Collateral is used

to collateralize a specified Borrow. This association is one-way (so it
does not work in reverse).
umee.leverage.v1.Token:
type: object
properties:
Expand Down
29 changes: 29 additions & 0 deletions x/leverage/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func GetQueryCmd() *cobra.Command {
cmd.AddCommand(
GetCmdQueryParams(),
GetCmdQueryRegisteredTokens(),
GetCmdQuerySpecialAssetPairs(),
GetCmdQueryMarketSummary(),
GetCmdQueryAccountBalances(),
GetCmdQueryAccountSummary(),
Expand Down Expand Up @@ -95,6 +96,34 @@ func GetCmdQueryRegisteredTokens() *cobra.Command {
return cmd
}

// GetCmdQuerySpecialAssetPairs creates a Cobra command to query for all
// the special asset pairs in the x/leverage module.
func GetCmdQuerySpecialAssetPairs() *cobra.Command {
cmd := &cobra.Command{
Use: "special-pairs",
Args: cobra.RangeArgs(0, 1),
Short: "Query for all currently registered special asset pairs",
toteki marked this conversation as resolved.
Show resolved Hide resolved
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
req := &types.QuerySpecialAssetPairs{}
if len(args) > 0 {
req.Denom = args[0]
}
resp, err := queryClient.SpecialAssetPairs(cmd.Context(), req)
return cli.PrintOrErr(resp, err, clientCtx)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdQueryMarketSummary creates a Cobra command to query for the
// Market Summary of a specific token.
func GetCmdQueryMarketSummary() *cobra.Command {
Expand Down
10 changes: 10 additions & 0 deletions x/leverage/client/tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ func (s *IntegrationTests) TestLeverageScenario() {
},
ErrMsg: "",
},
{
Name: "query special asset pairs",
Command: cli.GetCmdQuerySpecialAssetPairs(),
Args: []string{"uumee"},
Response: &types.QuerySpecialAssetPairsResponse{},
ExpectedResponse: &types.QuerySpecialAssetPairsResponse{
Pairs: []types.SpecialAssetPair{},
},
ErrMsg: "",
},
{
Name: "query registered token info by base_denom",
Command: cli.GetCmdQueryRegisteredTokens(),
Expand Down
5 changes: 5 additions & 0 deletions x/leverage/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {
for _, rate := range genState.InterestScalars {
util.Panic(k.setInterestScalar(ctx, rate.Denom, rate.Scalar))
}

for _, pair := range genState.SpecialPairs {
util.Panic(k.SetSpecialAssetPair(ctx, pair))
}
}

// ExportGenesis returns the x/leverage module's exported genesis state.
Expand All @@ -57,6 +61,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
k.getAllBadDebts(ctx),
k.getAllInterestScalars(ctx),
k.GetAllUTokenSupply(ctx),
k.GetAllSpecialAssetPairs(ctx),
)
}

Expand Down
Loading