PolyHedge

An agent that knows when NOT to hedge: Chainlink-validated, autonomously Dynamic-executed.

PolyHedge

Created At

ETHGlobal New York 2026

Project Description

PolyHedge is an autonomous, on-chain hedging agent for prediction markets like Polymarket.

The core insight: two markets can look identical to a human yet be impossible to hedge against each other. PolyHedge runs a five-dimension check — asset, threshold, direction, time window, and settlement source — to decide whether a hedge is real. For example, it rejects a market that reads almost the same as your position but settles on Binance BTC-USDT instead of Coinbase BTC-USD, because that oracle-source basis risk means the two prices can diverge at the exact settlement moment. It does not just match similar markets; it verifies whether the hedge is actually real.

Before any hedge is committed, the agent validates a live Chainlink BTC/USD price feed on Base Sepolia inside the HedgeGuard smart contract. The on-chain recordHedge function is gated by this check: the price must be positive, come from a complete round, not be stale, and be under three hours old. If the price check fails, the transaction reverts, preventing the hedge from being recorded against invalid data.

When a hedge passes every check, the agent acts on its own: it signs and broadcasts the transaction using a Dynamic server wallet via the Python dynamic-wallet-sdk. The wallet is created and controlled from the backend without exposing a private key to the app or the user. This makes PolyHedge a true agentic build — it decides what to do, then executes it on-chain by itself, but only after the hedge passes settlement, basis-risk, and price-validation checks.

Stack: Solidity (HedgeGuard contract), Python (engine + agent), web3.py, Chainlink price feeds, Dynamic server wallets, Streamlit (live demo), Base Sepolia.

Live demo: https://polyhedge.streamlit.app HedgeGuard contract: https://sepolia.basescan.org/address/0x6bAeCb1b31Bb340D0C85762a11c3202A7F8087dE Agentic tx: https://sepolia.basescan.org/tx/0xd4375d38679e9ef4d12e4eef7f6bafa240dc757548074ab01c4bc15a52b3e5c3

How it's Made

PolyHedge is built in two layers: a Python reasoning engine and an on-chain execution path.

The Python engine parses each prediction market into a structured schema: asset, threshold, direction, time window, and settlement source. It then compares a user's position against candidate hedge markets and classifies whether the hedge is actually valid. The key part is the fifth dimension: settlement source. Two markets can look nearly identical in their headline, but PolyHedge rejects them if one settles on Coinbase BTC-USD and the other on Binance BTC-USDT, because that oracle-source basis risk can make the hedge fail at settlement. This is what makes the system non-trivial: it catches risks that a headline-level matcher would miss.

On-chain, PolyHedge uses a Solidity 0.8.19 HedgeGuard contract on Base Sepolia. The contract reads the Chainlink BTC/USD AggregatorV3Interface and exposes getValidatedPrice(), which enforces four checks: the price must be positive, the oracle round must be complete, answeredInRound must be greater than or equal to roundId, and updatedAt must be less than three hours old. The recordHedge() function calls getValidatedPrice() before writing state, so the hedge record is gated by a live Chainlink oracle check. If the price validation fails, the transaction reverts.

Deployment and contract interaction are handled with web3.py. One implementation detail was manually ABI-encoding the recordHedge call data; web3.py v7 changed encodeABI to encode_abi and uses abi_element_identifier instead of fn_name, so I had to patch the call builder to make the transaction compatible with the current web3.py API.

For autonomous execution, PolyHedge uses Dynamic server wallets through the Python dynamic-wallet-sdk. The agent creates a backend-controlled wallet with create_wallet_account, funds it with Base Sepolia ETH, builds the recordHedge transaction using web3.py, and passes the transaction to Dynamic's send_transaction flow. Dynamic signs and broadcasts the transaction, allowing the agent to execute on-chain without exposing a private key to my app or requiring the user to manually approve every transaction. For SDK compatibility, I used a legacy gasPrice transaction format instead of EIP-1559 fields.

The live demo runs on Streamlit Community Cloud and is deployed directly from the GitHub repo. The Streamlit UI shows the hedge-classification engine, rejected unsafe markets, the accepted hedge, and the resulting on-chain transaction.

Partner technologies are central to the build: Chainlink gives PolyHedge a reliable on-chain price guard, while Dynamic gives the agent its own wallet and execution path. Together, they turn PolyHedge from a recommendation tool into an autonomous agent that decides when a hedge is valid and then executes it on-chain.

background image mobile

Join the mailing list

Get the latest news and updates

PolyHedge | ETHGlobal