@pythnetwork/price-pusher 10.2.0 → 10.3.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 (127) hide show
  1. package/{lib/aptos/aptos.js → dist/aptos/aptos.cjs} +80 -76
  2. package/{lib → dist}/aptos/aptos.d.ts +5 -5
  3. package/{lib/aptos/balance-tracker.js → dist/aptos/balance-tracker.cjs} +37 -25
  4. package/{lib → dist}/aptos/balance-tracker.d.ts +9 -9
  5. package/dist/aptos/command.cjs +161 -0
  6. package/{lib → dist}/aptos/command.d.ts +1 -2
  7. package/dist/common.cjs +4 -0
  8. package/{lib → dist}/common.d.ts +0 -1
  9. package/{lib/controller.js → dist/controller.cjs} +35 -33
  10. package/{lib → dist}/controller.d.ts +5 -6
  11. package/dist/evm/balance-tracker.cjs +58 -0
  12. package/{lib → dist}/evm/balance-tracker.d.ts +10 -10
  13. package/dist/evm/command.cjs +205 -0
  14. package/{lib → dist}/evm/command.d.ts +1 -2
  15. package/dist/evm/custom-gas-station.cjs +54 -0
  16. package/{lib → dist}/evm/custom-gas-station.d.ts +1 -2
  17. package/dist/evm/evm.cjs +287 -0
  18. package/{lib → dist}/evm/evm.d.ts +8 -7
  19. package/{lib/evm/pyth-abi.js → dist/evm/pyth-abi.cjs} +181 -160
  20. package/{lib → dist}/evm/pyth-abi.d.ts +0 -1
  21. package/dist/evm/pyth-contract.cjs +17 -0
  22. package/{lib → dist}/evm/pyth-contract.d.ts +3 -4
  23. package/dist/evm/super-wallet.cjs +90 -0
  24. package/{lib → dist}/evm/super-wallet.d.ts +1 -2
  25. package/dist/fuel/command.cjs +135 -0
  26. package/{lib → dist}/fuel/command.d.ts +1 -2
  27. package/dist/fuel/fuel.cjs +108 -0
  28. package/{lib → dist}/fuel/fuel.d.ts +5 -5
  29. package/dist/index.cjs +25 -0
  30. package/dist/index.d.ts +1 -0
  31. package/dist/injective/command.cjs +150 -0
  32. package/{lib → dist}/injective/command.d.ts +1 -2
  33. package/{lib/injective/injective.js → dist/injective/injective.cjs} +100 -98
  34. package/{lib → dist}/injective/injective.d.ts +7 -6
  35. package/dist/interface.cjs +142 -0
  36. package/{lib → dist}/interface.d.ts +12 -13
  37. package/dist/metrics.cjs +218 -0
  38. package/{lib → dist}/metrics.d.ts +10 -11
  39. package/dist/near/command.cjs +129 -0
  40. package/{lib → dist}/near/command.d.ts +1 -2
  41. package/dist/near/near.cjs +183 -0
  42. package/{lib → dist}/near/near.d.ts +5 -5
  43. package/dist/options.cjs +132 -0
  44. package/{lib → dist}/options.d.ts +1 -2
  45. package/dist/package.json +1 -0
  46. package/dist/price-config.cjs +104 -0
  47. package/{lib → dist}/price-config.d.ts +5 -6
  48. package/{lib/pyth-price-listener.js → dist/pyth-price-listener.cjs} +30 -24
  49. package/{lib → dist}/pyth-price-listener.d.ts +4 -4
  50. package/dist/solana/balance-tracker.cjs +60 -0
  51. package/{lib → dist}/solana/balance-tracker.d.ts +9 -9
  52. package/dist/solana/command.cjs +259 -0
  53. package/{lib → dist}/solana/command.d.ts +2 -3
  54. package/{lib/solana/solana.js → dist/solana/solana.cjs} +90 -78
  55. package/{lib → dist}/solana/solana.d.ts +6 -6
  56. package/dist/sui/balance-tracker.cjs +58 -0
  57. package/{lib → dist}/sui/balance-tracker.d.ts +9 -9
  58. package/dist/sui/command.cjs +190 -0
  59. package/{lib → dist}/sui/command.d.ts +1 -2
  60. package/{lib/sui/sui.js → dist/sui/sui.cjs} +145 -133
  61. package/{lib → dist}/sui/sui.d.ts +7 -8
  62. package/dist/ton/command.cjs +137 -0
  63. package/{lib → dist}/ton/command.d.ts +1 -2
  64. package/dist/ton/ton.cjs +103 -0
  65. package/{lib → dist}/ton/ton.d.ts +7 -6
  66. package/dist/utils.cjs +102 -0
  67. package/{lib → dist}/utils.d.ts +4 -4
  68. package/package.json +161 -20
  69. package/lib/aptos/aptos.d.ts.map +0 -1
  70. package/lib/aptos/balance-tracker.d.ts.map +0 -1
  71. package/lib/aptos/command.d.ts.map +0 -1
  72. package/lib/aptos/command.js +0 -126
  73. package/lib/common.d.ts.map +0 -1
  74. package/lib/common.js +0 -2
  75. package/lib/controller.d.ts.map +0 -1
  76. package/lib/evm/balance-tracker.d.ts.map +0 -1
  77. package/lib/evm/balance-tracker.js +0 -49
  78. package/lib/evm/command.d.ts.map +0 -1
  79. package/lib/evm/command.js +0 -178
  80. package/lib/evm/custom-gas-station.d.ts.map +0 -1
  81. package/lib/evm/custom-gas-station.js +0 -40
  82. package/lib/evm/evm.d.ts.map +0 -1
  83. package/lib/evm/evm.js +0 -270
  84. package/lib/evm/pyth-abi.d.ts.map +0 -1
  85. package/lib/evm/pyth-contract.d.ts.map +0 -1
  86. package/lib/evm/pyth-contract.js +0 -11
  87. package/lib/evm/super-wallet.d.ts.map +0 -1
  88. package/lib/evm/super-wallet.js +0 -73
  89. package/lib/fuel/command.d.ts.map +0 -1
  90. package/lib/fuel/command.js +0 -98
  91. package/lib/fuel/fuel.d.ts.map +0 -1
  92. package/lib/fuel/fuel.js +0 -101
  93. package/lib/index.d.ts +0 -3
  94. package/lib/index.d.ts.map +0 -1
  95. package/lib/index.js +0 -34
  96. package/lib/injective/command.d.ts.map +0 -1
  97. package/lib/injective/command.js +0 -119
  98. package/lib/injective/injective.d.ts.map +0 -1
  99. package/lib/interface.d.ts.map +0 -1
  100. package/lib/interface.js +0 -122
  101. package/lib/metrics.d.ts.map +0 -1
  102. package/lib/metrics.js +0 -152
  103. package/lib/near/command.d.ts.map +0 -1
  104. package/lib/near/command.js +0 -103
  105. package/lib/near/near.d.ts.map +0 -1
  106. package/lib/near/near.js +0 -168
  107. package/lib/options.d.ts.map +0 -1
  108. package/lib/options.js +0 -84
  109. package/lib/price-config.d.ts.map +0 -1
  110. package/lib/price-config.js +0 -114
  111. package/lib/pyth-price-listener.d.ts.map +0 -1
  112. package/lib/solana/balance-tracker.d.ts.map +0 -1
  113. package/lib/solana/balance-tracker.js +0 -51
  114. package/lib/solana/command.d.ts.map +0 -1
  115. package/lib/solana/command.js +0 -223
  116. package/lib/solana/solana.d.ts.map +0 -1
  117. package/lib/sui/balance-tracker.d.ts.map +0 -1
  118. package/lib/sui/balance-tracker.js +0 -49
  119. package/lib/sui/command.d.ts.map +0 -1
  120. package/lib/sui/command.js +0 -160
  121. package/lib/sui/sui.d.ts.map +0 -1
  122. package/lib/ton/command.d.ts.map +0 -1
  123. package/lib/ton/command.js +0 -99
  124. package/lib/ton/ton.d.ts.map +0 -1
  125. package/lib/ton/ton.js +0 -97
  126. package/lib/utils.d.ts.map +0 -1
  127. package/lib/utils.js +0 -61
