mcpField
L
lavarage

lavarage

github.com/sendaifun其他13077 次安装13 周前更新
代码仓库

关于 lavarage

Lavarage 是运行在 Solana 上的杠杆交易协议,可交易有流动性池的 SPL token。该 skill 通过 REST API 指引市场发现、报价、交易构建及仓位管理,并支持 MEV 保护提交。

主要功能

  1. 01搜索可用代币市场与流动性池
  2. 02构建多空杠杆及借贷交易
  3. 03预览交易报价和清算价格
  4. 04管理仓位、抵押品与杠杆
  5. 05通过 MEV 保护端点提交交易

适用场景

  1. 01查找长尾 SPL token 的杠杆市场
  2. 02交易前预览价格影响和预期收益
  3. 03部分平仓或为仓位追加抵押品
  4. 04借入代币而不建立方向性仓位

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/sendaifun/skills --skill lavarage

安装后在 Claude Code 中输入/lavarage确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

docs/
troubleshooting.md
examples/
borrow.ts
close-position.ts
discover-markets.ts
open-long.ts
open-short.ts
portfolio.ts
resources/
api-reference.md
program-addresses.md
types-reference.md
templates/
client.ts

详细介绍

Lavarage Protocol — Solana 上的杠杆交易

概述

Lavarage 是 Solana 上的无许可杠杆交易协议。与仅支持少数代币的固定市场永续合约平台不同,Lavarage 支持对任何拥有流动性池的 SPL 代币进行杠杆交易,包括 Meme 币、现实世界资产(股票、大宗商品)和长尾代币。

  • 杠杆做多 — 存入 SOL 或 USDC 作为抵押品,借入资金以放大敞口,最高可达 12x
  • 杠杆做空 — 存入 USDC 作为抵押品,做空任何受支持的代币
  • 广泛的代币覆盖范围 — 数百种代币,包括 BTC、ETH、SOL、Meme 币、股票(OPENAI、SPACEX)、黄金(XAUt0)等
  • 动态市场发现 — 搜索任意代币,查看是否存在杠杆市场
  • 仓位管理 — 部分卖出、拆分、合并、追加抵押品、提高杠杆
  • MEV 防护 — 通过 Astralane/Jito 提交交易,防范三明治攻击

主要差异点: 如果某个代币在其他杠杆交易平台上不可用,可以查看 Lavarage——无许可创建资金池意味着 Lavarage 通常支持固定市场协议不支持的代币。

快速开始

安装

无需安装 SDK。Lavarage 使用 REST API 返回可直接签名的 Solana 交易。请从此技能中的 templates/client.ts 复制 LavaApiClient。

import { LavaApiClient } from './client'

const client = new LavaApiClient(
  'https://api.lavarage.xyz',
  'lv2_prod_5e5f38fefc893ade780d8a2ccd7433ad8307808c83260e75',
  'your-wallet-public-key'
)

上面的公共 API 密钥可以安全使用——它用于标识负责费用路由的集成合作伙伴。仓位始终由钱包签名进行限定。

基本流程

每笔交易都遵循以下模式:

1. Discover  →  Search tokens & offers to find leveraged markets
2. Quote     →  Preview the trade (swap output, price impact, fees)
3. Build TX  →  API returns a serialized Solana transaction
4. Sign      →  Sign the transaction with your wallet
5. Submit    →  Send via MEV-protected endpoint

核心概念

代币覆盖范围

Lavarage 支持对任何拥有流动性池的 SPL 代币进行杠杆交易,包括:

  • 蓝筹代币: SOL、BTC(WBTC、cbBTC、zBTC)、ETH(WETH)
  • 作为抵押品的稳定币: 做空仓位使用 USDC
  • 现实世界资产: OPENAI、SPACEX(代币化股票)
  • 大宗商品: XAUt0(黄金)
  • Meme 币和长尾代币: 数百种拥有活跃资金池的代币

