Skip to content

Commit 49f912e

Browse files
amityadav0avkr003
andauthored
Stablestake Fixes (elys-network#1221)
* use new key * stablestake * migrate * fixes * review changes * update * fix * version * cov * add debt and interest queries * adding testnet migration * adding unit test cases * adding unit test cases * removing unused function * adding logs for debugging * removing redundant code * review changes * fix * fix * deposit * check * check * pool * remove comments * test * add query tests * total * testnet * changes for testnet upgrade handler * changes for testnet upgrade handler * changes for testnet upgrade handler * add to genesis --------- Co-authored-by: avkr003 <[email protected]> Co-authored-by: Abhinav Kumar <[email protected]>
1 parent 19b016f commit 49f912e

File tree

19 files changed

+4280
-446
lines changed

19 files changed

+4280
-446
lines changed

api/elys/stablestake/genesis.pulsar.go

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

api/elys/stablestake/query.pulsar.go

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

api/elys/stablestake/query_grpc.pb.go

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

app/setup_handlers.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package app
22

33
import (
44
"context"
5+
errorsmod "cosmossdk.io/errors"
56
"fmt"
67
"strings"
78

@@ -10,7 +11,6 @@ import (
1011

1112
sdk "github.com/cosmos/cosmos-sdk/types"
1213

13-
errorsmod "cosmossdk.io/errors"
1414
wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types"
1515
m "github.com/cosmos/cosmos-sdk/types/module"
1616
"github.com/cosmos/cosmos-sdk/version"
@@ -62,6 +62,10 @@ func (app *ElysApp) setUpgradeHandler() {
6262
ctx := sdk.UnwrapSDKContext(goCtx)
6363
app.Logger().Info("Running upgrade handler for " + upgradeVersion)
6464

65+
if ctx.ChainID() == "elysicstestnet-1" {
66+
app.StablestakeKeeper.TestnetMigrate(ctx)
67+
}
68+
6569
vm, vmErr := app.mm.RunMigrations(ctx, app.configurator, vm)
6670

6771
//oracleParams := app.OracleKeeper.GetParams(ctx)
@@ -73,13 +77,15 @@ func (app *ElysApp) setUpgradeHandler() {
7377
//}
7478

7579
// Set cosmwasm params
76-
wasmParams := wasmTypes.DefaultParams()
77-
wasmParams.CodeUploadAccess = wasmTypes.AllowNobody
78-
wasmParams.InstantiateDefaultPermission = wasmTypes.AccessTypeNobody
79-
if err := app.WasmKeeper.SetParams(ctx, wasmParams); err != nil {
80-
return vm, errorsmod.Wrapf(err, "unable to set CosmWasm params")
80+
if plan.Name == "v3" {
81+
wasmParams := wasmTypes.DefaultParams()
82+
wasmParams.CodeUploadAccess = wasmTypes.AllowNobody
83+
wasmParams.InstantiateDefaultPermission = wasmTypes.AccessTypeNobody
84+
if err := app.WasmKeeper.SetParams(ctx, wasmParams); err != nil {
85+
return vm, errorsmod.Wrapf(err, "unable to set CosmWasm params")
86+
}
87+
app.Logger().Info("Successfully set wasm Params in UpgradeHandler")
8188
}
82-
app.Logger().Info("Successfully set wasm Params in UpgradeHandler")
8389

8490
return vm, vmErr
8591
},
@@ -98,7 +104,7 @@ func (app *ElysApp) setUpgradeStore() {
98104

99105
app.Logger().Debug("Upgrade info", "info", upgradeInfo)
100106

101-
if shouldLoadUpgradeStore(app, upgradeInfo) {
107+
if shouldLoadUpgradeStore(app, upgradeInfo) && upgradeInfo.Name == "v3" {
102108
storeUpgrades := storetypes.StoreUpgrades{
103109
Added: []string{wasmTypes.StoreKey},
104110
//Added: []string{},

proto/elys/stablestake/genesis.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import "gogoproto/gogo.proto";
55
import "elys/stablestake/params.proto";
66
import "elys/stablestake/debt.proto";
77
import "elys/stablestake/types.proto";
8+
import "elys/stablestake/pool.proto";
89

910
option go_package = "github.com/elys-network/elys/x/stablestake/types";
1011

@@ -13,4 +14,6 @@ message GenesisState {
1314
Params params = 1 [ (gogoproto.nullable) = false ];
1415
repeated Debt debt_list = 2 [ (gogoproto.nullable) = false ];
1516
repeated InterestBlock interest_list = 3 [ (gogoproto.nullable) = false ];
17+
repeated Pool pools = 4 [ (gogoproto.nullable) = false ];
18+
repeated AmmPool amm_pools = 5 [ (gogoproto.nullable) = false ];
1619
}

proto/elys/stablestake/query.proto

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import "google/api/annotations.proto";
66
import "cosmos/base/query/v1beta1/pagination.proto";
77
import "elys/stablestake/params.proto";
88
import "elys/stablestake/pool.proto";
9+
import "elys/stablestake/types.proto";
10+
import "elys/stablestake/debt.proto";
911
import "cosmos_proto/cosmos.proto";
1012

1113
option go_package = "github.com/elys-network/elys/x/stablestake/types";
@@ -41,6 +43,16 @@ service Query {
4143
option (google.api.http).get =
4244
"/elys-network/elys/stablestake/all-amm-pools";
4345
}
46+
47+
rpc Debt(QueryDebtRequest) returns (QueryDebtResponse) {
48+
option (google.api.http).get =
49+
"/elys-network/elys/stablestake/debt/{pool_id}/{address}";
50+
}
51+
52+
rpc GetInterest(QueryGetInterestRequest) returns (QueryGetInterestResponse) {
53+
option (google.api.http).get =
54+
"/elys-network/elys/stablestake/interest/{pool_id}/{block_height}";
55+
}
4456
}
4557

4658
// QueryParamsRequest is request type for the Query/Params RPC method.
@@ -170,4 +182,20 @@ message PoolResponse {
170182
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
171183
(gogoproto.nullable) = false
172184
];
185+
}
186+
187+
message QueryDebtRequest {
188+
uint64 pool_id = 1;
189+
string address = 2;
190+
}
191+
192+
message QueryDebtResponse { Debt debt = 1 [ (gogoproto.nullable) = false ]; }
193+
194+
message QueryGetInterestRequest {
195+
uint64 pool_id = 1;
196+
uint64 block_height = 2;
197+
}
198+
199+
message QueryGetInterestResponse {
200+
InterestBlock interest_block = 1 [ (gogoproto.nullable) = false ];
173201
}

x/stablestake/autocli.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,29 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
3434
Use: "all-amm-pools",
3535
Short: "Query all amm pools liabilities",
3636
},
37+
{
38+
RpcMethod: "Pool",
39+
Use: "pool [pool-id]",
40+
Short: "Query pool",
41+
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "pool_id"}},
42+
},
43+
{
44+
RpcMethod: "Pools",
45+
Use: "pools",
46+
Short: "Query all pools",
47+
},
48+
{
49+
RpcMethod: "Debt",
50+
Use: "debt [pool-id] [address]",
51+
Short: "Query debt",
52+
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "pool_id"}, {ProtoField: "address"}},
53+
},
54+
{
55+
RpcMethod: "GetInterest",
56+
Use: "interest [pool-id] [block-height]",
57+
Short: "Query interest",
58+
PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "pool_id"}, {ProtoField: "block_height"}},
59+
},
3760
},
3861
},
3962
Tx: &autocliv1.ServiceCommandDescriptor{

x/stablestake/genesis.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
1515

1616
// Set all the interests
1717
for _, elem := range genState.InterestList {
18-
k.SetInterestForPool(ctx, elem.PoolId, elem.BlockHeight, elem)
18+
k.SetInterestForPool(ctx, elem)
19+
}
20+
21+
// Set all pools
22+
for _, elem := range genState.Pools {
23+
k.SetPool(ctx, elem)
24+
}
25+
26+
// Set all amm pools
27+
for _, elem := range genState.AmmPools {
28+
k.SetAmmPool(ctx, elem)
1929
}
2030

2131
// this line is used by starport scaffolding # genesis/module/init
@@ -30,6 +40,9 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
3040
genesis.DebtList = k.GetAllDebts(ctx)
3141
genesis.InterestList = k.GetAllInterest(ctx)
3242

43+
genesis.Pools = k.GetAllPools(ctx)
44+
genesis.AmmPools = k.GetAllAmmPools(ctx)
45+
3346
// this line is used by starport scaffolding # genesis/module/export
3447

3548
return genesis

x/stablestake/keeper/begin_blocker.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ func (k Keeper) UpdateInterestForAllPools(ctx sdk.Context) {
2424
for _, pool := range pools {
2525
pool.InterestRate = k.InterestRateComputationForPool(ctx, pool)
2626
k.SetPool(ctx, pool)
27-
k.SetInterestForPool(ctx, pool.Id, uint64(ctx.BlockHeight()), types.InterestBlock{InterestRate: pool.InterestRate, BlockTime: ctx.BlockTime().Unix(), BlockHeight: uint64(ctx.BlockHeight())})
27+
k.SetInterestForPool(ctx, types.InterestBlock{
28+
InterestRate: pool.InterestRate,
29+
BlockTime: ctx.BlockTime().Unix(),
30+
BlockHeight: uint64(ctx.BlockHeight()),
31+
PoolId: pool.Id,
32+
})
2833
}
2934
}

0 commit comments

Comments
 (0)