Aller au contenu

Jupiter Lend

Connector for Jupiter lending protocol on Solana.

almanak.framework.connectors.jupiter_lend

Jupiter Lend Protocol Connector.

Jupiter Lend is the #2 Solana money market (~$1.65B TVL), featuring isolated vaults, rehypothecation, and aggressive LTV ratios.

This connector provides: - JupiterLendClient: HTTP client for the Jupiter Lend API - JupiterLendAdapter: Adapter for converting lending intents to Solana transactions - JupiterLendReceiptParser: Balance-delta parser for extracting lending results

Example

from almanak.framework.connectors.jupiter_lend import JupiterLendClient, JupiterLendConfig

config = JupiterLendConfig(wallet_address="your-solana-pubkey") client = JupiterLendClient(config)

Get available vaults

vaults = client.get_vaults()

Build a deposit transaction

tx = client.deposit(vault=vaults[0].address, amount="100.0")

JupiterLendAdapter

JupiterLendAdapter(
    config: JupiterLendConfig,
    token_resolver: TokenResolver | None = None,
)

Adapter for Jupiter Lend integration with the Intent system.

Converts lending intents (Supply, Borrow, Repay, Withdraw) into ActionBundles containing serialized Solana VersionedTransactions from Jupiter Lend's REST API.

Example

config = JupiterLendConfig(wallet_address="your-solana-pubkey") adapter = JupiterLendAdapter(config)

intent = SupplyIntent(protocol="jupiter_lend", token="USDC", amount=Decimal("100")) bundle = adapter.compile_supply_intent(intent)

Initialize the Jupiter Lend adapter.

参数:

名称 类型 描述 默认
config JupiterLendConfig

Jupiter Lend client configuration

必需
token_resolver TokenResolver | None

Optional TokenResolver instance

None

compile_supply_intent

compile_supply_intent(intent: SupplyIntent) -> ActionBundle

Compile a SupplyIntent to an ActionBundle using Jupiter Lend.

参数:

名称 类型 描述 默认
intent SupplyIntent

The SupplyIntent to compile

必需

返回:

类型 描述
ActionBundle

ActionBundle containing a serialized Solana transaction

compile_borrow_intent

compile_borrow_intent(intent: BorrowIntent) -> ActionBundle

Compile a BorrowIntent to an ActionBundle using Jupiter Lend.

参数:

名称 类型 描述 默认
intent BorrowIntent

The BorrowIntent to compile

必需

返回:

类型 描述
ActionBundle

ActionBundle containing a serialized Solana transaction

compile_repay_intent

compile_repay_intent(intent: RepayIntent) -> ActionBundle

Compile a RepayIntent to an ActionBundle using Jupiter Lend.

参数:

名称 类型 描述 默认
intent RepayIntent

The RepayIntent to compile

必需

返回:

类型 描述
ActionBundle

ActionBundle containing a serialized Solana transaction

compile_withdraw_intent

compile_withdraw_intent(
    intent: WithdrawIntent,
) -> ActionBundle

Compile a WithdrawIntent to an ActionBundle using Jupiter Lend.

参数:

名称 类型 描述 默认
intent WithdrawIntent

The WithdrawIntent to compile

必需

返回:

类型 描述
ActionBundle

ActionBundle containing a serialized Solana transaction

JupiterLendClient

JupiterLendClient(config: JupiterLendConfig)

Client for interacting with the Jupiter Lend REST API.

This client provides methods for: - Listing lending vaults and their metrics - Building deposit, borrow, repay, and withdraw transactions

All transaction endpoints return base64-encoded unsigned VersionedTransactions. No authentication is required.

Example

config = JupiterLendConfig(wallet_address="your-solana-wallet-pubkey") client = JupiterLendClient(config)

vaults = client.get_vaults() tx = client.deposit(vault=vaults[0].address, amount="100.0")

Initialize the Jupiter Lend client.

参数:

名称 类型 描述 默认
config JupiterLendConfig

Jupiter Lend client configuration

必需

wallet_address property

wallet_address: str

Get the configured wallet address.

get_vaults

get_vaults(
    force_refresh: bool = False,
) -> list[JupiterLendVault]

List all available lending vaults.

Results are cached for 60 seconds to avoid redundant API calls during multi-intent compilation within a single strategy cycle.

参数:

名称 类型 描述 默认
force_refresh bool

