Skip to content

Commit 32bb5be

Browse files
committed
Add pending pnl and net yield for GMX v2 market
1 parent 37e967c commit 32bb5be

File tree

7 files changed

+18
-33
lines changed

7 files changed

+18
-33
lines changed

demeter/gmx/_typing2.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class GmxV2Balance(MarketBalance):
1616
gm_amount: Decimal
1717
long_amount: Decimal
1818
short_amount: Decimal
19+
net_yield: Decimal
20+
pending_pnl: Decimal
1921

2022

2123
@dataclass

demeter/gmx/gmx_v2/MarketUtils.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Tuple
22

3-
from ._typing import PoolConfig, GmxV2PoolStatus, MarketPoolValueInfo
3+
from ._typing import PoolConfig, GmxV2PoolStatus
44

55

66
class MarketUtils:
@@ -86,15 +86,3 @@ def getTokenAmountsFromGM(
8686
def get_values(amount: float, price: float, decimal: float) -> Tuple[float, float]:
8787
return amount, amount * price
8888

89-
@staticmethod
90-
def getPoolValueInfo(pool_status: GmxV2PoolStatus) -> MarketPoolValueInfo:
91-
result = MarketPoolValueInfo()
92-
result.longTokenAmount = pool_status.longAmount
93-
result.shortTokenAmount = pool_status.shortAmount
94-
95-
result.longTokenUsd = result.longTokenAmount * pool_status.longPrice
96-
result.shortTokenUsd = result.shortTokenAmount * pool_status.shortPrice
97-
98-
result.poolValue = result.longTokenUsd + result.shortTokenUsd
99-
100-
return result

demeter/gmx/gmx_v2/_typing.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ class GmxV2PoolStatus:
5151
poolValue: float
5252
marketTokensSupply: float
5353
impactPoolAmount: float
54+
pendingPnl: float
55+
realizedNetYield: float
5456
longPrice: float
5557
shortPrice: float
5658
indexPrice: float
5759

5860

59-
6061
@dataclass
6162
class LPResult:
6263
long_amount: float
@@ -71,18 +72,3 @@ class LPResult:
7172
fee_usd: float
7273

7374
price_impact_usd: float
74-
75-
76-
@dataclass
77-
class MarketPoolValueInfo:
78-
poolValue: float = 0
79-
longPnl: float = 0
80-
shortPnl: float = 0
81-
netPnl: float = 0
82-
longTokenAmount: float = 0
83-
shortTokenAmount: float = 0
84-
longTokenUsd: float = 0
85-
shortTokenUsd: float = 0
86-
totalBorrowingFees: float = 0
87-
borrowingFeePoolFactor: float = 0
88-
impactPoolAmount: float = 0

demeter/gmx/market2.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,22 @@ def get_market_balance(self) -> GmxV2Balance:
8282
if self.amount > 0:
8383
pool_data: GmxV2PoolStatus = self._market_status.data
8484
longAmount, shortAmount = MarketUtils.getTokenAmountsFromGM(pool_data, self.amount)
85+
share = Decimal(self.amount / pool_data.marketTokensSupply)
8586
long_amount = Decimal(longAmount)
8687
short_amount = Decimal(shortAmount)
87-
net_value = Decimal(self.amount * pool_data.poolValue / pool_data.marketTokensSupply)
88+
net_value = Decimal(pool_data.poolValue) * share
89+
pending_pnl = Decimal(pool_data.pendingPnl) * share
90+
net_yield = Decimal(pool_data.realizedNetYield) * share
8891
else:
89-
net_value = long_amount = short_amount = Decimal(0)
92+
net_value = long_amount = short_amount = net_yield = pending_pnl = Decimal(0)
9093

9194
return GmxV2Balance(
9295
net_value=net_value,
9396
gm_amount=Decimal(self.amount),
9497
long_amount=long_amount,
9598
short_amount=short_amount,
99+
net_yield=net_yield,
100+
pending_pnl=pending_pnl,
96101
)
97102

98103
def formatted_str(self):

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
project = 'Demeter'
1616
copyright = '2024, zelos research'
1717
author = 'zelos research'
18-
release = '1.1.0'
18+
release = '1.1.1'
1919

2020
# -- General configuration ---------------------------------------------------
2121
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

release_note.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Ver 1.1.1
2+
3+
* Add pending pnl and net yield for GMX v2 market
4+
15
# Ver 1.1.0
26

37
* Add gmx v2 market

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name="zelos-demeter",
10-
version="1.1.0",
10+
version="1.1.1",
1111
packages=find_packages(exclude=["tests", "tests.*", "samples", "samples.*"]),
1212
url="https://zelos-demeter.readthedocs.io",
1313
license="MIT",

0 commit comments

Comments
 (0)