ORCA事件的实时跟踪

在本文中,我们将探讨使用 Shyft Callback API 实时监听 Orca 上的事件的过程。

ORCA事件的实时跟踪
一键发币: SOL | BNB | ETH | BASE | Blast | ARB | OP | POLYGON | AVAX | FTM | OK

在今天的文章中,我们将探索跟踪 Orca 事件的最简单方法之一,包括使用 Shyft Callback API 创建池、交换代币、添加流动性和删除流动性。

Orca 是在 Solana 区块链上交换加密货币的最简单方法。 在这里,你可以以最低的交易费用和比以太坊上任何 DEX 更低的延迟来交换代币,同时知道你得到的是公平的价格。 此外,你可以向交易池提供流动性,以赚取一部分交易费用。

请在此处阅读 SHYFT API 文档

1、开始之前的准备工作

首先,我们需要一些东西。

注册你的 Shyft 帐户并获取你自己的 Shyft API 密钥。

x-api-key 是一个身份验证参数,可让你访问 Shyft API。 你可以从 Shyft 网站获取自己的 API 密钥。 只需在此处使用你的电子邮件 ID 注册即可免费获取。 如果已有 Shyft API 密钥,请跳过此步骤。

我们的教程将分为三个步骤:

  • 注册 Orca 程序地址的回调。 在此过程中,我们将利用 Shyft JS SDK 注册 Orca 程序地址的回调。
  • 建立一个 API 来监听来自 Shyft 的回调。 该 API 将负责接收来自 Shyft 的回调数据。
  • 回调数据分析:收到Shyft的回调数据后,我们将分析该数据的结构。 相信我,回调数据结构非常容易阅读和理解。

2、注册回调API

Shyft 允许我们为特定地址设置回调。 这意味着每当这些地址发生任何链上事件时,Shyft 都会及时通知我们相关事件数据。 在我们的场景中,我们为 Orca 程序地址设置了回调。 这使得 Shyft 能够在发生池创建、互换、增加流动性或消除流动性等事件时及时通知我们。

你可以选择通过手动调用 Shyft 的回调注册 API 或使用 Shyft JS SDK 并提供必要的数据来注册回调。 在我们的教程中,我们将选择 Shyft JS SDK 以增加便利。 有关回调 API 的更多详细信息,可以参考此链接

// setup Shyft client
import { Network, ShyftSdk } from "@shyft-to/js"

const ORCA_SHIRLPOOLS_ADDRESS = "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc";

const registerCallback = async () => {
  const shyft = new ShyftSdk({
    apiKey: process.env.NEXT_PUBLIC_SHYFT_API_KEY!,
    network: Network.Mainnet,
  });

  await shyft.callback.register({
    network: Network.Mainnet,
    addresses: [ORCA_SHIRLPOOLS_ADDRESS],
    // The URL of your API that listens for the callback event.
    // We will be set up in the next step.
    callbackUrl: `${window.location.href}api/callback`,
    // In our tutorial, we are only interested in four events, but you can provide as many events as you like.
    events: [TxnAction.CREATE_POOL, TxnAction.SWAP, TxnAction.ADD_LIQUIDITY, TxnAction.REMOVE_LIQUIDITY],
  });

  console.log("success");
};

3、设置API接收回调

该 API 是标准的 POST API。 我们在上一步中向 Shyft 提供了该 API 的 URL。 当事件发生时,Shyft 会调用该 API 并将数据发送给我们。 我们的责任包括检查和分析数据。 在我们的文章中,我们仅呈现数据,但你可以随意将其用于任何您想要的用途,例如在前端显示此数据或将其存储在数据库中以供以后使用。 要进一步了解回调数据的结构,可以参考此链接

import { CallbackDataType } from "@/types";
import { NextApiResponse } from "next";
import { NextRequest } from "next/server";
import { TxnAction } from "@shyft-to/js";