If True, bypass cache and fetch fresh data.

False

返回:

类型 描述
list[JupiterLendVault]

List of JupiterLendVault objects

引发:

类型 描述
JupiterLendAPIError

If the API request fails

find_vault_by_token

find_vault_by_token(
    token_symbol: str,
) -> JupiterLendVault | None

Find a vault by token symbol.

参数:

名称 类型 描述 默认
token_symbol str

Token symbol (e.g., "USDC", "SOL")

必需

返回:

类型 描述
JupiterLendVault | None

JupiterLendVault if found, None otherwise

deposit

deposit(
    vault: str, amount: str, wallet: str | None = None
) -> JupiterLendTransactionResponse

Build a deposit (supply) transaction.

参数:

名称 类型 描述 默认
vault str

Vault address to deposit into

必需
amount str

Amount in token units (e.g., "100.5" for 100.5 USDC)

必需
wallet str | None

Wallet address (defaults to config wallet)

None

返回:

类型 描述
JupiterLendTransactionResponse

JupiterLendTransactionResponse with base64-encoded unsigned transaction

引发:

类型 描述
JupiterLendAPIError

If the API request fails

borrow

borrow(
    vault: str, amount: str, wallet: str | None = None
) -> JupiterLendTransactionResponse

Build a borrow transaction.

参数:

名称 类型 描述 默认
vault str

Vault address to borrow from

必需
amount str

Amount in token units (e.g., "50.0" for 50 USDC)

必需
wallet str | None

Wallet address (defaults to config wallet)

None

返回:

类型 描述
JupiterLendTransactionResponse

JupiterLendTransactionResponse with base64-encoded unsigned transaction

引发:

类型 描述
JupiterLendAPIError

If the API request fails

repay

repay(
    vault: str, amount: str, wallet: str | None = None
) -> JupiterLendTransactionResponse

Build a repay transaction.

参数:

名称 类型 描述 默认
vault str

Vault address to repay into

必需
amount str

Amount in token units (e.g., "50.0" for 50 USDC)

必需
wallet str | None

Wallet address (defaults to config wallet)

None

返回:

类型 描述
JupiterLendTransactionResponse

JupiterLendTransactionResponse with base64-encoded unsigned transaction

引发:

类型 描述
JupiterLendAPIError

If the API request fails

withdraw

withdraw(
    vault: str, amount: str, wallet: str | None = None
) -> JupiterLendTransactionResponse

Build a withdraw transaction.

Use amount=U64_MAX ("18446744073709551615") to withdraw all.

参数:

名称 类型 描述 默认
vault str

Vault address to withdraw from

必需
amount str

Amount in token units, or U64_MAX for withdraw-all

必需
wallet str | None

Wallet address (defaults to config wallet)

None

返回:

类型 描述
JupiterLendTransactionResponse

JupiterLendTransactionResponse with base64-encoded unsigned transaction

引发:

类型 描述
JupiterLendAPIError

If the API request fails

JupiterLendConfig dataclass

JupiterLendConfig(
    wallet_address: str,
    base_url: str = "https://api.jup.ag/lend",
    timeout: int = 30,
)

Configuration for Jupiter Lend client.

属性:

名称 类型 描述
wallet_address str

Solana wallet public key (Base58)

base_url str

Jupiter Lend API base URL

timeout int

Request timeout in seconds

__post_init__

__post_init__() -> None

Validate configuration.

JupiterLendAPIError

JupiterLendAPIError(
    message: str,
    status_code: int,
    endpoint: str | None = None,
    error_code: str | None = None,
    error_data: dict | None = None,
)

Bases: JupiterLendError

Exception raised for errors in the Jupiter Lend API response.

属性:

名称 类型 描述
message

Error message

status_code

HTTP status code of the response

endpoint

The API endpoint that was called

error_code

Jupiter Lend-specific error code

error_data

Parsed error data from the response

JupiterLendConfigError

JupiterLendConfigError(
    message: str, parameter: str | None = None
)

Bases: JupiterLendError

Exception raised for configuration errors.

属性:

名称 类型 描述
message

Error message

parameter

Name of the configuration parameter that caused the error

JupiterLendError

Bases: Exception

Base exception class for all Jupiter Lend connector errors.

JupiterLendValidationError

JupiterLendValidationError(
    message: str,
    field: str | None = None,
    value: Any | None = None,
)

