Intents Client SDK
SDK for working with the intents program in Solana. Allows creating, managing, and executing intents for cross-chain operations.
Installation
npm install @debridge-finance/intents-client
File Structure and Usage Flow
The examples folder contains a sequence of files that demonstrate the complete workflow for using the Intents Client SDK. Each file represents a specific step in the process:
1. 01-init-intent-client.ts - Client Initialization
Purpose: Sets up the basic client configuration Contains:
new IntentsClient()- Instantiates the intents client
2. 02-init-intent.ts - Intent Configuration
Purpose: Defines the intent structure and parameters Contains:
- No client methods called
3. 03-create-intent.ts - Intent Creation and Deployment
Purpose: Creates and deploys the intent to the blockchain Contains:
client.createAndUpdateIntentTxs()- Creates single transaction (preferred)client.createIntentTxs()- Creates multiple transactions (fallback)
4. 05-sandwich-swap.ts - Swap Execution
Purpose: Performs token swaps using the created intent Contains:
client.swapTxs()- Generates swap transaction
5. 06-intent-execution.ts - Intent Execution
Purpose: Final step of executing the intent through DLN Contains:
client.executeIntentIxs()- Generates execution instructions
Call Sequence
Step-by-Step Execution Flow:
-
Initialize Client (
01-init-intent-client.ts)- Create Solana connection
- Generate keypair
- Instantiate IntentsClient
-
Configure Intent (
02-init-intent.ts)- Define Intent object with all parameters
- Set token addresses, amounts, and cross-chain details
-
Deploy Intent (
03-create-intent.ts)- Serialize intent data
- Try single transaction creation
- Fall back to multi-transaction if needed
- Send transactions to blockchain
-
Execute Swap (
04-sandwich-swap.ts)- Set up token accounts
- Create swap transaction with intent
- Execute the swap
-
Complete Intent (
05-intent-execution.ts)- Initialize DLN client
- Create cross-chain order
- Generate final execution instructions
Intent versions
Intent carries its wire format version: it is passed to the constructor and to Intent.deserialize. The program
accepts both v0 and v1 for new intents: the version is passed to initIntent* (take it from intent.version), recorded in
the intent storage and used to decode the intent at seal and later on; a payload that does not match the recorded version
is rejected. In v1 every exact price is a fraction:
output = input * price / 10^priceDenominator, where priceDenominator is in 0..=38:
const intent = new Intent(
{
// ...
giveTokens: [{ output: USDC, input: USDT, price: 1n, priceDenominator: 0 }],
},
IntentVersion.V1,
);
const encoded = intent.serialize();
v0 intents (price is scaled by the input mint decimals, no priceDenominator) are still decoded.
Intent<V> and IntentType<V> are generic over the version, so exact prices are checked at compile time:
priceDenominator is required for IntentVersion.V1 and not allowed for IntentVersion.V0
(the 0..=38 range is checked by serialize()).
The intent storage account keeps everything needed to decode the intent: the owner (maker), the version recorded at
init (version) and the encoded intent (storedIntent.ready|cancelled, returned as encodedIntent):
const storage = await client.getIntentStorage(connection, intentId);
// storage.encodedIntent is null while the storage is not initialized
const { maker, version, encodedIntent } = storage!;
switch (version) {
case IntentVersion.V0:
// Intent<IntentVersion.V0>
Intent.deserialize(encodedIntent!, maker, IntentVersion.V0);
break;
case IntentVersion.V1:
// Intent<IntentVersion.V1>: exact prices have priceDenominator
Intent.deserialize(encodedIntent!, maker, IntentVersion.V1);
break;
}
IntentsClient methods
- getState()
- getIntentStorage()
- executeIntentIxs()
- initIntentIxs()
- initIntentUsingSigIxs()
- setDelegateApprovedBudgetsIxs()
- swapBeginIxs()
- swapEndIxs()
- updateIntentIxs()
- closeRecordIxs()
- writeRecordIxs()
- reallocRecordIxs()
- initIntentTxs()
- writeIntentTxs()
- createIntentTxs()
- createAndUpdateIntentTxs()
- updateRecordTxs()
- closeIntentTxs()
- swapTxs()