MonmouthMonmouth Docs

SVM Router

Overview

The SVM Router precompile (0x1003) enables Monmouth agents to execute Solana VM programs directly from EVM transactions. This provides:

  • Cross-Chain DeFi: Access Solana ecosystem liquidity from Monmouth
  • Unified Interface: Same SDK for EVM and SVM operations
  • Atomic Execution: EVM and SVM operations in a single transaction

Address

0x0000000000000000000000000000000000001003

Interface

interface ISVMRouter {
    /// @notice Execute a Solana program
    /// @param programId The Solana program to call
    /// @param instruction The instruction data
    /// @param accounts The accounts required by the instruction
    /// @return success Whether the execution succeeded
    /// @return returnData Any data returned by the program
    function executeProgram(
        bytes32 programId,
        bytes calldata instruction,
        SVMAccount[] calldata accounts
    ) external returns (bool success, bytes memory returnData);
 
    /// @notice Get a Solana account's data
    /// @param account The account address
    /// @return data The account data
    function getAccountData(
        bytes32 account
    ) external view returns (bytes memory data);
 
    /// @notice Check if a program exists
    /// @param programId The program to check
    /// @return exists Whether the program exists
    function programExists(
        bytes32 programId
    ) external view returns (bool exists);
}
 
struct SVMAccount {
    bytes32 pubkey;
    bool isSigner;
    bool isWritable;
}

SDK Usage

The Wallet SDK provides a high-level interface:

// Execute a cross-chain swap
const result = await wallet.executeIntent({
  type: 'cross-chain',
  targetChain: 'solana',
  intent: {
    type: 'swap',
    fromToken: 'SOL',
    toToken: 'USDC',
    amount: '10 SOL',
  }
})

For low-level access:

import { SVMRouter } from '@monmouth/wallet-sdk'
 
const router = new SVMRouter(wallet)
 
// Execute arbitrary program
const result = await router.executeProgram({
  programId: '...',
  instruction: Buffer.from([...]),
  accounts: [
    { pubkey: '...', isSigner: true, isWritable: true },
    { pubkey: '...', isSigner: false, isWritable: true },
  ],
})

Transaction Flow

1. Agent submits cross-chain intent
2. Wallet SDK encodes SVM instruction
3. Transaction sent to Monmouth
4. SVM Router precompile executes
5. Results returned to agent

Error Handling

try {
  await router.executeProgram(...)
} catch (error) {
  if (error.code === 'SVM_PROGRAM_ERROR') {
    console.log(error.programError) // Solana program error
    console.log(error.logs)         // Program logs
  }
  if (error.code === 'SVM_ACCOUNT_NOT_FOUND') {
    console.log(error.account)      // Missing account
  }
}

Gas Costs

OperationBase GasPer-Account Gas
executeProgram21,0005,000
getAccountData10,000-
programExists5,000-

Security Considerations

  1. Account Validation: All accounts are validated before execution
  2. Program Allowlist: Only verified programs can be called
  3. Value Limits: Cross-chain value subject to guardrails
  4. Timeout: SVM operations have 30-second timeout

On this page