务必先搜索——不要假定某个代币不可用。任何人都可以创建新资金池。

// Search for any token by name, symbol, or mint address
const offers = await client.getOffers({ search: 'OPENAI', side: 'LONG' })
if (offers.length > 0) {
  console.log(`Found ${offers.length} offers for OPENAI`)
}
方向:LONG 与 SHORT
  • LONG: 存入抵押品(SOL/USDC),借入更多资金并兑换成目标代币。目标代币价格上涨时获利。
  • SHORT: 存入 USDC 作为抵押品,借入目标代币并卖出。目标代币价格下跌时获利。

API 会根据报价的基础代币自动确定方向:

  • 基础代币不是 USDC → LONG 仓位
  • 基础代币是 USDC → SHORT 仓位
杠杆

杠杆范围从 1.1x 到报价的最高杠杆(视资金池而定,最高约为 12x)。杠杆越高,潜在收益越高,但清算风险也越大。

Effective exposure = collateral × leverage
Borrowed amount = collateral × (leverage - 1)
单位
  • 抵押品输入: 始终使用代币的最小单位(SOL 的 lamports = 数量 × 10^9,micro-USDC = 数量 × 10^6)
  • 价格: USD
  • 滑点: 基点(50 = 0.5%)
  • 拆分/部分卖出数量: 仓位的基点(5000 = 50%)
报价(流动性池)

“报价”是一个流动性池,具有特定的基础代币-计价代币组合、利率和杠杆上限。同一代币组合可以对应多个报价,条款各不相同。请始终根据用户需求选择利率最优且流动性最高的报价。

核心操作

1. 发现可用市场

开仓前,请先搜索可用市场:

// Search by token name or symbol
const offers = await client.getOffers({ search: 'BTC' })

// Filter by side
const longOffers = await client.getOffers({ search: 'ETH', side: 'LONG' })
const shortOffers = await client.getOffers({ search: 'ETH', side: 'SHORT' })

// Get all available tokens
const tokens = await client.getTokens()

// Each offer includes:
// - offerPublicKey (needed for opening position)
// - baseToken { symbol, mint, decimals, priceUsd, logoUri }
// - quoteToken { symbol, mint, decimals, priceUsd }
// - side: 'LONG' | 'SHORT'
// - maxLeverage: number
// - interestRate: number (annual %)
// - totalLiquidity: string (available to borrow)
2. 获取报价(预览交易)

开仓前务必获取报价,以向用户展示预期输出:

const quote = await client.getOpenQuote({
  offerPublicKey: offer.address,
  userPublicKey: walletAddress,
  collateralAmount: '1000000000', // 1 SOL in lamports
  leverage: 3,
  slippageBps: 50,
})

// quote returns:
// - expectedOutput: tokens received
// - priceImpact: percentage
// - fees: breakdown of all fees
// - liquidationPrice: price at which position gets liquidated
3. 开仓
import { VersionedTransaction } from '@solana/web3.js'
import bs58 from 'bs58'

// Get MEV protection tip
const { tipLamports } = await client.getTipFloor()

// Build the transaction
const result = await client.buildOpenTx({
  offerPublicKey: offer.address,
  userPublicKey: walletAddress,
  collateralAmount: '1000000000', // 1 SOL
  leverage: 3,
  slippageBps: 50,
  astralaneTipLamports: tipLamports, // MEV protection
})

// result.transaction is base58-encoded
// Deserialize, sign, and submit:
const txBytes = bs58.decode(result.transaction)
const tx = VersionedTransaction.deserialize(txBytes)

// Sign with wallet
tx.sign([walletKeypair])

// Submit with MEV protection
const serialized = bs58.encode(tx.serialize())
const { result: txSignature } = await client.submitTransaction(serialized, true)
console.log(`Position opened: ${txSignature}`)
4. 平仓
// Preview close first
const closeQuote = await client.getCloseQuote({
  positionAddress: position.address,
  userPublicKey: walletAddress,
  slippageBps: 50,
})
// closeQuote shows: proceeds, pnl, fees

