Skip to content

add pinocchio escrow example#597

Closed
MarkFeder wants to merge 1 commit into
solana-foundation:mainfrom
MarkFeder:tokens-escrow-pinocchio
Closed

add pinocchio escrow example#597
MarkFeder wants to merge 1 commit into
solana-foundation:mainfrom
MarkFeder:tokens-escrow-pinocchio

Conversation

@MarkFeder

Copy link
Copy Markdown
Contributor

What

Adds a Pinocchio implementation of tokens/escrow, alongside the existing anchor and native versions. This is the second Pinocchio token example (after transfer-tokens) and the first Pinocchio example to use a PDA-owned vault.

Scope

A faithful port of the native escrow with two instructions:

  • MakeOffer — derives and creates the offer PDA ([b"offer", maker, id]), creates a vault associated token account owned by that PDA, transfers the maker's token A into the vault, and stores the offer terms.
  • TakeOffer — the taker sends the maker the requested token B, the offer PDA signs to release the vaulted token A to the taker, then the vault and offer accounts are closed.

It's pure SPL (token + associated-token-account CPIs) — no Metaplex — using pinocchio-token, pinocchio-associated-token-account, pinocchio-system, and pinocchio-pubkey.

Notes

  • Account orderings mirror tokens/escrow/native so the three options stay directly comparable.
  • The one idiomatic-Pinocchio difference: the offer PDA bump is passed in the MakeOffer instruction data (and stored), so the program uses pinocchio_pubkey::derive_address instead of an on-chain find_program_address. TakeOffer reads the bump back from the stored offer.
  • This adds pinocchio-token = "0.5.0" and pinocchio-associated-token-account = "0.3.0" to [workspace.dependencies] — the same two deps introduced by the transfer-tokens Pinocchio PR (add pinocchio transfer-tokens example #596). If that merges first, this rebases trivially (the lines are identical).
  • The TS toolchain (package.json / pnpm-lock.yaml / tsconfig.json) is copied from tokens/escrow/native, so the lockfile is self-consistent and the bankrun test reuses the same setup helpers.

Tests

tests/test.ts runs under bankrun and mirrors the native escrow's assertions: it mints token A to the maker and token B to the taker, makes an offer (asserting the stored offer fields and the vault balance), then takes it (asserting both accounts are closed and the tokens landed correctly).

Locally green: cargo fmt --check, cargo clippy -- -D warnings, and biome check all pass on the new files.

@MarkFeder MarkFeder closed this Jun 20, 2026
@MarkFeder MarkFeder deleted the tokens-escrow-pinocchio branch June 20, 2026 12:14
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.

1 participant