Skip to content

Commit

Permalink
chore: add partial close position on nibi perp (#222)
Browse files Browse the repository at this point in the history
* feat: partial close position on nibi perp

* refactor: upgrading protojs in nibijs package

* refactor: updating proto

---------

Co-authored-by: Cameron Gilbert <[email protected]>
  • Loading branch information
CalicoNino and cgilbe27 authored Sep 14, 2023
1 parent ea820c5 commit 1afbc87
Show file tree
Hide file tree
Showing 6 changed files with 11,433 additions and 11,753 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ temp

examples/foo.ts

proto/

### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
Expand Down
2 changes: 1 addition & 1 deletion packages/nibijs/docs/classes/StableSwap.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ y()
Calculate x[j] if one makes x[i] = x

Done by solving quadratic equation iteratively.
x*1**2 + x1 * (sum' - (A*n**n - 1) * D / (A _ n**n)) = D ** (n+1)/(n \*\* (2 _ n) \_ prod' \* A)
x*1\*\*2 + x1 * (sum' - (A*n\*\*n - 1) * D / (A _ n**n)) = D ** (n+1)/(n \*\* (2 _ n) \_ prod' \* A)
x_1\*\*2 + b\*x_1 = c

x_1 = (x_1\**2 + c) / (2*x_1 + b)
Expand Down
2 changes: 1 addition & 1 deletion packages/nibijs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@cosmjs/proto-signing": "^0.31.0",
"@cosmjs/stargate": "^0.31.0",
"@cosmjs/tendermint-rpc": "^0.31.0",
"@nibiruchain/protojs": "^0.21.11",
"@nibiruchain/protojs": "^0.21.13",
"bignumber.js": "^9.1.1",
"cross-fetch": "^3.1.5",
"long": "^5.2.0"
Expand Down
12 changes: 12 additions & 0 deletions packages/nibijs/src/msg/perp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
MsgMultiLiquidate,
MsgMarketOrder,
MsgRemoveMargin,
MsgPartialClose,
protobufPackage,
} from "@nibiruchain/protojs/dist/nibiru/perp/v2/tx"
import { Direction } from "@nibiruchain/protojs/dist/nibiru/perp/v2/state"
Expand All @@ -19,6 +20,7 @@ export const PERP_MSG_TYPE_URLS = {
MsgMarketOrder: `/${protobufPackage}.MsgMarketOrder`,
MsgClosePosition: `/${protobufPackage}.MsgClosePosition`,
MsgDonateToEcosystemFund: `/${protobufPackage}.MsgDonateToEcosystemFund`,
MsgPartialClose: `/${protobufPackage}.MsgPartialClose`,
}

export const perpTypes: ReadonlyArray<[string, GeneratedType]> = [
Expand All @@ -28,6 +30,7 @@ export const perpTypes: ReadonlyArray<[string, GeneratedType]> = [
[PERP_MSG_TYPE_URLS.MsgMarketOrder, MsgMarketOrder],
[PERP_MSG_TYPE_URLS.MsgClosePosition, MsgClosePosition],
[PERP_MSG_TYPE_URLS.MsgDonateToEcosystemFund, MsgDonateToEcosystemFund],
[PERP_MSG_TYPE_URLS.MsgPartialClose, MsgPartialClose],
]

export interface MsgAddMarginEncodeObject extends EncodeObject {
Expand Down Expand Up @@ -86,6 +89,15 @@ export const isMsgDonateToEcosystemFundEncodeObject = (
(encodeObject as MsgDonateToEcosystemFundEncodeObject).typeUrl ===
PERP_MSG_TYPE_URLS.MsgDonateToEcosystemFund

export interface MsgPartialClosEncodeObject extends EncodeObject {
readonly typeUrl: string
readonly value: Partial<MsgDonateToEcosystemFund>
}

export const isMsgPartialClosEncodeObject = (encodeObject: EncodeObject) =>
(encodeObject as MsgPartialClosEncodeObject).typeUrl ===
PERP_MSG_TYPE_URLS.MsgPartialClose

// ----------------------------------------------------------------------------

export class PerpMsgFactory {
Expand Down
2 changes: 1 addition & 1 deletion packages/nibijs/src/test/query.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "fs"
import { Block, coins } from "@cosmjs/stargate"
import Long from "long"
import { fetch } from "cross-fetch"
import fs from "fs"
import { NibiruQueryClient } from "../query"
import {
TEST_CHAIN,
Expand Down
Loading

0 comments on commit 1afbc87

Please sign in to comment.