Skip to content

Commit 13e6238

Browse files
k-yangmatthiasmatt
andauthored
chore: adapt for v0.20.0b5 (#224)
* chore: adapt for v0.20.0b5 * fix: tests * chore: linting --------- Co-authored-by: Matthias <md2022@matrixsystems.co>
1 parent 0b386a2 commit 13e6238

21 files changed

+515
-693
lines changed

examples/1- Connect to nibiru py and query.ipynb

Lines changed: 168 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,37 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": null,
5+
"execution_count": 11,
66
"metadata": {},
77
"outputs": [],
88
"source": [
9-
"import nibiru"
9+
"import nibiru\n",
10+
"\n",
11+
"import json"
1012
]
1113
},
1214
{
1315
"cell_type": "code",
14-
"execution_count": null,
16+
"execution_count": 12,
1517
"metadata": {},
16-
"outputs": [],
18+
"outputs": [
19+
{
20+
"data": {
21+
"text/plain": [
22+
"'0.20.0b5'"
23+
]
24+
},
25+
"execution_count": 12,
26+
"metadata": {},
27+
"output_type": "execute_result"
28+
}
29+
],
1730
"source": [
1831
"nibiru.__version__"
1932
]
2033
},
2134
{
35+
"attachments": {},
2236
"cell_type": "markdown",
2337
"metadata": {},
2438
"source": [
@@ -40,14 +54,15 @@
4054
},
4155
{
4256
"cell_type": "code",
43-
"execution_count": null,
57+
"execution_count": 3,
4458
"metadata": {},
4559
"outputs": [],
4660
"source": [
47-
"network = nibiru.Network.devnet()"
61+
"network = nibiru.Network.testnet(1)"
4862
]
4963
},
5064
{
65+
"attachments": {},
5166
"cell_type": "markdown",
5267
"metadata": {},
5368
"source": [
@@ -56,23 +71,42 @@
5671
},
5772
{
5873
"cell_type": "code",
59-
"execution_count": null,
74+
"execution_count": 4,
6075
"metadata": {},
61-
"outputs": [],
76+
"outputs": [
77+
{
78+
"name": "stderr",
79+
"output_type": "stream",
80+
"text": [
81+
"WARNING:root:The mnemonic used for the newly generated key is: \n",
82+
"coin cart alone walnut busy basket shiver october buddy lamp company diet nominee hover phrase acoustic forget repair intact noise assist mountain review win\n",
83+
"WARNING:root:Please write down this key, it will NOT be recoverable otherwise\n"
84+
]
85+
}
86+
],
6287
"source": [
6388
"trader = nibiru.Sdk.authorize().with_network(network)"
6489
]
6590
},
6691
{
6792
"cell_type": "code",
68-
"execution_count": null,
93+
"execution_count": 5,
6994
"metadata": {},
70-
"outputs": [],
95+
"outputs": [
96+
{
97+
"name": "stdout",
98+
"output_type": "stream",
99+
"text": [
100+
"nibi17pz067rhcnyerjvn5lkzsf2ne3udtjmk7zjp3r\n"
101+
]
102+
}
103+
],
71104
"source": [
72105
"print(trader.address)"
73106
]
74107
},
75108
{
109+
"attachments": {},
76110
"cell_type": "markdown",
77111
"metadata": {},
78112
"source": [
@@ -81,41 +115,153 @@
81115
},
82116
{
83117
"cell_type": "code",
84-
"execution_count": null,
118+
"execution_count": 17,
85119
"metadata": {},
86-
"outputs": [],
120+
"outputs": [
121+
{
122+
"name": "stdout",
123+
"output_type": "stream",
124+
"text": [
125+
"[\n",
126+
" {\n",
127+
" \"id\": \"1\",\n",
128+
" \"address\": \"nibi1w00c7pqkr5z7ptewg5z87j2ncvxd88w43ug679\",\n",
129+
" \"poolParams\": {\n",
130+
" \"swapFee\": 0.01,\n",
131+
" \"exitFee\": 0.01,\n",
132+
" \"A\": \"0\"\n",
133+
" },\n",
134+
" \"poolAssets\": [\n",
135+
" {\n",
136+
" \"token\": {\n",
137+
" \"denom\": \"unibi\",\n",
138+
" \"amount\": \"16434695127\"\n",
139+
" },\n",
140+
" \"weight\": \"1073741824\"\n",
141+
" },\n",
142+
" {\n",
143+
" \"token\": {\n",
144+
" \"denom\": \"unusd\",\n",
145+
" \"amount\": \"2025755901517\"\n",
146+
" },\n",
147+
" \"weight\": \"1073741824\"\n",
148+
" }\n",
149+
" ],\n",
150+
" \"totalWeight\": \"2147483648\",\n",
151+
" \"totalShares\": {\n",
152+
" \"denom\": \"nibiru/pool/1\",\n",
153+
" \"amount\": \"16382308445118085345149\"\n",
154+
" }\n",
155+
" },\n",
156+
" {\n",
157+
" \"id\": \"2\",\n",
158+
" \"address\": \"nibi1vm70ju9n2laspspsh6fs2hu50z3qzf4m2emr0p\",\n",
159+
" \"poolParams\": {\n",
160+
" \"swapFee\": 0.01,\n",
161+
" \"exitFee\": 0.01,\n",
162+
" \"A\": \"10\",\n",
163+
" \"poolType\": \"STABLESWAP\"\n",
164+
" },\n",
165+
" \"poolAssets\": [\n",
166+
" {\n",
167+
" \"token\": {\n",
168+
" \"denom\": \"unusd\",\n",
169+
" \"amount\": \"336875701340\"\n",
170+
" },\n",
171+
" \"weight\": \"1073741824\"\n",
172+
" },\n",
173+
" {\n",
174+
" \"token\": {\n",
175+
" \"denom\": \"uusdt\",\n",
176+
" \"amount\": \"9586964043151\"\n",
177+
" },\n",
178+
" \"weight\": \"1073741824\"\n",
179+
" }\n",
180+
" ],\n",
181+
" \"totalWeight\": \"2147483648\",\n",
182+
" \"totalShares\": {\n",
183+
" \"denom\": \"nibiru/pool/2\",\n",
184+
" \"amount\": \"379679519187813492101905\"\n",
185+
" }\n",
186+
" }\n",
187+
"]\n"
188+
]
189+
}
190+
],
87191
"source": [
88-
"trader.query.perp.params()"
192+
"print(json.dumps(trader.query.spot.pools(), indent=4))"
89193
]
90194
},
91195
{
92196
"cell_type": "code",
93-
"execution_count": null,
197+
"execution_count": 20,
94198
"metadata": {},
95-
"outputs": [],
199+
"outputs": [
200+
{
201+
"name": "stdout",
202+
"output_type": "stream",
203+
"text": [
204+
"{\n",
205+
" \"liquidity\": [\n",
206+
" {\n",
207+
" \"denom\": \"unibi\",\n",
208+
" \"amount\": \"16434695127\"\n",
209+
" },\n",
210+
" {\n",
211+
" \"denom\": \"unusd\",\n",
212+
" \"amount\": \"2025755901517\"\n",
213+
" }\n",
214+
" ]\n",
215+
"}\n"
216+
]
217+
}
218+
],
96219
"source": [
97-
"trader.query.vpool.all_pools()"
220+
"print(json.dumps(trader.query.spot.total_pool_liquidity(1), indent=4))"
98221
]
99222
},
100223
{
101224
"cell_type": "code",
102-
"execution_count": null,
225+
"execution_count": 19,
103226
"metadata": {},
104-
"outputs": [],
227+
"outputs": [
228+
{
229+
"name": "stdout",
230+
"output_type": "stream",
231+
"text": [
232+
"{\n",
233+
" \"liquidity\": [\n",
234+
" {\n",
235+
" \"denom\": \"unibi\",\n",
236+
" \"amount\": \"16434695127\"\n",
237+
" },\n",
238+
" {\n",
239+
" \"denom\": \"unusd\",\n",
240+
" \"amount\": \"2362631602857\"\n",
241+
" },\n",
242+
" {\n",
243+
" \"denom\": \"uusdt\",\n",
244+
" \"amount\": \"9586964043151\"\n",
245+
" }\n",
246+
" ]\n",
247+
"}\n"
248+
]
249+
}
250+
],
105251
"source": [
106-
"# Let's format the previous query\n",
107-
"import json\n",
108-
"print(json.dumps(trader.query.vpool.all_pools(), indent=4))"
252+
"print(json.dumps(trader.query.spot.total_liquidity(), indent=4))"
109253
]
110254
},
111255
{
256+
"attachments": {},
112257
"cell_type": "markdown",
113258
"metadata": {},
114259
"source": [
115260
"You can find the documentation on query you can execute on the official documentation website: https://nibiru-py.readthedocs.io/en/latest/nibiru.query_clients.html"
116261
]
117262
},
118263
{
264+
"attachments": {},
119265
"cell_type": "markdown",
120266
"metadata": {},
121267
"source": []
@@ -137,7 +283,7 @@
137283
"name": "python",
138284
"nbconvert_exporter": "python",
139285
"pygments_lexer": "ipython3",
140-
"version": "3.10.4"
286+
"version": "3.8.16"
141287
},
142288
"orig_nbformat": 4,
143289
"vscode": {

nibiru/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
Network,
2727
NetworkType,
2828
PoolAsset,
29-
Side,
3029
TxConfig,
3130
TxType,
3231
)

nibiru/event_specs.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
from enum import Enum
33

44
import google.protobuf.message
5-
from nibiru_proto.proto.oracle.v1beta1 import event_pb2 as oracle_events
6-
from nibiru_proto.proto.perp.v1 import event_pb2 as perp_events
5+
from nibiru_proto.proto.oracle.v1 import event_pb2 as oracle_events
6+
from nibiru_proto.proto.perp.v2 import event_pb2 as perp_events
77
from nibiru_proto.proto.spot.v1 import event_pb2 as spot_events
8-
from nibiru_proto.proto.stablecoin import events_pb2 as stablecoin_events # noqa
9-
from nibiru_proto.proto.vpool.v1 import event_pb2 as vpool_events
8+
from nibiru_proto.proto.stablecoin.v1 import events_pb2 as stablecoin_events # noqa
109

1110

1211
class EventType(Enum):
@@ -20,11 +19,6 @@ class EventType(Enum):
2019
PositionLiquidatedEvent = perp_events.PositionLiquidatedEvent
2120
FundingRateChangedEvent = perp_events.FundingRateChangedEvent
2221

23-
# Vpool events
24-
ReserveSnapshotSavedEvent = vpool_events.ReserveSnapshotSavedEvent
25-
SwapOnVpoolEvent = vpool_events.SwapOnVpoolEvent
26-
MarkPriceChanged = vpool_events.MarkPriceChangedEvent
27-
2822
# Spot event
2923
PoolJoinedEvent = spot_events.EventPoolJoined
3024
PoolCreatedEvent = spot_events.EventPoolCreated

nibiru/grpc_client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,9 @@ def __init__(
7070
# Query services
7171
self.spot = query_clients.SpotQueryClient(self.chain_channel)
7272
self.perp = query_clients.PerpQueryClient(self.chain_channel)
73-
self.vpool = query_clients.VpoolQueryClient(self.chain_channel)
7473
self.epoch = query_clients.EpochQueryClient(self.chain_channel)
7574
self.auth = query_clients.AuthQueryClient(self.chain_channel)
7675
self.staking = query_clients.StakingQueryClient(self.chain_channel)
77-
self.util = query_clients.UtilQueryClient(self.chain_channel)
7876
self.stablecoin = query_clients.StablecoinQueryClient(self.chain_channel)
7977

8078
if not bypass_version_check:

nibiru/msg/perp.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import dataclasses
22
from typing import List
33

4-
from nibiru_proto.proto.perp.v1 import state_pb2 as state_pb
5-
from nibiru_proto.proto.perp.v1 import tx_pb2 as pb
4+
from nibiru_proto.proto.perp.v2 import state_pb2 as state_pb
5+
from nibiru_proto.proto.perp.v2 import tx_pb2 as pb
66

7-
from nibiru.pytypes import Coin, PythonMsg, Side
7+
from nibiru.pytypes import Coin, Direction, PythonMsg
88
from nibiru.utils import to_sdk_dec, to_sdk_int
99

1010

@@ -51,15 +51,10 @@ def open_position(
5151
base_asset_amount_limit (float): The minimum amount of base you are willing to receive for this amount of
5252
quote.
5353
"""
54-
side: Side
55-
if is_long:
56-
side = Side.BUY
57-
else:
58-
side = Side.SELL
5954
return MsgOpenPosition(
6055
sender=sender,
6156
pair=pair,
62-
side=side,
57+
dir=Direction.LONG if is_long else Direction.SHORT,
6358
quote_asset_amount=quote_asset_amount,
6459
leverage=leverage,
6560
base_asset_amount_limit=base_asset_amount_limit,
@@ -221,7 +216,7 @@ class MsgOpenPosition(PythonMsg):
221216

222217
sender: str
223218
pair: str
224-
side: Side
219+
dir: Direction
225220
quote_asset_amount: float
226221
leverage: float
227222
base_asset_amount_limit: float
@@ -234,7 +229,11 @@ def to_pb(self) -> pb.MsgOpenPosition:
234229
pb.MsgOpenPosition: The proto object.
235230
236231
"""
237-
pb_side = state_pb.Side.BUY if self.side == Side.BUY else state_pb.SELL
232+
pb_side = (
233+
state_pb.Direction.LONG
234+
if self.dir == Direction.LONG
235+
else state_pb.Direction.SHORT
236+
)
238237
quote_asset_amount_pb = to_sdk_int(self.quote_asset_amount)
239238
base_asset_amount_limit_pb = to_sdk_int(self.base_asset_amount_limit)
240239
leverage_pb = to_sdk_dec(self.leverage)

nibiru/pytypes/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
PoolAsset,
99
PoolType,
1010
PythonMsg,
11-
Side,
1211
TxConfig,
1312
TxType,
1413
)

0 commit comments

Comments
 (0)