-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat, cli (perp): MsgLiquidate (#426)
* wip: Add liquidate initial code * feat: Add liquidation fee to params * feat: Allow multiple margin ratio calculation method * wip: Evaluate position to liquidate * test: test commit * feat: Add partial liquidation ratio * wip: squeletton for liquidation * feat: Add liquidation keeper function * feat: Add is over spread limit initial function * fix: Minor issue in error comments * fix: Fix calls in tests for new create pool parameter * feat: Add withdraw and send to IF * fix: Usemax oracle spread ratio in vpool * fix: Fix test failing because mustnewdec annoyingly need a left 0 * feat: Add initial test for liquidate (wip) * feat: ADd happy path test for no liquidaiton done * fix: Adujust max base on short * Pass oldPosition into keeper methods Also refactored trader to sdk.AccAddress * Add tests for GetPositionNotionalAndUnrealizedPnl * Delete interfaces.go * Add tests for getPreferencePositionNotionalAndUnrealizedPnL * Add comments for getPositionNotionalAndUnrealizedPnL * Test GetPositionNotionalAndUnrealizedPnl with ORACLE prices * wip: Error on the set params * fix: Fix casing for params * test: boilerplate test for createLiquidation test * fix: Fix module name issue in the testing function * tests: Add test for create liquidation * tests: Test individual close position functions * fix: SetParams panics due to missing transient store * fix (margin.go): bug in GetMarginRatio * fix, #wip * fix: Add send module to module keeper * feat: Happy path for margin high enough * fix wip: almost done with happy liquidate path * fix: liquidate happy path runs * test (liquidate): uncomment margin ok test case * refactor (liquidate.go): Prevent transfers with zero amount inputs * refactor (liquidate.go): Build output at end fo fn in CreateLiquidation * feat (perp): Liquidate proto rpc method with passing tests * cli (perp): LiquidateCmd connected to app * rename liquidation_test.go -> liquidate_unit_test.go * refactor, tests: Make types consistent on liquidate proto message. (2) ValidateBasic tests * Update x/perp/spec/02_msgs_and_client.md Co-authored-by: Walter White <101130700+NibiruHeisenberg@users.noreply.github.com> Co-authored-by: Matthias Darblade <matthias.darblade@gmail.com> Co-authored-by: MD <matthias@matrixsystems.co> Co-authored-by: Mat-Cosmos <97468149+matthiasmatt@users.noreply.github.com> Co-authored-by: Walter White <heisenberg@matrixsystems.co> Co-authored-by: Walter White <101130700+MatrixHeisenberg@users.noreply.github.com> Co-authored-by: Walter White <101130700+NibiruHeisenberg@users.noreply.github.com>
- Loading branch information
1 parent
b691edf
commit 47e1ed8
Showing
17 changed files
with
428 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Messages and Client <!-- omit in toc --> | ||
|
||
This page describes the message (`Msg`) structures and expected state transitions that these messages bring about when wrapped in transactions. These descriptions are accompanied by documentation for their corresponding CLI commands. | ||
|
||
- [OpenPosition](#openposition) | ||
- [ClosePosition](#closeposition) | ||
- [AddMargin](#addmargin) | ||
- [RemoveMargin](#removemargin) | ||
- [Liquidate](#liquidate) | ||
|
||
## OpenPosition | ||
|
||
`OpenPosition` defines a method for opening or altering a new position, which sends funds the vault to the trader, realizing any outstanding profits and losses (PnL), funding payments, and bad debt. | ||
|
||
#### `OpenPosition` CLI command: | ||
// TODO: | ||
```sh | ||
nibid tx perp open-perp --vpool --side --margin --leverage --base-limit | ||
``` | ||
|
||
This command has several required flags: | ||
- `vpool`: Identifier for the position's virtual pool. | ||
- `side`: Either "long" or "short" | ||
- `margin`: The amount of collateral input to back the position. This collateral is the quote asset of the 'vpool'. | ||
- `leverage`: A decimal number between 1 and 10 (inclusive) that specifies how much leverage the trader wishes to take on. | ||
- `base-limit`: Limiter to ensure the trader doesn't get screwed by slippage. | ||
|
||
|
||
## ClosePosition | ||
|
||
`ClosePosition` defines a method for closing a trader's position, which sends funds the vault to the trader, realizing any outstanding profits and losses (PnL), funding payments, and bad debt. | ||
|
||
#### `ClosePosition` CLI command: | ||
|
||
```sh | ||
nibid tx perp close-perp [vpool] | ||
``` | ||
|
||
## AddMargin | ||
|
||
`AddMargin` deleverages a trader's position by adding margin to it without altering its notional value. Adding margin increases the margin ratio of the position. | ||
|
||
```go | ||
type MsgAddMargin struct { | ||
// Sender: sdk.AccAddress of the owner of the position | ||
Sender string | ||
// TokenPair: identifier for the position's virtual pool | ||
TokenPair string | ||
// Margin: Amount of margin (quote units) to add to the position | ||
Margin sdk.Coin | ||
} | ||
``` | ||
|
||
#### `AddMargin` CLI command: | ||
|
||
```sh | ||
nibid tx perp add-margin [vpool] [margin] | ||
``` | ||
|
||
## RemoveMargin | ||
|
||
`RemoveMargin` further leverages a trader's position by removing some of the margin that backs it without altering its notional value. Removing margin decreases the margin ratio of the position and increases the risk of liquidation. | ||
|
||
#### `RemoveMargin` CLI command: | ||
|
||
```sh | ||
nibid tx perp remove-margin [vpool] [margin] | ||
# example | ||
nibid tx perp remove-margin atom:nusd 100nusd | ||
``` | ||
|
||
## Liquidate | ||
|
||
```sh | ||
nibid tx perp liquidate [vpool] [trader] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# State | ||
|
||
Describes the structures expected to be marshalled into the store and their keys. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Events |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.