From bb4b54309db4f546c0d6248f350b566720d8609a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hern=C3=A1n=20Di=20Pietro?= Date: Tue, 2 Nov 2021 11:49:06 -0300 Subject: [PATCH] gitignore and WIP files. --- .gitignore | 4 +- backend/fetcher/WormholePythPriceFetcher.ts | 66 +++++++++++++++++++++ teal/wormhole/core.teal | 50 +++++++++++++--- 3 files changed, 111 insertions(+), 9 deletions(-) create mode 100644 backend/fetcher/WormholePythPriceFetcher.ts diff --git a/.gitignore b/.gitignore index cc1e49e9a..865054938 100644 --- a/.gitignore +++ b/.gitignore @@ -103,4 +103,6 @@ dist # TernJS port file .tern-port -build/* \ No newline at end of file +build/* +teal/wormhole/pyteal/__pycache__/* +teal/wormhole/build/* diff --git a/backend/fetcher/WormholePythPriceFetcher.ts b/backend/fetcher/WormholePythPriceFetcher.ts new file mode 100644 index 000000000..70056191a --- /dev/null +++ b/backend/fetcher/WormholePythPriceFetcher.ts @@ -0,0 +1,66 @@ +/** + * Pricecaster Service. + * + * Fetcher backend component. + * + * (c) 2021 Randlabs, Inc. + */ + +import { IPriceFetcher } from './IPriceFetcher' +import { IStrategy } from '../strategy/strategy' +import { getPythProgramKeyForCluster, PriceData, Product, PythConnection } from '@pythnetwork/client' +import { Cluster, clusterApiUrl, Connection } from '@solana/web3.js' +import { PriceTicker } from '../common/priceTicker' +import { getEmitterAddressEth, getSignedVAA } from '@certusone/wormhole-sdk' + +export class WormholePythPriceFetcher implements IPriceFetcher { + private strategy: IStrategy + private symbol: string + private pythConnection: PythConnection + + constructor (symbol: string, strategy: IStrategy, solanaClusterName: string) { + const SOLANA_CLUSTER_NAME: Cluster = solanaClusterName as Cluster + const connection = new Connection(clusterApiUrl(SOLANA_CLUSTER_NAME)) + const pythPublicKey = getPythProgramKeyForCluster(SOLANA_CLUSTER_NAME) + this.pythConnection = new PythConnection(connection, pythPublicKey) + this.strategy = strategy + this.symbol = symbol + } + + async start () { + await this.pythConnection.start() + this.pythConnection.onPriceChange((product: Product, price: PriceData) => { + if (product.symbol === this.symbol) { + this.onPriceChange(price) + } + }) + } + + stop (): void { + this.pythConnection.stop() + } + + setStrategy (s: IStrategy) { + this.strategy = s + } + + hasData (): boolean { + return this.strategy.bufferCount() > 0 + } + + queryTicker (): PriceTicker | undefined { + getEmitterAddressEth() + + await getSignedVAA("https://wormhole-v2-testnet-api.certus.one", ) + //return this.strategy.getPrice() + } + + private onPriceChange (price: PriceData) { + GrpcWebImpl + PublicRPCServiceClientImpl + getSignedVAA() + const pt: PriceTicker = new PriceTicker(price.priceComponent, + price.confidenceComponent, price.exponent, price.publishSlot) + this.strategy.put(pt) + } +} diff --git a/teal/wormhole/core.teal b/teal/wormhole/core.teal index 98de9fb3d..ccf2008fc 100644 --- a/teal/wormhole/core.teal +++ b/teal/wormhole/core.teal @@ -47,7 +47,14 @@ // 2 Signature block // 3 Size of all signatures (66 * N) // 4 VAA Body hash - +// +// ----------------------------------------------------------------------------------------- +// Global state: +// +// "gsexptime": Guardian set expiration time +// "gssize" : Guardian set size (number of items) +// key N: address of guardian N +// ----------------------------------------------------------------------------------------- // Application creation. int 0 @@ -102,6 +109,10 @@ bnz success txn ApplicationArgs 0 store 0 +// ------------------------------------------------------ +// Verify VAA +// ------------------------------------------------------ + // Check version load 0 @@ -146,20 +157,43 @@ extract3 keccak256 store 4 +// ---------------------------------------------------------------------------- // verify signature loop +// ---------------------------------------------------------------------------- + +load 2 // sig + +// start -load 2 int 0 // sig index -dup -int 66 -* -extract3 +store 128 // SLOT128: index +loop: +load 4 // hash +int 66 // hash sig index 66 +* // hash sig (66*index) +int 66 // hash sig (66*i) 66 +extract3 // hash S(i) -substr3 -edcsa_verify 0 +load 128 +app_global_get // hash S(i) key(i) +edcsa_verify 0 // is_verified( h,S(i),k(i) ) +int 1 +== +assert +byte "gssize" +app_global_get // gssize +load 128 // gssize index +int 1 // gssize index 1 ++ // gssize (index + 1) +dup // gssize (index + 1)(index + 1) +store 128 // SLOT 128: index+1 +== // gssize == index + 1 +bz loop + +// All verified.