Bases: JupiterLendError

Exception raised for validation errors.

属性:

名称 类型 描述
message

Error message

field

Name of the field that failed validation

value

The invalid value

JupiterLendTransactionResponse dataclass

JupiterLendTransactionResponse(
    transaction: str,
    action: str = "",
    raw_response: dict[str, Any] = dict(),
)

Response from a Jupiter Lend transaction endpoint.

The Jupiter Lend API returns a base64-encoded unsigned VersionedTransaction ready for signing and submission.

属性:

名称 类型 描述
transaction str

Base64-encoded unsigned Solana VersionedTransaction

action str

The lending action (deposit, borrow, repay, withdraw)

raw_response dict[str, Any]

Full API response for debugging

from_api_response classmethod

from_api_response(
    data: dict[str, Any], action: str = ""
) -> JupiterLendTransactionResponse

Create from Jupiter Lend API transaction response.

参数:

名称 类型 描述 默认
data dict[str, Any]

Jupiter Lend API response dict

必需
action str

The lending action (deposit, borrow, repay, withdraw)

''

返回:

类型 描述
JupiterLendTransactionResponse

Parsed JupiterLendTransactionResponse

JupiterLendVault dataclass

JupiterLendVault(
    address: str,
    name: str = "",
    token_symbol: str = "",
    token_mint: str = "",
    max_ltv: str = "0",
    borrow_apy: str = "0",
    supply_apy: str = "0",
    total_supply: str = "0",
    total_borrow: str = "0",
    total_supply_usd: str = "0",
    total_borrow_usd: str = "0",
    utilization: str = "0",
)

A Jupiter Lend isolated vault.

属性:

名称 类型 描述
address str

Vault account public key (Base58)

name str

Human-readable vault name

token_symbol str

Underlying token symbol (e.g., "USDC", "SOL")

token_mint str

SPL token mint address (Base58)

max_ltv str

Maximum loan-to-value ratio (e.g., "0.85" = 85%)

borrow_apy str

Current borrow APY as decimal string

supply_apy str

Current supply APY as decimal string

total_supply str

Total supplied amount (in token units)

total_borrow str

Total borrowed amount (in token units)

total_supply_usd str

Total supplied in USD

total_borrow_usd str

Total borrowed in USD

utilization str

Current utilization ratio as decimal string

from_api_response classmethod

from_api_response(data: dict[str, Any]) -> JupiterLendVault

Create from Jupiter Lend API vault response.

JupiterLendReceiptParser

JupiterLendReceiptParser(**kwargs: Any)

Receipt parser for Jupiter Lend transactions.

Uses balance-delta approach: compares pre/post token balances in the Solana transaction receipt to extract the actual amounts deposited, borrowed, repaid, or withdrawn.

Initialize JupiterLendReceiptParser.

参数:

名称 类型 描述 默认
**kwargs Any

Keyword arguments from receipt_registry (e.g., chain).

{}

parse_receipt

parse_receipt(
    receipt: dict[str, Any], action: str = ""
) -> dict[str, Any]

Parse a receipt for ReceiptParser protocol compatibility.

参数:

名称 类型 描述 默认
receipt dict[str, Any]

Solana transaction receipt dict

必需
action str

The lending action (deposit, borrow, repay, withdraw). If provided, only that extraction is performed.

''

返回:

类型 描述
dict[str, Any]

Dict with parsed lending data

extract_supply_amounts

extract_supply_amounts(
    receipt: dict[str, Any], token_mint: str | None = None
) -> LendingAmounts | None

Extract supply (deposit) amounts from receipt.

Supply = tokens leaving the wallet (pre > post).

extract_borrow_amounts

extract_borrow_amounts(
    receipt: dict[str, Any], token_mint: str | None = None
) -> LendingAmounts | None

Extract borrow amounts from receipt.

Borrow = tokens arriving at the wallet (post > pre).

extract_repay_amounts

extract_repay_amounts(
    receipt: dict[str, Any], token_mint: str | None = None
) -> LendingAmounts | None

Extract repay amounts from receipt.

Repay = tokens leaving the wallet (pre > post).

extract_withdraw_amounts

extract_withdraw_amounts(
    receipt: dict[str, Any], token_mint: str | None = None
) -> LendingAmounts | None

Extract withdraw amounts from receipt.

Withdraw = tokens arriving at the wallet (post > pre).