From 66108f8d3b426c163edbfc71e177d657b74c4f92 Mon Sep 17 00:00:00 2001 From: Bogdan Pop Date: Sun, 3 Aug 2025 19:48:58 +0300 Subject: [PATCH 1/3] fix multiple nonce issue on market orders --- lighter/signer_client.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lighter/signer_client.py b/lighter/signer_client.py index 15bf092..ebdd0ea 100644 --- a/lighter/signer_client.py +++ b/lighter/signer_client.py @@ -86,6 +86,10 @@ async def wrapper(self, *args, **kwargs): if api_key_index == -1 and nonce == -1: api_key_index, nonce = self.nonce_manager.next_nonce() err = self.switch_api_key(api_key_index) + if "nonce" in kwargs: + del kwargs["nonce"] + if "api_key_index" in kwargs: + del kwargs["api_key_index"] if err != None: raise Exception(f"error switching api key: {err}") From f6a475b5460322235d0a59456b1089b9dde2e8e2 Mon Sep 17 00:00:00 2001 From: Bogdan Pop Date: Sun, 3 Aug 2025 20:12:24 +0300 Subject: [PATCH 2/3] fix types for other txs --- lighter/signer_client.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lighter/signer_client.py b/lighter/signer_client.py index ebdd0ea..c37a515 100644 --- a/lighter/signer_client.py +++ b/lighter/signer_client.py @@ -16,6 +16,7 @@ from lighter.errors import ValidationError from lighter.models import TxHash from lighter import nonce_manager +from lighter.models.resp_send_tx import RespSendTx from lighter.transactions import CreateOrder, CancelOrder, Withdraw logging.basicConfig(level=logging.DEBUG) @@ -658,7 +659,7 @@ async def modify_order( api_response = await self.send_tx(tx_type=self.TX_TYPE_MODIFY_ORDER, tx_info=tx_info) logging.debug(f"Modify Order Send Tx Response: {api_response}") - return api_response, None + return tx_info, api_response, None @process_api_key_and_nonce async def transfer(self, to_account_index, usdc_amount, nonce=-1, api_key_index=-1): @@ -671,7 +672,7 @@ async def transfer(self, to_account_index, usdc_amount, nonce=-1, api_key_index= api_response = await self.send_tx(tx_type=self.TX_TYPE_TRANSFER, tx_info=tx_info) logging.debug(f"Transfer Send Tx Response: {api_response}") - return api_response, None + return tx_info, api_response, None @process_api_key_and_nonce async def create_public_pool( @@ -686,7 +687,7 @@ async def create_public_pool( api_response = await self.send_tx(tx_type=self.TX_TYPE_CREATE_PUBLIC_POOL, tx_info=tx_info) logging.debug(f"Create Public Pool Send Tx Response: {api_response}") - return api_response, None + return tx_info, api_response, None @process_api_key_and_nonce async def update_public_pool( @@ -701,7 +702,7 @@ async def update_public_pool( api_response = await self.send_tx(tx_type=self.TX_TYPE_UPDATE_PUBLIC_POOL, tx_info=tx_info) logging.debug(f"Update Public Pool Send Tx Response: {api_response}") - return api_response, None + return tx_info, api_response, None @process_api_key_and_nonce async def mint_shares(self, public_pool_index, share_amount, nonce=-1, api_key_index=-1): @@ -712,7 +713,7 @@ async def mint_shares(self, public_pool_index, share_amount, nonce=-1, api_key_i api_response = await self.send_tx(tx_type=self.TX_TYPE_MINT_SHARES, tx_info=tx_info) logging.debug(f"Mint Shares Send Tx Response: {api_response}") - return api_response, None + return tx_info, api_response, None @process_api_key_and_nonce async def burn_shares(self, public_pool_index, share_amount, nonce=-1, api_key_index=-1): @@ -723,9 +724,9 @@ async def burn_shares(self, public_pool_index, share_amount, nonce=-1, api_key_i api_response = await self.send_tx(tx_type=self.TX_TYPE_BURN_SHARES, tx_info=tx_info) logging.debug(f"Burn Shares Send Tx Response: {api_response}") - return api_response, None + return tx_info, api_response, None - async def send_tx(self, tx_type: StrictInt, tx_info: str) -> TxHash: + async def send_tx(self, tx_type: StrictInt, tx_info: str) -> RespSendTx: if tx_info[0] != "{": raise Exception(tx_info) return await self.tx_api.send_tx(tx_type=tx_type, tx_info=tx_info) From 015a4effe419a16ed8616efd21de644da5c54386 Mon Sep 17 00:00:00 2001 From: Bogdan Pop Date: Sun, 3 Aug 2025 20:21:31 +0300 Subject: [PATCH 3/3] also on validation error --- lighter/signer_client.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lighter/signer_client.py b/lighter/signer_client.py index c37a515..a24eecc 100644 --- a/lighter/signer_client.py +++ b/lighter/signer_client.py @@ -630,7 +630,7 @@ async def withdraw(self, usdc_amount, nonce=-1, api_key_index=-1) -> (Withdraw, async def create_sub_account(self, nonce=-1): tx_info, error = self.sign_create_sub_account(nonce) if error is not None: - return None, error + return None, None, error logging.debug(f"Create Sub Account Tx Info: {tx_info}") api_response = await self.send_tx(tx_type=self.TX_TYPE_CREATE_SUB_ACCOUNT, tx_info=tx_info) @@ -641,7 +641,7 @@ async def create_sub_account(self, nonce=-1): async def cancel_all_orders(self, time_in_force, time, nonce=-1, api_key_index=-1): tx_info, error = self.sign_cancel_all_orders(time_in_force, time, nonce) if error is not None: - return None, error + return None, None, error logging.debug(f"Cancel All Orders Tx Info: {tx_info}") api_response = await self.send_tx(tx_type=self.TX_TYPE_CANCEL_ALL_ORDERS, tx_info=tx_info) @@ -654,7 +654,7 @@ async def modify_order( ): tx_info, error = self.sign_modify_order(market_index, order_index, base_amount, price, trigger_price, nonce) if error is not None: - return None, error + return None, None, error logging.debug(f"Modify Order Tx Info: {tx_info}") api_response = await self.send_tx(tx_type=self.TX_TYPE_MODIFY_ORDER, tx_info=tx_info) @@ -667,7 +667,7 @@ async def transfer(self, to_account_index, usdc_amount, nonce=-1, api_key_index= tx_info, error = self.sign_transfer(to_account_index, usdc_amount, nonce) if error is not None: - return None, error + return None, None, error logging.debug(f"Transfer Tx Info: {tx_info}") api_response = await self.send_tx(tx_type=self.TX_TYPE_TRANSFER, tx_info=tx_info) @@ -682,7 +682,7 @@ async def create_public_pool( operator_fee, initial_total_shares, min_operator_share_rate, nonce ) if error is not None: - return None, error + return None, None, error logging.debug(f"Create Public Pool Tx Info: {tx_info}") api_response = await self.send_tx(tx_type=self.TX_TYPE_CREATE_PUBLIC_POOL, tx_info=tx_info) @@ -697,7 +697,7 @@ async def update_public_pool( public_pool_index, status, operator_fee, min_operator_share_rate, nonce ) if error is not None: - return None, error + return None, None, error logging.debug(f"Update Public Pool Tx Info: {tx_info}") api_response = await self.send_tx(tx_type=self.TX_TYPE_UPDATE_PUBLIC_POOL, tx_info=tx_info) @@ -708,7 +708,7 @@ async def update_public_pool( async def mint_shares(self, public_pool_index, share_amount, nonce=-1, api_key_index=-1): tx_info, error = self.sign_mint_shares(public_pool_index, share_amount, nonce) if error is not None: - return None, error + return None, None, error logging.debug(f"Mint Shares Tx Info: {tx_info}") api_response = await self.send_tx(tx_type=self.TX_TYPE_MINT_SHARES, tx_info=tx_info) @@ -719,7 +719,7 @@ async def mint_shares(self, public_pool_index, share_amount, nonce=-1, api_key_i async def burn_shares(self, public_pool_index, share_amount, nonce=-1, api_key_index=-1): tx_info, error = self.sign_burn_shares(public_pool_index, share_amount, nonce) if error is not None: - return None, error + return None, None, error logging.debug(f"Burn Shares Tx Info: {tx_info}") api_response = await self.send_tx(tx_type=self.TX_TYPE_BURN_SHARES, tx_info=tx_info)