-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[price_pusher] Add near command (#1306)
* add near command * add try catch to getPriceFeedsUpdateData and getUpdateFeeEstimate * add private-key-path optional parameter * chore: run pre-commit * fix: make private key optional * chore: bump version --------- Co-authored-by: Ali Behjati <bahjatia@gmail.com>
- Loading branch information
1 parent
4747086
commit c8acfc5
Showing
8 changed files
with
1,274 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"node-url": "https://rpc.mainnet.near.org", | ||
"network": "mainnet", | ||
"account-id": "payer.near", | ||
"pyth-contract-address": "pyth-oracle.near", | ||
"price-service-endpoint": "https://hermes.pyth.network", | ||
"price-config-file": "./price-config.stable.sample.yaml" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"node-url": "https://rpc.testnet.near.org", | ||
"network": "testnet", | ||
"account-id": "payer.testnet", | ||
"pyth-contract-address": "pyth-oracle.testnet", | ||
"price-service-endpoint": "https://hermes-beta.pyth.network", | ||
"price-config-file": "./price-config.beta.sample.yaml" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { PriceServiceConnection } from "@pythnetwork/price-service-client"; | ||
import * as options from "../options"; | ||
import { readPriceConfigFile } from "../price-config"; | ||
import { PythPriceListener } from "../pyth-price-listener"; | ||
import { Controller } from "../controller"; | ||
import { Options } from "yargs"; | ||
import { NearAccount, NearPriceListener, NearPricePusher } from "./near"; | ||
|
||
export default { | ||
command: "near", | ||
describe: "run price pusher for near", | ||
builder: { | ||
"node-url": { | ||
description: | ||
"NEAR RPC API url. used to make JSON RPC calls to interact with NEAR.", | ||
type: "string", | ||
required: true, | ||
} as Options, | ||
network: { | ||
description: "testnet or mainnet.", | ||
type: "string", | ||
required: true, | ||
} as Options, | ||
"account-id": { | ||
description: "payer account identifier.", | ||
type: "string", | ||
required: true, | ||
} as Options, | ||
"private-key-path": { | ||
description: "path to payer private key file.", | ||
type: "string", | ||
required: false, | ||
} as Options, | ||
...options.priceConfigFile, | ||
...options.priceServiceEndpoint, | ||
...options.pythContractAddress, | ||
...options.pollingFrequency, | ||
...options.pushingFrequency, | ||
}, | ||
handler: function (argv: any) { | ||
// FIXME: type checks for this | ||
const { | ||
nodeUrl, | ||
network, | ||
accountId, | ||
privateKeyPath, | ||
priceConfigFile, | ||
priceServiceEndpoint, | ||
pythContractAddress, | ||
pushingFrequency, | ||
pollingFrequency, | ||
} = argv; | ||
|
||
const priceConfigs = readPriceConfigFile(priceConfigFile); | ||
const priceServiceConnection = new PriceServiceConnection( | ||
priceServiceEndpoint, | ||
{ | ||
logger: { | ||
// Log only warnings and errors from the price service client | ||
info: () => undefined, | ||
warn: console.warn, | ||
error: console.error, | ||
debug: () => undefined, | ||
trace: () => undefined, | ||
}, | ||
} | ||
); | ||
|
||
const priceItems = priceConfigs.map(({ id, alias }) => ({ id, alias })); | ||
|
||
const pythListener = new PythPriceListener( | ||
priceServiceConnection, | ||
priceItems | ||
); | ||
|
||
const nearAccount = new NearAccount( | ||
network, | ||
accountId, | ||
nodeUrl, | ||
privateKeyPath, | ||
pythContractAddress | ||
); | ||
|
||
const nearListener = new NearPriceListener(nearAccount, priceItems, { | ||
pollingFrequency, | ||
}); | ||
|
||
const nearPusher = new NearPricePusher(nearAccount, priceServiceConnection); | ||
|
||
const controller = new Controller( | ||
priceConfigs, | ||
pythListener, | ||
nearListener, | ||
nearPusher, | ||
{ pushingFrequency } | ||
); | ||
|
||
controller.start(); | ||
}, | ||
}; |
Oops, something went wrong.