Skip to content
This repository was archived by the owner on Apr 3, 2023. It is now read-only.

Commit ba9cab5

Browse files
committed
Expose separate functions for fetching and serializing
1 parent 7a82f13 commit ba9cab5

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

pyth-aptos-js/src/AptosPriceServiceConnection.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@ export class AptosPriceServiceConnection extends PriceServiceConnection {
99
* @param priceIds Array of hex-encoded price ids.
1010
* @returns Array of price update data, serialized such that it can be passed to the Pyth Aptos contract.
1111
*/
12-
async getPriceFeedsUpdateData(priceIds: HexString[]): Promise<Uint8Array> {
12+
async getPriceFeedsUpdateData(priceIds: HexString[]): Promise<number[][]> {
1313
// Fetch the latest price feed update VAAs from the price service
1414
const latestVaas = await this.getLatestVaas(priceIds);
15+
return latestVaas.map((vaa) => Array.from(Buffer.from(vaa, "base64")));
16+
}
1517

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 {
1724
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)));
2227
return serializer.getBytes();
2328
}
2429
}

0 commit comments

Comments
 (0)