From f13639cd78a52219972be453501f84d8373971df Mon Sep 17 00:00:00 2001 From: John Connor Date: Fri, 22 Jul 2022 16:28:27 -0700 Subject: [PATCH 1/2] Added pricefeed module --- nibiru/client.py | 4 +- nibiru/clients/__init__.py | 1 + nibiru/clients/pricefeed.py | 45 +++++++++++ nibiru/common.py | 2 +- nibiru/composer.py | 3 +- nibiru/composers/__init__.py | 1 + nibiru/composers/dex.py | 4 +- nibiru/composers/pricefeed.py | 17 ++++ nibiru/proto/perp/v1/tx_pb2.py | 60 +++++++++----- nibiru/proto/perp/v1/tx_pb2.pyi | 43 +++++++++- nibiru/proto/pricefeed/tx_pb2.py | 127 ++++++++++++++++++------------ nibiru/proto/pricefeed/tx_pb2.pyi | 8 +- nibiru/sdks/tx/common.py | 4 +- nibiru/sdks/tx/pricefeed.py | 11 +++ nibiru/sdks/tx/tx_client.py | 2 + nibiru/utils.py | 13 ++- 16 files changed, 261 insertions(+), 84 deletions(-) create mode 100644 nibiru/clients/pricefeed.py create mode 100644 nibiru/composers/pricefeed.py create mode 100644 nibiru/sdks/tx/pricefeed.py diff --git a/nibiru/client.py b/nibiru/client.py index 2eb80d35..b092c5da 100644 --- a/nibiru/client.py +++ b/nibiru/client.py @@ -8,6 +8,7 @@ from .clients import Dex as DexClient from .clients import Perp as PerpClient +from .clients import Pricefeed as PricefeedClient from .clients import VPool as VPoolClient from .exceptions import NotFoundError from .network import Network @@ -28,7 +29,6 @@ from .proto.epochs import query_pb2_grpc as epochs_query from .proto.incentivization.v1 import incentivization_pb2_grpc as incentivization_query from .proto.lockup.v1 import query_pb2_grpc as lockup_query -from .proto.pricefeed import query_pb2_grpc as pricefeed_query from .proto.stablecoin import query_pb2_grpc as stablecoin_query DEFAULT_TIMEOUTHEIGHT_SYNC_INTERVAL = 10 # seconds @@ -91,7 +91,7 @@ def __init__( ) # Query services self.dex = DexClient(self.exchange_channel) - self.stubPricefeed = pricefeed_query.QueryStub(self.exchange_channel) + self.pricefeed = PricefeedClient(self.exchange_channel) self.perp = PerpClient(self.exchange_channel) self.stubLockup = lockup_query.QueryStub(self.exchange_channel) self.stubIncentivization = incentivization_query.QueryStub(self.exchange_channel) diff --git a/nibiru/clients/__init__.py b/nibiru/clients/__init__.py index d36b82fc..f3e45e7c 100644 --- a/nibiru/clients/__init__.py +++ b/nibiru/clients/__init__.py @@ -1,3 +1,4 @@ from .dex import Dex # noqa from .perp import Perp # noqa +from .pricefeed import Pricefeed # noqa from .vpool import VPool # noqa diff --git a/nibiru/clients/pricefeed.py b/nibiru/clients/pricefeed.py new file mode 100644 index 00000000..f680826f --- /dev/null +++ b/nibiru/clients/pricefeed.py @@ -0,0 +1,45 @@ +from grpc import Channel + +from nibiru.proto.pricefeed import query_pb2 as pf_type +from nibiru.proto.pricefeed import query_pb2_grpc as pf_query + +from .util import deserialize + + +class Pricefeed: + """ + Pricefeed allows to query the endpoints made available by the Nibiru Chain's Pricefeed module. + """ + + def __init__(self, channel: Channel): + self.api = pf_query.QueryStub(channel) + + def params(self): + req = pf_type.QueryParamsRequest() + return deserialize(self.api.QueryParams(req)) + + def price(self, pair_id: str): + req = pf_type.QueryPriceRequest( + pair_id=pair_id, + ) + return deserialize(self.api.QueryPrice(req)) + + def prices(self): + req = pf_type.QueryPricesRequest() + return deserialize(self.api.QueryPrices(req)) + + def raw_prices(self, pair_id: str): + req = pf_type.QueryRawPricesRequest( + pair_id=pair_id, + ) + return deserialize(self.api.QueryRawPrices(req)) + + def oracles(self, pair_id: str): + req = pf_type.QueryOraclesRequest( + pair_id=pair_id, + ) + return deserialize(self.api.QueryOracles(req)) + + def markets(self): + req = pf_type.QueryMarketsRequest() + return deserialize(self.api.QueryMarkets(req)) diff --git a/nibiru/common.py b/nibiru/common.py index 227784d5..f42f2ccb 100644 --- a/nibiru/common.py +++ b/nibiru/common.py @@ -23,7 +23,7 @@ class Direction(Enum): @dataclass class PoolAsset: token: coin_pb.Coin - weight: str + weight: int class TxConfig: diff --git a/nibiru/composer.py b/nibiru/composer.py index 2d15385c..433f8180 100644 --- a/nibiru/composer.py +++ b/nibiru/composer.py @@ -2,7 +2,7 @@ from google.protobuf import any_pb2 -from .composers import Dex, Perp +from .composers import Dex, Perp, Pricefeed 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 from .proto.cosmos.base.v1beta1 import coin_pb2 as cosmos_base_coin_pb @@ -13,6 +13,7 @@ class Composer: dex = Dex perp = Perp + pricefeed = Pricefeed @staticmethod def coin(amount: float, denom: str): diff --git a/nibiru/composers/__init__.py b/nibiru/composers/__init__.py index 1d7a3df4..598102e7 100644 --- a/nibiru/composers/__init__.py +++ b/nibiru/composers/__init__.py @@ -1,2 +1,3 @@ from .dex import Dex # noqa from .perp import Perp # noqa +from .pricefeed import Pricefeed # noqa diff --git a/nibiru/composers/dex.py b/nibiru/composers/dex.py index 474bfe36..8a833128 100644 --- a/nibiru/composers/dex.py +++ b/nibiru/composers/dex.py @@ -9,8 +9,8 @@ class Dex: @staticmethod - def create_pool(creator: str, swap_fee: float, exit_fee: float, assets: List[PoolAsset]): - pool_assets = [pool_tx_pb.PoolAsset(token=a.token, weight=a.weight) for a in assets] + def create_pool(creator: str, assets: List[PoolAsset], swap_fee: float = 0, exit_fee: float = 0): + pool_assets = [pool_tx_pb.PoolAsset(token=a.token, weight=str(a.weight)) for a in assets] swap_fee_dec = float_to_sdkdec(swap_fee) exit_fee_dec = float_to_sdkdec(exit_fee) return dex_tx_pb.MsgCreatePool( diff --git a/nibiru/composers/pricefeed.py b/nibiru/composers/pricefeed.py new file mode 100644 index 00000000..a4d52ba0 --- /dev/null +++ b/nibiru/composers/pricefeed.py @@ -0,0 +1,17 @@ +from datetime import datetime + +from nibiru import utils +from nibiru.proto.pricefeed import tx_pb2 as pb + + +class Pricefeed: + @staticmethod + def post_price(oracle: str, token0: str, token1: str, price: float, expiry: datetime): + price_dec = utils.float_to_sdkdec(price) + return pb.MsgPostPrice( + oracle=oracle, + token0=token0, + token1=token1, + price=price_dec, + expiry=utils.toTsPb(expiry), + ) diff --git a/nibiru/proto/perp/v1/tx_pb2.py b/nibiru/proto/perp/v1/tx_pb2.py index 4c161832..8d2e96f5 100644 --- a/nibiru/proto/perp/v1/tx_pb2.py +++ b/nibiru/proto/perp/v1/tx_pb2.py @@ -19,7 +19,7 @@ from perp.v1 import state_pb2 as perp_dot_v1_dot_state__pb2 DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile( - b'\n\x10perp/v1/tx.proto\x12\x0enibiru.perp.v1\x1a\x1cgoogle/api/annotations.proto\x1a\x1e\x63osmos/base/v1beta1/coin.proto\x1a\x14gogoproto/gogo.proto\x1a\x13perp/v1/state.proto\"f\n\x0fMsgRemoveMargin\x12\x0e\n\x06sender\x18\x01 \x01(\t\x12\x12\n\ntoken_pair\x18\x02 \x01(\t\x12/\n\x06margin\x18\x03 \x01(\x0b\x32\x19.cosmos.base.v1beta1.CoinB\x04\xc8\xde\x1f\x00\"\x97\x01\n\x17MsgRemoveMarginResponse\x12\x33\n\nmargin_out\x18\x01 \x01(\x0b\x32\x19.cosmos.base.v1beta1.CoinB\x04\xc8\xde\x1f\x00\x12G\n\x0f\x66unding_payment\x18\x02 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\"c\n\x0cMsgAddMargin\x12\x0e\n\x06sender\x18\x01 \x01(\t\x12\x12\n\ntoken_pair\x18\x02 \x01(\t\x12/\n\x06margin\x18\x03 \x01(\x0b\x32\x19.cosmos.base.v1beta1.CoinB\x04\xc8\xde\x1f\x00\"\x8b\x01\n\x14MsgAddMarginResponse\x12G\n\x0f\x66unding_payment\x18\x01 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12*\n\x08position\x18\x02 \x01(\x0b\x32\x18.nibiru.perp.v1.Position\"B\n\x0cMsgLiquidate\x12\x0e\n\x06sender\x18\x01 \x01(\t\x12\x12\n\ntoken_pair\x18\x02 \x01(\t\x12\x0e\n\x06trader\x18\x03 \x01(\t\"\x97\x01\n\x14MsgLiquidateResponse\x12:\n\x11\x66\x65\x65_to_liquidator\x18\x01 \x01(\x0b\x32\x19.cosmos.base.v1beta1.CoinB\x04\xc8\xde\x1f\x00\x12\x43\n\x1a\x66\x65\x65_to_perp_ecosystem_fund\x18\x02 \x01(\x0b\x32\x19.cosmos.base.v1beta1.CoinB\x04\xc8\xde\x1f\x00\"\xb8\x02\n\x0fMsgOpenPosition\x12\x0e\n\x06sender\x18\x01 \x01(\t\x12\x12\n\ntoken_pair\x18\x02 \x01(\t\x12\"\n\x04side\x18\x03 \x01(\x0e\x32\x14.nibiru.perp.v1.Side\x12J\n\x12quote_asset_amount\x18\x04 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Int\xc8\xde\x1f\x00\x12@\n\x08leverage\x18\x05 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12O\n\x17\x62\x61se_asset_amount_limit\x18\x06 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Int\xc8\xde\x1f\x00\"\xd9\x04\n\x17MsgOpenPositionResponse\x12*\n\x08position\x18\x01 \x01(\x0b\x32\x18.nibiru.perp.v1.Position\x12P\n\x18\x65xchanged_notional_value\x18\x02 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12O\n\x17\x65xchanged_position_size\x18\x03 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12G\n\x0f\x66unding_payment\x18\x04 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12\x44\n\x0crealized_pnl\x18\x05 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12L\n\x14unrealized_pnl_after\x18\x06 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12G\n\x0fmargin_to_vault\x18\x07 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12I\n\x11position_notional\x18\x08 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\"6\n\x10MsgClosePosition\x12\x0e\n\x06sender\x18\x01 \x01(\t\x12\x12\n\ntoken_pair\x18\x02 \x01(\t\"\x1a\n\x18MsgClosePositionResponse2\xe7\x04\n\x03Msg\x12|\n\x0cRemoveMargin\x12\x1f.nibiru.perp.v1.MsgRemoveMargin\x1a\'.nibiru.perp.v1.MsgRemoveMarginResponse\"\"\x82\xd3\xe4\x93\x02\x1c\"\x1a/nibiru/perp/remove_margin\x12p\n\tAddMargin\x12\x1c.nibiru.perp.v1.MsgAddMargin\x1a$.nibiru.perp.v1.MsgAddMarginResponse\"\x1f\x82\xd3\xe4\x93\x02\x19\"\x17/nibiru/perp/add_margin\x12o\n\tLiquidate\x12\x1c.nibiru.perp.v1.MsgLiquidate\x1a$.nibiru.perp.v1.MsgLiquidateResponse\"\x1e\x82\xd3\xe4\x93\x02\x18\"\x16/nibiru/perp/liquidate\x12|\n\x0cOpenPosition\x12\x1f.nibiru.perp.v1.MsgOpenPosition\x1a\'.nibiru.perp.v1.MsgOpenPositionResponse\"\"\x82\xd3\xe4\x93\x02\x1c\"\x1a/nibiru/perp/open_position\x12\x80\x01\n\rClosePosition\x12 .nibiru.perp.v1.MsgClosePosition\x1a(.nibiru.perp.v1.MsgClosePositionResponse\"#\x82\xd3\xe4\x93\x02\x1d\"\x1b/nibiru/perp/close_positionB,Z*github.com/NibiruChain/nibiru/x/perp/typesb\x06proto3' + b'\n\x10perp/v1/tx.proto\x12\x0enibiru.perp.v1\x1a\x1cgoogle/api/annotations.proto\x1a\x1e\x63osmos/base/v1beta1/coin.proto\x1a\x14gogoproto/gogo.proto\x1a\x13perp/v1/state.proto\"f\n\x0fMsgRemoveMargin\x12\x0e\n\x06sender\x18\x01 \x01(\t\x12\x12\n\ntoken_pair\x18\x02 \x01(\t\x12/\n\x06margin\x18\x03 \x01(\x0b\x32\x19.cosmos.base.v1beta1.CoinB\x04\xc8\xde\x1f\x00\"\xc3\x01\n\x17MsgRemoveMarginResponse\x12\x33\n\nmargin_out\x18\x01 \x01(\x0b\x32\x19.cosmos.base.v1beta1.CoinB\x04\xc8\xde\x1f\x00\x12G\n\x0f\x66unding_payment\x18\x02 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12*\n\x08position\x18\x03 \x01(\x0b\x32\x18.nibiru.perp.v1.Position\"c\n\x0cMsgAddMargin\x12\x0e\n\x06sender\x18\x01 \x01(\t\x12\x12\n\ntoken_pair\x18\x02 \x01(\t\x12/\n\x06margin\x18\x03 \x01(\x0b\x32\x19.cosmos.base.v1beta1.CoinB\x04\xc8\xde\x1f\x00\"\x8b\x01\n\x14MsgAddMarginResponse\x12G\n\x0f\x66unding_payment\x18\x01 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12*\n\x08position\x18\x02 \x01(\x0b\x32\x18.nibiru.perp.v1.Position\"B\n\x0cMsgLiquidate\x12\x0e\n\x06sender\x18\x01 \x01(\t\x12\x12\n\ntoken_pair\x18\x02 \x01(\t\x12\x0e\n\x06trader\x18\x03 \x01(\t\"\x97\x01\n\x14MsgLiquidateResponse\x12:\n\x11\x66\x65\x65_to_liquidator\x18\x01 \x01(\x0b\x32\x19.cosmos.base.v1beta1.CoinB\x04\xc8\xde\x1f\x00\x12\x43\n\x1a\x66\x65\x65_to_perp_ecosystem_fund\x18\x02 \x01(\x0b\x32\x19.cosmos.base.v1beta1.CoinB\x04\xc8\xde\x1f\x00\"\xb8\x02\n\x0fMsgOpenPosition\x12\x0e\n\x06sender\x18\x01 \x01(\t\x12\x12\n\ntoken_pair\x18\x02 \x01(\t\x12\"\n\x04side\x18\x03 \x01(\x0e\x32\x14.nibiru.perp.v1.Side\x12J\n\x12quote_asset_amount\x18\x04 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Int\xc8\xde\x1f\x00\x12@\n\x08leverage\x18\x05 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12O\n\x17\x62\x61se_asset_amount_limit\x18\x06 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Int\xc8\xde\x1f\x00\"\xd9\x04\n\x17MsgOpenPositionResponse\x12*\n\x08position\x18\x01 \x01(\x0b\x32\x18.nibiru.perp.v1.Position\x12P\n\x18\x65xchanged_notional_value\x18\x02 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12O\n\x17\x65xchanged_position_size\x18\x03 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12G\n\x0f\x66unding_payment\x18\x04 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12\x44\n\x0crealized_pnl\x18\x05 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12L\n\x14unrealized_pnl_after\x18\x06 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12G\n\x0fmargin_to_vault\x18\x07 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12I\n\x11position_notional\x18\x08 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\"6\n\x10MsgClosePosition\x12\x0e\n\x06sender\x18\x01 \x01(\t\x12\x12\n\ntoken_pair\x18\x02 \x01(\t\"\x96\x03\n\x18MsgClosePositionResponse\x12P\n\x18\x65xchanged_notional_value\x18\x01 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12O\n\x17\x65xchanged_position_size\x18\x02 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12G\n\x0f\x66unding_payment\x18\x03 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12\x44\n\x0crealized_pnl\x18\x04 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12H\n\x10margin_to_trader\x18\x07 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x32\xe7\x04\n\x03Msg\x12|\n\x0cRemoveMargin\x12\x1f.nibiru.perp.v1.MsgRemoveMargin\x1a\'.nibiru.perp.v1.MsgRemoveMarginResponse\"\"\x82\xd3\xe4\x93\x02\x1c\"\x1a/nibiru/perp/remove_margin\x12p\n\tAddMargin\x12\x1c.nibiru.perp.v1.MsgAddMargin\x1a$.nibiru.perp.v1.MsgAddMarginResponse\"\x1f\x82\xd3\xe4\x93\x02\x19\"\x17/nibiru/perp/add_margin\x12o\n\tLiquidate\x12\x1c.nibiru.perp.v1.MsgLiquidate\x1a$.nibiru.perp.v1.MsgLiquidateResponse\"\x1e\x82\xd3\xe4\x93\x02\x18\"\x16/nibiru/perp/liquidate\x12|\n\x0cOpenPosition\x12\x1f.nibiru.perp.v1.MsgOpenPosition\x1a\'.nibiru.perp.v1.MsgOpenPositionResponse\"\"\x82\xd3\xe4\x93\x02\x1c\"\x1a/nibiru/perp/open_position\x12\x80\x01\n\rClosePosition\x12 .nibiru.perp.v1.MsgClosePosition\x1a(.nibiru.perp.v1.MsgClosePositionResponse\"#\x82\xd3\xe4\x93\x02\x1d\"\x1b/nibiru/perp/close_positionB,Z*github.com/NibiruChain/nibiru/x/perp/typesb\x06proto3' ) @@ -206,6 +206,26 @@ _MSGOPENPOSITIONRESPONSE.fields_by_name[ 'position_notional' ]._serialized_options = b'\332\336\037&github.com/cosmos/cosmos-sdk/types.Dec\310\336\037\000' + _MSGCLOSEPOSITIONRESPONSE.fields_by_name['exchanged_notional_value']._options = None + _MSGCLOSEPOSITIONRESPONSE.fields_by_name[ + 'exchanged_notional_value' + ]._serialized_options = b'\332\336\037&github.com/cosmos/cosmos-sdk/types.Dec\310\336\037\000' + _MSGCLOSEPOSITIONRESPONSE.fields_by_name['exchanged_position_size']._options = None + _MSGCLOSEPOSITIONRESPONSE.fields_by_name[ + 'exchanged_position_size' + ]._serialized_options = b'\332\336\037&github.com/cosmos/cosmos-sdk/types.Dec\310\336\037\000' + _MSGCLOSEPOSITIONRESPONSE.fields_by_name['funding_payment']._options = None + _MSGCLOSEPOSITIONRESPONSE.fields_by_name[ + 'funding_payment' + ]._serialized_options = b'\332\336\037&github.com/cosmos/cosmos-sdk/types.Dec\310\336\037\000' + _MSGCLOSEPOSITIONRESPONSE.fields_by_name['realized_pnl']._options = None + _MSGCLOSEPOSITIONRESPONSE.fields_by_name[ + 'realized_pnl' + ]._serialized_options = b'\332\336\037&github.com/cosmos/cosmos-sdk/types.Dec\310\336\037\000' + _MSGCLOSEPOSITIONRESPONSE.fields_by_name['margin_to_trader']._options = None + _MSGCLOSEPOSITIONRESPONSE.fields_by_name[ + 'margin_to_trader' + ]._serialized_options = b'\332\336\037&github.com/cosmos/cosmos-sdk/types.Dec\310\336\037\000' _MSG.methods_by_name['RemoveMargin']._options = None _MSG.methods_by_name[ 'RemoveMargin' @@ -225,23 +245,23 @@ _MSGREMOVEMARGIN._serialized_start = 141 _MSGREMOVEMARGIN._serialized_end = 243 _MSGREMOVEMARGINRESPONSE._serialized_start = 246 - _MSGREMOVEMARGINRESPONSE._serialized_end = 397 - _MSGADDMARGIN._serialized_start = 399 - _MSGADDMARGIN._serialized_end = 498 - _MSGADDMARGINRESPONSE._serialized_start = 501 - _MSGADDMARGINRESPONSE._serialized_end = 640 - _MSGLIQUIDATE._serialized_start = 642 - _MSGLIQUIDATE._serialized_end = 708 - _MSGLIQUIDATERESPONSE._serialized_start = 711 - _MSGLIQUIDATERESPONSE._serialized_end = 862 - _MSGOPENPOSITION._serialized_start = 865 - _MSGOPENPOSITION._serialized_end = 1177 - _MSGOPENPOSITIONRESPONSE._serialized_start = 1180 - _MSGOPENPOSITIONRESPONSE._serialized_end = 1781 - _MSGCLOSEPOSITION._serialized_start = 1783 - _MSGCLOSEPOSITION._serialized_end = 1837 - _MSGCLOSEPOSITIONRESPONSE._serialized_start = 1839 - _MSGCLOSEPOSITIONRESPONSE._serialized_end = 1865 - _MSG._serialized_start = 1868 - _MSG._serialized_end = 2483 + _MSGREMOVEMARGINRESPONSE._serialized_end = 441 + _MSGADDMARGIN._serialized_start = 443 + _MSGADDMARGIN._serialized_end = 542 + _MSGADDMARGINRESPONSE._serialized_start = 545 + _MSGADDMARGINRESPONSE._serialized_end = 684 + _MSGLIQUIDATE._serialized_start = 686 + _MSGLIQUIDATE._serialized_end = 752 + _MSGLIQUIDATERESPONSE._serialized_start = 755 + _MSGLIQUIDATERESPONSE._serialized_end = 906 + _MSGOPENPOSITION._serialized_start = 909 + _MSGOPENPOSITION._serialized_end = 1221 + _MSGOPENPOSITIONRESPONSE._serialized_start = 1224 + _MSGOPENPOSITIONRESPONSE._serialized_end = 1825 + _MSGCLOSEPOSITION._serialized_start = 1827 + _MSGCLOSEPOSITION._serialized_end = 1881 + _MSGCLOSEPOSITIONRESPONSE._serialized_start = 1884 + _MSGCLOSEPOSITIONRESPONSE._serialized_end = 2290 + _MSG._serialized_start = 2293 + _MSG._serialized_end = 2908 # @@protoc_insertion_point(module_scope) diff --git a/nibiru/proto/perp/v1/tx_pb2.pyi b/nibiru/proto/perp/v1/tx_pb2.pyi index 08a26830..c2da69bd 100644 --- a/nibiru/proto/perp/v1/tx_pb2.pyi +++ b/nibiru/proto/perp/v1/tx_pb2.pyi @@ -39,18 +39,26 @@ class MsgRemoveMarginResponse(google.protobuf.message.Message): DESCRIPTOR: google.protobuf.descriptor.Descriptor MARGIN_OUT_FIELD_NUMBER: builtins.int FUNDING_PAYMENT_FIELD_NUMBER: builtins.int + POSITION_FIELD_NUMBER: builtins.int @property def margin_out(self) -> cosmos.base.v1beta1.coin_pb2.Coin: - """MarginOut: tokens transferred back to the trader""" + """tokens transferred back to the trader""" pass funding_payment: typing.Text + """the funding payment applied on this position interaction""" + + @property + def position(self) -> perp.v1.state_pb2.Position: + """The resulting position""" + pass def __init__(self, *, margin_out: typing.Optional[cosmos.base.v1beta1.coin_pb2.Coin] = ..., funding_payment: typing.Text = ..., + position: typing.Optional[perp.v1.state_pb2.Position] = ..., ) -> None: ... - def HasField(self, field_name: typing_extensions.Literal["margin_out",b"margin_out"]) -> builtins.bool: ... - def ClearField(self, field_name: typing_extensions.Literal["funding_payment",b"funding_payment","margin_out",b"margin_out"]) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["margin_out",b"margin_out","position",b"position"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["funding_payment",b"funding_payment","margin_out",b"margin_out","position",b"position"]) -> None: ... global___MsgRemoveMarginResponse = MsgRemoveMarginResponse class MsgAddMargin(google.protobuf.message.Message): @@ -233,6 +241,35 @@ global___MsgClosePosition = MsgClosePosition class MsgClosePositionResponse(google.protobuf.message.Message): DESCRIPTOR: google.protobuf.descriptor.Descriptor + EXCHANGED_NOTIONAL_VALUE_FIELD_NUMBER: builtins.int + EXCHANGED_POSITION_SIZE_FIELD_NUMBER: builtins.int + FUNDING_PAYMENT_FIELD_NUMBER: builtins.int + REALIZED_PNL_FIELD_NUMBER: builtins.int + MARGIN_TO_TRADER_FIELD_NUMBER: builtins.int + exchanged_notional_value: typing.Text + """The amount of quote assets exchanged.""" + + exchanged_position_size: typing.Text + """The amount of base assets exchanged.""" + + funding_payment: typing.Text + """The funding payment applied on this position change, measured in quote units.""" + + realized_pnl: typing.Text + """The amount of PnL realized on this position changed, measured in quote units.""" + + margin_to_trader: typing.Text + """The amount of margin the trader receives after closing the position, from the vault. + Should never be negative. + """ + def __init__(self, + *, + exchanged_notional_value: typing.Text = ..., + exchanged_position_size: typing.Text = ..., + funding_payment: typing.Text = ..., + realized_pnl: typing.Text = ..., + margin_to_trader: typing.Text = ..., ) -> None: ... + def ClearField(self, field_name: typing_extensions.Literal["exchanged_notional_value",b"exchanged_notional_value","exchanged_position_size",b"exchanged_position_size","funding_payment",b"funding_payment","margin_to_trader",b"margin_to_trader","realized_pnl",b"realized_pnl"]) -> None: ... global___MsgClosePositionResponse = MsgClosePositionResponse diff --git a/nibiru/proto/pricefeed/tx_pb2.py b/nibiru/proto/pricefeed/tx_pb2.py index fbfdbb6c..0e37a4e4 100644 --- a/nibiru/proto/pricefeed/tx_pb2.py +++ b/nibiru/proto/pricefeed/tx_pb2.py @@ -7,79 +7,106 @@ from google.protobuf import message as _message from google.protobuf import reflection as _reflection from google.protobuf import symbol_database as _symbol_database + # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() from gogoproto import gogo_pb2 as gogoproto_dot_gogo__pb2 -from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2 from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2 +from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2 - -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x12pricefeed/tx.proto\x12\x13nibiru.pricefeed.v1\x1a\x14gogoproto/gogo.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x1cgoogle/api/annotations.proto\"\xb7\x01\n\x0cMsgPostPrice\x12\x0c\n\x04\x66rom\x18\x01 \x01(\t\x12\x0e\n\x06token0\x18\x02 \x01(\t\x12\x0e\n\x06token1\x18\x03 \x01(\t\x12=\n\x05price\x18\x04 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12\x34\n\x06\x65xpiry\x18\x05 \x01(\x0b\x32\x1a.google.protobuf.TimestampB\x08\x90\xdf\x1f\x01\xc8\xde\x1f\x00:\x04\x88\xa0\x1f\x00\"\x16\n\x14MsgPostPriceResponse\"\xb3\x01\n\x16\x45ventOracleUpdatePrice\x12\x0f\n\x07pair_id\x18\x01 \x01(\t\x12\x0e\n\x06oracle\x18\x02 \x01(\t\x12\x42\n\npair_price\x18\x03 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12\x34\n\x06\x65xpiry\x18\x04 \x01(\x0b\x32\x1a.google.protobuf.TimestampB\x08\x90\xdf\x1f\x01\xc8\xde\x1f\x00\"l\n\x15\x45ventPairPriceUpdated\x12\x0f\n\x07pair_id\x18\x01 \x01(\t\x12\x42\n\npair_price\x18\x02 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x32\x86\x01\n\x03Msg\x12\x7f\n\tPostPrice\x12!.nibiru.pricefeed.v1.MsgPostPrice\x1a).nibiru.pricefeed.v1.MsgPostPriceResponse\"$\x82\xd3\xe4\x93\x02\x1e\"\x1c/nibiru/pricefeed/post-priceB9Z/github.com/NibiruChain/nibiru/x/pricefeed/types\xa8\xe2\x1e\x01\xe0\xe1\x1e\x01\x62\x06proto3') - +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile( + b'\n\x12pricefeed/tx.proto\x12\x13nibiru.pricefeed.v1\x1a\x14gogoproto/gogo.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x1cgoogle/api/annotations.proto\"\xb9\x01\n\x0cMsgPostPrice\x12\x0e\n\x06oracle\x18\x01 \x01(\t\x12\x0e\n\x06token0\x18\x02 \x01(\t\x12\x0e\n\x06token1\x18\x03 \x01(\t\x12=\n\x05price\x18\x04 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12\x34\n\x06\x65xpiry\x18\x05 \x01(\x0b\x32\x1a.google.protobuf.TimestampB\x08\x90\xdf\x1f\x01\xc8\xde\x1f\x00:\x04\x88\xa0\x1f\x00\"\x16\n\x14MsgPostPriceResponse\"\xb3\x01\n\x16\x45ventOracleUpdatePrice\x12\x0f\n\x07pair_id\x18\x01 \x01(\t\x12\x0e\n\x06oracle\x18\x02 \x01(\t\x12\x42\n\npair_price\x18\x03 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x12\x34\n\x06\x65xpiry\x18\x04 \x01(\x0b\x32\x1a.google.protobuf.TimestampB\x08\x90\xdf\x1f\x01\xc8\xde\x1f\x00\"l\n\x15\x45ventPairPriceUpdated\x12\x0f\n\x07pair_id\x18\x01 \x01(\t\x12\x42\n\npair_price\x18\x02 \x01(\tB.\xda\xde\x1f&github.com/cosmos/cosmos-sdk/types.Dec\xc8\xde\x1f\x00\x32\x86\x01\n\x03Msg\x12\x7f\n\tPostPrice\x12!.nibiru.pricefeed.v1.MsgPostPrice\x1a).nibiru.pricefeed.v1.MsgPostPriceResponse\"$\x82\xd3\xe4\x93\x02\x1e\"\x1c/nibiru/pricefeed/post-priceB9Z/github.com/NibiruChain/nibiru/x/pricefeed/types\xa8\xe2\x1e\x01\xe0\xe1\x1e\x01\x62\x06proto3' +) _MSGPOSTPRICE = DESCRIPTOR.message_types_by_name['MsgPostPrice'] _MSGPOSTPRICERESPONSE = DESCRIPTOR.message_types_by_name['MsgPostPriceResponse'] _EVENTORACLEUPDATEPRICE = DESCRIPTOR.message_types_by_name['EventOracleUpdatePrice'] _EVENTPAIRPRICEUPDATED = DESCRIPTOR.message_types_by_name['EventPairPriceUpdated'] -MsgPostPrice = _reflection.GeneratedProtocolMessageType('MsgPostPrice', (_message.Message,), { - 'DESCRIPTOR' : _MSGPOSTPRICE, - '__module__' : 'pricefeed.tx_pb2' - # @@protoc_insertion_point(class_scope:nibiru.pricefeed.v1.MsgPostPrice) - }) +MsgPostPrice = _reflection.GeneratedProtocolMessageType( + 'MsgPostPrice', + (_message.Message,), + { + 'DESCRIPTOR': _MSGPOSTPRICE, + '__module__': 'pricefeed.tx_pb2' + # @@protoc_insertion_point(class_scope:nibiru.pricefeed.v1.MsgPostPrice) + }, +) _sym_db.RegisterMessage(MsgPostPrice) -MsgPostPriceResponse = _reflection.GeneratedProtocolMessageType('MsgPostPriceResponse', (_message.Message,), { - 'DESCRIPTOR' : _MSGPOSTPRICERESPONSE, - '__module__' : 'pricefeed.tx_pb2' - # @@protoc_insertion_point(class_scope:nibiru.pricefeed.v1.MsgPostPriceResponse) - }) +MsgPostPriceResponse = _reflection.GeneratedProtocolMessageType( + 'MsgPostPriceResponse', + (_message.Message,), + { + 'DESCRIPTOR': _MSGPOSTPRICERESPONSE, + '__module__': 'pricefeed.tx_pb2' + # @@protoc_insertion_point(class_scope:nibiru.pricefeed.v1.MsgPostPriceResponse) + }, +) _sym_db.RegisterMessage(MsgPostPriceResponse) -EventOracleUpdatePrice = _reflection.GeneratedProtocolMessageType('EventOracleUpdatePrice', (_message.Message,), { - 'DESCRIPTOR' : _EVENTORACLEUPDATEPRICE, - '__module__' : 'pricefeed.tx_pb2' - # @@protoc_insertion_point(class_scope:nibiru.pricefeed.v1.EventOracleUpdatePrice) - }) +EventOracleUpdatePrice = _reflection.GeneratedProtocolMessageType( + 'EventOracleUpdatePrice', + (_message.Message,), + { + 'DESCRIPTOR': _EVENTORACLEUPDATEPRICE, + '__module__': 'pricefeed.tx_pb2' + # @@protoc_insertion_point(class_scope:nibiru.pricefeed.v1.EventOracleUpdatePrice) + }, +) _sym_db.RegisterMessage(EventOracleUpdatePrice) -EventPairPriceUpdated = _reflection.GeneratedProtocolMessageType('EventPairPriceUpdated', (_message.Message,), { - 'DESCRIPTOR' : _EVENTPAIRPRICEUPDATED, - '__module__' : 'pricefeed.tx_pb2' - # @@protoc_insertion_point(class_scope:nibiru.pricefeed.v1.EventPairPriceUpdated) - }) +EventPairPriceUpdated = _reflection.GeneratedProtocolMessageType( + 'EventPairPriceUpdated', + (_message.Message,), + { + 'DESCRIPTOR': _EVENTPAIRPRICEUPDATED, + '__module__': 'pricefeed.tx_pb2' + # @@protoc_insertion_point(class_scope:nibiru.pricefeed.v1.EventPairPriceUpdated) + }, +) _sym_db.RegisterMessage(EventPairPriceUpdated) _MSG = DESCRIPTOR.services_by_name['Msg'] if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None - DESCRIPTOR._serialized_options = b'Z/github.com/NibiruChain/nibiru/x/pricefeed/types\250\342\036\001\340\341\036\001' - _MSGPOSTPRICE.fields_by_name['price']._options = None - _MSGPOSTPRICE.fields_by_name['price']._serialized_options = b'\332\336\037&github.com/cosmos/cosmos-sdk/types.Dec\310\336\037\000' - _MSGPOSTPRICE.fields_by_name['expiry']._options = None - _MSGPOSTPRICE.fields_by_name['expiry']._serialized_options = b'\220\337\037\001\310\336\037\000' - _MSGPOSTPRICE._options = None - _MSGPOSTPRICE._serialized_options = b'\210\240\037\000' - _EVENTORACLEUPDATEPRICE.fields_by_name['pair_price']._options = None - _EVENTORACLEUPDATEPRICE.fields_by_name['pair_price']._serialized_options = b'\332\336\037&github.com/cosmos/cosmos-sdk/types.Dec\310\336\037\000' - _EVENTORACLEUPDATEPRICE.fields_by_name['expiry']._options = None - _EVENTORACLEUPDATEPRICE.fields_by_name['expiry']._serialized_options = b'\220\337\037\001\310\336\037\000' - _EVENTPAIRPRICEUPDATED.fields_by_name['pair_price']._options = None - _EVENTPAIRPRICEUPDATED.fields_by_name['pair_price']._serialized_options = b'\332\336\037&github.com/cosmos/cosmos-sdk/types.Dec\310\336\037\000' - _MSG.methods_by_name['PostPrice']._options = None - _MSG.methods_by_name['PostPrice']._serialized_options = b'\202\323\344\223\002\036\"\034/nibiru/pricefeed/post-price' - _MSGPOSTPRICE._serialized_start=129 - _MSGPOSTPRICE._serialized_end=312 - _MSGPOSTPRICERESPONSE._serialized_start=314 - _MSGPOSTPRICERESPONSE._serialized_end=336 - _EVENTORACLEUPDATEPRICE._serialized_start=339 - _EVENTORACLEUPDATEPRICE._serialized_end=518 - _EVENTPAIRPRICEUPDATED._serialized_start=520 - _EVENTPAIRPRICEUPDATED._serialized_end=628 - _MSG._serialized_start=631 - _MSG._serialized_end=765 + DESCRIPTOR._options = None + DESCRIPTOR._serialized_options = ( + b'Z/github.com/NibiruChain/nibiru/x/pricefeed/types\250\342\036\001\340\341\036\001' + ) + _MSGPOSTPRICE.fields_by_name['price']._options = None + _MSGPOSTPRICE.fields_by_name[ + 'price' + ]._serialized_options = b'\332\336\037&github.com/cosmos/cosmos-sdk/types.Dec\310\336\037\000' + _MSGPOSTPRICE.fields_by_name['expiry']._options = None + _MSGPOSTPRICE.fields_by_name['expiry']._serialized_options = b'\220\337\037\001\310\336\037\000' + _MSGPOSTPRICE._options = None + _MSGPOSTPRICE._serialized_options = b'\210\240\037\000' + _EVENTORACLEUPDATEPRICE.fields_by_name['pair_price']._options = None + _EVENTORACLEUPDATEPRICE.fields_by_name[ + 'pair_price' + ]._serialized_options = b'\332\336\037&github.com/cosmos/cosmos-sdk/types.Dec\310\336\037\000' + _EVENTORACLEUPDATEPRICE.fields_by_name['expiry']._options = None + _EVENTORACLEUPDATEPRICE.fields_by_name['expiry']._serialized_options = b'\220\337\037\001\310\336\037\000' + _EVENTPAIRPRICEUPDATED.fields_by_name['pair_price']._options = None + _EVENTPAIRPRICEUPDATED.fields_by_name[ + 'pair_price' + ]._serialized_options = b'\332\336\037&github.com/cosmos/cosmos-sdk/types.Dec\310\336\037\000' + _MSG.methods_by_name['PostPrice']._options = None + _MSG.methods_by_name[ + 'PostPrice' + ]._serialized_options = b'\202\323\344\223\002\036\"\034/nibiru/pricefeed/post-price' + _MSGPOSTPRICE._serialized_start = 129 + _MSGPOSTPRICE._serialized_end = 314 + _MSGPOSTPRICERESPONSE._serialized_start = 316 + _MSGPOSTPRICERESPONSE._serialized_end = 338 + _EVENTORACLEUPDATEPRICE._serialized_start = 341 + _EVENTORACLEUPDATEPRICE._serialized_end = 520 + _EVENTPAIRPRICEUPDATED._serialized_start = 522 + _EVENTPAIRPRICEUPDATED._serialized_end = 630 + _MSG._serialized_start = 633 + _MSG._serialized_end = 767 # @@protoc_insertion_point(module_scope) diff --git a/nibiru/proto/pricefeed/tx_pb2.pyi b/nibiru/proto/pricefeed/tx_pb2.pyi index 121232c6..03db885d 100644 --- a/nibiru/proto/pricefeed/tx_pb2.pyi +++ b/nibiru/proto/pricefeed/tx_pb2.pyi @@ -14,11 +14,14 @@ DESCRIPTOR: google.protobuf.descriptor.FileDescriptor class MsgPostPrice(google.protobuf.message.Message): """MsgPostPrice represents a method for creating a new post price""" DESCRIPTOR: google.protobuf.descriptor.Descriptor - FROM_FIELD_NUMBER: builtins.int + ORACLE_FIELD_NUMBER: builtins.int TOKEN0_FIELD_NUMBER: builtins.int TOKEN1_FIELD_NUMBER: builtins.int PRICE_FIELD_NUMBER: builtins.int EXPIRY_FIELD_NUMBER: builtins.int + oracle: typing.Text + """From: address of oracle""" + token0: typing.Text """Token0: denominator unit of the price, a.k.a. quote asset""" @@ -32,13 +35,14 @@ class MsgPostPrice(google.protobuf.message.Message): def expiry(self) -> google.protobuf.timestamp_pb2.Timestamp: ... def __init__(self, *, + oracle: typing.Text = ..., token0: typing.Text = ..., token1: typing.Text = ..., price: typing.Text = ..., expiry: typing.Optional[google.protobuf.timestamp_pb2.Timestamp] = ..., ) -> None: ... def HasField(self, field_name: typing_extensions.Literal["expiry",b"expiry"]) -> builtins.bool: ... - def ClearField(self, field_name: typing_extensions.Literal["expiry",b"expiry","from",b"from","price",b"price","token0",b"token0","token1",b"token1"]) -> None: ... + def ClearField(self, field_name: typing_extensions.Literal["expiry",b"expiry","oracle",b"oracle","price",b"price","token0",b"token0","token1",b"token1"]) -> None: ... global___MsgPostPrice = MsgPostPrice class MsgPostPriceResponse(google.protobuf.message.Message): diff --git a/nibiru/sdks/tx/common.py b/nibiru/sdks/tx/common.py index 2becbd6f..1a856502 100644 --- a/nibiru/sdks/tx/common.py +++ b/nibiru/sdks/tx/common.py @@ -38,6 +38,7 @@ def execute(self, **kwargs): return res def execute_msg(self, *msg: message.Message, **kwargs): + address = None try: # TODO: It shouldn't be necessary to resync the block height for every tx, use bgTask instead self.client.sync_timeout_height() @@ -55,7 +56,8 @@ def execute_msg(self, *msg: message.Message, **kwargs): return self.execute_tx(tx, gas_estimate, **kwargs) except (RpcError, SimulationError) as err: logging.error("Failed tx execution: %s", err) - address.decrease_sequence() + if address: + address.decrease_sequence() raise TxError("Failed to execute transaction") from err def execute_tx(self, tx: Transaction, gas_estimate: float, **kwargs): diff --git a/nibiru/sdks/tx/pricefeed.py b/nibiru/sdks/tx/pricefeed.py new file mode 100644 index 00000000..c2a18b40 --- /dev/null +++ b/nibiru/sdks/tx/pricefeed.py @@ -0,0 +1,11 @@ +from datetime import datetime + +from nibiru.composers import Pricefeed as PricefeedComposer + +from .common import Tx + + +class Pricefeed(Tx): + def post_price(self, oracle: str, token0: str, token1: str, price: float, expiry: datetime, **kwargs): + msg = PricefeedComposer.post_price(oracle, token0, token1, price, expiry) + return super().execute_msg(msg, **kwargs) diff --git a/nibiru/sdks/tx/tx_client.py b/nibiru/sdks/tx/tx_client.py index 9a042c2f..7bcadf26 100644 --- a/nibiru/sdks/tx/tx_client.py +++ b/nibiru/sdks/tx/tx_client.py @@ -10,6 +10,7 @@ from .common import Tx from .dex import Dex from .perp import Perp +from .pricefeed import Pricefeed class TxClient(Tx): @@ -17,6 +18,7 @@ def __init__(self, client: Client, network: Network, priv_key: PrivateKey, confi super().__init__(client=client, network=network, priv_key=priv_key, config=config) self.dex = Dex(client=client, network=network, priv_key=priv_key, config=config) self.perp = Perp(client=client, network=network, priv_key=priv_key, config=config) + self.pricefeed = Pricefeed(client=client, network=network, priv_key=priv_key, config=config) def msg_send(self, from_address: str, to_address: str, coins: List[Coin], **kwargs): msg = Composer.msg_send(from_address, to_address, coins=coins) diff --git a/nibiru/utils.py b/nibiru/utils.py index f25b0210..39cae369 100644 --- a/nibiru/utils.py +++ b/nibiru/utils.py @@ -1,3 +1,7 @@ +from datetime import datetime + +from google.protobuf.timestamp_pb2 import Timestamp + from nibiru.exceptions import ConvertError, InvalidArgumentError # number of decimal places @@ -94,8 +98,7 @@ def sdkdec_to_float(dec_str: str) -> float: bz_str = '0.' # set relevant digits to 0 - for _ in range(PRECISION - input_size): - bz_str += '0' + bz_str += '0' * (PRECISION - input_size) # set final digits bz_str += dec_str @@ -119,3 +122,9 @@ def float_to_sdkint(i: float) -> str: def sdkint_to_float(int_str: str) -> float: return float(int_str) / INT_MULT + + +def toTsPb(dt: datetime): + ts = Timestamp() + ts.FromDatetime(dt) + return ts From 930dd3e241d6665ad9ab4f1af6321fa8131a53ea Mon Sep 17 00:00:00 2001 From: onikonychev Date: Mon, 25 Jul 2022 15:22:27 +0400 Subject: [PATCH 2/2] Bumped version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e69046c1..4cde8d2d 100755 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ EMAIL = "dev@nibiru.fi" AUTHOR = "Nibiru Chain" REQUIRES_PYTHON = ">=3.7.0" -VERSION = "0.0.9" +VERSION = "0.0.10" REQUIRED = [ "grpcio",