gitignore and WIP files.
This commit is contained in:
parent
b37c8943d4
commit
bb4b54309d
|
@ -103,4 +103,6 @@ dist
|
|||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
build/*
|
||||
build/*
|
||||
teal/wormhole/pyteal/__pycache__/*
|
||||
teal/wormhole/build/*
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue