跳转到内容
本页面的翻译由 LLM 生成。如果你发现翻译有误,请在 GitHub 上提交 issue 告诉我们。

LP API 参考

查询和订阅金库、存款、提现及收益等流动性池数据。

列出全部流动性金库及指标。

签名:

vaults(
where: LpVaultsFilter
limit: Int
offset: Int
order_by: LpVaultsOrder
order_desc: Boolean
): [LpVault!]!

参数:

  • where:可选筛选。
    • address:金库地址。
  • limit:最大数量。
  • offset:跳过数量。
  • order_by:address。
  • order_desc:降序。

返回: LpVault 数组。

示例:获取全部金库

query GetAllVaults {
lp {
vaults {
address
collateralDenom
collateralToken {
symbol
name
logoUrl
decimals
}
tvl
sharePrice
apy
availableAssets
currentEpoch
epochStart
sharesDenom
sharesERC20
collateralERC20
revenueInfo {
RevenueCumulative
NetProfit
TraderLosses
ClosedPnl
CurrentEpochPositiveOpenPnl
Liabilities
Rewards
}
}
}
}

示例:获取特定金库

query GetVault($address: String!) {
lp {
vaults(where: { address: $address }) {
address
tvl
sharePrice
apy
availableAssets
}
}
}

主要字段说明:

  • tvl:金库总锁仓价值。
  • sharePrice:一份金库份额的当前价值。
  • apy:年化收益率。
  • availableAssets:当前未用于未平仓仓位的资产。
  • currentEpoch:当前周期编号。
  • epochStart:当前周期开始的 Unix 时间。

应用场景:

  • 显示金库和指标。
  • 比较金库表现。
  • 显示可用流动性。
  • 计算潜在收益。

获取用户金库存款。

签名:

deposits(
where: LpDepositsFilter
limit: Int
offset: Int
order_by: LpDepositsOrder
order_desc: Boolean
): [LpDeposit!]!

参数:

  • where:可选筛选。
    • depositor:存款人地址。
    • vault:金库地址。
  • limit:最大数量。
  • offset:跳过数量。
  • order_by:depositor 或 vault。
  • order_desc:降序。

返回: LpDeposit 数组。

示例:获取用户存款

query GetUserDeposits($user: String!) {
lp {
deposits(where: { depositor: $user }) {
depositor
shares
vault {
address
collateralToken { symbol }
sharePrice
tvl
apy
}
}
}
}

示例:计算存款价值

query CalculateDepositValue($user: String!) {
lp {
deposits(where: { depositor: $user }) {
shares
vault {
sharePrice
collateralToken {
symbol
decimals
}
}
}
}
}

计算价值:

const value = (shares * sharePrice) / (10 ** decimals)

应用场景:

  • 显示用户 LP 头寸。
  • 计算总存款价值。
  • 追踪份额所有权。
  • 管理投资组合。

获取历史充值和提现事件。

签名:

depositHistory(
where: LpDepositHistoryFilter
limit: Int
offset: Int
order_by: LpDepositHistoryOrder
order_desc: Boolean
): [LpDepositHistoryItem!]!

参数:

  • where:可选筛选。
    • depositor:存款人地址。
    • vault:金库地址。
  • limit:最大数量。
  • offset:跳过数量。
  • order_by:depositor、sequence 或 vault。
  • order_desc:降序。

返回: LpDepositHistoryItem 数组。

示例:获取存款历史

query GetDepositHistory($user: String!) {
lp {
depositHistory(
where: { depositor: $user }
order_by: sequence
order_desc: true
limit: 50
) {
id
depositor
amount
shares
isWithdraw
vault {
address
collateralToken { symbol }
}
block {
block
block_ts
}
}
}
}

示例:筛选金库历史

query GetVaultHistory($vaultAddress: String!) {
lp {
depositHistory(
where: { vault: $vaultAddress }
order_by: sequence
order_desc: true
limit: 100
) {
depositor
amount
shares
isWithdraw
block { block_ts }
}
}
}

主要字段:

  • isWithdraw:提现为 true,存款为 false。
  • amount:存入或提取的抵押资产数量。
  • shares:存款铸造或提现销毁的份额。

应用场景:

  • 活动时间线。
  • 追踪存取款。
  • 审计金库操作。
  • 计算历史收益。

获取待处理提现申请。

签名:

withdrawRequests(
where: LpWithdrawRequestsFilter
limit: Int
offset: Int
order_by: LpWithdrawRequestsOrder
order_desc: Boolean
): [LpWithdrawRequest!]!

参数:

  • where:可选筛选。
    • depositor:存款人。
    • vault:金库。
  • limit:最大数量。
  • offset:跳过数量。
  • order_by:depositor、unlock_epoch 或 vault。
  • order_desc:降序。

返回: LpWithdrawRequest 数组。

