@pythnetwork/price-pusher 10.0.0 → 10.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -3
- 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} +36 -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 +11 -9
- 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 -129
- 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 -218
- 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
package/lib/injective/command.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
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
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
const hermes_client_1 = require("@pythnetwork/hermes-client");
|
|
40
|
-
const options = __importStar(require("../options"));
|
|
41
|
-
const price_config_1 = require("../price-config");
|
|
42
|
-
const fs_1 = __importDefault(require("fs"));
|
|
43
|
-
const injective_1 = require("./injective");
|
|
44
|
-
const pyth_price_listener_1 = require("../pyth-price-listener");
|
|
45
|
-
const controller_1 = require("../controller");
|
|
46
|
-
const networks_1 = require("@injectivelabs/networks");
|
|
47
|
-
const pino_1 = __importDefault(require("pino"));
|
|
48
|
-
const utils_1 = require("../utils");
|
|
49
|
-
exports.default = {
|
|
50
|
-
command: "injective",
|
|
51
|
-
describe: "run price pusher for injective",
|
|
52
|
-
builder: {
|
|
53
|
-
"grpc-endpoint": {
|
|
54
|
-
description: "gRPC endpoint URL for injective. The pusher will periodically" +
|
|
55
|
-
"poll for updates. The polling interval is configurable via the " +
|
|
56
|
-
"`polling-frequency` command-line argument.",
|
|
57
|
-
type: "string",
|
|
58
|
-
required: true,
|
|
59
|
-
},
|
|
60
|
-
network: {
|
|
61
|
-
description: "testnet or mainnet",
|
|
62
|
-
type: "string",
|
|
63
|
-
required: true,
|
|
64
|
-
},
|
|
65
|
-
"gas-price": {
|
|
66
|
-
description: "Gas price to be used for each transaction",
|
|
67
|
-
type: "number",
|
|
68
|
-
},
|
|
69
|
-
"gas-multiplier": {
|
|
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.",
|
|
75
|
-
type: "number",
|
|
76
|
-
required: false,
|
|
77
|
-
},
|
|
78
|
-
...options.priceConfigFile,
|
|
79
|
-
...options.priceServiceEndpoint,
|
|
80
|
-
...options.mnemonicFile,
|
|
81
|
-
...options.pythContractAddress,
|
|
82
|
-
...options.pollingFrequency,
|
|
83
|
-
...options.pushingFrequency,
|
|
84
|
-
...options.logLevel,
|
|
85
|
-
...options.controllerLogLevel,
|
|
86
|
-
},
|
|
87
|
-
handler: async function (argv) {
|
|
88
|
-
// FIXME: type checks for this
|
|
89
|
-
const { network, logLevel, gasPrice, grpcEndpoint, mnemonicFile, gasMultiplier, priceConfigFile, pollingFrequency, pushingFrequency, controllerLogLevel, pythContractAddress, priceServiceEndpoint, priceIdsProcessChunkSize, } = argv;
|
|
90
|
-
const logger = (0, pino_1.default)({ level: logLevel });
|
|
91
|
-
if (network !== "testnet" && network !== "mainnet") {
|
|
92
|
-
throw new Error("Please specify network. One of [testnet, mainnet]");
|
|
93
|
-
}
|
|
94
|
-
const priceConfigs = (0, price_config_1.readPriceConfigFile)(priceConfigFile);
|
|
95
|
-
const hermesClient = new hermes_client_1.HermesClient(priceServiceEndpoint);
|
|
96
|
-
const mnemonic = fs_1.default.readFileSync(mnemonicFile, "utf-8").trim();
|
|
97
|
-
let priceItems = priceConfigs.map(({ id, alias }) => ({ id, alias }));
|
|
98
|
-
// Better to filter out invalid price items before creating the pyth listener
|
|
99
|
-
const { existingPriceItems, invalidPriceItems } = await (0, utils_1.filterInvalidPriceItems)(hermesClient, priceItems);
|
|
100
|
-
if (invalidPriceItems.length > 0) {
|
|
101
|
-
logger.error(`Invalid price id submitted for: ${invalidPriceItems
|
|
102
|
-
.map(({ alias }) => alias)
|
|
103
|
-
.join(", ")}`);
|
|
104
|
-
}
|
|
105
|
-
priceItems = existingPriceItems;
|
|
106
|
-
const pythListener = new pyth_price_listener_1.PythPriceListener(hermesClient, priceItems, logger.child({ module: "PythPriceListener" }));
|
|
107
|
-
const injectiveListener = new injective_1.InjectivePriceListener(pythContractAddress, grpcEndpoint, priceItems, logger.child({ module: "InjectivePriceListener" }), {
|
|
108
|
-
pollingFrequency,
|
|
109
|
-
});
|
|
110
|
-
const injectivePusher = new injective_1.InjectivePricePusher(hermesClient, pythContractAddress, grpcEndpoint, logger.child({ module: "InjectivePricePusher" }), mnemonic, {
|
|
111
|
-
chainId: (0, networks_1.getNetworkInfo)(network).chainId,
|
|
112
|
-
gasPrice,
|
|
113
|
-
gasMultiplier,
|
|
114
|
-
priceIdsProcessChunkSize,
|
|
115
|
-
});
|
|
116
|
-
const controller = new controller_1.Controller(priceConfigs, pythListener, injectiveListener, injectivePusher, logger.child({ module: "Controller" }, { level: controllerLogLevel }), { pushingFrequency });
|
|
117
|
-
controller.start();
|
|
118
|
-
},
|
|
119
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
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,SAAS,EACT,SAAS,EACT,YAAY,EACZ,kBAAkB,EACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAa7C,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAmB9B,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;AAGF,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,qBAAa,oBAAqB,YAAW,YAAY;IAOrD,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,mBAAmB;IAC3B,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,MAAM;IAThB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,QAAQ,CACX,CAAC,2BAA2B;gBAGvB,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;IAaxC,OAAO,CAAC,SAAS;YAWH,mBAAmB;IA+C3B,eAAe,CACnB,QAAQ,EAAE,MAAM,EAAE,EAClB,cAAc,EAAE,MAAM,EAAE,GACvB,OAAO,CAAC,IAAI,CAAC;YAuBF,oBAAoB;IA+ClC;;;;;OAKG;YACW,SAAS;IA0CvB;;OAEG;YACW,wBAAwB;IAuBtC;;OAEG;YACW,YAAY;CAwB3B"}
|
package/lib/interface.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;CAC5D;AAED,8BAAsB,kBAAmB,YAAW,cAAc;IAK9D,OAAO,CAAC,gBAAgB;IACxB,SAAS,CAAC,UAAU,EAAE,SAAS,EAAE;IALnC,OAAO,CAAC,eAAe,CAA4B;IACnD,SAAS,CAAC,cAAc,EAAE,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;gBAGvC,gBAAgB,EAAE,iBAAiB,EACjC,UAAU,EAAE,SAAS,EAAE;IAQ7B,KAAK;YAMG,UAAU;IASxB,SAAS,CAAC,qBAAqB,CAC7B,OAAO,EAAE,SAAS,EAClB,aAAa,EAAE,SAAS;IAkB1B,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IAI1D,QAAQ,CAAC,mBAAmB,CAC1B,OAAO,EAAE,SAAS,GACjB,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;CAClC;AAED,MAAM,WAAW,YAAY;IAC3B,eAAe,CACb,QAAQ,EAAE,MAAM,EAAE,EAClB,cAAc,EAAE,aAAa,EAAE,GAC9B,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,sCAAsC;IACtC,cAAc,EAAE,iBAAiB,CAAC;IAClC,iDAAiD;IACjD,OAAO,EAAE,kBAAkB,CAAC;IAC5B,sBAAsB;IACtB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB;;OAEG;IACH,IAAI,IAAI,IAAI,CAAC;CACd;AAED;;GAEG;AACH,8BAAsB,kBAAmB,YAAW,eAAe;IACjE,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;IAC1B,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
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
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
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.BaseBalanceTracker = exports.ChainPriceListener = void 0;
|
|
37
|
-
class ChainPriceListener {
|
|
38
|
-
pollingFrequency;
|
|
39
|
-
priceItems;
|
|
40
|
-
latestPriceInfo;
|
|
41
|
-
priceIdToAlias;
|
|
42
|
-
constructor(pollingFrequency, priceItems) {
|
|
43
|
-
this.pollingFrequency = pollingFrequency;
|
|
44
|
-
this.priceItems = priceItems;
|
|
45
|
-
this.latestPriceInfo = new Map();
|
|
46
|
-
this.priceIdToAlias = new Map(priceItems.map(({ id, alias }) => [id, alias]));
|
|
47
|
-
}
|
|
48
|
-
async start() {
|
|
49
|
-
setInterval(this.pollPrices.bind(this), this.pollingFrequency * 1000);
|
|
50
|
-
await this.pollPrices();
|
|
51
|
-
}
|
|
52
|
-
async pollPrices() {
|
|
53
|
-
for (const { id: priceId } of this.priceItems) {
|
|
54
|
-
const currentPriceInfo = await this.getOnChainPriceInfo(priceId);
|
|
55
|
-
if (currentPriceInfo !== undefined) {
|
|
56
|
-
this.updateLatestPriceInfo(priceId, currentPriceInfo);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
updateLatestPriceInfo(priceId, observedPrice) {
|
|
61
|
-
const cachedLatestPriceInfo = this.getLatestPriceInfo(priceId);
|
|
62
|
-
// Ignore the observed price if the cache already has newer
|
|
63
|
-
// price. This could happen because we are using polling and
|
|
64
|
-
// subscription at the same time.
|
|
65
|
-
if (cachedLatestPriceInfo !== undefined &&
|
|
66
|
-
cachedLatestPriceInfo.publishTime > observedPrice.publishTime) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
this.latestPriceInfo.set(priceId, observedPrice);
|
|
70
|
-
}
|
|
71
|
-
// Should return undefined only when the price does not exist.
|
|
72
|
-
getLatestPriceInfo(priceId) {
|
|
73
|
-
return this.latestPriceInfo.get(priceId);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
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.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGjD,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,MAAM,CAAS;IAGhB,iBAAiB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACjC,mBAAmB,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACrC,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC/B,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC/B,wBAAwB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAExC,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;gBAExB,MAAM,EAAE,MAAM;IA2DnB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAOzB,iBAAiB,CACtB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,MAAc,GACtB,IAAI;IAUA,qBAAqB,CAC1B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,eAAe,GACzB,IAAI;IAgBA,sBAAsB,CAC3B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,MAAc,GACtB,IAAI;IAUA,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKvC,gBAAgB,CACrB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,4BAA4B,EAAE,MAAM,EACpC,4BAA4B,EAAE,MAAM,EACpC,yBAAyB,EAAE,MAAM,GAChC,IAAI;IAgBA,mBAAmB,CACxB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,MAAM,GACvB,IAAI;CAYR"}
|
package/lib/metrics.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
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
|
-
sourceTimestamp;
|
|
20
|
-
configuredTimeDifference;
|
|
21
|
-
// Wallet metrics
|
|
22
|
-
walletBalance;
|
|
23
|
-
constructor(logger) {
|
|
24
|
-
this.logger = logger;
|
|
25
|
-
this.registry = new prom_client_1.Registry();
|
|
26
|
-
this.server = (0, express_1.default)();
|
|
27
|
-
// Register the default metrics (memory, CPU, etc.)
|
|
28
|
-
this.registry.setDefaultLabels({ app: "price_pusher" });
|
|
29
|
-
// Create metrics
|
|
30
|
-
this.lastPublishedTime = new prom_client_1.Gauge({
|
|
31
|
-
name: "pyth_price_last_published_time",
|
|
32
|
-
help: "The last published time of a price feed in unix timestamp",
|
|
33
|
-
labelNames: ["price_id", "alias"],
|
|
34
|
-
registers: [this.registry],
|
|
35
|
-
});
|
|
36
|
-
this.priceUpdateAttempts = new prom_client_1.Counter({
|
|
37
|
-
name: "pyth_price_update_attempts_total",
|
|
38
|
-
help: "Total number of price update attempts with their trigger condition and status",
|
|
39
|
-
labelNames: ["price_id", "alias", "trigger", "status"],
|
|
40
|
-
registers: [this.registry],
|
|
41
|
-
});
|
|
42
|
-
this.priceFeedsTotal = new prom_client_1.Gauge({
|
|
43
|
-
name: "pyth_price_feeds_total",
|
|
44
|
-
help: "Total number of price feeds being monitored",
|
|
45
|
-
registers: [this.registry],
|
|
46
|
-
});
|
|
47
|
-
this.sourceTimestamp = new prom_client_1.Gauge({
|
|
48
|
-
name: "pyth_source_timestamp",
|
|
49
|
-
help: "Latest source chain price publish timestamp",
|
|
50
|
-
labelNames: ["price_id", "alias"],
|
|
51
|
-
registers: [this.registry],
|
|
52
|
-
});
|
|
53
|
-
this.configuredTimeDifference = new prom_client_1.Gauge({
|
|
54
|
-
name: "pyth_configured_time_difference",
|
|
55
|
-
help: "Configured time difference threshold between source and target chains",
|
|
56
|
-
labelNames: ["price_id", "alias"],
|
|
57
|
-
registers: [this.registry],
|
|
58
|
-
});
|
|
59
|
-
// Wallet balance metric
|
|
60
|
-
this.walletBalance = new prom_client_1.Gauge({
|
|
61
|
-
name: "pyth_wallet_balance",
|
|
62
|
-
help: "Current wallet balance of the price pusher in native token units",
|
|
63
|
-
labelNames: ["wallet_address", "network"],
|
|
64
|
-
registers: [this.registry],
|
|
65
|
-
});
|
|
66
|
-
// Setup the metrics endpoint
|
|
67
|
-
this.server.get("/metrics", async (req, res) => {
|
|
68
|
-
res.set("Content-Type", this.registry.contentType);
|
|
69
|
-
res.end(await this.registry.metrics());
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
// Start the metrics server
|
|
73
|
-
start(port) {
|
|
74
|
-
this.server.listen(port, () => {
|
|
75
|
-
this.logger.info(`Metrics server started on port ${port}`);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
// Record a successful price update
|
|
79
|
-
recordPriceUpdate(priceId, alias, trigger = "yes") {
|
|
80
|
-
this.priceUpdateAttempts.inc({
|
|
81
|
-
price_id: priceId,
|
|
82
|
-
alias,
|
|
83
|
-
trigger: trigger.toLowerCase(),
|
|
84
|
-
status: "success",
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
// Record update condition status (YES/NO/EARLY)
|
|
88
|
-
recordUpdateCondition(priceId, alias, condition) {
|
|
89
|
-
const triggerLabel = price_config_1.UpdateCondition[condition].toLowerCase();
|
|
90
|
-
// Only record as 'skipped' when the condition is NO
|
|
91
|
-
if (condition === price_config_1.UpdateCondition.NO) {
|
|
92
|
-
this.priceUpdateAttempts.inc({
|
|
93
|
-
price_id: priceId,
|
|
94
|
-
alias,
|
|
95
|
-
trigger: triggerLabel,
|
|
96
|
-
status: "skipped",
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
// YES and EARLY don't increment the counter here - they'll be counted
|
|
100
|
-
// when recordPriceUpdate or recordPriceUpdateError is called
|
|
101
|
-
}
|
|
102
|
-
// Record a price update error
|
|
103
|
-
recordPriceUpdateError(priceId, alias, trigger = "yes") {
|
|
104
|
-
this.priceUpdateAttempts.inc({
|
|
105
|
-
price_id: priceId,
|
|
106
|
-
alias,
|
|
107
|
-
trigger: trigger.toLowerCase(),
|
|
108
|
-
status: "error",
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
// Set the number of price feeds
|
|
112
|
-
setPriceFeedsTotal(count) {
|
|
113
|
-
this.priceFeedsTotal.set(count);
|
|
114
|
-
}
|
|
115
|
-
// Update source, target and configured time difference timestamps
|
|
116
|
-
updateTimestamps(priceId, alias, targetLatestPricePublishTime, sourceLatestPricePublishTime, priceConfigTimeDifference) {
|
|
117
|
-
this.sourceTimestamp.set({ price_id: priceId, alias }, sourceLatestPricePublishTime);
|
|
118
|
-
this.lastPublishedTime.set({ price_id: priceId, alias }, targetLatestPricePublishTime);
|
|
119
|
-
this.configuredTimeDifference.set({ price_id: priceId, alias }, priceConfigTimeDifference);
|
|
120
|
-
}
|
|
121
|
-
// Update wallet balance
|
|
122
|
-
updateWalletBalance(walletAddress, network, balance) {
|
|
123
|
-
// Convert to number for compatibility with prometheus
|
|
124
|
-
const balanceNum = typeof balance === "bigint" ? Number(balance) / 1e18 : balance;
|
|
125
|
-
this.walletBalance.set({ wallet_address: walletAddress, network }, balanceNum);
|
|
126
|
-
this.logger.debug(`Updated wallet balance metric: ${walletAddress} = ${balanceNum}`);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
exports.PricePusherMetrics = PricePusherMetrics;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/near/command.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;;;;;;;;;;;;oBAcvB,OAAO;iBAKP,OAAO;sBAKP,OAAO;4BAKP,OAAO;;oBASiB,GAAG;;AAjCpC,wBA8GE"}
|
package/lib/near/command.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
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
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
const hermes_client_1 = require("@pythnetwork/hermes-client");
|
|
40
|
-
const options = __importStar(require("../options"));
|
|
41
|
-
const price_config_1 = require("../price-config");
|
|
42
|
-
const pyth_price_listener_1 = require("../pyth-price-listener");
|
|
43
|
-
const controller_1 = require("../controller");
|
|
44
|
-
const near_1 = require("./near");
|
|
45
|
-
const pino_1 = __importDefault(require("pino"));
|
|
46
|
-
const utils_1 = require("../utils");
|
|
47
|
-
exports.default = {
|
|
48
|
-
command: "near",
|
|
49
|
-
describe: "run price pusher for near",
|
|
50
|
-
builder: {
|
|
51
|
-
"node-url": {
|
|
52
|
-
description: "NEAR RPC API url. used to make JSON RPC calls to interact with NEAR.",
|
|
53
|
-
type: "string",
|
|
54
|
-
required: true,
|
|
55
|
-
},
|
|
56
|
-
network: {
|
|
57
|
-
description: "testnet or mainnet.",
|
|
58
|
-
type: "string",
|
|
59
|
-
required: true,
|
|
60
|
-
},
|
|
61
|
-
"account-id": {
|
|
62
|
-
description: "payer account identifier.",
|
|
63
|
-
type: "string",
|
|
64
|
-
required: true,
|
|
65
|
-
},
|
|
66
|
-
"private-key-path": {
|
|
67
|
-
description: "path to payer private key file.",
|
|
68
|
-
type: "string",
|
|
69
|
-
required: false,
|
|
70
|
-
},
|
|
71
|
-
...options.priceConfigFile,
|
|
72
|
-
...options.priceServiceEndpoint,
|
|
73
|
-
...options.pythContractAddress,
|
|
74
|
-
...options.pollingFrequency,
|
|
75
|
-
...options.pushingFrequency,
|
|
76
|
-
...options.logLevel,
|
|
77
|
-
...options.controllerLogLevel,
|
|
78
|
-
},
|
|
79
|
-
handler: async function (argv) {
|
|
80
|
-
// FIXME: type checks for this
|
|
81
|
-
const { nodeUrl, network, accountId, privateKeyPath, priceConfigFile, priceServiceEndpoint, pythContractAddress, pushingFrequency, pollingFrequency, logLevel, controllerLogLevel, } = argv;
|
|
82
|
-
const logger = (0, pino_1.default)({ level: logLevel });
|
|
83
|
-
const priceConfigs = (0, price_config_1.readPriceConfigFile)(priceConfigFile);
|
|
84
|
-
const hermesClient = new hermes_client_1.HermesClient(priceServiceEndpoint);
|
|
85
|
-
let priceItems = priceConfigs.map(({ id, alias }) => ({ id, alias }));
|
|
86
|
-
// Better to filter out invalid price items before creating the pyth listener
|
|
87
|
-
const { existingPriceItems, invalidPriceItems } = await (0, utils_1.filterInvalidPriceItems)(hermesClient, priceItems);
|
|
88
|
-
if (invalidPriceItems.length > 0) {
|
|
89
|
-
logger.error(`Invalid price id submitted for: ${invalidPriceItems
|
|
90
|
-
.map(({ alias }) => alias)
|
|
91
|
-
.join(", ")}`);
|
|
92
|
-
}
|
|
93
|
-
priceItems = existingPriceItems;
|
|
94
|
-
const pythListener = new pyth_price_listener_1.PythPriceListener(hermesClient, priceItems, logger);
|
|
95
|
-
const nearAccount = new near_1.NearAccount(network, accountId, nodeUrl, privateKeyPath, pythContractAddress);
|
|
96
|
-
const nearListener = new near_1.NearPriceListener(nearAccount, priceItems, logger.child({ module: "NearPriceListener" }), {
|
|
97
|
-
pollingFrequency,
|
|
98
|
-
});
|
|
99
|
-
const nearPusher = new near_1.NearPricePusher(nearAccount, hermesClient, logger.child({ module: "NearPricePusher" }));
|
|
100
|
-
const controller = new controller_1.Controller(priceConfigs, pythListener, nearListener, nearPusher, logger.child({ module: "Controller" }, { level: controllerLogLevel }), { pushingFrequency });
|
|
101
|
-
controller.start();
|
|
102
|
-
},
|
|
103
|
-
};
|
package/lib/near/near.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"near.d.ts","sourceRoot":"","sources":["../../src/near/near.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,SAAS,EACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAa,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAG7C,OAAO,EAGL,qBAAqB,EACtB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,qBAAa,iBAAkB,SAAQ,kBAAkB;IAErD,OAAO,CAAC,OAAO;IAEf,OAAO,CAAC,MAAM;gBAFN,OAAO,EAAE,WAAW,EAC5B,UAAU,EAAE,SAAS,EAAE,EACf,MAAM,EAAE,MAAM,EACtB,MAAM,EAAE;QACN,gBAAgB,EAAE,iBAAiB,CAAC;KACrC;IAKG,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;CAwB3E;AAED,qBAAa,eAAgB,YAAW,YAAY;IAEhD,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,MAAM;gBAFN,OAAO,EAAE,WAAW,EACpB,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,MAAM;IAGlB,eAAe,CACnB,QAAQ,EAAE,MAAM,EAAE,EAClB,cAAc,EAAE,MAAM,EAAE,GACvB,OAAO,CAAC,IAAI,CAAC;YA0DF,uBAAuB;CAStC;AAED,qBAAa,WAAW;IAQpB,OAAO,CAAC,aAAa;IAPvB,OAAO,CAAC,OAAO,CAAU;gBAGvB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,MAAM,GAAG,SAAS,EAC1B,aAAa,EAAE,MAAM;IAWzB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAU7C,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAUhD,gBAAgB,CACpB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,GAAG,GACb,OAAO,CAAC,qBAAqB,CAAC;IAYjC,OAAO,CAAC,aAAa;CAkCtB"}
|
package/lib/near/near.js
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
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.NearAccount = exports.NearPricePusher = exports.NearPriceListener = void 0;
|
|
7
|
-
const os_1 = __importDefault(require("os"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const fs_1 = __importDefault(require("fs"));
|
|
10
|
-
const interface_1 = require("../interface");
|
|
11
|
-
const near_api_js_1 = require("near-api-js");
|
|
12
|
-
const key_stores_1 = require("near-api-js/lib/key_stores");
|
|
13
|
-
class NearPriceListener extends interface_1.ChainPriceListener {
|
|
14
|
-
account;
|
|
15
|
-
logger;
|
|
16
|
-
constructor(account, priceItems, logger, config) {
|
|
17
|
-
super(config.pollingFrequency, priceItems);
|
|
18
|
-
this.account = account;
|
|
19
|
-
this.logger = logger;
|
|
20
|
-
}
|
|
21
|
-
async getOnChainPriceInfo(priceId) {
|
|
22
|
-
try {
|
|
23
|
-
const priceRaw = await this.account.getPriceUnsafe(priceId);
|
|
24
|
-
this.logger.debug(`Polled a NEAR on chain price for feed ${this.priceIdToAlias.get(priceId)} (${priceId}) ${JSON.stringify(priceRaw)}.`);
|
|
25
|
-
if (priceRaw) {
|
|
26
|
-
return {
|
|
27
|
-
conf: priceRaw.conf,
|
|
28
|
-
price: priceRaw.price,
|
|
29
|
-
publishTime: priceRaw.publish_time,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
catch (err) {
|
|
37
|
-
this.logger.error(err, `Polling on-chain price for ${priceId} failed.:`);
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.NearPriceListener = NearPriceListener;
|
|
43
|
-
class NearPricePusher {
|
|
44
|
-
account;
|
|
45
|
-
hermesClient;
|
|
46
|
-
logger;
|
|
47
|
-
constructor(account, hermesClient, logger) {
|
|
48
|
-
this.account = account;
|
|
49
|
-
this.hermesClient = hermesClient;
|
|
50
|
-
this.logger = logger;
|
|
51
|
-
}
|
|
52
|
-
async updatePriceFeed(priceIds, pubTimesToPush) {
|
|
53
|
-
if (priceIds.length === 0) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (priceIds.length !== pubTimesToPush.length)
|
|
57
|
-
throw new Error("Invalid arguments");
|
|
58
|
-
let priceFeedUpdateData;
|
|
59
|
-
try {
|
|
60
|
-
priceFeedUpdateData = await this.getPriceFeedsUpdateData(priceIds);
|
|
61
|
-
}
|
|
62
|
-
catch (err) {
|
|
63
|
-
this.logger.error(err, "getPriceFeedsUpdateData failed");
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
for (const data of priceFeedUpdateData) {
|
|
67
|
-
let updateFee;
|
|
68
|
-
try {
|
|
69
|
-
updateFee = await this.account.getUpdateFeeEstimate(data);
|
|
70
|
-
this.logger.debug(`Update fee: ${updateFee}`);
|
|
71
|
-
}
|
|
72
|
-
catch (err) {
|
|
73
|
-
this.logger.error(err, "getUpdateFeeEstimate failed");
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
try {
|
|
77
|
-
const outcome = await this.account.updatePriceFeeds(data, updateFee);
|
|
78
|
-
const failureMessages = [];
|
|
79
|
-
const is_success = Object.values(outcome["receipts_outcome"]).reduce((is_success, receipt) => {
|
|
80
|
-
if (Object.prototype.hasOwnProperty.call(receipt["outcome"]["status"], "Failure")) {
|
|
81
|
-
failureMessages.push(receipt["outcome"]["status"]);
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
return is_success;
|
|
85
|
-
}, true);
|
|
86
|
-
if (is_success) {
|
|
87
|
-
this.logger.info({ hash: outcome["transaction"]["hash"] }, "updatePriceFeeds successful.");
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
this.logger.error({ failureMessages }, "updatePriceFeeds failed");
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
catch (err) {
|
|
94
|
-
this.logger.error(err, "updatePriceFeeds failed");
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
async getPriceFeedsUpdateData(priceIds) {
|
|
99
|
-
const response = await this.hermesClient.getLatestPriceUpdates(priceIds, {
|
|
100
|
-
encoding: "base64",
|
|
101
|
-
ignoreInvalidPriceIds: true,
|
|
102
|
-
});
|
|
103
|
-
return response.binary.data;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
exports.NearPricePusher = NearPricePusher;
|
|
107
|
-
class NearAccount {
|
|
108
|
-
pythAccountId;
|
|
109
|
-
account;
|
|
110
|
-
constructor(network, accountId, nodeUrl, privateKeyPath, pythAccountId) {
|
|
111
|
-
this.pythAccountId = pythAccountId;
|
|
112
|
-
const connection = this.getConnection(network, accountId, nodeUrl, privateKeyPath);
|
|
113
|
-
this.account = new near_api_js_1.Account(connection, accountId);
|
|
114
|
-
}
|
|
115
|
-
async getPriceUnsafe(priceId) {
|
|
116
|
-
return await this.account.viewFunction({
|
|
117
|
-
contractId: this.pythAccountId,
|
|
118
|
-
methodName: "get_price_unsafe",
|
|
119
|
-
args: {
|
|
120
|
-
price_identifier: priceId,
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
async getUpdateFeeEstimate(data) {
|
|
125
|
-
return await this.account.viewFunction({
|
|
126
|
-
contractId: this.pythAccountId,
|
|
127
|
-
methodName: "get_update_fee_estimate",
|
|
128
|
-
args: {
|
|
129
|
-
data,
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
async updatePriceFeeds(data, updateFee) {
|
|
134
|
-
return await this.account.functionCall({
|
|
135
|
-
contractId: this.pythAccountId,
|
|
136
|
-
methodName: "update_price_feeds",
|
|
137
|
-
args: {
|
|
138
|
-
data,
|
|
139
|
-
},
|
|
140
|
-
gas: "300000000000000",
|
|
141
|
-
attachedDeposit: updateFee,
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
getConnection(network, accountId, nodeUrl, privateKeyPath) {
|
|
145
|
-
const content = fs_1.default.readFileSync(privateKeyPath ||
|
|
146
|
-
path_1.default.join(os_1.default.homedir(), ".near-credentials", network, accountId + ".json"));
|
|
147
|
-
const accountInfo = JSON.parse(content.toString());
|
|
148
|
-
let privateKey = accountInfo.private_key;
|
|
149
|
-
if (!privateKey && accountInfo.secret_key) {
|
|
150
|
-
privateKey = accountInfo.secret_key;
|
|
151
|
-
}
|
|
152
|
-
if (accountInfo.account_id && privateKey) {
|
|
153
|
-
const keyPair = near_api_js_1.KeyPair.fromString(privateKey);
|
|
154
|
-
const keyStore = new key_stores_1.InMemoryKeyStore();
|
|
155
|
-
keyStore.setKey(network, accountInfo.account_id, keyPair);
|
|
156
|
-
return near_api_js_1.Connection.fromConfig({
|
|
157
|
-
networkId: network,
|
|
158
|
-
provider: { type: "JsonRpcProvider", args: { url: nodeUrl } },
|
|
159
|
-
signer: { type: "InMemorySigner", keyStore },
|
|
160
|
-
jsvmAccountId: `jsvm.${network}`,
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
throw new Error("Invalid key file!");
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
exports.NearAccount = NearAccount;
|
package/lib/options.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|