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

updates collateral #95

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 24 additions & 21 deletions proto/reserve/vaults/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -71,54 +71,56 @@ message MsgActiveCollateral {
option (gogoproto.goproto_getters) = false;
option (cosmos.msg.v1.signer) = "authority";

string denom = 1;
string collateral_denom = 1;
string collateral_symbol = 2;

string min_collateral_ratio = 2 [
string min_collateral_ratio = 3 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(amino.dont_omitempty) = true,
(gogoproto.nullable) = false
];

string liquidation_ratio = 3 [
string liquidation_ratio = 4 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(amino.dont_omitempty) = true,
(gogoproto.nullable) = false
];

string max_debt = 4 [
string max_debt = 5 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(amino.dont_omitempty) = true,
(gogoproto.nullable) = false
];

string stability_fee = 5 [
string stability_fee = 6 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(amino.dont_omitempty) = true,
(gogoproto.nullable) = false
];

string liquidation_penalty = 6 [
string liquidation_penalty = 7 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(amino.dont_omitempty) = true,
(gogoproto.nullable) = false
];

string minting_fee = 7 [
string minting_fee = 8 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(amino.dont_omitempty) = true,
(gogoproto.nullable) = false
];
uint64 oracl_script = 8;
uint64 oracl_script = 9;

string authority = 10 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

string authority = 9 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
string sym_bol = 10;
string mint_denom = 11;
string mint_symbol = 12;
}

// MsgActiveCollateralResponse defines the Msg/ActiveCollateral response type.
Expand All @@ -130,55 +132,56 @@ message MsgUpdatesCollateral {
option (gogoproto.goproto_getters) = false;
option (cosmos.msg.v1.signer) = "authority";

string denom = 1;
string collateral_denom = 1;
string collateral_sym_bol = 2;

string min_collateral_ratio = 2 [
string min_collateral_ratio = 3 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(amino.dont_omitempty) = true,
(gogoproto.nullable) = false
];

string liquidation_ratio = 3 [
string liquidation_ratio = 4 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(amino.dont_omitempty) = true,
(gogoproto.nullable) = false
];

string max_debt = 4 [
string max_debt = 5 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(amino.dont_omitempty) = true,
(gogoproto.nullable) = false
];

string stability_fee = 5 [
string stability_fee = 6 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(amino.dont_omitempty) = true,
(gogoproto.nullable) = false
];

string liquidation_penalty = 6 [
string liquidation_penalty = 7 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(amino.dont_omitempty) = true,
(gogoproto.nullable) = false
];

string minting_fee = 7 [
string minting_fee = 8 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(amino.dont_omitempty) = true,
(gogoproto.nullable) = false
];

uint64 oracl_script = 8;
uint64 oracl_script = 9;

string authority = 9 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
string sym_bol = 10;
string mint_denom = 11;
string authority = 10 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
string sym_bol = 11;
string mint_denom = 12;
}

