Skip to content

ESPN: approval-gated trade proposals (propose → approve) - #181

Merged
warnerktsang merged 11 commits into
mainfrom
espn-trade-proposals
Oct 30, 2026
Merged

warnerktsang merged 11 commits into
mainfrom
espn-trade-proposals

Conversation

@warnerktsang

Copy link
Copy Markdown
Collaborator

The ESPN module's third write, mirroring the add/drop gate (PR #176) end to end.

Gate: POST /espn/trades validates against the live league (counterparty exists and isn't the caller's team; every give player on the caller's roster; every receive player on the counterparty's; post-trade roster legal for BOTH teams under the league slot counts with IR accounting, so 2-for-1/1-for-2 change sizes on both sides; trade deadline from league settings not passed) and persists a pending proposal with both sides' snapshots + preview + 30-min expiry, submitting NOTHING. POST /espn/trades/{id}/approve claims atomically (double-approve 409, cross-account 404), re-validates fail-closed, submits ONE ESPN TRADE transaction, records offered/failed + the ESPN transaction id. GET /espn/trades[/{id}] reads. MCP tools propose_trade / approve_trade / get_trades mirror the routes.

Payload shape: the TRADE item shape ({playerId, type: TRADE, fromTeamId, toTeamId} per player, correct directions) is sourced from a real mTransactions2 read fixture already in the repo (t-trade in test_espn_logic.py); the submission envelope mirrors post_roster_transaction's. No fixture captures a trade SUBMISSION, so post_trade_transaction's docstring flags the envelope as derived — if ESPN wants a trade-specific envelope field, the first live offer surfaces it as a recorded rejection rather than a silent bad write. Development used mocked clients only; no live submissions.

Migration 0015 creates espn_trade_proposals (contract 14 → 15). Tests: ESPN scope 559 passed locally (533 baseline + 26 new). CLI verbs (trade / trade-approve / trades) + gate discipline documented in the local connector (edited in place, lands with the deploy).

@warnerktsang
warnerktsang merged commit 86c2da4 into main Oct 30, 2026
9 checks passed
@warnerktsang
warnerktsang deleted the espn-trade-proposals branch October 30, 2026 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant