Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

3.0 KB
Raw Blame
// `agent_wallet`: resolve a wallet and its SOL balance. Three modes:
//   asset   → the asset's built-in wallet (mpl-core Asset Signer PDA)
//   address → any wallet, verbatim
//   neither → the configured signer (the wallet that pays for mints)

import { z } from 'zod';

import { NETWORK, SOLANA_DEFAULT_SECRET } from '../config.js';
import { buildUmi, solBalance, assetSignerAddress } from '../lib/solana.js';
import { threeBalance, tierFor, nextTier } from '../lib/three.js';

export const def = {
	name: 'agent_wallet',
	title: "An agent's built-in wallet, or the signer wallet, with balance",
	annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: false, openWorldHint: true },
	description:
		"Show a wallet address and its live SOL balance. Pass `asset` to derive an on-chain agent's built-in wallet " +
		'(the Metaplex Core Asset Signer PDA, the wallet shown on metaplex.com/agents). Pass `address` to inspect ' +
		'any wallet. Pass neither to see the configured signing wallet, e.g. to confirm it is funded before ' +
		'mint_onchain_agent. On mainnet it also reports the wallet $THREE balance and the deploy-fee tier that ' +
		'balance earns (see three_status). Use this to check a balance before a mint or after funding a wallet. ' +
		'Read-only; never moves funds.',
	inputSchema: {
		asset: z.string().min(32).max(44).optional().describe("A Core asset address: derives that agent's built-in wallet."),
		address: z.string().min(32).max(44).optional().describe('A wallet address to inspect verbatim.'),
		network: z.enum(['mainnet', 'devnet']).optional().describe('Cluster. Defaults to the configured network.'),
	},
	async handler(args) {
		const network = args.network || NETWORK;
		if (args.asset && args.address) {
			throw Object.assign(new Error('pass either `asset` or `address`, not both'), { code: 'validation_error' });
		}
		const umi = buildUmi({ network });

		let address;
		let kind;
		if (args.asset) {
			address = assetSignerAddress(umi, args.asset);
			kind = 'asset_signer';
		} else if (args.address) {
			address = String(args.address).trim();
			kind = 'address';
		} else {
			if (!SOLANA_DEFAULT_SECRET) {
				throw Object.assign(
					new Error('No `asset` or `address` given and no SOLANA_SECRET_KEY configured. Pass one, or set a signer.'),
					{ code: 'no_signer' },
				);
			}
			const signerUmi = buildUmi({ network, requireSigner: true });
			address = signerUmi.identity.publicKey.toString();
			kind = 'signer';
		}

		const sol = await solBalance(umi, address);

		// The $THREE read is mainnet-only (the mint does not exist on devnet) and
		// never fatal: a wallet lookup must still answer if the token RPC hiccups.
		let three = null;
		if (network === 'mainnet') {
			three = await threeBalance(umi, address).catch(() => null);
		}

		return {
			ok: true,
			network,
			kind,
			address,
			sol,
			...(three
				? {
						three: three.tokens,
						three_tier: tierFor(three.tokens).tier,
						three_next_tier: nextTier(three.tokens),
					}
				: {}),
			...(args.asset ? { asset: args.asset } : {}),
		};
	},
};