@pythnetwork/price-pusher 6.8.0 → 7.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.
Files changed (56) hide show
  1. package/README.md +26 -14
  2. package/lib/aptos/aptos.d.ts +5 -2
  3. package/lib/aptos/aptos.d.ts.map +1 -1
  4. package/lib/aptos/aptos.js +31 -31
  5. package/lib/aptos/command.d.ts +3 -0
  6. package/lib/aptos/command.d.ts.map +1 -1
  7. package/lib/aptos/command.js +12 -14
  8. package/lib/controller.d.ts +3 -1
  9. package/lib/controller.d.ts.map +1 -1
  10. package/lib/controller.js +11 -4
  11. package/lib/evm/command.d.ts +3 -0
  12. package/lib/evm/command.d.ts.map +1 -1
  13. package/lib/evm/command.js +14 -16
  14. package/lib/evm/custom-gas-station.d.ts +4 -2
  15. package/lib/evm/custom-gas-station.d.ts.map +1 -1
  16. package/lib/evm/custom-gas-station.js +7 -6
  17. package/lib/evm/evm.d.ts +7 -3
  18. package/lib/evm/evm.d.ts.map +1 -1
  19. package/lib/evm/evm.js +25 -24
  20. package/lib/injective/command.d.ts +3 -0
  21. package/lib/injective/command.d.ts.map +1 -1
  22. package/lib/injective/command.js +11 -13
  23. package/lib/injective/injective.d.ts +5 -2
  24. package/lib/injective/injective.d.ts.map +1 -1
  25. package/lib/injective/injective.js +24 -23
  26. package/lib/interface.d.ts +1 -2
  27. package/lib/interface.d.ts.map +1 -1
  28. package/lib/interface.js +1 -4
  29. package/lib/near/command.d.ts +3 -0
  30. package/lib/near/command.d.ts.map +1 -1
  31. package/lib/near/command.js +14 -13
  32. package/lib/near/near.d.ts +5 -2
  33. package/lib/near/near.d.ts.map +1 -1
  34. package/lib/near/near.js +19 -17
  35. package/lib/options.d.ts +9 -0
  36. package/lib/options.d.ts.map +1 -1
  37. package/lib/options.js +28 -1
  38. package/lib/price-config.d.ts +2 -1
  39. package/lib/price-config.d.ts.map +1 -1
  40. package/lib/price-config.js +4 -6
  41. package/lib/pyth-price-listener.d.ts +4 -1
  42. package/lib/pyth-price-listener.d.ts.map +1 -1
  43. package/lib/pyth-price-listener.js +14 -2
  44. package/lib/solana/command.d.ts +5 -1
  45. package/lib/solana/command.d.ts.map +1 -1
  46. package/lib/solana/command.js +16 -18
  47. package/lib/solana/solana.d.ts +11 -5
  48. package/lib/solana/solana.d.ts.map +1 -1
  49. package/lib/solana/solana.js +41 -18
  50. package/lib/sui/command.d.ts +3 -0
  51. package/lib/sui/command.d.ts.map +1 -1
  52. package/lib/sui/command.js +12 -14
  53. package/lib/sui/sui.d.ts +6 -7
  54. package/lib/sui/sui.d.ts.map +1 -1
  55. package/lib/sui/sui.js +42 -63
  56. package/package.json +21 -11