const ACTIONS = [
  TxnAction.CREATE_POOL,
  TxnAction.ADD_LIQUIDITY,
  TxnAction.REMOVE_LIQUIDITY,
  TxnAction.SWAP,
];

export async function POST(req: NextRequest, res: NextApiResponse) {
  const body = (await req.json()) as CallbackDataType;
  if (
    !body.type ||
    !body.actions ||
    body.status !== "Success" ||
    !ACTIONS.includes(body.type as TxnAction)
  )
    return res.status(400).json({ message: "Invalid callback data" });

  // You can store the callback data into database for later use.
  console.dir(body, { depth: null });

  return Response.json({ success: true });
}

4、回调数据分析

我们的后端服务器现已全面运行,每当发生重大链上事件(包括 Orca 上的代币交换、流动性增加或删除)时,都可以无缝接收来自 Shyft 的实时数据。 此数据流对于你的去中心化应用程序 (dApp) 具有巨大的价值,使你能够在前端编排动态、实时更新,从而确保你的用户保持知情和参与。

现在,让我们来看看我们收到的一些事件。

4.1 交换事件

{
  "timestamp": "2024-02-22T03:24:28.000Z",
  "fee": 0.000005,
  "fee_payer": "YubozzSnKomEnH3pkmYsdatUUwUTcm7s4mHJVmefEWj",
  "signers": [
    "YubozzSnKomEnH3pkmYsdatUUwUTcm7s4mHJVmefEWj"
  ],
  "signatures": [
    "39g1YwK9aHbDDc1ZMruKB5WvSQdEvfoWG8coBYLycVTs4hH7WfCRmCqXUu7ZUZsyDN4gfp3ZM1MKu8JmRzgeihTn"
  ],
  "protocol": {
    "address": "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc",
    "name": "ORCA_WHIRLPOOLS"
  },
  "type": "SWAP",
  "status": "Success",
  "actions": [
    {
      "info": {
        "swapper": "YubozzSnKomEnH3pkmYsdatUUwUTcm7s4mHJVmefEWj",
        "tokens_swapped": {
          "in": {
            "token_address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
            "name": "USD Coin",
            "symbol": "USDC",
            "image_uri": "https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v/logo.png",
            "amount": 100
          },
          "out": {
            "token_address": "So11111111111111111111111111111111111111112",
            "name": "Wrapped SOL",
            "symbol": "SOL",
            "image_uri": "https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/So11111111111111111111111111111111111111112/logo.png",
            "amount": 0.971308406
          }
        },
        "swaps": [
          {
            "liquidity_pool_address": "83v8iPyZihDEjDdY8RdZddyZNyUtXngz69Lgo9Kt5d6d",
            "name": "USD Coin-Wrapped SOL",
            "source": "whirlpool",
            "in": {
              "token_address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
              "name": "USD Coin",
              "symbol": "USDC",
              "image_uri": "https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v/logo.png",
              "amount": 100
            },
            "out": {
              "token_address": "So11111111111111111111111111111111111111112",
              "name": "Wrapped SOL",
              "symbol": "SOL",
              "image_uri": "https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/So11111111111111111111111111111111111111112/logo.png",
              "amount": 0.971308406
            }
          }
        ],
        "slippage_in_percent": null,
        "quoted_out_amount": null,
        "slippage_paid": null
      },
      "source_protocol": {
        "address": "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc",
        "name": "ORCA_WHIRLPOOLS"
      },
      "parent_protocol": "8i97DHS9KPnG311fSY9yin4cyk9ZzkBjLXobyEFvtfKY",
      "type": "SWAP"
    },
    {
      "info": {
        "amount": 100,
        "sender": "YubozzSnKomEnH3pkmYsdatUUwUTcm7s4mHJVmefEWj",
        "receiver_associated_account": "dwxR9YF7WwnJJu7bPC4UNcWFpcSsooH6fxbpoa3fTbJ",
        "receiver": "83v8iPyZihDEjDdY8RdZddyZNyUtXngz69Lgo9Kt5d6d",
        "token_address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
      },
      "source_protocol": {
        "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
        "name": "Token Program"
      },
      "type": "TOKEN_TRANSFER",
      "parent_protocol": "8i97DHS9KPnG311fSY9yin4cyk9ZzkBjLXobyEFvtfKY"
    },
    {
      "info": {
        "amount": 0.971308406,
        "sender": "83v8iPyZihDEjDdY8RdZddyZNyUtXngz69Lgo9Kt5d6d",
        "receiver_associated_account": "BqjtchQuxAYHQyQhc2Yfj4oujFMSDLVd2woL2HX6tU9H",
        "receiver": "YubozzSnKomEnH3pkmYsdatUUwUTcm7s4mHJVmefEWj",
        "token_address": "So11111111111111111111111111111111111111112"
      },
      "source_protocol": {
        "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
        "name": "Token Program"
      },
      "type": "TOKEN_TRANSFER",
      "parent_protocol": "8i97DHS9KPnG311fSY9yin4cyk9ZzkBjLXobyEFvtfKY"
    }
  ],
  "accounts": []
}