@@ -1,10 +1,12 @@
1
- import { ChainPriceListener, IPricePusher, PriceInfo, PriceItem } from "../interface";
2
- import { DurationInSeconds } from "../utils";
3
- import { SuiPythClient } from "@pythnetwork/pyth-sui-js";
1
+ import type { SuiObjectRef } from "@mysten/sui/client";
2
+ import { SuiClient } from "@mysten/sui/client";
4
3
  import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
5
- import { SuiClient, SuiObjectRef } from "@mysten/sui/client";
6
- import { Logger } from "pino";
7
4
  import { HermesClient } from "@pythnetwork/hermes-client";
5
+ import { SuiPythClient } from "@pythnetwork/pyth-sui-js";
6
+ import type { Logger } from "pino";
7
+ import type { IPricePusher, PriceInfo, PriceItem } from "../interface.js";
8
+ import { ChainPriceListener } from "../interface.js";
9
+ import type { DurationInSeconds } from "../utils.js";
8
10
  type ObjectId = string;
9
11
  export declare class SuiPriceListener extends ChainPriceListener {
10
12
  private pythClient;
@@ -41,8 +43,6 @@ export declare class SuiPricePusher implements IPricePusher {
41
43
  /**
42
44
  * getPackageId returns the latest package id that the object belongs to. Use this to
43
45
  * fetch the latest package id for a given object id and handle package upgrades automatically.
44
- * @param provider
45
- * @param objectId
46
46
  * @returns package id
47
47
  */
48
48
  static getPackageId(provider: SuiClient, objectId: ObjectId): Promise<ObjectId>;
@@ -63,4 +63,3 @@ export declare class SuiPricePusher implements IPricePusher {
63
63
  private static mergeGasCoinsIntoOne;
64
64
  }
65
65
  export {};
66
- //# sourceMappingURL=sui.d.ts.map
@@ -0,0 +1,137 @@
1
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-explicit-any */ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return _default;
9
+ }
10
+ });
11
+ const _nodefs = /*#__PURE__*/ _interop_require_default(require("node:fs"));
12
+ const _hermesclient = require("@pythnetwork/hermes-client");
13
+ const _ton = require("@ton/ton");
14
+ const _pino = require("pino");
15
+ const _options = /*#__PURE__*/ _interop_require_wildcard(require("../options.cjs"));
16
+ const _priceconfig = require("../price-config.cjs");
17
+ const _pythpricelistener = require("../pyth-price-listener.cjs");
18
+ const _ton1 = require("./ton.cjs");
19
+ const _controller = require("../controller.cjs");
20
+ const _utils = require("../utils.cjs");
21
+ function _interop_require_default(obj) {
22
+ return obj && obj.__esModule ? obj : {
23
+ default: obj
24
+ };
25
+ }
26
+ function _getRequireWildcardCache(nodeInterop) {
27
+ if (typeof WeakMap !== "function") return null;
28
+ var cacheBabelInterop = new WeakMap();
29
+ var cacheNodeInterop = new WeakMap();
30
+ return (_getRequireWildcardCache = function(nodeInterop) {
31
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
32
+ })(nodeInterop);
33
+ }
34
+ function _interop_require_wildcard(obj, nodeInterop) {
35
+ if (!nodeInterop && obj && obj.__esModule) {
36
+ return obj;
37
+ }
38
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
39
+ return {
40
+ default: obj
41
+ };
42
+ }
43
+ var cache = _getRequireWildcardCache(nodeInterop);
44
+ if (cache && cache.has(obj)) {
45
+ return cache.get(obj);
46
+ }
47
+ var newObj = {
48
+ __proto__: null
49
+ };
50
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
51
+ for(var key in obj){
52
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
53
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
54
+ if (desc && (desc.get || desc.set)) {
55
+ Object.defineProperty(newObj, key, desc);
56
+ } else {
57
+ newObj[key] = obj[key];
58
+ }
59
+ }
60
+ }
61
+ newObj.default = obj;
62
+ if (cache) {
63
+ cache.set(obj, newObj);
64
+ }
65
+ return newObj;
66
+ }
67
+ const _default = {
68
+ command: "ton",
69
+ describe: "run price pusher for TON",
70
+ builder: {
71
+ endpoint: {
72
+ description: "TON RPC API endpoint",
73
+ type: "string",
74
+ required: true
75
+ },
76
+ "private-key-file": {
77
+ description: "Path to the private key file",
78
+ type: "string",
79
+ required: true
80
+ },
81
+ "pyth-contract-address": {
82
+ description: "Pyth contract address on TON",
83
+ type: "string",
84
+ required: true
85
+ },
86
+ ..._options.priceConfigFile,
87
+ ..._options.priceServiceEndpoint,
88
+ ..._options.pushingFrequency,
89
+ ..._options.pollingFrequency,
90
+ ..._options.logLevel,
91
+ ..._options.controllerLogLevel
92
+ },
93
+ handler: async function(argv) {
94
+ const { endpoint, privateKeyFile, pythContractAddress, priceConfigFile, priceServiceEndpoint, pushingFrequency, pollingFrequency, logLevel, controllerLogLevel } = argv;
95
+ const logger = (0, _pino.pino)({
96
+ level: logLevel
97
+ });
98
+ const priceConfigs = (0, _priceconfig.readPriceConfigFile)(priceConfigFile);
99
+ const hermesClient = new _hermesclient.HermesClient(priceServiceEndpoint);
100
+ let priceItems = priceConfigs.map(({ id, alias })=>({
101
+ id,
102
+ alias
103
+ }));
104
+ // Better to filter out invalid price items before creating the pyth listener
105
+ const { existingPriceItems, invalidPriceItems } = await (0, _utils.filterInvalidPriceItems)(hermesClient, priceItems);
106
+ if (invalidPriceItems.length > 0) {
107
+ logger.error(`Invalid price id submitted for: ${invalidPriceItems.map(({ alias })=>alias).join(", ")}`);
108
+ }
109
+ priceItems = existingPriceItems;
110
+ const pythListener = new _pythpricelistener.PythPriceListener(hermesClient, priceItems, logger.child({
111
+ module: "PythPriceListener"
112
+ }));
113
+ const client = new _ton.TonClient({
114
+ endpoint
115
+ });
116
+ const privateKey = _nodefs.default.readFileSync(privateKeyFile, "utf8").trim();
117
+ const contractAddress = _ton.Address.parse(pythContractAddress);
118
+ const provider = client.provider(contractAddress);
119
+ const tonPriceListener = new _ton1.TonPriceListener(provider, contractAddress, priceItems, logger.child({
120
+ module: "TonPriceListener"
121
+ }), {
122
+ pollingFrequency
123
+ });
124
+ const tonPricePusher = new _ton1.TonPricePusher(client, privateKey, contractAddress, hermesClient, logger.child({
125
+ module: "TonPricePusher"
126
+ }));
127
+ const controller = new _controller.Controller(priceConfigs, pythListener, // TODO: This is very unsafe, but matches existing behavior with looser types
128
+ tonPriceListener, tonPricePusher, logger.child({
129
+ module: "Controller"
130
+ }, {
131
+ level: controllerLogLevel
132
+ }), {
133
+ pushingFrequency
134
+ });
135
+ void controller.start();
136
+ }
137
+ };
@@ -1,4 +1,4 @@
1
- import { Options } from "yargs";
1
+ import type { Options } from "yargs";
2
2
  declare const _default: {
3
3
  command: string;
4
4
  describe: string;
@@ -16,4 +16,3 @@ declare const _default: {
16
16
  handler: (argv: any) => Promise<void>;
17
17
  };
18
18
  export default _default;
19
- //# sourceMappingURL=command.d.ts.map
@@ -0,0 +1,103 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get TonPriceListener () {
13
+ return TonPriceListener;
14
+ },
15
+ get TonPricePusher () {
16
+ return TonPricePusher;
17
+ }
18
+ });
19
+ const _pythtonjs = require("@pythnetwork/pyth-ton-js");
20
+ const _crypto = require("@ton/crypto");
21
+ const _ton = require("@ton/ton");
22
+ const _interface = require("../interface.cjs");
23
+ const _utils = require("../utils.cjs");
24
+ class TonPriceListener extends _interface.ChainPriceListener {
25
+ provider;
26
+ contractAddress;
27
+ logger;
28
+ contract;
29
+ constructor(provider, contractAddress, priceItems, logger, config){
30
+ super(config.pollingFrequency, priceItems), this.provider = provider, this.contractAddress = contractAddress, this.logger = logger;
31
+ this.contract = this.provider.open(_pythtonjs.PythContract.createFromAddress(this.contractAddress));
32
+ }
33
+ async getOnChainPriceInfo(priceId) {
34
+ try {
35
+ const formattedPriceId = (0, _utils.addLeading0x)(priceId);
36
+ const priceInfo = await this.contract.getPriceUnsafe(formattedPriceId);
37
+ this.logger.debug(`Polled a TON on chain price for feed ${this.priceIdToAlias.get(priceId) ?? ""} (${priceId}).`);
38
+ return {
39
+ conf: priceInfo.conf.toString(),
40
+ price: priceInfo.price.toString(),
41
+ publishTime: priceInfo.publishTime
42
+ };
43
+ } catch (error) {
44
+ this.logger.error({
45
+ err: error,
46
+ priceId
47
+ }, `Polling on-chain price failed.`);
48
+ return undefined;
49
+ }
50
+ }
51
+ }
52
+ class TonPricePusher {
53
+ client;
54
+ privateKey;
55
+ contractAddress;
56
+ hermesClient;
57
+ logger;
58
+ contract;
59
+ sender;
60
+ constructor(client, privateKey, contractAddress, hermesClient, logger){
61
+ this.client = client;
62
+ this.privateKey = privateKey;
63
+ this.contractAddress = contractAddress;
64
+ this.hermesClient = hermesClient;
65
+ this.logger = logger;
66
+ this.contract = this.client.provider(this.contractAddress).open(_pythtonjs.PythContract.createFromAddress(this.contractAddress));
67
+ const keyPair = (0, _crypto.keyPairFromSeed)(Buffer.from(this.privateKey, "hex"));
68
+ const wallet = _ton.WalletContractV4.create({
69
+ publicKey: keyPair.publicKey,
70
+ workchain: 0
71
+ });
72
+ const provider = this.client.open(wallet);
73
+ this.sender = provider.sender(keyPair.secretKey);
74
+ }
75
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
76
+ async updatePriceFeed(priceIds, _) {
77
+ if (priceIds.length === 0) {
78
+ return;
79
+ }
80
+ let priceFeedUpdateData;
81
+ try {
82
+ const response = await this.hermesClient.getLatestPriceUpdates(priceIds, {
83
+ encoding: "base64",
84
+ ignoreInvalidPriceIds: true
85
+ });
86
+ priceFeedUpdateData = response.binary.data;
87
+ } catch (error) {
88
+ this.logger.error(error, "getPriceFeedsUpdateData failed");
89
+ return;
90
+ }
91
+ try {
92
+ for (const updateData of priceFeedUpdateData){
93
+ const updateDataBuffer = Buffer.from(updateData, "base64");
94
+ const updateFee = await this.contract.getUpdateFee(updateDataBuffer);
95
+ const totalFee = (0, _pythtonjs.calculateUpdatePriceFeedsFee)(BigInt(priceIds.length)) + BigInt(updateFee);
96
+ await this.contract.sendUpdatePriceFeeds(this.sender, updateDataBuffer, totalFee);
97
+ }
98
+ this.logger.info("updatePriceFeed successful");
99
+ } catch (error) {
100
+ this.logger.error(error, "updatePriceFeed failed");
101
+ }
102
+ }
103
+ }
@@ -1,8 +1,10 @@
1
1
  import { HermesClient } from "@pythnetwork/hermes-client";
2
- import { ChainPriceListener, IPricePusher, PriceInfo, PriceItem } from "../interface";
3
- import { DurationInSeconds } from "../utils";
4
- import { Logger } from "pino";
5
- import { Address, ContractProvider, TonClient } from "@ton/ton";
2
+ import type { ContractProvider } from "@ton/ton";
3
+ import { Address, TonClient } from "@ton/ton";
4
+ import type { Logger } from "pino";
5
+ import type { IPricePusher, PriceInfo, PriceItem } from "../interface.js";
6
+ import { ChainPriceListener } from "../interface.js";
7
+ import type { DurationInSeconds } from "../utils.js";
6
8
  export declare class TonPriceListener extends ChainPriceListener {
7
9
  private provider;
8
10
  private contractAddress;
@@ -22,6 +24,5 @@ export declare class TonPricePusher implements IPricePusher {
22
24
  private contract;
23
25
  private sender;
24
26
  constructor(client: TonClient, privateKey: string, contractAddress: Address, hermesClient: HermesClient, logger: Logger);
25
- updatePriceFeed(priceIds: string[], pubTimesToPush: number[]): Promise<void>;
27
+ updatePriceFeed(priceIds: string[], _: number[]): Promise<void>;
26
28
  }
27
- //# sourceMappingURL=ton.d.ts.map
package/dist/utils.cjs ADDED
@@ -0,0 +1,102 @@
1
+ /* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/no-unnecessary-type-parameters */ /* eslint-disable @typescript-eslint/no-explicit-any */ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get addLeading0x () {
13
+ return addLeading0x;
14
+ },
15
+ get assertDefined () {
16
+ return assertDefined;
17
+ },
18
+ get customGasChainIds () {
19
+ return customGasChainIds;
20
+ },
21
+ get filterInvalidPriceItems () {
22
+ return filterInvalidPriceItems;
23
+ },
24
+ get isWsEndpoint () {
25
+ return isWsEndpoint;
26
+ },
27
+ get removeLeading0x () {
28
+ return removeLeading0x;
29
+ },
30
+ get sleep () {
31
+ return sleep;
32
+ },
33
+ get txSpeeds () {
34
+ return txSpeeds;
35
+ },
36
+ get verifyValidOption () {
37
+ return verifyValidOption;
38
+ }
39
+ });
40
+ const txSpeeds = [
41
+ "slow",
42
+ "standard",
43
+ "fast"
44
+ ];
45
+ const customGasChainIds = [
46
+ 137
47
+ ];
48
+ async function sleep(ms) {
49
+ return new Promise((resolve)=>setTimeout(resolve, ms));
50
+ }
51
+ function removeLeading0x(id) {
52
+ if (id.startsWith("0x")) {
53
+ return id.slice(2);
54
+ }
55
+ return id;
56
+ }
57
+ const addLeading0x = (id)=>hasLeading0x(id) ? id : `0x${id}`;
58
+ const hasLeading0x = (input)=>input.startsWith("0x");
59
+ function isWsEndpoint(endpoint) {
60
+ const url = new URL(endpoint);
61
+ const protocol = url.protocol;
62
+ if (protocol === "ws:" || protocol == "wss:") {
63
+ return true;
64
+ }
65
+ return false;
66
+ }
67
+ function verifyValidOption(option, validOptions) {
68
+ if (validOptions.includes(option)) {
69
+ return option;
70
+ }
71
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
72
+ const errorString = `${option} is not a valid option. Please choose betweeen ${validOptions}`;
73
+ throw new Error(errorString);
74
+ }
75
+ const assertDefined = (value)=>{
76
+ if (value === undefined) {
77
+ throw new Error("Assertion failed: value was undefined");
78
+ } else {
79
+ return value;
80
+ }
81
+ };
82
+ async function filterInvalidPriceItems(hermesClient, priceItems) {
83
+ const priceMetadata = await hermesClient.getPriceFeeds();
84
+ const allPriceIds = new Set(priceMetadata.map((priceMetadata)=>priceMetadata.id));
85
+ // Filter out invalid price ids
86
+ // eslint-disable-next-line unicorn/no-array-reduce
87
+ const { existingPriceItems, invalidPriceItems } = priceItems.reduce((acc, item)=>{
88
+ if (allPriceIds.has(item.id)) {
89
+ acc.existingPriceItems.push(item);
90
+ } else {
91
+ acc.invalidPriceItems.push(item);
92
+ }
93
+ return acc;
94
+ }, {
95
+ existingPriceItems: [],
96
+ invalidPriceItems: []
97
+ });
98
+ return {
99
+ existingPriceItems,
100
+ invalidPriceItems
101
+ };
102
+ }
@@ -1,5 +1,6 @@
1
- import { HermesClient, HexString } from "@pythnetwork/hermes-client";
2
- import { PriceItem } from "./interface";
1
+ import type { HexString } from "@pythnetwork/hermes-client";
2
+ import { HermesClient } from "@pythnetwork/hermes-client";
3
+ import type { PriceItem } from "./interface.js";
3
4
  export type PctNumber = number;
