@pythnetwork/price-pusher 9.0.1 → 9.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -1
- package/lib/aptos/balance-tracker.d.ts +46 -0
- package/lib/aptos/balance-tracker.d.ts.map +1 -0
- package/lib/aptos/balance-tracker.js +61 -0
- package/lib/aptos/command.d.ts +2 -0
- package/lib/aptos/command.d.ts.map +1 -1
- package/lib/aptos/command.js +46 -9
- package/lib/controller.d.ts +3 -0
- package/lib/controller.d.ts.map +1 -1
- package/lib/controller.js +37 -1
- package/lib/evm/balance-tracker.d.ts +42 -0
- package/lib/evm/balance-tracker.d.ts.map +1 -0
- package/lib/evm/balance-tracker.js +49 -0
- package/lib/evm/command.d.ts +3 -0
- package/lib/evm/command.d.ts.map +1 -1
- package/lib/evm/command.js +53 -11
- package/lib/evm/evm.d.ts +2 -1
- package/lib/evm/evm.d.ts.map +1 -1
- package/lib/evm/evm.js +6 -3
- package/lib/evm/pyth-contract.d.ts.map +1 -1
- package/lib/evm/super-wallet.d.ts.map +1 -1
- package/lib/evm/super-wallet.js +17 -7
- package/lib/fuel/command.js +17 -7
- package/lib/index.js +3 -0
- package/lib/injective/command.d.ts +1 -0
- package/lib/injective/command.d.ts.map +1 -1
- package/lib/injective/command.js +26 -10
- package/lib/injective/injective.d.ts +2 -0
- package/lib/injective/injective.d.ts.map +1 -1
- package/lib/injective/injective.js +22 -7
- package/lib/interface.d.ts +51 -0
- package/lib/interface.d.ts.map +1 -1
- package/lib/interface.js +80 -1
- package/lib/metrics.d.ts +22 -0
- package/lib/metrics.d.ts.map +1 -0
- package/lib/metrics.js +113 -0
- package/lib/near/command.js +17 -7
- package/lib/options.d.ts +6 -0
- package/lib/options.d.ts.map +1 -1
- package/lib/options.js +17 -1
- package/lib/price-config.d.ts.map +1 -1
- package/lib/price-config.js +5 -1
- package/lib/solana/balance-tracker.d.ts +42 -0
- package/lib/solana/balance-tracker.d.ts.map +1 -0
- package/lib/solana/balance-tracker.js +51 -0
- package/lib/solana/command.d.ts +2 -0
- package/lib/solana/command.d.ts.map +1 -1
- package/lib/solana/command.js +48 -10
- package/lib/solana/solana.d.ts.map +1 -1
- package/lib/solana/solana.js +1 -1
- package/lib/sui/balance-tracker.d.ts +39 -0
- package/lib/sui/balance-tracker.d.ts.map +1 -0
- package/lib/sui/balance-tracker.js +54 -0
- package/lib/sui/command.d.ts +2 -0
- package/lib/sui/command.d.ts.map +1 -1
- package/lib/sui/command.js +50 -12
- package/lib/sui/sui.d.ts.map +1 -1
- package/lib/ton/command.js +17 -7
- package/lib/utils.d.ts +2 -2
- package/lib/utils.d.ts.map +1 -1
- package/package.json +17 -10
package/lib/evm/command.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
|
@@ -38,6 +48,8 @@ const pino_1 = __importDefault(require("pino"));
|
|
|
38
48
|
const super_wallet_1 = require("./super-wallet");
|
|
39
49
|
const pyth_contract_1 = require("./pyth-contract");
|
|
40
50
|
const utils_1 = require("../utils");
|
|
51
|
+
const metrics_1 = require("../metrics");
|
|
52
|
+
const balance_tracker_1 = require("./balance-tracker");
|
|
41
53
|
exports.default = {
|
|
42
54
|
command: "evm",
|
|
43
55
|
describe: "run price pusher for evm",
|
|
@@ -82,6 +94,11 @@ exports.default = {
|
|
|
82
94
|
type: "number",
|
|
83
95
|
required: false,
|
|
84
96
|
},
|
|
97
|
+
"gas-price": {
|
|
98
|
+
description: "Override the gas price that would be received from the RPC",
|
|
99
|
+
type: "number",
|
|
100
|
+
required: false,
|
|
101
|
+
},
|
|
85
102
|
"update-fee-multiplier": {
|
|
86
103
|
description: "Multiplier for the fee to update the price. It is useful in networks " +
|
|
87
104
|
"such as Hedera where setting on-chain getUpdateFee as the transaction value " +
|
|
@@ -98,10 +115,12 @@ exports.default = {
|
|
|
98
115
|
...options.pushingFrequency,
|
|
99
116
|
...options.logLevel,
|
|
100
117
|
...options.controllerLogLevel,
|
|
118
|
+
...options.enableMetrics,
|
|
119
|
+
...options.metricsPort,
|
|
101
120
|
},
|
|
102
121
|
handler: async function (argv) {
|
|
103
122
|
// FIXME: type checks for this
|
|
104
|
-
const { endpoint, priceConfigFile, priceServiceEndpoint, mnemonicFile, pythContractAddress, pushingFrequency, pollingFrequency, customGasStation, txSpeed, overrideGasPriceMultiplier, overrideGasPriceMultiplierCap, gasLimit, updateFeeMultiplier, logLevel, controllerLogLevel, } = argv;
|
|
123
|
+
const { endpoint, priceConfigFile, priceServiceEndpoint, mnemonicFile, pythContractAddress, pushingFrequency, pollingFrequency, customGasStation, txSpeed, overrideGasPriceMultiplier, overrideGasPriceMultiplierCap, gasLimit, gasPrice, updateFeeMultiplier, logLevel, controllerLogLevel, enableMetrics, metricsPort, } = argv;
|
|
105
124
|
console.log("***** priceServiceEndpoint *****", priceServiceEndpoint);
|
|
106
125
|
const logger = (0, pino_1.default)({
|
|
107
126
|
level: logLevel,
|
|
@@ -118,6 +137,13 @@ exports.default = {
|
|
|
118
137
|
.join(", ")}`);
|
|
119
138
|
}
|
|
120
139
|
priceItems = existingPriceItems;
|
|
140
|
+
// Initialize metrics if enabled
|
|
141
|
+
let metrics;
|
|
142
|
+
if (enableMetrics) {
|
|
143
|
+
metrics = new metrics_1.PricePusherMetrics(logger.child({ module: "Metrics" }));
|
|
144
|
+
metrics.start(metricsPort);
|
|
145
|
+
logger.info(`Metrics server started on port ${metricsPort}`);
|
|
146
|
+
}
|
|
121
147
|
const pythListener = new pyth_price_listener_1.PythPriceListener(hermesClient, priceItems, logger.child({ module: "PythPriceListener" }));
|
|
122
148
|
const client = await (0, super_wallet_1.createClient)(endpoint, mnemonic);
|
|
123
149
|
const pythContract = (0, pyth_contract_1.createPythContract)(client, pythContractAddress);
|
|
@@ -130,8 +156,24 @@ exports.default = {
|
|
|
130
156
|
pollingFrequency,
|
|
131
157
|
});
|
|
132
158
|
const gasStation = (0, custom_gas_station_1.getCustomGasStation)(logger.child({ module: "CustomGasStation" }), customGasStation, txSpeed);
|
|
133
|
-
const evmPusher = new evm_1.EvmPricePusher(hermesClient, client, pythContract, logger.child({ module: "EvmPricePusher" }), overrideGasPriceMultiplier, overrideGasPriceMultiplierCap, updateFeeMultiplier, gasLimit, gasStation);
|
|
134
|
-
const controller = new controller_1.Controller(priceConfigs, pythListener, evmListener, evmPusher, logger.child({ module: "Controller" }, { level: controllerLogLevel }), {
|
|
135
|
-
|
|
159
|
+
const evmPusher = new evm_1.EvmPricePusher(hermesClient, client, pythContract, logger.child({ module: "EvmPricePusher" }), overrideGasPriceMultiplier, overrideGasPriceMultiplierCap, updateFeeMultiplier, gasLimit, gasStation, gasPrice);
|
|
160
|
+
const controller = new controller_1.Controller(priceConfigs, pythListener, evmListener, evmPusher, logger.child({ module: "Controller" }, { level: controllerLogLevel }), {
|
|
161
|
+
pushingFrequency,
|
|
162
|
+
metrics,
|
|
163
|
+
});
|
|
164
|
+
// Create and start the balance tracker if metrics are enabled
|
|
165
|
+
if (metrics) {
|
|
166
|
+
const balanceTracker = (0, balance_tracker_1.createEvmBalanceTracker)({
|
|
167
|
+
client,
|
|
168
|
+
address: client.account.address,
|
|
169
|
+
network: await client.getChainId().then((id) => id.toString()),
|
|
170
|
+
updateInterval: pushingFrequency,
|
|
171
|
+
metrics,
|
|
172
|
+
logger,
|
|
173
|
+
});
|
|
174
|
+
// Start the balance tracker
|
|
175
|
+
await balanceTracker.start();
|
|
176
|
+
}
|
|
177
|
+
await controller.start();
|
|
136
178
|
},
|
|
137
179
|
};
|
package/lib/evm/evm.d.ts
CHANGED
|
@@ -27,9 +27,10 @@ export declare class EvmPricePusher implements IPricePusher {
|
|
|
27
27
|
private updateFeeMultiplier;
|
|
28
28
|
private gasLimit?;
|
|
29
29
|
private customGasStation?;
|
|
30
|
+
private gasPrice?;
|
|
30
31
|
private pusherAddress;
|
|
31
32
|
private lastPushAttempt;
|
|
32
|
-
constructor(hermesClient: HermesClient, client: SuperWalletClient, pythContract: PythContract, logger: Logger, overrideGasPriceMultiplier: number, overrideGasPriceMultiplierCap: number, updateFeeMultiplier: number, gasLimit?: number | undefined, customGasStation?: CustomGasStation | undefined);
|
|
33
|
+
constructor(hermesClient: HermesClient, client: SuperWalletClient, pythContract: PythContract, logger: Logger, overrideGasPriceMultiplier: number, overrideGasPriceMultiplierCap: number, updateFeeMultiplier: number, gasLimit?: number | undefined, customGasStation?: CustomGasStation | undefined, gasPrice?: number | undefined);
|
|
33
34
|
updatePriceFeed(priceIds: string[], pubTimesToPush: UnixTimestamp[]): Promise<void>;
|
|
34
35
|
private waitForTransactionReceipt;
|
|
35
36
|
private getPriceFeedsUpdateData;
|
package/lib/evm/evm.d.ts.map
CHANGED
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CAA0B;gBAGvC,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,iBAAiB,EACzB,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,MAAM,EACd,0BAA0B,EAAE,MAAM,EAClC,6BAA6B,EAAE,MAAM,EACrC,mBAAmB,EAAE,MAAM,EAC3B,QAAQ,CAAC,EAAE,MAAM,YAAA,EACjB,gBAAgB,CAAC,EAAE,gBAAgB,YAAA,EACnC,QAAQ,CAAC,EAAE,MAAM,YAAA;IASrB,eAAe,CACnB,QAAQ,EAAE,MAAM,EAAE,EAClB,cAAc,EAAE,aAAa,EAAE,GAC9B,OAAO,CAAC,IAAI,CAAC;YAkPF,yBAAyB;YAuBzB,uBAAuB;CAStC"}
|
package/lib/evm/evm.js
CHANGED
|
@@ -75,9 +75,10 @@ class EvmPricePusher {
|
|
|
75
75
|
updateFeeMultiplier;
|
|
76
76
|
gasLimit;
|
|
77
77
|
customGasStation;
|
|
78
|
+
gasPrice;
|
|
78
79
|
pusherAddress;
|
|
79
80
|
lastPushAttempt;
|
|
80
|
-
constructor(hermesClient, client, pythContract, logger, overrideGasPriceMultiplier, overrideGasPriceMultiplierCap, updateFeeMultiplier, gasLimit, customGasStation) {
|
|
81
|
+
constructor(hermesClient, client, pythContract, logger, overrideGasPriceMultiplier, overrideGasPriceMultiplierCap, updateFeeMultiplier, gasLimit, customGasStation, gasPrice) {
|
|
81
82
|
this.hermesClient = hermesClient;
|
|
82
83
|
this.client = client;
|
|
83
84
|
this.pythContract = pythContract;
|
|
@@ -87,6 +88,7 @@ class EvmPricePusher {
|
|
|
87
88
|
this.updateFeeMultiplier = updateFeeMultiplier;
|
|
88
89
|
this.gasLimit = gasLimit;
|
|
89
90
|
this.customGasStation = customGasStation;
|
|
91
|
+
this.gasPrice = gasPrice;
|
|
90
92
|
}
|
|
91
93
|
// The pubTimes are passed here to use the values that triggered the push.
|
|
92
94
|
// This is an optimization to avoid getting a newer value (as an update comes)
|
|
@@ -118,8 +120,9 @@ class EvmPricePusher {
|
|
|
118
120
|
// addition of baseFee and priorityFee required to land the transaction. We
|
|
119
121
|
// are using this to remain compatible with the networks that doesn't
|
|
120
122
|
// support this transaction type.
|
|
121
|
-
let gasPrice =
|
|
122
|
-
Number(await this.
|
|
123
|
+
let gasPrice = this.gasPrice ??
|
|
124
|
+
Number(await (this.customGasStation?.getCustomGasPrice() ??
|
|
125
|
+
this.client.getGasPrice()));
|
|
123
126
|
// Try to re-use the same nonce and increase the gas if the last tx is not landed yet.
|
|
124
127
|
if (this.pusherAddress === undefined) {
|
|
125
128
|
this.pusherAddress = this.client.account.address;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pyth-contract.d.ts","sourceRoot":"","sources":["../../src/evm/pyth-contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,OAAO,EAAE,qBAAqB,EAAE,MAAM,MAAM,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,MAAM,MAAM,YAAY,GAAG,qBAAqB,CAC9C,OAAO,OAAO,EACd,iBAAiB,CAClB,CAAC;AAEF,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"pyth-contract.d.ts","sourceRoot":"","sources":["../../src/evm/pyth-contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,OAAO,EAAE,qBAAqB,EAAE,MAAM,MAAM,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,MAAM,MAAM,YAAY,GAAG,qBAAqB,CAC9C,OAAO,OAAO,EACd,iBAAiB,CAClB,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,iBAAiB,EACzB,SAAS,OAAO,KACf,YAKC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"super-wallet.d.ts","sourceRoot":"","sources":["../../src/evm/super-wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,OAAO,EACP,KAAK,EAEL,MAAM,EACN,SAAS,EACT,aAAa,EACb,aAAa,EAGb,SAAS,EACV,MAAM,MAAM,CAAC;AAmBd,MAAM,MAAM,iBAAiB,GAAG,MAAM,CACpC,SAAS,EACT,KAAK,EACL,OAAO,EACP,SAAS,EACT,aAAa,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,CACzE,CAAC;AAcF,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"super-wallet.d.ts","sourceRoot":"","sources":["../../src/evm/super-wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,OAAO,EACP,KAAK,EAEL,MAAM,EACN,SAAS,EACT,aAAa,EACb,aAAa,EAGb,SAAS,EACV,MAAM,MAAM,CAAC;AAmBd,MAAM,MAAM,iBAAiB,GAAG,MAAM,CACpC,SAAS,EACT,KAAK,EACL,OAAO,EACP,SAAS,EACT,aAAa,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,CACzE,CAAC;AAcF,eAAO,MAAM,YAAY,GACvB,UAAU,MAAM,EAChB,UAAU,MAAM,KACf,OAAO,CAAC,iBAAiB,CAY3B,CAAC"}
|
package/lib/evm/super-wallet.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.createClient = void 0;
|
|
27
37
|
const viem_1 = require("viem");
|
package/lib/fuel/command.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
package/lib/index.js
CHANGED
|
@@ -14,12 +14,15 @@ const command_5 = __importDefault(require("./near/command"));
|
|
|
14
14
|
const command_6 = __importDefault(require("./solana/command"));
|
|
15
15
|
const command_7 = __importDefault(require("./fuel/command"));
|
|
16
16
|
const command_8 = __importDefault(require("./ton/command"));
|
|
17
|
+
const options_1 = require("./options");
|
|
17
18
|
(0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
18
19
|
.parserConfiguration({
|
|
19
20
|
"parse-numbers": false,
|
|
20
21
|
})
|
|
21
22
|
.config("config")
|
|
22
23
|
.global("config")
|
|
24
|
+
.option("enable-metrics", options_1.enableMetrics["enable-metrics"])
|
|
25
|
+
.option("metrics-port", options_1.metricsPort["metrics-port"])
|
|
23
26
|
.command(command_2.default)
|
|
24
27
|
.command(command_7.default)
|
|
25
28
|
.command(command_1.default)
|
|
@@ -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;;;;;;;;;;;;;yBAevB,OAAO;iBAKP,OAAO;qBAIP,OAAO;0BAIP,OAAO;;oBAUiB,GAAG;;
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/injective/command.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;;;;;;;;;;;;;yBAevB,OAAO;iBAKP,OAAO;qBAIP,OAAO;0BAIP,OAAO;wCAMP,OAAO;;oBAUiB,GAAG;;AAxCpC,wBA4HE"}
|
package/lib/injective/command.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
|
@@ -53,12 +63,17 @@ exports.default = {
|
|
|
53
63
|
required: true,
|
|
54
64
|
},
|
|
55
65
|
"gas-price": {
|
|
56
|
-
description: "Gas price to be used for each
|
|
66
|
+
description: "Gas price to be used for each transaction",
|
|
57
67
|
type: "number",
|
|
58
68
|
},
|
|
59
69
|
"gas-multiplier": {
|
|
60
|
-
description: "Gas multiplier to be used for each
|
|
70
|
+
description: "Gas multiplier to be used for each transaction",
|
|
71
|
+
type: "number",
|
|
72
|
+
},
|
|
73
|
+
"price-ids-process-chunk-size": {
|
|
74
|
+
description: "Set in case we wanna split price feeds updates into chunks to have smaller transactions. Set to -1 to disable chunking.",
|
|
61
75
|
type: "number",
|
|
76
|
+
required: false,
|
|
62
77
|
},
|
|
63
78
|
...options.priceConfigFile,
|
|
64
79
|
...options.priceServiceEndpoint,
|
|
@@ -71,7 +86,7 @@ exports.default = {
|
|
|
71
86
|
},
|
|
72
87
|
handler: async function (argv) {
|
|
73
88
|
// FIXME: type checks for this
|
|
74
|
-
const {
|
|
89
|
+
const { network, logLevel, gasPrice, grpcEndpoint, mnemonicFile, gasMultiplier, priceConfigFile, pollingFrequency, pushingFrequency, controllerLogLevel, pythContractAddress, priceServiceEndpoint, priceIdsProcessChunkSize, } = argv;
|
|
75
90
|
const logger = (0, pino_1.default)({ level: logLevel });
|
|
76
91
|
if (network !== "testnet" && network !== "mainnet") {
|
|
77
92
|
throw new Error("Please specify network. One of [testnet, mainnet]");
|
|
@@ -96,6 +111,7 @@ exports.default = {
|
|
|
96
111
|
chainId: (0, networks_1.getNetworkInfo)(network).chainId,
|
|
97
112
|
gasPrice,
|
|
98
113
|
gasMultiplier,
|
|
114
|
+
priceIdsProcessChunkSize,
|
|
99
115
|
});
|
|
100
116
|
const controller = new controller_1.Controller(priceConfigs, pythListener, injectiveListener, injectivePusher, logger.child({ module: "Controller" }, { level: controllerLogLevel }), { pushingFrequency });
|
|
101
117
|
controller.start();
|
|
@@ -15,6 +15,7 @@ type InjectiveConfig = {
|
|
|
15
15
|
chainId: string;
|
|
16
16
|
gasMultiplier: number;
|
|
17
17
|
gasPrice: number;
|
|
18
|
+
priceIdsProcessChunkSize: number;
|
|
18
19
|
};
|
|
19
20
|
export declare class InjectivePricePusher implements IPricePusher {
|
|
20
21
|
private hermesClient;
|
|
@@ -29,6 +30,7 @@ export declare class InjectivePricePusher implements IPricePusher {
|
|
|
29
30
|
private signAndBroadcastMsg;
|
|
30
31
|
getPriceFeedUpdateObject(priceIds: string[]): Promise<any>;
|
|
31
32
|
updatePriceFeed(priceIds: string[], pubTimesToPush: number[]): Promise<void>;
|
|
33
|
+
private updatePriceFeedChunk;
|
|
32
34
|
}
|
|
33
35
|
export {};
|
|
34
36
|
//# sourceMappingURL=injective.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injective.d.ts","sourceRoot":"","sources":["../../src/injective/injective.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EACL,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,SAAS,EACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"injective.d.ts","sourceRoot":"","sources":["../../src/injective/injective.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EACL,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,SAAS,EACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAa7C,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAyB9B,qBAAa,sBAAuB,SAAQ,kBAAkB;IAE1D,OAAO,CAAC,mBAAmB;IAC3B,OAAO,CAAC,YAAY;IAEpB,OAAO,CAAC,MAAM;gBAHN,mBAAmB,EAAE,MAAM,EAC3B,YAAY,EAAE,MAAM,EAC5B,UAAU,EAAE,SAAS,EAAE,EACf,MAAM,EAAE,MAAM,EACtB,MAAM,EAAE;QACN,gBAAgB,EAAE,iBAAiB,CAAC;KACrC;IAKG,mBAAmB,CACvB,OAAO,EAAE,SAAS,GACjB,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;CA4BlC;AAED,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,wBAAwB,EAAE,MAAM,CAAC;CAClC,CAAC;AACF,qBAAa,oBAAqB,YAAW,YAAY;IAMrD,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,mBAAmB;IAC3B,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,MAAM;IARhB,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,OAAO,CAAwB;gBAG7B,YAAY,EAAE,YAAY,EAC1B,mBAAmB,EAAE,MAAM,EAC3B,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC;IAcxC,OAAO,CAAC,gBAAgB;YAIV,mBAAmB;IAmE3B,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IAa1D,eAAe,CACnB,QAAQ,EAAE,MAAM,EAAE,EAClB,cAAc,EAAE,MAAM,EAAE,GACvB,OAAO,CAAC,IAAI,CAAC;YAqBF,oBAAoB;CA0EnC"}
|
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.InjectivePricePusher = exports.InjectivePriceListener = void 0;
|
|
4
4
|
const interface_1 = require("../interface");
|
|
5
5
|
const sdk_ts_1 = require("@injectivelabs/sdk-ts");
|
|
6
|
+
const utils_1 = require("@injectivelabs/utils");
|
|
6
7
|
const DEFAULT_GAS_PRICE = 160000000;
|
|
7
8
|
const DEFAULT_GAS_MULTIPLIER = 1.05;
|
|
9
|
+
const DEFAULT_PRICE_IDS_PROCESS_CHUNK_SIZE = -1;
|
|
8
10
|
const INJECTIVE_TESTNET_CHAIN_ID = "injective-888";
|
|
9
11
|
// this use price without leading 0x
|
|
10
12
|
class InjectivePriceListener extends interface_1.ChainPriceListener {
|
|
@@ -56,6 +58,8 @@ class InjectivePricePusher {
|
|
|
56
58
|
chainId: chainConfig?.chainId ?? INJECTIVE_TESTNET_CHAIN_ID,
|
|
57
59
|
gasMultiplier: chainConfig?.gasMultiplier ?? DEFAULT_GAS_MULTIPLIER,
|
|
58
60
|
gasPrice: chainConfig?.gasPrice ?? DEFAULT_GAS_PRICE,
|
|
61
|
+
priceIdsProcessChunkSize: chainConfig?.priceIdsProcessChunkSize ??
|
|
62
|
+
DEFAULT_PRICE_IDS_PROCESS_CHUNK_SIZE,
|
|
59
63
|
};
|
|
60
64
|
}
|
|
61
65
|
injectiveAddress() {
|
|
@@ -72,7 +76,7 @@ class InjectivePricePusher {
|
|
|
72
76
|
chainId: this.chainConfig.chainId,
|
|
73
77
|
pubKey: this.wallet.toPublicKey().toBase64(),
|
|
74
78
|
});
|
|
75
|
-
const txService = new sdk_ts_1.
|
|
79
|
+
const txService = new sdk_ts_1.TxGrpcApi(this.grpcEndpoint);
|
|
76
80
|
// simulation
|
|
77
81
|
try {
|
|
78
82
|
const { gasInfo: { gasUsed }, } = await txService.simulate(simulateTxRaw);
|
|
@@ -132,13 +136,24 @@ class InjectivePricePusher {
|
|
|
132
136
|
}
|
|
133
137
|
if (priceIds.length !== pubTimesToPush.length)
|
|
134
138
|
throw new Error("Invalid arguments");
|
|
139
|
+
const priceIdChunks = this.chainConfig.priceIdsProcessChunkSize === -1
|
|
140
|
+
? [priceIds]
|
|
141
|
+
: (0, utils_1.splitArrayToChunks)({
|
|
142
|
+
array: priceIds,
|
|
143
|
+
chunkSize: this.chainConfig.priceIdsProcessChunkSize,
|
|
144
|
+
});
|
|
145
|
+
for (const [chunkIndex, priceIdChunk] of priceIdChunks.entries()) {
|
|
146
|
+
await this.updatePriceFeedChunk(priceIdChunk, chunkIndex);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
async updatePriceFeedChunk(priceIds, chunkIndex) {
|
|
135
150
|
let priceFeedUpdateObject;
|
|
136
151
|
try {
|
|
137
152
|
// get the latest VAAs for updatePriceFeed and then push them
|
|
138
153
|
priceFeedUpdateObject = await this.getPriceFeedUpdateObject(priceIds);
|
|
139
154
|
}
|
|
140
155
|
catch (err) {
|
|
141
|
-
this.logger.error(err,
|
|
156
|
+
this.logger.error(err, `Error fetching the latest vaas to push for chunk ${chunkIndex}`);
|
|
142
157
|
return;
|
|
143
158
|
}
|
|
144
159
|
let updateFeeQueryResponse;
|
|
@@ -153,7 +168,7 @@ class InjectivePricePusher {
|
|
|
153
168
|
updateFeeQueryResponse = JSON.parse(json);
|
|
154
169
|
}
|
|
155
170
|
catch (err) {
|
|
156
|
-
this.logger.error(err,
|
|
171
|
+
this.logger.error(err, `Error fetching update fee for chunk ${chunkIndex}`);
|
|
157
172
|
// Throwing an error because it is likely an RPC issue
|
|
158
173
|
throw err;
|
|
159
174
|
}
|
|
@@ -165,19 +180,19 @@ class InjectivePricePusher {
|
|
|
165
180
|
funds: [updateFeeQueryResponse],
|
|
166
181
|
});
|
|
167
182
|
const rs = await this.signAndBroadcastMsg(executeMsg);
|
|
168
|
-
this.logger.info({ hash: rs.txHash },
|
|
183
|
+
this.logger.info({ hash: rs.txHash }, `Successfully broadcasted txHash for chunk ${chunkIndex}`);
|
|
169
184
|
}
|
|
170
185
|
catch (err) {
|
|
171
186
|
if (err.message.match(/account inj[a-zA-Z0-9]+ not found/) !== null) {
|
|
172
|
-
this.logger.error(err,
|
|
187
|
+
this.logger.error(err, `Account not found for chunk ${chunkIndex}`);
|
|
173
188
|
throw new Error("Please check the mnemonic");
|
|
174
189
|
}
|
|
175
190
|
if (err.message.match(/insufficient/) !== null &&
|
|
176
191
|
err.message.match(/funds/) !== null) {
|
|
177
|
-
this.logger.error(err,
|
|
192
|
+
this.logger.error(err, `Insufficient funds for chunk ${chunkIndex}`);
|
|
178
193
|
throw new Error("Insufficient funds");
|
|
179
194
|
}
|
|
180
|
-
this.logger.error(err,
|
|
195
|
+
this.logger.error(err, `Error executing messages for chunk ${chunkIndex}`);
|
|
181
196
|
}
|
|
182
197
|
}
|
|
183
198
|
}
|
package/lib/interface.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { HexString, UnixTimestamp } from "@pythnetwork/hermes-client";
|
|
2
2
|
import { DurationInSeconds } from "./utils";
|
|
3
|
+
import { Logger } from "pino";
|
|
4
|
+
import { PricePusherMetrics } from "./metrics";
|
|
3
5
|
export type PriceItem = {
|
|
4
6
|
id: HexString;
|
|
5
7
|
alias: string;
|
|
@@ -28,4 +30,53 @@ export declare abstract class ChainPriceListener implements IPriceListener {
|
|
|
28
30
|
export interface IPricePusher {
|
|
29
31
|
updatePriceFeed(priceIds: string[], pubTimesToPush: UnixTimestamp[]): Promise<void>;
|
|
30
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Common configuration properties for all balance trackers
|
|
35
|
+
*/
|
|
36
|
+
export interface BaseBalanceTrackerConfig {
|
|
37
|
+
/** Address of the wallet to track */
|
|
38
|
+
address: string;
|
|
39
|
+
/** Name/ID of the network/chain */
|
|
40
|
+
network: string;
|
|
41
|
+
/** How often to update the balance */
|
|
42
|
+
updateInterval: DurationInSeconds;
|
|
43
|
+
/** Metrics instance to report balance updates */
|
|
44
|
+
metrics: PricePusherMetrics;
|
|
45
|
+
/** Logger instance */
|
|
46
|
+
logger: Logger;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Interface for all balance trackers to implement
|
|
50
|
+
* Each chain will have its own implementation of this interface
|
|
51
|
+
*/
|
|
52
|
+
export interface IBalanceTracker {
|
|
53
|
+
/**
|
|
54
|
+
* Start tracking the wallet balance
|
|
55
|
+
*/
|
|
56
|
+
start(): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Stop tracking the wallet balance
|
|
59
|
+
*/
|
|
60
|
+
stop(): void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Abstract base class that implements common functionality for all balance trackers
|
|
64
|
+
*/
|
|
65
|
+
export declare abstract class BaseBalanceTracker implements IBalanceTracker {
|
|
66
|
+
protected address: string;
|
|
67
|
+
protected network: string;
|
|
68
|
+
protected updateInterval: DurationInSeconds;
|
|
69
|
+
protected metrics: PricePusherMetrics;
|
|
70
|
+
protected logger: Logger;
|
|
71
|
+
protected isRunning: boolean;
|
|
72
|
+
constructor(config: BaseBalanceTrackerConfig);
|
|
73
|
+
start(): Promise<void>;
|
|
74
|
+
private startUpdateLoop;
|
|
75
|
+
/**
|
|
76
|
+
* Chain-specific balance update implementation
|
|
77
|
+
* Each chain will implement this method differently
|
|
78
|
+
*/
|
|
79
|
+
protected abstract updateBalance(): Promise<void>;
|
|
80
|
+
stop(): void;
|
|
81
|
+
}
|
|
31
82
|
//# sourceMappingURL=interface.d.ts.map
|
package/lib/interface.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C,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;CAC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C1B,SAAS,CAAC,cAAc,EAAE,iBAAiB,CAAC;IAC5C,SAAS,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACtC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,SAAS,EAAE,OAAO,CAAS;gBAEzB,MAAM,EAAE,wBAAwB;IAQ/B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAcrB,eAAe;IAkB7B;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAE1C,IAAI,IAAI,IAAI;CAGpB"}
|
package/lib/interface.js
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ChainPriceListener = void 0;
|
|
36
|
+
exports.BaseBalanceTracker = exports.ChainPriceListener = void 0;
|
|
4
37
|
class ChainPriceListener {
|
|
5
38
|
pollingFrequency;
|
|
6
39
|
priceItems;
|
|
@@ -41,3 +74,49 @@ class ChainPriceListener {
|
|
|
41
74
|
}
|
|
42
75
|
}
|
|
43
76
|
exports.ChainPriceListener = ChainPriceListener;
|
|
77
|
+
/**
|
|
78
|
+
* Abstract base class that implements common functionality for all balance trackers
|
|
79
|
+
*/
|
|
80
|
+
class BaseBalanceTracker {
|
|
81
|
+
address;
|
|
82
|
+
network;
|
|
83
|
+
updateInterval;
|
|
84
|
+
metrics;
|
|
85
|
+
logger;
|
|
86
|
+
isRunning = false;
|
|
87
|
+
constructor(config) {
|
|
88
|
+
this.address = config.address;
|
|
89
|
+
this.network = config.network;
|
|
90
|
+
this.updateInterval = config.updateInterval;
|
|
91
|
+
this.metrics = config.metrics;
|
|
92
|
+
this.logger = config.logger;
|
|
93
|
+
}
|
|
94
|
+
async start() {
|
|
95
|
+
if (this.isRunning) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
this.isRunning = true;
|
|
99
|
+
// Initial balance update
|
|
100
|
+
await this.updateBalance();
|
|
101
|
+
// Start the update loop
|
|
102
|
+
this.startUpdateLoop();
|
|
103
|
+
}
|
|
104
|
+
async startUpdateLoop() {
|
|
105
|
+
// We're using dynamic import to avoid circular dependencies
|
|
106
|
+
const { sleep } = await Promise.resolve().then(() => __importStar(require("./utils")));
|
|
107
|
+
// Run in a loop to regularly update the balance
|
|
108
|
+
for (;;) {
|
|
109
|
+
// Wait first, since we already did the initial update in start()
|
|
110
|
+
await sleep(this.updateInterval * 1000);
|
|
111
|
+
// Only continue if we're still running
|
|
112
|
+
if (!this.isRunning) {
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
await this.updateBalance();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
stop() {
|
|
119
|
+
this.isRunning = false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.BaseBalanceTracker = BaseBalanceTracker;
|
package/lib/metrics.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Counter, Gauge } from "prom-client";
|
|
2
|
+
import { PriceInfo } from "./interface";
|
|
3
|
+
import { Logger } from "pino";
|
|
4
|
+
import { UpdateCondition } from "./price-config";
|
|
5
|
+
export declare class PricePusherMetrics {
|
|
6
|
+
private registry;
|
|
7
|
+
private server;
|
|
8
|
+
private logger;
|
|
9
|
+
lastPublishedTime: Gauge<string>;
|
|
10
|
+
priceUpdateAttempts: Counter<string>;
|
|
11
|
+
priceFeedsTotal: Gauge<string>;
|
|
12
|
+
walletBalance: Gauge<string>;
|
|
13
|
+
constructor(logger: Logger);
|
|
14
|
+
start(port: number): void;
|
|
15
|
+
updateLastPublishedTime(priceId: string, alias: string, priceInfo: PriceInfo): void;
|
|
16
|
+
recordPriceUpdate(priceId: string, alias: string, trigger?: string): void;
|
|
17
|
+
recordUpdateCondition(priceId: string, alias: string, condition: UpdateCondition): void;
|
|
18
|
+
recordPriceUpdateError(priceId: string, alias: string, trigger?: string): void;
|
|
19
|
+
setPriceFeedsTotal(count: number): void;
|
|
20
|
+
updateWalletBalance(walletAddress: string, network: string, balance: bigint | number): void;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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