8
8
from v4_proto .cosmos .bank .v1beta1 import query_pb2_grpc as bank_query_grpc
9
9
from v4_proto .cosmos .base .v1beta1 .coin_pb2 import Coin
10
10
from v4_proto .cosmos .tx .v1beta1 import service_pb2_grpc
11
- from v4_proto .cosmos .tx .v1beta1 .service_pb2 import SimulateRequest , BroadcastTxRequest , BroadcastMode
11
+ from v4_proto .cosmos .tx .v1beta1 .service_pb2 import (
12
+ SimulateRequest ,
13
+ BroadcastTxRequest ,
14
+ BroadcastMode ,
15
+ )
12
16
from v4_proto .cosmos .tx .v1beta1 .tx_pb2 import Tx , TxBody , AuthInfo , Fee
13
17
from dydx_v4_client .wallet import from_mnemonic , Wallet
14
18
@@ -100,7 +104,7 @@ async def simulate_transfer_native_token(self, amount: str, recipient: str) -> F
100
104
msg_send = bank_tx .MsgSend (
101
105
from_address = self .wallet .address ,
102
106
to_address = recipient ,
103
- amount = [Coin (amount = amount , denom = "uusdc" )]
107
+ amount = [Coin (amount = amount , denom = "uusdc" )],
104
108
)
105
109
any_msg = Any ()
106
110
any_msg .Pack (msg_send )
@@ -113,8 +117,10 @@ async def simulate_transfer_native_token(self, amount: str, recipient: str) -> F
113
117
simulate_request = SimulateRequest (tx = tx )
114
118
simulate_response = stub .Simulate (simulate_request )
115
119
116
- return Fee (amount = simulate_response .gas_info .fee .amount , gas_limit = simulate_response .gas_info .gas_used )
117
-
120
+ return Fee (
121
+ amount = simulate_response .gas_info .fee .amount ,
122
+ gas_limit = simulate_response .gas_info .gas_used ,
123
+ )
118
124
119
125
async def transfer_native (self , amount : str , recipient : str ) -> str :
120
126
"""
@@ -137,12 +143,11 @@ async def transfer_native(self, amount: str, recipient: str) -> str:
137
143
msg_send = bank_tx .MsgSend (
138
144
from_address = self .wallet .address ,
139
145
to_address = recipient ,
140
- amount = [Coin (amount = amount , denom = "uusdc" )]
146
+ amount = [Coin (amount = amount , denom = "uusdc" )],
141
147
)
142
148
any_msg = Any ()
143
149
any_msg .Pack (msg_send )
144
150
145
-
146
151
tx_body = TxBody (messages = [any_msg ], memo = self .default_client_memo )
147
152
fee = await self .simulate_transfer_native_token (amount , recipient )
148
153
@@ -151,7 +156,10 @@ async def transfer_native(self, amount: str, recipient: str) -> str:
151
156
signed_tx = self .wallet .sign_tx (tx )
152
157
153
158
stub = service_pb2_grpc .ServiceStub (self .channel )
154
- broadcast_request = BroadcastTxRequest (tx_bytes = signed_tx .SerializeToString (), mode = BroadcastMode .BROADCAST_MODE_BLOCK )
159
+ broadcast_request = BroadcastTxRequest (
160
+ tx_bytes = signed_tx .SerializeToString (),
161
+ mode = BroadcastMode .BROADCAST_MODE_BLOCK ,
162
+ )
155
163
broadcast_response = stub .BroadcastTx (broadcast_request )
156
164
157
165
return broadcast_response .tx_response .txhash
0 commit comments