> ## Documentation Index
> Fetch the complete documentation index at: https://developers.circle.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Before reading these docs, install the relevant Circle Skill to get pre-loaded context — skills are LLM-optimized and cover architecture decisions, correct flows, and common pitfalls. In Claude Code: run /plugin marketplace add circlefin/skills then /plugin install circle-skills@circle. With Vercel Skills CLI: run npx skills add circlefin/skills. Available skills: use-usdc https://github.com/circlefin/skills/blob/master/plugins/circle/skills/use-usdc/SKILL.md (balances, transfers, approvals on EVM and Solana); EURC has no skill — see https://developers.circle.com/stablecoins/what-is-eurc.md; bridge-stablecoin https://github.com/circlefin/skills/blob/master/plugins/circle/skills/bridge-stablecoin/SKILL.md (crosschain transfers via CCTP, USDC, EURC, and third-party assets); use-arc https://github.com/circlefin/skills/blob/master/plugins/circle/skills/use-arc/SKILL.md (Arc chain config, contract deployment, USDC bridging — Arc docs: https://docs.arc.io/llms.txt); use-circle-wallets https://github.com/circlefin/skills/blob/master/plugins/circle/skills/use-circle-wallets/SKILL.md (choose wallet type); use-developer-controlled-wallets https://github.com/circlefin/skills/blob/master/plugins/circle/skills/use-developer-controlled-wallets/SKILL.md (custodial wallets for payouts and treasury); use-user-controlled-wallets https://github.com/circlefin/skills/blob/master/plugins/circle/skills/use-user-controlled-wallets/SKILL.md (embedded wallets with Web2 login); use-modular-wallets https://github.com/circlefin/skills/blob/master/plugins/circle/skills/use-modular-wallets/SKILL.md (smart contract wallets with passkeys and ERC-4337); use-gateway https://github.com/circlefin/skills/blob/master/plugins/circle/skills/use-gateway/SKILL.md (unified USDC balance, nanopayments); use-smart-contract-platform https://github.com/circlefin/skills/blob/master/plugins/circle/skills/use-smart-contract-platform/SKILL.md (deploy, interact, monitor contracts). Pair any skill with the Circle MCP server for live SDK signatures, contract addresses, and chain IDs: {"mcpServers":{"circle":{"url":"https://api.circle.com/v1/codegen/mcp"}}}.
> Read the product overview first. Each product has an overview explaining when and why to use it. Read it before quickstarts.
> Pick the right wallet type. Developer-controlled (you hold keys), user-controlled (end user holds keys via PIN/social login), or modular (smart contract wallets with passkeys). See https://developers.circle.com/wallets.md.
> Use CCTP V2 for crosschain transfers. CCTP natively transfers USDC and EURC via burn-and-mint, and supports permissionless wrapping of third-party assets via lock-and-mint. V1 is legacy; always use V2 unless V1 is specified or the chain requires it (Noble, Sui, and Aptos still require V1). Migration guide: https://developers.circle.com/cctp/migration-from-v1-to-v2.md.
> Use Bridge Kit for frontend bridging. Wraps CCTP with a simpler SDK for user-facing apps. Use CCTP directly for backend transfers.
> Gas Station vs Paymaster. Gas Station sponsors gas for Circle Wallet transactions. Paymaster lets users pay gas in USDC. Different use cases — read both overviews.
> Gateway Nanopayments for sub-cent payments. Gasless USDC micropayments down to $0.000001 via x402 and batched settlement. For pay-per-request APIs, AI agent payments, streaming.
> Look up USDC addresses per chain. Never hardcode — use https://developers.circle.com/stablecoins/usdc-contract-addresses.md.
> Prefer SDKs over raw API calls. Node.js and Python SDKs handle auth, retries, and errors.
> API key required. Bearer token in Authorization header. Testnet and mainnet use separate keys and may use different base URLs depending on the product.
> Set up webhooks when available. Most operations are async. Webhooks deliver transaction confirmations and state changes.
> When calling list endpoints, paginate using pageSize and pageAfter until no nextPageAfter cursor is returned—stopping at the first page silently misses records.
> Building an AI agent? Start with the Agent Stack—Circle CLI, agent wallets, and nanopayments built for autonomous use cases: https://developers.circle.com/agent-stack.md.