package/lib/evm/evm.js CHANGED
@@ -13,20 +13,22 @@ const utils_2 = require("../utils");
13
13
  class EvmPriceListener extends interface_1.ChainPriceListener {
14
14
  pythContractFactory;
15
15
  pythContract;
16
- constructor(pythContractFactory, priceItems, config) {
17
- super("Evm", config.pollingFrequency, priceItems);
16
+ logger;
17
+ constructor(pythContractFactory, priceItems, logger, config) {
18
+ super(config.pollingFrequency, priceItems);
18
19
  this.pythContractFactory = pythContractFactory;
19
20
  this.pythContract = this.pythContractFactory.createPythContract();
21
+ this.logger = logger;
20
22
  }
21
23
  // This method should be awaited on and once it finishes it has the latest value
22
24
  // for the given price feeds (if they exist).
23
25
  async start() {
24
26
  if (this.pythContractFactory.hasWebsocketProvider()) {
25
- console.log("Subscribing to the target network pyth contract events...");
27
+ this.logger.info("Subscribing to the target network pyth contract events...");
26
28
  this.startSubscription();
27
29
  }
28
30
  else {
29
- console.log("The target network RPC endpoint is not Websocket. " +
31
+ this.logger.info("The target network RPC endpoint is not Websocket. " +
30
32
  "Listening for updates only via polling....");
31
33
  }
32
34
  // base class for polling
@@ -44,11 +46,11 @@ class EvmPriceListener extends interface_1.ChainPriceListener {
44
46
  }
45
47
  onPriceFeedUpdate(err, event) {
46
48
  if (err !== null) {
47
- console.error("PriceFeedUpdate EventEmitter received an error..");
49
+ this.logger.error(err, "PriceFeedUpdate EventEmitter received an error..");
48
50
  throw err;
49
51
  }
50
52
  const priceId = (0, utils_1.removeLeading0x)(event.returnValues.id);
51
- console.log(`Received a new Evm PriceFeedUpdate event for price feed ${this.priceIdToAlias.get(priceId)} (${priceId}).`);
53
+ this.logger.debug(`Received a new Evm PriceFeedUpdate event for price feed ${this.priceIdToAlias.get(priceId)} (${priceId}).`);
52
54
  const priceInfo = {
53
55
  conf: event.returnValues.conf,
54
56
  price: event.returnValues.price,
@@ -63,12 +65,11 @@ class EvmPriceListener extends interface_1.ChainPriceListener {
63
65
  .getPriceUnsafe((0, utils_1.addLeading0x)(priceId))
64
66
  .call();
65
67
  }
66
- catch (e) {
67
- console.error(`Polling on-chain price for ${priceId} failed. Error:`);
68
- console.error(e);
68
+ catch (err) {
69
+ this.logger.error(err, `Polling on-chain price for ${priceId} failed.`);
69
70
  return undefined;
70
71
  }
71
- console.log(`Polled an EVM on chain price for feed ${this.priceIdToAlias.get(priceId)} (${priceId}).`);
72
+ this.logger.debug(`Polled an EVM on chain price for feed ${this.priceIdToAlias.get(priceId)} (${priceId}).`);
72
73
  return {
73
74
  conf: priceRaw.conf,
74
75
  price: priceRaw.price,
@@ -79,6 +80,7 @@ class EvmPriceListener extends interface_1.ChainPriceListener {
79
80
  exports.EvmPriceListener = EvmPriceListener;
80
81
  class EvmPricePusher {
81
82
  connection;
83
+ logger;
82
84
  overrideGasPriceMultiplier;
83
85
  overrideGasPriceMultiplierCap;
84
86
  updateFeeMultiplier;
@@ -88,8 +90,9 @@ class EvmPricePusher {
88
90
  web3;
89
91
  pusherAddress;
90
92
  lastPushAttempt;
91
- constructor(connection, pythContractFactory, overrideGasPriceMultiplier, overrideGasPriceMultiplierCap, updateFeeMultiplier, gasLimit, customGasStation) {
93
+ constructor(connection, pythContractFactory, logger, overrideGasPriceMultiplier, overrideGasPriceMultiplierCap, updateFeeMultiplier, gasLimit, customGasStation) {
92
94
  this.connection = connection;
95
+ this.logger = logger;
93
96
  this.overrideGasPriceMultiplier = overrideGasPriceMultiplier;
94
97
  this.overrideGasPriceMultiplierCap = overrideGasPriceMultiplierCap;
95
98
  this.updateFeeMultiplier = updateFeeMultiplier;
@@ -112,17 +115,16 @@ class EvmPricePusher {
112
115
  throw new Error("Invalid arguments");
113
116
  const priceIdsWith0x = priceIds.map((priceId) => (0, utils_1.addLeading0x)(priceId));
114
117
  const priceFeedUpdateData = await this.getPriceFeedsUpdateData(priceIdsWith0x);
115
- console.log("Pushing ", priceIdsWith0x);
116
118
  let updateFee;
117
119
  try {
118
120
  updateFee = await this.pythContract.methods
119
121
  .getUpdateFee(priceFeedUpdateData)
120
122
  .call();
121
123
  updateFee = Number(updateFee) * (this.updateFeeMultiplier || 1);
122
- console.log(`Update fee: ${updateFee}`);
124
+ this.logger.debug(`Update fee: ${updateFee}`);
123
125
  }
124
126
  catch (e) {
125
- console.error("An unidentified error has occured when getting the update fee:");
127
+ this.logger.error(e, "An unidentified error has occured when getting the update fee.");
126
128
  throw e;
127
129
  }
128
130
  let gasPrice = Number((await this.customGasStation?.getCustomGasPrice()) ||
@@ -145,7 +147,7 @@ class EvmPricePusher {
145
147
  gasPrice = Math.min(gasPriceToOverride, gasPrice * this.overrideGasPriceMultiplierCap);
146
148
  }
147
149
  const txNonce = lastExecutedNonce + 1;
148
- console.log(`Using gas price: ${gasPrice} and nonce: ${txNonce}`);
150
+ this.logger.debug(`Using gas price: ${gasPrice} and nonce: ${txNonce}`);
149
151
  this.pythContract.methods
150
152
  .updatePriceFeedsIfNecessary(priceFeedUpdateData, priceIdsWith0x, pubTimesToPush)
151
153
  .send({
@@ -155,7 +157,7 @@ class EvmPricePusher {
155
157
  gasLimit: this.gasLimit,
156
158
  })
157
159
  .on("transactionHash", (hash) => {
158
- console.log(`Successful. Tx hash: ${hash}`);
160
+ this.logger.info({ hash }, "Price update successful");
159
161
  })
160
162
  .on("error", (err, receipt) => {
161
163
  if (err.message.includes("revert")) {
@@ -163,14 +165,14 @@ class EvmPricePusher {
163
165
  // doesn't return any information why the call has reverted. Assuming that
164
166
  // the update data is valid there is no possible rejection cause other than
165
167
  // the target chain price being already updated.
166
- console.log("Execution reverted. With high probability, the target chain price " +
168
+ this.logger.info({ err, receipt }, "Execution reverted. With high probability, the target chain price " +
167
169
  "has already updated, Skipping this push.");
168
170
  return;
169
171
  }
170
172
  if (err.message.includes("the tx doesn't have the correct nonce.") ||
171
173
  err.message.includes("nonce too low") ||
172
174
  err.message.includes("invalid nonce")) {
173
- console.log("The nonce is incorrect (are multiple users using this account?). Skipping this push.");
175
+ this.logger.info({ err, receipt }, "The nonce is incorrect (are multiple users using this account?). Skipping this push.");
174
176
  return;
175
177
  }
176
178
  if (err.message.includes("max fee per gas less than block base fee")) {
@@ -178,25 +180,24 @@ class EvmPricePusher {
178
180
  // LastPushAttempt was stored with the class
179
181
  // Next time the update will be executing, it will check the last attempt
180
182
  // and increase the gas price accordingly.
181
- console.log("The transaction failed with error: max fee per gas less than block base fee ");
183
+ this.logger.info({ err, receipt }, "The transaction failed with error: max fee per gas less than block base fee ");
182
184
  return;
183
185
  }
184
186
  if (err.message.includes("sender doesn't have enough funds to send tx.")) {
185
- console.error("Payer is out of balance, please top it up.");
187
+ this.logger.error({ err, receipt }, "Payer is out of balance, please top it up.");
186
188
  throw err;
187
189
  }
188
190
  if (err.message.includes("transaction underpriced")) {
189
- console.error("The gas price of the transaction is too low. Skipping this push. " +
191
+ this.logger.error({ err, receipt }, "The gas price of the transaction is too low. Skipping this push. " +
190
192
  "You might want to use a custom gas station or increase the override gas price " +
191
193
  "multiplier to increase the likelihood of the transaction landing on-chain.");
192
194
  return;
193
195
  }
194
196
  if (err.message.includes("could not replace existing tx")) {
195
- console.log("A transaction with the same nonce has been mined and this one is no longer needed.");
197
+ this.logger.error({ err, receipt }, "A transaction with the same nonce has been mined and this one is no longer needed.");
196
198
  return;
197
199
  }
198
- console.error("An unidentified error has occured:");
199
- console.error(receipt);
200
+ this.logger.error({ err, receipt }, "An unidentified error has occured.");
200
201
  throw err;
201
202
  });
202
203
  // Update lastAttempt
@@ -3,6 +3,9 @@ declare const _default: {
3
3
  command: string;
4
4
  describe: string;
5
5
  builder: {
6
+ "controller-log-level": Options;
7
+ "price-service-connection-log-level": Options;
8
+ "log-level": Options;
6
9
  "pushing-frequency": Options;
7
10
  "polling-frequency": Options;
8
11
  "pyth-contract-address": Options;
@@ -1 +1 @@
1
- {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/injective/command.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;;;;;;;;;;;;;;;oBA+BL,GAAG;;AA5B9B,wBAkGE"}
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/injective/command.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;;;;;;;;;;;;;;;;;;oBAmCL,GAAG;;AA/B9B,wBA0GE"}
@@ -34,6 +34,7 @@ const injective_1 = require("./injective");
34
34
  const pyth_price_listener_1 = require("../pyth-price-listener");
35
35
  const controller_1 = require("../controller");
36
36
  const networks_1 = require("@injectivelabs/networks");
37
+ const pino_1 = __importDefault(require("pino"));
37
38
  exports.default = {
38
39
  command: "injective",
39
40
  describe: "run price pusher for injective",
@@ -60,35 +61,32 @@ exports.default = {
60
61
  ...options.pythContractAddress,
61
62
  ...options.pollingFrequency,
62
63
  ...options.pushingFrequency,
64
+ ...options.logLevel,
65
+ ...options.priceServiceConnectionLogLevel,
66
+ ...options.controllerLogLevel,
63
67
  },
64
68
  handler: function (argv) {
65
69
  // FIXME: type checks for this
66
- const { gasPrice, grpcEndpoint, priceConfigFile, priceServiceEndpoint, mnemonicFile, pythContractAddress, pushingFrequency, pollingFrequency, network, } = argv;
70
+ const { gasPrice, grpcEndpoint, priceConfigFile, priceServiceEndpoint, mnemonicFile, pythContractAddress, pushingFrequency, pollingFrequency, network, logLevel, priceServiceConnectionLogLevel, controllerLogLevel, } = argv;
71
+ const logger = (0, pino_1.default)({ level: logLevel });
67
72
  if (network !== "testnet" && network !== "mainnet") {
68
73
  throw new Error("Please specify network. One of [testnet, mainnet]");
69
74
  }
70
75
  const priceConfigs = (0, price_config_1.readPriceConfigFile)(priceConfigFile);
71
76
  const priceServiceConnection = new price_service_client_1.PriceServiceConnection(priceServiceEndpoint, {
72
- logger: {
73
- // Log only warnings and errors from the price service client
74
- info: () => undefined,
75
- warn: console.warn,
76
- error: console.error,
77
- debug: () => undefined,
78
- trace: () => undefined,
79
- },
77
+ logger: logger.child({ module: "PriceServiceConnection" }, { level: priceServiceConnectionLogLevel }),
80
78
  });
81
79
  const mnemonic = fs_1.default.readFileSync(mnemonicFile, "utf-8").trim();
82
80
  const priceItems = priceConfigs.map(({ id, alias }) => ({ id, alias }));
83
- const pythListener = new pyth_price_listener_1.PythPriceListener(priceServiceConnection, priceItems);
84
- const injectiveListener = new injective_1.InjectivePriceListener(pythContractAddress, grpcEndpoint, priceItems, {
81
+ const pythListener = new pyth_price_listener_1.PythPriceListener(priceServiceConnection, priceItems, logger.child({ module: "PythPriceListener" }));
82
+ const injectiveListener = new injective_1.InjectivePriceListener(pythContractAddress, grpcEndpoint, priceItems, logger.child({ module: "InjectivePriceListener" }), {
85
83
  pollingFrequency,
86
84
  });
87
- const injectivePusher = new injective_1.InjectivePricePusher(priceServiceConnection, pythContractAddress, grpcEndpoint, mnemonic, {
85
+ const injectivePusher = new injective_1.InjectivePricePusher(priceServiceConnection, pythContractAddress, grpcEndpoint, logger.child({ module: "InjectivePricePusher" }), mnemonic, {
88
86
  chainId: (0, networks_1.getNetworkInfo)(network).chainId,
89
87
  gasPrice,
90
88
  });
91
- const controller = new controller_1.Controller(priceConfigs, pythListener, injectiveListener, injectivePusher, { pushingFrequency });
89
+ const controller = new controller_1.Controller(priceConfigs, pythListener, injectiveListener, injectivePusher, logger.child({ module: "Controller" }, { level: controllerLogLevel }), { pushingFrequency });
92
90
  controller.start();
93
91
  },
94
92
  };
@@ -1,10 +1,12 @@
1
1
  import { HexString, PriceServiceConnection } from "@pythnetwork/price-service-client";
2
2
  import { IPricePusher, PriceInfo, ChainPriceListener, PriceItem } from "../interface";
3
3
  import { DurationInSeconds } from "../utils";
4
+ import { Logger } from "pino";
4
5
  export declare class InjectivePriceListener extends ChainPriceListener {
5
6
  private pythContractAddress;
6
7
  private grpcEndpoint;
7
- constructor(pythContractAddress: string, grpcEndpoint: string, priceItems: PriceItem[], config: {
8
+ private logger;
9
+ constructor(pythContractAddress: string, grpcEndpoint: string, priceItems: PriceItem[], logger: Logger, config: {
8
10
  pollingFrequency: DurationInSeconds;
9
11
  });
10
12
  getOnChainPriceInfo(priceId: HexString): Promise<PriceInfo | undefined>;
@@ -18,10 +20,11 @@ export declare class InjectivePricePusher implements IPricePusher {
18
20
  private priceServiceConnection;
19
21
  private pythContractAddress;
20
22
  private grpcEndpoint;
23
+ private logger;
21
24
  private wallet;
22
25
  private chainConfig;
23
26
  private account;
24
- constructor(priceServiceConnection: PriceServiceConnection, pythContractAddress: string, grpcEndpoint: string, mnemonic: string, chainConfig?: Partial<InjectiveConfig>);
27
+ constructor(priceServiceConnection: PriceServiceConnection, pythContractAddress: string, grpcEndpoint: string, logger: Logger, mnemonic: string, chainConfig?: Partial<InjectiveConfig>);
25
28
  private injectiveAddress;
26
29
  private signAndBroadcastMsg;
27
30
  getPriceFeedUpdateObject(priceIds: string[]): Promise<any>;
@@ -1 +1 @@
1
- {"version":3,"file":"injective.d.ts","sourceRoot":"","sources":["../../src/injective/injective.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,sBAAsB,EACvB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,SAAS,EACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAiC7C,qBAAa,sBAAuB,SAAQ,kBAAkB;IAE1D,OAAO,CA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@ -8,10 +8,12 @@ const DEFAULT_GAS_PRICE = 500000000;
8
8
  class InjectivePriceListener extends interface_1.ChainPriceListener {
9
9
  pythContractAddress;
10
10
  grpcEndpoint;
11
- constructor(pythContractAddress, grpcEndpoint, priceItems, config) {
12
- super("Injective", config.pollingFrequency, priceItems);
11
+ logger;
12
+ constructor(pythContractAddress, grpcEndpoint, priceItems, logger, config) {
13
+ super(config.pollingFrequency, priceItems);
13
14
  this.pythContractAddress = pythContractAddress;
14
15
  this.grpcEndpoint = grpcEndpoint;
16
+ this.logger = logger;
15
17
  }
16
18
  async getOnChainPriceInfo(priceId) {
17
19
  let priceQueryResponse;
@@ -21,12 +23,11 @@ class InjectivePriceListener extends interface_1.ChainPriceListener {
21
23
  const json = Buffer.from(data).toString();
22
24
  priceQueryResponse = JSON.parse(json);
23
25
  }
24
- catch (e) {
25
- console.error(`Polling on-chain price for ${priceId} failed. Error:`);
26
- console.error(e);
26
+ catch (err) {
27
+ this.logger.error(err, `Polling on-chain price for ${priceId} failed.`);
27
28
  return undefined;
28
29
  }
29
- console.log(`Polled an Injective on chain price for feed ${this.priceIdToAlias.get(priceId)} (${priceId}).`);
30
+ this.logger.debug(`Polled an Injective on chain price for feed ${this.priceIdToAlias.get(priceId)} (${priceId}).`);
30
31
  return {
31
32
  conf: priceQueryResponse.price_feed.price.conf,
32
33
  price: priceQueryResponse.price_feed.price.price,
@@ -39,13 +40,15 @@ class InjectivePricePusher {
39
40
  priceServiceConnection;
40
41
  pythContractAddress;
41
42
  grpcEndpoint;
43
+ logger;
42
44
  wallet;
43
45
  chainConfig;
44
46
  account = null;
45
- constructor(priceServiceConnection, pythContractAddress, grpcEndpoint, mnemonic, chainConfig) {
47
+ constructor(priceServiceConnection, pythContractAddress, grpcEndpoint, logger, mnemonic, chainConfig) {
46
48
  this.priceServiceConnection = priceServiceConnection;
47
49
  this.pythContractAddress = pythContractAddress;
48
50
  this.grpcEndpoint = grpcEndpoint;
51
+ this.logger = logger;
49
52
  this.wallet = sdk_ts_1.PrivateKey.fromMnemonic(mnemonic);
50
53
  this.chainConfig = {
51
54
  chainId: chainConfig?.chainId ?? "injective-888",
@@ -129,9 +132,8 @@ class InjectivePricePusher {
129
132
  // get the latest VAAs for updatePriceFeed and then push them
130
133
  priceFeedUpdateObject = await this.getPriceFeedUpdateObject(priceIds);
131
134
  }
132
- catch (e) {
133
- console.error("Error fetching the latest vaas to push");
134
- console.error(e);
135
+ catch (err) {
136
+ this.logger.error(err, "Error fetching the latest vaas to push");
135
137
  return;
136
138
  }
137
139
  let updateFeeQueryResponse;
@@ -145,10 +147,10 @@ class InjectivePricePusher {
145
147
  const json = Buffer.from(data).toString();
146
148
  updateFeeQueryResponse = JSON.parse(json);
147
149
  }
148
- catch (e) {
149
- console.error("Error fetching update fee");
150
- console.error(e);
151
- return;
150
+ catch (err) {
151
+ this.logger.error(err, "Error fetching update fee");
152
+ // Throwing an error because it is likely an RPC issue
153
+ throw err;
152
154
  }
153
155
  try {
154
156
  const executeMsg = sdk_ts_1.MsgExecuteContract.fromJSON({
@@ -158,20 +160,19 @@ class InjectivePricePusher {
158
160
  funds: [updateFeeQueryResponse],
159
161
  });
160
162
  const rs = await this.signAndBroadcastMsg(executeMsg);
161
- console.log("Succesfully broadcasted txHash:", rs.txHash);
163
+ this.logger.info({ hash: rs.txHash }, "Succesfully broadcasted txHash");
162
164
  }
163
- catch (e) {
164
- if (e.message.match(/account inj[a-zA-Z0-9]+ not found/) !== null) {
165
- console.error(e);
165
+ catch (err) {
166
+ if (err.message.match(/account inj[a-zA-Z0-9]+ not found/) !== null) {
167
+ this.logger.error(err, "Account not found");
166
168
  throw new Error("Please check the mnemonic");
167
169
  }
168
- if (e.message.match(/insufficient/) !== null &&
169
- e.message.match(/funds/) !== null) {
170
- console.error(e);
170
+ if (err.message.match(/insufficient/) !== null &&
171
+ err.message.match(/funds/) !== null) {
172
+ this.logger.error(err, "Insufficient funds");
171
173
  throw new Error("Insufficient funds");
172
174
  }
173
- console.error("Error executing messages");
174
- console.log(e);
175
+ this.logger.error(err, "Error executing messages");
175
176
  }
176
177
  }
177
178
  }
@@ -14,12 +14,11 @@ export interface IPriceListener {
14
14
  getLatestPriceInfo(priceId: string): PriceInfo | undefined;
15
15
  }
16
16
  export declare abstract class ChainPriceListener implements IPriceListener {
17
- private chain;
18
17
  private pollingFrequency;
19
18
  protected priceItems: PriceItem[];
20
19
  private latestPriceInfo;
21
20
  protected priceIdToAlias: Map<HexString, string>;
22
- constructor(chain: string, pollingFrequency: DurationInSeconds, priceItems: PriceItem[]);
21
+ constructor(pollingFrequency: DurationInSeconds, priceItems: PriceItem[]);
23
22
  start(): Promise<void>;
24
23
  private pollPrices;
25
24
  protected updateLatestPriceInfo(priceId: HexString, observedPrice: PriceInfo): void;
@@ -1 +1 @@
1
- {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE5C,MAAM,MAAM,SAAS,GAAG;IACtB,EAAE,EAAE,SAAS,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,aAAa,CAAC;CAC5B,CAAC;AAEF,MAAM,WAAW,cAAc;IAE7B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;CAC5D;AAED,8BAAsB,kBAAmB,YAAW,cAAc;IAK9D,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,gBAAgB;IACxB,SAAS,CAAC,UAAU,EAAE,SAAS,EAAE;IANnC,OAAO,CAAC,eAAe,CAA4B;IACnD,SAAS,CAAC,cA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AAe,CAA4B;IACnD,SAAS,CAAC,cAAc,EAAE,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;gBAGvC,gBAAgB,EAAE,iBAAiB,EACjC,UAAU,EAAE,SAAS,EAAE;IAQ7B,KAAK;YAMG,UAAU;IASxB,SAAS,CAAC,qBAAqB,CAC7B,OAAO,EAAE,SAAS,EAClB,aAAa,EAAE,SAAS;IAkB1B,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IAI1D,QAAQ,CAAC,mBAAmB,CAC1B,OAAO,EAAE,SAAS,GACjB,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;CAClC;AAED,MAAM,WAAW,YAAY;IAC3B,eAAe,CACb,QAAQ,EAAE,MAAM,EAAE,EAClB,cAAc,EAAE,aAAa,EAAE,GAC9B,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB"}
package/lib/interface.js CHANGED
@@ -2,20 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ChainPriceListener = void 0;
4
4
  class ChainPriceListener {
5
- chain;
6
5
  pollingFrequency;
7
6
  priceItems;
8
7
  latestPriceInfo;
9
8
  priceIdToAlias;
10
- constructor(chain, pollingFrequency, priceItems) {
11
- this.chain = chain;
9
+ constructor(pollingFrequency, priceItems) {
12
10
  this.pollingFrequency = pollingFrequency;
13
11
  this.priceItems = priceItems;
14
12
  this.latestPriceInfo = new Map();
15
13
  this.priceIdToAlias = new Map(priceItems.map(({ id, alias }) => [id, alias]));
16
14
  }
17
15
  async start() {
18
- console.log(`Polling the prices on ${this.chain} every ${this.pollingFrequency} seconds...`);
19
16
  setInterval(this.pollPrices.bind(this), this.pollingFrequency * 1000);
20
17
  await this.pollPrices();
21
18
  }
@@ -3,6 +3,9 @@ declare const _default: {
3
3
  command: string;
4
4
  describe: string;
5
5
  builder: {
6
+ "controller-log-level": Options;
7
+ "price-service-connection-log-level": Options;
8
+ "log-level": Options;
6
9
  "pushing-frequency": Options;
7
10
  "polling-frequency": Options;
8
11
  "pyth-contract-address": Options;
@@ -1 +1 @@
1
- {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/near/command.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;;;;;;;;;;;;;;;oBAkCL,GAAG;;AA/B9B,wBA2FE"}
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/near/command.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;;;;;;;;;;;;;;;;;;oBAsCL,GAAG;;AAlC9B,wBA0GE"}
@@ -22,6 +22,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
29
  const price_service_client_1 = require("@pythnetwork/price-service-client");
27
30
  const options = __importStar(require("../options"));
@@ -29,6 +32,7 @@ const price_config_1 = require("../price-config");
29
32
  const pyth_price_listener_1 = require("../pyth-price-listener");
30
33
  const controller_1 = require("../controller");
31
34
  const near_1 = require("./near");
35
+ const pino_1 = __importDefault(require("pino"));
32
36
  exports.default = {
33
37
  command: "near",
34
38
  describe: "run price pusher for near",
@@ -58,29 +62,26 @@ exports.default = {
58
62
  ...options.pythContractAddress,
59
63
  ...options.pollingFrequency,
60
64
  ...options.pushingFrequency,
65
+ ...options.logLevel,
66
+ ...options.priceServiceConnectionLogLevel,
67
+ ...options.controllerLogLevel,
61
68
  },
62
69
  handler: function (argv) {
63
70
  // FIXME: type checks for this
64
- const { nodeUrl, network, accountId, privateKeyPath, priceConfigFile, priceServiceEndpoint, pythContractAddress, pushingFrequency, pollingFrequency, } = argv;
71
+ const { nodeUrl, network, accountId, privateKeyPath, priceConfigFile, priceServiceEndpoint, pythContractAddress, pushingFrequency, pollingFrequency, logLevel, priceServiceConnectionLogLevel, controllerLogLevel, } = argv;
72
+ const logger = (0, pino_1.default)({ level: logLevel });
65
73
  const priceConfigs = (0, price_config_1.readPriceConfigFile)(priceConfigFile);
66
74
  const priceServiceConnection = new price_service_client_1.PriceServiceConnection(priceServiceEndpoint, {
67
- logger: {
68
- // Log only warnings and errors from the price service client
69
- info: () => undefined,
70
- warn: console.warn,
71
- error: console.error,
72
- debug: () => undefined,
73
- trace: () => undefined,
74
- },
75
+ logger: logger.child({ module: "PriceServiceConnection" }, { level: priceServiceConnectionLogLevel }),
75
76
  });
76
77
  const priceItems = priceConfigs.map(({ id, alias }) => ({ id, alias }));
77
- const pythListener = new pyth_price_listener_1.PythPriceListener(priceServiceConnection, priceItems);
78
+ const pythListener = new pyth_price_listener_1.PythPriceListener(priceServiceConnection, priceItems, logger);
78
79
  const nearAccount = new near_1.NearAccount(network, accountId, nodeUrl, privateKeyPath, pythContractAddress);
79
- const nearListener = new near_1.NearPriceListener(nearAccount, priceItems, {
80
+ const nearListener = new near_1.NearPriceListener(nearAccount, priceItems, logger.child({ module: "NearPriceListener" }), {
80
81
  pollingFrequency,
81
82
  });
82
- const nearPusher = new near_1.NearPricePusher(nearAccount, priceServiceConnection);
83
- const controller = new controller_1.Controller(priceConfigs, pythListener, nearListener, nearPusher, { pushingFrequency });
83
+ const nearPusher = new near_1.NearPricePusher(nearAccount, priceServiceConnection, logger.child({ module: "NearPricePusher" }));
84
+ const controller = new controller_1.Controller(priceConfigs, pythListener, nearListener, nearPusher, logger.child({ module: "Controller" }, { level: controllerLogLevel }), { pushingFrequency });
84
85
  controller.start();
85
86
  },
86
87
  };
@@ -2,9 +2,11 @@ import { IPricePusher, PriceInfo, ChainPriceListener, PriceItem } from "../inter
2
2
  import { PriceServiceConnection } from "@pythnetwork/price-service-client";
3
3
  import { DurationInSeconds } from "../utils";
4
4
  import { FinalExecutionOutcome } from "near-api-js/lib/providers/provider";
5
+ import { Logger } from "pino";
5
6
  export declare class NearPriceListener extends ChainPriceListener {
6
7
  private account;
7
- constructor(account: NearAccount, priceItems: PriceItem[], config: {
8
+ private logger;
9
+ constructor(account: NearAccount, priceItems: PriceItem[], logger: Logger, config: {
8
10
  pollingFrequency: DurationInSeconds;
9
11
  });
10
12
  getOnChainPriceInfo(priceId: string): Promise<PriceInfo | undefined>;
@@ -12,7 +14,8 @@ export declare class NearPriceListener extends ChainPriceListener {
12
14
  export declare class NearPricePusher implements IPricePusher {
13
15
  private account;
14
16
  private connection;
15
- constructor(account: NearAccount, connection: PriceServiceConnection);
17
+ private logger;
18
+ constructor(account: NearAccount, connection: PriceServiceConnection, logger: Logger);
16
19
  updatePriceFeed(priceIds: string[], pubTimesToPush: number[]): Promise<void>;
17
20
  private getPriceFeedsUpdateData;
18
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"near.d.ts","sourceRoot":"","sources":["../../src/near/near.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,SAAS,EACV,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,sBAAsB,EAEvB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAG7C,OAAO,EAGL,qBAAqB,EACtB,MAAM,oCAAoC,CAAC;AAG5C,qBAAa,iBAAkB,SAAQ,kBAAkB;IAErD,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,WAAW,EAC5B,UAAU,EAAE,SAAS,EAAE,EACvB,MAAM,EAAE;QACN,gBAAgB,EAAE,iBAAiB,CAAC;KACrC;IAKG,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;CAyB3E;AAED,qBAAa,eAAgB,YAAW,YAAY;IAEhD,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,UAAU;gBADV,OAAO,EAAE,WAAW,EACpB,UAAU,EAAE,sBAAsB;IAGtC,eA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C,SAAS,GAAG,SAAS,CAAC;CAwB3E;AAED,qBAAa,eAAgB,YAAW,YAAY;IAEhD,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,MAAM;gBAFN,OAAO,EAAE,WAAW,EACpB,UAAU,EAAE,sBAAsB,EAClC,MAAM,EAAE,MAAM;IAGlB,eAAe,CACnB,QAAQ,EAAE,MAAM,EAAE,EAClB,cAAc,EAAE,MAAM,EAAE,GACvB,OAAO,CAAC,IAAI,CAAC;YA0DF,uBAAuB;CAMtC;AAED,qBAAa,WAAW;IAQpB,OAAO,CAAC,aAAa;IAPvB,OAAO,CAAC,OAAO,CAAU;gBAGvB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,MAAM,GAAG,SAAS,EAC1B,aAAa,EAAE,MAAM;IAWzB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAU7C,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAUhD,gBAAgB,CACpB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,GAAG,GACb,OAAO,CAAC,qBAAqB,CAAC;IAYjC,OAAO,CAAC,aAAa;CAkCtB"}
package/lib/near/near.js CHANGED
@@ -12,14 +12,16 @@ const near_api_js_1 = require("near-api-js");
12
12
  const key_stores_1 = require("near-api-js/lib/key_stores");
13
13
  class NearPriceListener extends interface_1.ChainPriceListener {
14
14
  account;
15
- constructor(account, priceItems, config) {
16
- super("near", config.pollingFrequency, priceItems);
15
+ logger;
16
+ constructor(account, priceItems, logger, config) {
17
+ super(config.pollingFrequency, priceItems);
17
18
  this.account = account;
19
+ this.logger = logger;
18
20
  }
19
21
  async getOnChainPriceInfo(priceId) {
20
22
  try {
21
23
  const priceRaw = await this.account.getPriceUnsafe(priceId);
22
- console.log(`Polled a NEAR on chain price for feed ${this.priceIdToAlias.get(priceId)} (${priceId}) ${JSON.stringify(priceRaw)}.`);
24
+ this.logger.debug(`Polled a NEAR on chain price for feed ${this.priceIdToAlias.get(priceId)} (${priceId}) ${JSON.stringify(priceRaw)}.`);
23
25
  if (priceRaw) {
24
26
  return {
25
27
  conf: priceRaw.conf,
@@ -31,9 +33,8 @@ class NearPriceListener extends interface_1.ChainPriceListener {
31
33
  return undefined;
32
34
  }
33
35
  }
34
- catch (e) {
35
- console.error(`Polling on-chain price for ${priceId} failed. Error:`);
36
- console.error(e);
36
+ catch (err) {
37
+ this.logger.error(err, `Polling on-chain price for ${priceId} failed.:`);
37
38
  return undefined;
38
39
  }
39
40
  }
@@ -42,9 +43,11 @@ exports.NearPriceListener = NearPriceListener;
42
43
  class NearPricePusher {
43
44
  account;
44
45
  connection;
45
- constructor(account, connection) {
46
+ logger;
47
+ constructor(account, connection, logger) {
46
48
  this.account = account;
47
49
  this.connection = connection;
50
+ this.logger = logger;
48
51
  }
49
52
  async updatePriceFeed(priceIds, pubTimesToPush) {
50
53
  if (priceIds.length === 0) {
@@ -56,19 +59,18 @@ class NearPricePusher {
56
59
  try {
57
60
  priceFeedUpdateData = await this.getPriceFeedsUpdateData(priceIds);
58
61
  }
59
- catch (e) {
60
- console.error(new Date(), "getPriceFeedsUpdateData failed:", e);
62
+ catch (err) {
63
+ this.logger.error(err, "getPriceFeedsUpdateData failed");
61
64
  return;
62
65
  }
63
- console.log("Pushing ", priceIds);
64
66
  for (const data of priceFeedUpdateData) {
65
67
  let updateFee;
66
68
  try {
67
69
  updateFee = await this.account.getUpdateFeeEstimate(data);
68
- console.log(`Update fee: ${updateFee}`);
70
+ this.logger.debug(`Update fee: ${updateFee}`);
69
71
  }
70
- catch (e) {
71
- console.error(new Date(), "getUpdateFeeEstimate failed:", e);
72
+ catch (err) {
73
+ this.logger.error(err, "getUpdateFeeEstimate failed");
72
74
  continue;
73
75
  }
74
76
  try {
@@ -82,14 +84,14 @@ class NearPricePusher {
82
84
  return is_success;
83
85
  }, true);
84
86
  if (is_success) {
85
- console.log(new Date(), "updatePriceFeeds successful. Tx hash: ", outcome["transaction"]["hash"]);
87
+ this.logger.info({ hash: outcome["transaction"]["hash"] }, "updatePriceFeeds successful.");
86
88
  }
87
89
  else {
88
- console.error(new Date(), "updatePriceFeeds failed:", JSON.stringify(failureMessages, undefined, 2));
90
+ this.logger.error({ failureMessages }, "updatePriceFeeds failed");
89
91
  }
90
92
  }
91
- catch (e) {
92
- console.error(new Date(), "updatePriceFeeds failed:", e);
93
+ catch (err) {
94
+ this.logger.error(err, "updatePriceFeeds failed");
93
95
  }
94
96
  }
95
97
  }
package/lib/options.d.ts CHANGED
@@ -17,4 +17,13 @@ export declare const pushingFrequency: {
17
17
  export declare const mnemonicFile: {
18
18
  "mnemonic-file": Options;
19
19
  };
20
+ export declare const logLevel: {
21
+ "log-level": Options;
22
+ };
23
+ export declare const priceServiceConnectionLogLevel: {
24
+ "price-service-connection-log-level": Options;
25
+ };
26
+ export declare const controllerLogLevel: {
27
+ "controller-log-level": Options;
28
+ };
20
29
  //# sourceMappingURL=options.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,eAAO,MAAM,oBAAoB;;CAOhC,CAAC;AAEF,eAAO,MAAM,mBAAmB;;CAQ/B,CAAC;AAEF,eAAO,MAAM,eAAe;;CAM3B,CAAC;AAEF,eAAO,MAAM,gBAAgB;;CAQ5B,CAAC;AAEF,eAAO,MAAM,gBAAgB;;CAU5B,CAAC;AAEF,eAAO,MAAM,YAAY;;CAMxB,CAAC"}
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,eAAO,MAAM,oBAAoB;;CAOhC,CAAC;AAEF,eAAO,MAAM,mBAAmB;;CAQ/B,CAAC;AAEF,eAAO,MAAM,eAAe;;CAM3B,CAAC;AAEF,eAAO,MAAM,gBAAgB;;CAQ5B,CAAC;AAEF,eAAO,MAAM,gBAAgB;;CAU5B,CAAC;AAEF,eAAO,MAAM,YAAY;;CAMxB,CAAC;AAEF,eAAO,MAAM,QAAQ;;CAQpB,CAAC;AAEF,eAAO,MAAM,8BAA8B;;CAQ1C,CAAC;AAEF,eAAO,MAAM,kBAAkB;;CAQ9B,CAAC"}