A trustless token swap program built on Solana using the Anchor framework. Two parties can exchange SPL tokens without needing to trust each other — the program acts as a neutral intermediary.
- Maker creates an escrow, deposits token A into a vault, and specifies how much token B they want in return
- Taker fulfils the deal by sending token B to the maker and receiving token A from the vault
- Maker can cancel at any time and get their tokens back via a refund
| Instruction | Signer | Description |
|---|---|---|
make |
Maker | Creates the escrow PDA, creates vault, deposits token A |
take |
Taker | Sends token B to maker, receives token A from vault, closes escrow |
refund |
Maker | Cancels the escrow, returns token A, closes all accounts |
programs/escrow/src/
├── lib.rs ← entry point
├── constants.rs ← PDA seeds
├── error.rs ← custom errors
├── state/
│ ├── mod.rs
│ └── escrow.rs ← Escrow account struct
└── instructions/
├── mod.rs
├── make.rs ← make instruction
├── take.rs ← take instruction
└── refund.rs ← refund instruction
- PDA-owned vault — no human controls the locked tokens
has_oneconstraints prevent token substitution attacksTransferCheckedused for all transfers — prevents decimal manipulation- Bump stored on-chain — prevents bump substitution attacks
overflow-checks = truein release profile — prevents integer overflow- Anchor discriminators — prevent account type confusion
anchor build
anchor test- Anchor 0.32.1
- anchor-spl 0.32.0
- Solana Token Interface (supports both Token and Token-2022)