1
- import { AptosClient } from "aptos" ;
1
+ import { Aptos , AptosConfig , Network } from "@ aptos-labs/ts-sdk " ;
2
2
import {
3
3
BaseBalanceTracker ,
4
4
BaseBalanceTrackerConfig ,
@@ -24,7 +24,7 @@ export interface AptosBalanceTrackerConfig extends BaseBalanceTrackerConfig {
24
24
* Aptos-specific implementation of the balance tracker
25
25
*/
26
26
export class AptosBalanceTracker extends BaseBalanceTracker {
27
- private client : AptosClient ;
27
+ private client : Aptos ;
28
28
private aptosAddress : string ;
29
29
private decimals : number ;
30
30
@@ -33,8 +33,9 @@ export class AptosBalanceTracker extends BaseBalanceTracker {
33
33
...config ,
34
34
logger : config . logger . child ( { module : "AptosBalanceTracker" } ) ,
35
35
} ) ;
36
-
37
- this . client = new AptosClient ( config . endpoint ) ;
36
+ this . client = new Aptos (
37
+ new AptosConfig ( { network : Network . CUSTOM , fullnode : config . endpoint } ) ,
38
+ ) ;
38
39
this . aptosAddress = config . address ;
39
40
// APT has 8 decimal places by default
40
41
this . decimals = config . decimals ?? 8 ;
@@ -47,16 +48,12 @@ export class AptosBalanceTracker extends BaseBalanceTracker {
47
48
protected async updateBalance ( ) : Promise < void > {
48
49
try {
49
50
// 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
+ } ) ;
57
54
58
- // Convert the balance to a bigint
59
- const balance = BigInt ( rawBalance ) ;
55
+ // Convert the amount to a bigint
56
+ const balance = BigInt ( accountAPTAmount ) ;
60
57
61
58
// Calculate the normalized balance for display
62
59
const normalizedBalance = Number ( balance ) / Math . pow ( 10 , this . decimals ) ;
0 commit comments