@gearbox-protocol/sdk 12.9.9 → 12.10.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.
Files changed (48) hide show
  1. package/dist/cjs/history/errors.js +2 -0
  2. package/dist/cjs/permissionless/utils/price-update/get-prices.js +0 -3
  3. package/dist/cjs/permissionless/utils/price-update/get-updatable-feeds.js +2 -23
  4. package/dist/cjs/sdk/GearboxSDK.js +5 -25
  5. package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +8 -6
  6. package/dist/cjs/sdk/market/pricefeeds/PythPriceFeed.js +3 -27
  7. package/dist/cjs/sdk/market/pricefeeds/RedstonePriceFeed.js +2 -0
  8. package/dist/cjs/sdk/market/pricefeeds/index.js +0 -2
  9. package/dist/cjs/sdk/market/pricefeeds/updates/RedstoneUpdater.js +3 -202
  10. package/dist/cjs/sdk/market/pricefeeds/updates/fetchRedstonePayloads.js +4 -126
  11. package/dist/cjs/sdk/market/pricefeeds/updates/index.js +0 -7
  12. package/dist/cjs/sdk/options.js +1 -5
  13. package/dist/esm/history/errors.js +2 -0
  14. package/dist/esm/permissionless/utils/price-update/get-prices.js +0 -3
  15. package/dist/esm/permissionless/utils/price-update/get-updatable-feeds.js +2 -27
  16. package/dist/esm/sdk/GearboxSDK.js +5 -25
  17. package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +8 -6
  18. package/dist/esm/sdk/market/pricefeeds/PythPriceFeed.js +4 -28
  19. package/dist/esm/sdk/market/pricefeeds/RedstonePriceFeed.js +2 -0
  20. package/dist/esm/sdk/market/pricefeeds/index.js +0 -2
  21. package/dist/esm/sdk/market/pricefeeds/updates/RedstoneUpdater.js +3 -202
  22. package/dist/esm/sdk/market/pricefeeds/updates/fetchRedstonePayloads.js +4 -130
  23. package/dist/esm/sdk/market/pricefeeds/updates/index.js +0 -4
  24. package/dist/esm/sdk/options.js +2 -9
  25. package/dist/types/permissionless/utils/price-update/get-updatable-feeds.d.ts +4 -3
  26. package/dist/types/sdk/market/pricefeeds/PriceFeedsRegister.d.ts +2 -3
  27. package/dist/types/sdk/market/pricefeeds/PythPriceFeed.d.ts +2 -25
  28. package/dist/types/sdk/market/pricefeeds/index.d.ts +1 -1
  29. package/dist/types/sdk/market/pricefeeds/updates/RedstoneUpdater.d.ts +5 -10
  30. package/dist/types/sdk/market/pricefeeds/updates/fetchRedstonePayloads.d.ts +2 -6
  31. package/dist/types/sdk/market/pricefeeds/updates/index.d.ts +0 -2
  32. package/dist/types/sdk/options.d.ts +0 -6
  33. package/package.json +6 -7
  34. package/dist/cjs/sdk/market/pricefeeds/updates/PriceUpdateTx.js +0 -55
  35. package/dist/cjs/sdk/market/pricefeeds/updates/PriceUpdatesCache.js +0 -78
  36. package/dist/cjs/sdk/market/pricefeeds/updates/PythAccumulatorUpdateData.js +0 -195
  37. package/dist/cjs/sdk/market/pricefeeds/updates/PythUpdater.js +0 -183
  38. package/dist/cjs/sdk/market/pricefeeds/updates/fetchPythPayloads.js +0 -135
  39. package/dist/esm/sdk/market/pricefeeds/updates/PriceUpdateTx.js +0 -31
  40. package/dist/esm/sdk/market/pricefeeds/updates/PriceUpdatesCache.js +0 -54
  41. package/dist/esm/sdk/market/pricefeeds/updates/PythAccumulatorUpdateData.js +0 -157
  42. package/dist/esm/sdk/market/pricefeeds/updates/PythUpdater.js +0 -158
  43. package/dist/esm/sdk/market/pricefeeds/updates/fetchPythPayloads.js +0 -115
  44. package/dist/types/sdk/market/pricefeeds/updates/PriceUpdateTx.d.ts +0 -13
  45. package/dist/types/sdk/market/pricefeeds/updates/PriceUpdatesCache.d.ts +0 -24
  46. package/dist/types/sdk/market/pricefeeds/updates/PythAccumulatorUpdateData.d.ts +0 -41
  47. package/dist/types/sdk/market/pricefeeds/updates/PythUpdater.d.ts +0 -26
  48. package/dist/types/sdk/market/pricefeeds/updates/fetchPythPayloads.d.ts +0 -45
@@ -1,9 +1,7 @@
1
- import type { Address, ContractFunctionParameters, Hex } from "viem";
1
+ import type { Address, Hex } from "viem";
2
2
  import type { ConstructOptions } from "../../base/Construct.js";
3
- import type { RawTx } from "../../types/index.js";
4
3
  import type { PartialPriceFeedTreeNode } from "./AbstractPriceFeed.js";
5
4
  import { AbstractPriceFeedContract } from "./AbstractPriceFeed.js";
6
- import type { IUpdatablePriceFeedContract } from "./types.js";
7
5
  declare const abi: readonly [{
8
6
  readonly type: "constructor";
9
7
  readonly inputs: readonly [{
@@ -217,32 +215,11 @@ declare const abi: readonly [{
217
215
  readonly inputs: readonly [];
218
216
  }];
219
217
  type abi = typeof abi;
220
- declare const iPythAbi: readonly [{
221
- readonly name: "getUpdateFee";
222
- readonly type: "function";
223
- readonly stateMutability: "view";
224
- readonly inputs: readonly [{
225
- readonly type: "bytes[]";
226
- readonly name: "updateData";
227
- }];
228
- readonly outputs: readonly [{
229
- readonly type: "uint256";
230
- readonly name: "feeAmount";
231
- }];
232
- }];
233
- type iPythAbi = typeof iPythAbi;
234
- export declare class PythPriceFeed extends AbstractPriceFeedContract<abi> implements IUpdatablePriceFeedContract {
218
+ export declare class PythPriceFeed extends AbstractPriceFeedContract<abi> {
235
219
  readonly token: Address;
236
220
  readonly priceFeedId: Hex;
237
221
  readonly pyth: Address;
238
222
  readonly maxConfToPriceRatio?: bigint;
239
223
  constructor(options: ConstructOptions, args: PartialPriceFeedTreeNode);
240
- createPriceUpdateTx(data: `0x${string}`): RawTx;
241
- /**
242
- * Returns contract function parameters for the getUpdateFee function on original Pyth contract
243
- * @param calldata
244
- * @returns
245
- */
246
- getUpdateFeeParams(calldata: Hex): ContractFunctionParameters<iPythAbi, "view", "getUpdateFee">;
247
224
  }
248
225
  export {};
@@ -18,7 +18,7 @@ export * from "./PriceFeedsRegister.js";
18
18
  export * from "./PythPriceFeed.js";
19
19
  export * from "./RedstonePriceFeed.js";
20
20
  export * from "./types.js";
21
- export { type FetchPythPayloadsOptions, type FetchRedstonePayloadsOptions, fetchPythPayloads, fetchRedstonePayloads, type TimestampedCalldata, } from "./updates/index.js";
21
+ export { type FetchRedstonePayloadsOptions, fetchRedstonePayloads, type TimestampedCalldata, } from "./updates/index.js";
22
22
  export * from "./WstETHPriceFeed.js";
23
23
  export * from "./YearnPriceFeed.js";
24
24
  export * from "./ZeroPriceFeed.js";
@@ -1,15 +1,13 @@
1
1
  import { z } from "zod/v4";
2
2
  import { SDKConstruct } from "../../../base/index.js";
3
3
  import type { GearboxSDK } from "../../../GearboxSDK.js";
4
+ import type { IPriceUpdateTx } from "../../../types/index.js";
4
5
  import type { IPriceFeedContract } from "../types.js";
5
- import { PriceUpdateTx } from "./PriceUpdateTx.js";
6
6
  import type { IPriceUpdater, IPriceUpdateTask } from "./types.js";
7
7
  interface RedstoneUpdateTask extends IPriceUpdateTask {
8
8
  dataServiceId: string;
9
9
  }
10
- declare class RedstoneUpdateTx extends PriceUpdateTx<RedstoneUpdateTask> {
11
- readonly name = "redstone";
12
- }
10
+ /** @deprecated RedStone options are accepted for compatibility and ignored. */
13
11
  export declare const RedstoneOptions: z.ZodObject<{
14
12
  historicTimestamp: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<true>]>>;
15
13
  gateways: z.ZodOptional<z.ZodArray<z.ZodURL>>;
@@ -18,12 +16,9 @@ export declare const RedstoneOptions: z.ZodObject<{
18
16
  enableLogging: z.ZodOptional<z.ZodBoolean>;
19
17
  }, z.core.$strip>;
20
18
  export type RedstoneOptions = z.infer<typeof RedstoneOptions>;
21
- /**
22
- * Class to update multiple redstone price feeds at once
23
- */
19
+ /** @deprecated RedStone updates are no longer supported. */
24
20
  export declare class RedstoneUpdater extends SDKConstruct implements IPriceUpdater<RedstoneUpdateTask> {
25
- #private;
26
- constructor(sdk: GearboxSDK, opts?: RedstoneOptions);
27
- getUpdateTxs(feeds: IPriceFeedContract[]): Promise<RedstoneUpdateTx[]>;
21
+ constructor(sdk: GearboxSDK, _opts?: RedstoneOptions);
22
+ getUpdateTxs(_feeds: IPriceFeedContract[]): Promise<IPriceUpdateTx<RedstoneUpdateTask>[]>;
28
23
  }
29
24
  export {};
@@ -45,15 +45,11 @@ export interface FetchRedstonePayloadsOptions {
45
45
  */
46
46
  returnPrices?: boolean;
47
47
  }
48
- /**
49
- * Fetches redstone payloads with price data
50
- */
48
+ /** @deprecated RedStone payload fetching is no longer supported. */
51
49
  export declare function fetchRedstonePayloads(options: FetchRedstonePayloadsOptions & {
52
50
  returnPrices: true;
53
51
  }): Promise<TimestampedCalldataWithPrice[]>;
54
- /**
55
- * Fetches redstone payloads
56
- */
52
+ /** @deprecated RedStone payload fetching is no longer supported. */
57
53
  export declare function fetchRedstonePayloads(options: FetchRedstonePayloadsOptions & {
58
54
  returnPrices?: false;
59
55
  }): Promise<TimestampedCalldata[]>;
@@ -1,5 +1,3 @@
1
- export * from "./fetchPythPayloads.js";
2
1
  export * from "./fetchRedstonePayloads.js";
3
- export { PythOptions, PythUpdater } from "./PythUpdater.js";
4
2
  export { RedstoneOptions, RedstoneUpdater } from "./RedstoneUpdater.js";
5
3
  export type * from "./types.js";
@@ -17,12 +17,6 @@ export declare const SDKOptions: z.ZodObject<{
17
17
  ignoreMissingFeeds: z.ZodOptional<z.ZodBoolean>;
18
18
  enableLogging: z.ZodOptional<z.ZodBoolean>;
19
19
  }, z.core.$strip>>;
20
- pyth: z.ZodOptional<z.ZodObject<{
21
- historicTimestamp: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<true>]>>;
22
- apiProxy: z.ZodOptional<z.ZodURL>;
23
- cacheTTL: z.ZodOptional<z.ZodNumber>;
24
- ignoreMissingFeeds: z.ZodOptional<z.ZodBoolean>;
25
- }, z.core.$strip>>;
26
20
  gasLimit: z.ZodOptional<z.ZodNullable<z.ZodBigInt>>;
27
21
  }, z.core.$strip>;
28
22
  export type SDKOptions<Plugins extends PluginsMap> = Omit<z.infer<typeof SDKOptions>, "logger" | "plugins"> & {
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "12.9.9",
3
+ "version": "12.10.1",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/Gearbox-protocol/sdk.git"
9
+ },
6
10
  "main": "./dist/cjs/sdk/index.js",
7
11
  "module": "./dist/esm/sdk/index.js",
8
12
  "types": "./dist/types/sdk/index.d.ts",
@@ -57,14 +61,9 @@
57
61
  },
58
62
  "dependencies": {
59
63
  "@gearbox-protocol/integrations-v3": "1.54.2",
60
- "@redstone-finance/evm-connector": "^0.9.0",
61
- "@redstone-finance/protocol": "^0.9.0",
62
- "@redstone-finance/sdk": "^0.9.0",
63
- "@redstone-finance/utils": "^0.9.0",
64
64
  "@types/bn.js": "^5.2.0",
65
65
  "abitype": "^1.2.3",
66
66
  "bn.js": "^5.2.3",
67
- "buffer": "^6.0.3",
68
67
  "date-fns": "^4.1.0",
69
68
  "decimal.js-light": "^2.5.1",
70
69
  "viem": ">=2.23.15 <3.0.0",
@@ -102,5 +101,5 @@
102
101
  "biome check --no-errors-on-unmatched --write"
103
102
  ]
104
103
  },
105
- "packageManager": "yarn@4.9.2"
104
+ "packageManager": "pnpm@12.3.1"
106
105
  }
