Skip to content

Commit

Permalink
Merge pull request #3 from NibiruChain/jc/proto2
Browse files Browse the repository at this point in the history
Added pyi (type info) to generated protos + minor cleanup
  • Loading branch information
john-connor84 authored Jul 5, 2022
2 parents bb61a53 + a014956 commit ff40f78
Show file tree
Hide file tree
Showing 252 changed files with 19,961 additions and 172 deletions.
4 changes: 2 additions & 2 deletions examples/chain_client/msg_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async def main() -> None:

# build tx
gas_price = 1
gas_limit = sim_res.gas_info.gas_used + 2 # add 20k for gas, fee computation
gas_limit = sim_res.gas_info.gas_used + 20_000 # add 20k for gas, fee computation
gas_fee = '{:.18f}'.format((gas_price * gas_limit) / pow(10, 18)).rstrip('0')
fee = [composer.Coin(
amount=gas_price * gas_limit,
Expand All @@ -73,7 +73,7 @@ async def main() -> None:
tx_raw_bytes = tx.get_signed_tx_data()

# broadcast tx: send_tx_async_mode, send_tx_sync_mode, send_tx_block_mode
res = await client.send_tx_sync_mode(tx_raw_bytes)
res = await client.send_tx_block_mode(tx_raw_bytes)
print(res)
print("gas wanted: {}".format(gas_limit))
print("gas fee: {} unibi".format(gas_fee))
Expand Down
4 changes: 2 additions & 2 deletions nibiru/clients/dex_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def pools(self, **kwargs):
key = kwargs.get("key"),
offset = kwargs.get("offset"),
limit = kwargs.get("limit"),
countTotal = kwargs.get("count_total"),
count_total = kwargs.get("count_total"),
reverse = kwargs.get("reverse"),
),
)
Expand All @@ -50,7 +50,7 @@ async def total_liquidity(self):
return await self.api.TotalLiquidity(req)

async def total_pool_liquidity(self, pool_id: int):
req = dex_type.QueryTotalLiquidityRequest(poolId = pool_id)
req = dex_type.QueryTotalPoolLiquidityRequest(poolId = pool_id)
return await self.api.TotalPoolLiquidity(req)

async def total_shares(self, pool_id: int):
Expand Down
2 changes: 1 addition & 1 deletion nibiru/clients/perp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async def params(self):

async def trader_position(self, token_pair: str, trader: str):
req = perp_type.QueryTraderPositionRequest(
tokenPair = token_pair,
token_pair = token_pair,
trader = trader,
)
return await self.api.TraderPosition(req)
10 changes: 2 additions & 8 deletions nibiru/composer.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from time import time
import json
from dataclasses import dataclass

from google.protobuf import any_pb2, message, timestamp_pb2
from google.protobuf import any_pb2

from nibiru.composers import (
DexComposer, PerpComposer,
)

from .proto.cosmos.authz.v1beta1 import authz_pb2 as cosmos_authz_pb
from .proto.cosmos.authz.v1beta1 import tx_pb2 as cosmos_authz_tx_pb

from .proto.cosmos.bank.v1beta1 import tx_pb2 as cosmos_bank_tx_pb
Expand Down Expand Up @@ -63,13 +60,10 @@ def msg_delegate(
validator_address: str,
amount: float
):

be_amount = amount_to_backend(amount, 18)

return cosmos_staking_tx_pb.MsgDelegate(
delegator_address=delegator_address,
validator_address=validator_address,
amount=self.Coin(amount=be_amount, denom="inj"),
amount=self.Coin(amount=amount, denom="inj"),
)

def msg_withdraw_delegator_reward(
Expand Down
16 changes: 7 additions & 9 deletions nibiru/composers/dex_composer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from dataclasses import dataclass

from nibiru.proto.dex.v1 import (
tx_pb2 as dex_tx_pb,
pool_pb2 as pool_tx_pb,
Expand All @@ -24,21 +22,21 @@ def create_pool(self, creator: str, swap_fee: str, exit_fee: str, assets: List[P
def join_pool(self, sender: str, pool_id: int, tokens: List[coin_pb.Coin]):
return dex_tx_pb.MsgJoinPool(
sender = sender,
pool_id = pool_id,
tokens_in = tokens,
poolId = pool_id,
tokensIn = tokens,
)

def exit_pool(self, sender: str, pool_id: int, pool_shares: coin_pb.Coin):
return dex_tx_pb.MsgExitPool(
sender = sender,
pool_id = pool_id,
pool_shares = pool_shares,
poolId = pool_id,
poolShares = pool_shares,
)

def swap_assets(self, sender: str, pool_id: int, token_in: coin_pb.Coin, token_out_denom):
return dex_tx_pb.MsgSwapAssets(
sender = sender,
pool_id = pool_id,
token_in = token_in,
token_out_denom = token_out_denom,
poolId = pool_id,
tokenIn = token_in,
tokenOutDenom = token_out_denom,
)
8 changes: 4 additions & 4 deletions nibiru/composers/perp_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ class PerpComposer:
def remove_margin(self, sender: str, token_pair: str, margin: coin_pb.Coin):
return tx.MsgRemoveMargin(
sender = sender,
tokenPair = token_pair,
token_pair = token_pair,
margin = margin,
)

def add_margin(self, sender: str, token_pair: str, margin: coin_pb.Coin):
return tx.MsgAddMargin(
sender = sender,
tokenPair = token_pair,
token_pair = token_pair,
margin = margin,
)

def liquidate(self, sender: str, token_pair: str, trader: str):
return tx.MsgLiquidate(
sender = sender,
tokenPair = token_pair,
token_pair = token_pair,
trader = trader,
)

Expand All @@ -44,5 +44,5 @@ def open_position(self, sender: str, token_pair: str, side: Side, quote_asset_am
def close_position(self, sender: str, token_pair: str):
return tx.MsgClosePosition(
sender = sender,
tokenPair = token_pair,
token_pair = token_pair,
)
12 changes: 1 addition & 11 deletions nibiru/proto/common/common_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions nibiru/proto/common/common_pb2.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
@generated by mypy-protobuf. Do not edit manually!
isort:skip_file
"""
import builtins
import google.protobuf.descriptor
import google.protobuf.message
import typing
import typing_extensions

DESCRIPTOR: google.protobuf.descriptor.FileDescriptor

class AssetPair(google.protobuf.message.Message):
DESCRIPTOR: google.protobuf.descriptor.Descriptor
TOKEN0_FIELD_NUMBER: builtins.int
TOKEN1_FIELD_NUMBER: builtins.int
token0: typing.Text
token1: typing.Text
def __init__(self,
*,
token0: typing.Text = ...,
token1: typing.Text = ...,
) -> None: ...
def ClearField(self, field_name: typing_extensions.Literal["token0",b"token0","token1",b"token1"]) -> None: ...
global___AssetPair = AssetPair
4 changes: 4 additions & 0 deletions nibiru/proto/common/common_pb2_grpc.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
@generated by mypy-protobuf. Do not edit manually!
isort:skip_file
"""
Loading

0 comments on commit ff40f78

Please sign in to comment.