Backend: WIP Wormhole Engine.
This commit is contained in:
parent
115ca04af2
commit
c24827252b
|
@ -16,6 +16,7 @@ import { IPublisher, PublishInfo } from '../publisher/IPublisher'
|
|||
import { PriceTicker } from '../common/priceTicker'
|
||||
import { StatusCode } from '../common/statusCodes'
|
||||
import { sleep } from '../common/sleep'
|
||||
import { WormholePythPriceFetcher } from 'backend/fetcher/WormholePythPriceFetcher'
|
||||
|
||||
const algosdk = require('algosdk')
|
||||
const charm = require('charm')()
|
||||
|
@ -63,7 +64,7 @@ export class WormholeClientEngine implements IEngine {
|
|||
this.settings.algo.port
|
||||
)
|
||||
|
||||
const fetcher = new PythPriceFetcher(this.settings.params.symbol,
|
||||
const fetcher = new WormholePythPriceFetcher(this.settings.params.symbol,
|
||||
new StrategyLastPrice(this.settings.params.bufferSize), this.settings.pyth?.solanaClusterName!)
|
||||
await fetcher.start()
|
||||
|
||||
|
|
|
@ -1,66 +1,66 @@
|
|||
// /**
|
||||
// * Pricecaster Service.
|
||||
// *
|
||||
// * Fetcher backend component.
|
||||
// *
|
||||
// * (c) 2021 Randlabs, Inc.
|
||||
// */
|
||||
/**
|
||||
* 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'
|
||||
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
|
||||
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
|
||||
// }
|
||||
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)
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
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()
|
||||
// }
|
||||
stop (): void {
|
||||
this.pythConnection.stop()
|
||||
}
|
||||
|
||||
// setStrategy (s: IStrategy) {
|
||||
// this.strategy = s
|
||||
// }
|
||||
setStrategy (s: IStrategy) {
|
||||
this.strategy = s
|
||||
}
|
||||
|
||||
// hasData (): boolean {
|
||||
// return this.strategy.bufferCount() > 0
|
||||
// }
|
||||
hasData (): boolean {
|
||||
return this.strategy.bufferCount() > 0
|
||||
}
|
||||
|
||||
// queryTicker (): PriceTicker | undefined {
|
||||
// getEmitterAddressEth()
|
||||
queryTicker (): PriceTicker | undefined {
|
||||
getEmitterAddressEth()
|
||||
|
||||
// await getSignedVAA("https://wormhole-v2-testnet-api.certus.one", )
|
||||
// //return this.strategy.getPrice()
|
||||
// }
|
||||
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)
|
||||
// }
|
||||
// }
|
||||
private onPriceChange (price: PriceData) {
|
||||
GrpcWebImpl
|
||||
PublicRPCServiceClientImpl
|
||||
getSignedVAA()
|
||||
const pt: PriceTicker = new PriceTicker(price.priceComponent,
|
||||
price.confidenceComponent, price.exponent, price.publishSlot)
|
||||
this.strategy.put(pt)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue