The RainFi loan operations enable collateralized lending on Solana. Users can borrow assets against collateral with transparent terms, competitive APRs, and automated liquidation protection.
Quote loan calculator
Calculate loan quotes with optimal interest rates based on available liquidity pools.
Function signature
quoteLoanCalculator ( params : {
amountIn: number ;
currencyIn : string ;
currencyOut : string ;
borrower : string ;
}): Promise < LoanTransactionRequest >
Parameters
Amount of collateral to deposit, in smallest units (lamports for SOL)
Collateral currency address. Must be a valid Solana token mint address. Example: "So11111111111111111111111111111111111111112" for SOL
Loan currency address. Must be a valid Solana token mint address. Example: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" for USDC
Borrower’s wallet public key as a base58 string
Response
Complete loan request ready for execution Borrower’s wallet address
Collateral amount in smallest units
Collateral currency address
Best available loan terms from liquidity pools Show simulation properties
Loan amount in smallest units
Total interest amount as string
Authorization token for transaction execution
Base loan amount before fees
Slippage tolerance in basis points (default: 1000 = 10%)
Transaction fee configuration prioritizationFeeLamports
Priority fee level: "fast", "medium", or "slow"
Maximum fee cap in lamports (optional)
Jito MEV tip amount in lamports (optional)
Example usage
import { quoteLoanCalculator } from '@/utils/syntoUtils/agent/plugins/plugin-defi/rainfi/tools' ;
const quote = await quoteLoanCalculator ({
amountIn: 1000000000 , // 1 SOL
currencyIn: "So11111111111111111111111111111111111111112" , // SOL
currencyOut: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" , // USDC
borrower: "2gLAprD3LUJrSGdcXv88Nvi1ZfHRqpaL7c84SV7M4XWs" ,
});
console . log ( `Loan amount: ${ quote . simulation . amount } ` );
console . log ( `APR: ${ quote . simulation . apr } %` );
console . log ( `Duration: ${ quote . simulation . duration } seconds` );
API endpoint
POST https://api-v3.rain.fi/loan-calculator/defi/quote
{
"order" : [ "LowestInterest" ],
"amountIn" : 1000000000 ,
"currencyIn" : "So11111111111111111111111111111111111111112" ,
"currencyOut" : "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" ,
"minDurationInDays" : 1 ,
"borrower" : "2gLAprD3LUJrSGdcXv88Nvi1ZfHRqpaL7c84SV7M4XWs"
}
{
"order" : [ "LowestInterest" ],
"amountIn" : 1000000000 ,
"currencyIn" : "So11111111111111111111111111111111111111112" ,
"currencyOut" : "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" ,
"borrower" : "2gLAprD3LUJrSGdcXv88Nvi1ZfHRqpaL7c84SV7M4XWs" ,
"isReverse" : false ,
"minDurationInDays" : 1 ,
"simulations" : [
{
"amount" : 109821097 ,
"duration" : 691200 ,
"interest" : "0" ,
"rainFees" : 0 ,
"apr" : 0 ,
"pool" : "B4eiUfuTBjiy8BbcdU44PT7q57TkmK54dWtT3YJAZZTB" ,
"bank" : "6SaE8e2bpm78Ewv8WUqguEPYUoEXRNTn7jzL8xzgH6Bv" ,
"authorization" : "C6MnBHEVVRkoFkt6uzJzboYJU4vCZbkjC2EtsXk3GbRs"
}
]
}
Build loan transaction
Build and execute a loan transaction using pre-calculated quote parameters.
Function signature
RainfiTransactionBuilder (
agent : SolanaAgentKit ,
params : LoanTransactionRequest
): Promise < string >
Parameters
Initialized Solana agent instance with wallet and connection
params
LoanTransactionRequest
required
Response
Transaction signature after successful execution
Example usage
Complete flow
With error handling
import { quoteLoanCalculator , RainfiTransactionBuilder } from '@/utils/syntoUtils/agent/plugins/plugin-defi/rainfi/tools' ;
import { SolanaAgentKit } from '@/utils/syntoUtils/agent' ;
// Step 1: Get loan quote
const quote = await quoteLoanCalculator ({
amountIn: 1000000000 ,
currencyIn: "So11111111111111111111111111111111111111112" ,
currencyOut: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" ,
borrower: agent . wallet . publicKey . toString (),
});
// Step 2: Display quote to user
console . log ( `APR: ${ quote . simulation . apr } %` );
console . log ( `Loan amount: ${ quote . simulation . amount } ` );
// Step 3: Execute transaction
const signature = await RainfiTransactionBuilder ( agent , quote );
console . log ( `Transaction successful: ${ signature } ` );
API endpoint
POST https://api-v3.rain.fi/transaction-builder/defi/take-loan
{
"borrower" : "2gLAprD3LUJrSGdcXv88Nvi1ZfHRqpaL7c84SV7M4XWs" ,
"amountIn" : 23000000000 ,
"currencyIn" : "So11111111111111111111111111111111111111112" ,
"currencyOut" : "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" ,
"simulation" : {
"amount" : 109821097 ,
"duration" : 691200 ,
"interest" : "0" ,
"rainFees" : 0 ,
"apr" : 0 ,
"currency" : "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" ,
"bank" : "6SaE8e2bpm78Ewv8WUqguEPYUoEXRNTn7jzL8xzgH6Bv" ,
"authorization" : "C6MnBHEVVRkoFkt6uzJzboYJU4vCZbkjC2EtsXk3GbRs" ,
"pool" : "B4eiUfuTBjiy8BbcdU44PT7q57TkmK54dWtT3YJAZZTB" ,
"baseAmount" : 109821097
},
"slippage" : 50 ,
"options" : {
"prioritizationFeeLamports" : "fast" ,
"maxFeeCapLamports" : 0 ,
"jitoTipLamports" : 1408925
}
}
{
"transactions" : [ "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQAHEb...base64..." ],
"version" : 0 ,
"kind" : "defi-take-loan" ,
"blockhash" : "4sGjMW1kKj1VqBdKpNxKBJQqGWJKvZqxKGCPxrVyGyB2" ,
"lastValidBlockHeight" : 245678910
}
Get user loans
Retrieve all active loans for a wallet address.
Function signature
GetUserLoans ( params : {
address: string ;
}): Promise < { loans : UserLoans [] } >
Parameters
Wallet public key to query loans for
Response
Array of active loans Show UserLoans properties
Borrower’s wallet address
Total borrowed amount in smallest units
Loan expiration timestamp (ISO 8601)
Liquidation threshold ratio
Total interest amount. Note: 10 = 0.1%
Principal token mint address
Collateral token mint address
Collateral amount in smallest units
Example usage
Basic usage
With agent
Display formatted
import { GetUserLoans } from '@/utils/syntoUtils/agent/plugins/plugin-defi/rainfi/tools' ;
const { loans } = await GetUserLoans ({
address: "2gLAprD3LUJrSGdcXv88Nvi1ZfHRqpaL7c84SV7M4XWs" ,
});
console . log ( `Found ${ loans . length } active loans` );
loans . forEach ( loan => {
console . log ( `Loan: ${ loan . pubkey } ` );
console . log ( `Amount: ${ loan . borrowedAmount } ` );
console . log ( `Expires: ${ loan . expiredAt } ` );
});
API endpoint
GET https://api-v3.rain.fi/api/loan/user?pubkey={address}&status=Ongoing&offset=0&limit=20
{
"user" : "2gLAprD3LUJrSGdcXv88Nvi1ZfHRqpaL7c84SV7M4XWs" ,
"status" : "Ongoing" ,
"limit" : 20 ,
"offset" : 0 ,
"isAdmin" : 0 ,
"totalCount" : 2 ,
"ongoingCount" : 2 ,
"loans" : [
{
"__t" : "defi-loan" ,
"pubkey" : "8xKjzqKGqz8SjhXVy5tJGBR5Q2vC9YmKbW3pZrNfDxYz" ,
"borrower" : "2gLAprD3LUJrSGdcXv88Nvi1ZfHRqpaL7c84SV7M4XWs" ,
"borrowedAmount" : "109821097" ,
"expiredAt" : "2026-03-11T12:00:00.000Z" ,
"duration" : 691200 ,
"liquidation" : 75 ,
"interest" : "0" ,
"principal" : "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" ,
"collateral" : "So11111111111111111111111111111111111111112" ,
"collateralAmount" : "1000000000"
}
]
}
Interest values are stored as basis points. To convert to percentage, divide by 100. For example, "10" = 0.1%.
Repay loan
Repay an outstanding loan and reclaim collateral.
Function signature
RepayLoan (
agent : SolanaAgentKit ,
params : RepayLoanRequest
): Promise < string >
Parameters
Initialized Solana agent instance with wallet and connection
Loan repayment parameters Show RepayLoanRequest properties
Borrower’s wallet address
Amount to repay in smallest units (must cover principal + interest)
Loan account public key from GetUserLoans
options
TransactionOptions
required
Transaction fee configuration prioritizationFeeLamports
Priority fee level: "fast", "medium", or "slow"
Maximum fee cap in lamports (optional)
Jito MEV tip amount in lamports (optional)
Response
Transaction signature after successful repayment
Example usage
Basic repayment
With validation
Repay specific loan
import { GetUserLoans , RepayLoan } from '@/utils/syntoUtils/agent/plugins/plugin-defi/rainfi/tools' ;
// Get active loans
const { loans } = await GetUserLoans ({
address: agent . wallet . publicKey . toString (),
});
if ( loans . length > 0 ) {
const loan = loans [ 0 ];
// Calculate total repayment (principal + interest)
const totalRepayment = parseFloat ( loan . borrowedAmount ) + parseFloat ( loan . interest );
// Repay the loan
const signature = await RepayLoan ( agent , {
borrower: agent . wallet . publicKey . toString (),
amountIn: totalRepayment ,
loan: loan . pubkey ,
options: {
prioritizationFeeLamports: "fast" ,
maxFeeCapLamports: 0 ,
jitoTipLamports: 688925 ,
},
});
console . log ( `Loan repaid: ${ signature } ` );
}
API endpoint
POST https://api-v3.rain.fi/transaction-builder/defi/repay-loan
{
"borrower" : "2gLAprD3LUJrSGdcXv88Nvi1ZfHRqpaL7c84SV7M4XWs" ,
"amountIn" : 109821097 ,
"loan" : "8xKjzqKGqz8SjhXVy5tJGBR5Q2vC9YmKbW3pZrNfDxYz" ,
"isDefi" : true ,
"options" : {
"prioritizationFeeLamports" : "fast" ,
"maxFeeCapLamports" : 0 ,
"jitoTipLamports" : 688925
}
}
{
"transactions" : [ "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQAHEb...base64..." ],
"version" : 0 ,
"kind" : "defi-repay-loan" ,
"blockhash" : "9fGjKL2pNm34Qab7xVqRsEPYTnYXMKtn8mzR9yzgR4C3" ,
"lastValidBlockHeight" : 245679123
}
Ensure you have sufficient balance of the loan currency to cover the full repayment amount (principal + interest).
AI agent actions
All RainFi operations are also available as AI agent actions for natural language interaction.
RAINFI_QUOTE_LOAN_CALCULATOR
RAINFI_QUOTE_LOAN_CALCULATOR
["quote loan calculator", "calculate loan", "get loan quote", "loan quote calculator"]
Calculate the loan quote for a given amount and currency. Currencies must be addresses, not symbols. Once you have the quote, display it to the user in a readable format before calling another tool.
RAINFI_TRANSACTION_BUILDER
RAINFI_TRANSACTION_BUILDER
["build rainfi transaction", "execute loan transaction", "build loan transaction", "create rainfi transaction", "execute rainfi loan"]
Build and execute a loan transaction on RainFi using the loan quote parameters. The borrower is automatically set to the wallet public key.
RAINFI_GET_USER_LOANS
["get user loans", "get user loan"]
Get user loans from RainFi. Displays loans in a readable format, converts interest to percentage (10 = 0.1%), and converts amounts from smallest units to correct decimals.
RAINFI_REPAY_LOAN
["repay loan", "repay loans"]
Repay a loan from RainFi using the provided loan account address.
Source code reference
Plugin index ~/workspace/source/utils/syntoUtils/agent/plugins/plugin-defi/index.ts:1
Quote calculator ~/workspace/source/utils/syntoUtils/agent/plugins/plugin-defi/rainfi/tools/quoteLoanCalculator.ts:10
Transaction builder ~/workspace/source/utils/syntoUtils/agent/plugins/plugin-defi/rainfi/tools/RainfiTransactionBuilder.ts:15
Get user loans ~/workspace/source/utils/syntoUtils/agent/plugins/plugin-defi/rainfi/tools/GetUserLoans.ts:10
Repay loan ~/workspace/source/utils/syntoUtils/agent/plugins/plugin-defi/rainfi/tools/RepayLoans.ts:15
Type definitions ~/workspace/source/utils/syntoUtils/agent/plugins/plugin-defi/rainfi/types/index.ts:1