@@ -7,18 +7,23 @@ export class AptosPriceServiceConnection extends PriceServiceConnection {
7
7
* This will throw an axios error if there is a network problem or the price service returns a non-ok response (e.g: Invalid price ids)
8
8
*
9
9
* @param priceIds Array of hex-encoded price ids.
10
- * @returns Array of price update data, serialized such that it can be passed to the Pyth Aptos contract .
10
+ * @returns Array of price update data.
11
11
*/
12
- async getPriceFeedsUpdateData ( priceIds : HexString [ ] ) : Promise < Uint8Array > {
12
+ async getPriceFeedsUpdateData ( priceIds : HexString [ ] ) : Promise < number [ ] [ ] > {
13
13
// Fetch the latest price feed update VAAs from the price service
14
14
const latestVaas = await this . getLatestVaas ( priceIds ) ;
15
+ return latestVaas . map ( ( vaa ) => Array . from ( Buffer . from ( vaa , "base64" ) ) ) ;
16
+ }
15
17
16
- // Serialize the VAAs using BCS
18
+ /**
19
+ * Serializes the given updateData using BCS. Browser wallets typically automatically
20
+ * serialize the data, but this function can be used to manually serialize the update data
21
+ * if necessary.
22
+ */
23
+ static serializeUpdateData ( updateData : number [ ] [ ] ) : Uint8Array {
17
24
const serializer = new BCS . Serializer ( ) ;
18
- serializer . serializeU32AsUleb128 ( latestVaas . length ) ;
19
- latestVaas . forEach ( ( vaa ) =>
20
- serializer . serializeBytes ( Buffer . from ( vaa , "base64" ) )
21
- ) ;
25
+ serializer . serializeU32AsUleb128 ( updateData . length ) ;
26
+ updateData . forEach ( ( vaa ) => serializer . serializeBytes ( Buffer . from ( vaa ) ) ) ;
22
27
return serializer . getBytes ( ) ;
23
28
}
24
29
}
0 commit comments