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 { PriceTicker } from '../common/priceTicker'
|
||||||
import { StatusCode } from '../common/statusCodes'
|
import { StatusCode } from '../common/statusCodes'
|
||||||
import { sleep } from '../common/sleep'
|
import { sleep } from '../common/sleep'
|
||||||
|
import { WormholePythPriceFetcher } from 'backend/fetcher/WormholePythPriceFetcher'
|
||||||
|
|
||||||
const algosdk = require('algosdk')
|
const algosdk = require('algosdk')
|
||||||
const charm = require('charm')()
|
const charm = require('charm')()
|
||||||
|
@ -63,7 +64,7 @@ export class WormholeClientEngine implements IEngine {
|
||||||
this.settings.algo.port
|
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!)
|
new StrategyLastPrice(this.settings.params.bufferSize), this.settings.pyth?.solanaClusterName!)
|
||||||
await fetcher.start()
|
await fetcher.start()
|
||||||
|
|
||||||
|
|
|
@ -1,66 +1,66 @@
|
||||||
// /**
|
/**
|
||||||
// * Pricecaster Service.
|
* Pricecaster Service.
|
||||||
// *
|
*
|
||||||
// * Fetcher backend component.
|
* Fetcher backend component.
|
||||||
// *
|
*
|
||||||
// * (c) 2021 Randlabs, Inc.
|
* (c) 2021 Randlabs, Inc.
|
||||||
// */
|
*/
|
||||||
|
|
||||||
// import { IPriceFetcher } from './IPriceFetcher'
|
import { IPriceFetcher } from './IPriceFetcher'
|
||||||
// import { IStrategy } from '../strategy/strategy'
|
import { IStrategy } from '../strategy/strategy'
|
||||||
// import { getPythProgramKeyForCluster, PriceData, Product, PythConnection } from '@pythnetwork/client'
|
import { getPythProgramKeyForCluster, PriceData, Product, PythConnection } from '@pythnetwork/client'
|
||||||
// import { Cluster, clusterApiUrl, Connection } from '@solana/web3.js'
|
import { Cluster, clusterApiUrl, Connection } from '@solana/web3.js'
|
||||||
// import { PriceTicker } from '../common/priceTicker'
|
import { PriceTicker } from '../common/priceTicker'
|
||||||
// import { getEmitterAddressEth, getSignedVAA } from '@certusone/wormhole-sdk'
|
import { getEmitterAddressEth, getSignedVAA } from '@certusone/wormhole-sdk'
|
||||||
|
|
||||||
// export class WormholePythPriceFetcher implements IPriceFetcher {
|
export class WormholePythPriceFetcher implements IPriceFetcher {
|
||||||
// private strategy: IStrategy
|
private strategy: IStrategy
|
||||||
// private symbol: string
|
private symbol: string
|
||||||
// private pythConnection: PythConnection
|
private pythConnection: PythConnection
|
||||||
|
|
||||||
// constructor (symbol: string, strategy: IStrategy, solanaClusterName: string) {
|
constructor (symbol: string, strategy: IStrategy, solanaClusterName: string) {
|
||||||
// const SOLANA_CLUSTER_NAME: Cluster = solanaClusterName as Cluster
|
const SOLANA_CLUSTER_NAME: Cluster = solanaClusterName as Cluster
|
||||||
// const connection = new Connection(clusterApiUrl(SOLANA_CLUSTER_NAME))
|
const connection = new Connection(clusterApiUrl(SOLANA_CLUSTER_NAME))
|
||||||
// const pythPublicKey = getPythProgramKeyForCluster(SOLANA_CLUSTER_NAME)
|
const pythPublicKey = getPythProgramKeyForCluster(SOLANA_CLUSTER_NAME)
|
||||||
// this.pythConnection = new PythConnection(connection, pythPublicKey)
|
this.pythConnection = new PythConnection(connection, pythPublicKey)
|
||||||
// this.strategy = strategy
|
this.strategy = strategy
|
||||||
// this.symbol = symbol
|
this.symbol = symbol
|
||||||
// }
|
}
|
||||||
|
|
||||||
// async start () {
|
async start () {
|
||||||
// await this.pythConnection.start()
|
await this.pythConnection.start()
|
||||||
// this.pythConnection.onPriceChange((product: Product, price: PriceData) => {
|
this.pythConnection.onPriceChange((product: Product, price: PriceData) => {
|
||||||
// if (product.symbol === this.symbol) {
|
if (product.symbol === this.symbol) {
|
||||||
// this.onPriceChange(price)
|
this.onPriceChange(price)
|
||||||
// }
|
}
|
||||||
// })
|
})
|
||||||
// }
|
}
|
||||||
|
|
||||||
// stop (): void {
|
stop (): void {
|
||||||
// this.pythConnection.stop()
|
this.pythConnection.stop()
|
||||||
// }
|
}
|
||||||
|
|
||||||
// setStrategy (s: IStrategy) {
|
setStrategy (s: IStrategy) {
|
||||||
// this.strategy = s
|
this.strategy = s
|
||||||
// }
|
}
|
||||||
|
|
||||||
// hasData (): boolean {
|
hasData (): boolean {
|
||||||
// return this.strategy.bufferCount() > 0
|
return this.strategy.bufferCount() > 0
|
||||||
// }
|
}
|
||||||
|
|
||||||
// queryTicker (): PriceTicker | undefined {
|
queryTicker (): PriceTicker | undefined {
|
||||||
// getEmitterAddressEth()
|
getEmitterAddressEth()
|
||||||
|
|
||||||
// await getSignedVAA("https://wormhole-v2-testnet-api.certus.one", )
|
await getSignedVAA("https://wormhole-v2-testnet-api.certus.one", )
|
||||||
// //return this.strategy.getPrice()
|
//return this.strategy.getPrice()
|
||||||
// }
|
}
|
||||||
|
|
||||||
// private onPriceChange (price: PriceData) {
|
private onPriceChange (price: PriceData) {
|
||||||
// GrpcWebImpl
|
GrpcWebImpl
|
||||||
// PublicRPCServiceClientImpl
|
PublicRPCServiceClientImpl
|
||||||
// getSignedVAA()
|
getSignedVAA()
|
||||||
// const pt: PriceTicker = new PriceTicker(price.priceComponent,
|
const pt: PriceTicker = new PriceTicker(price.priceComponent,
|
||||||
// price.confidenceComponent, price.exponent, price.publishSlot)
|
price.confidenceComponent, price.exponent, price.publishSlot)
|
||||||
// this.strategy.put(pt)
|
this.strategy.put(pt)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
Loading…
Reference in New Issue