// Build close transaction
const { tipLamports } = await client.getTipFloor()
const result = await client.buildCloseTx({
  positionAddress: position.address,
  userPublicKey: walletAddress,
  slippageBps: 50,
  astralaneTipLamports: tipLamports,
})

// Sign and submit (same pattern as open)
const txBytes = bs58.decode(result.transaction)
const tx = VersionedTransaction.deserialize(txBytes)
tx.sign([walletKeypair])
const serialized = bs58.encode(tx.serialize())
await client.submitTransaction(serialized, true)
5. 列出仓位
// All positions
const positions = await client.getPositions()

// Filter by status
const active = await client.getPositions('EXECUTED')

// Each position includes computed fields:
// - address, status, side
// - collateralAmount, borrowedAmount
// - currentPrice, entryPrice
// - unrealizedPnlUsd, roiPercent
// - liquidationPrice, currentLtv
// - effectiveLeverage
// - interestAccrued, dailyInterestCost
// - baseToken, quoteToken metadata
6. 部分卖出

卖出部分仓位,同时保留其余仓位:

// Sell 30% of position
const result = await client.buildPartialSellTx({
  positionAddress: position.address,
  userPublicKey: walletAddress,
  splitRatioBps: 3000, // 30%
  slippageBps: 50,
})

// Returns two transactions that must be submitted as a Jito bundle:
// 1. Split transaction (splits position into two)
// 2. Close transaction (closes the split-off portion)

// Build tip transaction, sign all three, submit as bundle:
const { tipLamports } = await client.getTipFloor()
// ... build tip TX ...

await client.submitBundle([
  tipTxBase58,
  result.splitTransaction,
  result.closeTransaction,
])
7. 追加抵押品(降低风险)
// Preview impact
const quote = await client.getAddCollateralQuote({
  positionAddress: position.address,
  userPublicKey: walletAddress,
  collateralAmount: '500000000', // 0.5 SOL
})
// Shows new LTV, new liquidation price

// Build and submit
const result = await client.buildAddCollateralTx({
  positionAddress: position.address,
  userPublicKey: walletAddress,
  collateralAmount: '500000000',
})
// Sign and submit...
8. 提高杠杆
// Two modes:
// - 'withdraw': borrow more and receive tokens in wallet
// - 'compound': borrow more and swap into base token (increases position size)

const quote = await client.getIncreaseBorrowQuote({
  positionAddress: position.address,
  userPublicKey: walletAddress,
  mode: 'compound',
  slippageBps: 50,
})

const result = await client.buildIncreaseBorrowTx({
  positionAddress: position.address,
  userPublicKey: walletAddress,
  additionalBorrowAmount: '100000000',
  mode: 'compound',
  slippageBps: 50,
})
// Sign and submit...
9. 借款(不押注方向)

以抵押品借入代币,而不建立杠杆头寸。持有 SOL,同时获取 USDC 流动性;反之亦然。

// 1. Find borrow offers
const offers = await client.getOffers({ search: 'USDC' })

// 2. Borrow USDC against SOL collateral
// leverage controls LTV: 2x = borrow equal to collateral (50% LTV)
const { tipLamports } = await client.getTipFloor()
const result = await client.buildBorrowTx({
  offerPublicKey: offers[0].address,
  userPublicKey: walletAddress,
  collateralAmount: '1000000000', // 1 SOL
  leverage: 2, // borrow ~1 SOL worth of USDC
  slippageBps: 50,
  astralaneTipLamports: tipLamports,
})

// Sign and submit same as any other position
// Repay later with buildRepayTx() or buildPartialRepayTx()

交易提交

所有交易都应通过 MEV 保护端点提交,以防止夹击攻击:

// Single transaction — use Astralane MEV protection
await client.submitTransaction(signedTxBase58, true)

