Skip to content

jupiter: simulate the swap before signing - #1644

Open
Timothymycompc wants to merge 1 commit into
coinbase:mainfrom
Timothymycompc:jupiter-simulate-before-signing
Open

Timothymycompc wants to merge 1 commit into
coinbase:mainfrom
Timothymycompc:jupiter-simulate-before-signing

Conversation

@Timothymycompc

Copy link
Copy Markdown

What

The Jupiter swap action signs whatever transaction Jupiter's /swap endpoint returns. Agents sign without a person reviewing a wallet popup, so if that response were ever wrong (a misconfiguration, a compromised endpoint or proxy), the agent's wallet would sign it anyway.

This PR simulates the unsigned transaction before signing (swapCheck.ts, using the wallet provider's own connection, no new dependencies) and refuses to sign when:

  • the simulation fails,
  • the wallet would give up more of the input token than the quote's inAmount,
  • the wallet would receive less of the output token than the quote's otherAmountThreshold,
  • more SOL would leave the wallet than the SOL sold plus a 0.01 SOL allowance for fees and new-account rent.

When it refuses, the action returns Refused to sign the swap transaction: <reason> instead of signing.

Tests

  • swapCheck.test.ts: a swap that does what the quote says passes (including one that opens the output token account); swaps that pay someone else, take extra SOL, take more of the input token, or fail in simulation are refused.
  • jupiterActionProvider.test.ts: a refused check means signAndSendTransaction is never called.
  • Changeset included (patch).

Disclosure: I maintain an open-source pre-sign checker for Solana agents (Solana Pulse); this PR doesn't depend on it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DYNBQQhnYiveWR3NW9fyjP

The swap action signed whatever transaction Jupiter's API returned. It now simulates the unsigned transaction first and refuses to sign when the simulation fails, the wallet would give up more than the quoted input amount, or it would receive less than the quote's minimum output (otherAmountThreshold).
@cb-heimdall

Copy link
Copy Markdown

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
1 if authored by an app that is not allowlisted and lacks verified human attribution 0
Sum 1

@github-actions github-actions Bot added documentation Improvements or additions to documentation action provider New action provider typescript labels Nov 12, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action provider New action provider documentation Improvements or additions to documentation typescript

Development

Successfully merging this pull request may close these issues.

2 participants