// MsgActiveCollateralResponse defines the Msg/ActiveCollateral response type.
Expand Down
10 changes: 6 additions & 4 deletions script/proposal-vault-1.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
{
"messages": [{
"@type": "/reserve.vaults.MsgActiveCollateral",
"denom": "usdt",
"collateral_denom": "usdt",
"collateral_symbol":"usdt",
"authority":"onomy10d07y265gmmuvt4z0w9aw880jnsr700jqr8n8k",
"min_collateral_ratio": "0.5",
"liquidation_ratio":"0.5",
"max_debt":"1000000000000000000000000000",
"sym_bol": "usdt",
"oracl_script": "44",
"mint_denom": "nomUSD",
"mint_symbol":"USD",
"stability_fee": "0.1"
},
{
"@type": "/reserve.vaults.MsgActiveCollateral",
"denom": "atom",
"collateral_denom": "atom",
"collateral_symbol":"ATOM",
"authority":"onomy10d07y265gmmuvt4z0w9aw880jnsr700jqr8n8k",
"min_collateral_ratio": "0.5",
"liquidation_ratio":"0.5",
"max_debt":"1000000000000000000000000000",
"sym_bol": "atom",
"oracl_script": "44",
"mint_denom": "nomUSD",
"mint_symbol":"USD",
"stability_fee": "0.1"
}],
"deposit": "100000000stake",
Expand Down
1 change: 0 additions & 1 deletion script/vaults-gov-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,3 @@ reserved tx vaults create-vault 1250000000atom 50000000nomUSD --home=$HOME/.rese
# 02420E85EC300BE3E9219C5D8330207451F0D33764
# liquidationMap map[]
# nextId 0 <nil>
# 10:26AM ERR panic recovered in runTx err="recovered: module account reserve does not exist: unknown address [cosmos/[email protected]/x/bank/keeper/keeper.go:286]\nstack:\ngoroutine 438 [running]:\nruntime/debug.Stack()\n\t/usr/local/go/src/runtime/debug/stack.go:26 +0x64\ngithub.com/cosmos/cosmos-sdk/baseapp.NewBaseApp.newDefaultRecoveryMiddleware.func5({0x106011480, 0x140023cc840})\n\t/Users/donglieu/go/pkg/mod/github.com/cosmos/[email protected]/baseapp/recovery.go:74 +0x24\ngithub.com/cosmos/cosmos-sdk/baseapp.NewBaseApp.newDefaultRecoveryMiddleware.newRecoveryMiddleware.func7({0x106011480?, 0x140023cc840?})\n\t/Users/donglieu/go/pkg/mod/github.com/cosmos/[email protected]/baseapp/recovery.go:42 +0x38\ngithub.com/cosmos/cosmos-sdk/baseapp.processRecovery({0x106011480, 0x140023cc840}, 0x14003c493d8?)\n\t/Users/donglieu/go/pkg/mod/github.com/cosmos/[email protected]/baseapp/recovery.go:31 +0x38\ngithub.com/cosmos/cosmos-sdk/baseapp.processRecovery({0x106011480, 0x140023cc840}, 0x8?)\n\t/Users/donglieu/go/pkg/mod/github.com/cosmos/[email protected]/baseapp/recovery.go:36 +0x60\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runTx.func1()\n\t/Users/donglieu/go/pkg/mod/github.com/cosmos/[email protected]/baseapp/baseapp.go:837 +0xd4\npanic({0x106011480?, 0x140023cc840?})\n\t/usr/local/go/src/runtime/panic.go:785 +0x124\ngithub.com/cosmos/cosmos-sdk/x/bank/keeper.BaseKeeper.SendCoinsFromModuleToModule({{{{0x106376aa0, 0x14000d05160}, {0x1063259e0, 0x14001588318}, {0x10637e670, 0x14000355400}, {0x106364930, 0x1400208e620}, {0x140015946a8, {...}, ...}, ...}, ...}, ...}, ...)\n\t/Users/donglieu/go/pkg/mod/github.com/cosmos/[email protected]/x/bank/keeper/keeper.go:286 +0x15c\ngithub.com/onomyprotocol/reserve/x/vaults/keeper.(*Keeper).CreateNewVault(0x14003c4aab8, {0x10635c228, 0x14006ab5080}, {0x140023664b0, 0x14, 0x15}, {{0x140019fcb80?, 0x1063259c0?}, {0x14001b59520?}}, {{0x140019fcbc0?, ...}, ...})\n\t/Users/donglieu/102024/main/reserve/x/vaults/keeper/vault.go:68 +0x3dc\ngithub.com/onomyprotocol/reserve/x/vaults/keeper.msgServer.CreateVault({{{0x106376aa0, 0x14000d05160}, {0x1063259e0, 0x140015883a0}, {0x1519327e8, 0x14000595688}, {0x10633ca60, 0x140015fd040}, {0x106336280, 0x14000be1c78}, ...}}, ...)\n\t/Users/donglieu/102024/main/reserve/x/vaults/keeper/msg_server.go:67 +0x74\ngithub.com/onomyprotocol/reserve/x/vaults/types._Msg_CreateVault_Handler.func1({0x10635c228?, 0x14006ab5080?}, {0x1061a5b00?, 0x14006296080?})\n\t/Users/donglieu/102024/main/reserve/x/vaults/types/tx.pb.go:1102 +0xd0\ngithub.com/cosmos/cosmos-sdk/baseapp.(*MsgServiceRouter).registerMsgServiceHandler.func2.1({0x10635c0d8, 0x14003c68008}, {0x14003c4b098?, 0x103f592f0?}, 0x358?, 0x140011a5bc0)\n\t/Users/donglieu/go/pkg/mod/github.com/cosmos/[email protected]/baseapp/msg_service_router.go:175 +0x98\ngithub.com/onomyprotocol/reserve/x/vaults/types._Msg_CreateVault_Handler({0x1062c7640, 0x140012ca008}, {0x10635c0d8, 0x14003c68008}, 0x1063132e8, 0x14001b59580)\n\t/Users/donglieu/102024/main/reserve/x/vaults/types/tx.pb.go:1104 +0x148\ngithub.com/cosmos/cosmos-sdk/baseapp.(*MsgServiceRouter).registerMsgServiceHandler.func2({{0x10635c0a0, 0x107e7b100}, {0x106377360, 0x14006296100}, {{0x0, 0x0}, {0x14001c322a0, 0x9}, 0x67, {0x60f9708, ...}, ...}, ...}, ...)\n\t/Users/donglieu/go/pkg/mod/github.com/cosmos/[email protected]/baseapp/msg_service_router.go:198 +0x2b0\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runMsgs(_, {{0x10635c0a0, 0x107e7b100}, {0x106377360, 0x14006296100}, {{0x0, 0x0}, {0x14001c322a0, 0x9}, 0x67, ...}, ...}, ...)\n\t/Users/donglieu/go/pkg/mod/github.com/cosmos/[email protected]/baseapp/baseapp.go:1010 +0x170\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runTx(0x140023fc248, 0x7, {0x140014f4140, 0x123, 0x123})\n\t/Users/donglieu/go/pkg/mod/github.com/cosmos/[email protected]/baseapp/baseapp.go:948 +0xbf8\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).deliverTx(0x140023fc248, {0x140014f4140?, 0x123?, 0x14001a01540?})\n\t/Users/donglieu/go/pkg/mod/github.com/cosmos/[email protected]/baseapp/baseapp.go:763 +0x88\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).internalFinalizeBlock(0x140023fc248, {0x10635c0a0, 0x107e7b100}, 0x14003c33b00)\n\t/Users/donglieu/go/pkg/mod/github.com/cosmos/[email protected]/baseapp/abci.go:790 +0xc2c\ngithub.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).FinalizeBlock(0x140023fc248, 0x14003c33b00)\n\t/Users/donglieu/go/pkg/mod/github.com/cosmos/[email protected]/baseapp/abci.go:884 +0x118\ngithub.com/cosmos/cosmos-sdk/server.cometABCIWrapper.FinalizeBlock(...)\n\t/Users/donglieu/go/pkg/mod/github.com/cosmos/[email protected]/server/cmt_abci.go:44\ngithub.com/cometbft/cometbft/abci/client.(*localClient).FinalizeBlock(0x14001688c20?, {0x10635c308?, 0x107e7b100?}, 0x10a8b0a68?)\n\t/Users/donglieu/go/pkg/mod/github.com/cometbft/[email protected]/abci/client/local_client.go:185 +0xe4\ngithub.com/cometbft/cometbft/proxy.(*appConnConsensus).FinalizeBlock(0x14001a040c0, {0x10635c308, 0x107e7b100}, 0x14003c33b00)\n\t/Users/donglieu/go/pkg/mod/github.com/cometbft/[email protected]/proxy/app_conn.go:104 +0x124\ngithub.com/cometbft/cometbft/state.(*BlockExecutor).applyBlock(_, {{{0xb, 0x0}, {0x14000a14069, 0x7}}, {0x14000a14080, 0x9}, 0x1, 0x66, {{0x140061a1b20, ...}, ...}, ...}, ...)\n\t/Users/donglieu/go/pkg/mod/github.com/cometbft/[email protected]/state/execution.go:224 +0x410\ngithub.com/cometbft/cometbft/state.(*BlockExecutor).ApplyVerifiedBlock(...)\n\t/Users/donglieu/go/pkg/mod/github.com/cometbft/[email protected]/state/execution.go:202\ngithub.com/cometbft/cometbft/consensus.(*State).finalizeCommit(0x1400248b508, 0x67)\n\t/Users/donglieu/go/pkg/mod/github.com/cometbft/[email protected]/consensus/state.go:1772 +0x97c\ngithub.com/cometbft/cometbft/consensus.(*State).tryFinalizeCommit(0x1400248b508, 0x67)\n\t/Users/donglieu/go/pkg/mod/github.com/cometbft/[email protected]/consensus/state.go:1682 +0x26c\ngithub.com/cometbft/cometbft/consensus.(*State).enterCommit.func1()\n\t/Users/donglieu/go/pkg/mod/github.com/cometbft/[email protected]/consensus/state.go:1617 +0x8c\ngithub.com/cometbft/cometbft/consensus.(*State).enterCommit(0x1400248b508, 0x67, 0x0)\n\t/Users/donglieu/go/pkg/mod/github.com/cometbft/[email protected]/consensus/state.go:1655 +0xac0\ngithub.com/cometbft/cometbft/consensus.(*State).addVote(0x1400248b508, 0x14001334750, {0x14001004090, 0x28})\n\t/Users/donglieu/go/pkg/mod/github.com/cometbft/[email protected]/consensus/state.go:2335 +0x182c\ngithub.com/cometbft/cometbft/consensus.(*State).tryAddVote(0x1400248b508, 0x14001334750, {0x14001004090?, 0x103dd81c4?})\n\t/Users/donglieu/go/pkg/mod/github.com/cometbft/[email protected]/consensus/state.go:2067 +0x28\ngithub.com/cometbft/cometbft/consensus.(*State).handleMsg(0x1400248b508, {{0x10632e320, 0x14000e82200}, {0x14001004090, 0x28}})\n\t/Users/donglieu/go/pkg/mod/github.com/cometbft/[email protected]/consensus/state.go:929 +0x2fc\ngithub.com/cometbft/cometbft/consensus.(*State).receiveRoutine(0x1400248b508, 0x0)\n\t/Users/donglieu/go/pkg/mod/github.com/cometbft/[email protected]/consensus/state.go:836 +0x2b8\ncreated by github.com/cometbft/cometbft/consensus.(*State).OnStart in goroutine 372\n\t/Users/donglieu/go/pkg/mod/github.com/cometbft/[email protected]/consensus/state.go:398 +0xf0\n: panic" module=server
4 changes: 2 additions & 2 deletions x/vaults/keeper/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (s *KeeperTestSuite) TestBeginBlock() {
name: "success: one vault",
setup: func() { // 100000000000atom debt 210000000nomUSD(get 200000000nomUSD + 10000000nomUSD MintingFee)
err := s.k.ActiveCollateralAsset(s.Ctx,
denom, denom, "nomUSD", math.LegacyMustNewDecFromStr("1.6"),
denom, denom, "nomUSD", "USD", math.LegacyMustNewDecFromStr("1.6"),
math.LegacyMustNewDecFromStr("1.5"),
maxDebt, stabilityFee,
types.DefaultMintingFee,
Expand Down Expand Up @@ -62,7 +62,7 @@ func (s *KeeperTestSuite) TestBeginBlock() {
name: "success: no vault, LastUpdateTime updates",
setup: func() { // 100000000000atom debt 210000000nomUSD(get 200000000nomUSD + 10000000nomUSD MintingFee)
err := s.k.ActiveCollateralAsset(s.Ctx,
denom, denom, "nomUSD", math.LegacyMustNewDecFromStr("1.6"),
denom, denom, "nomUSD", "USD", math.LegacyMustNewDecFromStr("1.6"),
math.LegacyMustNewDecFromStr("1.5"),
maxDebt, stabilityFee,
types.DefaultMintingFee,
Expand Down
23 changes: 12 additions & 11 deletions x/vaults/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ func (k Keeper) GetAuthority() string {

func (k *Keeper) ActiveCollateralAsset(
ctx context.Context,
denom string,
symbol string,
mintDenom string,
CollateralDenom string,
CollateralSymbol string,
MintDenom string,
MintSymbol string,
minCollateralRatio math.LegacyDec,
liquidationRatio math.LegacyDec,
maxDebt math.Int,
Expand All @@ -87,16 +88,16 @@ func (k *Keeper) ActiveCollateralAsset(
oracleScript int64,
) error {
// Check if asset alreay be actived
actived := k.IsActived(ctx, denom)
actived := k.IsActived(ctx, CollateralDenom)
if actived {
return fmt.Errorf("denom %s already be actived", denom)
return fmt.Errorf("denom %s already be actived", CollateralDenom)
}
vm := types.VaultMamager{
Denom: denom,
Symbol: symbol,
Denom: CollateralDenom,
Symbol: CollateralSymbol,
Params: types.VaultMamagerParams{
MintDenom: mintDenom,
MintSymbol: symbol,
MintDenom: MintDenom,
MintSymbol: MintSymbol,
MinCollateralRatio: minCollateralRatio,
LiquidationRatio: liquidationRatio,
MaxDebt: maxDebt,
Expand All @@ -106,12 +107,12 @@ func (k *Keeper) ActiveCollateralAsset(
},
MintAvailable: maxDebt,
}
err := k.OracleKeeper.AddNewSymbolToBandOracleRequest(ctx, denom, oracleScript)
err := k.OracleKeeper.AddNewSymbolToBandOracleRequest(ctx, CollateralSymbol, oracleScript)
if err != nil {
return err
}

return k.VaultsManager.Set(ctx, denom, vm)
return k.VaultsManager.Set(ctx, CollateralDenom, vm)
}

func (k *Keeper) UpdatesCollateralAsset(
Expand Down
1 change: 1 addition & 0 deletions x/vaults/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func (s *KeeperTestSuite) SetupTest() {
mockOK := mock.NewMockOracleKeeper()
mockOK.SetPrice("atom", math.LegacyMustNewDecFromStr("8.0"))
mockOK.SetPrice(types.DefaultMintDenoms[0], math.LegacyMustNewDecFromStr("1"))
mockOK.SetPrice("USD", math.LegacyMustNewDecFromStr("1"))
s.App.VaultsKeeper.OracleKeeper = mockOK
s.k = s.App.VaultsKeeper
s.msgServer = keeper.NewMsgServerImpl(s.k)
Expand Down
4 changes: 2 additions & 2 deletions x/vaults/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (k msgServer) ActiveCollateral(ctx context.Context, msg *types.MsgActiveCol
return nil, errorsmod.Wrapf(types.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, msg.Authority)
}

err = k.ActiveCollateralAsset(ctx, msg.Denom, msg.SymBol, msg.MintDenom, msg.MinCollateralRatio, msg.LiquidationRatio, msg.MaxDebt, msg.StabilityFee, msg.MintingFee, msg.LiquidationPenalty, int64(msg.OraclScript))
err = k.ActiveCollateralAsset(ctx, msg.CollateralDenom, msg.CollateralSymbol, msg.MintDenom, msg.MintSymbol, msg.MinCollateralRatio, msg.LiquidationRatio, msg.MaxDebt, msg.StabilityFee, msg.MintingFee, msg.LiquidationPenalty, int64(msg.OraclScript))
if err != nil {
return nil, err
}
Expand All @@ -64,7 +64,7 @@ func (k msgServer) UpdatesCollateral(ctx context.Context, msg *types.MsgUpdatesC
return nil, errorsmod.Wrapf(types.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, msg.Authority)
}

err = k.UpdatesCollateralAsset(ctx, msg.Denom, msg.MinCollateralRatio, msg.LiquidationRatio, msg.MaxDebt, msg.StabilityFee, msg.MintingFee, msg.LiquidationPenalty)
err = k.UpdatesCollateralAsset(ctx, msg.CollateralDenom, msg.MinCollateralRatio, msg.LiquidationRatio, msg.MaxDebt, msg.StabilityFee, msg.MintingFee, msg.LiquidationPenalty)
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions x/vaults/keeper/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (k *Keeper) CreateNewVault(
return fmt.Errorf("%s was not actived", denom)
}
collateralSymbol := vm.Symbol
mintDenom := vm.Params.MintDenom
mintSymbol := vm.Params.MintSymbol

allowedMintDenoms := k.GetAllowedMintDenoms(ctx)
// TODO: Check if mint denom is allowed
Expand All @@ -45,8 +45,7 @@ func (k *Keeper) CreateNewVault(
}

// Calculate collateral ratio
price := k.OracleKeeper.GetPrice(ctx, collateralSymbol, mintDenom)
fmt.Println(price, collateralSymbol, mintDenom)
price := k.OracleKeeper.GetPrice(ctx, collateralSymbol, mintSymbol)
if price == nil || price.IsNil() {
return errors.Wrapf(oracletypes.ErrInvalidOracle, "CreateNewVault: can not get price with base %s quote %s", denom, types.DefaultMintDenoms)
}
Expand Down
Loading
Loading