Skip to content

Commit

Permalink
fix: always pull tx nonce from sender (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
yruej301 authored Nov 21, 2024
1 parent 1ad6b8d commit 77a42eb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "vertex-protocol"
version = "2.1.7"
version = "2.1.8"
description = "Vertex Protocol SDK"
authors = ["Jeury Mejia <jeury@vertexprotocol.com>"]
homepage = "https://vertexprotocol.com/"
Expand Down
22 changes: 15 additions & 7 deletions sanity/engine_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down Expand Up @@ -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",
)
)
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand Down
19 changes: 14 additions & 5 deletions sanity/vertex_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down Expand Up @@ -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))
Expand Down
10 changes: 7 additions & 3 deletions vertex_protocol/engine_client/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down

0 comments on commit 77a42eb

Please sign in to comment.