Integration Examples

Ready-to-use examples for major Solana protocols. Each shows the full commit → verify flow.

Jupiter Swap

DEX swap with intent verification. Protects against amount and slippage manipulation.

Raydium LP

Add/remove liquidity with verified amounts. Prevents pool ratio attacks.

Tensor / Magic Eden

NFT buy, list, bid, and delist with price verification.

Marinade Staking

Stake, unstake, delayed unstake, and claim with amount verification.

Jupiter Swap

Source: examples/jupiter-swap.ts

Intent Hash Format

const hash = computeIntentHash('jupiter_swap', {
  inputMint: 'So11111111111111111111111111111111111111112',
  outputMint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
  amount: 1_000_000_000,
  slippageBps: 50,
});

Protected Transaction

// 1. Commit intent (mobile)
const commitIx = createCommitIntentInstruction(user, JUPITER_PROGRAM, hash, 300);
await sendTx(commitIx);

// 2. Build Jupiter swap route
const route = await fetchJupiterRoute({ inputMint, outputMint, amount, slippageBps });
const swapIx = buildSwapInstruction(route);

// 3. Verify + swap atomically
const verifyIx = createVerifyIntentInstruction(user, JUPITER_PROGRAM, hash);
const tx = new Transaction().add(verifyIx).add(swapIx);

Attack scenario: If a compromised frontend changes amount from 1 SOL to 100 SOL, the hash won't match and the entire TX reverts.

Raydium LP

Source: examples/raydium-lp.ts

Add Liquidity

const hash = computeIntentHash('raydium_add_lp', {
  poolId: '58oQChx...',
  tokenAAmount: 500_000_000,
  tokenBAmount: 10_000_000,
  minLpTokens: 1_000,
});

Remove Liquidity

const hash = computeIntentHash('raydium_remove_lp', {
  poolId: '58oQChx...',
  lpTokenAmount: 5_000,
  minTokenA: 400_000_000,
  minTokenB: 8_000_000,
});

Tensor / Magic Eden NFT

Source: examples/tensor-nft.ts

Buy NFT

const hash = computeIntentHash('tensor_buy', {
  mint: 'NFTMint111...',
  maxPrice: 5_000_000_000,  // 5 SOL max
  marketplace: 'tensor',
});

List NFT

const hash = computeIntentHash('tensor_list', {
  mint: 'NFTMint111...',
  listPrice: 10_000_000_000,  // 10 SOL
  marketplace: 'tensor',
});

Marinade Staking

Source: examples/marinade-stake.ts

Stake SOL

const hash = computeIntentHash('marinade_stake', {
  amount: 10_000_000_000,  // 10 SOL
  minMsolReceived: 9_500_000_000,
});

Delayed Unstake

const hash = computeIntentHash('marinade_delayed_unstake', {
  msolAmount: 5_000_000_000,
  minSolReceived: 5_200_000_000,
});

SPL Token Transfer

Source: examples/protected-transfer.ts

const hash = computeIntentHash('transfer', {
  recipient: 'RecipientPubkey...',
  mint: 'EPjFWdd5...',
  amount: 1_000_000,  // 1 USDC
});

Rust CPI Integration

Source: examples/cpi-integration.rs

use intentguard_cpi::{verify_intent_cpi, VerifyAccounts};

pub fn protected_action(ctx: Context<MyAction>, hash: [u8; 32]) -> Result<()> {
    verify_intent_cpi(
        VerifyAccounts { /* ... */ },
        hash,
    )?;
    // Safe to proceed
    do_action(ctx)
}

Hash Format Summary

ProtocolAction NameKey Params
Jupiterjupiter_swapinputMint, outputMint, amount, slippageBps
Raydiumraydium_add_lppoolId, tokenAAmount, tokenBAmount, minLpTokens
Tensortensor_buymint, maxPrice, marketplace
Marinademarinade_stakeamount, minMsolReceived
Transfertransferrecipient, mint, amount