@gearbox-protocol/sdk 14.11.20 → 14.11.21

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 (27) hide show
  1. package/dist/cjs/permissionless/bindings/instance-manager.js +1 -1
  2. package/dist/cjs/permissionless/utils/price-update/get-updatable-feeds.js +2 -23
  3. package/dist/cjs/sdk/OnchainSDK.js +0 -15
  4. package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +4 -6
  5. package/dist/cjs/sdk/market/pricefeeds/PythPriceFeed.js +1 -0
  6. package/dist/cjs/sdk/market/pricefeeds/RedstonePriceFeed.js +1 -0
  7. package/dist/cjs/sdk/market/pricefeeds/updates/PythUpdater.js +4 -122
  8. package/dist/cjs/sdk/market/pricefeeds/updates/RedstoneUpdater.js +4 -196
  9. package/dist/cjs/sdk/market/pricefeeds/updates/fetchPythPayloads.js +3 -105
  10. package/dist/cjs/sdk/market/pricefeeds/updates/fetchRedstonePayloads.js +4 -126
  11. package/dist/esm/permissionless/bindings/instance-manager.js +1 -1
  12. package/dist/esm/permissionless/utils/price-update/get-updatable-feeds.js +2 -27
  13. package/dist/esm/sdk/OnchainSDK.js +0 -15
  14. package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +4 -6
  15. package/dist/esm/sdk/market/pricefeeds/PythPriceFeed.js +1 -0
  16. package/dist/esm/sdk/market/pricefeeds/RedstonePriceFeed.js +1 -0
  17. package/dist/esm/sdk/market/pricefeeds/updates/PythUpdater.js +4 -122
  18. package/dist/esm/sdk/market/pricefeeds/updates/RedstoneUpdater.js +4 -196
  19. package/dist/esm/sdk/market/pricefeeds/updates/fetchPythPayloads.js +3 -109
  20. package/dist/esm/sdk/market/pricefeeds/updates/fetchRedstonePayloads.js +4 -130
  21. package/dist/types/permissionless/utils/price-update/get-updatable-feeds.d.ts +4 -3
  22. package/dist/types/sdk/market/pricefeeds/PriceFeedsRegister.d.ts +4 -5
  23. package/dist/types/sdk/market/pricefeeds/updates/PythUpdater.d.ts +5 -7
  24. package/dist/types/sdk/market/pricefeeds/updates/RedstoneUpdater.d.ts +5 -8
  25. package/dist/types/sdk/market/pricefeeds/updates/fetchPythPayloads.d.ts +2 -6
  26. package/dist/types/sdk/market/pricefeeds/updates/fetchRedstonePayloads.d.ts +2 -6
  27. package/package.json +1 -5