# Quickstart: Subscribe and redeem USYC on Solana

This quickstart shows you how to use the following Yieldcoin Manager program
instructions:

* **Deposit**: Convert underlying assets (USDC) into USYC shares
* **Redeem**: Convert USYC shares back into underlying assets

The Yieldcoin Manager program is an audited smart contract that handles USYC
subscriptions and redemptions on Solana. It includes the teller for processing
deposits and redemptions, a fee configuration account for fee parameters, and a
permissioning system for entitled addresses.

The TypeScript examples in this quickstart use the
[Solana Kit library](https://github.com/anza-xyz/kit).

<Note>
  The code snippets in this quickstart use Solana devnet addresses. For mainnet
  addresses, see [USYC contract addresses](/tokenized/usyc/smart-contracts).
</Note>

## Prerequisites

Before you begin, ensure that you've:

* Installed [Node.js](https://nodejs.org/) and [npm](https://www.npmjs.com/)
* Obtained an entitled address to interact with the teller and hold USYC

## Step 1: Set up the project

This step shows you how to install dependencies and generate the client code you
need to interact with the Yieldcoin Manager program.

### 1.1. Install dependencies

Install the Solana Kit library and token program packages:

```bash Shell theme={null}
npm install @solana/kit @solana-program/token @solana-program/token-2022
```

### 1.2. Generate client code

Generate client code from the
[Yieldcoin Manager IDL](https://explorer.solana.com/address/8FZQeFy39fNK47ebUd7aUWoK1rLgJ7fsteWev3FPP1Aw/idl?cluster=devnet)
using your preferred code generator, such as Codama or other Solana IDL tools.

The generated code provides instruction builders similar to the following:

```typescript TypeScript theme={null}
// Example of generated getDepositInstruction function
export function getDepositInstruction<
  TAccountPayer extends string,
  TAccountAssetMint extends string,
  TAccountSenderAssetAccount extends string,
  TAccountTreasuryAssetAccount extends string,
  TAccountFeeRecipientAssetAccount extends string,
  TAccountTeller extends string,
  TAccountFeeConfig extends string,
  TAccountShareMint extends string,
  TAccountReceiverShareAccount extends string,
  TAccountReceiverPermissions extends string,
  TAccountAssetTokenProgram extends string,
  TAccountShareTokenProgram extends string,
  TAccountEventAuthority extends string,
  TAccountProgram extends string,
  TProgramAddress extends Address,
>(
  input: DepositInput</* ... type parameters ... */>,
  config?: { programAddress?: TProgramAddress },
): DepositInstruction</* ... return type parameters ... */>;
```

## Step 2: Set up the script

This step shows you how to configure imports, constants, and helper functions
for interacting with the Yieldcoin Manager program.

### 2.1. Define imports and constants

Create a new TypeScript file and add the following imports and constants:

```typescript TypeScript theme={null}
import {
  address as toAddress,
  Address,
  appendTransactionMessageInstruction,
  createSolanaRpc,
  createTransactionMessage,
  getAddressEncoder,
  getProgramDerivedAddress,
  Instruction,
  pipe,
  sendAndConfirmTransaction,
  setTransactionMessageFeePayerSigner,
  setTransactionMessageLifetimeUsingBlockhash,
  signTransactionMessageWithSigners,
  TransactionSigner,
} from "@solana/kit";
import {
  fetchMaybeTeller,
  fetchMaybeFeeConfig,
  type Teller,
  type FeeConfig,
  getDepositInstruction,
  getRedeemInstruction,
} from "./generated-client"; // Your generated client code
import { TOKEN_PROGRAM_ADDRESS } from "@solana-program/token";
import { TOKEN_2022_PROGRAM_ADDRESS } from "@solana-program/token-2022";

// Program address (devnet)
const YIELDCOIN_MANAGER_PROGRAM_ADDRESS =
  "8FZQeFy39fNK47ebUd7aUWoK1rLgJ7fsteWev3FPP1Aw" as Address;

// Program seeds for PDA derivation
const PROGRAM_SEEDS = {
  USER_PERMISSIONS: "user_permissions",
  EVENT_AUTHORITY: "__event_authority",
  TELLER: "teller",
  FEE_CONFIG: "fee_config",
};

const ONE_HUNDRED_USDC = 100_000000n;
const ONE_HUNDRED_USYC = 100_000000n;
```

### 2.2. Define helper functions

Add the following helper functions to derive PDAs, fetch teller data, and send
transactions:

```typescript TypeScript theme={null}
// Get all public PDAs
export const getPublicPDAs = async () => {
  const programAddress = YIELDCOIN_MANAGER_PROGRAM_ADDRESS;

  const [tellerPda] = await getProgramDerivedAddress({
    programAddress,
    seeds: [PROGRAM_SEEDS.TELLER],
  });

  const [eventAuthorityPda] = await getProgramDerivedAddress({
    programAddress,
    seeds: [PROGRAM_SEEDS.EVENT_AUTHORITY],
  });

  const [feeConfigPda] = await getProgramDerivedAddress({
    programAddress,
    seeds: [PROGRAM_SEEDS.FEE_CONFIG],
  });

  return { tellerPda, eventAuthorityPda, feeConfigPda };
};

// Get user permissions PDA - derived from wallet address
export const getUserPermissionsPDA = async (
  walletAddress: Address,
): Promise<Address> => {
  const addressEncoder = getAddressEncoder();
  const [userPermissionsPda] = await getProgramDerivedAddress({
    programAddress: YIELDCOIN_MANAGER_PROGRAM_ADDRESS,
    seeds: [
      PROGRAM_SEEDS.USER_PERMISSIONS,
      addressEncoder.encode(walletAddress),
    ],
  });
  return userPermissionsPda;
};

// Fetch teller and fee config account data
export const fetchAccountData = async (rpcEndpoint: string) => {
  const rpc = createSolanaRpc(rpcEndpoint);
  const { tellerPda, feeConfigPda } = await getPublicPDAs();

  const [tellerAccount, feeConfigAccount] = await Promise.all([
    fetchMaybeTeller(rpc, tellerPda),
    fetchMaybeFeeConfig(rpc, feeConfigPda),
  ]);

  if (!tellerAccount.exists || !tellerAccount.data) {
    throw new Error("Teller account not found");
  }
  if (!feeConfigAccount.exists || !feeConfigAccount.data) {
    throw new Error("Fee config account not found");
  }

  return {
    tellerData: tellerAccount.data,
    feeConfigData: feeConfigAccount.data,
  };
};

// Send a transaction with a single instruction
export const sendTransaction = async (
  rpcEndpoint: string,
  instruction: Instruction,
  feePayerSigner: TransactionSigner,
) => {
  const rpc = createSolanaRpc(rpcEndpoint);

  const { value: latestBlockhash } = await rpc
    .getLatestBlockhash({ commitment: "confirmed" })
    .send();

  const transactionMessage = pipe(
    createTransactionMessage({ version: 0 }),
    (m) => setTransactionMessageFeePayerSigner(feePayerSigner, m),
    (m) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, m),
    (m) => appendTransactionMessageInstruction(instruction, m),
  );

  const signedTx = await signTransactionMessageWithSigners(transactionMessage);

  return await sendAndConfirmTransaction(rpc, signedTx, {
    commitment: "confirmed",
  });
};
```

## Step 3: Subscribe and redeem

This step shows you how to subscribe to USYC (deposit USDC) and redeem USYC
(withdraw USDC) using the generated contract functions.

### 3.1. Subscribe to USYC (deposit)

The deposit operation converts USDC into USYC shares. Add the following code to
create a deposit instruction and execute it:

```typescript TypeScript theme={null}
export const createUSYCSubscribeInstruction = async (
  walletAddress: Address,
  senderAssetAccount: Address,
  receiverShareAccount: Address,
  assetAmount: bigint,
  tellerData: Teller,
  feeConfigData: FeeConfig,
) => {
  const { tellerPda, eventAuthorityPda, feeConfigPda } = await getPublicPDAs();
  const receiverPermissions = await getUserPermissionsPDA(walletAddress);
  const programAddress = YIELDCOIN_MANAGER_PROGRAM_ADDRESS;

  const depositInstruction = getDepositInstruction(
    {
      payer: walletAddress,
      assetMint: tellerData.assetMint,
      senderAssetAccount,
      treasuryAssetAccount: tellerData.treasuryAssetAccount,
      feeRecipientAssetAccount: feeConfigData.feeRecipientAssetAccount,
      teller: tellerPda,
      feeConfig: feeConfigPda,
      shareMint: tellerData.shareMint,
      receiverShareAccount,
      receiverPermissions,
      assetTokenProgram: TOKEN_PROGRAM_ADDRESS,
      shareTokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
      eventAuthority: eventAuthorityPda,
      program: programAddress,
      assets: assetAmount,
      receiver: walletAddress,
    },
    { programAddress },
  );

  return depositInstruction;
};

// Example usage
export const subscribeExample = async (signer: TransactionSigner) => {
  const walletAddress = "YourWalletAddressHere";
  const senderAssetAccount: Address = "YourUSDCTokenAccountHere";
  const receiverShareAccount: Address = "YourUSYCTokenAccountHere";

  const { tellerData, feeConfigData } = await fetchAccountData(
    "https://api.devnet.solana.com",
  );

  const instruction = await createUSYCSubscribeInstruction(
    walletAddress,
    senderAssetAccount,
    receiverShareAccount,
    ONE_HUNDRED_USDC,
    tellerData,
    feeConfigData,
  );

  return await sendTransaction(
    "https://api.devnet.solana.com",
    instruction,
    signer,
  );
};
```

### 3.2. Redeem USYC

The redeem operation converts USYC shares back into USDC. Add the following code
to create a redeem instruction and execute it:

```typescript TypeScript theme={null}
export const createUSYCRedeemInstruction = async (
  walletAddress: Address,
  senderShareAccount: Address,
  receiverAssetAccount: Address,
  shareAmount: bigint,
  tellerData: Teller,
  feeConfigData: FeeConfig,
) => {
  const { tellerPda, eventAuthorityPda, feeConfigPda } = await getPublicPDAs();
  const senderPermissions = await getUserPermissionsPDA(walletAddress);
  const programAddress = YIELDCOIN_MANAGER_PROGRAM_ADDRESS;

  const redeemInstruction = getRedeemInstruction(
    {
      payer: walletAddress,
      assetMint: tellerData.assetMint,
      receiverAssetAccount,
      treasuryAssetAccount: tellerData.treasuryAssetAccount,
      feeRecipientAssetAccount: feeConfigData.feeRecipientAssetAccount,
      teller: tellerPda,
      feeConfig: feeConfigPda,
      shareMint: tellerData.shareMint,
      senderShareAccount,
      senderPermissions,
      assetTokenProgram: TOKEN_PROGRAM_ADDRESS,
      shareTokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
      eventAuthority: eventAuthorityPda,
      program: programAddress,
      shares: shareAmount,
      receiver: walletAddress,
    },
    { programAddress },
  );

  return redeemInstruction;
};

// Example usage
export const redeemExample = async (signer: TransactionSigner) => {
  const walletAddress = "YourWalletAddressHere";
  const senderShareAccount: Address = "YourUSYCTokenAccountHere";
  const receiverAssetAccount: Address = "YourUSDCTokenAccountHere";

  const { tellerData, feeConfigData } = await fetchAccountData(
    "https://api.devnet.solana.com",
  );

  const instruction = await createUSYCRedeemInstruction(
    walletAddress,
    senderShareAccount,
    receiverAssetAccount,
    ONE_HUNDRED_USYC,
    tellerData,
    feeConfigData,
  );

  return await sendTransaction(
    "https://api.devnet.solana.com",
    instruction,
    signer,
  );
};
```