@@ -1,55 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var PriceUpdateTx_exports = {};
20
- __export(PriceUpdateTx_exports, {
21
- PriceUpdateTx: () => PriceUpdateTx
22
- });
23
- module.exports = __toCommonJS(PriceUpdateTx_exports);
24
- const MAX_DATA_TIMESTAMP_DELAY_SECONDS = 10n * 60n;
25
- const MAX_DATA_TIMESTAMP_AHEAD_SECONDS = 60n;
26
- class PriceUpdateTx {
27
- /**
28
- * raw tx with encoded `priceFeed.updatePrice` call
29
- */
30
- raw;
31
- data;
32
- constructor(raw, data) {
33
- this.raw = raw;
34
- this.data = data;
35
- }
36
- get pretty() {
37
- const cached = this.data.cached ? " (cached)" : "";
38
- return `${this.name} feed ${this.data.dataFeedId} at ${this.data.priceFeed} with timestamp ${this.data.timestamp}${cached}`;
39
- }
40
- validateTimestamp(blockTimestamp) {
41
- const { timestamp: expectedPayloadTimestamp } = this.data;
42
- if (blockTimestamp < expectedPayloadTimestamp) {
43
- if (BigInt(expectedPayloadTimestamp) - blockTimestamp > MAX_DATA_TIMESTAMP_AHEAD_SECONDS) {
44
- return "in future";
45
- }
46
- } else if (blockTimestamp - BigInt(expectedPayloadTimestamp) > MAX_DATA_TIMESTAMP_DELAY_SECONDS) {
47
- return "too old";
48
- }
49
- return "valid";
50
- }
51
- }
52
- // Annotate the CommonJS export names for ESM import in node:
53
- 0 && (module.exports = {
54
- PriceUpdateTx
55
- });
@@ -1,78 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var PriceUpdatesCache_exports = {};
20
- __export(PriceUpdatesCache_exports, {
21
- PriceUpdatesCache: () => PriceUpdatesCache
22
- });
23
- module.exports = __toCommonJS(PriceUpdatesCache_exports);
24
- class PriceUpdatesCache {
25
- static #caches = /* @__PURE__ */ new Map();
26
- /**
27
- * Price update caches can be shared across networks
28
- * @param id - unique key to identify the cache
29
- * @param opts
30
- * @returns
31
- */
32
- static get(id, opts) {
33
- const key = `${id}:${opts.historical ? "historical" : "latest"}:${opts.ttl}`;
34
- const cache = PriceUpdatesCache.#caches.get(key);
35
- if (cache) {
36
- return cache;
37
- }
38
- const newCache = new PriceUpdatesCache(opts);
39
- PriceUpdatesCache.#caches.set(key, newCache);
40
- return newCache;
41
- }
42
- #cache = /* @__PURE__ */ new Map();
43
- #ttlMs;
44
- #historical;
45
- constructor(opts) {
46
- this.#ttlMs = opts.ttl;
47
- this.#historical = opts.historical;
48
- }
49
- get(...path) {
50
- const key = this.#cacheKey(...path);
51
- const data = this.#cache.get(key);
52
- if (!data) {
53
- return void 0;
54
- }
55
- if (this.#expired(data)) {
56
- this.#cache.delete(key);
57
- return void 0;
58
- }
59
- return data;
60
- }
61
- set(value, ...path) {
62
- const key = this.#cacheKey(...path);
63
- this.#cache.set(key, value);
64
- }
65
- #expired(value) {
66
- if (this.#historical) {
67
- return false;
68
- }
69
- return value.timestamp * 1e3 + this.#ttlMs < Date.now();
70
- }
71
- #cacheKey(...path) {
72
- return path.join(":");
73
- }
74
- }
75
- // Annotate the CommonJS export names for ESM import in node:
76
- 0 && (module.exports = {
77
- PriceUpdatesCache
78
- });
@@ -1,195 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var PythAccumulatorUpdateData_exports = {};
30
- __export(PythAccumulatorUpdateData_exports, {
31
- isAccumulatorUpdateData: () => isAccumulatorUpdateData,
32
- parseAccumulatorUpdateData: () => parseAccumulatorUpdateData,
33
- parsePriceFeedMessage: () => parsePriceFeedMessage,
34
- parseTwapMessage: () => parseTwapMessage,
35
- sliceAccumulatorUpdateData: () => sliceAccumulatorUpdateData
36
- });
37
- module.exports = __toCommonJS(PythAccumulatorUpdateData_exports);
38
- var import_bn = __toESM(require("bn.js"));
39
- var import_buffer = require("buffer");
40
- const ACCUMULATOR_MAGIC = "504e4155";
41
- const MAJOR_VERSION = 1;
42
- const MINOR_VERSION = 0;
43
- const KECCAK160_HASH_SIZE = 20;
44
- const PRICE_FEED_MESSAGE_VARIANT = 0;
45
- const TWAP_MESSAGE_VARIANT = 1;
46
- function isAccumulatorUpdateData(updateBytes) {
47
- return updateBytes.toString("hex").slice(0, 8) === ACCUMULATOR_MAGIC && updateBytes[4] === MAJOR_VERSION && updateBytes[5] === MINOR_VERSION;
48
- }
49
- function parsePriceFeedMessage(message) {
50
- let cursor = 0;
51
- const variant = message.readUInt8(cursor);
52
- if (variant !== PRICE_FEED_MESSAGE_VARIANT) {
53
- throw new Error("Not a price feed message");
54
- }
55
- cursor += 1;
56
- const feedId = message.subarray(cursor, cursor + 32);
57
- cursor += 32;
58
- const price = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
59
- cursor += 8;
60
- const confidence = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
61
- cursor += 8;
62
- const exponent = message.readInt32BE(cursor);
63
- cursor += 4;
64
- const publishTime = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
65
- cursor += 8;
66
- const prevPublishTime = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
67
- cursor += 8;
68
- const emaPrice = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
69
- cursor += 8;
70
- const emaConf = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
71
- cursor += 8;
72
- return {
73
- feedId,
74
- price,
75
- confidence,
76
- exponent,
77
- publishTime,
78
- prevPublishTime,
79
- emaPrice,
80
- emaConf
81
- };
82
- }
83
- function parseTwapMessage(message) {
84
- let cursor = 0;
85
- const variant = message.readUInt8(cursor);
86
- if (variant !== TWAP_MESSAGE_VARIANT) {
87
- throw new Error("Not a twap message");
88
- }
89
- cursor += 1;
90
- const feedId = message.subarray(cursor, cursor + 32);
91
- cursor += 32;
92
- const cumulativePrice = new import_bn.default(message.subarray(cursor, cursor + 16), "be");
93
- cursor += 16;
94
- const cumulativeConf = new import_bn.default(message.subarray(cursor, cursor + 16), "be");
95
- cursor += 16;
96
- const numDownSlots = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
97
- cursor += 8;
98
- const exponent = message.readInt32BE(cursor);
99
- cursor += 4;
100
- const publishTime = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
101
- cursor += 8;
102
- const prevPublishTime = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
103
- cursor += 8;
104
- const publishSlot = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
105
- cursor += 8;
106
- return {
107
- feedId,
108
- cumulativePrice,
109
- cumulativeConf,
110
- numDownSlots,
111
- exponent,
112
- publishTime,
113
- prevPublishTime,
114
- publishSlot
115
- };
116
- }
117
- function sliceAccumulatorUpdateData(data, start, end) {
118
- if (!isAccumulatorUpdateData(data)) {
119
- throw new Error("Invalid accumulator message");
120
- }
121
- let cursor = 6;
122
- const trailingPayloadSize = data.readUint8(cursor);
123
- cursor += 1 + trailingPayloadSize;
124
- cursor += 1;
125
- const vaaSize = data.readUint16BE(cursor);
126
- cursor += 2;
127
- cursor += vaaSize;
128
- const endOfVaa = cursor;
129
- const updates = [];
130
- const numUpdates = data.readUInt8(cursor);
131
- cursor += 1;
132
- for (let i = 0; i < numUpdates; i++) {
133
- const updateStart = cursor;
134
- const messageSize = data.readUint16BE(cursor);
135
- cursor += 2;
136
- cursor += messageSize;
137
- const numProofs = data.readUInt8(cursor);
138
- cursor += 1;
139
- cursor += KECCAK160_HASH_SIZE * numProofs;
140
- updates.push(data.subarray(updateStart, cursor));
141
- }
142
- if (cursor !== data.length) {
143
- throw new Error("Didn't reach the end of the message");
144
- }
145
- const sliceUpdates = updates.slice(start, end);
146
- return import_buffer.Buffer.concat([
147
- data.subarray(0, endOfVaa),
148
- import_buffer.Buffer.from([sliceUpdates.length]),
149
- ...updates.slice(start, end)
150
- ]);
151
- }
152
- function parseAccumulatorUpdateData(data) {
153
- if (!isAccumulatorUpdateData(data)) {
154
- throw new Error("Invalid accumulator message");
155
- }
156
- let cursor = 6;
157
- const trailingPayloadSize = data.readUint8(cursor);
158
- cursor += 1 + trailingPayloadSize;
159
- cursor += 1;
160
- const vaaSize = data.readUint16BE(cursor);
161
- cursor += 2;
162
- const vaa = data.subarray(cursor, cursor + vaaSize);
163
- cursor += vaaSize;
164
- const numUpdates = data.readUInt8(cursor);
165
- const updates = [];
166
- cursor += 1;
167
- for (let i = 0; i < numUpdates; i++) {
168
- const messageSize = data.readUint16BE(cursor);
169
- cursor += 2;
170
- const message = data.subarray(cursor, cursor + messageSize);
171
- cursor += messageSize;
172
- const numProofs = data.readUInt8(cursor);
173
- cursor += 1;
174
- const proof = [];
175
- for (let j = 0; j < numProofs; j++) {
176
- proof.push(
177
- Array.from(data.subarray(cursor, cursor + KECCAK160_HASH_SIZE))
178
- );
179
- cursor += KECCAK160_HASH_SIZE;
180
- }
181
- updates.push({ message, proof });
182
- }
183
- if (cursor !== data.length) {
184
- throw new Error("Didn't reach the end of the message");
185
- }
186
- return { vaa, updates };
187
- }
188
- // Annotate the CommonJS export names for ESM import in node:
189
- 0 && (module.exports = {
190
- isAccumulatorUpdateData,
191
- parseAccumulatorUpdateData,
192
- parsePriceFeedMessage,
193
- parseTwapMessage,
194
- sliceAccumulatorUpdateData
195
- });
@@ -1,183 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var PythUpdater_exports = {};
20
- __export(PythUpdater_exports, {
21
- PythOptions: () => PythOptions,
22
- PythUpdater: () => PythUpdater
23
- });
24
- module.exports = __toCommonJS(PythUpdater_exports);
25
- var import_v4 = require("zod/v4");
26
- var import_base = require("../../../base/index.js");
27
- var import_fetchPythPayloads = require("./fetchPythPayloads.js");
28
- var import_PriceUpdatesCache = require("./PriceUpdatesCache.js");
29
- var import_PriceUpdateTx = require("./PriceUpdateTx.js");
30
- class PythUpdateTx extends import_PriceUpdateTx.PriceUpdateTx {
31
- name = "pyth";
32
- }
33
- const PythOptions = import_v4.z.object({
34
- /**
35
- * Fixed pyth historic timestamp in seconds
36
- * Set to true to enable pyth historical mode using timestamp from attach block
37
- */
38
- historicTimestamp: import_v4.z.union([import_v4.z.number().nonnegative(), import_v4.z.literal(true)]).optional(),
39
- /**
40
- * Override Hermes API with this proxy. Can be used to set caching proxies, to avoid rate limiting
41
- */
42
- apiProxy: import_v4.z.url().optional(),
43
- /**
44
- * TTL for pyth cache in milliseconds
45
- * If 0, disables caching
46
- * If not set, uses some default value
47
- * Cache is always enabled in historical mode
48
- */
49
- cacheTTL: import_v4.z.number().nonnegative().optional(),
50
- /**
51
- * When true, no error will be thrown when pyth is unable to fetch data for some feeds
52
- */
53
- ignoreMissingFeeds: import_v4.z.boolean().optional()
54
- });
55
- class PythUpdater extends import_base.SDKConstruct {
56
- #cache;
57
- #historicalTimestamp;
58
- #apiProxy;
59
- #ignoreMissingFeeds;
60
- constructor(sdk, opts = {}) {
61
- super(sdk);
62
- const { apiProxy, cacheTTL, ignoreMissingFeeds, historicTimestamp } = opts;
63
- this.#ignoreMissingFeeds = ignoreMissingFeeds;
64
- this.#apiProxy = apiProxy;
65
- if (historicTimestamp) {
66
- this.#historicalTimestamp = historicTimestamp === true ? Number(this.sdk.timestamp) : historicTimestamp;
67
- this.logger?.debug(
68
- `using historical timestamp ${this.#historicalTimestamp}`
69
- );
70
- }
71
- this.#cache = import_PriceUpdatesCache.PriceUpdatesCache.get("pyth", {
72
- // currently staleness period is 240 seconds on all networks, add some buffer
73
- // this period of 4 minutes is selected based on time that is required for user to sign transaction with wallet
74
- // so it's unlikely to decrease
75
- ttl: cacheTTL ?? 225 * 1e3,
76
- historical: !!historicTimestamp
77
- });
78
- }
79
- async getUpdateTxs(feeds) {
80
- if (feeds.length === 0) {
81
- return [];
82
- }
83
- this.logger?.debug(
84
- `generating update transactions for ${feeds.length} pyth price feeds`
85
- );
86
- const pythFeeds = new Map(
87
- feeds.filter(isPyth).map((f) => [f.priceFeedId, f])
88
- );
89
- const payloads = await this.#getPayloads(new Set(pythFeeds.keys()));
90
- let [minTimestamp, maxTimestamp] = [Number.POSITIVE_INFINITY, 0];
91
- const results = [];
92
- for (const p of payloads) {
93
- const priceFeed = pythFeeds.get(p.dataFeedId);
94
- if (!priceFeed) {
95
- throw new Error(`cannot find price feed for ${p.dataFeedId}`);
96
- }
97
- const { dataFeedId, timestamp, cached, data } = p;
98
- minTimestamp = Math.min(minTimestamp, timestamp);
99
- maxTimestamp = Math.max(maxTimestamp, timestamp);
100
- results.push(
101
- new PythUpdateTx(priceFeed.createPriceUpdateTx(data), {
102
- dataFeedId,
103
- priceFeed: priceFeed.address,
104
- timestamp,
105
- cached
106
- })
107
- );
108
- }
109
- let tsRange = "";
110
- if (results.length) {
111
- const minDelta = BigInt(minTimestamp) - this.sdk.timestamp;
112
- tsRange = `, timestamps ${minTimestamp} (${minDelta})`;
113
- if (minTimestamp !== maxTimestamp) {
114
- const maxDelta = BigInt(maxTimestamp) - this.sdk.timestamp;
115
- tsRange = `${tsRange} - ${maxTimestamp} (${maxDelta})`;
116
- }
117
- }
118
- this.logger?.debug(
119
- `generated ${results.length} update transactions for pyth price feeds: ${Array.from(pythFeeds.keys()).join(", ")}${tsRange}`
120
- );
121
- return results;
122
- }
123
- /**
124
- * Gets pyth payloads
125
- * @param dataFeedsIds
126
- * @returns
127
- */
128
- async #getPayloads(dataFeedsIds) {
129
- this.logger?.debug(
130
- `getting pyth payloads for ${dataFeedsIds.size} price feeds: ${Array.from(dataFeedsIds).join(", ")}`
131
- );
132
- const fromCache = [];
133
- const uncached = [];
134
- for (const priceFeedsId of dataFeedsIds) {
135
- const cached = this.#cache.get(priceFeedsId);
136
- if (cached) {
137
- fromCache.push({ ...cached, cached: true });
138
- } else {
139
- uncached.push(priceFeedsId);
140
- }
141
- }
142
- const fromPyth = await this.#fetchPayloads(
143
- new Set(uncached)
144
- );
145
- for (const resp of fromPyth) {
146
- this.#cache.set(resp, resp.dataFeedId);
147
- }
148
- this.logger?.debug(
149
- `got ${fromPyth.length} new pyth updates and ${fromCache.length} from cache`
150
- );
151
- return [...fromCache, ...fromPyth];
152
- }
153
- /**
154
- * Fetches pyth payloads from Hermes API
155
- * @param dataFeedsIds
156
- * @returns
157
- */
158
- async #fetchPayloads(dataFeedsIds) {
159
- if (dataFeedsIds.size === 0) {
160
- return [];
161
- }
162
- const ids = Array.from(dataFeedsIds);
163
- const tsStr = this.#historicalTimestamp ? ` with historical timestamp ${this.#historicalTimestamp}` : "";
164
- this.logger?.debug(
165
- `fetching pyth payloads for ${dataFeedsIds.size} price feeds: ${ids.join(", ")}${tsStr}`
166
- );
167
- return (0, import_fetchPythPayloads.fetchPythPayloads)({
168
- dataFeedsIds,
169
- historicalTimestampSeconds: this.#historicalTimestamp,
170
- apiProxy: this.#apiProxy,
171
- ignoreMissingFeeds: this.#ignoreMissingFeeds,
172
- logger: this.logger
173
- });
174
- }
175
- }
176
- function isPyth(pf) {
177
- return pf.contractType === "PRICE_FEED::PYTH";
178
- }
179
- // Annotate the CommonJS export names for ESM import in node:
180
- 0 && (module.exports = {
181
- PythOptions,
182
- PythUpdater
183
- });