Skip to content

Commit 4b0231a

Browse files
committed
upgrade to v2.0.0-rc.15
1 parent f5a2f2b commit 4b0231a

16 files changed

Lines changed: 15356 additions & 5541 deletions

File tree

api/side/lending/lending.pulsar.go

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

api/side/liquidation/params.pulsar.go

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

app/app.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ import (
164164
upgradev2rc12 "github.com/sideprotocol/side/app/upgrades/v2_rc12"
165165
upgradev2rc13 "github.com/sideprotocol/side/app/upgrades/v2_rc13"
166166
upgradev2rc14 "github.com/sideprotocol/side/app/upgrades/v2_rc14"
167+
upgradev2rc15 "github.com/sideprotocol/side/app/upgrades/v2_rc15"
167168
upgradev2rc8 "github.com/sideprotocol/side/app/upgrades/v2_rc8"
168169
upgradev2rc9 "github.com/sideprotocol/side/app/upgrades/v2_rc9"
169170
)
@@ -1342,6 +1343,7 @@ func (app *App) SetUpgradeHandlers() {
13421343
app.UpgradeKeeper.SetUpgradeHandler(upgradev2rc12.UpgradeName, upgradev2rc12.CreateUpgradeHandler(app.ModuleManager, app.configurator))
13431344
app.UpgradeKeeper.SetUpgradeHandler(upgradev2rc13.UpgradeName, upgradev2rc13.CreateUpgradeHandler(app.ModuleManager, app.configurator))
13441345
app.UpgradeKeeper.SetUpgradeHandler(upgradev2rc14.UpgradeName, upgradev2rc14.CreateUpgradeHandler(app.ModuleManager, app.configurator))
1346+
app.UpgradeKeeper.SetUpgradeHandler(upgradev2rc15.UpgradeName, upgradev2rc15.CreateUpgradeHandler(app.ModuleManager, app.configurator))
13451347

13461348
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
13471349
if err != nil {

app/upgrades/v2_rc15/upgrade.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package v2_rc15
2+
3+
import (
4+
"context"
5+
6+
upgradetypes "cosmossdk.io/x/upgrade/types"
7+
"github.com/cosmos/cosmos-sdk/types/module"
8+
)
9+
10+
// UpgradeName is the upgrade version name
11+
const UpgradeName = "v2.0.0-rc.15"
12+
13+
// CreateUpgradeHandler creates the upgrade handler
14+
func CreateUpgradeHandler(
15+
mm *module.Manager,
16+
configurator module.Configurator,
17+
) upgradetypes.UpgradeHandler {
18+
return func(ctx context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
19+
return mm.RunMigrations(ctx, configurator, vm)
20+
}
21+
}

proto/side/lending/lending.proto

Lines changed: 135 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ message PoolTrancheConfig {
3838
];
3939
}
4040

41+
// Pool tranche config V1
42+
message PoolTrancheConfigV1 {
43+
// maturity duration in seconds
44+
int64 maturity = 1;
45+
// borrow apr permille
46+
uint32 borrow_apr = 2 [(gogoproto.customname) = "BorrowAPR"];
47+
}
48+
4149
// Pool config
4250
message PoolConfig {
4351
// collateral asset metadata
@@ -125,7 +133,7 @@ message PoolConfigV1 {
125133
(gogoproto.nullable) = false
126134
];
127135
// tranches
128-
repeated PoolTrancheConfig tranches = 7 [(gogoproto.nullable) = false];
136+
repeated PoolTrancheConfigV1 tranches = 7 [(gogoproto.nullable) = false];
129137
// request fee
130138
cosmos.base.v1beta1.Coin request_fee = 8 [
131139
(gogoproto.nullable) = false
@@ -147,6 +155,50 @@ message PoolConfigV1 {
147155
bool paused = 14;
148156
}
149157

158+
// Pool config V2
159+
message PoolConfigV2 {
160+
// collateral asset metadata
161+
AssetMetadata collateral_asset = 1 [(gogoproto.nullable) = false];
162+
// lending asset metadata
163+
AssetMetadata lending_asset = 2 [(gogoproto.nullable) = false];
164+
// supply cap
165+
string supply_cap = 3 [
166+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
167+
(gogoproto.nullable) = false
168+
];
169+
// borrow cap
170+
string borrow_cap = 4 [
171+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
172+
(gogoproto.nullable) = false
173+
];
174+
// minimum amount to be borrowed
175+
string min_borrow_amount = 5 [
176+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
177+
(gogoproto.nullable) = false
178+
];
179+
// maximum amount to be borrowed
180+
string max_borrow_amount = 6 [
181+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
182+
(gogoproto.nullable) = false
183+
];
184+
// tranches
185+
repeated PoolTrancheConfigV1 tranches = 7 [(gogoproto.nullable) = false];
186+
// request fee
187+
cosmos.base.v1beta1.Coin request_fee = 8 [
188+
(gogoproto.nullable) = false
189+
];
190+
// origination fee factor permille
191+
uint32 origination_fee_factor = 9;
192+
// reserve factor permille
193+
uint32 reserve_factor = 10;
194+
// maximum ltv percent
195+
uint32 max_ltv = 11;
196+
// liquidation ltv percent
197+
uint32 liquidation_threshold = 12;
198+
// indicates if the pool is paused
199+
bool paused = 13;
200+
}
201+
150202
// Pool tranche
151203
message PoolTranche {
152204
// maturity duration
@@ -237,6 +289,40 @@ message LendingPoolV1 {
237289
PoolStatus status = 11;
238290
}
239291

292+
message LendingPoolV2 {
293+
string id = 1;
294+
cosmos.base.v1beta1.Coin supply = 2 [
295+
(gogoproto.nullable) = false
296+
];
297+
string available_amount = 3 [
298+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
299+
(gogoproto.nullable) = false
300+
];
301+
string borrowed_amount = 4 [
302+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
303+
(gogoproto.nullable) = false
304+
];
305+
string total_borrowed = 5 [
306+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
307+
(gogoproto.nullable) = false
308+
];
309+
string reserve_amount = 6 [
310+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
311+
(gogoproto.nullable) = false
312+
];
313+
string total_reserve = 7 [
314+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
315+
(gogoproto.nullable) = false
316+
];
317+
cosmos.base.v1beta1.Coin total_ytokens = 8 [
318+
(gogoproto.nullable) = false,
319+
(gogoproto.customname) = "TotalYTokens"
320+
];
321+
repeated PoolTranche tranches = 9 [(gogoproto.nullable) = false];
322+
PoolConfigV2 config = 10 [(gogoproto.nullable) = false];
323+
PoolStatus status = 11;
324+
}
325+
240326
// Loan Status
241327
enum LoanStatus {
242328
// Unspecified
@@ -476,6 +562,54 @@ message LoanV3 {
476562
LoanStatus status = 25;
477563
}
478564

565+
message LoanV4 {
566+
string vault_address = 1; // id
567+
string borrower = 2;
568+
string borrowerPubKey = 3;
569+
string borrowerAuthPubKey = 4;
570+
string dcm = 5 [(gogoproto.customname) = "DCM"];
571+
int64 maturity_time = 6;
572+
int64 final_timeout = 7;
573+
string pool_id = 8;
574+
cosmos.base.v1beta1.Coin borrow_amount = 9 [(gogoproto.nullable) = false];
575+
cosmos.base.v1beta1.Coin request_fee = 10 [(gogoproto.nullable) = false];
576+
string origination_fee = 11 [
577+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
578+
(gogoproto.nullable) = false
579+
];
580+
string interest = 12 [
581+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
582+
(gogoproto.nullable) = false
583+
];
584+
string protocol_fee = 13 [
585+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
586+
(gogoproto.nullable) = false
587+
];
588+
int64 maturity = 14;
589+
uint32 borrow_apr = 15 [(gogoproto.customname) = "BorrowAPR"];
590+
string start_borrow_index = 16 [
591+
(cosmos_proto.scalar) = "cosmos.Dec",
592+
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
593+
(gogoproto.nullable) = false
594+
];
595+
string liquidation_price = 17 [
596+
(cosmos_proto.scalar) = "cosmos.Dec",
597+
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
598+
(gogoproto.nullable) = false
599+
];
600+
uint64 dlc_event_id = 18;
601+
repeated Authorization authorizations = 19 [(gogoproto.nullable) = false];
602+
string collateral_amount = 20 [
603+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
604+
(gogoproto.nullable) = false
605+
];
606+
uint64 liquidation_id = 21;
607+
Referrer referrer = 22;
608+
google.protobuf.Timestamp create_at = 23 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
609+
google.protobuf.Timestamp disburse_at = 24 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
610+
LoanStatus status = 25;
611+
}
612+
479613
// Referrer defines the referrer
480614
message Referrer {
481615
// Optional name

proto/side/liquidation/params.proto

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,16 @@ message Params {
2929
// protocol liquidation fee collector
3030
string protocol_liquidation_fee_collector = 4;
3131
}
32+
33+
34+
// ParamsV1 defines the V1 parameters for the module.
35+
message ParamsV1 {
36+
// minimum liquidation factor permille
37+
uint32 min_liquidation_factor = 1;
38+
// liquidation bonus factor permille
39+
uint32 liquidation_bonus_factor = 2;
40+
// protocol liquidation fee factor permille
41+
uint32 protocol_liquidation_fee_factor = 3;
42+
// protocol liquidation fee collector
43+
string protocol_liquidation_fee_collector = 4;
44+
}

x/lending/keeper/migrations.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
v3 "github.com/sideprotocol/side/x/lending/migrations/v3"
88
v4 "github.com/sideprotocol/side/x/lending/migrations/v4"
99
v5 "github.com/sideprotocol/side/x/lending/migrations/v5"
10+
v6 "github.com/sideprotocol/side/x/lending/migrations/v6"
1011
)
1112

1213
// Migrator is a struct for handling in-place store migrations
@@ -38,3 +39,8 @@ func (m Migrator) Migrate3to4(ctx sdk.Context) error {
3839
func (m Migrator) Migrate4to5(ctx sdk.Context) error {
3940
return v5.MigrateStore(ctx, m.keeper.storeKey, m.keeper.dlcKeeper, m.keeper.cdc)
4041
}
42+
43+
// Migrate5to6 migrates from version 5 to 6
44+
func (m Migrator) Migrate5to6(ctx sdk.Context) error {
45+
return v6.MigrateStore(ctx, m.keeper.storeKey, m.keeper.dlcKeeper, m.keeper.cdc)
46+
}

x/lending/migrations/v3/store.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func migratePools(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.Binar
7676
cdc.MustUnmarshal(iterator.Value(), &poolV1)
7777

7878
// build new pool
79-
pool := &types.LendingPool{
79+
pool := &types.LendingPoolV2{
8080
Id: poolV1.Id,
8181
Supply: poolV1.Supply,
8282
AvailableAmount: poolV1.AvailableAmount,
@@ -86,7 +86,7 @@ func migratePools(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.Binar
8686
TotalReserve: poolV1.TotalReserve,
8787
TotalYTokens: poolV1.TotalYTokens,
8888
Tranches: poolV1.Tranches,
89-
Config: types.PoolConfig{
89+
Config: types.PoolConfigV2{
9090
CollateralAsset: poolV1.Config.CollateralAsset,
9191
LendingAsset: poolV1.Config.LendingAsset,
9292
SupplyCap: poolV1.Config.SupplyCap,

x/lending/migrations/v4/store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func migrateLoans(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.Binar
3737
}
3838

3939
// build new loan
40-
loan := &types.Loan{
40+
loan := &types.LoanV4{
4141
VaultAddress: loanV3.VaultAddress,
4242
Borrower: loanV3.Borrower,
4343
BorrowerPubKey: loanV3.BorrowerPubKey,

x/lending/migrations/v6/store.go

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package v6
2+
3+
import (
4+
sdkmath "cosmossdk.io/math"
5+
storetypes "cosmossdk.io/store/types"
6+
"github.com/cosmos/cosmos-sdk/codec"
7+
sdk "github.com/cosmos/cosmos-sdk/types"
8+
9+
"github.com/sideprotocol/side/x/lending/types"
10+
)
11+
12+
// MigrateStore migrates the x/lending module state from the consensus version 5 to
13+
// version 6
14+
func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, dlcKeeper types.DLCKeeper, cdc codec.BinaryCodec) error {
15+
migrateLoans(ctx, storeKey, cdc)
16+
migratePools(ctx, storeKey, cdc)
17+
18+
return nil
19+
}
20+
21+
// migrateLoans performs the loan migration
22+
func migrateLoans(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) {
23+
store := ctx.KVStore(storeKey)
24+
25+
iterator := storetypes.KVStorePrefixIterator(store, types.LoanKeyPrefix)
26+
defer iterator.Close()
27+
28+
for ; iterator.Valid(); iterator.Next() {
29+
// unmarshal loan to v4
30+
var loanV4 types.LoanV4
31+
cdc.MustUnmarshal(iterator.Value(), &loanV4)
32+
33+
// build new loan
34+
loan := &types.Loan{
35+
VaultAddress: loanV4.VaultAddress,
36+
Borrower: loanV4.Borrower,
37+
BorrowerPubKey: loanV4.BorrowerPubKey,
38+
BorrowerAuthPubKey: loanV4.BorrowerAuthPubKey,
39+
DCM: loanV4.DCM,
40+
MaturityTime: loanV4.MaturityTime,
41+
FinalTimeout: loanV4.FinalTimeout,
42+
PoolId: loanV4.PoolId,
43+
BorrowAmount: loanV4.BorrowAmount,
44+
RequestFee: loanV4.RequestFee,
45+
OriginationFee: loanV4.OriginationFee,
46+
Interest: loanV4.Interest,
47+
ProtocolFee: loanV4.ProtocolFee,
48+
Maturity: loanV4.Maturity,
49+
BorrowAPR: sdkmath.LegacyNewDec(int64(loanV4.BorrowAPR)).QuoInt64(1000),
50+
StartBorrowIndex: loanV4.StartBorrowIndex,
51+
LiquidationPrice: loanV4.LiquidationPrice,
52+
DlcEventId: loanV4.DlcEventId,
53+
Authorizations: loanV4.Authorizations,
54+
CollateralAmount: loanV4.CollateralAmount,
55+
LiquidationId: loanV4.LiquidationId,
56+
Referrer: loanV4.Referrer,
57+
CreateAt: loanV4.CreateAt,
58+
DisburseAt: loanV4.DisburseAt,
59+
Status: loanV4.Status,
60+
}
61+
62+
// update loan
63+
store.Set(iterator.Key(), cdc.MustMarshal(loan))
64+
}
65+
}
66+
67+
// migratePools performs the pool migration
68+
func migratePools(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) {
69+
store := ctx.KVStore(storeKey)
70+
71+
iterator := storetypes.KVStorePrefixIterator(store, types.PoolKeyPrefix)
72+
defer iterator.Close()
73+
74+
for ; iterator.Valid(); iterator.Next() {
75+
// unmarshal pool to v2
76+
var poolV2 types.LendingPoolV2
77+
cdc.MustUnmarshal(iterator.Value(), &poolV2)
78+
79+
// build new pool
80+
pool := &types.LendingPool{
81+
Id: poolV2.Id,
82+
Supply: poolV2.Supply,
83+
AvailableAmount: poolV2.AvailableAmount,
84+
BorrowedAmount: poolV2.BorrowedAmount,
85+
TotalBorrowed: poolV2.TotalBorrowed,
86+
ReserveAmount: poolV2.ReserveAmount,
87+
TotalReserve: poolV2.TotalReserve,
88+
TotalYTokens: poolV2.TotalYTokens,
89+
Tranches: poolV2.Tranches,
90+
Config: types.PoolConfig{
91+
CollateralAsset: poolV2.Config.CollateralAsset,
92+
LendingAsset: poolV2.Config.LendingAsset,
93+
SupplyCap: poolV2.Config.SupplyCap,
94+
BorrowCap: poolV2.Config.BorrowCap,
95+
MinBorrowAmount: poolV2.Config.MinBorrowAmount,
96+
MaxBorrowAmount: poolV2.Config.MaxBorrowAmount,
97+
RequestFee: poolV2.Config.RequestFee,
98+
OriginationFeeFactor: sdkmath.LegacyNewDec(int64(poolV2.Config.OriginationFeeFactor)).QuoInt64(1000),
99+
ReserveFactor: sdkmath.LegacyNewDec(int64(poolV2.Config.ReserveFactor)).QuoInt64(1000),
100+
MaxLtv: sdkmath.LegacyNewDec(int64(poolV2.Config.MaxLtv)).QuoInt64(100),
101+
LiquidationThreshold: sdkmath.LegacyNewDec(int64(poolV2.Config.LiquidationThreshold)).QuoInt64(100),
102+
Paused: poolV2.Config.Paused,
103+
},
104+
Status: poolV2.Status,
105+
}
106+
107+
for _, tranche := range poolV2.Config.Tranches {
108+
pool.Config.Tranches = append(pool.Config.Tranches, types.PoolTrancheConfig{
109+
Maturity: tranche.Maturity,
110+
BorrowAPR: sdkmath.LegacyNewDec(int64(tranche.BorrowAPR)).QuoInt64(1000),
111+
})
112+
}
113+
114+
// update pool
115+
store.Set(iterator.Key(), cdc.MustMarshal(pool))
116+
}
117+
}

0 commit comments

Comments
 (0)