Skip to main content
The DeFi plugin provides seamless integration with decentralized finance protocols on Solana, enabling your AI agent to perform lending, borrowing, and loan management operations through RainFi.

Features

The DeFi plugin offers four core capabilities:

Loan quotes

Calculate loan quotes with optimal interest rates and terms

Loan execution

Build and execute collateralized loan transactions

Loan management

Retrieve all active loans for a wallet address

Loan repayment

Repay outstanding loans and reclaim collateral

Installation

The DeFi plugin is included in the Synto Mobile SDK. Initialize it when configuring your agent:
import DefiPlugin from '@/utils/syntoUtils/agent/plugins/plugin-defi';
import { SolanaAgentKit } from '@/utils/syntoUtils/agent';

const agent = new SolanaAgentKit(
  privateKey,
  rpcUrl,
  openAiApiKey
);

// Plugin is automatically available
agent.defi.quoteLoanCalculator(params);

Plugin structure

The plugin exports methods and actions that work together:
const DefiPlugin = {
  name: "defi",
  
  methods: {
    quoteLoanCalculator,
    RainfiTransactionBuilder,
    GetUserLoans,
    RepayLoan,
  },
  
  actions: [
    quoteLoanCalculatorAction,
    rainfiTransactionBuilderAction,
    rainfiGetUserLoansAction,
    rainfiRepayLoanAction,
  ],
  
  initialize: function (agent: SolanaAgentKit): void {
    // Binds all methods to the agent instance
  },
};

API endpoint

All operations communicate with the RainFi API:
RAINFI_API
string
default:"https://api-v3.rain.fi"
Base URL for all RainFi protocol operations

Available operations

RainFi loans

Complete API reference for RainFi loan operations including quotes, execution, management, and repayment

Error handling

All DeFi operations return structured responses with error handling:
try {
  const quote = await agent.defi.quoteLoanCalculator({
    amountIn: 1000000000,
    currencyIn: "So11111111111111111111111111111111111111112",
    currencyOut: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    borrower: walletAddress,
  });
  
  return {
    status: "success",
    message: "Loan quote calculated successfully",
    loanTransactionRequest: quote,
  };
} catch (error) {
  return {
    status: "error",
    message: error.message,
  };
}

Common error messages

No loan quote found
error
No available loans match the requested parameters. Try increasing the amount or using different currencies.
API request failed
error
The RainFi API returned an error. Check the status code and message for details.
Failed to parse API response as JSON
error
The API response was invalid. This may indicate a temporary service issue.
Invalid transaction: No account keys found
error
The transaction builder returned an invalid transaction. Verify all parameters are correct.

Best practices

1

Use currency addresses

Always use full Solana addresses for currencies, not symbols. For example, use "So11111111111111111111111111111111111111112" for SOL.
2

Display quotes before execution

Show loan quotes to users in a readable format before executing transactions. Include APR, duration, fees, and total repayment amount.
3

Handle amounts correctly

All amounts are in the smallest unit (lamports for SOL, base units for tokens). Convert to decimals for display.
4

Validate loan status

Before attempting repayment, verify the loan exists and is in “Ongoing” status using GetUserLoans.

Next steps

RainFi loans

Detailed API reference for all RainFi operations

AI agent actions

Learn how actions work with the AI agent

Build docs developers (and LLMs) love