@pythnetwork/price-pusher 10.2.0 → 10.3.1
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
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Controller", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Controller;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _priceconfig = require("./price-config.cjs");
|
|
12
|
+
const _utils = require("./utils.cjs");
|
|
6
13
|
class Controller {
|
|
7
14
|
priceConfigs;
|
|
8
15
|
sourcePriceListener;
|
|
@@ -11,7 +18,7 @@ class Controller {
|
|
|
11
18
|
logger;
|
|
12
19
|
pushingFrequency;
|
|
13
20
|
metrics;
|
|
14
|
-
constructor(priceConfigs, sourcePriceListener, targetPriceListener, targetChainPricePusher, logger, config)
|
|
21
|
+
constructor(priceConfigs, sourcePriceListener, targetPriceListener, targetChainPricePusher, logger, config){
|
|
15
22
|
this.priceConfigs = priceConfigs;
|
|
16
23
|
this.sourcePriceListener = sourcePriceListener;
|
|
17
24
|
this.targetPriceListener = targetPriceListener;
|
|
@@ -29,14 +36,14 @@ class Controller {
|
|
|
29
36
|
// wait for the listeners to get updated. There could be a restart
|
|
30
37
|
// before this run and we need to respect the cooldown duration as
|
|
31
38
|
// their might be a message sent before.
|
|
32
|
-
await (0,
|
|
33
|
-
for
|
|
39
|
+
await (0, _utils.sleep)(this.pushingFrequency * 1000);
|
|
40
|
+
for(;;){
|
|
34
41
|
// We will push all prices whose update condition is YES or EARLY as long as there is
|
|
35
42
|
// at least one YES.
|
|
36
43
|
let pushThresholdMet = false;
|
|
37
44
|
const pricesToPush = [];
|
|
38
45
|
const pubTimesToPush = [];
|
|
39
|
-
for (const priceConfig of this.priceConfigs)
|
|
46
|
+
for (const priceConfig of this.priceConfigs){
|
|
40
47
|
const priceId = priceConfig.id;
|
|
41
48
|
const alias = priceConfig.alias;
|
|
42
49
|
const targetLatestPrice = this.targetPriceListener.getLatestPriceInfo(priceId);
|
|
@@ -45,59 +52,54 @@ class Controller {
|
|
|
45
52
|
this.metrics.updateTimestamps(priceId, alias, targetLatestPrice.publishTime, sourceLatestPrice.publishTime, priceConfig.timeDifference);
|
|
46
53
|
this.metrics.updatePriceValues(priceId, alias, sourceLatestPrice.price, targetLatestPrice.price);
|
|
47
54
|
}
|
|
48
|
-
const priceShouldUpdate = (0,
|
|
55
|
+
const priceShouldUpdate = (0, _priceconfig.shouldUpdate)(priceConfig, sourceLatestPrice, targetLatestPrice, this.logger);
|
|
49
56
|
// Record update condition in metrics
|
|
50
57
|
if (this.metrics) {
|
|
51
58
|
this.metrics.recordUpdateCondition(priceId, alias, priceShouldUpdate);
|
|
52
59
|
}
|
|
53
|
-
if (priceShouldUpdate ==
|
|
60
|
+
if (priceShouldUpdate == _priceconfig.UpdateCondition.YES) {
|
|
54
61
|
pushThresholdMet = true;
|
|
55
62
|
}
|
|
56
|
-
if (priceShouldUpdate ==
|
|
57
|
-
priceShouldUpdate == price_config_1.UpdateCondition.EARLY) {
|
|
63
|
+
if (priceShouldUpdate == _priceconfig.UpdateCondition.YES || priceShouldUpdate == _priceconfig.UpdateCondition.EARLY) {
|
|
58
64
|
pricesToPush.push(priceConfig);
|
|
59
|
-
pubTimesToPush.push((targetLatestPrice?.publishTime
|
|
65
|
+
pubTimesToPush.push((targetLatestPrice?.publishTime ?? 0) + 1);
|
|
60
66
|
}
|
|
61
67
|
}
|
|
62
68
|
if (pushThresholdMet) {
|
|
63
69
|
this.logger.info({
|
|
64
|
-
priceIds: pricesToPush.map((priceConfig)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
70
|
+
priceIds: pricesToPush.map((priceConfig)=>({
|
|
71
|
+
id: priceConfig.id,
|
|
72
|
+
alias: priceConfig.alias
|
|
73
|
+
}))
|
|
68
74
|
}, "Some of the checks triggered pushing update. Will push the updates for some feeds.");
|
|
69
75
|
// note that the priceIds are without leading "0x"
|
|
70
|
-
const priceIds = pricesToPush.map((priceConfig)
|
|
76
|
+
const priceIds = pricesToPush.map((priceConfig)=>priceConfig.id);
|
|
71
77
|
try {
|
|
72
78
|
await this.targetChainPricePusher.updatePriceFeed(priceIds, pubTimesToPush);
|
|
73
79
|
// Record successful updates
|
|
74
80
|
if (this.metrics) {
|
|
75
|
-
for (const config of pricesToPush)
|
|
76
|
-
const triggerValue = (0,
|
|
77
|
-
? "yes"
|
|
78
|
-
: "early";
|
|
81
|
+
for (const config of pricesToPush){
|
|
82
|
+
const triggerValue = (0, _priceconfig.shouldUpdate)(config, this.sourcePriceListener.getLatestPriceInfo(config.id), this.targetPriceListener.getLatestPriceInfo(config.id), this.logger) === _priceconfig.UpdateCondition.YES ? "yes" : "early";
|
|
79
83
|
this.metrics.recordPriceUpdate(config.id, config.alias, triggerValue);
|
|
80
84
|
}
|
|
81
85
|
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
} catch (error) {
|
|
87
|
+
this.logger.error({
|
|
88
|
+
error,
|
|
89
|
+
priceIds
|
|
90
|
+
}, "Error pushing price updates to chain");
|
|
85
91
|
// Record errors in metrics
|
|
86
92
|
if (this.metrics) {
|
|
87
|
-
for (const config of pricesToPush)
|
|
88
|
-
const triggerValue = (0,
|
|
89
|
-
? "yes"
|
|
90
|
-
: "early";
|
|
93
|
+
for (const config of pricesToPush){
|
|
94
|
+
const triggerValue = (0, _priceconfig.shouldUpdate)(config, this.sourcePriceListener.getLatestPriceInfo(config.id), this.targetPriceListener.getLatestPriceInfo(config.id), this.logger) === _priceconfig.UpdateCondition.YES ? "yes" : "early";
|
|
91
95
|
this.metrics.recordPriceUpdateError(config.id, config.alias, triggerValue);
|
|
92
96
|
}
|
|
93
97
|
}
|
|
94
98
|
}
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
99
|
+
} else {
|
|
97
100
|
this.logger.info("None of the checks were triggered. No push needed.");
|
|
98
101
|
}
|
|
99
|
-
await (0,
|
|
102
|
+
await (0, _utils.sleep)(this.pushingFrequency * 1000);
|
|
100
103
|
}
|
|
101
104
|
}
|
|
102
105
|
}
|
|
103
|
-
exports.Controller = Controller;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { IPriceListener, IPricePusher } from "./interface";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import type { Logger } from "pino";
|
|
2
|
+
import type { IPriceListener, IPricePusher } from "./interface.js";
|
|
3
|
+
import { PricePusherMetrics } from "./metrics.js";
|
|
4
|
+
import type { PriceConfig } from "./price-config.js";
|
|
5
|
+
import type { DurationInSeconds } from "./utils.js";
|
|
6
6
|
export declare class Controller {
|
|
7
7
|
private priceConfigs;
|
|
8
8
|
private sourcePriceListener;
|
|
@@ -17,4 +17,3 @@ export declare class Controller {
|
|
|
17
17
|
});
|
|
18
18
|
start(): Promise<void>;
|
|
19
19
|
}
|
|
20
|
-
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"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 EvmBalanceTracker () {
|
|
13
|
+
return EvmBalanceTracker;
|
|
14
|
+
},
|
|
15
|
+
get createEvmBalanceTracker () {
|
|
16
|
+
return createEvmBalanceTracker;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _interface = require("../interface.cjs");
|
|
20
|
+
class EvmBalanceTracker extends _interface.BaseBalanceTracker {
|
|
21
|
+
client;
|
|
22
|
+
evmAddress;
|
|
23
|
+
constructor(config){
|
|
24
|
+
super({
|
|
25
|
+
...config,
|
|
26
|
+
logger: config.logger.child({
|
|
27
|
+
module: "EvmBalanceTracker"
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
this.client = config.client;
|
|
31
|
+
this.evmAddress = config.address;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* EVM-specific implementation of balance update
|
|
35
|
+
*/ async updateBalance() {
|
|
36
|
+
try {
|
|
37
|
+
const balance = await this.client.getBalance({
|
|
38
|
+
address: this.evmAddress
|
|
39
|
+
});
|
|
40
|
+
this.metrics.updateWalletBalance(this.address, this.network, balance);
|
|
41
|
+
this.logger.debug(`Updated EVM wallet balance: ${this.address} = ${balance.toString()}`);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
this.logger.error({
|
|
44
|
+
error
|
|
45
|
+
}, "Error fetching EVM wallet balance for metrics");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function createEvmBalanceTracker(params) {
|
|
50
|
+
return new EvmBalanceTracker({
|
|
51
|
+
client: params.client,
|
|
52
|
+
address: params.address,
|
|
53
|
+
network: params.network,
|
|
54
|
+
updateInterval: params.updateInterval,
|
|
55
|
+
metrics: params.metrics,
|
|
56
|
+
logger: params.logger
|
|
57
|
+
});
|
|
58
|
+
}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import type { Logger } from "pino";
|
|
2
|
+
import type { SuperWalletClient } from "./super-wallet.js";
|
|
3
|
+
import type { BaseBalanceTrackerConfig, IBalanceTracker } from "../interface.js";
|
|
4
|
+
import { BaseBalanceTracker } from "../interface.js";
|
|
5
|
+
import { PricePusherMetrics } from "../metrics.js";
|
|
6
|
+
import type { DurationInSeconds } from "../utils.js";
|
|
6
7
|
/**
|
|
7
8
|
* EVM-specific configuration for balance tracker
|
|
8
9
|
*/
|
|
9
|
-
export
|
|
10
|
+
export type EvmBalanceTrackerConfig = {
|
|
10
11
|
/** EVM wallet client */
|
|
11
12
|
client: SuperWalletClient;
|
|
12
13
|
/** EVM address with 0x prefix */
|
|
13
14
|
address: `0x${string}`;
|
|
14
|
-
}
|
|
15
|
+
} & BaseBalanceTrackerConfig;
|
|
15
16
|
/**
|
|
16
17
|
* EVM-specific implementation of the balance tracker
|
|
17
18
|
*/
|
|
@@ -27,16 +28,15 @@ export declare class EvmBalanceTracker extends BaseBalanceTracker {
|
|
|
27
28
|
/**
|
|
28
29
|
* Parameters for creating an EVM balance tracker
|
|
29
30
|
*/
|
|
30
|
-
export
|
|
31
|
+
export type CreateEvmBalanceTrackerParams = {
|
|
31
32
|
client: SuperWalletClient;
|
|
32
33
|
address: `0x${string}`;
|
|
33
34
|
network: string;
|
|
34
35
|
updateInterval: DurationInSeconds;
|
|
35
36
|
metrics: PricePusherMetrics;
|
|
36
37
|
logger: Logger;
|
|
37
|
-
}
|
|
38
|
+
};
|
|
38
39
|
/**
|
|
39
40
|
* Factory function to create a balance tracker for EVM chains
|
|
40
41
|
*/
|
|
41
42
|
export declare function createEvmBalanceTracker(params: CreateEvmBalanceTrackerParams): IBalanceTracker;
|
|
42
|
-
//# sourceMappingURL=balance-tracker.d.ts.map
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */ /* eslint-disable @typescript-eslint/restrict-template-expressions */ /* 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 _pino = /*#__PURE__*/ _interop_require_default(require("pino"));
|
|
14
|
+
const _controller = require("../controller.cjs");
|
|
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 _customgasstation = require("./custom-gas-station.cjs");
|
|
19
|
+
const _evm = require("./evm.cjs");
|
|
20
|
+
const _pythcontract = require("./pyth-contract.cjs");
|
|
21
|
+
const _superwallet = require("./super-wallet.cjs");
|
|
22
|
+
const _metrics = require("../metrics.cjs");
|
|
23
|
+
const _utils = require("../utils.cjs");
|
|
24
|
+
const _balancetracker = require("./balance-tracker.cjs");
|
|
25
|
+
function _interop_require_default(obj) {
|
|
26
|
+
return obj && obj.__esModule ? obj : {
|
|
27
|
+
default: obj
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
31
|
+
if (typeof WeakMap !== "function") return null;
|
|
32
|
+
var cacheBabelInterop = new WeakMap();
|
|
33
|
+
var cacheNodeInterop = new WeakMap();
|
|
34
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
35
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
36
|
+
})(nodeInterop);
|
|
37
|
+
}
|
|
38
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
39
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
40
|
+
return obj;
|
|
41
|
+
}
|
|
42
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
43
|
+
return {
|
|
44
|
+
default: obj
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
48
|
+
if (cache && cache.has(obj)) {
|
|
49
|
+
return cache.get(obj);
|
|
50
|
+
}
|
|
51
|
+
var newObj = {
|
|
52
|
+
__proto__: null
|
|
53
|
+
};
|
|
54
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
55
|
+
for(var key in obj){
|
|
56
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
57
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
58
|
+
if (desc && (desc.get || desc.set)) {
|
|
59
|
+
Object.defineProperty(newObj, key, desc);
|
|
60
|
+
} else {
|
|
61
|
+
newObj[key] = obj[key];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
newObj.default = obj;
|
|
66
|
+
if (cache) {
|
|
67
|
+
cache.set(obj, newObj);
|
|
68
|
+
}
|
|
69
|
+
return newObj;
|
|
70
|
+
}
|
|
71
|
+
const _default = {
|
|
72
|
+
command: "evm",
|
|
73
|
+
describe: "run price pusher for evm",
|
|
74
|
+
builder: {
|
|
75
|
+
endpoint: {
|
|
76
|
+
description: "RPC endpoint URL for evm network. If you provide a normal HTTP endpoint, the pusher " + "will periodically poll for updates. The polling interval is configurable via the " + "`polling-frequency` command-line argument. If you provide a websocket RPC " + "endpoint (`ws[s]://...`), the price pusher will use event subscriptions to read " + "the current EVM price in addition to polling. ",
|
|
77
|
+
type: "string",
|
|
78
|
+
required: true
|
|
79
|
+
},
|
|
80
|
+
"custom-gas-station": {
|
|
81
|
+
description: "If using a custom gas station, chainId of custom gas station to use",
|
|
82
|
+
type: "number",
|
|
83
|
+
required: false
|
|
84
|
+
},
|
|
85
|
+
"tx-speed": {
|
|
86
|
+
description: "txSpeed for custom gas station. choose between 'slow'|'standard'|'fast'",
|
|
87
|
+
choices: [
|
|
88
|
+
"slow",
|
|
89
|
+
"standard",
|
|
90
|
+
"fast"
|
|
91
|
+
],
|
|
92
|
+
required: false
|
|
93
|
+
},
|
|
94
|
+
"override-gas-price-multiplier": {
|
|
95
|
+
description: "Multiply the previous gas price by this number if the transaction is not landing to override. " + "Please note that the gas price can grow exponentially on consecutive failures; " + "to set a cap on the multiplier, use the `override-gas-price-multiplier-cap` option." + "Default to 1.1",
|
|
96
|
+
type: "number",
|
|
97
|
+
required: false,
|
|
98
|
+
default: 1.1
|
|
99
|
+
},
|
|
100
|
+
"override-gas-price-multiplier-cap": {
|
|
101
|
+
description: "Maximum gas price multiplier to use in override compared to the RPC returned " + "gas price. Default to 5",
|
|
102
|
+
type: "number",
|
|
103
|
+
required: false,
|
|
104
|
+
default: 5
|
|
105
|
+
},
|
|
106
|
+
"gas-limit": {
|
|
107
|
+
description: "Gas limit for the transaction",
|
|
108
|
+
type: "number",
|
|
109
|
+
required: false
|
|
110
|
+
},
|
|
111
|
+
"gas-price": {
|
|
112
|
+
description: "Override the gas price that would be received from the RPC",
|
|
113
|
+
type: "number",
|
|
114
|
+
required: false
|
|
115
|
+
},
|
|
116
|
+
"update-fee-multiplier": {
|
|
117
|
+
description: "Multiplier for the fee to update the price. It is useful in networks " + "such as Hedera where setting on-chain getUpdateFee as the transaction value " + "won't work. Default to 1",
|
|
118
|
+
type: "number",
|
|
119
|
+
required: false,
|
|
120
|
+
default: 1
|
|
121
|
+
},
|
|
122
|
+
..._options.priceConfigFile,
|
|
123
|
+
..._options.priceServiceEndpoint,
|
|
124
|
+
..._options.mnemonicFile,
|
|
125
|
+
..._options.pythContractAddress,
|
|
126
|
+
..._options.pollingFrequency,
|
|
127
|
+
..._options.pushingFrequency,
|
|
128
|
+
..._options.logLevel,
|
|
129
|
+
..._options.controllerLogLevel,
|
|
130
|
+
..._options.enableMetrics,
|
|
131
|
+
..._options.metricsPort
|
|
132
|
+
},
|
|
133
|
+
handler: async function(argv) {
|
|
134
|
+
// FIXME: type checks for this
|
|
135
|
+
const { endpoint, priceConfigFile, priceServiceEndpoint, mnemonicFile, pythContractAddress, pushingFrequency, pollingFrequency, customGasStation, txSpeed, overrideGasPriceMultiplier, overrideGasPriceMultiplierCap, gasLimit, gasPrice, updateFeeMultiplier, logLevel, controllerLogLevel, enableMetrics, metricsPort } = argv;
|
|
136
|
+
const logger = (0, _pino.default)({
|
|
137
|
+
level: logLevel
|
|
138
|
+
});
|
|
139
|
+
const priceConfigs = (0, _priceconfig.readPriceConfigFile)(priceConfigFile);
|
|
140
|
+
const hermesClient = new _hermesclient.HermesClient(priceServiceEndpoint);
|
|
141
|
+
const mnemonic = _nodefs.default.readFileSync(mnemonicFile, "utf8").trim();
|
|
142
|
+
let priceItems = priceConfigs.map(({ id, alias })=>({
|
|
143
|
+
id,
|
|
144
|
+
alias
|
|
145
|
+
}));
|
|
146
|
+
// Better to filter out invalid price items before creating the pyth listener
|
|
147
|
+
const { existingPriceItems, invalidPriceItems } = await (0, _utils.filterInvalidPriceItems)(hermesClient, priceItems);
|
|
148
|
+
if (invalidPriceItems.length > 0) {
|
|
149
|
+
logger.error(`Invalid price id submitted for: ${invalidPriceItems.map(({ alias })=>alias).join(", ")}`);
|
|
150
|
+
}
|
|
151
|
+
priceItems = existingPriceItems;
|
|
152
|
+
// Initialize metrics if enabled
|
|
153
|
+
let metrics;
|
|
154
|
+
if (enableMetrics) {
|
|
155
|
+
metrics = new _metrics.PricePusherMetrics(logger.child({
|
|
156
|
+
module: "Metrics"
|
|
157
|
+
}));
|
|
158
|
+
metrics.start(metricsPort);
|
|
159
|
+
logger.info(`Metrics server started on port ${metricsPort}`);
|
|
160
|
+
}
|
|
161
|
+
const pythListener = new _pythpricelistener.PythPriceListener(hermesClient, priceItems, logger.child({
|
|
162
|
+
module: "PythPriceListener"
|
|
163
|
+
}));
|
|
164
|
+
const client = await (0, _superwallet.createClient)(endpoint, mnemonic);
|
|
165
|
+
const pythContract = (0, _pythcontract.createPythContract)(client, pythContractAddress);
|
|
166
|
+
logger.info(`Pushing updates from wallet address: ${client.account.address}`);
|
|
167
|
+
// It is possible to watch the events in the non-ws endpoints, either by getFilter
|
|
168
|
+
// or by getLogs, but it is very expensive and our polling mechanism does it
|
|
169
|
+
// in a more efficient way. So we only do it with ws endpoints.
|
|
170
|
+
const watchEvents = (0, _utils.isWsEndpoint)(endpoint);
|
|
171
|
+
const evmListener = new _evm.EvmPriceListener(pythContract, priceItems, watchEvents, logger.child({
|
|
172
|
+
module: "EvmPriceListener"
|
|
173
|
+
}), {
|
|
174
|
+
pollingFrequency
|
|
175
|
+
});
|
|
176
|
+
const gasStation = (0, _customgasstation.getCustomGasStation)(logger.child({
|
|
177
|
+
module: "CustomGasStation"
|
|
178
|
+
}), customGasStation, txSpeed);
|
|
179
|
+
const evmPusher = new _evm.EvmPricePusher(hermesClient, client, pythContract, logger.child({
|
|
180
|
+
module: "EvmPricePusher"
|
|
181
|
+
}), overrideGasPriceMultiplier, overrideGasPriceMultiplierCap, updateFeeMultiplier, gasLimit, gasStation, gasPrice);
|
|
182
|
+
const controller = new _controller.Controller(priceConfigs, pythListener, evmListener, evmPusher, logger.child({
|
|
183
|
+
module: "Controller"
|
|
184
|
+
}, {
|
|
185
|
+
level: controllerLogLevel
|
|
186
|
+
}), {
|
|
187
|
+
pushingFrequency,
|
|
188
|
+
metrics: metrics
|
|
189
|
+
});
|
|
190
|
+
// Create and start the balance tracker if metrics are enabled
|
|
191
|
+
if (metrics) {
|
|
192
|
+
const balanceTracker = (0, _balancetracker.createEvmBalanceTracker)({
|
|
193
|
+
client,
|
|
194
|
+
address: client.account.address,
|
|
195
|
+
network: await client.getChainId().then((id)=>id.toString()),
|
|
196
|
+
updateInterval: pushingFrequency,
|
|
197
|
+
metrics,
|
|
198
|
+
logger
|
|
199
|
+
});
|
|
200
|
+
// Start the balance tracker
|
|
201
|
+
await balanceTracker.start();
|
|
202
|
+
}
|
|
203
|
+
void controller.start();
|
|
204
|
+
}
|
|
205
|
+
};
|
|
@@ -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;
|
|
@@ -25,4 +25,3 @@ declare const _default: {
|
|
|
25
25
|
handler: (argv: any) => Promise<void>;
|
|
26
26
|
};
|
|
27
27
|
export default _default;
|
|
28
|
-
//# sourceMappingURL=command.d.ts.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-argument */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ "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 CustomGasStation () {
|
|
13
|
+
return CustomGasStation;
|
|
14
|
+
},
|
|
15
|
+
get getCustomGasStation () {
|
|
16
|
+
return getCustomGasStation;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _viem = require("viem");
|
|
20
|
+
const _utils = require("../utils.cjs");
|
|
21
|
+
class CustomGasStation {
|
|
22
|
+
chain;
|
|
23
|
+
speed;
|
|
24
|
+
chainMethods = {
|
|
25
|
+
137: this.fetchMaticMainnetGasPrice.bind(this)
|
|
26
|
+
};
|
|
27
|
+
logger;
|
|
28
|
+
constructor(logger, chain, speed){
|
|
29
|
+
this.logger = logger;
|
|
30
|
+
this.speed = (0, _utils.verifyValidOption)(speed, _utils.txSpeeds);
|
|
31
|
+
this.chain = (0, _utils.verifyValidOption)(chain, _utils.customGasChainIds);
|
|
32
|
+
}
|
|
33
|
+
async getCustomGasPrice() {
|
|
34
|
+
return this.chainMethods[this.chain]();
|
|
35
|
+
}
|
|
36
|
+
async fetchMaticMainnetGasPrice() {
|
|
37
|
+
try {
|
|
38
|
+
const res = await fetch("https://gasstation.polygon.technology/v2");
|
|
39
|
+
// TODO: improve the typing specificity here
|
|
40
|
+
const jsonRes = await res.json();
|
|
41
|
+
const gasPrice = jsonRes[this.speed].maxFee;
|
|
42
|
+
return (0, _viem.parseGwei)(gasPrice.toFixed(2));
|
|
43
|
+
} catch (error) {
|
|
44
|
+
this.logger.error(error, "Failed to fetch gas price from Matic mainnet. Returning undefined");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function getCustomGasStation(logger, customGasStation, txSpeed) {
|
|
50
|
+
if (customGasStation && txSpeed) {
|
|
51
|
+
return new CustomGasStation(logger, customGasStation, txSpeed);
|
|
52
|
+
}
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Logger } from "pino";
|
|
1
|
+
import type { Logger } from "pino";
|
|
2
2
|
export declare class CustomGasStation {
|
|
3
3
|
private chain;
|
|
4
4
|
private speed;
|
|
@@ -9,4 +9,3 @@ export declare class CustomGasStation {
|
|
|
9
9
|
private fetchMaticMainnetGasPrice;
|
|
10
10
|
}
|
|
11
11
|
export declare function getCustomGasStation(logger: Logger, customGasStation?: number, txSpeed?: string): CustomGasStation | undefined;
|
|
12
|
-
//# sourceMappingURL=custom-gas-station.d.ts.map
|