4
5
  export type DurationInSeconds = number;
5
6
  export declare const txSpeeds: readonly ["slow", "standard", "fast"];
@@ -10,10 +11,9 @@ export declare function sleep(ms: number): Promise<void>;
10
11
  export declare function removeLeading0x(id: HexString): HexString;
11
12
  export declare const addLeading0x: (id: HexString) => `0x${string}`;
12
13
  export declare function isWsEndpoint(endpoint: string): boolean;
13
- export declare function verifyValidOption<options extends Readonly<Array<any>>, validOption extends options[number]>(option: any, validOptions: options): validOption;
14
+ export declare function verifyValidOption<options extends readonly any[], validOption extends options[number]>(option: any, validOptions: options): validOption;
14
15
  export declare const assertDefined: <T>(value: T | undefined) => T;
15
16
  export declare function filterInvalidPriceItems(hermesClient: HermesClient, priceItems: PriceItem[]): Promise<{
16
17
  existingPriceItems: PriceItem[];
17
18
  invalidPriceItems: PriceItem[];
18
19
  }>;
19
- //# sourceMappingURL=utils.d.ts.map
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@pythnetwork/price-pusher",
3
- "version": "10.2.0",
3
+ "version": "10.3.0",
4
4
  "description": "Pyth Price Pusher",
