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

# Configure assets and prices: runnable example

> Resolve a price reference, create token accounts, and add a deposit asset to a new vault.

Use this script after [creating a vault](https://docs.exponent.finance/developer-strategy-vaults/create-vault.md), before adding assets or strategy positions. It adds one deposit asset using registered prices. [Configure assets and prices](https://docs.exponent.finance/developer-strategy-vaults/configure-assets-and-prices.md) explains the fields and required accounts.

The manager signs and pays SOL for account rent and transaction fees. The script supports account creation for Token Program and Token-2022 mints; the selected asset must also be supported by the Strategy Vaults program.

## Set up the example

```bash theme={null}
npm install @exponent-labs/exponent-sdk @solana/web3.js@1.98.4 @solana/spl-token@0.4.8
npm install --save-dev typescript tsx @types/node
```

Set the RPC endpoint, manager keypair file, vault address, and accepted token's mint. `ASSET_MINT` must be an actual token mint with a registered price path to the vault's accounting denomination.

```bash theme={null}
export RPC_URL="https://your-mainnet-rpc-endpoint"
export MANAGER_KEYPAIR_PATH="/absolute/path/to/manager.json"
export VAULT_ADDRESS="<vault-address>"
export ASSET_MINT="<deposit-token-mint>"
```

## Add the asset

Save the script as `configure-assets-and-prices.mts`. It creates both token accounts and adds the entry in one transaction. The transaction is sent to the network selected by `RPC_URL`.

```typescript configure-assets-and-prices.mts theme={null}
import { readFileSync } from "node:fs";
import {
  AumCalculator,
  ExponentVault,
  resolvePriceIdFromMintToUnderlying,
  vaultSettingsAction,
} from "@exponent-labs/exponent-sdk";
import {
  createAssociatedTokenAccountIdempotentInstruction,
  getAssociatedTokenAddressSync,
  getMint,
  TOKEN_PROGRAM_ID,
  TOKEN_2022_PROGRAM_ID,
} from "@solana/spl-token";
import {
  ComputeBudgetProgram,
  Connection,
  Keypair,
  PublicKey,
  Transaction,
  sendAndConfirmTransaction,
} from "@solana/web3.js";

function requiredEnv(name: string): string {
  const value = process.env[name];
  if (!value) throw new Error(`Set ${name}`);
  return value;
}

const connection = new Connection(requiredEnv("RPC_URL"), "confirmed");
const manager = Keypair.fromSecretKey(Uint8Array.from(
  JSON.parse(readFileSync(requiredEnv("MANAGER_KEYPAIR_PATH"), "utf8")),
));
const vaultAddress = new PublicKey(requiredEnv("VAULT_ADDRESS"));
const assetMint = new PublicKey(requiredEnv("ASSET_MINT"));
const vault = await ExponentVault.load({ connection, address: vaultAddress });

if (!vault.state.roles.manager.some((key) => key.equals(manager.publicKey))) {
  throw new Error("The signer must be a vault manager");
}
if (vault.state.tokenEntries.length || vault.state.strategyPositions.length) {
  throw new Error("Use a new vault without token entries or strategy positions");
}
if (vault.getTotalAum() !== 0n || await vault.fetchLpTokenSupply() !== 0n) {
  throw new Error("Use a vault with zero AUM and LP supply");
}
if (vault.isAumRefreshRequired()) {
  throw new Error("Refresh AUM before changing vault settings");
}

const mintAccount = await connection.getAccountInfo(assetMint);
if (!mintAccount) throw new Error("The deposit mint does not exist");
const tokenProgram = mintAccount.owner;
if (!tokenProgram.equals(TOKEN_PROGRAM_ID) &&
    !tokenProgram.equals(TOKEN_2022_PROGRAM_ID)) {
  throw new Error("The mint must use Token Program or Token-2022");
}
await getMint(connection, assetMint, "confirmed", tokenProgram);

const prices = await vault.fetcher.fetchExponentPrices();
const assetPriceId = resolvePriceIdFromMintToUnderlying(
  prices,
  assetMint,
  vault.state.underlyingMint,
);
if (!assetPriceId) throw new Error("No registered price path for this asset");

const tokenSquadsAccount = getAssociatedTokenAddressSync(
  assetMint, vault.state.squadsVault, true, tokenProgram,
);
const tokenAccountVault = getAssociatedTokenAddressSync(
  assetMint, vault.selfAddress, true, tokenProgram,
);
const addAsset = vault.ixManageVaultSettings({
  manager: manager.publicKey,
  actions: [vaultSettingsAction("AddTokenEntry", [{
    mint: assetMint,
    priceId: assetPriceId,
    tokenSquadsAccount,
    tokenAccountVault,
    lastObservedAmount: 0n,
    forceDeallocatePolicyIds: [],
  }])],
  remainingAccounts: [tokenSquadsAccount, tokenAccountVault].map((pubkey) => ({
    pubkey,
    isSigner: false,
    isWritable: false,
  })),
});

const transaction = new Transaction().add(
  ComputeBudgetProgram.setComputeUnitLimit({ units: 400_000 }),
  ComputeBudgetProgram.requestHeapFrame({ bytes: 256 * 1024 }),
  createAssociatedTokenAccountIdempotentInstruction(
    manager.publicKey, tokenSquadsAccount, vault.state.squadsVault,
    assetMint, tokenProgram,
  ),
  createAssociatedTokenAccountIdempotentInstruction(
    manager.publicKey, tokenAccountVault, vault.selfAddress,
    assetMint, tokenProgram,
  ),
  addAsset,
);
const signature = await sendAndConfirmTransaction(
  connection, transaction, [manager], { commitment: "confirmed" },
);

await vault.reload();
const entry = vault.state.tokenEntries.find((item) => item.mint.equals(assetMint));
if (!entry || !entry.tokenSquadsAccount.equals(tokenSquadsAccount) ||
    !entry.tokenAccountVault.equals(tokenAccountVault)) {
  throw new Error("Reloaded token entry does not match the submitted accounts");
}
const expectedPriceIds = assetPriceId.__kind === "Simple"
  ? [assetPriceId.priceId]
  : assetPriceId.priceIds;
if (AumCalculator.getPriceIds(entry.priceId).join(",") !==
    expectedPriceIds.join(",")) {
  throw new Error("Reloaded price reference does not match the submitted chain");
}
console.log({
  signature,
  mint: entry.mint.toBase58(),
  priceId: entry.priceId,
  tokenSquadsAccount: entry.tokenSquadsAccount.toBase58(),
  tokenAccountVault: entry.tokenAccountVault.toBase58(),
  aumRefreshRequired: vault.isAumRefreshRequired(),
});
```

Run it:

```bash theme={null}
npx tsx configure-assets-and-prices.mts
```

After confirmation, [refresh prices and AUM](https://docs.exponent.finance/developer-strategy-vaults/refresh-aum.md) before the next setup operation. The script stops after adding and checking the entry.

If confirmation times out, resolve the transaction's status and reload the vault before retrying. Associated account creation is idempotent; adding a duplicate token entry is rejected.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.