@@ -1,114 +1,8 @@
1
- import { Buffer } from "buffer";
2
- import { encodeAbiParameters, toHex } from "viem";
3
- import { retry } from "../../../utils/index.js";
4
- import {
5
- parseAccumulatorUpdateData,
6
- parsePriceFeedMessage,
7
- sliceAccumulatorUpdateData
8
- } from "./PythAccumulatorUpdateData.js";
9
1
  async function fetchPythPayloads(options) {
10
- const {
11
- dataFeedsIds,
12
- failOnMissingFeeds,
13
- historicalTimestampSeconds,
14
- logger,
15
- apiProxy,
16
- customFetch = fetch,
17
- returnPrices
18
- } = options;
19
- const ids = Array.from(new Set(dataFeedsIds)).sort();
20
- if (ids.length === 0) {
21
- return [];
2
+ for (const _feed of options.dataFeedsIds) {
3
+ throw new Error("Pyth price updates are no longer supported by this SDK");
22
4
  }
23
- let api = apiProxy ?? "https://hermes.pyth.network/v2/updates/price/";
24
- api = api.endsWith("/") ? api : `${api}/`;
25
- const url = new URL(api + (historicalTimestampSeconds ?? "latest"));
26
- url.searchParams.append("parsed", returnPrices ? "true" : "false");
27
- if (!failOnMissingFeeds) {
28
- url.searchParams.append("ignore_invalid_price_ids", "true");
29
- }
30
- for (const id of ids) {
31
- url.searchParams.append("ids[]", id);
32
- }
33
- const resp = await retry(
34
- async () => {
35
- const resp2 = await customFetch(url.toString());
36
- if (!resp2.ok) {
37
- const body = await resp2.text();
38
- throw new Error(
39
- `failed to fetch pyth payloads: ${resp2.statusText}: ${body}`
40
- );
41
- }
42
- const data = await resp2.json();
43
- return data;
44
- },
45
- { attempts: 3, exponent: 2, interval: 200 }
46
- );
47
- const result = respToCalldata(resp, returnPrices);
48
- if (result.length !== ids.length) {
49
- if (failOnMissingFeeds) {
50
- throw new Error(
51
- `expected ${ids.length} price feeds, got ${result.length}`
52
- );
53
- } else {
54
- logger?.warn(`expected ${ids.length} price feeds, got ${result.length}`);
55
- }
56
- }
57
- return result;
58
- }
59
- function respToCalldata(resp, returnPrices) {
60
- if (resp.binary.data.length === 0) {
61
- return [];
62
- }
63
- const updates = splitAccumulatorUpdates(resp.binary.data[0]);
64
- const priceMap = /* @__PURE__ */ new Map();
65
- if (returnPrices && resp.parsed) {
66
- for (const feed of resp.parsed) {
67
- const feedId = feed.id.startsWith("0x") ? feed.id : `0x${feed.id}`;
68
- priceMap.set(feedId.toLowerCase(), {
69
- price: BigInt(feed.price.price),
70
- decimals: Math.abs(feed.price.expo)
71
- });
72
- }
73
- }
74
- return updates.map(({ data, dataFeedId, timestamp }) => {
75
- const base = {
76
- dataFeedId,
77
- data: encodeAbiParameters(
78
- [{ type: "uint256" }, { type: "bytes[]" }],
79
- [BigInt(timestamp), [data]]
80
- ),
81
- timestamp,
82
- cached: false
83
- };
84
- if (returnPrices) {
85
- const priceInfo = priceMap.get(dataFeedId.toLowerCase());
86
- if (!priceInfo) {
87
- throw new Error(`Price info not found for feed ${dataFeedId}`);
88
- }
89
- return {
90
- ...base,
91
- price: priceInfo.price,
92
- decimals: priceInfo.decimals
93
- };
94
- }
95
- return base;
96
- });
97
- }
98
- function splitAccumulatorUpdates(binary) {
99
- const data = Buffer.from(binary, "hex");
100
- const parsed = parseAccumulatorUpdateData(data);
101
- const results = [];
102
- for (let i = 0; i < parsed.updates.length; i++) {
103
- const upd = parsed.updates[i].message;
104
- const msg = parsePriceFeedMessage(upd);
105
- results.push({
106
- dataFeedId: toHex(msg.feedId),
107
- timestamp: Number(msg.publishTime),
108
- data: toHex(sliceAccumulatorUpdateData(data, i, i + 1))
109
- });
110
- }
111
- return results;
5
+ return [];
112
6
  }
113
7
  export {
114
8
  fetchPythPayloads
@@ -1,136 +1,10 @@
1
- import { DataServiceWrapper } from "@redstone-finance/evm-connector";
2
- import {
3
- RedstonePayload
4
- } from "@redstone-finance/protocol";
5
- import {
6
- getSignersForDataServiceId
7
- } from "@redstone-finance/sdk";
8
- import { MathUtils } from "@redstone-finance/utils";
9
- import { encodeAbiParameters, toBytes } from "viem";
10
- import { retry } from "../../../utils/index.js";
11
1
  async function fetchRedstonePayloads(options) {
12
- const {
13
- dataServiceId,
14
- dataFeedsIds,
15
- uniqueSignersCount,
16
- historicalTimestampMs,
17
- gateways,
18
- failOnMissingFeeds,
19
- enableLogging,
20
- logger,
21
- returnPrices
22
- } = options;
23
- const metadataTimestampMs = historicalTimestampMs ?? options.metadataTimestampMs;
24
- const dataPackagesIds = Array.from(new Set(dataFeedsIds));
25
- if (dataPackagesIds.length === 0) {
26
- return [];
27
- }
28
- const wrapper = new DataServiceWrapper({
29
- dataServiceId,
30
- dataPackagesIds,
31
- uniqueSignersCount,
32
- authorizedSigners: getSignersForDataServiceId(
33
- dataServiceId
34
- ),
35
- historicalTimestamp: historicalTimestampMs,
36
- urls: gateways,
37
- ignoreMissingFeed: !failOnMissingFeeds,
38
- enableEnhancedLogs: enableLogging
39
- });
40
- if (metadataTimestampMs) {
41
- wrapper.setMetadataTimestamp(metadataTimestampMs);
42
- }
43
- const dataPayload = await retry(() => wrapper.prepareRedstonePayload(true), {
44
- attempts: 5,
45
- interval: historicalTimestampMs ? 30500 : 250
46
- });
47
- const parsed = RedstonePayload.parse(toBytes(`0x${dataPayload}`));
48
- const packagesByDataFeedId = groupDataPackages(parsed.signedDataPackages);
49
- const result = [];
50
- for (const dataFeedId of dataFeedsIds) {
51
- const signedDataPackages = packagesByDataFeedId[dataFeedId];
52
- if (!signedDataPackages) {
53
- if (failOnMissingFeeds) {
54
- throw new Error(`cannot find data packages for ${dataFeedId}`);
55
- }
56
- logger?.warn(`cannot find data packages for ${dataFeedId}`);
57
- continue;
58
- }
59
- if (signedDataPackages.length !== uniqueSignersCount) {
60
- if (failOnMissingFeeds) {
61
- throw new Error(
62
- `got ${signedDataPackages.length} data packages for ${dataFeedId}, but expected ${uniqueSignersCount}`
63
- );
64
- }
65
- logger?.warn(
66
- `got ${signedDataPackages.length} data packages for ${dataFeedId}, but expected ${uniqueSignersCount}`
67
- );
68
- continue;
69
- }
70
- result.push(
71
- getCalldataWithTimestamp(
72
- dataFeedId,
73
- signedDataPackages,
74
- wrapper.getUnsignedMetadata(),
75
- returnPrices
76
- )
2
+ for (const _feed of options.dataFeedsIds) {
3
+ throw new Error(
4
+ "RedStone price updates are no longer supported by this SDK"
77
5
  );
78
6
  }
79
- return result;
80
- }
81
- function groupDataPackages(signedDataPackages) {
82
- const packagesByDataFeedId = {};
83
- for (const p of signedDataPackages) {
84
- const { dataPoints } = p.dataPackage;
85
- const dataFeedId0 = dataPoints[0].dataFeedId;
86
- for (const dp of dataPoints) {
87
- if (dp.dataFeedId !== dataFeedId0) {
88
- throw new Error(
89
- `data package contains data points with different dataFeedIds: ${dp.dataFeedId} and ${dataFeedId0}`
90
- );
91
- }
92
- }
93
- if (!packagesByDataFeedId[dataFeedId0]) {
94
- packagesByDataFeedId[dataFeedId0] = [];
95
- }
96
- packagesByDataFeedId[dataFeedId0].push(p);
97
- }
98
- return packagesByDataFeedId;
99
- }
100
- function getCalldataWithTimestamp(dataFeedId, packages, unsignedMetadata, returnPrices) {
101
- const originalPayload = RedstonePayload.prepare(packages, unsignedMetadata);
102
- const originalPayloadLength = originalPayload.length / 2;
103
- const bytesToAdd = 32 - originalPayloadLength % 32;
104
- const newUnsignedMetadata = unsignedMetadata + "_".repeat(bytesToAdd);
105
- const payload = RedstonePayload.prepare(packages, newUnsignedMetadata);
106
- let timestamp = 0;
107
- for (const p of packages) {
108
- const newTimestamp = p.dataPackage.timestampMilliseconds / 1e3;
109
- if (timestamp === 0) {
110
- timestamp = newTimestamp;
111
- } else if (timestamp !== newTimestamp) {
112
- throw new Error("Timestamps are not equal");
113
- }
114
- }
115
- const base = {
116
- dataFeedId,
117
- data: encodeAbiParameters(
118
- [{ type: "uint256" }, { type: "bytes" }],
119
- [BigInt(timestamp), `0x${payload}`]
120
- ),
121
- timestamp,
122
- cached: false
123
- };
124
- if (returnPrices) {
125
- const prices = packages.flatMap((p) => p.dataPackage.dataPoints).map((dp) => BigInt(`0x${Buffer.from(dp.value).toString("hex")}`));
126
- const medianPrice = BigInt(MathUtils.getMedianOfBigNumbers(prices));
127
- return {
128
- ...base,
129
- price: medianPrice,
130
- decimals: 8
131
- };
132
- }
133
- return base;
7
+ return [];
134
8
  }
135
9
  export {
136
10
  fetchRedstonePayloads
@@ -1,6 +1,7 @@
1
- import { type Address, type PublicClient } from "viem";
2
- import { type IPriceFeedContract, type OnchainSDK } from "../../../sdk/index.js";
3
- export declare function getUpdatablePriceFeeds(args: {
1
+ import type { Address, PublicClient } from "viem";
2
+ import type { IPriceFeedContract, OnchainSDK } from "../../../sdk/index.js";
3
+ /** Pyth and RedStone updates are disabled; retained for compatibility. */
4
+ export declare function getUpdatablePriceFeeds(_args: {
4
5
  sdk: OnchainSDK;
5
6
  client: PublicClient;
6
7
  pfCompressor: Address;
@@ -18,11 +18,11 @@ export type PriceFeedRegisterHooks = {
18
18
  **/
19
19
  export interface PriceFeedRegisterOptions {
20
20
  /**
21
- * Redstone price-update provider options.
21
+ * @deprecated RedStone options are accepted for compatibility and ignored.
22
22
  **/
23
23
  redstone?: RedstoneOptions;
24
24
  /**
25
- * Pyth price-update provider options.
25
+ * @deprecated Pyth options are accepted for compatibility and ignored.
26
26
  **/
27
27
  pyth?: PythOptions;
28
28
  }
@@ -45,12 +45,11 @@ export interface LatestUpdate {
45
45
  *
46
46
  * All {@link IPriceOracleContract}s across different markets share a single
47
47
  * `PriceFeedRegister`, avoiding duplicate contract wrappers for the same
48
- * on-chain feed. The register also orchestrates off-chain price updates
49
- * (Pyth, Redstone, etc.).
48
+ * on-chain feed. Pyth and RedStone off-chain updates are disabled.
50
49
  **/
51
50
  export declare class PriceFeedRegister extends SDKConstruct implements IHooks<PriceFeedRegisterHooks> {
52
51
  #private;
53
- constructor(sdk: OnchainSDK, opts?: PriceFeedRegisterOptions);
52
+ constructor(sdk: OnchainSDK, _opts?: PriceFeedRegisterOptions);
54
53
  /**
55
54
  * @internal
56
55
  * Registers a callback for price-feed register lifecycle events.
@@ -2,13 +2,14 @@ import { z } from "zod/v4";
2
2
  import { SDKConstruct } from "../../../base/index.js";
3
3
  import type { OnchainSDK } from "../../../OnchainSDK.js";
4
4
  import type { IPriceFeedContract } from "../types.js";
5
- import { PriceUpdatesCache } from "./PriceUpdatesCache.js";
5
+ import type { PriceUpdatesCache } from "./PriceUpdatesCache.js";
6
6
  import { PriceUpdateTx } from "./PriceUpdateTx.js";
7
7
  import type { IPriceUpdater, IPriceUpdateTask } from "./types.js";
8
8
  export type PythUpdateTask = IPriceUpdateTask;
9
9
  declare class PythUpdateTx extends PriceUpdateTx<PythUpdateTask> {
10
10
  readonly name = "pyth";
11
11
  }
12
+ /** @deprecated Options are accepted for compatibility and ignored. */
12
13
  export declare const PythOptions: z.ZodObject<{
13
14
  historicTimestamp: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<true>]>>;
14
15
  apiProxy: z.ZodOptional<z.ZodURL>;
@@ -19,13 +20,10 @@ export type PythOptions = z.infer<typeof PythOptions> & {
19
20
  /** Shared cache injected by {@link MultichainSDK} to avoid redundant fetches. */
20
21
  cache?: PriceUpdatesCache;
21
22
  };
22
- /**
23
- * Class to update multiple pyth price feeds at once
24
- */
23
+ /** @deprecated Pyth updates are no longer supported. */
25
24
  export declare class PythUpdater extends SDKConstruct implements IPriceUpdater<PythUpdateTask> {
26
- #private;
27
- constructor(sdk: OnchainSDK, opts?: PythOptions);
28
- getUpdateTxs(feeds: IPriceFeedContract[]): Promise<PythUpdateTx[]>;
25
+ constructor(sdk: OnchainSDK, _opts?: PythOptions);
26
+ getUpdateTxs(_feeds: IPriceFeedContract[]): Promise<PythUpdateTx[]>;
29
27
  get historical(): boolean;
30
28
  }
31
29
  export {};
@@ -2,7 +2,7 @@ import { z } from "zod/v4";
2
2
  import { SDKConstruct } from "../../../base/index.js";
3
3
  import type { OnchainSDK } from "../../../OnchainSDK.js";
4
4
  import type { IPriceFeedContract } from "../types.js";
5
- import { PriceUpdatesCache } from "./PriceUpdatesCache.js";
5
+ import type { PriceUpdatesCache } from "./PriceUpdatesCache.js";
6
6
  import { PriceUpdateTx } from "./PriceUpdateTx.js";
7
7
  import type { IPriceUpdater, IPriceUpdateTask } from "./types.js";
8
8
  interface RedstoneUpdateTask extends IPriceUpdateTask {
@@ -11,6 +11,7 @@ interface RedstoneUpdateTask extends IPriceUpdateTask {
11
11
  declare class RedstoneUpdateTx extends PriceUpdateTx<RedstoneUpdateTask> {
12
12
  readonly name = "redstone";
13
13
  }
14
+ /** @deprecated Options are accepted for compatibility and ignored. */
14
15
  export declare const RedstoneOptions: z.ZodObject<{
15
16
  historicTimestamp: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<true>]>>;
16
17
  gateways: z.ZodOptional<z.ZodArray<z.ZodURL>>;
@@ -19,16 +20,12 @@ export declare const RedstoneOptions: z.ZodObject<{
19
20
  enableLogging: z.ZodOptional<z.ZodBoolean>;
20
21
  }, z.core.$strip>;
21
22
  export type RedstoneOptions = z.infer<typeof RedstoneOptions> & {
22
- /** Shared cache injected by {@link MultichainSDK} to avoid redundant fetches. */
23
23
  cache?: PriceUpdatesCache;
24
24
  };
25
- /**
26
- * Class to update multiple redstone price feeds at once
27
- */
25
+ /** @deprecated Redstone updates are no longer supported. */
28
26
  export declare class RedstoneUpdater extends SDKConstruct implements IPriceUpdater<RedstoneUpdateTask> {
29
- #private;
30
- constructor(sdk: OnchainSDK, opts?: RedstoneOptions);
31
- getUpdateTxs(feeds: IPriceFeedContract[]): Promise<RedstoneUpdateTx[]>;
27
+ constructor(sdk: OnchainSDK, _opts?: RedstoneOptions);
28
+ getUpdateTxs(_feeds: IPriceFeedContract[]): Promise<RedstoneUpdateTx[]>;
32
29
  get historical(): boolean;
33
30
  }
34
31
  export {};
@@ -31,15 +31,11 @@ export interface FetchPythPayloadsOptions {
31
31
  */
32
32
  returnPrices?: boolean;
33
33
  }
34
- /**
35
- * Fetches pyth payloads from Hermes API with price data
36
- */
34
+ /** @deprecated Pyth payload fetching is no longer supported. */
37
35
  export declare function fetchPythPayloads(options: FetchPythPayloadsOptions & {
38
36
  returnPrices: true;
39
37
  }): Promise<TimestampedCalldataWithPrice[]>;
40
- /**
41
- * Fetches pyth payloads from Hermes API
42
- */
38
+ /** @deprecated Pyth payload fetching is no longer supported. */
43
39
  export declare function fetchPythPayloads(options: FetchPythPayloadsOptions & {
44
40
  returnPrices?: false;
45
41
  }): Promise<TimestampedCalldata[]>;
@@ -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[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "14.11.20",
3
+ "version": "14.11.21",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -79,10 +79,6 @@
79
79
  },
80
80
  "dependencies": {
81
81
  "@gearbox-protocol/integrations-v3": "1.54.2",
82
- "@redstone-finance/evm-connector": "^0.9.0",
83
- "@redstone-finance/protocol": "^0.9.0",
84
- "@redstone-finance/sdk": "^0.9.0",
85
- "@redstone-finance/utils": "^0.9.0",
86
82
  "abitype": "^1.2.4",
87
83
  "buffer": "^6.0.3",
88
84
  "date-fns": "^4.4.0",