5
5
  "homepage": "https://pyth.network",
6
- "main": "lib/index.js",
7
- "types": "lib/index.d.ts",
6
+ "main": "./dist/index.cjs",
7
+ "types": "./dist/index.d.ts",
8
8
  "files": [
9
- "lib/**/*"
9
+ "dist/**/*"
10
10
  ],
11
11
  "bin": {
12
- "pyth-price-pusher": "./lib/index.js"
12
+ "pyth-price-pusher": "./dist/index.js"
13
13
  },
14
14
  "repository": {
15
15
  "type": "git",
@@ -32,19 +32,19 @@
32
32
  ],
33
33
  "license": "Apache-2.0",
34
34
  "devDependencies": {
35
+ "@cprussin/eslint-config": "^4.0.2",
36
+ "@pythnetwork/jest-config": "",
35
37
  "@types/ethereum-protocol": "^1.0.2",
36
38
  "@types/express": "^4.17.21",
37
39
  "@types/jest": "^27.4.1",
38
40
  "@types/yargs": "^17.0.10",
39
41
  "@typescript-eslint/eslint-plugin": "^6.0.0",
40
42
  "@typescript-eslint/parser": "^6.0.0",
41
- "eslint": "^8.13.0",
43
+ "eslint": "^9.23.0",
42
44
  "jest": "^29.7.0",
43
45
  "pino-pretty": "^11.2.1",
44
46
  "prettier": "^3.5.3",
45
- "ts-jest": "^29.1.1",
46
- "ts-node": "^10.9.2",
47
- "typescript": "^5.8.2"
47
+ "ts-node": "^10.9.2"
48
48
  },