示例:获取用户提现

query GetWithdrawRequests($user: String!) {
lp {
withdrawRequests(where: { depositor: $user }) {
depositor
shares
status
unlockEpoch
autoRedeem
vault {
address
collateralToken { symbol }
currentEpoch
sharePrice
}
}
}
}

示例:检查提现状态

query CheckWithdrawalReady($user: String!) {
lp {
withdrawRequests(where: { depositor: $user }) {
shares
unlockEpoch
autoRedeem
vault {
currentEpoch
sharePrice
}
}
}
}

检查是否可提现:

const isReady = vault.currentEpoch >= unlockEpoch
const estimatedValue = (shares * vault.sharePrice) / (10 ** decimals)

主要字段:

  • status:申请状态。
  • unlockEpoch:可提现的周期。
  • autoRedeem:true 时解锁后自动赎回。

应用场景:

  • 显示待处理提现。
  • 计算提现时间。
  • 显示预估金额。
  • 可提现时通知。

获取以天计的周期长度。

签名:

epochDurationDays: Int!

示例:

query GetEpochDuration {
lp {
epochDurationDays
epochDurationHours
}
}

获取以小时计的周期长度。

签名:

epochDurationHours: Int!

订阅 LP 数据实时更新。

订阅全部金库更新。

签名:

subscription {
lpVaults: [LpVault!]!
}

示例:

subscription WatchVaults {
lpVaults {
address
tvl
sharePrice
apy
availableAssets
currentEpoch
}
}

应用场景:

  • 实时追踪 TVL。
  • 更新 APY。
  • 监控可用流动性。
  • 追踪周期变更。

订阅用户存款更新。

签名:

subscription {
lpDeposits(where: SubLpDepositsFilter!): [LpDeposit!]!
}

示例:

subscription WatchUserDeposits($user: String!) {
lpDeposits(where: { depositor: $user }) {
depositor
shares
vault {
address
sharePrice
}
}
}

应用场景:

  • 实时更新投资组合。
  • 追踪份额余额变化。
  • 监控头寸价值。

订阅存取款事件。

签名:

subscription {
lpDepositHistory(where: SubLpDepositHistoryFilter!): [LpDepositHistoryItem!]!
}

示例:

subscription WatchDepositEvents($user: String!, $vault: String!) {
lpDepositHistory(where: { depositor: $user, vault: $vault }) {
id
amount
shares
isWithdraw
block { block_ts }
}
}

应用场景:

  • 实时活动列表。
  • 即时交易通知。
  • 实时历史更新。

订阅提现申请更新。

签名:

subscription {
lpWithdrawRequests(where: SubLpWithdrawRequestsFilter!): [LpWithdrawRequest!]!
}

示例:

subscription WatchWithdrawals($user: String!, $vault: String!) {
lpWithdrawRequests(where: { depositor: $user, vault: $vault }) {
shares
status
unlockEpoch
vault {
currentEpoch
}
}
}

应用场景:

  • 可提现时通知。
  • 追踪状态。
  • 解锁时更新界面。

type LpVault {
address: String!
collateralDenom: String!
collateralToken: Token!
collateralERC20: String!
sharesDenom: String!
sharesERC20: String!
tvl: Int!
sharePrice: Float!
apy: Float
availableAssets: Int!
currentEpoch: Int!
epochStart: Int!
revenueInfo: RevenueInfo!
}
type LpDeposit {
depositor: String!
shares: Int!
vault: LpVault!
}
type LpDepositHistoryItem {
id: Int!
depositor: String!
amount: Int!
shares: Int!
isWithdraw: Boolean!
vault: LpVault!
block: Block!
}
type LpWithdrawRequest {
depositor: String!
shares: Int!
status: String!
unlockEpoch: Int!
autoRedeem: Boolean!
vault: LpVault!
}

追踪金库收益和表现。

type RevenueInfo {
RevenueCumulative: Int! # Total revenue earned
NetProfit: Int! # Current net profit
TraderLosses: Int! # Profits from trader losses
ClosedPnl: Int! # Realized PnL from closed positions
CurrentEpochPositiveOpenPnl: Int! # Current epoch unrealized gains
Liabilities: Int! # Current liabilities (trader profits)
Rewards: Int! # Rewards received
}

// Calculate current value of deposit
const depositValue = (shares * sharePrice) / (10 ** decimals)
// For pending withdrawal
const estimatedValue = (shares * currentSharePrice) / (10 ** decimals)
// Calculate epochs remaining
const epochsRemaining = unlockEpoch - currentEpoch
// Calculate time remaining (assuming epoch duration)
const hoursRemaining = epochsRemaining * epochDurationHours

APY 根据历史收益计算。

// Simplified APY calculation
const apy = (revenueInfo.NetProfit / tvl) * (365 / epochDurationDays)