For the complete documentation index, see llms.txt. This page is also available as Markdown.

Subscription request

Approve the asset and create a subscription request on the shares contract.

Subscribing is a two-step flow, just like a standard deposit:

  1. Approve the shares contract to spend your subscription asset — a standard ERC-20 approve call.

  2. Create the request with requestSubscription on the shares contract:

function requestSubscription(
    uint256 assetsIn,         // amount of the asset to deposit
    uint256 minSharesOut,     // slippage protection (see Calculate share price)
    address subscriptionAsset,// must be approved for deposits
    address receiver          // who receives the minted shares
) external returns (uint256 requestId);

Example

Subscribing 1,000 USDC (6 decimals) into a fund. We derive minSharesOut from previewSubscription(assets, 0, asset) (the 0 uses the fund's last settled price) and apply a 0.5% slippage tolerance.

import { createWalletClient, createPublicClient, http, parseAbi, parseUnits } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { mainnet } from "viem/chains";

const SHARES = "0x...";  // fund shares contract — see the fund's Policies and addresses
const USDC   = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";

const sharesAbi = parseAbi([
  "function previewSubscription(uint256 assets, uint256 sharesPrice, address subscriptionAsset) view returns (uint256)",
  "function requestSubscription(uint256 assetsIn, uint256 minSharesOut, address subscriptionAsset, address receiver) returns (uint256)",
]);
const erc20Abi = parseAbi(["function approve(address spender, uint256 amount) returns (bool)"]);

const account = privateKeyToAccount("0x...");
const pub = createPublicClient({ chain: mainnet, transport: http() });
const wallet = createWalletClient({ account, chain: mainnet, transport: http() });

const assetsIn = parseUnits("1000", 6); // 1,000 USDC

// 1. Estimate shares at the last settled price, then apply 0.5% slippage tolerance.
const expectedShares = await pub.readContract({
  address: SHARES, abi: sharesAbi, functionName: "previewSubscription",
  args: [assetsIn, 0n, USDC],
});
const minSharesOut = (expectedShares * 9950n) / 10000n;

// 2. Approve, then request.
await wallet.writeContract({ address: USDC, abi: erc20Abi, functionName: "approve", args: [SHARES, assetsIn] });
const hash = await wallet.writeContract({
  address: SHARES, abi: sharesAbi, functionName: "requestSubscription",
  args: [assetsIn, minSharesOut, USDC, account.address],
});

Events

Creating a subscription request emits a SubscriptionRequest event containing the requestId, cancelableFrom, and expiryAt. Track it as described in Monitor a request.

Subscription flow example, with USDC as subscription token.

Last updated