@pythnetwork/price-pusher 8.3.3 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/lib/aptos/aptos.d.ts +3 -3
- package/lib/aptos/aptos.d.ts.map +1 -1
- package/lib/aptos/aptos.js +8 -7
- package/lib/aptos/command.d.ts +1 -2
- package/lib/aptos/command.d.ts.map +1 -1
- package/lib/aptos/command.js +16 -10
- package/lib/evm/command.d.ts +0 -1
- package/lib/evm/command.d.ts.map +1 -1
- package/lib/evm/command.js +18 -10
- package/lib/evm/evm.d.ts +3 -3
- package/lib/evm/evm.d.ts.map +1 -1
- package/lib/evm/evm.js +13 -9
- package/lib/fuel/command.d.ts +0 -1
- package/lib/fuel/command.d.ts.map +1 -1
- package/lib/fuel/command.js +15 -9
- package/lib/fuel/fuel.d.ts +3 -3
- package/lib/fuel/fuel.d.ts.map +1 -1
- package/lib/fuel/fuel.js +8 -5
- package/lib/injective/command.d.ts +1 -2
- package/lib/injective/command.d.ts.map +1 -1
- package/lib/injective/command.js +16 -10
- package/lib/injective/injective.d.ts +3 -3
- package/lib/injective/injective.d.ts.map +1 -1
- package/lib/injective/injective.js +7 -4
- package/lib/interface.d.ts +1 -1
- package/lib/interface.d.ts.map +1 -1
- package/lib/near/command.d.ts +1 -2
- package/lib/near/command.d.ts.map +1 -1
- package/lib/near/command.js +16 -10
- package/lib/near/near.d.ts +3 -3
- package/lib/near/near.d.ts.map +1 -1
- package/lib/near/near.js +7 -5
- package/lib/options.d.ts +0 -3
- package/lib/options.d.ts.map +1 -1
- package/lib/options.js +2 -11
- package/lib/price-config.d.ts +1 -1
- package/lib/price-config.d.ts.map +1 -1
- package/lib/pyth-price-listener.d.ts +4 -5
- package/lib/pyth-price-listener.d.ts.map +1 -1
- package/lib/pyth-price-listener.js +30 -85
- package/lib/solana/command.d.ts +1 -2
- package/lib/solana/command.d.ts.map +1 -1
- package/lib/solana/command.js +20 -14
- package/lib/solana/solana.d.ts +5 -5
- package/lib/solana/solana.d.ts.map +1 -1
- package/lib/solana/solana.js +14 -8
- package/lib/sui/command.d.ts +0 -1
- package/lib/sui/command.d.ts.map +1 -1
- package/lib/sui/command.js +16 -13
- package/lib/sui/sui.d.ts +4 -4
- package/lib/sui/sui.d.ts.map +1 -1
- package/lib/sui/sui.js +11 -9
- package/lib/ton/command.d.ts +0 -1
- package/lib/ton/command.d.ts.map +1 -1
- package/lib/ton/command.js +15 -9
- package/lib/ton/ton.d.ts +3 -3
- package/lib/ton/ton.d.ts.map +1 -1
- package/lib/ton/ton.js +7 -4
- package/lib/utils.d.ts +6 -1
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +16 -0
- package/package.json +4 -5
package/lib/solana/solana.js
CHANGED
|
@@ -62,13 +62,13 @@ class SolanaPriceListener extends interface_1.ChainPriceListener {
|
|
|
62
62
|
exports.SolanaPriceListener = SolanaPriceListener;
|
|
63
63
|
class SolanaPricePusher {
|
|
64
64
|
pythSolanaReceiver;
|
|
65
|
-
|
|
65
|
+
hermesClient;
|
|
66
66
|
logger;
|
|
67
67
|
shardId;
|
|
68
68
|
computeUnitPriceMicroLamports;
|
|
69
|
-
constructor(pythSolanaReceiver,
|
|
69
|
+
constructor(pythSolanaReceiver, hermesClient, logger, shardId, computeUnitPriceMicroLamports) {
|
|
70
70
|
this.pythSolanaReceiver = pythSolanaReceiver;
|
|
71
|
-
this.
|
|
71
|
+
this.hermesClient = hermesClient;
|
|
72
72
|
this.logger = logger;
|
|
73
73
|
this.shardId = shardId;
|
|
74
74
|
this.computeUnitPriceMicroLamports = computeUnitPriceMicroLamports;
|
|
@@ -85,7 +85,10 @@ class SolanaPricePusher {
|
|
|
85
85
|
.map((x) => x.element);
|
|
86
86
|
let priceFeedUpdateData;
|
|
87
87
|
try {
|
|
88
|
-
|
|
88
|
+
const response = await this.hermesClient.getLatestPriceUpdates(shuffledPriceIds, {
|
|
89
|
+
encoding: "base64",
|
|
90
|
+
});
|
|
91
|
+
priceFeedUpdateData = response.binary.data;
|
|
89
92
|
}
|
|
90
93
|
catch (err) {
|
|
91
94
|
this.logger.error(err, "getPriceFeedsUpdateData failed:");
|
|
@@ -112,7 +115,7 @@ class SolanaPricePusher {
|
|
|
112
115
|
exports.SolanaPricePusher = SolanaPricePusher;
|
|
113
116
|
class SolanaPricePusherJito {
|
|
114
117
|
pythSolanaReceiver;
|
|
115
|
-
|
|
118
|
+
hermesClient;
|
|
116
119
|
logger;
|
|
117
120
|
shardId;
|
|
118
121
|
defaultJitoTipLamports;
|
|
@@ -121,9 +124,9 @@ class SolanaPricePusherJito {
|
|
|
121
124
|
searcherClient;
|
|
122
125
|
jitoBundleSize;
|
|
123
126
|
updatesPerJitoBundle;
|
|
124
|
-
constructor(pythSolanaReceiver,
|
|
127
|
+
constructor(pythSolanaReceiver, hermesClient, logger, shardId, defaultJitoTipLamports, dynamicJitoTips, maxJitoTipLamports, searcherClient, jitoBundleSize, updatesPerJitoBundle) {
|
|
125
128
|
this.pythSolanaReceiver = pythSolanaReceiver;
|
|
126
|
-
this.
|
|
129
|
+
this.hermesClient = hermesClient;
|
|
127
130
|
this.logger = logger;
|
|
128
131
|
this.shardId = shardId;
|
|
129
132
|
this.defaultJitoTipLamports = defaultJitoTipLamports;
|
|
@@ -160,7 +163,10 @@ class SolanaPricePusherJito {
|
|
|
160
163
|
this.logger.info({ cappedJitoTip }, "using jito tip of");
|
|
161
164
|
let priceFeedUpdateData;
|
|
162
165
|
try {
|
|
163
|
-
|
|
166
|
+
const response = await this.hermesClient.getLatestPriceUpdates(priceIds, {
|
|
167
|
+
encoding: "base64",
|
|
168
|
+
});
|
|
169
|
+
priceFeedUpdateData = response.binary.data;
|
|
164
170
|
}
|
|
165
171
|
catch (err) {
|
|
166
172
|
this.logger.error(err, "getPriceFeedsUpdateData failed");
|
package/lib/sui/command.d.ts
CHANGED
package/lib/sui/command.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/sui/command.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/sui/command.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;;;;;;;;;;;;kBAqBvB,OAAO;yBAOP,OAAO;6BAOP,OAAO;2BAMP,OAAO;8BAOP,OAAO;sBAMP,OAAO;yBAMP,OAAO;;oBASiB,GAAG;;AA/DpC,wBAsJE"}
|
package/lib/sui/command.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const
|
|
29
|
+
const hermes_client_1 = require("@pythnetwork/hermes-client");
|
|
30
30
|
const options = __importStar(require("../options"));
|
|
31
31
|
const price_config_1 = require("../price-config");
|
|
32
32
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -35,11 +35,12 @@ const controller_1 = require("../controller");
|
|
|
35
35
|
const sui_1 = require("./sui");
|
|
36
36
|
const ed25519_1 = require("@mysten/sui/keypairs/ed25519");
|
|
37
37
|
const pino_1 = __importDefault(require("pino"));
|
|
38
|
+
const utils_1 = require("../utils");
|
|
38
39
|
exports.default = {
|
|
39
40
|
command: "sui",
|
|
40
41
|
describe: "Run price pusher for sui. Most of the arguments below are" +
|
|
41
42
|
"network specific, so there's one set of values for mainnet and" +
|
|
42
|
-
"another for testnet. See config.sui
|
|
43
|
+
" another for testnet. See config.sui.mainnet.sample.json for the " +
|
|
43
44
|
"appropriate values for your network. ",
|
|
44
45
|
builder: {
|
|
45
46
|
endpoint: {
|
|
@@ -91,28 +92,30 @@ exports.default = {
|
|
|
91
92
|
...options.pollingFrequency,
|
|
92
93
|
...options.pushingFrequency,
|
|
93
94
|
...options.logLevel,
|
|
94
|
-
...options.priceServiceConnectionLogLevel,
|
|
95
95
|
...options.controllerLogLevel,
|
|
96
96
|
},
|
|
97
97
|
handler: async function (argv) {
|
|
98
|
-
const { endpoint, priceConfigFile, priceServiceEndpoint, mnemonicFile, pushingFrequency, pollingFrequency, pythStateId, wormholeStateId, numGasObjects, ignoreGasObjects, gasBudget, accountIndex, logLevel,
|
|
98
|
+
const { endpoint, priceConfigFile, priceServiceEndpoint, mnemonicFile, pushingFrequency, pollingFrequency, pythStateId, wormholeStateId, numGasObjects, ignoreGasObjects, gasBudget, accountIndex, logLevel, controllerLogLevel, } = argv;
|
|
99
99
|
const logger = (0, pino_1.default)({ level: logLevel });
|
|
100
100
|
const priceConfigs = (0, price_config_1.readPriceConfigFile)(priceConfigFile);
|
|
101
|
-
const
|
|
102
|
-
logger: logger.child({ module: "PriceServiceConnection" }, { level: priceServiceConnectionLogLevel }),
|
|
103
|
-
priceFeedRequestConfig: {
|
|
104
|
-
binary: true,
|
|
105
|
-
},
|
|
106
|
-
});
|
|
101
|
+
const hermesClient = new hermes_client_1.HermesClient(priceServiceEndpoint);
|
|
107
102
|
const mnemonic = fs_1.default.readFileSync(mnemonicFile, "utf-8").trim();
|
|
108
103
|
const keypair = ed25519_1.Ed25519Keypair.deriveKeypair(mnemonic, `m/44'/784'/${accountIndex}'/0'/0'`);
|
|
109
104
|
logger.info(`Pushing updates from wallet address: ${keypair
|
|
110
105
|
.getPublicKey()
|
|
111
106
|
.toSuiAddress()}`);
|
|
112
|
-
|
|
113
|
-
|
|
107
|
+
let priceItems = priceConfigs.map(({ id, alias }) => ({ id, alias }));
|
|
108
|
+
// Better to filter out invalid price items before creating the pyth listener
|
|
109
|
+
const { existingPriceItems, invalidPriceItems } = await (0, utils_1.filterInvalidPriceItems)(hermesClient, priceItems);
|
|
110
|
+
if (invalidPriceItems.length > 0) {
|
|
111
|
+
logger.error(`Invalid price id submitted for: ${invalidPriceItems
|
|
112
|
+
.map(({ alias }) => alias)
|
|
113
|
+
.join(", ")}`);
|
|
114
|
+
}
|
|
115
|
+
priceItems = existingPriceItems;
|
|
116
|
+
const pythListener = new pyth_price_listener_1.PythPriceListener(hermesClient, priceItems, logger.child({ module: "PythPriceListener" }));
|
|
114
117
|
const suiListener = new sui_1.SuiPriceListener(pythStateId, wormholeStateId, endpoint, priceItems, logger.child({ module: "SuiPriceListener" }), { pollingFrequency });
|
|
115
|
-
const suiPusher = await sui_1.SuiPricePusher.createWithAutomaticGasPool(
|
|
118
|
+
const suiPusher = await sui_1.SuiPricePusher.createWithAutomaticGasPool(hermesClient, logger.child({ module: "SuiPricePusher" }), pythStateId, wormholeStateId, endpoint, keypair, gasBudget, numGasObjects, ignoreGasObjects);
|
|
116
119
|
const controller = new controller_1.Controller(priceConfigs, pythListener, suiListener, suiPusher, logger.child({ module: "Controller" }, { level: controllerLogLevel }), { pushingFrequency });
|
|
117
120
|
controller.start();
|
|
118
121
|
},
|
package/lib/sui/sui.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ChainPriceListener, IPricePusher, PriceInfo, PriceItem } from "../interface";
|
|
2
2
|
import { DurationInSeconds } from "../utils";
|
|
3
|
-
import { PriceServiceConnection } from "@pythnetwork/price-service-client";
|
|
4
3
|
import { SuiPythClient } from "@pythnetwork/pyth-sui-js";
|
|
5
4
|
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
6
5
|
import { SuiClient, SuiObjectRef } from "@mysten/sui/client";
|
|
7
6
|
import { Logger } from "pino";
|
|
7
|
+
import { HermesClient } from "@pythnetwork/hermes-client";
|
|
8
8
|
type ObjectId = string;
|
|
9
9
|
export declare class SuiPriceListener extends ChainPriceListener {
|
|
10
10
|
private pythClient;
|
|
@@ -33,11 +33,11 @@ export declare class SuiPricePusher implements IPricePusher {
|
|
|
33
33
|
private readonly signer;
|
|
34
34
|
private readonly provider;
|
|
35
35
|
private logger;
|
|
36
|
-
private
|
|
36
|
+
private hermesClient;
|
|
37
37
|
private gasBudget;
|
|
38
38
|
private gasPool;
|
|
39
39
|
private pythClient;
|
|
40
|
-
constructor(signer: Ed25519Keypair, provider: SuiClient, logger: Logger,
|
|
40
|
+
constructor(signer: Ed25519Keypair, provider: SuiClient, logger: Logger, hermesClient: HermesClient, gasBudget: number, gasPool: SuiObjectRef[], pythClient: SuiPythClient);
|
|
41
41
|
/**
|
|
42
42
|
* getPackageId returns the latest package id that the object belongs to. Use this to
|
|
43
43
|
* fetch the latest package id for a given object id and handle package upgrades automatically.
|
|
@@ -50,7 +50,7 @@ export declare class SuiPricePusher implements IPricePusher {
|
|
|
50
50
|
* Create a price pusher with a pool of `numGasObjects` gas coins that will be used to send transactions.
|
|
51
51
|
* The gas coins of the wallet for the provided keypair will be merged and then evenly split into `numGasObjects`.
|
|
52
52
|
*/
|
|
53
|
-
static createWithAutomaticGasPool(
|
|
53
|
+
static createWithAutomaticGasPool(hermesClient: HermesClient, logger: Logger, pythStateId: string, wormholeStateId: string, endpoint: string, keypair: Ed25519Keypair, gasBudget: number, numGasObjects: number, ignoreGasObjects: string[]): Promise<SuiPricePusher>;
|
|
54
54
|
updatePriceFeed(priceIds: string[], pubTimesToPush: number[]): Promise<void>;
|
|
55
55
|
/** Send every transaction in txs in parallel, returning when all transactions have completed. */
|
|
56
56
|
private sendTransactionBlocks;
|
package/lib/sui/sui.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sui.d.ts","sourceRoot":"","sources":["../../src/sui/sui.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,SAAS,EACT,SAAS,EACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"sui.d.ts","sourceRoot":"","sources":["../../src/sui/sui.ts"],"names":[],"mappings":"AAAA,OAAO,E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Y,EAAE,EACvB,UAAU,EAAE,aAAa;IAGnC;;;;;;OAMG;WACU,YAAY,CACvB,QAAQ,EAAE,SAAS,EACnB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,QAAQ,CAAC;IAyBpB;;;OAGG;WACU,0BAA0B,CACrC,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,gBAAgB,EAAE,MAAM,EAAE,GACzB,OAAO,CAAC,cAAc,CAAC;IAkCpB,eAAe,CACnB,QAAQ,EAAE,MAAM,EAAE,EAClB,cAAc,EAAE,MAAM,EAAE,GACvB,OAAO,CAAC,IAAI,CAAC;IA6ChB,iGAAiG;YACnF,qBAAqB;IAInC,sEAAsE;YACxD,oBAAoB;mBAyDb,iBAAiB;mBAsDjB,yBAAyB;mBAgBzB,cAAc;mBAiCd,mBAAmB;mBAwCnB,oBAAoB;CAiE1C"}
|
package/lib/sui/sui.js
CHANGED
|
@@ -73,15 +73,15 @@ class SuiPricePusher {
|
|
|
73
73
|
signer;
|
|
74
74
|
provider;
|
|
75
75
|
logger;
|
|
76
|
-
|
|
76
|
+
hermesClient;
|
|
77
77
|
gasBudget;
|
|
78
78
|
gasPool;
|
|
79
79
|
pythClient;
|
|
80
|
-
constructor(signer, provider, logger,
|
|
80
|
+
constructor(signer, provider, logger, hermesClient, gasBudget, gasPool, pythClient) {
|
|
81
81
|
this.signer = signer;
|
|
82
82
|
this.provider = provider;
|
|
83
83
|
this.logger = logger;
|
|
84
|
-
this.
|
|
84
|
+
this.hermesClient = hermesClient;
|
|
85
85
|
this.gasBudget = gasBudget;
|
|
86
86
|
this.gasPool = gasPool;
|
|
87
87
|
this.pythClient = pythClient;
|
|
@@ -118,14 +118,14 @@ class SuiPricePusher {
|
|
|
118
118
|
* Create a price pusher with a pool of `numGasObjects` gas coins that will be used to send transactions.
|
|
119
119
|
* The gas coins of the wallet for the provided keypair will be merged and then evenly split into `numGasObjects`.
|
|
120
120
|
*/
|
|
121
|
-
static async createWithAutomaticGasPool(
|
|
121
|
+
static async createWithAutomaticGasPool(hermesClient, logger, pythStateId, wormholeStateId, endpoint, keypair, gasBudget, numGasObjects, ignoreGasObjects) {
|
|
122
122
|
if (numGasObjects > MAX_NUM_OBJECTS_IN_ARGUMENT) {
|
|
123
123
|
throw new Error(`numGasObjects cannot be greater than ${MAX_NUM_OBJECTS_IN_ARGUMENT} until we implement split chunking`);
|
|
124
124
|
}
|
|
125
125
|
const provider = new client_1.SuiClient({ url: endpoint });
|
|
126
126
|
const gasPool = await SuiPricePusher.initializeGasPool(keypair, provider, numGasObjects, ignoreGasObjects, logger);
|
|
127
127
|
const pythClient = new pyth_sui_js_1.SuiPythClient(provider, pythStateId, wormholeStateId);
|
|
128
|
-
return new SuiPricePusher(keypair, provider, logger,
|
|
128
|
+
return new SuiPricePusher(keypair, provider, logger, hermesClient, gasBudget, gasPool, pythClient);
|
|
129
129
|
}
|
|
130
130
|
async updatePriceFeed(priceIds, pubTimesToPush) {
|
|
131
131
|
if (priceIds.length === 0) {
|
|
@@ -141,11 +141,13 @@ class SuiPricePusher {
|
|
|
141
141
|
const priceIdChunks = chunkArray(priceIds, 3);
|
|
142
142
|
const txBlocks = [];
|
|
143
143
|
await Promise.all(priceIdChunks.map(async (priceIdChunk) => {
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
const response = await this.hermesClient.getLatestPriceUpdates(priceIdChunk, {
|
|
145
|
+
encoding: "base64",
|
|
146
|
+
});
|
|
147
|
+
if (response.binary.data.length !== 1) {
|
|
148
|
+
throw new Error(`Expected a single VAA for all priceIds ${priceIdChunk} but received ${response.binary.data.length} VAAs: ${response.binary.data}`);
|
|
147
149
|
}
|
|
148
|
-
const vaa =
|
|
150
|
+
const vaa = response.binary.data[0];
|
|
149
151
|
const tx = new transactions_1.Transaction();
|
|
150
152
|
await this.pythClient.updatePriceFeeds(tx, [Buffer.from(vaa, "base64")], priceIdChunk);
|
|
151
153
|
txBlocks.push(tx);
|
package/lib/ton/command.d.ts
CHANGED
package/lib/ton/command.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/ton/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/ton/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;;;;;;;;;;;kBAoBvB,OAAO;4BAKP,OAAO;iCAKP,OAAO;;oBAQiB,GAAG;;AA1BpC,wBAmGE"}
|
package/lib/ton/command.js
CHANGED
|
@@ -28,13 +28,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
const options = __importStar(require("../options"));
|
|
30
30
|
const price_config_1 = require("../price-config");
|
|
31
|
-
const price_service_client_1 = require("@pythnetwork/price-service-client");
|
|
32
31
|
const pyth_price_listener_1 = require("../pyth-price-listener");
|
|
33
32
|
const ton_1 = require("./ton");
|
|
34
33
|
const controller_1 = require("../controller");
|
|
35
34
|
const ton_2 = require("@ton/ton");
|
|
36
35
|
const fs_1 = __importDefault(require("fs"));
|
|
37
36
|
const pino_1 = __importDefault(require("pino"));
|
|
37
|
+
const hermes_client_1 = require("@pythnetwork/hermes-client");
|
|
38
|
+
const utils_1 = require("../utils");
|
|
38
39
|
exports.default = {
|
|
39
40
|
command: "ton",
|
|
40
41
|
describe: "run price pusher for TON",
|
|
@@ -59,24 +60,29 @@ exports.default = {
|
|
|
59
60
|
...options.pushingFrequency,
|
|
60
61
|
...options.pollingFrequency,
|
|
61
62
|
...options.logLevel,
|
|
62
|
-
...options.priceServiceConnectionLogLevel,
|
|
63
63
|
...options.controllerLogLevel,
|
|
64
64
|
},
|
|
65
65
|
handler: async function (argv) {
|
|
66
|
-
const { endpoint, privateKeyFile, pythContractAddress, priceConfigFile, priceServiceEndpoint, pushingFrequency, pollingFrequency, logLevel,
|
|
66
|
+
const { endpoint, privateKeyFile, pythContractAddress, priceConfigFile, priceServiceEndpoint, pushingFrequency, pollingFrequency, logLevel, controllerLogLevel, } = argv;
|
|
67
67
|
const logger = (0, pino_1.default)({ level: logLevel });
|
|
68
68
|
const priceConfigs = (0, price_config_1.readPriceConfigFile)(priceConfigFile);
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
69
|
+
const hermesClient = new hermes_client_1.HermesClient(priceServiceEndpoint);
|
|
70
|
+
let priceItems = priceConfigs.map(({ id, alias }) => ({ id, alias }));
|
|
71
|
+
// Better to filter out invalid price items before creating the pyth listener
|
|
72
|
+
const { existingPriceItems, invalidPriceItems } = await (0, utils_1.filterInvalidPriceItems)(hermesClient, priceItems);
|
|
73
|
+
if (invalidPriceItems.length > 0) {
|
|
74
|
+
logger.error(`Invalid price id submitted for: ${invalidPriceItems
|
|
75
|
+
.map(({ alias }) => alias)
|
|
76
|
+
.join(", ")}`);
|
|
77
|
+
}
|
|
78
|
+
priceItems = existingPriceItems;
|
|
79
|
+
const pythListener = new pyth_price_listener_1.PythPriceListener(hermesClient, priceItems, logger.child({ module: "PythPriceListener" }));
|
|
74
80
|
const client = new ton_2.TonClient({ endpoint });
|
|
75
81
|
const privateKey = fs_1.default.readFileSync(privateKeyFile, "utf8").trim();
|
|
76
82
|
const contractAddress = ton_2.Address.parse(pythContractAddress);
|
|
77
83
|
const provider = client.provider(contractAddress);
|
|
78
84
|
const tonPriceListener = new ton_1.TonPriceListener(provider, contractAddress, priceItems, logger.child({ module: "TonPriceListener" }), { pollingFrequency });
|
|
79
|
-
const tonPricePusher = new ton_1.TonPricePusher(client, privateKey, contractAddress,
|
|
85
|
+
const tonPricePusher = new ton_1.TonPricePusher(client, privateKey, contractAddress, hermesClient, logger.child({ module: "TonPricePusher" }));
|
|
80
86
|
const controller = new controller_1.Controller(priceConfigs, pythListener, tonPriceListener, tonPricePusher, logger.child({ module: "Controller" }, { level: controllerLogLevel }), { pushingFrequency });
|
|
81
87
|
await controller.start();
|
|
82
88
|
},
|
package/lib/ton/ton.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HermesClient } from "@pythnetwork/hermes-client";
|
|
2
2
|
import { ChainPriceListener, IPricePusher, PriceInfo, PriceItem } from "../interface";
|
|
3
3
|
import { DurationInSeconds } from "../utils";
|
|
4
4
|
import { Logger } from "pino";
|
|
@@ -17,11 +17,11 @@ export declare class TonPricePusher implements IPricePusher {
|
|
|
17
17
|
private client;
|
|
18
18
|
private privateKey;
|
|
19
19
|
private contractAddress;
|
|
20
|
-
private
|
|
20
|
+
private hermesClient;
|
|
21
21
|
private logger;
|
|
22
22
|
private contract;
|
|
23
23
|
private sender;
|
|
24
|
-
constructor(client: TonClient, privateKey: string, contractAddress: Address,
|
|
24
|
+
constructor(client: TonClient, privateKey: string, contractAddress: Address, hermesClient: HermesClient, logger: Logger);
|
|
25
25
|
updatePriceFeed(priceIds: string[], pubTimesToPush: number[]): Promise<void>;
|
|
26
26
|
}
|
|
27
27
|
//# sourceMappingURL=ton.d.ts.map
|
package/lib/ton/ton.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ton.d.ts","sourceRoot":"","sources":["../../src/ton/ton.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ton.d.ts","sourceRoot":"","sources":["../../src/ton/ton.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,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;
|
|
45
45
|
contract;
|
|
46
46
|
sender;
|
|
47
|
-
constructor(client, privateKey, contractAddress,
|
|
47
|
+
constructor(client, privateKey, contractAddress, hermesClient, logger) {
|
|
48
48
|
this.client = client;
|
|
49
49
|
this.privateKey = privateKey;
|
|
50
50
|
this.contractAddress = contractAddress;
|
|
51
|
-
this.
|
|
51
|
+
this.hermesClient = hermesClient;
|
|
52
52
|
this.logger = logger;
|
|
53
53
|
this.contract = this.client
|
|
54
54
|
.provider(this.contractAddress)
|
|
@@ -69,7 +69,10 @@ class TonPricePusher {
|
|
|
69
69
|
}
|
|
70
70
|
let priceFeedUpdateData;
|
|
71
71
|
try {
|
|
72
|
-
|
|
72
|
+
const response = await this.hermesClient.getLatestPriceUpdates(priceIds, {
|
|
73
|
+
encoding: "base64",
|
|
74
|
+
});
|
|
75
|
+
priceFeedUpdateData = response.binary.data;
|
|
73
76
|
}
|
|
74
77
|
catch (err) {
|
|
75
78
|
this.logger.error(err, "getPriceFeedsUpdateData failed");
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { HexString } from "@pythnetwork/
|
|
1
|
+
import { HermesClient, HexString } from "@pythnetwork/hermes-client";
|
|
2
|
+
import { PriceItem } from "./interface";
|
|
2
3
|
export type PctNumber = number;
|
|
3
4
|
export type DurationInSeconds = number;
|
|
4
5
|
export declare const txSpeeds: readonly ["slow", "standard", "fast"];
|
|
@@ -11,4 +12,8 @@ export declare const addLeading0x: (id: HexString) => `0x${string}`;
|
|
|
11
12
|
export declare function isWsEndpoint(endpoint: string): boolean;
|
|
12
13
|
export declare function verifyValidOption<options extends Readonly<Array<any>>, validOption extends options[number]>(option: any, validOptions: options): validOption;
|
|
13
14
|
export declare const assertDefined: <T>(value: T | undefined) => T;
|
|
15
|
+
export declare function filterInvalidPriceItems(hermesClient: HermesClient, priceItems: PriceItem[]): Promise<{
|
|
16
|
+
existingPriceItems: PriceItem[];
|
|
17
|
+
invalidPriceItems: PriceItem[];
|
|
18
|
+
}>;
|
|
14
19
|
//# sourceMappingURL=utils.d.ts.map
|
package/lib/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAC/B,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC;AACvC,eAAO,MAAM,QAAQ,uCAAwC,CAAC;AAC9D,MAAM,MAAM,OAAO,GAAG,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC9C,eAAO,MAAM,iBAAiB,gBAAiB,CAAC;AAChD,MAAM,MAAM,gBAAgB,GAAG,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC;AAEhE,wBAAsB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAErD;AAED,wBAAgB,eAAe,CAAC,EAAE,EAAE,SAAS,GAAG,SAAS,CAKxD;AAED,eAAO,MAAM,YAAY,OAAQ,SAAS,KAAG,KAAK,MAAM,EACrB,CAAC;AAKpC,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAStD;AAED,wBAAgB,iBAAiB,CAC/B,OAAO,SAAS,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EACpC,WAAW,SAAS,OAAO,CAAC,MAAM,CAAC,EACnC,MAAM,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,GAEf,WAAW,CAK/B;AAED,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,CAAC,GAAG,SAAS,KAAG,CAMvD,CAAC;AAEF,wBAAsB,uBAAuB,CAC3C,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,SAAS,EAAE,GACtB,OAAO,CAAC;IACT,kBAAkB,EAAE,SAAS,EAAE,CAAC;IAChC,iBAAiB,EAAE,SAAS,EAAE,CAAC;CAChC,CAAC,CAqBD"}
|
package/lib/utils.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.sleep = sleep;
|
|
|
5
5
|
exports.removeLeading0x = removeLeading0x;
|
|
6
6
|
exports.isWsEndpoint = isWsEndpoint;
|
|
7
7
|
exports.verifyValidOption = verifyValidOption;
|
|
8
|
+
exports.filterInvalidPriceItems = filterInvalidPriceItems;
|
|
8
9
|
exports.txSpeeds = ["slow", "standard", "fast"];
|
|
9
10
|
exports.customGasChainIds = [137];
|
|
10
11
|
async function sleep(ms) {
|
|
@@ -43,3 +44,18 @@ const assertDefined = (value) => {
|
|
|
43
44
|
}
|
|
44
45
|
};
|
|
45
46
|
exports.assertDefined = assertDefined;
|
|
47
|
+
async function filterInvalidPriceItems(hermesClient, priceItems) {
|
|
48
|
+
const priceMetadata = await hermesClient.getPriceFeeds();
|
|
49
|
+
const allPriceIds = priceMetadata.map((priceMetadata) => priceMetadata.id);
|
|
50
|
+
// Filter out invalid price ids
|
|
51
|
+
const { existingPriceItems, invalidPriceItems } = priceItems.reduce((acc, item) => {
|
|
52
|
+
if (allPriceIds.includes(item.id)) {
|
|
53
|
+
acc.existingPriceItems.push(item);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
acc.invalidPriceItems.push(item);
|
|
57
|
+
}
|
|
58
|
+
return acc;
|
|
59
|
+
}, { existingPriceItems: [], invalidPriceItems: [] });
|
|
60
|
+
return { existingPriceItems, invalidPriceItems };
|
|
61
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pythnetwork/price-pusher",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "Pyth Price Pusher",
|
|
5
5
|
"homepage": "https://pyth.network",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
25
25
|
"test:lint": "eslint src/",
|
|
26
26
|
"start": "node lib/index.js",
|
|
27
|
-
"test": "jest",
|
|
28
27
|
"dev": "ts-node src/index.ts",
|
|
29
28
|
"prepublishOnly": "pnpm run build && pnpm run test:lint",
|
|
30
29
|
"preversion": "pnpm run test:lint",
|
|
@@ -61,14 +60,14 @@
|
|
|
61
60
|
"@injectivelabs/networks": "^1.14.6",
|
|
62
61
|
"@injectivelabs/sdk-ts": "1.10.72",
|
|
63
62
|
"@mysten/sui": "^1.3.0",
|
|
64
|
-
"@pythnetwork/
|
|
63
|
+
"@pythnetwork/hermes-client": "^1.3.1",
|
|
65
64
|
"@pythnetwork/price-service-sdk": "^1.8.0",
|
|
66
65
|
"@pythnetwork/pyth-fuel-js": "1.0.7",
|
|
67
66
|
"@pythnetwork/pyth-sdk-solidity": "4.0.0",
|
|
68
67
|
"@pythnetwork/pyth-solana-receiver": "0.9.1",
|
|
69
68
|
"@pythnetwork/pyth-sui-js": "2.1.0",
|
|
70
69
|
"@pythnetwork/pyth-ton-js": "0.1.2",
|
|
71
|
-
"@pythnetwork/solana-utils": "0.4.
|
|
70
|
+
"@pythnetwork/solana-utils": "0.4.4",
|
|
72
71
|
"@solana/web3.js": "^1.93.0",
|
|
73
72
|
"@ton/crypto": "^3.3.0",
|
|
74
73
|
"@ton/ton": "^15.1.0",
|
|
@@ -83,5 +82,5 @@
|
|
|
83
82
|
"yaml": "^2.1.1",
|
|
84
83
|
"yargs": "^17.5.1"
|
|
85
84
|
},
|
|
86
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "f5c4b3df87829b926d59a5058be74917eec05b90"
|
|
87
86
|
}
|