Skip to content

Add scoped-token auth and live hedge MCP execution - #53

Open
JaeLeex wants to merge 5 commits into
jl/btcswp-funding-hedge-mcpfrom
jl/scoped-token-hedge-exec-mcp
Open

Add scoped-token auth and live hedge MCP execution#53
JaeLeex wants to merge 5 commits into
jl/btcswp-funding-hedge-mcpfrom
jl/scoped-token-hedge-exec-mcp

Conversation

@JaeLeex

@JaeLeex JaeLeex commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add local hl auth scoped-token import/status/export/revoke flow for keyless signing without raw private keys.
  • Teach MCP to use trusted hosted context or local scoped-token storage, and expose guarded funding_hedge_execute for live BTCSWP hedge execution.
  • Add max hedge notional policy enforcement before hl hedge execute signs/submits orders.

Test plan

  • python3 -m pytest tests/test_auth_scoped_token.py tests/test_web_auth_signer.py tests/test_setup_auth_guidance.py tests/test_mcp_gateway_context.py tests/test_mcp_annotations.py tests/test_funding_hedge.py tests/test_hedge_margin_port.py
  • python3 -m pytest

Made with Cursor

JaeLeex and others added 3 commits June 26, 2026 11:17
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
sdb001
sdb001 previously requested changes Jun 29, 2026

@sdb001 sdb001 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking this for two execution-policy issues.\n\n1. defaults to , but a stored scoped token with still fails in unless the caller also sends . Dry-run preview should not require confirmation, and this currently contradicts the tool's default/docstring.\n\n2. The MCP tool passes scoped policy env into , but the CLI command itself does not enforce with . That means action/network/wallet/notional policy constraints are not checked inside the subprocess before the hedge order path runs. Please add a canonical hedge action and enforce it in before signing/submitting.

@sdb001

sdb001 commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Blocking this for two execution-policy issues.

  1. funding_hedge_execute defaults to dry_run=true, but a stored scoped token with NUNCHI_REQUIRE_CONFIRMATION=true still fails in _context_limit_error unless the caller also sends confirmed=true. Dry-run preview should not require confirmation, and this currently contradicts the tool's default/docstring.

  2. The MCP tool passes scoped policy env into hl hedge execute, but the CLI command itself does not enforce NUNCHI_SESSION_POLICY with guard_or_exit. That means action/network/wallet/notional policy constraints are not checked inside the subprocess before the hedge order path runs. Please add a canonical hedge action and enforce it in cli/commands/hedge.py before signing/submitting.

Comment thread cli/mcp_server.py
Comment thread cli/commands/hedge.py
Co-authored-by: Cursor <cursoragent@cursor.com>
@JaeLeex

JaeLeex commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

Addressed Sam's two execution-policy blockers in 11f11e3:

  • funding_hedge_execute dry-run previews now satisfy the confirmation check while still requiring signing context, so scoped tokens with NUNCHI_REQUIRE_CONFIRMATION=true can preview without confirmed=true.
  • Added canonical hedge session-policy action and enforce NUNCHI_SESSION_POLICY in hl hedge execute before signing/submitting, including network, wallet, market, and hedge notional. Local/trusted scoped-token contexts now generate policies with hedge allowed and map NUNCHI_MAX_HEDGE_NOTIONAL into max_notional_usd_per_action.

Verification: python3 -m pytest -> 1506 passed, 1 skipped.

@sdb001
sdb001 deleted the branch jl/btcswp-funding-hedge-mcp July 2, 2026 12:20
@sdb001 sdb001 closed this Jul 2, 2026
@sdb001 sdb001 reopened this Jul 2, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
@JaeLeex

JaeLeex commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Resolved the two stale execution-policy threads after rebasing/merging the base branch into this PR. Verified locally with: python3 -m pytest tests/test_funding_hedge.py tests/test_hedge_margin_port.py tests/test_mcp_gateway_context.py tests/test_web_auth_signer.py (53 passed).

@JaeLeex
JaeLeex requested a review from sdb001 July 8, 2026 12:16
@JaeLeex
JaeLeex dismissed sdb001’s stale review July 8, 2026 17:12

Addressed in 11f11e3 and c9a2ee0: dry-run skips confirmation when NUNCHI_REQUIRE_CONFIRMATION=true; hl hedge execute enforces ACTION_HEDGE via guard_or_exit with wallet/network/market/notional. Tests pass (15/15 funding_hedge).

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.

2 participants