49
49
  "dependencies": {
50
50
  "@aptos-labs/ts-sdk": "^1.39.0",
@@ -61,7 +61,7 @@
61
61
  "@types/pino": "^7.0.5",
62
62
  "aptos": "^1.8.5",
63
63
  "express": "^4.18.2",
64
- "fuels": "^0.94.5",
64
+ "fuels": "0.101.3",
65
65
  "jito-ts": "^3.0.1",
66
66
  "joi": "^17.6.0",
67
67
  "near-api-js": "^3.0.2",
@@ -70,23 +70,164 @@
70
70
  "viem": "^2.19.4",
71
71
  "yaml": "^2.1.1",
72
72
  "yargs": "^17.5.1",
73
- "@pythnetwork/price-service-sdk": "^1.8.0",
74
- "@pythnetwork/pyth-fuel-js": "1.0.7",
75
- "@pythnetwork/pyth-solana-receiver": "0.12.0",
76
- "@pythnetwork/pyth-sui-js": "2.2.0",
77
- "@pythnetwork/solana-utils": "0.5.0",
78
- "@pythnetwork/pyth-ton-js": "0.1.2",
79
- "@pythnetwork/pyth-sdk-solidity": "4.2.0"
73
+ "@pythnetwork/price-service-sdk": "^1.9.0",
74
+ "@pythnetwork/pyth-fuel-js": "1.1.0",
75
+ "@pythnetwork/pyth-sui-js": "2.4.0",
76
+ "@pythnetwork/pyth-ton-js": "0.3.0",
77
+ "@pythnetwork/pyth-sdk-solidity": "4.3.0",
78
+ "@pythnetwork/pyth-solana-receiver": "0.13.0",
79
+ "@pythnetwork/solana-utils": "0.6.0"
80
80
  },
