Skip to content

Commit

Permalink
[price_pusher] Add near command (#1306)
Browse files Browse the repository at this point in the history
* 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
MagicGordon and ali-bahjati authored Mar 1, 2024
1 parent 4747086 commit c8acfc5
Show file tree
Hide file tree
Showing 8 changed files with 1,274 additions and 2 deletions.
910 changes: 909 additions & 1 deletion package-lock.json

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions price_pusher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ npm run start -- sui \
[--polling-frequency 5] \
[--num-gas-objects 30]
# For Near
npm run start -- near \
--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 \
[--private-key-path ./payer.testnet.json] \
[--pushing-frequency 10] \
[--polling-frequency 5]
# Or, run the price pusher docker image instead of building from the source
docker run public.ecr.aws/pyth-network/xc-price-pusher:v<version> -- <above-arguments>
Expand Down
8 changes: 8 additions & 0 deletions price_pusher/config.near.mainnet.sample.json
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"
}
8 changes: 8 additions & 0 deletions price_pusher/config.near.testnet.sample.json
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"
}
3 changes: 2 additions & 1 deletion price_pusher/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pythnetwork/price-pusher",
"version": "6.1.0",
"version": "6.2.0",
"description": "Pyth Price Pusher",
"homepage": "https://pyth.network",
"main": "lib/index.js",
Expand Down Expand Up @@ -59,6 +59,7 @@
"@truffle/hdwallet-provider": "^2.1.3",
"aptos": "^1.8.5",
"joi": "^17.6.0",
"near-api-js": "^3.0.2",
"web3": "^1.8.1",
"web3-eth-contract": "^1.8.1",
"yaml": "^2.1.1",
Expand Down
2 changes: 2 additions & 0 deletions price_pusher/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import injective from "./injective/command";
import evm from "./evm/command";
import aptos from "./aptos/command";
import sui from "./sui/command";
import near from "./near/command";

yargs(hideBin(process.argv))
.config("config")
Expand All @@ -13,4 +14,5 @@ yargs(hideBin(process.argv))
.command(injective)
.command(aptos)
.command(sui)
.command(near)
.help().argv;
100 changes: 100 additions & 0 deletions price_pusher/src/near/command.ts
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();
},
};
Loading

0 comments on commit c8acfc5

Please sign in to comment.