Skip to content

Commit

Permalink
refactor(perp)!: PositionLiquidatedEvent (#1466)
Browse files Browse the repository at this point in the history
* refactor(perp): position liquidated event

* refactor(perp): new position liquidated event

* refactor(perp): clean up liquidation response logic

* Update CHANGELOG.md
  • Loading branch information
k-yang authored Jul 1, 2023
1 parent c1ee1a9 commit 652ce78
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 843 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Improvements

* #[1466](https://github.com/NibiruChain/nibiru/pull/1466) - refactor(perp): `PositionLiquidatedEvent`

### Features

* [#1463](https://github.com/NibiruChain/nibiru/pull/1463) - feat(oracle): add genesis pricefeeder delegation
Expand Down
74 changes: 7 additions & 67 deletions proto/nibiru/perp/v2/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -71,86 +71,26 @@ message PositionChangedEvent {
[ (gogoproto.customtype) = "ChangeReason", (gogoproto.nullable) = false ];
}

// Emitted when a position is liquidated.
// Emitted when a position is liquidated. Wraps a PositionChanged event since a
// liquidation causes position changes.
message PositionLiquidatedEvent {
// identifier of the corresponding virtual pool for the position
string pair = 1 [
(gogoproto.customtype) =
"github.com/NibiruChain/nibiru/x/common/asset.Pair",
(gogoproto.nullable) = false
];

// owner of the position.
string trader_address = 2;

// margin * leverage * vPrice. 'notional' is the virtual size times the
// virtual price on 'perp.amm'.
string exchanged_quote_amount = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// virtual amount of base assets for the position, which would be margin *
// leverage * priceBasePerQuote.
string exchanged_position_size = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
PositionChangedEvent position_changed_event = 1
[ (gogoproto.nullable) = false ];

// Address of the account that executed the tx.
string liquidator_address = 5;
string liquidator_address = 2;

// Commission (in margin units) received by 'liquidator'.
cosmos.base.v1beta1.Coin fee_to_liquidator = 6 [
cosmos.base.v1beta1.Coin fee_to_liquidator = 3 [
(gogoproto.moretags) = "yaml:\"fee_to_liquidator\"",
(gogoproto.nullable) = false
];

// Commission (in margin units) given to the ecosystem fund.
cosmos.base.v1beta1.Coin fee_to_ecosystem_fund = 7 [
cosmos.base.v1beta1.Coin fee_to_ecosystem_fund = 4 [
(gogoproto.moretags) = "yaml:\"fee_to_ecosystem_fund\"",
(gogoproto.nullable) = false
];

// Bad debt (margin units) cleared by the PerpEF during the tx. Bad debt is
// negative net margin past the liquidation point of a position.
cosmos.base.v1beta1.Coin bad_debt = 8 [ (gogoproto.nullable) = false ];

// Remaining margin in the position after liquidation
cosmos.base.v1beta1.Coin margin = 9 [
(gogoproto.moretags) = "yaml:\"margin\"",
(gogoproto.nullable) = false
];

// Remaining position notional in the position after liquidation
string position_notional = 10 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// Remaining position size in the position after liquidation
string position_size = 11 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// Unrealized PnL in the position after liquidation
string unrealizedPnl = 12 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// Spot price of the vAMM after liquidation
string mark_price = 13 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// The block number at which this liquidation occured.
int64 block_height = 14;

// The unix timestamp in milliseconds at which this liquidation occured.
int64 block_time_ms = 15;
}

// Emitted when a position is settled.
Expand Down
Loading

0 comments on commit 652ce78

Please sign in to comment.