Skip to content

add pinocchio escrow example#598

Merged
Perelyn-sama merged 3 commits into
solana-foundation:mainfrom
MarkFeder:tokens-escrow-pinocchio
Jun 21, 2026
Merged

add pinocchio escrow example#598
Perelyn-sama merged 3 commits 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 and others added 3 commits June 20, 2026 14:14
The whole-repo `biome check ./` (TypeScript CI job) was failing on three
files unrelated to this PR, which kept the check red:

- basics/cross-program-invocation/pinocchio/tests/test.ts: remove an unused
  discriminator constant and replace non-null assertions with explicit null
  guards
- tokens/token-swap/anchor/tests/deposit-liquidity.ts: apply the biome formatter
- tokens/token-2022/.../app/public/{next,vercel}.svg: add a <title> element
  (noSvgWithoutTitle)
@Perelyn-sama Perelyn-sama merged commit 5f4a6c8 into solana-foundation:main Jun 21, 2026
15 checks passed
@MarkFeder MarkFeder deleted the tokens-escrow-pinocchio branch June 21, 2026 21:01
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.

2 participants