Skip to content

Spending Cross-Chain

Build a spend request, submit it to the attester for signing, then execute the attestation on the destination chain.

use alloy_primitives::{address, U256};
use trident_sdk::SpendRequestBuilder;
let request = SpendRequestBuilder::new(
1, // source domain (Avalanche)
address!("aaa..."), // source token address
2, // destination domain (Optimism)
address!("bbb..."), // destination token address
address!("ccc..."), // recipient on destination chain
U256::from(500_000), // amount
);
// Optional: pin execution to a specific caller address
// let request = request.with_caller(address!("ddd..."));
// Optional: set an explicit max fee (otherwise estimated automatically)
// let request = request.with_max_fee(U256::from(1000));
// Submit to attester - returns a signed attestation
let attestation = client.spend(request).await?;
// Execute the attestation on-chain (destination chain)
let receipt = attestation.execute().await?;
println!("Spend tx: {:?}", receipt.transaction_hash);
  1. The SDK generates a random anti-replay salt
  2. If no max_fee is set, the SDK calls the attester’s GetSpendFees RPC to estimate fees
  3. The spend intent is submitted to the attester’s delivery service
  4. The attester validates the request, checks balances, and returns a signed AcceptedSpendAttestation
  5. If rejected, a SpendRejected error is returned with the reason
  1. The SDK calls tridentSpend(attestation, signature) on the destination Trident contract
  2. The contract verifies the signer, domain, expiry, and replay protection
  3. If usdcMinted > 0: USDC is minted via Circle Gateway and supplied to Aave as collateral
  4. The requested token is borrowed from Aave V3
  5. The borrowed token is transferred to the recipient
  6. If any step fails, the entire transaction reverts
FieldRequiredDescription
src_domainYesSource chain domain ID
src_tokenYesToken address on the source chain
dst_domainYesDestination chain domain ID
dst_tokenYesToken address on the destination chain
dst_recipientYesAddress that receives tokens on the destination chain
amountYesAmount to transfer (in token’s smallest unit)
max_feeNoMaximum fee you’re willing to pay. Auto-estimated if omitted
callerNoIf set, only this address can submit the attestation on-chain. Defaults to address(0) (any caller)