81
+ "engines": {
82
+ "node": ">=22.14.0"
83
+ },
84
+ "type": "module",
85
+ "exports": {
86
+ "./aptos/aptos": {
87
+ "types": "./dist/aptos/aptos.d.ts",
88
+ "default": "./dist/aptos/aptos.cjs"
89
+ },
90
+ "./aptos/balance-tracker": {
91
+ "types": "./dist/aptos/balance-tracker.d.ts",
92
+ "default": "./dist/aptos/balance-tracker.cjs"
93
+ },
94
+ "./aptos/command": {
95
+ "types": "./dist/aptos/command.d.ts",
96
+ "default": "./dist/aptos/command.cjs"
97
+ },
98
+ "./common": {
99
+ "types": "./dist/common.d.ts",
100
+ "default": "./dist/common.cjs"
101
+ },
102
+ "./controller": {
103
+ "types": "./dist/controller.d.ts",
104
+ "default": "./dist/controller.cjs"
105
+ },
106
+ "./evm/balance-tracker": {
107
+ "types": "./dist/evm/balance-tracker.d.ts",
108
+ "default": "./dist/evm/balance-tracker.cjs"
109
+ },
110
+ "./evm/command": {
111
+ "types": "./dist/evm/command.d.ts",
112
+ "default": "./dist/evm/command.cjs"
113
+ },
114
+ "./evm/custom-gas-station": {
115
+ "types": "./dist/evm/custom-gas-station.d.ts",
116
+ "default": "./dist/evm/custom-gas-station.cjs"
117
+ },
118
+ "./evm/evm": {
119
+ "types": "./dist/evm/evm.d.ts",
120
+ "default": "./dist/evm/evm.cjs"
121
+ },
122
+ "./evm/pyth-abi": {
123
+ "types": "./dist/evm/pyth-abi.d.ts",
124
+ "default": "./dist/evm/pyth-abi.cjs"
125
+ },
126
+ "./evm/pyth-contract": {
127
+ "types": "./dist/evm/pyth-contract.d.ts",
128
+ "default": "./dist/evm/pyth-contract.cjs"
129
+ },
130
+ "./evm/super-wallet": {
131
+ "types": "./dist/evm/super-wallet.d.ts",
132
+ "default": "./dist/evm/super-wallet.cjs"
133
+ },
134
+ "./fuel/command": {
135
+ "types": "./dist/fuel/command.d.ts",
136
+ "default": "./dist/fuel/command.cjs"
137
+ },
138
+ "./fuel/fuel": {
139
+ "types": "./dist/fuel/fuel.d.ts",
140
+ "default": "./dist/fuel/fuel.cjs"
141
+ },
142
+ ".": {
143
+ "types": "./dist/index.d.ts",
144
+ "default": "./dist/index.cjs"
145
+ },
146
+ "./injective/command": {
147
+ "types": "./dist/injective/command.d.ts",
148
+ "default": "./dist/injective/command.cjs"
149
+ },
150
+ "./injective/injective": {
151
+ "types": "./dist/injective/injective.d.ts",
152
+ "default": "./dist/injective/injective.cjs"
153
+ },
154
+ "./interface": {
155
+ "types": "./dist/interface.d.ts",
156
+ "default": "./dist/interface.cjs"
157
+ },
158
+ "./metrics": {
159
+ "types": "./dist/metrics.d.ts",
160
+ "default": "./dist/metrics.cjs"
161
+ },
162
+ "./near/command": {
163
+ "types": "./dist/near/command.d.ts",
164
+ "default": "./dist/near/command.cjs"
165
+ },
166
+ "./near/near": {
167
+ "types": "./dist/near/near.d.ts",
168
+ "default": "./dist/near/near.cjs"
169
+ },
170
+ "./options": {
171
+ "types": "./dist/options.d.ts",
172
+ "default": "./dist/options.cjs"
173
+ },
174
+ "./price-config": {
175
+ "types": "./dist/price-config.d.ts",
176
+ "default": "./dist/price-config.cjs"
177
+ },
178
+ "./pyth-price-listener": {
179
+ "types": "./dist/pyth-price-listener.d.ts",
180
+ "default": "./dist/pyth-price-listener.cjs"
181
+ },
182
+ "./solana/balance-tracker": {
183
+ "types": "./dist/solana/balance-tracker.d.ts",
184
+ "default": "./dist/solana/balance-tracker.cjs"
185
+ },
186
+ "./solana/command": {
187
+ "types": "./dist/solana/command.d.ts",
188
+ "default": "./dist/solana/command.cjs"
189
+ },
190
+ "./solana/solana": {
191
+ "types": "./dist/solana/solana.d.ts",
192
+ "default": "./dist/solana/solana.cjs"
193
+ },
194
+ "./sui/balance-tracker": {
195
+ "types": "./dist/sui/balance-tracker.d.ts",
196
+ "default": "./dist/sui/balance-tracker.cjs"
197
+ },
198
+ "./sui/command": {
199
+ "types": "./dist/sui/command.d.ts",
200
+ "default": "./dist/sui/command.cjs"
201
+ },
202
+ "./sui/sui": {
203
+ "types": "./dist/sui/sui.d.ts",
204
+ "default": "./dist/sui/sui.cjs"
205
+ },
206
+ "./ton/command": {
207
+ "types": "./dist/ton/command.d.ts",
208
+ "default": "./dist/ton/command.cjs"
209
+ },
210
+ "./ton/ton": {
211
+ "types": "./dist/ton/ton.d.ts",
212
+ "default": "./dist/ton/ton.cjs"
213
+ },
214
+ "./utils": {
215
+ "types": "./dist/utils.d.ts",
216
+ "default": "./dist/utils.cjs"
217
+ },
218
+ "./package.json": "./package.json"
219
+ },
220
+ "module": "./dist/esm/index.js",
81
221
  "scripts": {
82
- "build": "tsc",
222
+ "build": "ts-duality --noEsm",
83
223
  "fix:format": "prettier --write \"src/**/*.ts\"",
84
224
  "fix:lint": "eslint src/ --fix --max-warnings 0",
85
225
  "test:format": "prettier --check \"src/**/*.ts\"",
86
226
  "test:lint": "eslint src/ --max-warnings 0",
87
- "start": "node lib/index.js",
227
+ "start": "node dist/index.js",
88
228
  "dev": "ts-node src/index.ts",
89
229
  "preversion": "pnpm run test:lint",
90
- "version": "pnpm run test:format && pnpm run test:lint && git add -A src"
230
+ "version": "pnpm run test:format && pnpm run test:lint && git add -A src",
231
+ "clean": "rm -rf ./dist"
91
232
  }
