Prepare what an asset manager’s vault needs before it can hold a gated token: show that the gate blocks an unlisted vault, allowlist it, and confirm what a pause does to it.
An asset manager’s vault holding a gated token is subject to that gate like
any other holder. If the vault’s accounts were not allowlisted at deployment,
the first deposit fails.This tutorial covers the token side of a vault deployment: show that the gate
applies to a vault, get the vault onto the allowlist, and verify its account.
It continues with the mint from
gate the holders,
so $MINT and $LIST should already be exported, on the same network.
Mosaic issues and operates tokens; it does not deploy vaults. The steps below
use an ordinary key file to stand in for the vault’s authority.
1
Stand up the vault authority
In a deployed vault this address is a PDA owned by the vault program. Here a
key file stands in, which is enough to show the allowlist interactions: the
gate checks the address only, so a PDA and a keypair are treated the same way,
in allowlist and in blocklist mode.
Terminal
solana-keygen new --no-bip39-passphrase --silent \ --outfile ~/.config/solana/demo-vault.jsonexport VAULT=$(solana-keygen pubkey ~/.config/solana/demo-vault.json)
When you move to a real vault, allowlist the program’s PDA instead of a wallet,
derived the same way the program derives it. See
program and authority design
for why the vault’s token account should be owned by a PDA.
2
Show that the gate blocks an unlisted vault
Before allowlisting, confirm the failure mode: have the holder move the asset
into the vault while it is not on the list, with the transfer script from
gate the holders,
run with $VAULT 1.
Mosaic SDK
Kit
Web3.js v3
Rust
Mosaic SDK
// npx tsx transfer.ts <recipient> <amount>import { address } from "@solana/kit";import { createTransferTransaction } from "@solana/mosaic-sdk";import { arg, env, loadSigner, rpc, sendMessage } from "./common";// The holder signs and pays for its own transfer.const holder = await loadSigner("demo-holder");const mint = address(env("MINT"));// Creates the recipient's token account if it is missing and thaws it// through the gate before the transfer, so the gate decides whether the// recipient may hold the token.await sendMessage( await createTransferTransaction({ rpc, mint, from: holder.address, to: address(arg(1, "the recipient wallet")), feePayer: holder, authority: holder, amount: arg(2, "the amount"), }),);
Sending 1 to the vault before it is on the allowlist
// npx tsx transfer.ts <recipient> <amount>import { address } from "@solana/kit";import { fetchMint, findAssociatedTokenPda, getTransferCheckedInstruction, TOKEN_2022_PROGRAM_ADDRESS,} from "@solana-program/token-2022";import { arg, env, loadSigner, rpc, send, toBaseUnits } from "./common";import { openThroughGate } from "./gate";// The holder signs and pays for its own transfer.const holder = await loadSigner("demo-holder");const mint = address(env("MINT"));const list = address(env("LIST"));const { data } = await fetchMint(rpc, mint);const [source] = await findAssociatedTokenPda({ mint, owner: holder.address, tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,});// The thaw is where an unlisted recipient fails: the gate rejects the owner// and the whole transaction is dropped before any token moves.const { tokenAccount: destination, instructions } = await openThroughGate( holder, mint, address(arg(1, "the recipient wallet")), list,);await send(holder, [ ...instructions, getTransferCheckedInstruction({ source, mint, destination, authority: holder, amount: toBaseUnits(arg(2, "the amount"), data.decimals), decimals: data.decimals, }),]);
Sending 1 to the vault before it is on the allowlist
Output
Failed: Program GATEzzqxhJnsWF6vHRsgtixxSB8PaQdcqGEVTEHWiULz failed: custom program error: 0x1002
Web3.js v3
// npx tsx transfer.ts <recipient> <amount>import { PublicKey } from "@solana/web3.js";import { findAssociatedTokenPda, getMintDecoder, getTransferCheckedInstruction, TOKEN_2022_PROGRAM_ADDRESS,} from "@solana-program/token-2022";import { addressOf, arg, connection, env, loadKeypair, send, toBaseUnits,} from "./common";import { openThroughGate } from "./gate";// The holder signs and pays for its own transfer.const holder = await loadKeypair("demo-holder");const mint = addressOf(env("MINT"));const list = addressOf(env("LIST"));const mintAccount = await connection.getAccountInfo(new PublicKey(mint));const { decimals } = getMintDecoder().decode(mintAccount!.data);const [source] = await findAssociatedTokenPda({ mint, owner: holder.publicKey.toBase58(), tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,});// The thaw is where an unlisted recipient fails: the gate rejects the owner// and the whole transaction is dropped before any token moves.const { tokenAccount: destination, instructions } = await openThroughGate( holder, mint, addressOf(arg(1, "the recipient wallet")), list,);await send( [holder], [ ...instructions, getTransferCheckedInstruction({ source, mint, destination, authority: holder, amount: toBaseUnits(arg(2, "the amount"), decimals), decimals, }), ],);
Sending 1 to the vault before it is on the allowlist
Output
Failed: Program GATEzzqxhJnsWF6vHRsgtixxSB8PaQdcqGEVTEHWiULz failed: custom program error: 0x1002
Rust
// cargo run --release --bin transfer -- <recipient> <amount>use anyhow::Result;use gated_token::{ acl, arg, arg_pubkey, ata, env, load_keypair, mint_decimals, rpc, send, to_base_units, TOKEN_2022,};use solana_sdk::signature::Signer;use spl_token_2022_interface::instruction::transfer_checked;#[tokio::main]async fn main() -> Result<()> { let rpc = rpc(); // The holder signs and pays for its own transfer. let holder = load_keypair("demo-holder")?; let mint = env("MINT")?; let list = env("LIST")?; let recipient = arg_pubkey(1, "the recipient wallet")?; let decimals = mint_decimals(&rpc, &mint).await?; // The thaw is where an unlisted recipient fails: the gate rejects the // owner and the whole transaction is dropped before any token moves. let (destination, mut instructions) = acl::open_through_gate(&rpc, &holder.pubkey(), &mint, &recipient, &list).await?; instructions.push(transfer_checked( &TOKEN_2022, &ata(&mint, &holder.pubkey()), &mint, &destination, &holder.pubkey(), &[], to_base_units(&arg(2, "the amount")?, decimals)?, decimals, )?); send(&rpc, &[&holder], &instructions).await}
Sending 1 to the vault before it is on the allowlist
Output
Failed: Program GATEzzqxhJnsWF6vHRsgtixxSB8PaQdcqGEVTEHWiULz failed: custom program error: 0x1002
It fails. The vault’s token account is created frozen, and the gate program
rejects the permissionless thaw for it with custom program error 0x1002
(4098), because the vault is not on the list. A program is not exempt from the
gate. A deposit that inserts the thaw fails with this error; one that does not
fails on the frozen account (0x11).
3
Allowlist every account the vault touches
List them before you start. A vault over a gated token needs at least the
vault’s wallet or PDA on this mint’s list and, if the fund’s shares are
themselves a restricted token, each participant’s wallet on the share mint’s
list. This covers the first:
npx tsx allowlist-add.ts $VAULT
cargo run --release --bin allowlist-add -- $VAULT
Repeat it for each address on your list. A missing one fails when a
participant tries to transact.
4
Confirm the deposit path works
Run the same transfer again. It succeeds and prints its signature; as in the
issuing tutorial, only the list entry changed.
npx tsx transfer.ts $VAULT 1
cargo run --release --bin transfer -- $VAULT 1
5
Verify the gate state of each account
Before going live, read every account the vault depends on and confirm its
state. This is the pre-deployment check to automate. First derive the vault’s
token account address, with spl-token or with the derive-ata script from
the custodian tutorial
run with $VAULT:
Reading the vault’s token account after the deposit
Output
SPL Token Account Address: Ag9Hfo8UdcsGgw7jRt44Zf3WEEafr51KAk7ZVnmiqv4k Program: TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb Balance: 1 Decimals: 6 Mint: 8ComqBcog3Aig4hYN9PcCQHcK4rCCUhv7QoxUfrVVB66 Owner: CKfxdA7YLKW8JxmCVQXDBJ43HRnwHKTUbQSVxRKgoHcP State: Initialized Delegation: (not set) Close authority: (not set)Extensions: Immutable owner* This token has a permanent delegate! This means the mint may withdraw all funds from this account at any time. If this was not adequately disclosed to you, you may be dealing with a malicious mint.
Kit
// npx tsx read-account.ts <token account> [commitment]import { address, type Commitment } from "@solana/kit";import { AccountState, fetchToken } from "@solana-program/token-2022";import { arg, rpc } from "./common";const tokenAccount = address(arg(1, "the token account"));// Read at a stated commitment level. Use "finalized" for anything that feeds// a book of record; "confirmed" is enough for a display.const commitment = (process.argv[3] ?? "confirmed") as Commitment;const { data } = await fetchToken(rpc, tokenAccount, { commitment });console.log("Mint:", data.mint);console.log("Owner:", data.owner);console.log("Balance (base units):", data.amount.toString());console.log("State:", AccountState[data.state]);
Reading the vault’s token account after the deposit
// npx tsx read-account.ts <token account> [commitment]import { type Commitment, PublicKey } from "@solana/web3.js";import { AccountState, getTokenDecoder } from "@solana-program/token-2022";import { arg, connection } from "./common";const tokenAccount = new PublicKey(arg(1, "the token account"));// Read at a stated commitment level. Use "finalized" for anything that feeds// a book of record; "confirmed" is enough for a display.const commitment = (process.argv[3] ?? "confirmed") as Commitment;const info = await connection.getAccountInfo(tokenAccount, commitment);const data = getTokenDecoder().decode(info!.data);console.log("Mint:", data.mint);console.log("Owner:", data.owner);console.log("Balance (base units):", data.amount.toString());console.log("State:", AccountState[data.state]);
Reading the vault’s token account after the deposit
// cargo run --release --bin read-account -- <token account> [commitment]use anyhow::{anyhow, Result};use gated_token::{arg, arg_pubkey, rpc_with};use solana_commitment_config::CommitmentConfig;use spl_token_2022_interface::{ extension::StateWithExtensions, state::{Account, AccountState},};#[tokio::main]async fn main() -> Result<()> { let token_account = arg_pubkey(1, "the token account")?; // Read at a stated commitment level. Use "finalized" for anything that // feeds a book of record; "confirmed" is enough for a display. let commitment = match arg(2, "the commitment").as_deref() { Ok("finalized") => CommitmentConfig::finalized(), _ => CommitmentConfig::confirmed(), }; let rpc = rpc_with(commitment); let account = rpc .get_account_with_commitment(&token_account, commitment) .await? .value .ok_or_else(|| anyhow!("{token_account} not found at {commitment:?}"))?; let state = StateWithExtensions::<Account>::unpack(&account.data)?.base; println!("Mint: {}", state.mint); println!("Owner: {}", state.owner); println!("Balance (base units): {}", state.amount); let label = if state.state == AccountState::Frozen { "Frozen" } else { "Initialized" }; println!("State: {label}"); Ok(())}
Reading the vault’s token account after the deposit
State must read Initialized. Frozen means the account is gated out, and
any deposit or settlement that touches it will fail.
6
Confirm what a pause does to the vault
A pause of the token stops the vault along with everything else: requests in
progress cannot settle while it holds. Issuer side:
npx tsx pause.ts
cargo run --release --bin pause
With the token paused, the same deposit fails with 0x43 (67), Token-2022’s
MintPaused:
Mosaic SDK
Kit
Web3.js v3
Rust
Mosaic SDK
// npx tsx transfer.ts <recipient> <amount>import { address } from "@solana/kit";import { createTransferTransaction } from "@solana/mosaic-sdk";import { arg, env, loadSigner, rpc, sendMessage } from "./common";// The holder signs and pays for its own transfer.const holder = await loadSigner("demo-holder");const mint = address(env("MINT"));// Creates the recipient's token account if it is missing and thaws it// through the gate before the transfer, so the gate decides whether the// recipient may hold the token.await sendMessage( await createTransferTransaction({ rpc, mint, from: holder.address, to: address(arg(1, "the recipient wallet")), feePayer: holder, authority: holder, amount: arg(2, "the amount"), }),);
Sending 1 to the vault while the token is paused
Output
Failed: Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb failed: custom program error: 0x43
Kit
// npx tsx transfer.ts <recipient> <amount>import { address } from "@solana/kit";import { fetchMint, findAssociatedTokenPda, getTransferCheckedInstruction, TOKEN_2022_PROGRAM_ADDRESS,} from "@solana-program/token-2022";import { arg, env, loadSigner, rpc, send, toBaseUnits } from "./common";import { openThroughGate } from "./gate";// The holder signs and pays for its own transfer.const holder = await loadSigner("demo-holder");const mint = address(env("MINT"));const list = address(env("LIST"));const { data } = await fetchMint(rpc, mint);const [source] = await findAssociatedTokenPda({ mint, owner: holder.address, tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,});// The thaw is where an unlisted recipient fails: the gate rejects the owner// and the whole transaction is dropped before any token moves.const { tokenAccount: destination, instructions } = await openThroughGate( holder, mint, address(arg(1, "the recipient wallet")), list,);await send(holder, [ ...instructions, getTransferCheckedInstruction({ source, mint, destination, authority: holder, amount: toBaseUnits(arg(2, "the amount"), data.decimals), decimals: data.decimals, }),]);
Sending 1 to the vault while the token is paused
Output
Failed: Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb failed: custom program error: 0x43
Web3.js v3
// npx tsx transfer.ts <recipient> <amount>import { PublicKey } from "@solana/web3.js";import { findAssociatedTokenPda, getMintDecoder, getTransferCheckedInstruction, TOKEN_2022_PROGRAM_ADDRESS,} from "@solana-program/token-2022";import { addressOf, arg, connection, env, loadKeypair, send, toBaseUnits,} from "./common";import { openThroughGate } from "./gate";// The holder signs and pays for its own transfer.const holder = await loadKeypair("demo-holder");const mint = addressOf(env("MINT"));const list = addressOf(env("LIST"));const mintAccount = await connection.getAccountInfo(new PublicKey(mint));const { decimals } = getMintDecoder().decode(mintAccount!.data);const [source] = await findAssociatedTokenPda({ mint, owner: holder.publicKey.toBase58(), tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,});// The thaw is where an unlisted recipient fails: the gate rejects the owner// and the whole transaction is dropped before any token moves.const { tokenAccount: destination, instructions } = await openThroughGate( holder, mint, addressOf(arg(1, "the recipient wallet")), list,);await send( [holder], [ ...instructions, getTransferCheckedInstruction({ source, mint, destination, authority: holder, amount: toBaseUnits(arg(2, "the amount"), decimals), decimals, }), ],);
Sending 1 to the vault while the token is paused
Output
Failed: Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb failed: custom program error: 0x43
Rust
// cargo run --release --bin transfer -- <recipient> <amount>use anyhow::Result;use gated_token::{ acl, arg, arg_pubkey, ata, env, load_keypair, mint_decimals, rpc, send, to_base_units, TOKEN_2022,};use solana_sdk::signature::Signer;use spl_token_2022_interface::instruction::transfer_checked;#[tokio::main]async fn main() -> Result<()> { let rpc = rpc(); // The holder signs and pays for its own transfer. let holder = load_keypair("demo-holder")?; let mint = env("MINT")?; let list = env("LIST")?; let recipient = arg_pubkey(1, "the recipient wallet")?; let decimals = mint_decimals(&rpc, &mint).await?; // The thaw is where an unlisted recipient fails: the gate rejects the // owner and the whole transaction is dropped before any token moves. let (destination, mut instructions) = acl::open_through_gate(&rpc, &holder.pubkey(), &mint, &recipient, &list).await?; instructions.push(transfer_checked( &TOKEN_2022, &ata(&mint, &holder.pubkey()), &mint, &destination, &holder.pubkey(), &[], to_base_units(&arg(2, "the amount")?, decimals)?, decimals, )?); send(&rpc, &[&holder], &instructions).await}
Sending 1 to the vault while the token is paused
Output
Failed: Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb failed: custom program error: 0x43
The remaining decisions are set out in
vault architectures:
whether the design is synchronous or request-and-settle, what is escrowed at
request time, how the cut-off is enforced, who may publish a valuation, and
what happens to a request that cannot settle.If subscriptions or redemptions are to settle through the
DvP program, note that it rejects mints
carrying Scaled UI Amount, which this tutorial’s mint has.