diff --git a/pyproject.toml b/pyproject.toml index e9a9a05..6b9427c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "vertex-protocol" -version = "2.1.7" +version = "2.1.8" description = "Vertex Protocol SDK" authors = ["Jeury Mejia "] homepage = "https://vertexprotocol.com/" diff --git a/sanity/engine_client.py b/sanity/engine_client.py index 3b15e22..6c0b136 100644 --- a/sanity/engine_client.py +++ b/sanity/engine_client.py @@ -62,13 +62,15 @@ def run(): btc_perp = client.get_symbols(product_ids=[2]) pprint(btc_perp) + order_price = 100_000 + print("placing order...") product_id = 1 order = OrderParams( sender=SubaccountParams( subaccount_owner=client.signer.address, subaccount_name="default" ), - priceX18=to_x18(60000), + priceX18=to_x18(order_price), amount=to_pow_10(1, 17), expiration=get_expiration_timestamp(OrderType.DEFAULT, int(time.time()) + 40), nonce=gen_order_nonce(), @@ -86,7 +88,7 @@ def run(): sender=SubaccountParams( subaccount_owner=client.signer.address, subaccount_name="default" ), - priceX18=to_x18(60000), + priceX18=to_x18(order_price), amount=to_pow_10(1, 17), expiration=get_expiration_timestamp(OrderType.DEFAULT, int(time.time()) + 40), nonce=gen_order_nonce(), @@ -147,7 +149,7 @@ def run(): QueryMaxOrderSizeParams( sender=sender, product_id=product_id, - price_x18=to_x18(60000), + price_x18=to_x18(order_price), direction="short", ) ) @@ -183,8 +185,8 @@ def run(): ), productId=3, amountBase=to_x18(1), - quoteAmountLow=to_x18(1000), - quoteAmountHigh=to_x18(2000), + quoteAmountLow=to_x18(2000), + quoteAmountHigh=to_x18(4000), ) res = client.mint_lp(mint_lp_params) print("mint lp results:", res.json(indent=2)) @@ -196,7 +198,13 @@ def run(): ), productId=3, amount=to_x18(1), - nonce=client.tx_nonce(), + nonce=client.tx_nonce( + subaccount_to_hex( + SubaccountParams( + subaccount_owner=client.signer.address, subaccount_name="default" + ) + ) + ), ) res = client.burn_lp(burn_lp_params) print("burn lp result:", res.json(indent=2)) @@ -249,7 +257,7 @@ def run(): sender=SubaccountParams( subaccount_owner=client.signer.address, subaccount_name="default" ), - priceX18=to_x18(60000), + priceX18=to_x18(order_price), amount=to_pow_10(1, 17), expiration=get_expiration_timestamp( OrderType.DEFAULT, int(time.time()) + 40 diff --git a/sanity/vertex_client.py b/sanity/vertex_client.py index d07c21d..75b22bd 100644 --- a/sanity/vertex_client.py +++ b/sanity/vertex_client.py @@ -73,6 +73,8 @@ def run(): ) time.sleep(1) + order_price = 95_000 + owner = client.context.engine_client.signer.address print("placing order...") product_id = 1 @@ -81,7 +83,7 @@ def run(): subaccount_owner=owner, subaccount_name="default", ), - priceX18=to_x18(55000), + priceX18=to_x18(order_price), amount=to_pow_10(1, 17), expiration=get_expiration_timestamp(OrderType.POST_ONLY, int(time.time()) + 40), nonce=gen_order_nonce(), @@ -134,7 +136,7 @@ def run(): subaccount_owner=owner, subaccount_name="default", ), - priceX18=to_x18(55000), + priceX18=to_x18(order_price), amount=to_pow_10(1, 17), expiration=get_expiration_timestamp(OrderType.POST_ONLY, int(time.time()) + 40), nonce=gen_order_nonce(), @@ -158,7 +160,7 @@ def run(): subaccount_owner=owner, subaccount_name="default", ), - priceX18=to_x18(65000), + priceX18=to_x18(order_price + 10_000), amount=-to_pow_10(1, 17), expiration=get_expiration_timestamp(OrderType.POST_ONLY, int(time.time()) + 40), nonce=gen_order_nonce(), @@ -180,7 +182,7 @@ def run(): subaccount_owner=owner, subaccount_name="default", ), - priceX18=to_x18(55000), + priceX18=to_x18(order_price), amount=to_pow_10(1, 17), expiration=get_expiration_timestamp(OrderType.POST_ONLY, int(time.time()) + 60), nonce=gen_order_nonce(), @@ -372,7 +374,14 @@ def run(): ), productId=3, amount=to_x18(1), - nonce=client.context.engine_client.tx_nonce(), + nonce=client.context.engine_client.tx_nonce( + subaccount_to_hex( + SubaccountParams( + subaccount_owner=client.context.engine_client.signer.address, + subaccount_name="default", + ) + ) + ), ) res = client.market.burn_lp(burn_lp_params) print("burn lp result:", res.json(indent=2)) diff --git a/vertex_protocol/engine_client/execute.py b/vertex_protocol/engine_client/execute.py index 753c6f2..01f547a 100644 --- a/vertex_protocol/engine_client/execute.py +++ b/vertex_protocol/engine_client/execute.py @@ -99,17 +99,21 @@ def _inject_nonce_if_needed( """ if params.nonce is not None: return params - params.nonce = self.order_nonce() if use_order_nonce else self.tx_nonce() + params.nonce = ( + self.order_nonce() + if use_order_nonce + else self.tx_nonce(subaccount_to_hex(params.sender)) + ) return params - def tx_nonce(self) -> int: + def tx_nonce(self, sender: str) -> int: """ Get the transaction nonce. Used to perform executes such as `withdraw_collateral`. Returns: int: The transaction nonce. """ - return int(self._querier.get_nonces(self.signer.address).tx_nonce) + return int(self._querier.get_nonces(sender[:42]).tx_nonce) def order_nonce(self, recv_time_ms: Optional[int] = None) -> int: """