1- import { AptosClient } from "aptos" ;
1+ import { Aptos , AptosConfig , Network } from "@ aptos-labs/ts-sdk " ;
22import {
33 BaseBalanceTracker ,
44 BaseBalanceTrackerConfig ,
@@ -24,7 +24,7 @@ export interface AptosBalanceTrackerConfig extends BaseBalanceTrackerConfig {
2424 * Aptos-specific implementation of the balance tracker
2525 */
2626export 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