Skip to main content

interveil_sdk/intent/
builder.rs

1use crate::intent::intent::Intent;
2use crate::intent::payload::IntentPayload;
3use crate::types::{Chain, Nonce};
4use std::time::{SystemTime, UNIX_EPOCH};
5
6impl Intent {
7    /// Create a TransferSol intent in one line.
8    /// Auto-sets: version = 1, chain = Solana, nonce = current timestamp millis
9    pub fn transfer_sol(to: String, lamports: u64) -> Self {
10        Self {
11            version: 1,
12            chain: Chain::Solana,
13            nonce: current_timestamp_millis(),
14            payload: IntentPayload::TransferSol { to, lamports },
15        }
16    }
17}
18
19/// Returns current UTC timestamp in milliseconds.
20/// Used as nonce source. Not cryptographically random, but sufficient
21/// for Phase 1 replay protection (unique per intent creation moment).
22fn current_timestamp_millis() -> Nonce {
23    SystemTime::now()
24        .duration_since(UNIX_EPOCH)
25        .expect("system clock before UNIX epoch")
26        .as_millis() as u64
27}