Skip to main content
intent-router is a thin coordinator. It does not execute trades, it records each step the user performs across delta-vault, split-engine, and yield-amm, and verifies the end-to-end achieved rate meets the user’s target.

Accounts

IntentSession

["session", owner, session_id_le].
FieldTypeNotes
ownerPubkeyUser
stateSessionStateCreated, Step1Complete, Step2Complete, Completed
session_idu64Client-supplied nonce
target_rateu64Minimum APY (9-decimal fixed point)
durationi64Lock duration in seconds
amountu64USDC deposited
vault_sharesu64After Step 1
pt_receivedu64After Step 2
yt_receivedu64After Step 2
market, poolPubkeyThe split-engine market + yield-AMM pool used
bumpu8

Instructions

InstructionPurpose
create_sessionOpen session (Created); stores target_rate, duration, amount, market, pool
record_step1Verify vault_shares delivered; advance to Step1Complete
record_step2Verify pt_received, yt_received; advance to Step2Complete
record_step3Verify swap; compute achieved_rate; require achieved_rate ≥ target_rate; advance to Completed
close_sessionClose account, refund rent (any state)

Rate formula (record_step3)

Given pt_sold and underlying_received from the AMM swap: discount=pt_soldunderlying_received\text{discount} = \text{pt\_sold} - \text{underlying\_received} achieved_rate=discount×ONE×SECONDS_PER_YEARunderlying_received×duration\text{achieved\_rate} = \frac{\text{discount} \times \text{ONE} \times \text{SECONDS\_PER\_YEAR}}{\text{underlying\_received} \times \text{duration}} If achieved_rate < target_rate, the instruction errors with TargetRateNotAchievable and the session stays at Step2Complete. The user’s PT and YT tokens are untouched, they can unwind manually.

Events

Only IntentFulfilled is emitted as an Anchor #[event] (at record_step3, carrying owner, session_id, amount, target_rate, achieved_rate, pt_received, yt_received). Session creation and the interim steps log progress via msg! and by advancing the session account’s state field.

Errors

InvalidSessionState, TargetRateNotAchievable, TargetRateNotAchieved, SessionCompleted, NotSessionOwner, MathOverflow, ZeroAmount, NoSharesReceived, NoTokensReceived, SlippageExceeded, PtBalanceMismatch, UnderlyingBalanceInsufficient, NoSwapPerformed, NegativeDiscount, InvalidDuration.

Fixed-rate intents

Why the session exists.

Lock a fixed rate

Full code walkthrough.