Skip to content

feat: add refund instruction - #140

Merged
s2imonovic merged 3 commits into
developfrom
feat/refund-withdrawals
Jun 29, 2026
Merged

s2imonovic merged 3 commits into
developfrom
feat/refund-withdrawals

Conversation

@s2imonovic

@s2imonovic s2imonovic commented Jun 22, 2026 •

Copy link
Copy Markdown
Member

Create an instruction for the refund after withdrawals are disabled.


Note

High Risk
Authority can move arbitrary SPL amounts from custody to any recipient ATA without TSS or nonce; compromise or misuse of the PDA authority is a direct custody risk.

Overview
Adds refund_spl_token, an authority-only path to return SPL from the gateway PDA ATA to a user when normal TSS withdrawals are unavailable (e.g. withdrawals disabled).

The handler checks PDA authority, positive amount, custody balance, and PDA/recipient ATA–mint alignment; it can create the recipient ATA if missing (same pattern as SPL withdraw), then transfer_checked from custody with the PDA as signer. It does not use TSS signatures or nonce, and is not blocked by deposit pause. New errors: InsufficientBalance, InvalidAmount.

Gateway tests cover happy path, non-authority rejection, insufficient balance, ATA creation, and refunds while deposits are paused.

Reviewed by Cursor Bugbot for commit 26925b2. Configure here.

@s2imonovic
s2imonovic requested a review from a team as a code owner June 22, 2026 15:29

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 26925b2. Configure here.

@codecov-commenter

codecov-commenter commented Jun 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 83 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
programs/gateway/src/instructions/refund.rs 0.00% 79 Missing ⚠️
programs/gateway/src/lib.rs 0.00% 3 Missing ⚠️
programs/gateway/src/contexts.rs 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@skosito skosito left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Solid, mirrors the withdraw SPL flow closely and has good test coverage. A couple of design points to confirm (trust model, no rent reimbursement) plus minor nits. LGTM once the trust-model intent is confirmed.

Note: the Cursor Bugbot "ATA create invoke order wrong" comment looks like a false positive. Solana matches invoke accounts by pubkey, not slice position, the identical ordering is used in the working withdraw::handle_spl, and the new "creates recipient ATA if needed" test exercises this exact path.

Comment thread programs/gateway/src/contexts.rs Resolved
Comment thread programs/gateway/src/contexts.rs Resolved
Comment thread tests/gateway.ts Resolved

@morde08 morde08 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A couple of test-coverage gaps on the new refund path — both low priority, neither blocking.

Comment thread tests/gateway.ts Resolved
Comment thread tests/gateway.ts Resolved
@s2imonovic
s2imonovic merged commit 07402fc into develop Jun 29, 2026
11 of 12 checks passed
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.

4 participants