我们收到每笔链上交易的人类可读数据。

  • timestamp:时间戳,交易发生的日期和时间。
  • type:类型字段指示交易的操作,在本例中为“交换”。
  • Fee、fee_payer 和 Signers 字段是不言自明的:它们代表交易的 Gas 费、支付费用的钱包以及为交易签名的钱包。
  • protocol字段包含执行事务的程序的名称和地址。
  • status:状态,交易的结果。
  • actions 字段是提供详细信息的操作列表。 在这种情况下,可以观察交换器(即钱包)执行此交换。 此外,还可以查看换入和换出的代币的详细信息,包括代币地址、名称、符号、图像 URL 和数量。

4.2 添加流动性事件

{
  "timestamp": "2024-02-22T23:38:30.000Z",
  "fee": 0.000019,
  "fee_payer": "882DFRCi5akKFyYxT4PP2vZkoQEGvm2Nsind2nPDuGqu",
  "signers": ["882DFRCi5akKFyYxT4PP2vZkoQEGvm2Nsind2nPDuGqu"],
  "signatures": [
    "5XkQ4WUuWb4EWcfU73u7MuBdTRK1HdixSk5SHA5T9fqbTEvSrSvNgVX55a29y6phf6ahZ49i9DrD7epbZ1F4rRcX"
  ],
  "protocol": {
    "address": "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc",
    "name": "ORCA_WHIRLPOOLS"
  },
  "type": "ADD_LIQUIDITY",
  "status": "Success",
  "actions": [
    {
      "info": {
        "liquidity_provider_address": "882DFRCi5akKFyYxT4PP2vZkoQEGvm2Nsind2nPDuGqu",
        "liquidity_pool_address": "FpCMFDFGYotvufJ7HrFHsWEiiQCGbkLCtwHiDnh7o28Q",
        "nft_address": "",
        "liquidity_added": [
          {
            "token_address": "So11111111111111111111111111111111111111112",
            "amount": 60,
            "name": "Wrapped SOL",
            "symbol": "SOL",
            "image_uri": "https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/So11111111111111111111111111111111111111112/logo.png"
          },
          {
            "token_address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
            "amount": 6131.004543,
            "name": "USD Coin",
            "symbol": "USDC",
            "image_uri": "https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v/logo.png"
          }
        ]
      },
      "source_protocol": {
        "address": "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc",
        "name": "ORCA_WHIRLPOOLS"
      },
      "type": "ADD_LIQUIDITY",
      "parent_protocol": "F5mYQ3f3B6UmBv84bumcdFrRjejh9skG2cQGHNab2aZZ"
    },
    {
      "info": {
        "liquidity_provider_address": "882DFRCi5akKFyYxT4PP2vZkoQEGvm2Nsind2nPDuGqu",
        "liquidity_pool_address": "FpCMFDFGYotvufJ7HrFHsWEiiQCGbkLCtwHiDnh7o28Q",
        "nft_address": "",
        "liquidity_removed": [
          {
            "token_address": "So11111111111111111111111111111111111111112",
            "amount": 0.56272084,
            "name": "Wrapped SOL",
            "symbol": "SOL",
            "image_uri": "https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/So11111111111111111111111111111111111111112/logo.png"
          },
          {
            "token_address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
            "amount": 0,
            "name": "USD Coin",
            "symbol": "USDC",
            "image_uri": "https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v/logo.png"
          }
        ]
      },
      "source_protocol": {
        "address": "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc",
        "name": "ORCA_WHIRLPOOLS"
      },
      "type": "REMOVE_LIQUIDITY",
      "parent_protocol": "F5mYQ3f3B6UmBv84bumcdFrRjejh9skG2cQGHNab2aZZ"
    },
    {
      "info": {
        "liquidity_provider_address": "882DFRCi5akKFyYxT4PP2vZkoQEGvm2Nsind2nPDuGqu",
        "liquidity_pool_address": "FpCMFDFGYotvufJ7HrFHsWEiiQCGbkLCtwHiDnh7o28Q",
        "nft_address": "",
        "liquidity_removed": []
      },
      "source_protocol": {
        "address": "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc",
        "name": "ORCA_WHIRLPOOLS"
      },
      "type": "REMOVE_LIQUIDITY",
      "parent_protocol": "F5mYQ3f3B6UmBv84bumcdFrRjejh9skG2cQGHNab2aZZ"
    },
    {
      "info": {
        "liquidity_provider_address": "882DFRCi5akKFyYxT4PP2vZkoQEGvm2Nsind2nPDuGqu",
        "liquidity_pool_address": "FpCMFDFGYotvufJ7HrFHsWEiiQCGbkLCtwHiDnh7o28Q",
        "nft_address": "",
        "liquidity_removed": []
      },
      "source_protocol": {
        "address": "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc",
        "name": "ORCA_WHIRLPOOLS"
      },
      "type": "REMOVE_LIQUIDITY",
      "parent_protocol": "F5mYQ3f3B6UmBv84bumcdFrRjejh9skG2cQGHNab2aZZ"
    },
    {
      "info": {
        "amount": 0.56272084,
        "sender": "882DFRCi5akKFyYxT4PP2vZkoQEGvm2Nsind2nPDuGqu",
        "receiver_associated_account": "6mQ8xEaHdTikyMvvMxUctYch6dUjnKgfoeib2msyMMi1",
        "receiver": "FpCMFDFGYotvufJ7HrFHsWEiiQCGbkLCtwHiDnh7o28Q",
        "token_address": "So11111111111111111111111111111111111111112"
      },
      "source_protocol": {
        "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
        "name": "Token Program"
      },
      "type": "TOKEN_TRANSFER",
      "parent_protocol": "F5mYQ3f3B6UmBv84bumcdFrRjejh9skG2cQGHNab2aZZ"
    },
    {
      "info": {
        "amount": 0,
        "sender": "882DFRCi5akKFyYxT4PP2vZkoQEGvm2Nsind2nPDuGqu",
        "receiver_associated_account": "AQ36QRk3HAe6PHqBCtKTQnYKpt2kAagq9YoeTqUPMGHx",
        "receiver": "FpCMFDFGYotvufJ7HrFHsWEiiQCGbkLCtwHiDnh7o28Q",
        "token_address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
      },
      "source_protocol": {
        "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
        "name": "Token Program"
      },
      "type": "TOKEN_TRANSFER",
      "parent_protocol": "F5mYQ3f3B6UmBv84bumcdFrRjejh9skG2cQGHNab2aZZ"
    },
    {
      "info": {
        "amount": 0.025155793,
        "sender": "FpCMFDFGYotvufJ7HrFHsWEiiQCGbkLCtwHiDnh7o28Q",
        "receiver_associated_account": "2rw3gMo4AB5Y5YggfXyh3ZCwc7LerdR1nFD3x6aedPSt",
        "receiver": "882DFRCi5akKFyYxT4PP2vZkoQEGvm2Nsind2nPDuGqu",
        "token_address": "So11111111111111111111111111111111111111112"
      },
      "source_protocol": {
        "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
        "name": "Token Program"
      },
      "type": "TOKEN_TRANSFER",
      "parent_protocol": "F5mYQ3f3B6UmBv84bumcdFrRjejh9skG2cQGHNab2aZZ"
    },
    {
      "info": {
        "amount": 16.959437,
        "sender": "FpCMFDFGYotvufJ7HrFHsWEiiQCGbkLCtwHiDnh7o28Q",
        "receiver_associated_account": "3stBgcqaa1UWK23ybiZjTS1h9VuCH18dPkhxyiWfDaLd",
        "receiver": "882DFRCi5akKFyYxT4PP2vZkoQEGvm2Nsind2nPDuGqu",
        "token_address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
      },
      "source_protocol": {
        "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
        "name": "Token Program"
      },
      "type": "TOKEN_TRANSFER",
      "parent_protocol": "F5mYQ3f3B6UmBv84bumcdFrRjejh9skG2cQGHNab2aZZ"
    },
    {
      "info": {
        "amount": 0.740776027,
        "sender": "882DFRCi5akKFyYxT4PP2vZkoQEGvm2Nsind2nPDuGqu",
        "receiver_associated_account": "6mQ8xEaHdTikyMvvMxUctYch6dUjnKgfoeib2msyMMi1",
        "receiver": "FpCMFDFGYotvufJ7HrFHsWEiiQCGbkLCtwHiDnh7o28Q",
        "token_address": "So11111111111111111111111111111111111111112"
      },
      "source_protocol": {
        "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
        "name": "Token Program"
      },
      "type": "TOKEN_TRANSFER",
      "parent_protocol": "F5mYQ3f3B6UmBv84bumcdFrRjejh9skG2cQGHNab2aZZ"
    },
    {
      "info": {
        "amount": 0,
        "sender": "882DFRCi5akKFyYxT4PP2vZkoQEGvm2Nsind2nPDuGqu",
        "receiver_associated_account": "AQ36QRk3HAe6PHqBCtKTQnYKpt2kAagq9YoeTqUPMGHx",
        "receiver": "FpCMFDFGYotvufJ7HrFHsWEiiQCGbkLCtwHiDnh7o28Q",
        "token_address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
      },
      "source_protocol": {
        "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
        "name": "Token Program"
      },
      "type": "TOKEN_TRANSFER",
      "parent_protocol": "F5mYQ3f3B6UmBv84bumcdFrRjejh9skG2cQGHNab2aZZ"
    },
    {
      "info": {
        "amount": 0,
        "sender": "FpCMFDFGYotvufJ7HrFHsWEiiQCGbkLCtwHiDnh7o28Q",
        "receiver_associated_account": "2rw3gMo4AB5Y5YggfXyh3ZCwc7LerdR1nFD3x6aedPSt",
        "receiver": "882DFRCi5akKFyYxT4PP2vZkoQEGvm2Nsind2nPDuGqu",
        "token_address": "So11111111111111111111111111111111111111112"
      },
      "source_protocol": {
        "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
        "name": "Token Program"
      },
      "type": "TOKEN_TRANSFER",
      "parent_protocol": "F5mYQ3f3B6UmBv84bumcdFrRjejh9skG2cQGHNab2aZZ"
    },
    {
      "info": {
        "amount": 55.421012,
        "sender": "FpCMFDFGYotvufJ7HrFHsWEiiQCGbkLCtwHiDnh7o28Q",
        "receiver_associated_account": "3stBgcqaa1UWK23ybiZjTS1h9VuCH18dPkhxyiWfDaLd",
        "receiver": "882DFRCi5akKFyYxT4PP2vZkoQEGvm2Nsind2nPDuGqu",
        "token_address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
      },
      "source_protocol": {
        "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
        "name": "Token Program"
      },
      "type": "TOKEN_TRANSFER",
      "parent_protocol": "F5mYQ3f3B6UmBv84bumcdFrRjejh9skG2cQGHNab2aZZ"
    },
    {
      "info": {
        "amount": 0.737050271,
        "sender": "882DFRCi5akKFyYxT4PP2vZkoQEGvm2Nsind2nPDuGqu",
        "receiver_associated_account": "6mQ8xEaHdTikyMvvMxUctYch6dUjnKgfoeib2msyMMi1",
        "receiver": "FpCMFDFGYotvufJ7HrFHsWEiiQCGbkLCtwHiDnh7o28Q",
        "token_address": "So11111111111111111111111111111111111111112"
      },
      "source_protocol": {
        "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
        "name": "Token Program"
      },
      "type": "TOKEN_TRANSFER",
      "parent_protocol": "F5mYQ3f3B6UmBv84bumcdFrRjejh9skG2cQGHNab2aZZ"
    },
    {
      "info": {
        "amount": 0,
        "sender": "882DFRCi5akKFyYxT4PP2vZkoQEGvm2Nsind2nPDuGqu",
        "receiver_associated_account": "AQ36QRk3HAe6PHqBCtKTQnYKpt2kAagq9YoeTqUPMGHx",
        "receiver": "FpCMFDFGYotvufJ7HrFHsWEiiQCGbkLCtwHiDnh7o28Q",
        "token_address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
      },
      "source_protocol": {
        "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
        "name": "Token Program"
      },
      "type": "TOKEN_TRANSFER",
      "parent_protocol": "F5mYQ3f3B6UmBv84bumcdFrRjejh9skG2cQGHNab2aZZ"
    },
    {
      "info": {
        "amount": 0,
        "sender": "FpCMFDFGYotvufJ7HrFHsWEiiQCGbkLCtwHiDnh7o28Q",
        "receiver_associated_account": "2rw3gMo4AB5Y5YggfXyh3ZCwc7LerdR1nFD3x6aedPSt",
        "receiver": "882DFRCi5akKFyYxT4PP2vZkoQEGvm2Nsind2nPDuGqu",
        "token_address": "So11111111111111111111111111111111111111112"
      },
      "source_protocol": {
        "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
        "name": "Token Program"
      },
      "type": "TOKEN_TRANSFER",
      "parent_protocol": "F5mYQ3f3B6UmBv84bumcdFrRjejh9skG2cQGHNab2aZZ"
    },
    {
      "info": {
        "amount": 75.010236,
        "sender": "FpCMFDFGYotvufJ7HrFHsWEiiQCGbkLCtwHiDnh7o28Q",
        "receiver_associated_account": "3stBgcqaa1UWK23ybiZjTS1h9VuCH18dPkhxyiWfDaLd",
        "receiver": "882DFRCi5akKFyYxT4PP2vZkoQEGvm2Nsind2nPDuGqu",
        "token_address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
      },
      "source_protocol": {
        "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
        "name": "Token Program"
      },
      "type": "TOKEN_TRANSFER",
      "parent_protocol": "F5mYQ3f3B6UmBv84bumcdFrRjejh9skG2cQGHNab2aZZ"
    }
  ],
  "events": []
}

