55/* eslint-disable @typescript-eslint/no-unsafe-member-access */
66/* eslint-disable @typescript-eslint/no-unsafe-assignment */
77import { HermesClient } from "@pythnetwork/hermes-client" ;
8- import { AptosAccount , AptosClient } from "aptos" ;
8+ import {
9+ Account ,
10+ Aptos ,
11+ AptosConfig ,
12+ Network ,
13+ } from "@aptos-labs/ts-sdk" ;
914import type { Logger } from "pino" ;
1015
1116import type { IPricePusher , PriceInfo , PriceItem } from "../interface.js" ;
@@ -26,23 +31,28 @@ export class AptosPriceListener extends ChainPriceListener {
2631 }
2732
2833 async getOnChainPriceInfo ( priceId : string ) : Promise < PriceInfo | undefined > {
29- const client = new AptosClient ( this . endpoint ) ;
30-
31- const res = await client . getAccountResource (
32- this . pythModule ,
33- `${ this . pythModule } ::state::LatestPriceInfo` ,
34+ const client = new Aptos (
35+ new AptosConfig ( { network : Network . CUSTOM , fullnode : this . endpoint } ) ,
3436 ) ;
3537
38+ const res = await client . getAccountResource < { info : { handle : string } } > ( {
39+ accountAddress : this . pythModule ,
40+ resourceType : `${ this . pythModule } ::state::LatestPriceInfo` ,
41+ } ) ;
42+
3643 try {
3744 // This depends upon the pyth contract storage on Aptos and should not be undefined.
3845 // If undefined, there has been some change and we would need to update accordingly.
39- const handle = ( res . data as any ) . info . handle ;
46+ const handle = res . info . handle ;
4047
41- const priceItemRes = await client . getTableItem ( handle , {
42- key_type : `${ this . pythModule } ::price_identifier::PriceIdentifier` ,
43- value_type : `${ this . pythModule } ::price_info::PriceInfo` ,
44- key : {
45- bytes : priceId ,
48+ const priceItemRes = await client . getTableItem < any > ( {
49+ handle,
50+ data : {
51+ key_type : `${ this . pythModule } ::price_identifier::PriceIdentifier` ,
52+ value_type : `${ this . pythModule } ::price_info::PriceInfo` ,
53+ key : {
54+ bytes : priceId ,
55+ } ,
4656 } ,
4757 } ) ;
4858
@@ -138,28 +148,31 @@ export class AptosPricePusher implements IPricePusher {
138148 return ;
139149 }
140150
141- const account = AptosAccount . fromDerivePath (
142- APTOS_ACCOUNT_HD_PATH ,
143- this . mnemonic ,
151+ const account = Account . fromDerivationPath ( {
152+ path : APTOS_ACCOUNT_HD_PATH ,
153+ mnemonic : this . mnemonic ,
154+ } ) ;
155+ const client = new Aptos (
156+ new AptosConfig ( { network : Network . CUSTOM , fullnode : this . endpoint } ) ,
144157 ) ;
145- const client = new AptosClient ( this . endpoint ) ;
146158
147159 const sequenceNumber = await this . tryGetNextSequenceNumber ( client , account ) ;
148- const rawTx = await client . generateTransaction (
149- account . address ( ) ,
150- {
160+ const transaction = await client . transaction . build . simple ( {
161+ sender : account . accountAddress ,
162+ data : {
151163 function : `${ this . pythContractAddress } ::pyth::update_price_feeds_with_funder` ,
152- type_arguments : [ ] ,
153- arguments : [ priceFeedUpdateData ] ,
164+ functionArguments : [ priceFeedUpdateData ] ,
154165 } ,
155- {
156- sequence_number : sequenceNumber . toFixed ( 0 ) ,
166+ options : {
167+ accountSequenceNumber : sequenceNumber ,
157168 } ,
158- ) ;
169+ } ) ;
159170
160171 try {
161- const signedTx = await client . signTransaction ( account , rawTx ) ;
162- const pendingTx = await client . submitTransaction ( signedTx ) ;
172+ const pendingTx = await client . signAndSubmitTransaction ( {
173+ signer : account ,
174+ transaction,
175+ } ) ;
163176
164177 this . logger . debug (
165178 { hash : pendingTx . hash } ,
@@ -185,13 +198,13 @@ export class AptosPricePusher implements IPricePusher {
185198
186199 // Wait for the transaction to be confirmed. If it fails, reset the sequence number.
187200 private async waitForTransactionConfirmation (
188- client : AptosClient ,
201+ client : Aptos ,
189202 txHash : string ,
190203 ) : Promise < void > {
191204 try {
192- await client . waitForTransaction ( txHash , {
193- checkSuccess : true ,
194- timeoutSecs : 10 ,
205+ await client . waitForTransaction ( {
206+ transactionHash : txHash ,
207+ options : { checkSuccess : true , timeoutSecs : 10 } ,
195208 } ) ;
196209
197210 this . logger . info ( { hash : txHash } , `Transaction confirmed.` ) ;
@@ -209,8 +222,8 @@ export class AptosPricePusher implements IPricePusher {
209222 // to predict the next sequence number if possible; if not, it fetches the number from
210223 // the blockchain itself (and caches it for later).
211224 private async tryGetNextSequenceNumber (
212- client : AptosClient ,
213- account : AptosAccount ,
225+ client : Aptos ,
226+ account : Account ,
214227 ) : Promise < number > {
215228 if ( this . lastSequenceNumber === undefined ) {
216229 // Fetch from the blockchain if we don't have the local cache.
@@ -222,7 +235,11 @@ export class AptosPricePusher implements IPricePusher {
222235 try {
223236 this . sequenceNumberLocked = true ;
224237 this . lastSequenceNumber = Number (
225- ( await client . getAccount ( account . address ( ) ) ) . sequence_number ,
238+ (
239+ await client . getAccountInfo ( {
240+ accountAddress : account . accountAddress ,
241+ } )
242+ ) . sequence_number ,
226243 ) ;
227244 this . logger . debug (
228245 `Fetched account sequence number: ${ this . lastSequenceNumber } ` ,
0 commit comments