// Multi-transaction bundle (e.g., partial sell) — use Jito
await client.submitBundle([tipTx, splitTx, closeTx])

// Get current tip floor (for MEV protection fee)
const { tipLamports } = await client.getTipFloor()
// Minimum 1,000,000 lamports (0.001 SOL)

API 端点参考

方法路径身份验证描述
GET/offers无列出/搜索可用市场
GET/tokens无列出所有代币
GET/positionsx-api-key按所有者查询头寸
POST/positions/openx-api-key构建开仓交易
POST/positions/closex-api-key构建平仓交易
POST/positions/quotex-api-key预览开仓交易
POST/positions/close-quotex-api-key预览平仓交易
POST/positions/splitx-api-key将头寸拆分为两个
POST/positions/mergex-api-key合并两个头寸
POST/positions/partial-sellx-api-key构建拆分并平仓的交易包
POST/positions/repayx-api-key偿还借款头寸
POST/positions/partial-repayx-api-key部分偿还借款
POST/positions/increase-borrowx-api-key提高杠杆
POST/positions/increase-borrow-quotex-api-key预览提高杠杆
POST/positions/add-collateralx-api-key为头寸追加抵押品
POST/positions/add-collateral-quotex-api-key预览追加抵押品
GET/positions/trade-historyx-api-key交易事件历史记录
GET/bundle/tip无当前 Jito 小费下限
POST/bundle/submit无提交单笔 TX(受 MEV 保护)
POST/bundle无提交 Jito 交易包

所有路径均以 /api/v1/ 为前缀。基础 URL:https://api.lavarage.xyz

最佳实践

  • 操作前务必先搜索 — 如果用户要求交易某种代币,请先在 Lavarage 上搜索。无需许可的池创建机制意味着许多其他平台没有的代币也可供交易。
  • 交易前务必先获取报价 — 执行前向用户展示预期输出、价格影响和清算价格。
  • 使用 MEV 保护 — 构建交易时务必包含 astralaneTipLamports,并通过 /bundle/submit 提交,同时设置 mevProtect: true。
  • 检查清算价格 — 如果用户的清算价格距离当前价格不到 15%,请向其发出警告。
  • 优先部分卖出,而非全部平仓 — 如果用户想获利了结,建议部分卖出,以锁定收益并保留部分敞口。
  • 处理滑点 — 默认的 50 bps(0.5%)对大多数代币来说都足够安全。对于流动性较低的代币,请使用 100-300 bps。

错误处理

API 返回的常见错误代码:

代码含义操作
INSUFFICIENT_BALANCE钱包中的代币不足检查余额,减少抵押品
SIMULATION_FAILED交易模拟失败使用更高的滑点重试,或检查报价的流动性
POSITION_NOT_FOUND头寸地址无效,或不属于该钱包验证地址和所有者
OFFER_NOT_FOUND报价/池不存在重新搜索可用报价
INVALID_LEVERAGE杠杆超出允许范围检查报价的 maxLeverage
SLIPPAGE_EXCEEDED价格波动超出容差范围增大 slippageBps 或重试

资源

技能结构

lavarage/
├── SKILL.md                  # This file
├── resources/
│   ├── api-reference.md      # Detailed endpoint documentation
│   ├── program-addresses.md  # On-chain program and token addresses
│   └── types-reference.md    # TypeScript types and enums
├── examples/
│   ├── discover-markets.ts   # Search tokens and find offers
│   ├── open-long.ts          # Open leveraged long position
│   ├── open-short.ts         # Open leveraged short position
│   ├── close-position.ts     # Close position with PnL
│   ├── portfolio.ts          # View positions and portfolio
│   └── borrow.ts             # Borrow tokens against collateral + repay
├── templates/
│   └── client.ts             # LavaApiClient — copy-paste TypeScript client
└── docs/
    └── troubleshooting.md    # Common errors and solutions

评论

支持 Markdown