瀏覽代碼

Merge pull request #2656 from pyth-network/aptos-price-pusher-2

feat(apps/price_pusher): update Aptos balance tracker to use new SDK and improve balance retrieval
Daniel Chew 6 月之前
父節點
當前提交
f859a6fa44
共有 3 個文件被更改,包括 278 次插入248 次删除
  1. 3 2
      apps/price_pusher/package.json
  2. 10 13
      apps/price_pusher/src/aptos/balance-tracker.ts
  3. 265 233
      pnpm-lock.yaml

+ 3 - 2
apps/price_pusher/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@pythnetwork/price-pusher",
-  "version": "9.3.1",
+  "version": "9.3.2",
   "description": "Pyth Price Pusher",
   "homepage": "https://pyth.network",
   "main": "lib/index.js",
@@ -59,10 +59,11 @@
     "typescript": "catalog:"
   },
   "dependencies": {
+    "@aptos-labs/ts-sdk": "^1.39.0",
     "@coral-xyz/anchor": "^0.30.0",
     "@injectivelabs/networks": "1.14.47",
-    "@injectivelabs/utils": "^1.14.48",
     "@injectivelabs/sdk-ts": "1.14.50",
+    "@injectivelabs/utils": "^1.14.48",
     "@mysten/sui": "^1.3.0",
     "@pythnetwork/hermes-client": "^1.3.1",
     "@pythnetwork/price-service-sdk": "workspace:^",

+ 10 - 13
apps/price_pusher/src/aptos/balance-tracker.ts

@@ -1,4 +1,4 @@
-import { AptosClient } from "aptos";
+import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
 import {
   BaseBalanceTracker,
   BaseBalanceTrackerConfig,
@@ -24,7 +24,7 @@ export interface AptosBalanceTrackerConfig extends BaseBalanceTrackerConfig {
  * Aptos-specific implementation of the balance tracker
  */
 export class AptosBalanceTracker extends BaseBalanceTracker {
-  private client: AptosClient;
+  private client: Aptos;
   private aptosAddress: string;
   private decimals: number;
 
@@ -33,8 +33,9 @@ export class AptosBalanceTracker extends BaseBalanceTracker {
       ...config,
       logger: config.logger.child({ module: "AptosBalanceTracker" }),
     });
-
-    this.client = new AptosClient(config.endpoint);
+    this.client = new Aptos(
+      new AptosConfig({ network: Network.CUSTOM, fullnode: config.endpoint }),
+    );
     this.aptosAddress = config.address;
     // APT has 8 decimal places by default
     this.decimals = config.decimals ?? 8;
@@ -47,16 +48,12 @@ export class AptosBalanceTracker extends BaseBalanceTracker {
   protected async updateBalance(): Promise<void> {
     try {
       // Get account resource to check the balance
-      const accountResource = await this.client.getAccountResource(
-        this.aptosAddress,
-        "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
-      );
-
-      // Extract the balance value from the account resource
-      const rawBalance = (accountResource.data as any).coin.value;
+      const accountAPTAmount = await this.client.getAccountAPTAmount({
+        accountAddress: this.aptosAddress,
+      });
 
-      // Convert the balance to a bigint
-      const balance = BigInt(rawBalance);
+      // Convert the amount to a bigint
+      const balance = BigInt(accountAPTAmount);
 
       // Calculate the normalized balance for display
       const normalizedBalance = Number(balance) / Math.pow(10, this.decimals);

文件差異過大導致無法顯示
+ 265 - 233
pnpm-lock.yaml


部分文件因文件數量過多而無法顯示