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

Commit 3c2b6fb

Browse files
authored
Merge pull request #47 from pyth-network/aptos-wallet-serialization
Expose separate functions for fetching and serialization
2 parents 2938735 + 0f8267d commit 3c2b6fb

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

pyth-aptos-js/src/AptosPriceServiceConnection.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,23 @@ export class AptosPriceServiceConnection extends PriceServiceConnection {
77
* 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)
88
*
99
* @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.
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
}

pyth-aptos-js/src/examples/AptosRelay.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async function run() {
5454
argv.pythContract + "::pyth",
5555
"update_price_feeds_with_funder",
5656
[],
57-
[priceFeedUpdateData]
57+
[AptosPriceServiceConnection.serializeUpdateData(priceFeedUpdateData)]
5858
)
5959
)
6060
);

0 commit comments

Comments
 (0)