@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/metrics.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PricePusherMetrics = void 0;
|
|
7
|
+
const prom_client_1 = require("prom-client");
|
|
8
|
+
const express_1 = __importDefault(require("express"));
|
|
9
|
+
const price_config_1 = require("./price-config");
|
|
10
|
+
// Define the metrics we want to track
|
|
11
|
+
class PricePusherMetrics {
|
|
12
|
+
registry;
|
|
13
|
+
server;
|
|
14
|
+
logger;
|
|
15
|
+
// Metrics for price feed updates
|
|
16
|
+
lastPublishedTime;
|
|
17
|
+
priceUpdateAttempts;
|
|
18
|
+
priceFeedsTotal;
|
|
19
|
+
// Wallet metrics
|
|
20
|
+
walletBalance;
|
|
21
|
+
constructor(logger) {
|
|
22
|
+
this.logger = logger;
|
|
23
|
+
this.registry = new prom_client_1.Registry();
|
|
24
|
+
this.server = (0, express_1.default)();
|
|
25
|
+
// Register the default metrics (memory, CPU, etc.)
|
|
26
|
+
this.registry.setDefaultLabels({ app: "price_pusher" });
|
|
27
|
+
// Create metrics
|
|
28
|
+
this.lastPublishedTime = new prom_client_1.Gauge({
|
|
29
|
+
name: "pyth_price_last_published_time",
|
|
30
|
+
help: "The last published time of a price feed in unix timestamp",
|
|
31
|
+
labelNames: ["price_id", "alias"],
|
|
32
|
+
registers: [this.registry],
|
|
33
|
+
});
|
|
34
|
+
this.priceUpdateAttempts = new prom_client_1.Counter({
|
|
35
|
+
name: "pyth_price_update_attempts_total",
|
|
36
|
+
help: "Total number of price update attempts with their trigger condition and status",
|
|
37
|
+
labelNames: ["price_id", "alias", "trigger", "status"],
|
|
38
|
+
registers: [this.registry],
|
|
39
|
+
});
|
|
40
|
+
this.priceFeedsTotal = new prom_client_1.Gauge({
|
|
41
|
+
name: "pyth_price_feeds_total",
|
|
42
|
+
help: "Total number of price feeds being monitored",
|
|
43
|
+
registers: [this.registry],
|
|
44
|
+
});
|
|
45
|
+
// Wallet balance metric
|
|
46
|
+
this.walletBalance = new prom_client_1.Gauge({
|
|
47
|
+
name: "pyth_wallet_balance",
|
|
48
|
+
help: "Current wallet balance of the price pusher in native token units",
|
|
49
|
+
labelNames: ["wallet_address", "network"],
|
|
50
|
+
registers: [this.registry],
|
|
51
|
+
});
|
|
52
|
+
// Setup the metrics endpoint
|
|
53
|
+
this.server.get("/metrics", async (req, res) => {
|
|
54
|
+
res.set("Content-Type", this.registry.contentType);
|
|
55
|
+
res.end(await this.registry.metrics());
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// Start the metrics server
|
|
59
|
+
start(port) {
|
|
60
|
+
this.server.listen(port, () => {
|
|
61
|
+
this.logger.info(`Metrics server started on port ${port}`);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
// Update the last published time for a price feed
|
|
65
|
+
updateLastPublishedTime(priceId, alias, priceInfo) {
|
|
66
|
+
this.lastPublishedTime.set({ price_id: priceId, alias }, priceInfo.publishTime);
|
|
67
|
+
}
|
|
68
|
+
// Record a successful price update
|
|
69
|
+
recordPriceUpdate(priceId, alias, trigger = "yes") {
|
|
70
|
+
this.priceUpdateAttempts.inc({
|
|
71
|
+
price_id: priceId,
|
|
72
|
+
alias,
|
|
73
|
+
trigger: trigger.toLowerCase(),
|
|
74
|
+
status: "success",
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
// Record update condition status (YES/NO/EARLY)
|
|
78
|
+
recordUpdateCondition(priceId, alias, condition) {
|
|
79
|
+
const triggerLabel = price_config_1.UpdateCondition[condition].toLowerCase();
|
|
80
|
+
// Only record as 'skipped' when the condition is NO
|
|
81
|
+
if (condition === price_config_1.UpdateCondition.NO) {
|
|
82
|
+
this.priceUpdateAttempts.inc({
|
|
83
|
+
price_id: priceId,
|
|
84
|
+
alias,
|
|
85
|
+
trigger: triggerLabel,
|
|
86
|
+
status: "skipped",
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
// YES and EARLY don't increment the counter here - they'll be counted
|
|
90
|
+
// when recordPriceUpdate or recordPriceUpdateError is called
|
|
91
|
+
}
|
|
92
|
+
// Record a price update error
|
|
93
|
+
recordPriceUpdateError(priceId, alias, trigger = "yes") {
|
|
94
|
+
this.priceUpdateAttempts.inc({
|
|
95
|
+
price_id: priceId,
|
|
96
|
+
alias,
|
|
97
|
+
trigger: trigger.toLowerCase(),
|
|
98
|
+
status: "error",
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
// Set the number of price feeds
|
|
102
|
+
setPriceFeedsTotal(count) {
|
|
103
|
+
this.priceFeedsTotal.set(count);
|
|
104
|
+
}
|
|
105
|
+
// Update wallet balance
|
|
106
|
+
updateWalletBalance(walletAddress, network, balance) {
|
|
107
|
+
// Convert to number for compatibility with prometheus
|
|
108
|
+
const balanceNum = typeof balance === "bigint" ? Number(balance) / 1e18 : balance;
|
|
109
|
+
this.walletBalance.set({ wallet_address: walletAddress, network }, balanceNum);
|
|
110
|
+
this.logger.debug(`Updated wallet balance metric: ${walletAddress} = ${balanceNum}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.PricePusherMetrics = PricePusherMetrics;
|
package/lib/near/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/options.d.ts
CHANGED
|
@@ -23,4 +23,10 @@ export declare const logLevel: {
|
|
|
23
23
|
export declare const controllerLogLevel: {
|
|
24
24
|
"controller-log-level": Options;
|
|
25
25
|
};
|
|
26
|
+
export declare const enableMetrics: {
|
|
27
|
+
"enable-metrics": Options;
|
|
28
|
+
};
|
|
29
|
+
export declare const metricsPort: {
|
|
30
|
+
"metrics-port": Options;
|
|
31
|
+
};
|
|
26
32
|
//# sourceMappingURL=options.d.ts.map
|
package/lib/options.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,eAAO,MAAM,oBAAoB;8BAM1B,OAAO;CACb,CAAC;AAEF,eAAO,MAAM,mBAAmB;6BAOzB,OAAO;CACb,CAAC;AAEF,eAAO,MAAM,eAAe;yBAKrB,OAAO;CACb,CAAC;AAEF,eAAO,MAAM,gBAAgB;yBAOtB,OAAO;CACb,CAAC;AAEF,eAAO,MAAM,gBAAgB;yBAStB,OAAO;CACb,CAAC;AAEF,eAAO,MAAM,YAAY;qBAKlB,OAAO;CACb,CAAC;AAEF,eAAO,MAAM,QAAQ;iBAOd,OAAO;CACb,CAAC;AAEF,eAAO,MAAM,kBAAkB;4BAOxB,OAAO;CACb,CAAC"}
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,eAAO,MAAM,oBAAoB;8BAM1B,OAAO;CACb,CAAC;AAEF,eAAO,MAAM,mBAAmB;6BAOzB,OAAO;CACb,CAAC;AAEF,eAAO,MAAM,eAAe;yBAKrB,OAAO;CACb,CAAC;AAEF,eAAO,MAAM,gBAAgB;yBAOtB,OAAO;CACb,CAAC;AAEF,eAAO,MAAM,gBAAgB;yBAStB,OAAO;CACb,CAAC;AAEF,eAAO,MAAM,YAAY;qBAKlB,OAAO;CACb,CAAC;AAEF,eAAO,MAAM,QAAQ;iBAOd,OAAO;CACb,CAAC;AAEF,eAAO,MAAM,kBAAkB;4BAOxB,OAAO;CACb,CAAC;AAEF,eAAO,MAAM,aAAa;sBAMnB,OAAO;CACb,CAAC;AAEF,eAAO,MAAM,WAAW;oBAMjB,OAAO;CACb,CAAC"}
|
package/lib/options.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.controllerLogLevel = exports.logLevel = exports.mnemonicFile = exports.pushingFrequency = exports.pollingFrequency = exports.priceConfigFile = exports.pythContractAddress = exports.priceServiceEndpoint = void 0;
|
|
3
|
+
exports.metricsPort = exports.enableMetrics = exports.controllerLogLevel = exports.logLevel = exports.mnemonicFile = exports.pushingFrequency = exports.pollingFrequency = exports.priceConfigFile = exports.pythContractAddress = exports.priceServiceEndpoint = void 0;
|
|
4
4
|
exports.priceServiceEndpoint = {
|
|
5
5
|
"price-service-endpoint": {
|
|
6
6
|
description: "Endpoint URL for the hermes client. e.g: https://endpoint/example",
|
|
@@ -66,3 +66,19 @@ exports.controllerLogLevel = {
|
|
|
66
66
|
choices: ["trace", "debug", "info", "warn", "error"],
|
|
67
67
|
},
|
|
68
68
|
};
|
|
69
|
+
exports.enableMetrics = {
|
|
70
|
+
"enable-metrics": {
|
|
71
|
+
description: "Enable Prometheus metrics server",
|
|
72
|
+
type: "boolean",
|
|
73
|
+
required: false,
|
|
74
|
+
default: true,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
exports.metricsPort = {
|
|
78
|
+
"metrics-port": {
|
|
79
|
+
description: "Port for the Prometheus metrics server",
|
|
80
|
+
type: "number",
|
|
81
|
+
required: false,
|
|
82
|
+
default: 9090,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"price-config.d.ts","sourceRoot":"","sources":["../src/price-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAIvD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAmB,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAuBxC,MAAM,MAAM,WAAW,GAAG;IACxB,KAA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,yBAAyB,EAAE,SAAS,GAAG,SAAS,CAAC;IACjD,0BAA0B,EAAE,SAAS,GAAG,SAAS,CAAC;CACnD,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE,CAuB/D;AAED,oBAAY,eAAe;IAEzB,GAAG,IAAA;IAEH,KAAK,IAAA;IAEL,EAAE,IAAA;CACH;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,WAAW,EAAE,WAAW,EACxB,iBAAiB,EAAE,SAAS,GAAG,SAAS,EACxC,iBAAiB,EAAE,SAAS,GAAG,SAAS,EACxC,MAAM,EAAE,MAAM,GACb,eAAe,CAsEjB"}
|
package/lib/price-config.js
CHANGED
|
@@ -84,7 +84,11 @@ function shouldUpdate(priceConfig, sourceLatestPrice, targetLatestPrice, logger)
|
|
|
84
84
|
Number(targetLatestPrice.price)) *
|
|
85
85
|
100;
|
|
86
86
|
const confidenceRatioPct = Math.abs((Number(sourceLatestPrice.conf) / Number(sourceLatestPrice.price)) * 100);
|
|
87
|
-
logger.info({
|
|
87
|
+
logger.info({
|
|
88
|
+
sourcePrice: sourceLatestPrice,
|
|
89
|
+
targetPrice: targetLatestPrice,
|
|
90
|
+
symbol: priceConfig.alias,
|
|
91
|
+
}, `Analyzing price ${priceConfig.alias} (${priceId}). ` +
|
|
88
92
|
`Time difference: ${timeDifference} (< ${priceConfig.timeDifference}? / early: < ${priceConfig.earlyUpdateTimeDifference}) OR ` +
|
|
89
93
|
`Price deviation: ${priceDeviationPct.toFixed(5)}% (< ${priceConfig.priceDeviation}%? / early: < ${priceConfig.earlyUpdatePriceDeviation}%?) OR ` +
|
|
90
94
|
`Confidence ratio: ${confidenceRatioPct.toFixed(5)}% (< ${priceConfig.confidenceRatio}%? / early: < ${priceConfig.earlyUpdatePriceDeviation}%?)`);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { BaseBalanceTracker, BaseBalanceTrackerConfig, IBalanceTracker } from "../interface";
|
|
3
|
+
import { DurationInSeconds } from "../utils";
|
|
4
|
+
import { PricePusherMetrics } from "../metrics";
|
|
5
|
+
import { Logger } from "pino";
|
|
6
|
+
/**
|
|
7
|
+
* Solana-specific configuration for balance tracker
|
|
8
|
+
*/
|
|
9
|
+
export interface SolanaBalanceTrackerConfig extends BaseBalanceTrackerConfig {
|
|
10
|
+
/** Solana connection instance */
|
|
11
|
+
connection: Connection;
|
|
12
|
+
/** Solana public key */
|
|
13
|
+
publicKey: PublicKey;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Solana-specific implementation of the balance tracker
|
|
17
|
+
*/
|
|
18
|
+
export declare class SolanaBalanceTracker extends BaseBalanceTracker {
|
|
19
|
+
private connection;
|
|
20
|
+
private publicKey;
|
|
21
|
+
constructor(config: SolanaBalanceTrackerConfig);
|
|
22
|
+
/**
|
|
23
|
+
* Solana-specific implementation of balance update
|
|
24
|
+
*/
|
|
25
|
+
protected updateBalance(): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Parameters for creating a Solana balance tracker
|
|
29
|
+
*/
|
|
30
|
+
export interface CreateSolanaBalanceTrackerParams {
|
|
31
|
+
connection: Connection;
|
|
32
|
+
publicKey: PublicKey;
|
|
33
|
+
network: string;
|
|
34
|
+
updateInterval: DurationInSeconds;
|
|
35
|
+
metrics: PricePusherMetrics;
|
|
36
|
+
logger: Logger;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Factory function to create a balance tracker for Solana
|
|
40
|
+
*/
|
|
41
|
+
export declare function createSolanaBalanceTracker(params: CreateSolanaBalanceTrackerParams): IBalanceTracker;
|
|
42
|
+
//# sourceMappingURL=balance-tracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"balance-tracker.d.ts","sourceRoot":"","sources":["../../src/solana/balance-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAoB,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,eAAe,EAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B;;GAEG;AACH,MAAM,WAAW,0BAA2B,SAAQ,wBAAwB;IAC1E,iCAAiC;IACjC,UAAU,EAAE,UAAU,CAAC;IACvB,wBAAwB;IACxB,SAAS,EAAE,SAAS,CAAC;CACtB;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,kBAAkB;IAC1D,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,SAAS,CAAY;gBAEjB,MAAM,EAAE,0BAA0B;IAU9C;;OAEG;cACa,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;CAwB/C;AAED;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAC/C,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,EAAE,SAAS,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,iBAAiB,CAAC;IAClC,OAAO,EAAE,kBAAkB,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,gCAAgC,GACvC,eAAe,CAUjB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SolanaBalanceTracker = void 0;
|
|
4
|
+
exports.createSolanaBalanceTracker = createSolanaBalanceTracker;
|
|
5
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
+
const interface_1 = require("../interface");
|
|
7
|
+
/**
|
|
8
|
+
* Solana-specific implementation of the balance tracker
|
|
9
|
+
*/
|
|
10
|
+
class SolanaBalanceTracker extends interface_1.BaseBalanceTracker {
|
|
11
|
+
connection;
|
|
12
|
+
publicKey;
|
|
13
|
+
constructor(config) {
|
|
14
|
+
super({
|
|
15
|
+
...config,
|
|
16
|
+
logger: config.logger.child({ module: "SolanaBalanceTracker" }),
|
|
17
|
+
});
|
|
18
|
+
this.connection = config.connection;
|
|
19
|
+
this.publicKey = config.publicKey;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Solana-specific implementation of balance update
|
|
23
|
+
*/
|
|
24
|
+
async updateBalance() {
|
|
25
|
+
try {
|
|
26
|
+
const balanceInLamports = await this.connection.getBalance(this.publicKey);
|
|
27
|
+
// Convert from lamports to SOL
|
|
28
|
+
const balanceInSol = balanceInLamports / web3_js_1.LAMPORTS_PER_SOL;
|
|
29
|
+
this.metrics.updateWalletBalance(this.address, this.network, balanceInSol);
|
|
30
|
+
this.logger.debug(`Updated Solana wallet balance: ${this.address} = ${balanceInSol.toString()} SOL (${balanceInLamports} lamports)`);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
this.logger.error({ error }, "Error fetching Solana wallet balance for metrics");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.SolanaBalanceTracker = SolanaBalanceTracker;
|
|
38
|
+
/**
|
|
39
|
+
* Factory function to create a balance tracker for Solana
|
|
40
|
+
*/
|
|
41
|
+
function createSolanaBalanceTracker(params) {
|
|
42
|
+
return new SolanaBalanceTracker({
|
|
43
|
+
connection: params.connection,
|
|
44
|
+
publicKey: params.publicKey,
|
|
45
|
+
address: params.publicKey.toString(),
|
|
46
|
+
network: params.network,
|
|
47
|
+
updateInterval: params.updateInterval,
|
|
48
|
+
metrics: params.metrics,
|
|
49
|
+
logger: params.logger,
|
|
50
|
+
});
|
|
51
|
+
}
|
package/lib/solana/command.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/solana/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAehC,OAAO,EACL,cAAc,EAEf,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/solana/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAehC,OAAO,EACL,cAAc,EAEf,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;;;;;;;;;;;;;;kBAerB,OAAO;wBAKP,OAAO;oBAKP,OAAO;6CAKP,OAAO;yBAKP,OAAO;6BAMP,OAAO;6BAKP,OAAO;6BAKP,OAAO;iCAKP,OAAO;4BAKP,OAAO;mCAKP,OAAO;wCAKP,OAAO;uBAMP,OAAO;;oBAWiB,GAAG;;AAjFpC,wBAyOE;AAEF,eAAO,MAAM,cAAc,GAAI,GAAG,cAAc,EAAE,QAAQ,MAAM,SAO/D,CAAC"}
|
package/lib/solana/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
|
};
|
|
@@ -41,6 +51,8 @@ const searcher_1 = require("jito-ts/dist/sdk/block-engine/searcher");
|
|
|
41
51
|
const pino_1 = __importDefault(require("pino"));
|
|
42
52
|
const hermes_client_1 = require("@pythnetwork/hermes-client");
|
|
43
53
|
const utils_1 = require("../utils");
|
|
54
|
+
const metrics_1 = require("../metrics");
|
|
55
|
+
const balance_tracker_1 = require("./balance-tracker");
|
|
44
56
|
exports.default = {
|
|
45
57
|
command: "solana",
|
|
46
58
|
describe: "run price pusher for solana",
|
|
@@ -117,12 +129,21 @@ exports.default = {
|
|
|
117
129
|
...options.pushingFrequency,
|
|
118
130
|
...options.logLevel,
|
|
119
131
|
...options.controllerLogLevel,
|
|
132
|
+
...options.enableMetrics,
|
|
133
|
+
...options.metricsPort,
|
|
120
134
|
},
|
|
121
135
|
handler: async function (argv) {
|
|
122
|
-
const { endpoint, keypairFile, shardId, computeUnitPriceMicroLamports, priceConfigFile, priceServiceEndpoint, pythContractAddress, pushingFrequency, pollingFrequency, jitoEndpoint, jitoKeypairFile, jitoTipLamports, dynamicJitoTips, maxJitoTipLamports, jitoBundleSize, updatesPerJitoBundle, addressLookupTableAccount, treasuryId, logLevel, controllerLogLevel, } = argv;
|
|
136
|
+
const { endpoint, keypairFile, shardId, computeUnitPriceMicroLamports, priceConfigFile, priceServiceEndpoint, pythContractAddress, pushingFrequency, pollingFrequency, jitoEndpoint, jitoKeypairFile, jitoTipLamports, dynamicJitoTips, maxJitoTipLamports, jitoBundleSize, updatesPerJitoBundle, addressLookupTableAccount, treasuryId, logLevel, controllerLogLevel, enableMetrics, metricsPort, } = argv;
|
|
123
137
|
const logger = (0, pino_1.default)({ level: logLevel });
|
|
124
138
|
const priceConfigs = (0, price_config_1.readPriceConfigFile)(priceConfigFile);
|
|
125
139
|
const hermesClient = new hermes_client_1.HermesClient(priceServiceEndpoint);
|
|
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
|
+
}
|
|
126
147
|
let priceItems = priceConfigs.map(({ id, alias }) => ({ id, alias }));
|
|
127
148
|
// Better to filter out invalid price items before creating the pyth listener
|
|
128
149
|
const { existingPriceItems, invalidPriceItems } = await (0, utils_1.filterInvalidPriceItems)(hermesClient, priceItems);
|
|
@@ -133,7 +154,8 @@ exports.default = {
|
|
|
133
154
|
}
|
|
134
155
|
priceItems = existingPriceItems;
|
|
135
156
|
const pythListener = new pyth_price_listener_1.PythPriceListener(hermesClient, priceItems, logger.child({ module: "PythPriceListener" }));
|
|
136
|
-
const
|
|
157
|
+
const keypair = web3_js_1.Keypair.fromSecretKey(Uint8Array.from(JSON.parse(fs_1.default.readFileSync(keypairFile, "ascii"))));
|
|
158
|
+
const wallet = new nodewallet_1.default(keypair);
|
|
137
159
|
const connection = new web3_js_1.Connection(endpoint, "processed");
|
|
138
160
|
const pythSolanaReceiver = new pyth_solana_receiver_1.PythSolanaReceiver({
|
|
139
161
|
connection,
|
|
@@ -141,6 +163,19 @@ exports.default = {
|
|
|
141
163
|
pushOracleProgramId: new web3_js_2.PublicKey(pythContractAddress),
|
|
142
164
|
treasuryId: treasuryId,
|
|
143
165
|
});
|
|
166
|
+
// Create and start the balance tracker if metrics are enabled
|
|
167
|
+
if (metrics) {
|
|
168
|
+
const balanceTracker = (0, balance_tracker_1.createSolanaBalanceTracker)({
|
|
169
|
+
connection,
|
|
170
|
+
publicKey: keypair.publicKey,
|
|
171
|
+
network: "solana",
|
|
172
|
+
updateInterval: 60,
|
|
173
|
+
metrics,
|
|
174
|
+
logger,
|
|
175
|
+
});
|
|
176
|
+
// Start the balance tracker
|
|
177
|
+
await balanceTracker.start();
|
|
178
|
+
}
|
|
144
179
|
// Fetch the account lookup table if provided
|
|
145
180
|
const lookupTableAccount = addressLookupTableAccount
|
|
146
181
|
? await connection
|
|
@@ -158,7 +193,10 @@ exports.default = {
|
|
|
158
193
|
solanaPricePusher = new solana_1.SolanaPricePusher(pythSolanaReceiver, hermesClient, logger.child({ module: "SolanaPricePusher" }), shardId, computeUnitPriceMicroLamports, lookupTableAccount);
|
|
159
194
|
}
|
|
160
195
|
const solanaPriceListener = new solana_1.SolanaPriceListener(pythSolanaReceiver, shardId, priceItems, logger.child({ module: "SolanaPriceListener" }), { pollingFrequency });
|
|
161
|
-
const controller = new controller_1.Controller(priceConfigs, pythListener, solanaPriceListener, solanaPricePusher, logger.child({ module: "Controller" }, { level: controllerLogLevel }), {
|
|
196
|
+
const controller = new controller_1.Controller(priceConfigs, pythListener, solanaPriceListener, solanaPricePusher, logger.child({ module: "Controller" }, { level: controllerLogLevel }), {
|
|
197
|
+
pushingFrequency,
|
|
198
|
+
metrics,
|
|
199
|
+
});
|
|
162
200
|
controller.start();
|
|
163
201
|
},
|
|
164
202
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solana.d.ts","sourceRoot":"","sources":["../../src/solana/solana.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,SAAS,EACT,SAAS,EACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,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AAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;YAsB/C,KAAK;IAIb,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAyEzD"}
|
package/lib/solana/solana.js
CHANGED
|
@@ -142,7 +142,7 @@ class SolanaPricePusherJito {
|
|
|
142
142
|
}
|
|
143
143
|
async getRecentJitoTipLamports() {
|
|
144
144
|
try {
|
|
145
|
-
const response = await fetch("
|
|
145
|
+
const response = await fetch("https://bundles.jito.wtf/api/v1/bundles/tip_floor");
|
|
146
146
|
if (!response.ok) {
|
|
147
147
|
this.logger.error({ status: response.status, statusText: response.statusText }, "getRecentJitoTips http request failed");
|
|
148
148
|
return undefined;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { SuiClient } from "@mysten/sui/client";
|
|
2
|
+
import { BaseBalanceTracker, BaseBalanceTrackerConfig, IBalanceTracker } from "../interface";
|
|
3
|
+
import { DurationInSeconds } from "../utils";
|
|
4
|
+
import { PricePusherMetrics } from "../metrics";
|
|
5
|
+
import { Logger } from "pino";
|
|
6
|
+
/**
|
|
7
|
+
* Sui-specific configuration for balance tracker
|
|
8
|
+
*/
|
|
9
|
+
export interface SuiBalanceTrackerConfig extends BaseBalanceTrackerConfig {
|
|
10
|
+
/** Sui client instance */
|
|
11
|
+
client: SuiClient;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Sui-specific implementation of the balance tracker
|
|
15
|
+
*/
|
|
16
|
+
export declare class SuiBalanceTracker extends BaseBalanceTracker {
|
|
17
|
+
private client;
|
|
18
|
+
constructor(config: SuiBalanceTrackerConfig);
|
|
19
|
+
/**
|
|
20
|
+
* Sui-specific implementation of balance update
|
|
21
|
+
*/
|
|
22
|
+
protected updateBalance(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Parameters for creating a Sui balance tracker
|
|
26
|
+
*/
|
|
27
|
+
export interface CreateSuiBalanceTrackerParams {
|
|
28
|
+
client: SuiClient;
|
|
29
|
+
address: string;
|
|
30
|
+
network: string;
|
|
31
|
+
updateInterval: DurationInSeconds;
|
|
32
|
+
metrics: PricePusherMetrics;
|
|
33
|
+
logger: Logger;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Factory function to create a balance tracker for Sui chain
|
|
37
|
+
*/
|
|
38
|
+
export declare function createSuiBalanceTracker(params: CreateSuiBalanceTrackerParams): IBalanceTracker;
|
|
39
|
+
//# sourceMappingURL=balance-tracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"balance-tracker.d.ts","sourceRoot":"","sources":["../../src/sui/balance-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,eAAe,EAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B;;GAEG;AACH,MAAM,WAAW,uBAAwB,SAAQ,wBAAwB;IACvE,0BAA0B;IAC1B,MAAM,EAAE,SAAS,CAAC;CACnB;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,kBAAkB;IACvD,OAAO,CAAC,MAAM,CAAY;gBAEd,MAAM,EAAE,uBAAuB;IAS3C;;OAEG;cACa,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;CA+B/C;AAED;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C,MAAM,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,iBAAiB,CAAC;IAClC,OAAO,EAAE,kBAAkB,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,6BAA6B,GACpC,eAAe,CASjB"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SuiBalanceTracker = void 0;
|
|
4
|
+
exports.createSuiBalanceTracker = createSuiBalanceTracker;
|
|
5
|
+
const interface_1 = require("../interface");
|
|
6
|
+
/**
|
|
7
|
+
* Sui-specific implementation of the balance tracker
|
|
8
|
+
*/
|
|
9
|
+
class SuiBalanceTracker extends interface_1.BaseBalanceTracker {
|
|
10
|
+
client;
|
|
11
|
+
constructor(config) {
|
|
12
|
+
super({
|
|
13
|
+
...config,
|
|
14
|
+
logger: config.logger.child({ module: "SuiBalanceTracker" }),
|
|
15
|
+
});
|
|
16
|
+
this.client = config.client;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Sui-specific implementation of balance update
|
|
20
|
+
*/
|
|
21
|
+
async updateBalance() {
|
|
22
|
+
try {
|
|
23
|
+
// Get all coins owned by the address
|
|
24
|
+
const { data: coins } = await this.client.getCoins({
|
|
25
|
+
owner: this.address,
|
|
26
|
+
});
|
|
27
|
+
// Sum up all coin balances
|
|
28
|
+
const totalBalance = coins.reduce((acc, coin) => {
|
|
29
|
+
return acc + BigInt(coin.balance);
|
|
30
|
+
}, BigInt(0));
|
|
31
|
+
// Convert to a normalized number for reporting (SUI has 9 decimals)
|
|
32
|
+
const normalizedBalance = Number(totalBalance) / 1e9;
|
|
33
|
+
this.metrics.updateWalletBalance(this.address, this.network, normalizedBalance);
|
|
34
|
+
this.logger.debug(`Updated Sui wallet balance: ${this.address} = ${normalizedBalance} SUI`);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
this.logger.error({ error }, "Error fetching Sui wallet balance for metrics");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.SuiBalanceTracker = SuiBalanceTracker;
|
|
42
|
+
/**
|
|
43
|
+
* Factory function to create a balance tracker for Sui chain
|
|
44
|
+
*/
|
|
45
|
+
function createSuiBalanceTracker(params) {
|
|
46
|
+
return new SuiBalanceTracker({
|
|
47
|
+
client: params.client,
|
|
48
|
+
address: params.address,
|
|
49
|
+
network: params.network,
|
|
50
|
+
updateInterval: params.updateInterval,
|
|
51
|
+
metrics: params.metrics,
|
|
52
|
+
logger: params.logger,
|
|
53
|
+
});
|
|
54
|
+
}
|
package/lib/sui/command.d.ts
CHANGED
package/lib/sui/command.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/sui/command.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/sui/command.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;;;;;;;;;;;;;;kBAwBvB,OAAO;yBAOP,OAAO;6BAOP,OAAO;2BAMP,OAAO;8BAOP,OAAO;sBAMP,OAAO;yBAMP,OAAO;;oBAWiB,GAAG;;AAjEpC,wBAoLE"}
|