上面我们已经解释了一些字段,所以我们只需要明确 actions 字段即可。 在这种情况下,操作字段包括有关流动性提供者地址和池地址的信息。 此外,我们可以观察添加到池中的代币对。

4.3 移除流动性事件

{
  "timestamp": "2024-02-22T23:50:01.000Z",
  "fee": 0.00001,
  "fee_payer": "9xuLKEdMWKSQsuysCMZRXuuT85ZDJemUo3gUhzgqhgEN",
  "signers": ["9xuLKEdMWKSQsuysCMZRXuuT85ZDJemUo3gUhzgqhgEN"],
  "signatures": [
    "5oh38LUYYZRR1YJinoEDQWWv2NFiYZithHUQdnyYoURKn3ikGiMPEfdEVYcBNt3BCqB49KicNeipLdceDBU3HC3G"
  ],
  "protocol": {
    "address": "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc",
    "name": "ORCA_WHIRLPOOLS"
  },
  "type": "REMOVE_LIQUIDITY",
  "status": "Success",
  "actions": [
    {
      "info": {
        "liquidity_provider_address": "9xuLKEdMWKSQsuysCMZRXuuT85ZDJemUo3gUhzgqhgEN",
        "liquidity_pool_address": "8JwS5zosnLFT84S1NebSp1HS6aeaxviXYS7jBh9PQ8vp",
        "nft_address": "Ke32Y8stFGMTkFoHd8wZarTkmcUGtu8YKzBDJUNTJRB",
        "liquidity_removed": [
          {
            "token_address": "hntyVP6YFm1Hg25TN9WGLqM12b8TQmcknKrdu1oxWux",
            "amount": 137.28790981,
            "name": "Helium",
            "symbol": "HNT",
            "image_uri": "https://assets.coingecko.com/coins/images/4284/large/Helium_HNT.png?1696504894"
          },
          {
            "token_address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
            "amount": 0,
            "name": "USD Coin",
            "symbol": "USDC",
            "image_uri": "https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v/logo.png"
          }
        ]
      },
      "source_protocol": {
        "address": "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc",
        "name": "ORCA_WHIRLPOOLS"
      },
      "type": "REMOVE_LIQUIDITY"
    },
    {
      "info": {
        "wallet": "9xuLKEdMWKSQsuysCMZRXuuT85ZDJemUo3gUhzgqhgEN",
        "amount": 1,
        "nft_address": "Ke32Y8stFGMTkFoHd8wZarTkmcUGtu8YKzBDJUNTJRB"
      },
      "source_protocol": {
        "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
        "name": "Token Program"
      },
      "type": "NFT_BURN",
      "parent_protocol": "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc"
    },
    {
      "info": {
        "amount": 139.34722846,
        "sender": "8JwS5zosnLFT84S1NebSp1HS6aeaxviXYS7jBh9PQ8vp",
        "receiver_associated_account": "E5ambN8UUydsBPrYTZpYk2hbuAV8zUA27E48bCsYapSk",
        "receiver": "9xuLKEdMWKSQsuysCMZRXuuT85ZDJemUo3gUhzgqhgEN",
        "token_address": "hntyVP6YFm1Hg25TN9WGLqM12b8TQmcknKrdu1oxWux"
      },
      "source_protocol": {
        "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
        "name": "Token Program"
      },
      "type": "TOKEN_TRANSFER",
      "parent_protocol": "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc"
    },
    {
      "info": {
        "amount": 0,
        "sender": "8JwS5zosnLFT84S1NebSp1HS6aeaxviXYS7jBh9PQ8vp",
        "receiver_associated_account": "D9VUp28BjsoYbMry7t8aZmgkhDNjgAWw8FhUwNakgsPS",
        "receiver": "9xuLKEdMWKSQsuysCMZRXuuT85ZDJemUo3gUhzgqhgEN",
        "token_address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
      },
      "source_protocol": {
        "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
        "name": "Token Program"
      },
      "type": "TOKEN_TRANSFER",
      "parent_protocol": "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc"
    }
  ]
}

与添加流动性事件类似,此 JSON 包含操作字段,其中包括有关流动性提供者地址和池地址的信息。 此外,我们可以观察从池中删除的代币对。

5、结束语

因此,我们刚刚指导你如何使用 Shyft Callback API 实时监听链上 Orca 事件。 通过监听链上事件,可以轻松地为你的 dApp 提供实时体验。


原文链接:How to track real-time Orca events

DefiPlot翻译整理,转载请标明出处

通过 NowPayments 打赏