2525 SimulateRequest ,
2626)
2727from v4_proto .cosmos .tx .v1beta1 .tx_pb2 import Tx
28+ from v4_proto .dydxprotocol .accountplus import query_pb2 as accountplus_query
29+ from v4_proto .dydxprotocol .accountplus import query_pb2_grpc as accountplus_query_grpc
30+ from v4_proto .dydxprotocol .accountplus import tx_pb2 as accountplus_tx
2831from v4_proto .dydxprotocol .bridge import query_pb2 as bridge_query
2932from v4_proto .dydxprotocol .bridge import query_pb2_grpc as bridge_query_grpc
3033from v4_proto .dydxprotocol .clob import clob_pair_pb2 as clob_pair_type
6972from v4_proto .dydxprotocol .clob .tx_pb2 import OrderBatch
7073
7174from dydx_v4_client .network import NodeConfig
72- from dydx_v4_client .node .builder import Builder
75+ from dydx_v4_client .node .authenticators import *
76+ from dydx_v4_client .node .builder import Builder , TxOptions
7377from dydx_v4_client .node .fee import Coin , Fee , calculate_fee , Denom
7478from dydx_v4_client .node .message import (
7579 cancel_order ,
7983 transfer ,
8084 withdraw ,
8185 batch_cancel ,
86+ add_authenticator ,
87+ remove_authenticator ,
8288)
8389from dydx_v4_client .wallet import Wallet
8490
@@ -429,6 +435,14 @@ async def get_rewards_params(self) -> rewards_query.QueryParamsResponse:
429435 stub = rewards_query_grpc .QueryStub (self .channel )
430436 return stub .Params (rewards_query .QueryParamsRequest ())
431437
438+ async def get_authenticators (
439+ self , address : str
440+ ) -> accountplus_query .GetAuthenticatorsResponse :
441+ stub = accountplus_query_grpc .QueryStub (self .channel )
442+ return stub .GetAuthenticators (
443+ accountplus_query .GetAuthenticatorsRequest (account = address )
444+ )
445+
432446
433447class SequenceManager :
434448 def __init__ (self , query_node_client : QueryNodeClient ):
@@ -528,7 +542,11 @@ async def send_message(
528542 return response
529543
530544 async def broadcast_message (
531- self , wallet : Wallet , message : Message , mode = BroadcastMode .BROADCAST_MODE_SYNC
545+ self ,
546+ wallet : Wallet ,
547+ message : Message ,
548+ mode = BroadcastMode .BROADCAST_MODE_SYNC ,
549+ tx_options : Optional [TxOptions ] = None ,
532550 ):
533551 """
534552 Broadcasts a message.
@@ -537,16 +555,20 @@ async def broadcast_message(
537555 wallet (Wallet): The wallet to use for signing the transaction.
538556 message (Message): The message to broadcast.
539557 mode (BroadcastMode, optional): The broadcast mode. Defaults to BroadcastMode.BROADCAST_MODE_SYNC.
558+ tx_options (TxOptions, optional): Options for transaction to support authenticators.
540559
541560 Returns:
542561 The response from the broadcast.
543562 """
544- if self .sequence_manager :
563+ if not tx_options and self .sequence_manager :
545564 await self .sequence_manager .before_send (wallet )
546565
547- response = await self .broadcast (self .builder .build (wallet , message ), mode )
566+ response = await self .broadcast (
567+ self .builder .build (wallet , message , tx_options = tx_options ),
568+ mode ,
569+ )
548570
549- if self .sequence_manager :
571+ if not tx_options and self .sequence_manager :
550572 await self .sequence_manager .after_send (wallet )
551573
552574 return response
@@ -710,25 +732,36 @@ async def transfer(
710732 ),
711733 )
712734
713- async def place_order (self , wallet : Wallet , order : Order ):
735+ async def place_order (
736+ self ,
737+ wallet : Wallet ,
738+ order : Order ,
739+ tx_options : Optional [TxOptions ] = None ,
740+ ):
714741 """
715742 Places an order.
716743
717744 Args:
718745 wallet (Wallet): The wallet to use for signing the transaction.
719746 order (Order): The order to place.
747+ tx_options (TxOptions, optional): Options for transaction to support authenticators.
720748
721749 Returns:
722750 The response from the transaction broadcast.
723751 """
724- return await self .broadcast_message (wallet , place_order (order ))
752+ return await self .broadcast_message (
753+ wallet ,
754+ place_order (order ),
755+ tx_options = tx_options ,
756+ )
725757
726758 async def cancel_order (
727759 self ,
728760 wallet : Wallet ,
729761 order_id : OrderId ,
730762 good_til_block : int = None ,
731763 good_til_block_time : int = None ,
764+ tx_options : Optional [TxOptions ] = None ,
732765 ):
733766 """
734767 Cancels an order.
@@ -738,12 +771,15 @@ async def cancel_order(
738771 order_id (OrderId): The ID of the order to cancel.
739772 good_til_block (int, optional): The block number until which the order is valid. Defaults to None.
740773 good_til_block_time (int, optional): The block time until which the order is valid. Defaults to None.
774+ tx_options (TxOptions, optional): Options for transaction to support authenticators.
741775
742776 Returns:
743777 The response from the transaction broadcast.
744778 """
745779 return await self .broadcast_message (
746- wallet , cancel_order (order_id , good_til_block , good_til_block_time )
780+ wallet ,
781+ cancel_order (order_id , good_til_block , good_til_block_time ),
782+ tx_options = tx_options ,
747783 )
748784
749785 async def batch_cancel_orders (
@@ -752,6 +788,7 @@ async def batch_cancel_orders(
752788 subaccount_id : SubaccountId ,
753789 short_term_cancels : List [OrderBatch ],
754790 good_til_block : int ,
791+ tx_options : Optional [TxOptions ] = None ,
755792 ):
756793 """
757794 Batch cancels orders for a subaccount.
@@ -761,6 +798,7 @@ async def batch_cancel_orders(
761798 subaccount_id (SubaccountId): The subaccount ID for which to cancel orders.
762799 short_term_cancels (List[OrderBatch]): List of OrderBatch objects containing the orders to cancel.
763800 good_til_block (int): The last block the short term order cancellations can be executed at.
801+ tx_options (TxOptions, optional): Options for transaction to support authenticators.
764802
765803 Returns:
766804 The response from the transaction broadcast.
@@ -770,4 +808,56 @@ async def batch_cancel_orders(
770808 short_term_cancels = short_term_cancels ,
771809 good_til_block = good_til_block ,
772810 )
773- return await self .broadcast_message (wallet , batch_cancel_msg )
811+ return await self .broadcast_message (
812+ wallet ,
813+ batch_cancel_msg ,
814+ tx_options = tx_options ,
815+ )
816+
817+ async def add_authenticator (
818+ self ,
819+ wallet : Wallet ,
820+ authenticator : Authenticator ,
821+ ):
822+ """
823+ Adds authenticator to a subaccount.
824+
825+ Args:
826+ wallet (Wallet): The wallet to use for signing the transaction or authenticating the request.
827+ authenticator Authenticator: The authenticator to be added.
828+
829+ Returns:
830+ The response from the transaction broadcast.
831+ """
832+ add_authenticator_msg = add_authenticator (
833+ wallet .address ,
834+ authenticator .type ,
835+ authenticator .config ,
836+ )
837+
838+ return await self .send_message (
839+ wallet ,
840+ add_authenticator_msg ,
841+ )
842+
843+ async def remove_authenticator (self , wallet : Wallet , authenticator_id : int ):
844+ """
845+ Removes authenticator from a subaccount.
846+
847+ Args:
848+ wallet (Wallet): The wallet to use for signing the transaction or authenticating the request.
849+ authenticator_id (int): The authenticator identifier.
850+
851+ Returns:
852+ The response from the transaction broadcast.
853+ """
854+
855+ remove_authenticator_msg = remove_authenticator (
856+ wallet .address ,
857+ authenticator_id ,
858+ )
859+
860+ return await self .send_message (
861+ wallet ,
862+ remove_authenticator_msg ,
863+ )
0 commit comments