Skip to content

Commit 42692b0

Browse files
committed
separate pool config from module params
1 parent 718f45b commit 42692b0

File tree

24 files changed

+3746
-1688
lines changed

24 files changed

+3746
-1688
lines changed

api/side/lending/lending.pulsar.go

Lines changed: 1488 additions & 254 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/side/lending/params.pulsar.go

Lines changed: 148 additions & 279 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/side/lending/query.pulsar.go

Lines changed: 297 additions & 224 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/side/lending/tx.pulsar.go

Lines changed: 401 additions & 308 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/side/lending/lending.proto

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,69 @@ import "cosmos/base/v1beta1/coin.proto";
77
import "side/btcbridge/btcbridge.proto";
88

99
option go_package = "github.com/sideprotocol/side/x/lending/types";
10+
1011
// Status options for a lending pool
1112
enum PoolStatus {
1213
ACTIVE = 0;
1314
INACTIVE = 1;
1415
}
1516

17+
// Lending pool config
18+
message PoolConfig {
19+
// supply rate permille
20+
uint32 supply_rate = 1;
21+
// borrow rate permille
22+
uint32 borrow_rate = 2;
23+
// reserve factor permille
24+
uint32 reserve_factor = 3;
25+
// supply cap
26+
string supply_cap = 4 [
27+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
28+
(gogoproto.nullable) = false
29+
];
30+
// borrow cap
31+
string borrow_cap = 5 [
32+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
33+
(gogoproto.nullable) = false
34+
];
35+
// debt ceiling
36+
string debt_ceiling = 6 [
37+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
38+
(gogoproto.nullable) = false
39+
];
40+
// origination fee
41+
string origination_fee = 7 [
42+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
43+
(gogoproto.nullable) = false
44+
];
45+
// maximum loan to value permille
46+
uint32 ltv = 8;
47+
// liquidation ltv permille
48+
uint32 liquidation_threshold = 9;
49+
// liquidation penalty permille
50+
uint32 liquidation_penalty = 10;
51+
}
52+
1653
message LendingPool {
1754
string id = 1;
18-
cosmos.base.v1beta1.Coin supply = 2;
19-
string total_shares = 3 [
20-
(gogoproto.customtype) = "cosmossdk.io/math.Int",
21-
(gogoproto.nullable) = false
22-
];
55+
cosmos.base.v1beta1.Coin supply = 2 [
56+
(gogoproto.nullable) = false,
57+
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coin"
58+
];
59+
string available_amount = 3 [
60+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
61+
(gogoproto.nullable) = false
62+
];
2363
string borrowed_amount = 4 [
24-
(gogoproto.customtype) = "cosmossdk.io/math.Int",
25-
(gogoproto.nullable) = false
26-
];
27-
PoolStatus status = 5;
64+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
65+
(gogoproto.nullable) = false
66+
];
67+
string total_shares = 5 [
68+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
69+
(gogoproto.nullable) = false
70+
];
71+
PoolConfig config = 6 [(gogoproto.nullable) = false];
72+
PoolStatus status = 7;
2873
}
2974

3075
// Loan Status

proto/side/lending/params.proto

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,18 @@ syntax = "proto3";
22
package side.lending;
33

44
import "gogoproto/gogo.proto";
5+
import "google/protobuf/duration.proto";
56

67
option go_package = "github.com/sideprotocol/side/x/lending/types";
78

8-
99
// Params defines the parameters for the module.
1010
message Params {
11-
12-
string supply_rate_permille = 1[
13-
(gogoproto.customtype) = "cosmossdk.io/math.Int",
14-
(gogoproto.nullable) = false
15-
];
16-
string borrow_rate_permille = 2[
17-
(gogoproto.customtype) = "cosmossdk.io/math.Int",
18-
(gogoproto.nullable) = false
19-
];
20-
string fee_recipient = 3;
11+
// origination fee collector address
12+
string origination_fee_collector = 1;
13+
// protocol fee collector address
14+
string protocol_fee_collector = 2;
15+
// final timeout duration for each loan
16+
google.protobuf.Duration final_timeout_duration = 3 [(gogoproto.nullable) = false, (gogoproto.stdduration) = true];
17+
// authorized pool creators
2118
repeated string pool_creators = 4;
22-
string min_initial_ltv_percent = 5 [
23-
(gogoproto.customtype) = "cosmossdk.io/math.Int",
24-
(gogoproto.nullable) = false
25-
];
26-
string liquidation_threshold_percent = 6[
27-
(gogoproto.customtype) = "cosmossdk.io/math.Int",
28-
(gogoproto.nullable) = false
29-
];
3019
}

proto/side/lending/query.proto

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ message QueryPoolsResponse {
8484
cosmos.base.query.v1beta1.PageResponse pagination = 2;
8585
}
8686

