[price-service] Update wormhole sdk package (#495)

* [price-service] Update wormhole sdk package

Wormhole new sdk does not use wasm and is cleaner. It makes our code one
step closer to no wasm too.

* trigger ci

* Fix pre-commit errors
This commit is contained in:
Ali Behjati 2023-01-16 19:07:08 +01:00 committed by GitHub
parent c10ed691da
commit b05845ede5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 4230 additions and 2006 deletions

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,7 @@
"typescript": "^4.3.5" "typescript": "^4.3.5"
}, },
"dependencies": { "dependencies": {
"@certusone/wormhole-sdk": "^0.1.4", "@certusone/wormhole-sdk": "^0.9.9",
"@certusone/wormhole-spydk": "^0.0.1", "@certusone/wormhole-spydk": "^0.0.1",
"@pythnetwork/p2w-sdk-js": "file:../third_party/pyth/p2w-sdk/js", "@pythnetwork/p2w-sdk-js": "file:../third_party/pyth/p2w-sdk/js",
"@pythnetwork/pyth-sdk-js": "^1.1.0", "@pythnetwork/pyth-sdk-js": "^1.1.0",

View File

@ -42,7 +42,7 @@ function dummyPriceInfoPair(
priceFeed: dummyPriceFeed(id), priceFeed: dummyPriceFeed(id),
publishTime: 0, publishTime: 0,
attestationTime: 0, attestationTime: 0,
seqNum, seqNum: BigInt(seqNum),
vaa: Buffer.from(vaa, "hex"), vaa: Buffer.from(vaa, "hex"),
emitterChainId: 0, emitterChainId: 0,
priceServiceReceiveTime: 0, priceServiceReceiveTime: 0,

View File

@ -1,5 +1,3 @@
import { setDefaultWasm } from "@certusone/wormhole-sdk/lib/cjs/solana/wasm";
import { envOrErr } from "./helpers"; import { envOrErr } from "./helpers";
import { Listener } from "./listen"; import { Listener } from "./listen";
import { initLogger } from "./logging"; import { initLogger } from "./logging";
@ -17,8 +15,6 @@ console.log("Loading config file [%s]", configFile);
// tslint:disable:no-var-requires // tslint:disable:no-var-requires
require("dotenv").config({ path: configFile }); require("dotenv").config({ path: configFile });
setDefaultWasm("node");
// Set up the logger. // Set up the logger.
initLogger({ logLevel: process.env.LOG_LEVEL }); initLogger({ logLevel: process.env.LOG_LEVEL });

View File

@ -1,11 +1,9 @@
import { ChainId, uint8ArrayToHex } from "@certusone/wormhole-sdk";
import { import {
createSpyRPCServiceClient, createSpyRPCServiceClient,
subscribeSignedVAA, subscribeSignedVAA,
} from "@certusone/wormhole-spydk"; } from "@certusone/wormhole-spydk";
import { importCoreWasm } from "@certusone/wormhole-sdk/lib/cjs/solana/wasm"; import { ChainId, uint8ArrayToHex, parseVaa } from "@certusone/wormhole-sdk";
import { import {
FilterEntry, FilterEntry,
@ -25,7 +23,7 @@ import { PromClient } from "./promClient";
export type PriceInfo = { export type PriceInfo = {
vaa: Buffer; vaa: Buffer;
seqNum: number; seqNum: bigint;
publishTime: TimestampInSec; publishTime: TimestampInSec;
attestationTime: TimestampInSec; attestationTime: TimestampInSec;
priceFeed: PriceFeed; priceFeed: PriceFeed;
@ -249,14 +247,12 @@ export class Listener implements PriceStore {
} }
async processVaa(vaa: Buffer) { async processVaa(vaa: Buffer) {
const { parse_vaa } = await importCoreWasm(); const parsedVaa = parseVaa(vaa);
const parsedVaa = parse_vaa(vaa); const vaaEmitterAddressHex = Buffer.from(parsedVaa.emitterAddress).toString(
"hex"
const vaaEmitterAddressHex = Buffer.from( );
parsedVaa.emitter_address const observedVaasKey: VaaKey = `${parsedVaa.emitterChain}#${vaaEmitterAddressHex}#${parsedVaa.sequence}`;
).toString("hex");
const observedVaasKey: VaaKey = `${parsedVaa.emitter_chain}#${vaaEmitterAddressHex}#${parsedVaa.sequence}`;
if (this.observedVaas.has(observedVaasKey)) { if (this.observedVaas.has(observedVaasKey)) {
return; return;
@ -287,7 +283,7 @@ export class Listener implements PriceStore {
publishTime: priceAttestation.publishTime, publishTime: priceAttestation.publishTime,
attestationTime: priceAttestation.attestationTime, attestationTime: priceAttestation.attestationTime,
priceFeed, priceFeed,
emitterChainId: parsedVaa.emitter_chain, emitterChainId: parsedVaa.emitterChain,
priceServiceReceiveTime: Math.floor(new Date().getTime() / 1000), priceServiceReceiveTime: Math.floor(new Date().getTime() / 1000),
}; };
@ -318,9 +314,9 @@ export class Listener implements PriceStore {
logger.info( logger.info(
"Parsed a new Batch Price Attestation: [" + "Parsed a new Batch Price Attestation: [" +
parsedVaa.emitter_chain + parsedVaa.emitterChain +
":" + ":" +
uint8ArrayToHex(parsedVaa.emitter_address) + uint8ArrayToHex(parsedVaa.emitterAddress) +
"], seqNum: " + "], seqNum: " +
parsedVaa.sequence + parsedVaa.sequence +
", Batch Summary: " + ", Batch Summary: " +

View File

@ -84,7 +84,7 @@ export class RestAPI {
// Multiple price ids might share same vaa, we use sequence number as // Multiple price ids might share same vaa, we use sequence number as
// key of a vaa and deduplicate using a map of seqnum to vaa bytes. // key of a vaa and deduplicate using a map of seqnum to vaa bytes.
const vaaMap = new Map<number, Buffer>(); const vaaMap = new Map<bigint, Buffer>();
const notFoundIds: string[] = []; const notFoundIds: string[] = [];