@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.
- package/{lib/aptos/aptos.js → dist/aptos/aptos.cjs} +80 -76
- package/{lib → dist}/aptos/aptos.d.ts +5 -5
- package/{lib/aptos/balance-tracker.js → dist/aptos/balance-tracker.cjs} +37 -25
- package/{lib → dist}/aptos/balance-tracker.d.ts +9 -9
- package/dist/aptos/command.cjs +161 -0
- package/{lib → dist}/aptos/command.d.ts +1 -2
- package/dist/common.cjs +4 -0
- package/{lib → dist}/common.d.ts +0 -1
- package/{lib/controller.js → dist/controller.cjs} +35 -33
- package/{lib → dist}/controller.d.ts +5 -6
- package/dist/evm/balance-tracker.cjs +58 -0
- package/{lib → dist}/evm/balance-tracker.d.ts +10 -10
- package/dist/evm/command.cjs +205 -0
- package/{lib → dist}/evm/command.d.ts +1 -2
- package/dist/evm/custom-gas-station.cjs +54 -0
- package/{lib → dist}/evm/custom-gas-station.d.ts +1 -2
- package/dist/evm/evm.cjs +287 -0
- package/{lib → dist}/evm/evm.d.ts +8 -7
- package/{lib/evm/pyth-abi.js → dist/evm/pyth-abi.cjs} +181 -160
- package/{lib → dist}/evm/pyth-abi.d.ts +0 -1
- package/dist/evm/pyth-contract.cjs +17 -0
- package/{lib → dist}/evm/pyth-contract.d.ts +3 -4
- package/dist/evm/super-wallet.cjs +90 -0
- package/{lib → dist}/evm/super-wallet.d.ts +1 -2
- package/dist/fuel/command.cjs +135 -0
- package/{lib → dist}/fuel/command.d.ts +1 -2
- package/dist/fuel/fuel.cjs +108 -0
- package/{lib → dist}/fuel/fuel.d.ts +5 -5
- package/dist/index.cjs +25 -0
- package/dist/index.d.ts +1 -0
- package/dist/injective/command.cjs +150 -0
- package/{lib → dist}/injective/command.d.ts +1 -2
- package/{lib/injective/injective.js → dist/injective/injective.cjs} +100 -98
- package/{lib → dist}/injective/injective.d.ts +7 -6
- package/dist/interface.cjs +142 -0
- package/{lib → dist}/interface.d.ts +12 -13
- package/dist/metrics.cjs +218 -0
- package/{lib → dist}/metrics.d.ts +10 -11
- package/dist/near/command.cjs +129 -0
- package/{lib → dist}/near/command.d.ts +1 -2
- package/dist/near/near.cjs +183 -0
- package/{lib → dist}/near/near.d.ts +5 -5
- package/dist/options.cjs +132 -0
- package/{lib → dist}/options.d.ts +1 -2
- package/dist/package.json +1 -0
- package/dist/price-config.cjs +104 -0
- package/{lib → dist}/price-config.d.ts +5 -6
- package/{lib/pyth-price-listener.js → dist/pyth-price-listener.cjs} +30 -24
- package/{lib → dist}/pyth-price-listener.d.ts +4 -4
- package/dist/solana/balance-tracker.cjs +60 -0
- package/{lib → dist}/solana/balance-tracker.d.ts +9 -9
- package/dist/solana/command.cjs +259 -0
- package/{lib → dist}/solana/command.d.ts +2 -3
- package/{lib/solana/solana.js → dist/solana/solana.cjs} +90 -78
- package/{lib → dist}/solana/solana.d.ts +6 -6
- package/dist/sui/balance-tracker.cjs +58 -0
- package/{lib → dist}/sui/balance-tracker.d.ts +9 -9
- package/dist/sui/command.cjs +190 -0
- package/{lib → dist}/sui/command.d.ts +1 -2
- package/{lib/sui/sui.js → dist/sui/sui.cjs} +145 -133
- package/{lib → dist}/sui/sui.d.ts +7 -8
- package/dist/ton/command.cjs +137 -0
- package/{lib → dist}/ton/command.d.ts +1 -2
- package/dist/ton/ton.cjs +103 -0
- package/{lib → dist}/ton/ton.d.ts +7 -6
- package/dist/utils.cjs +102 -0
- package/{lib → dist}/utils.d.ts +4 -4
- package/package.json +161 -20
- package/lib/aptos/aptos.d.ts.map +0 -1
- package/lib/aptos/balance-tracker.d.ts.map +0 -1
- package/lib/aptos/command.d.ts.map +0 -1
- package/lib/aptos/command.js +0 -126
- package/lib/common.d.ts.map +0 -1
- package/lib/common.js +0 -2
- package/lib/controller.d.ts.map +0 -1
- package/lib/evm/balance-tracker.d.ts.map +0 -1
- package/lib/evm/balance-tracker.js +0 -49
- package/lib/evm/command.d.ts.map +0 -1
- package/lib/evm/command.js +0 -178
- package/lib/evm/custom-gas-station.d.ts.map +0 -1
- package/lib/evm/custom-gas-station.js +0 -40
- package/lib/evm/evm.d.ts.map +0 -1
- package/lib/evm/evm.js +0 -270
- package/lib/evm/pyth-abi.d.ts.map +0 -1
- package/lib/evm/pyth-contract.d.ts.map +0 -1
- package/lib/evm/pyth-contract.js +0 -11
- package/lib/evm/super-wallet.d.ts.map +0 -1
- package/lib/evm/super-wallet.js +0 -73
- package/lib/fuel/command.d.ts.map +0 -1
- package/lib/fuel/command.js +0 -98
- package/lib/fuel/fuel.d.ts.map +0 -1
- package/lib/fuel/fuel.js +0 -101
- package/lib/index.d.ts +0 -3
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -34
- package/lib/injective/command.d.ts.map +0 -1
- package/lib/injective/command.js +0 -119
- package/lib/injective/injective.d.ts.map +0 -1
- package/lib/interface.d.ts.map +0 -1
- package/lib/interface.js +0 -122
- package/lib/metrics.d.ts.map +0 -1
- package/lib/metrics.js +0 -152
- package/lib/near/command.d.ts.map +0 -1
- package/lib/near/command.js +0 -103
- package/lib/near/near.d.ts.map +0 -1
- package/lib/near/near.js +0 -168
- package/lib/options.d.ts.map +0 -1
- package/lib/options.js +0 -84
- package/lib/price-config.d.ts.map +0 -1
- package/lib/price-config.js +0 -114
- package/lib/pyth-price-listener.d.ts.map +0 -1
- package/lib/solana/balance-tracker.d.ts.map +0 -1
- package/lib/solana/balance-tracker.js +0 -51
- package/lib/solana/command.d.ts.map +0 -1
- package/lib/solana/command.js +0 -223
- package/lib/solana/solana.d.ts.map +0 -1
- package/lib/sui/balance-tracker.d.ts.map +0 -1
- package/lib/sui/balance-tracker.js +0 -49
- package/lib/sui/command.d.ts.map +0 -1
- package/lib/sui/command.js +0 -160
- package/lib/sui/sui.d.ts.map +0 -1
- package/lib/ton/command.d.ts.map +0 -1
- package/lib/ton/command.js +0 -99
- package/lib/ton/ton.d.ts.map +0 -1
- package/lib/ton/ton.js +0 -97
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js +0 -61
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "createPythContract", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return createPythContract;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _viem = require("viem");
|
|
12
|
+
const _pythabi = require("./pyth-abi.cjs");
|
|
13
|
+
const createPythContract = (client, address)=>(0, _viem.getContract)({
|
|
14
|
+
client,
|
|
15
|
+
abi: _pythabi.PythAbi,
|
|
16
|
+
address
|
|
17
|
+
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Address, GetContractReturnType } from "viem";
|
|
2
|
-
import { PythAbi } from "./pyth-abi";
|
|
3
|
-
import { SuperWalletClient } from "./super-wallet";
|
|
1
|
+
import type { Address, GetContractReturnType } from "viem";
|
|
2
|
+
import { PythAbi } from "./pyth-abi.js";
|
|
3
|
+
import type { SuperWalletClient } from "./super-wallet.js";
|
|
4
4
|
export type PythContract = GetContractReturnType<typeof PythAbi, SuperWalletClient>;
|
|
5
5
|
export declare const createPythContract: (client: SuperWalletClient, address: Address) => PythContract;
|
|
6
|
-
//# sourceMappingURL=pyth-contract.d.ts.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "createClient", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return createClient;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _viem = require("viem");
|
|
12
|
+
const _accounts = require("viem/accounts");
|
|
13
|
+
const _chains = /*#__PURE__*/ _interop_require_wildcard(require("viem/chains"));
|
|
14
|
+
const _utils = require("../utils.cjs");
|
|
15
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
16
|
+
if (typeof WeakMap !== "function") return null;
|
|
17
|
+
var cacheBabelInterop = new WeakMap();
|
|
18
|
+
var cacheNodeInterop = new WeakMap();
|
|
19
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
20
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
21
|
+
})(nodeInterop);
|
|
22
|
+
}
|
|
23
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
24
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
28
|
+
return {
|
|
29
|
+
default: obj
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
33
|
+
if (cache && cache.has(obj)) {
|
|
34
|
+
return cache.get(obj);
|
|
35
|
+
}
|
|
36
|
+
var newObj = {
|
|
37
|
+
__proto__: null
|
|
38
|
+
};
|
|
39
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
40
|
+
for(var key in obj){
|
|
41
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
42
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
43
|
+
if (desc && (desc.get || desc.set)) {
|
|
44
|
+
Object.defineProperty(newObj, key, desc);
|
|
45
|
+
} else {
|
|
46
|
+
newObj[key] = obj[key];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
newObj.default = obj;
|
|
51
|
+
if (cache) {
|
|
52
|
+
cache.set(obj, newObj);
|
|
53
|
+
}
|
|
54
|
+
return newObj;
|
|
55
|
+
}
|
|
56
|
+
const UNKNOWN_CHAIN_CONFIG = {
|
|
57
|
+
name: "Unknown",
|
|
58
|
+
nativeCurrency: {
|
|
59
|
+
name: "Unknown",
|
|
60
|
+
symbol: "Unknown",
|
|
61
|
+
decimals: 18
|
|
62
|
+
},
|
|
63
|
+
rpcUrls: {
|
|
64
|
+
default: {
|
|
65
|
+
http: []
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
// Get the transport based on the endpoint
|
|
70
|
+
const getTransport = (endpoint)=>(0, _utils.isWsEndpoint)(endpoint) ? (0, _viem.webSocket)(endpoint) : (0, _viem.http)(endpoint);
|
|
71
|
+
// Get the chain corresponding to the chainId. If the chain is not found, it will return
|
|
72
|
+
// an unknown chain which should work fine in most of the cases. We might need to update
|
|
73
|
+
// the viem package to support new chains if they don't work as expected with the unknown
|
|
74
|
+
// chain.
|
|
75
|
+
const getChainById = (chainId)=>// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
76
|
+
Object.values(_chains).find((chain)=>chain.id === chainId) || (0, _viem.defineChain)({
|
|
77
|
+
id: chainId,
|
|
78
|
+
...UNKNOWN_CHAIN_CONFIG
|
|
79
|
+
});
|
|
80
|
+
const createClient = async (endpoint, mnemonic)=>{
|
|
81
|
+
const transport = getTransport(endpoint);
|
|
82
|
+
const chainId = await (0, _viem.createPublicClient)({
|
|
83
|
+
transport
|
|
84
|
+
}).getChainId();
|
|
85
|
+
return (0, _viem.createWalletClient)({
|
|
86
|
+
transport,
|
|
87
|
+
account: (0, _accounts.mnemonicToAccount)(mnemonic),
|
|
88
|
+
chain: getChainById(chainId)
|
|
89
|
+
}).extend(_viem.publicActions);
|
|
90
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Account, Chain, Client, RpcSchema, WalletActions, PublicActions, Transport } from "viem";
|
|
1
|
+
import type { Account, Chain, Client, RpcSchema, WalletActions, PublicActions, Transport } from "viem";
|
|
2
2
|
export type SuperWalletClient = Client<Transport, Chain, Account, RpcSchema, PublicActions<Transport, Chain, Account> & WalletActions<Chain, Account>>;
|
|
3
3
|
export declare const createClient: (endpoint: string, mnemonic: string) => Promise<SuperWalletClient>;
|
|
4
|
-
//# sourceMappingURL=super-wallet.d.ts.map
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-call */ /* 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 _fuels = require("fuels");
|
|
14
|
+
const _pino = /*#__PURE__*/ _interop_require_default(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 _fuel = require("./fuel.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: "fuel",
|
|
69
|
+
describe: "run price pusher for Fuel",
|
|
70
|
+
builder: {
|
|
71
|
+
endpoint: {
|
|
72
|
+
description: "Fuel 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 Fuel",
|
|
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.default)({
|
|
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
|
+
// @ts-expect-error - TODO: this dependency's typings are mismatched and there isn't a create() function on the Provider
|
|
114
|
+
// which may blow up at runtime (but this was existing behavior as of 29 Oct 2025)
|
|
115
|
+
const provider = await _fuels.Provider.create(endpoint);
|
|
116
|
+
const privateKey = _nodefs.default.readFileSync(privateKeyFile, "utf8").trim();
|
|
117
|
+
const wallet = _fuels.Wallet.fromPrivateKey(privateKey, provider);
|
|
118
|
+
const fuelPriceListener = new _fuel.FuelPriceListener(provider, pythContractAddress, priceItems, logger.child({
|
|
119
|
+
module: "FuelPriceListener"
|
|
120
|
+
}), {
|
|
121
|
+
pollingFrequency
|
|
122
|
+
});
|
|
123
|
+
const fuelPricePusher = new _fuel.FuelPricePusher(wallet, pythContractAddress, hermesClient, logger.child({
|
|
124
|
+
module: "FuelPricePusher"
|
|
125
|
+
}));
|
|
126
|
+
const controller = new _controller.Controller(priceConfigs, pythListener, fuelPriceListener, fuelPricePusher, logger.child({
|
|
127
|
+
module: "Controller"
|
|
128
|
+
}, {
|
|
129
|
+
level: controllerLogLevel
|
|
130
|
+
}), {
|
|
131
|
+
pushingFrequency
|
|
132
|
+
});
|
|
133
|
+
void controller.start();
|
|
134
|
+
}
|
|
135
|
+
};
|
|
@@ -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,108 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unsafe-argument */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/restrict-template-expressions */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable no-console */ "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 FuelPriceListener () {
|
|
13
|
+
return FuelPriceListener;
|
|
14
|
+
},
|
|
15
|
+
get FuelPricePusher () {
|
|
16
|
+
return FuelPricePusher;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _pythfueljs = require("@pythnetwork/pyth-fuel-js");
|
|
20
|
+
const _fuels = require("fuels");
|
|
21
|
+
const _interface = require("../interface.cjs");
|
|
22
|
+
const _utils = require("../utils.cjs");
|
|
23
|
+
// Convert TAI64 timestamp to Unix timestamp
|
|
24
|
+
function tai64ToUnix(tai64) {
|
|
25
|
+
// TAI64 is 2^62 seconds ahead of Unix epoch (1970-01-01)
|
|
26
|
+
// Additional 10-second offset accounts for TAI being ahead of UTC at Unix epoch
|
|
27
|
+
const result = BigInt(tai64.toString()) - BigInt(2n ** 62n) - 10n;
|
|
28
|
+
return Number(result);
|
|
29
|
+
}
|
|
30
|
+
class FuelPriceListener extends _interface.ChainPriceListener {
|
|
31
|
+
provider;
|
|
32
|
+
pythContractId;
|
|
33
|
+
logger;
|
|
34
|
+
contract;
|
|
35
|
+
constructor(provider, pythContractId, priceItems, logger, config){
|
|
36
|
+
super(config.pollingFrequency, priceItems), this.provider = provider, this.pythContractId = pythContractId, this.logger = logger;
|
|
37
|
+
this.contract = new _fuels.Contract(this.pythContractId, _pythfueljs.PYTH_CONTRACT_ABI, this.provider);
|
|
38
|
+
}
|
|
39
|
+
async getOnChainPriceInfo(priceId) {
|
|
40
|
+
try {
|
|
41
|
+
const formattedPriceId = (0, _utils.addLeading0x)(priceId);
|
|
42
|
+
const priceInfo = await this.contract.functions.price_unsafe?.(formattedPriceId).get();
|
|
43
|
+
console.log({
|
|
44
|
+
conf: priceInfo?.value.confidence.toString(),
|
|
45
|
+
price: priceInfo?.value.price.toString(),
|
|
46
|
+
publishTime: tai64ToUnix(priceInfo?.value.publish_time)
|
|
47
|
+
});
|
|
48
|
+
this.logger.debug(`Polled a Fuel on chain price for feed ${this.priceIdToAlias.get(priceId)} (${priceId}).`);
|
|
49
|
+
return {
|
|
50
|
+
conf: priceInfo?.value.confidence.toString() ?? "",
|
|
51
|
+
price: priceInfo?.value.price.toString() ?? "",
|
|
52
|
+
publishTime: tai64ToUnix(priceInfo?.value.publish_time)
|
|
53
|
+
};
|
|
54
|
+
} catch (error) {
|
|
55
|
+
this.logger.error({
|
|
56
|
+
err: error,
|
|
57
|
+
priceId
|
|
58
|
+
}, `Polling on-chain price failed.`);
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
class FuelPricePusher {
|
|
64
|
+
wallet;
|
|
65
|
+
pythContractId;
|
|
66
|
+
hermesClient;
|
|
67
|
+
logger;
|
|
68
|
+
contract;
|
|
69
|
+
constructor(wallet, pythContractId, hermesClient, logger){
|
|
70
|
+
this.wallet = wallet;
|
|
71
|
+
this.pythContractId = pythContractId;
|
|
72
|
+
this.hermesClient = hermesClient;
|
|
73
|
+
this.logger = logger;
|
|
74
|
+
this.contract = new _fuels.Contract(this.pythContractId, _pythfueljs.PYTH_CONTRACT_ABI, this.wallet);
|
|
75
|
+
}
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
77
|
+
async updatePriceFeed(priceIds, _) {
|
|
78
|
+
if (priceIds.length === 0) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
let priceFeedUpdateData;
|
|
82
|
+
try {
|
|
83
|
+
const response = await this.hermesClient.getLatestPriceUpdates(priceIds, {
|
|
84
|
+
encoding: "base64",
|
|
85
|
+
ignoreInvalidPriceIds: true
|
|
86
|
+
});
|
|
87
|
+
priceFeedUpdateData = response.binary.data;
|
|
88
|
+
} catch (error) {
|
|
89
|
+
this.logger.error(error, "getPriceFeedsUpdateData failed");
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const updateData = priceFeedUpdateData.map((data)=>(0, _fuels.arrayify)(data));
|
|
93
|
+
try {
|
|
94
|
+
const updateFee = await this.contract.functions.update_fee?.(updateData).get();
|
|
95
|
+
const result = await this.contract.functions.update_price_feeds?.(updateData).callParams({
|
|
96
|
+
forward: [
|
|
97
|
+
updateFee?.value,
|
|
98
|
+
(0, _fuels.hexlify)(_pythfueljs.FUEL_ETH_ASSET_ID)
|
|
99
|
+
]
|
|
100
|
+
}).call();
|
|
101
|
+
this.logger.info({
|
|
102
|
+
transactionId: result?.transactionId
|
|
103
|
+
}, "updatePriceFeed successful");
|
|
104
|
+
} catch (error) {
|
|
105
|
+
this.logger.error(error, "updatePriceFeed failed");
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
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
2
|
import { Provider, Wallet } from "fuels";
|
|
3
|
+
import type { Logger } from "pino";
|
|
4
|
+
import type { IPricePusher, PriceInfo, PriceItem } from "../interface.js";
|
|
5
|
+
import { ChainPriceListener } from "../interface.js";
|
|
6
|
+
import type { DurationInSeconds } from "../utils.js";
|
|
6
7
|
export declare class FuelPriceListener extends ChainPriceListener {
|
|
7
8
|
private provider;
|
|
8
9
|
private pythContractId;
|
|
@@ -20,6 +21,5 @@ export declare class FuelPricePusher implements IPricePusher {
|
|
|
20
21
|
private logger;
|
|
21
22
|
private contract;
|
|
22
23
|
constructor(wallet: Wallet, pythContractId: string, hermesClient: HermesClient, logger: Logger);
|
|
23
|
-
updatePriceFeed(priceIds: string[],
|
|
24
|
+
updatePriceFeed(priceIds: string[], _: number[]): Promise<void>;
|
|
24
25
|
}
|
|
25
|
-
//# sourceMappingURL=fuel.d.ts.map
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _yargs = /*#__PURE__*/ _interop_require_default(require("yargs"));
|
|
6
|
+
const _helpers = require("yargs/helpers");
|
|
7
|
+
const _command = /*#__PURE__*/ _interop_require_default(require("./aptos/command.cjs"));
|
|
8
|
+
const _command1 = /*#__PURE__*/ _interop_require_default(require("./evm/command.cjs"));
|
|
9
|
+
const _command2 = /*#__PURE__*/ _interop_require_default(require("./fuel/command.cjs"));
|
|
10
|
+
const _command3 = /*#__PURE__*/ _interop_require_default(require("./injective/command.cjs"));
|
|
11
|
+
const _command4 = /*#__PURE__*/ _interop_require_default(require("./near/command.cjs"));
|
|
12
|
+
const _options = require("./options.cjs");
|
|
13
|
+
const _command5 = /*#__PURE__*/ _interop_require_default(require("./solana/command.cjs"));
|
|
14
|
+
const _command6 = /*#__PURE__*/ _interop_require_default(require("./sui/command.cjs"));
|
|
15
|
+
const _command7 = /*#__PURE__*/ _interop_require_default(require("./ton/command.cjs"));
|
|
16
|
+
function _interop_require_default(obj) {
|
|
17
|
+
return obj && obj.__esModule ? obj : {
|
|
18
|
+
default: obj
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const yargs = (0, _yargs.default)((0, _helpers.hideBin)(process.argv));
|
|
22
|
+
// let the application run but don't await on the value here, per existing behavior
|
|
23
|
+
void yargs.parserConfiguration({
|
|
24
|
+
"parse-numbers": false
|
|
25
|
+
}).config("config").global("config").option("enable-metrics", _options.enableMetrics["enable-metrics"]).option("metrics-port", _options.metricsPort["metrics-port"]).command(_command1.default).command(_command2.default).command(_command3.default).command(_command.default).command(_command6.default).command(_command4.default).command(_command5.default).command(_command7.default).help().argv;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,150 @@
|
|
|
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 _networks = require("@injectivelabs/networks");
|
|
13
|
+
const _hermesclient = require("@pythnetwork/hermes-client");
|
|
14
|
+
const _pino = require("pino");
|
|
15
|
+
const _options = /*#__PURE__*/ _interop_require_wildcard(require("../options.cjs"));
|
|
16
|
+
const _priceconfig = require("../price-config.cjs");
|
|
17
|
+
const _injective = require("./injective.cjs");
|
|
18
|
+
const _controller = require("../controller.cjs");
|
|
19
|
+
const _pythpricelistener = require("../pyth-price-listener.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: "injective",
|
|
69
|
+
describe: "run price pusher for injective",
|
|
70
|
+
builder: {
|
|
71
|
+
"grpc-endpoint": {
|
|
72
|
+
description: "gRPC endpoint URL for injective. The pusher will periodically" + "poll for updates. The polling interval is configurable via the " + "`polling-frequency` command-line argument.",
|
|
73
|
+
type: "string",
|
|
74
|
+
required: true
|
|
75
|
+
},
|
|
76
|
+
network: {
|
|
77
|
+
description: "testnet or mainnet",
|
|
78
|
+
type: "string",
|
|
79
|
+
required: true
|
|
80
|
+
},
|
|
81
|
+
"gas-price": {
|
|
82
|
+
description: "Gas price to be used for each transaction",
|
|
83
|
+
type: "number"
|
|
84
|
+
},
|
|
85
|
+
"gas-multiplier": {
|
|
86
|
+
description: "Gas multiplier to be used for each transaction",
|
|
87
|
+
type: "number"
|
|
88
|
+
},
|
|
89
|
+
"price-ids-process-chunk-size": {
|
|
90
|
+
description: "Set in case we wanna split price feeds updates into chunks to have smaller transactions. Set to -1 to disable chunking.",
|
|
91
|
+
type: "number",
|
|
92
|
+
required: false
|
|
93
|
+
},
|
|
94
|
+
..._options.priceConfigFile,
|
|
95
|
+
..._options.priceServiceEndpoint,
|
|
96
|
+
..._options.mnemonicFile,
|
|
97
|
+
..._options.pythContractAddress,
|
|
98
|
+
..._options.pollingFrequency,
|
|
99
|
+
..._options.pushingFrequency,
|
|
100
|
+
..._options.logLevel,
|
|
101
|
+
..._options.controllerLogLevel
|
|
102
|
+
},
|
|
103
|
+
handler: async function(argv) {
|
|
104
|
+
// FIXME: type checks for this
|
|
105
|
+
const { network, logLevel, gasPrice, grpcEndpoint, mnemonicFile, gasMultiplier, priceConfigFile, pollingFrequency, pushingFrequency, controllerLogLevel, pythContractAddress, priceServiceEndpoint, priceIdsProcessChunkSize } = argv;
|
|
106
|
+
const logger = (0, _pino.pino)({
|
|
107
|
+
level: logLevel
|
|
108
|
+
});
|
|
109
|
+
if (network !== "testnet" && network !== "mainnet") {
|
|
110
|
+
throw new Error("Please specify network. One of [testnet, mainnet]");
|
|
111
|
+
}
|
|
112
|
+
const priceConfigs = (0, _priceconfig.readPriceConfigFile)(priceConfigFile);
|
|
113
|
+
const hermesClient = new _hermesclient.HermesClient(priceServiceEndpoint);
|
|
114
|
+
const mnemonic = _nodefs.default.readFileSync(mnemonicFile, "utf8").trim();
|
|
115
|
+
let priceItems = priceConfigs.map(({ id, alias })=>({
|
|
116
|
+
id,
|
|
117
|
+
alias
|
|
118
|
+
}));
|
|
119
|
+
// Better to filter out invalid price items before creating the pyth listener
|
|
120
|
+
const { existingPriceItems, invalidPriceItems } = await (0, _utils.filterInvalidPriceItems)(hermesClient, priceItems);
|
|
121
|
+
if (invalidPriceItems.length > 0) {
|
|
122
|
+
logger.error(`Invalid price id submitted for: ${invalidPriceItems.map(({ alias })=>alias).join(", ")}`);
|
|
123
|
+
}
|
|
124
|
+
priceItems = existingPriceItems;
|
|
125
|
+
const pythListener = new _pythpricelistener.PythPriceListener(hermesClient, priceItems, logger.child({
|
|
126
|
+
module: "PythPriceListener"
|
|
127
|
+
}));
|
|
128
|
+
const injectiveListener = new _injective.InjectivePriceListener(pythContractAddress, grpcEndpoint, priceItems, logger.child({
|
|
129
|
+
module: "InjectivePriceListener"
|
|
130
|
+
}), {
|
|
131
|
+
pollingFrequency
|
|
132
|
+
});
|
|
133
|
+
const injectivePusher = new _injective.InjectivePricePusher(hermesClient, pythContractAddress, grpcEndpoint, logger.child({
|
|
134
|
+
module: "InjectivePricePusher"
|
|
135
|
+
}), mnemonic, {
|
|
136
|
+
chainId: (0, _networks.getNetworkInfo)(network).chainId,
|
|
137
|
+
gasPrice,
|
|
138
|
+
gasMultiplier,
|
|
139
|
+
priceIdsProcessChunkSize
|
|
140
|
+
});
|
|
141
|
+
const controller = new _controller.Controller(priceConfigs, pythListener, injectiveListener, injectivePusher, logger.child({
|
|
142
|
+
module: "Controller"
|
|
143
|
+
}, {
|
|
144
|
+
level: controllerLogLevel
|
|
145
|
+
}), {
|
|
146
|
+
pushingFrequency
|
|
147
|
+
});
|
|
148
|
+
void controller.start();
|
|
149
|
+
}
|
|
150
|
+
};
|
|
@@ -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;
|
|
@@ -20,4 +20,3 @@ declare const _default: {
|
|
|
20
20
|
handler: (argv: any) => Promise<void>;
|
|
21
21
|
};
|
|
22
22
|
export default _default;
|
|
23
|
-
//# sourceMappingURL=command.d.ts.map
|