Escrow
Trustless P2P token swaps with PDA-based escrow vaults
Deployed
Anchor 0.32
Program ID
FKz12mj5HcA9wJRTmpEN2mstdat7KVrwJyy1QULaVi4J
Repository
ExpertVagabond/solana-escrow
Binary Size
315K
Cluster
Devnet
Instructions
IX
make_offer
Creates a new escrow offer, depositing tokens into a PDA vault.
| Parameter | Type | Description |
|---|---|---|
seed | u64 | Unique seed for deriving the escrow PDA |
offer_amount | u64 | Amount of token A to offer |
want_amount | u64 | Amount of token B desired in return |
IX
take_offer
Accepts an existing escrow offer, completing the token swap between both parties.
| Parameter | Type | Description |
|---|---|---|
| No parameters | ||
IX
cancel_offer
Cancels the escrow and returns deposited tokens to the maker.
| Parameter | Type | Description |
|---|---|---|
| No parameters | ||
Accounts
Escrow
| Field | Type | Description |
|---|---|---|
maker | Pubkey | The wallet that created the escrow offer |
mint_a | Pubkey | Mint address of the offered token |
mint_b | Pubkey | Mint address of the desired token |
offer_amount | u64 | Amount of token A offered |
want_amount | u64 | Amount of token B requested |
seed | u64 | Unique seed for PDA derivation |
bump | u8 | PDA bump seed |
PDA Derivation
escrow
seeds = [b"escrow", maker, seed.to_le_bytes()]
vault
seeds = [b"vault", escrow]
Error Codes
InvalidAmount
The offer or want amount must be greater than zero
OfferExpired
The escrow offer has expired and can no longer be taken
Usage Example
import { Program, AnchorProvider } from "@coral-xyz/anchor"; import { PublicKey } from "@solana/web3.js"; import { getAssociatedTokenAddress } from "@solana/spl-token"; const seed = new BN(1); const offerAmount = new BN(1_000_000); const wantAmount = new BN(500_000); // Derive the escrow PDA const [escrowPda] = PublicKey.findProgramAddressSync( [Buffer.from("escrow"), maker.publicKey.toBuffer(), seed.toArrayLike(Buffer, "le", 8)], program.programId ); // Create the escrow offer await program.methods .makeOffer(seed, offerAmount, wantAmount) .accounts({ maker: maker.publicKey, mintA, mintB, escrow: escrowPda, }) .signers([maker]) .rpc();