87-
message QueryLiquidationEventRequest{
88-
string collateral_amount = 1;
89-
string borrow_amount = 2;
87+
message QueryLiquidationEventRequest {
88+
string pool_id = 1;
89+
string collateral_amount = 2;
90+
string borrow_amount = 3;
9091
}
9192

9293
message QueryLiquidationEventResponse {

proto/side/lending/tx.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ service Msg {
3939

4040
message MsgCreatePool {
4141
option (cosmos.msg.v1.signer) = "creator";
42-
42+
4343
string creator = 1;
4444
string pool_id = 2;
4545
string lending_asset = 3;
46-
46+
PoolConfig config = 4 [(gogoproto.nullable) = false];
4747
}
4848

4949
message MsgCreatePoolResponse{}

x/lending/client/cli/query.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ func CmdQueryCollateralAddress() *cobra.Command {
172172

173173
func CmdQueryLiquidationEvent() *cobra.Command {
174174
cmd := &cobra.Command{
175-
Use: "liquidation-event [collateral amount] [borrowed amount]",
175+
Use: "liquidation-event [pool id] [collateral amount] [borrowed amount]",
176176
Short: "Query the corresponding liquidation event according to the collateral amount and borrowed amount",
177-
Args: cobra.ExactArgs(2),
177+
Args: cobra.ExactArgs(3),
178178
RunE: func(cmd *cobra.Command, args []string) error {
179179
clientCtx, err := client.GetClientQueryContext(cmd)
180180
if err != nil {
@@ -184,8 +184,9 @@ func CmdQueryLiquidationEvent() *cobra.Command {
184184
queryClient := types.NewQueryClient(clientCtx)
185185

186186
res, err := queryClient.LiquidationEvent(cmd.Context(), &types.QueryLiquidationEventRequest{
187-
CollateralAmount: args[0],
188-
BorrowAmount: args[1],
187+
PoolId: args[0],
188+
CollateralAmount: args[1],
189+
BorrowAmount: args[2],
189190
})
190191
if err != nil {
191192
return err

x/lending/client/cli/tx.go

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88

99
"github.com/spf13/cobra"
1010

11+
errorsmod "cosmossdk.io/errors"
12+
sdkmath "cosmossdk.io/math"
1113
"github.com/cosmos/cosmos-sdk/client"
1214
"github.com/cosmos/cosmos-sdk/client/flags"
1315
"github.com/cosmos/cosmos-sdk/client/tx"
@@ -53,19 +55,82 @@ func GetTxCmd() *cobra.Command {
5355

5456
func CmdCreatePool() *cobra.Command {
5557
cmd := &cobra.Command{
56-
Use: "create-pool [id] [lending asset]",
57-
Short: "Create a lending pool with the specified asset",
58-
Args: cobra.ExactArgs(2),
58+
Use: `create-pool [id] [lending asset] [supply rate] [borrow rate] [reserve factor] [supply cap]
59+
[borrow cap] [debt ceiling] [origination fee] [ltv] [liquidation threshold] [liquidation penalty]`,
60+
Short: "Create a lending pool with the specified params",
61+
Args: cobra.ExactArgs(12),
5962
RunE: func(cmd *cobra.Command, args []string) (err error) {
6063
clientCtx, err := client.GetClientTxContext(cmd)
6164
if err != nil {
6265
return err
6366
}
6467

68+
supplyRate, err := strconv.ParseUint(args[2], 10, 32)
69+
if err != nil {
70+
return err
71+
}
72+
73+
borrowRate, err := strconv.ParseUint(args[3], 10, 32)
74+
if err != nil {
75+
return err
76+
}
77+
78+
reserveFactor, err := strconv.ParseUint(args[4], 10, 32)
79+
if err != nil {
80+
return err
81+
}
82+
83+
supplyCap, ok := sdkmath.NewIntFromString(args[5])
84+
if !ok {
85+
return errorsmod.Wrap(types.ErrInvalidPoolConfig, "invalid supply cap")
86+
}
87+
88+
borrowCap, ok := sdkmath.NewIntFromString(args[6])
89+
if !ok {
90+
return errorsmod.Wrap(types.ErrInvalidPoolConfig, "invalid borrow cap")
91+
}
92+
93+
debtCeiling, ok := sdkmath.NewIntFromString(args[7])
94+
if !ok {
95+
return errorsmod.Wrap(types.ErrInvalidPoolConfig, "invalid debt ceiling")
96+
}
97+
98+
originationFee, ok := sdkmath.NewIntFromString(args[8])
99+
if !ok {
100+
return errorsmod.Wrap(types.ErrInvalidPoolConfig, "invalid origination fee")
101+
}
102+
103+
ltv, err := strconv.ParseUint(args[9], 10, 32)
104+
if err != nil {
105+
return err
106+
}
107+
108+
liquidationThreshold, err := strconv.ParseUint(args[10], 10, 32)
109+
if err != nil {
110+
return err
111+
}
112+
113+
liquidationPenalty, err := strconv.ParseUint(args[11], 10, 32)
114+
if err != nil {
115+
return err
116+
}
117+
65118
msg := types.NewMsgCreatePool(
66119
clientCtx.GetFromAddress().String(),
67120
args[0],
68121
args[1],
122+
types.PoolConfig{
123+
SupplyRate: uint32(supplyRate),
124+
BorrowRate: uint32(borrowRate),
125+
ReserveFactor: uint32(reserveFactor),
126+
SupplyCap: supplyCap,
127+
BorrowCap: borrowCap,
128+
DebtCeiling: debtCeiling,
129+
OriginationFee: originationFee,
130+
Ltv: uint32(ltv),
131+
LiquidationThreshold: uint32(liquidationThreshold),
132+
LiquidationPenalty: uint32(liquidationPenalty),
133+
},
69134
)
70135

71136
if err := msg.ValidateBasic(); err != nil {

0 commit comments

Comments
 (0)