Repository navigation
Conversation
adi-poly
marked this pull request as draft
October 9, 2026 18:03
adi-poly
force-pushed
the
feat/directional-support
branch
3 times, most recently
from
October 14, 2026 16:35
72c917a to
51275bf
Compare
Add protocol ID bindings for neg-risk and directional events, buckets, Void, and thresholds under @polymarket/bindings/protocol. Add event split/merge, NO conversion, threshold compose/decompose, and two-line directional split/merge as wallet actions, plus local bucket and threshold position derivation helpers. Native V2 condition IDs in split, merge, and redeem now resolve locally without a market listing. Data condition filters accept directional conditions, and resolution types include ATOMIC_DIRECTIONAL and INCREMENTAL_DIRECTIONAL.
adi-poly
force-pushed
the
feat/directional-support
branch
from
October 14, 2026 18:06
51275bf to
b13d690
Compare
Author
|
bugbot run |
adi-poly
marked this pull request as ready for review
October 14, 2026 18:31
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b4b29c1. Configure here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Market makers holding ABOVE on a lower threshold and BELOW on a higher threshold can return collateral and retain the middle-bucket YES positions, then reverse the operation. Implements the DCR SDK scope.
Consumer workflow
Return collateral from the authenticated wallet's indexed directional holdings with no arguments:
The helper repeatedly discovers pairs, chooses the largest collateral return, confirms one merge, and rediscovers until no candidate remains. Overlapping inventory is refreshed after each transaction.
To spend available pUSD and indexed middle-bucket YES holdings to restore threshold pairs:
Split-all independently selects the largest feasible amount, preferring the widest contiguous bucket range on ties, confirms the split, then rediscovers until no eligible inventory or collateral remains. It selects the best range without enumerating all subranges. It does not replay a previous merge history.
Both bulk methods return
Promise<DirectionalBulkResult>containing exactly{ outcomes, errors }, and wait for confirmation internally. Outcomes contain confirmed transactions. Errors retain the original failure, phase, pair/amount for execution failures, and known transaction identifiers.The helpers use existing approvals and execute sequentially; previously confirmed transactions persist. Both depend on indexed holdings and make greedy selections rather than guaranteeing a global optimum. Inspect
errorsbefore assuming a run exhausted all eligible inventory.Discover eligible bucket YES holdings before deciding to split:
findDirectionalBuckets({ eventId? }, options?)returns positive middle-bucket YES holdings withpositionId,eventId,bucketIndex, freshbalance,requiredPusd, and adjacent threshold IDs. It refreshes bucket balances without reading or filtering by wallet pUSD.requiredPusdequals the full reported bucket balance in six-decimal base units; execution checks actual collateral. Outer buckets, NO positions, and Void are excluded. Contiguous buckets may be split together, so singleton requirements should not be summed as an optimal combined cost.The single-pair methods
mergeDirectional(positionIdA, positionIdB, amount?)andsplitDirectional(positionIdA, positionIdB, amount?)accept the two threshold position IDs in either order. The SDK validates the pair and derives its event and line indices locally; callers need no event ID or line indices. Matchingprepare*methods support custom signing.amountis a bigint in six-decimal base units or'max'; omission defaults to'max'. Merge uses the fresh minimum of both wing balances. Split uses the fresh minimum of pUSD and every required middle-bucket YES balance. To reverse a known merge, use the same two IDs and its explicit amount:Discovery requires indexed holdings and refreshes candidate balances on chain.
findDirectionalPairs()ranks candidates by collateral returned. Explicit known-pair execution does not require market metadata discovery.Included behavior
wait()handles and EOA / Deposit Wallet / Safe / Proxy execution paths.decodePositionId, bucket/threshold derivation, and read-only pair discovery.The integration guide covers wallet setup, data dependencies, and staging acceptance. Integration into
planCollateralReturn/executeCollateralReturnPlanremains deferred (P2).Validation
Build, lint, typecheck, and all 1,534 local tests pass: 427 bindings tests and 1,107 client/type tests. The offline directional example runs successfully. Public type tests cover the positional signatures; live pre-write checks reject incompatible/malformed IDs and invalid amounts.
Bulk workflow tests cover bounded discovery/preparation retries, same-handle confirmation retries, retained outcomes, exact failed-pair exclusions and overlapping alternatives, uncertain submission pauses, cancellation, and the failed-pair cap. Split selection is compared with exhaustive references and a 5,000-bucket ladder. A viem receipt-boundary regression confirms that mined reverts remain
TransactionFailedErrorwhile RPC failures remainTransportError. Generated declarations expose{ outcomes, errors }. Live bulk execution remains unverified: the configured staging Data API hostname did not resolve during the last connectivity check.The earlier event/line API completed a Deposit Wallet merge/reverse round trip on staging with restored inventory. The positional API rerun passed invalid-input checks but stopped during the first inventory-seeding split: the staging relayer returned
context deadline exceeded, before the directional merge. Subsequent reads found zero in all six tracked position balances. The refactored live round trip remains unverified. Safe and EOA cases skip without their credentials.The configured staging
/v2/activityand/v2/positionsroutes returned 404, so activity, portfolio visibility, and the discovery loop remain unverified in that environment. Line-split inventory setup does not establish trading/fill settlement.Remaining launch checks include the trade → on-chain settlement → discovery → merge → reverse flow, all wallet types, normal line-book activation, selector sponsorship/withdrawal policy, bucket portfolio visibility, and upstream PnL policy.
Note
High Risk
Introduces extensive on-chain transaction paths and ID parsing for directional collateral flows without full staging verification, so balance or encoding mistakes could misroute user funds.
Overview
feat(client): directional collateral return
Adds a full directional protocol surface: a new
@polymarket/bindings/protocolexport with ID schemas, decoders, and derivation helpers; updates activity, resolution, condition validation, and balance analytics to understand the new module-4 identifiers; extends Router ABI wiring and position context routing so splits/merges/redeems work on directional conditions without listings.Client gains compose/decompose, event basket, convert,
mergeDirectional/splitDirectional, wallet discovery helpers, greedymergeAllUserPositionsDirectional/splitAllUserPositionsDirectional, shared basket amount resolution, gasless/Eoa workflows, exhaustive tests, and adirectional:positionsexample plus thedocs/directional-markets.mdguide.Beyond scope, note that end-to-end staging verification remains outstanding.
Risk
High – large surface area touching fund-moving workflows, new bulk execution loops, and protocol ID parsing; live staging coverage is incomplete so regressions could impact collateral movement.
Reviewed by Cursor Bugbot for commit 2142b33. Bugbot is set up for automated code reviews on this repo. Configure here.