Skip to content

Commit c8acfc5

Browse files
[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 <[email protected]>
1 parent 4747086 commit c8acfc5

File tree

8 files changed

+1274
-2
lines changed

8 files changed

+1274
-2
lines changed

package-lock.json

Lines changed: 909 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

price_pusher/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ npm run start -- sui \
133133
[--polling-frequency 5] \
134134
[--num-gas-objects 30]
135135
136+
# For Near
137+
npm run start -- near \
138+
--node-url https://rpc.testnet.near.org \
139+
--network testnet \
140+
--account-id payer.testnet \
141+
--pyth-contract-address pyth-oracle.testnet \
142+
--price-service-endpoint "https://hermes-beta.pyth.network" \
143+
--price-config-file ./price-config.beta.sample.yaml \
144+
[--private-key-path ./payer.testnet.json] \
145+
[--pushing-frequency 10] \
146+
[--polling-frequency 5]
147+
136148
137149
# Or, run the price pusher docker image instead of building from the source
138150
docker run public.ecr.aws/pyth-network/xc-price-pusher:v<version> -- <above-arguments>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"node-url": "https://rpc.mainnet.near.org",
3+
"network": "mainnet",
4+
"account-id": "payer.near",
5+
"pyth-contract-address": "pyth-oracle.near",
6+
"price-service-endpoint": "https://hermes.pyth.network",
7+
"price-config-file": "./price-config.stable.sample.yaml"
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"node-url": "https://rpc.testnet.near.org",
3+
"network": "testnet",
4+
"account-id": "payer.testnet",
5+
"pyth-contract-address": "pyth-oracle.testnet",
6+
"price-service-endpoint": "https://hermes-beta.pyth.network",
7+
"price-config-file": "./price-config.beta.sample.yaml"
8+
}

price_pusher/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/price-pusher",
3-
"version": "6.1.0",
3+
"version": "6.2.0",
44
"description": "Pyth Price Pusher",
55
"homepage": "https://pyth.network",
66
"main": "lib/index.js",
@@ -59,6 +59,7 @@
5959
"@truffle/hdwallet-provider": "^2.1.3",
6060
"aptos": "^1.8.5",
6161
"joi": "^17.6.0",
62+
"near-api-js": "^3.0.2",
6263
"web3": "^1.8.1",
6364
"web3-eth-contract": "^1.8.1",
6465
"yaml": "^2.1.1",

price_pusher/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import injective from "./injective/command";
55
import evm from "./evm/command";
66
import aptos from "./aptos/command";
77
import sui from "./sui/command";
8+
import near from "./near/command";
89

910
yargs(hideBin(process.argv))
1011
.config("config")
@@ -13,4 +14,5 @@ yargs(hideBin(process.argv))
1314
.command(injective)
1415
.command(aptos)
1516
.command(sui)
17+
.command(near)
1618
.help().argv;

price_pusher/src/near/command.ts

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { PriceServiceConnection } from "@pythnetwork/price-service-client";
2+
import * as options from "../options";
3+
import { readPriceConfigFile } from "../price-config";
4+
import { PythPriceListener } from "../pyth-price-listener";
5+
import { Controller } from "../controller";
6+
import { Options } from "yargs";
7+
import { NearAccount, NearPriceListener, NearPricePusher } from "./near";
8+
9+
export default {
10+
command: "near",
11+
describe: "run price pusher for near",
12+
builder: {
13+
"node-url": {
14+
description:
15+
"NEAR RPC API url. used to make JSON RPC calls to interact with NEAR.",
16+
type: "string",
17+
required: true,
18+
} as Options,
19+
network: {
20+
description: "testnet or mainnet.",
21+
type: "string",
22+
required: true,
23+
} as Options,
24+
"account-id": {
25+
description: "payer account identifier.",
26+
type: "string",
27+
required: true,
28+
} as Options,
29+
"private-key-path": {
30+
description: "path to payer private key file.",
31+
type: "string",
32+
required: false,
33+
} as Options,
34+
...options.priceConfigFile,
35+
...options.priceServiceEndpoint,
36+
...options.pythContractAddress,
37+
...options.pollingFrequency,
38+
...options.pushingFrequency,
39+
},
40+
handler: function (argv: any) {
41+
// FIXME: type checks for this
42+
const {
43+
nodeUrl,
44+
network,
45+
accountId,
46+
privateKeyPath,
47+
priceConfigFile,
48+
priceServiceEndpoint,
49+
pythContractAddress,
50+
pushingFrequency,
51+
pollingFrequency,
52+
} = argv;
53+
54+
const priceConfigs = readPriceConfigFile(priceConfigFile);
55+
const priceServiceConnection = new PriceServiceConnection(
56+
priceServiceEndpoint,
57+
{
58+
logger: {
59+
// Log only warnings and errors from the price service client
60+
info: () => undefined,
61+
warn: console.warn,
62+
error: console.error,
63+
debug: () => undefined,
64+
trace: () => undefined,
65+
},
66+
}
67+
);
68+
69+
const priceItems = priceConfigs.map(({ id, alias }) => ({ id, alias }));
70+
71+
const pythListener = new PythPriceListener(
72+
priceServiceConnection,
73+
priceItems
74+
);
75+
76+
const nearAccount = new NearAccount(
77+
network,
78+
accountId,
79+
nodeUrl,
80+
privateKeyPath,
81+
pythContractAddress
82+
);
83+
84+
const nearListener = new NearPriceListener(nearAccount, priceItems, {
85+
pollingFrequency,
86+
});
87+
88+
const nearPusher = new NearPricePusher(nearAccount, priceServiceConnection);
89+
90+
const controller = new Controller(
91+
priceConfigs,
92+
pythListener,
93+
nearListener,
94+
nearPusher,
95+
{ pushingFrequency }
96+
);
97+
98+
controller.start();
99+
},
100+
};

0 commit comments

Comments
 (0)