Skip to content

Commit f859a6f

Browse files
authored
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
2 parents 721aa08 + 00a4fba commit f859a6f

File tree

3 files changed

+347
-457
lines changed

3 files changed

+347
-457
lines changed

apps/price_pusher/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/price-pusher",
3-
"version": "9.3.1",
3+
"version": "9.3.2",
44
"description": "Pyth Price Pusher",
55
"homepage": "https://pyth.network",
66
"main": "lib/index.js",
@@ -59,10 +59,11 @@
5959
"typescript": "catalog:"
6060
},
6161
"dependencies": {
62+
"@aptos-labs/ts-sdk": "^1.39.0",
6263
"@coral-xyz/anchor": "^0.30.0",
6364
"@injectivelabs/networks": "1.14.47",
64-
"@injectivelabs/utils": "^1.14.48",
6565
"@injectivelabs/sdk-ts": "1.14.50",
66+
"@injectivelabs/utils": "^1.14.48",
6667
"@mysten/sui": "^1.3.0",
6768
"@pythnetwork/hermes-client": "^1.3.1",
6869
"@pythnetwork/price-service-sdk": "workspace:^",

apps/price_pusher/src/aptos/balance-tracker.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AptosClient } from "aptos";
1+
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
22
import {
33
BaseBalanceTracker,
44
BaseBalanceTrackerConfig,
@@ -24,7 +24,7 @@ export interface AptosBalanceTrackerConfig extends BaseBalanceTrackerConfig {
2424
* Aptos-specific implementation of the balance tracker
2525
*/
2626
export class AptosBalanceTracker extends BaseBalanceTracker {
27-
private client: AptosClient;
27+
private client: Aptos;
2828
private aptosAddress: string;
2929
private decimals: number;
3030

@@ -33,8 +33,9 @@ export class AptosBalanceTracker extends BaseBalanceTracker {
3333
...config,
3434
logger: config.logger.child({ module: "AptosBalanceTracker" }),
3535
});
36-
37-
this.client = new AptosClient(config.endpoint);
36+
this.client = new Aptos(
37+
new AptosConfig({ network: Network.CUSTOM, fullnode: config.endpoint }),
38+
);
3839
this.aptosAddress = config.address;
3940
// APT has 8 decimal places by default
4041
this.decimals = config.decimals ?? 8;
@@ -47,16 +48,12 @@ export class AptosBalanceTracker extends BaseBalanceTracker {
4748
protected async updateBalance(): Promise<void> {
4849
try {
4950
// Get account resource to check the balance
50-
const accountResource = await this.client.getAccountResource(
51-
this.aptosAddress,
52-
"0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
53-
);
54-
55-
// Extract the balance value from the account resource
56-
const rawBalance = (accountResource.data as any).coin.value;
51+
const accountAPTAmount = await this.client.getAccountAPTAmount({
52+
accountAddress: this.aptosAddress,
53+
});
5754

58-
// Convert the balance to a bigint
59-
const balance = BigInt(rawBalance);
55+
// Convert the amount to a bigint
56+
const balance = BigInt(accountAPTAmount);
6057

6158
// Calculate the normalized balance for display
6259
const normalizedBalance = Number(balance) / Math.pow(10, this.decimals);

0 commit comments

Comments
 (0)