92
233
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"aptos.d.ts","sourceRoot":"","sources":["../../src/aptos/aptos.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,SAAS,EACT,SAAS,EACV,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,qBAAa,kBAAmB,SAAQ,kBAAkB;IAEtD,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,QAAQ;IAEhB,OAAO,CAAC,MAAM;gBAHN,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EACxB,UAAU,EAAE,SAAS,EAAE,EACf,MAAM,EAAE,MAAM,EACtB,MAAM,EAAE;QACN,gBAAgB,EAAE,iBAAiB,CAAC;KACrC;IAKG,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;CA6C3E;AAGD,eAAO,MAAM,qBAAqB,wBAAwB,CAAC;AAE3D;;;;;;;;;GASG;AACH,qBAAa,gBAAiB,YAAW,YAAY;IAOjD,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,mBAAmB;IAC3B,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,0BAA0B;IAVpC,OAAO,CAAC,kBAAkB,CAAqB;IAE/C,OAAO,CAAC,oBAAoB,CAAU;gBAG5B,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,MAAM,EAC3B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,0BAA0B,EAAE,MAAM;IAK5C;;;;;;OAMG;IACG,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;IAUhE,eAAe,CACnB,QAAQ,EAAE,MAAM,EAAE,EAClB,cAAc,EAAE,MAAM,EAAE,GACvB,OAAO,CAAC,IAAI,CAAC;YA+DF,8BAA8B;YAwB9B,wBAAwB;CA+BvC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"balance-tracker.d.ts","sourceRoot":"","sources":["../../src/aptos/balance-tracker.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,eAAe,EAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B;;GAEG;AACH,MAAM,WAAW,yBAA0B,SAAQ,wBAAwB;IACzE,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,4BAA4B;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,kBAAkB;IACzD,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAS;gBAEb,MAAM,EAAE,yBAAyB;IAa7C;;;OAGG;cACa,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;CA8B/C;AAED;;GAEG;AACH,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,iBAAiB,CAAC;IAClC,OAAO,EAAE,kBAAkB,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,+BAA+B,GACtC,eAAe,CAUjB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/aptos/command.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;;;;;;;;;;;;;;;kBAuBvB,OAAO;yCAOP,OAAO;;oBAYiB,GAAG;;AA9BpC,wBAuIE"}