Skip to content

Commit d6a222a

Browse files
committed
fix: RPC dependency, batch claiming, and order size floor truncation
1 parent bc0bbf1 commit d6a222a

File tree

3 files changed

+37
-51
lines changed

3 files changed

+37
-51
lines changed

examples/market_maker.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -621,30 +621,19 @@ def ensure_settlement_approved(self, settlement_address: str) -> None:
621621
print(f"Relayer TX: {tx_hash}")
622622
print("Waiting for confirmation...")
623623

624-
from web3 import Web3
625-
rpc_urls = {
626-
137: "https://polygon-bor-rpc.publicnode.com",
627-
43114: "https://api.avax.network/ext/bc/C/rpc",
628-
84532: "https://sepolia.base.org",
629-
}
630-
rpc_url = rpc_urls.get(self.client.chain_id)
631-
w3 = Web3(Web3.HTTPProvider(rpc_url))
632-
624+
# Wait for confirmation by polling allowance via API
633625
for _ in range(30):
634626
try:
635-
receipt = w3.eth.get_transaction_receipt(tx_hash)
636-
if receipt:
637-
if receipt["status"] == 1:
638-
print(f"Max USDC approval confirmed (gasless)")
639-
self.approved_settlements[settlement_address] = 2**256 - 1
640-
else:
641-
print(f"Transaction failed!")
627+
allowance = self.client.get_usdc_allowance(spender=settlement_address)
628+
if allowance >= self.MAX_APPROVAL_THRESHOLD:
629+
print(f"Max USDC approval confirmed (gasless)")
630+
self.approved_settlements[settlement_address] = allowance
642631
break
643632
except Exception:
644633
pass
645-
time.sleep(1)
634+
time.sleep(2)
646635
else:
647-
print(f"Transaction pending (may still confirm)")
636+
print(f"Approval pending (may still confirm)")
648637
self.approved_settlements[settlement_address] = 2**256 - 1
649638

650639
except Exception as e:

examples/price_action_bot.py

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import argparse
3535
import asyncio
36+
import math
3637
import os
3738
import re
3839
import time
@@ -197,7 +198,7 @@ def calculate_shares_from_usdc(self, usdc_amount: float, price: int) -> int:
197198
return 0
198199
# shares = usdc / (price / 1_000_000) = usdc * 1_000_000 / price
199200
# Result in 6 decimals
200-
return int((usdc_amount * 1_000_000 * 1_000_000) / price)
201+
return math.ceil((usdc_amount * 1_000_000 * 1_000_000) / price)
201202

202203
def get_position_usdc(self, state: AssetState, market_id: str) -> float:
203204
"""Get current position in USDC for a market."""
@@ -240,31 +241,19 @@ def ensure_settlement_approved(self, settlement_address: str) -> None:
240241
print(f"Relayer TX: {tx_hash}")
241242
print("Waiting for confirmation...")
242243

243-
# Wait for confirmation
244-
from web3 import Web3
245-
rpc_urls = {
246-
137: "https://polygon-bor-rpc.publicnode.com",
247-
43114: "https://api.avax.network/ext/bc/C/rpc",
248-
84532: "https://sepolia.base.org",
249-
}
250-
rpc_url = rpc_urls.get(self.client.chain_id)
251-
w3 = Web3(Web3.HTTPProvider(rpc_url))
252-
244+
# Wait for confirmation by polling allowance via API
253245
for _ in range(30):
254246
try:
255-
receipt = w3.eth.get_transaction_receipt(tx_hash)
256-
if receipt:
257-
if receipt["status"] == 1:
258-
print(f"✓ Max USDC approval confirmed (gasless)")
259-
self.approved_settlements[settlement_address] = 2**256 - 1
260-
else:
261-
print(f"✗ Transaction failed!")
247+
allowance = self.client.get_usdc_allowance(spender=settlement_address)
248+
if allowance >= self.MAX_APPROVAL_THRESHOLD:
249+
print(f"✓ Max USDC approval confirmed (gasless)")
250+
self.approved_settlements[settlement_address] = allowance
262251
break
263252
except Exception:
264253
pass
265-
time.sleep(1)
254+
time.sleep(2)
266255
else:
267-
print(f"⚠ Transaction pending (may still confirm)")
256+
print(f"⚠ Approval pending (may still confirm)")
268257
self.approved_settlements[settlement_address] = 2**256 - 1
269258

270259
except Exception as e:
@@ -773,26 +762,34 @@ async def claim_resolved_markets(self) -> None:
773762
await asyncio.sleep(retry_delay)
774763
continue
775764

765+
# Collect all resolved markets first
766+
resolved: list[tuple[str, str, AssetState]] = []
776767
for market_id, contract_address, state in all_traded:
777768
try:
778769
resolution = self.client.get_resolution(market_id)
779-
if not (resolution and resolution.resolved):
780-
continue
770+
if resolution and resolution.resolved:
771+
resolved.append((market_id, contract_address, state))
781772
except Exception:
782773
continue
783774

784-
try:
785-
result = self.client.claim_winnings(contract_address)
786-
tx_hash = result.get("txHash", result.get("tx_hash", "unknown"))
787-
print(f"[{state.asset}] 💰 Claimed winnings from {market_id[:8]}... TX: {tx_hash}")
775+
if not resolved:
776+
await asyncio.sleep(retry_delay)
777+
continue
778+
779+
# Batch claim in one transaction
780+
market_addresses = [addr for _, addr, _ in resolved]
781+
try:
782+
result = self.client.batch_claim_winnings(market_addresses)
783+
tx_hash = result.get("txHash", result.get("tx_hash", "unknown"))
784+
print(f"💰 Batch claimed {len(resolved)} markets TX: {tx_hash}")
785+
for market_id, _, state in resolved:
788786
del state.traded_markets[market_id]
789-
except ValueError as e:
790-
if "no winning tokens" in str(e).lower():
787+
except ValueError as e:
788+
if "no winning tokens" in str(e).lower():
789+
for market_id, _, state in resolved:
791790
del state.traded_markets[market_id]
792-
except Exception as e:
793-
print(f"[{state.asset}] Claim error: {e}")
794-
795-
await asyncio.sleep(15)
791+
except Exception as e:
792+
print(f"Batch claim error: {e}")
796793

797794
except Exception as e:
798795
print(f"Claim monitor error: {e}")

turbine_client/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,7 @@ def batch_claim_winnings(
16251625
"chain_id": str(self._chain_id),
16261626
"markets": ",".join(market_contract_addresses),
16271627
}
1628-
response = self._http.get(endpoint, params=params)
1628+
response = self._http.get(endpoint, params=params, authenticated=True)
16291629
markets_data = response.get("markets", [])
16301630

16311631
redemptions = []

0 commit comments

Comments
 (0)