@gearbox-protocol/sdk 8.0.3 → 8.1.0-next.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 (52) hide show
  1. package/dist/cjs/sdk/GearboxSDK.js +20 -8
  2. package/dist/cjs/sdk/abi/oracles.js +141 -0
  3. package/dist/cjs/sdk/chain/chains.js +2 -2
  4. package/dist/cjs/sdk/market/pricefeeds/AbstractPriceFeed.js +2 -1
  5. package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +17 -23
  6. package/dist/cjs/sdk/market/pricefeeds/PythPriceFeed.js +9 -1
  7. package/dist/cjs/sdk/market/pricefeeds/RedstonePriceFeed.js +9 -7
  8. package/dist/cjs/sdk/market/pricefeeds/index.js +2 -0
  9. package/dist/cjs/sdk/market/pricefeeds/isUpdatablePriceFeed.js +30 -0
  10. package/dist/cjs/sdk/market/pricefeeds/updates/PriceUpdateTx.js +52 -0
  11. package/dist/cjs/sdk/market/pricefeeds/{RedstoneCache.js → updates/PriceUpdatesCache.js} +12 -12
  12. package/dist/cjs/sdk/market/pricefeeds/updates/PythUpdater.js +175 -0
  13. package/dist/cjs/sdk/market/pricefeeds/{RedstoneUpdater.js → updates/RedstoneUpdater.js} +21 -45
  14. package/dist/cjs/sdk/market/pricefeeds/updates/index.js +31 -0
  15. package/dist/cjs/sdk/market/pricefeeds/updates/types.js +16 -0
  16. package/dist/cjs/sdk/utils/retry.js +4 -2
  17. package/dist/esm/sdk/GearboxSDK.js +20 -8
  18. package/dist/esm/sdk/abi/oracles.js +140 -0
  19. package/dist/esm/sdk/chain/chains.js +2 -2
  20. package/dist/esm/sdk/market/pricefeeds/AbstractPriceFeed.js +2 -1
  21. package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +18 -24
  22. package/dist/esm/sdk/market/pricefeeds/PythPriceFeed.js +9 -1
  23. package/dist/esm/sdk/market/pricefeeds/RedstonePriceFeed.js +8 -5
  24. package/dist/esm/sdk/market/pricefeeds/index.js +1 -0
  25. package/dist/esm/sdk/market/pricefeeds/isUpdatablePriceFeed.js +6 -0
  26. package/dist/esm/sdk/market/pricefeeds/updates/PriceUpdateTx.js +28 -0
  27. package/dist/esm/sdk/market/pricefeeds/{RedstoneCache.js → updates/PriceUpdatesCache.js} +8 -8
  28. package/dist/esm/sdk/market/pricefeeds/updates/PythUpdater.js +151 -0
  29. package/dist/esm/sdk/market/pricefeeds/{RedstoneUpdater.js → updates/RedstoneUpdater.js} +21 -44
  30. package/dist/esm/sdk/market/pricefeeds/updates/index.js +6 -0
  31. package/dist/esm/sdk/market/pricefeeds/updates/types.js +0 -0
  32. package/dist/esm/sdk/utils/retry.js +4 -2
  33. package/dist/types/sdk/GearboxSDK.d.ts +5 -1
  34. package/dist/types/sdk/abi/oracles.d.ts +212 -0
  35. package/dist/types/sdk/market/pricefeeds/AbstractPriceFeed.d.ts +2 -2
  36. package/dist/types/sdk/market/pricefeeds/PriceFeedsRegister.d.ts +4 -4
  37. package/dist/types/sdk/market/pricefeeds/PythPriceFeed.d.ts +218 -4
  38. package/dist/types/sdk/market/pricefeeds/RedstonePriceFeed.d.ts +4 -4
  39. package/dist/types/sdk/market/pricefeeds/index.d.ts +1 -0
  40. package/dist/types/sdk/market/pricefeeds/isUpdatablePriceFeed.d.ts +2 -0
  41. package/dist/types/sdk/market/pricefeeds/types.d.ts +5 -2
  42. package/dist/types/sdk/market/pricefeeds/updates/PriceUpdateTx.d.ts +10 -0
  43. package/dist/types/sdk/market/pricefeeds/updates/PriceUpdatesCache.d.ts +17 -0
  44. package/dist/types/sdk/market/pricefeeds/updates/PythUpdater.d.ts +40 -0
  45. package/dist/types/sdk/market/pricefeeds/{RedstoneUpdater.d.ts → updates/RedstoneUpdater.d.ts} +11 -18
  46. package/dist/types/sdk/market/pricefeeds/updates/RedstoneUpdater.test.d.ts +1 -0
  47. package/dist/types/sdk/market/pricefeeds/updates/index.d.ts +3 -0
  48. package/dist/types/sdk/market/pricefeeds/updates/types.d.ts +21 -0
  49. package/dist/types/sdk/sdk-legacy/core/creditAccount.d.ts +2 -2
  50. package/dist/types/sdk/utils/retry.d.ts +1 -0
  51. package/package.json +1 -1
  52. package/dist/types/sdk/market/pricefeeds/RedstoneCache.d.ts +0 -25
@@ -22,8 +22,8 @@ import { ExternalPriceFeedContract } from "./ExternalPriceFeed.js";
22
22
  import { MellowLRTPriceFeedContract } from "./MellowLRTPriceFeed.js";
23
23
  import { PendleTWAPPTPriceFeed } from "./PendleTWAPPTPriceFeed.js";
24
24
  import { PythPriceFeed } from "./PythPriceFeed.js";
25
- import { isRedstone, RedstonePriceFeedContract } from "./RedstonePriceFeed.js";
26
- import { RedstoneUpdater } from "./RedstoneUpdater.js";
25
+ import { RedstonePriceFeedContract } from "./RedstonePriceFeed.js";
26
+ import { PythUpdater, RedstoneUpdater } from "./updates/index.js";
27
27
  import { WstETHPriceFeedContract } from "./WstETHPriceFeed.js";
28
28
  import { YearnPriceFeedContract } from "./YearnPriceFeed.js";
29
29
  import { ZeroPriceFeedContract } from "./ZeroPriceFeed.js";
@@ -32,11 +32,14 @@ class PriceFeedRegister extends SDKConstruct {
32
32
  #hooks = new Hooks();
33
33
  #feeds = new AddressMap(void 0, "priceFeeds");
34
34
  #latestUpdate;
35
- redstoneUpdater;
35
+ updaters;
36
36
  constructor(sdk, opts = {}) {
37
37
  super(sdk);
38
38
  this.logger = childLogger("PriceFeedRegister", sdk.logger);
39
- this.redstoneUpdater = new RedstoneUpdater(sdk, opts?.redstone);
39
+ this.updaters = [
40
+ new RedstoneUpdater(sdk, opts?.redstone),
41
+ new PythUpdater(sdk, opts?.pyth)
42
+ ];
40
43
  }
41
44
  addHook = this.#hooks.addHook.bind(this.#hooks);
42
45
  removeHook = this.#hooks.removeHook.bind(this.#hooks);
@@ -49,31 +52,22 @@ class PriceFeedRegister extends SDKConstruct {
49
52
  async generatePriceFeedsUpdateTxs(priceFeeds, logContext = {}) {
50
53
  const updateables = priceFeeds ? priceFeeds.flatMap((pf) => pf.updatableDependencies()) : this.#feeds.values();
51
54
  const txs = [];
52
- const redstonePFs = [];
53
55
  const latestUpdate = {
54
- redstone: [],
56
+ updates: [],
55
57
  timestamp: Math.floor(Date.now() / 1e3)
56
58
  };
57
- for (const pf of updateables) {
58
- if (isRedstone(pf)) {
59
- redstonePFs.push(pf);
60
- }
61
- }
59
+ const updates = (await Promise.all(
60
+ this.updaters.map((u) => u.getUpdateTxs(updateables, logContext))
61
+ )).flat();
62
62
  let maxTimestamp = 0;
63
- if (redstonePFs.length > 0) {
64
- const redstoneUpdates = await this.redstoneUpdater.getUpdateTxs(
65
- redstonePFs,
66
- logContext
67
- );
68
- for (const tx of redstoneUpdates) {
69
- const { data } = tx;
70
- const { timestamp } = data;
71
- if (timestamp > maxTimestamp) {
72
- maxTimestamp = timestamp;
73
- }
74
- txs.push(tx);
75
- latestUpdate.redstone.push(data);
63
+ for (const tx of updates) {
64
+ const { data } = tx;
65
+ const { timestamp } = data;
66
+ if (timestamp > maxTimestamp) {
67
+ maxTimestamp = timestamp;
76
68
  }
69
+ txs.push(tx);
70
+ latestUpdate.updates.push(data);
77
71
  }
78
72
  const result = { txs, timestamp: maxTimestamp };
79
73
  const tsDelta = BigInt(maxTimestamp) - this.sdk.timestamp;
@@ -1,6 +1,7 @@
1
1
  import { decodeAbiParameters } from "viem";
2
+ import { pythPriceFeedAbi } from "../../abi/oracles.js";
2
3
  import { AbstractPriceFeedContract } from "./AbstractPriceFeed.js";
3
- const abi = [];
4
+ const abi = pythPriceFeedAbi;
4
5
  class PythPriceFeed extends AbstractPriceFeedContract {
5
6
  token;
6
7
  priceFeedId;
@@ -40,6 +41,13 @@ class PythPriceFeed extends AbstractPriceFeedContract {
40
41
  this.pyth = decoded[2];
41
42
  }
42
43
  }
44
+ createPriceUpdateTx(data) {
45
+ return this.createRawTx({
46
+ functionName: "updatePrice",
47
+ args: [data],
48
+ description: `updating pyth price for ${this.priceFeedId} [${this.labelAddress(this.address)}]`
49
+ });
50
+ }
43
51
  }
44
52
  export {
45
53
  PythPriceFeed
@@ -75,11 +75,14 @@ class RedstonePriceFeedContract extends AbstractPriceFeedContract {
75
75
  lastPayloadTimestamp: this.lastPayloadTimestamp.toString()
76
76
  };
77
77
  }
78
- }
79
- function isRedstone(pf) {
80
- return pf.contractType === "PRICE_FEED::REDSTONE";
78
+ createPriceUpdateTx(data) {
79
+ return this.createRawTx({
80
+ functionName: "updatePrice",
81
+ args: [data],
82
+ description: `updating redstone price for ${this.dataId} [${this.labelAddress(this.address)}]`
83
+ });
84
+ }
81
85
  }
82
86
  export {
83
- RedstonePriceFeedContract,
84
- isRedstone
87
+ RedstonePriceFeedContract
85
88
  };
@@ -8,6 +8,7 @@ export * from "./CurveStablePriceFeed.js";
8
8
  export * from "./CurveUSDPriceFeed.js";
9
9
  export * from "./Erc4626PriceFeed.js";
10
10
  export * from "./ExternalPriceFeed.js";
11
+ export * from "./isUpdatablePriceFeed.js";
11
12
  export * from "./MellowLRTPriceFeed.js";
12
13
  export * from "./PendleTWAPPTPriceFeed.js";
13
14
  export * from "./PriceFeedRef.js";
@@ -0,0 +1,6 @@
1
+ function isUpdatablePriceFeed(pf) {
2
+ return pf.updatable;
3
+ }
4
+ export {
5
+ isUpdatablePriceFeed
6
+ };
@@ -0,0 +1,28 @@
1
+ const MAX_DATA_TIMESTAMP_DELAY_SECONDS = 10n * 60n;
2
+ const MAX_DATA_TIMESTAMP_AHEAD_SECONDS = 60n;
3
+ class PriceUpdateTx {
4
+ raw;
5
+ data;
6
+ constructor(raw, data) {
7
+ this.raw = raw;
8
+ this.data = data;
9
+ }
10
+ get pretty() {
11
+ const cached = this.data.cached ? " (cached)" : "";
12
+ return `${this.name} feed ${this.data.dataFeedId} at ${this.data.priceFeed} with timestamp ${this.data.timestamp}${cached}`;
13
+ }
14
+ validateTimestamp(blockTimestamp) {
15
+ const { timestamp: expectedPayloadTimestamp } = this.data;
16
+ if (blockTimestamp < expectedPayloadTimestamp) {
17
+ if (BigInt(expectedPayloadTimestamp) - blockTimestamp > MAX_DATA_TIMESTAMP_AHEAD_SECONDS) {
18
+ return "in future";
19
+ }
20
+ } else if (blockTimestamp - BigInt(expectedPayloadTimestamp) > MAX_DATA_TIMESTAMP_DELAY_SECONDS) {
21
+ return "too old";
22
+ }
23
+ return "valid";
24
+ }
25
+ }
26
+ export {
27
+ PriceUpdateTx
28
+ };
@@ -1,4 +1,4 @@
1
- class RedstoneCache {
1
+ class PriceUpdatesCache {
2
2
  #cache = /* @__PURE__ */ new Map();
3
3
  #ttlMs;
4
4
  #historical;
@@ -6,8 +6,8 @@ class RedstoneCache {
6
6
  this.#ttlMs = opts.ttl;
7
7
  this.#historical = opts.historical;
8
8
  }
9
- get(dataServiceId, dataFeedId, uniqueSignersCount) {
10
- const key = this.#cacheKey(dataServiceId, dataFeedId, uniqueSignersCount);
9
+ get(...path) {
10
+ const key = this.#cacheKey(...path);
11
11
  const data = this.#cache.get(key);
12
12
  if (!data) {
13
13
  return void 0;
@@ -18,8 +18,8 @@ class RedstoneCache {
18
18
  }
19
19
  return data;
20
20
  }
21
- set(dataServiceId, dataFeedId, uniqueSignersCount, value) {
22
- const key = this.#cacheKey(dataServiceId, dataFeedId, uniqueSignersCount);
21
+ set(value, ...path) {
22
+ const key = this.#cacheKey(...path);
23
23
  this.#cache.set(key, value);
24
24
  }
25
25
  #expired(value) {
@@ -28,10 +28,10 @@ class RedstoneCache {
28
28
  }
29
29
  return value.timestamp * 1e3 + this.#ttlMs < Date.now();
30
30
  }
31
- #cacheKey(dataServiceId, dataFeedId, uniqueSignersCount) {
32
- return `${dataServiceId}:${dataFeedId}:${uniqueSignersCount}`;
31
+ #cacheKey(...path) {
32
+ return path.join(":");
33
33
  }
34
34
  }
35
35
  export {
36
- RedstoneCache
36
+ PriceUpdatesCache
37
37
  };
@@ -0,0 +1,151 @@
1
+ import { decodeAbiParameters, encodeAbiParameters } from "viem";
2
+ import { SDKConstruct } from "../../../base/index.js";
3
+ import { childLogger, retry } from "../../../utils/index.js";
4
+ import { PriceUpdatesCache } from "./PriceUpdatesCache.js";
5
+ import { PriceUpdateTx } from "./PriceUpdateTx.js";
6
+ class PythUpdateTx extends PriceUpdateTx {
7
+ name = "pyth";
8
+ }
9
+ class PythUpdater extends SDKConstruct {
10
+ #logger;
11
+ #cache;
12
+ #historicalTimestamp;
13
+ #api;
14
+ #ignoreMissingFeeds;
15
+ constructor(sdk, opts = {}) {
16
+ super(sdk);
17
+ this.#logger = childLogger("PythUpdater", sdk.logger);
18
+ this.#ignoreMissingFeeds = opts.ignoreMissingFeeds;
19
+ this.#api = opts.apiProxy ?? "https://hermes.pyth.network/v2/updates/price/";
20
+ this.#api = this.#api.endsWith("/") ? this.#api : this.#api + "/";
21
+ let ts = opts.historicTimestamp;
22
+ if (ts) {
23
+ this.#historicalTimestamp = ts === true ? Number(this.sdk.timestamp) : ts;
24
+ }
25
+ this.#cache = new PriceUpdatesCache({
26
+ // currently staleness period is 240 seconds on all networks, add some buffer
27
+ // this period of 4 minutes is selected based on time that is required for user to sign transaction with wallet
28
+ // so it's unlikely to decrease
29
+ ttl: opts.cacheTTL ?? 225 * 1e3,
30
+ historical: !!ts
31
+ });
32
+ }
33
+ async getUpdateTxs(feeds, logContext = {}) {
34
+ this.#logger?.debug(
35
+ logContext,
36
+ `generating update transactions for ${feeds.length} pyth price feeds`
37
+ );
38
+ const pythFeeds = new Map(
39
+ feeds.filter(isPyth).map((f) => [f.priceFeedId, f])
40
+ );
41
+ const payloads = await this.#getPayloads(new Set(pythFeeds.keys()));
42
+ const results = payloads.map((p) => {
43
+ const priceFeed = pythFeeds.get(p.dataFeedId);
44
+ if (!priceFeed) {
45
+ throw new Error(`cannot find price feed for ${p.dataFeedId}`);
46
+ }
47
+ const { dataFeedId, timestamp, cached, data } = p;
48
+ return new PythUpdateTx(priceFeed.createPriceUpdateTx(data), {
49
+ dataFeedId,
50
+ priceFeed: priceFeed.address,
51
+ timestamp,
52
+ cached
53
+ });
54
+ });
55
+ this.#logger?.debug(
56
+ logContext,
57
+ `generated ${results.length} update transactions for pyth price feeds`
58
+ );
59
+ return results;
60
+ }
61
+ /**
62
+ * Gets pyth payloads
63
+ * @param dataFeedsIds
64
+ * @returns
65
+ */
66
+ async #getPayloads(dataFeedsIds) {
67
+ this.#logger?.debug(
68
+ `getting pyth payloads for ${dataFeedsIds.size} price feeds: ${Array.from(dataFeedsIds).join(", ")}`
69
+ );
70
+ const fromCache = [];
71
+ const uncached = [];
72
+ for (const priceFeedsId of dataFeedsIds) {
73
+ const cached = this.#cache.get(priceFeedsId);
74
+ if (cached) {
75
+ fromCache.push({ ...cached, cached: true });
76
+ } else {
77
+ uncached.push(priceFeedsId);
78
+ }
79
+ }
80
+ const fromPyth = await this.#fetchPayloads(
81
+ new Set(uncached)
82
+ );
83
+ for (const resp of fromPyth) {
84
+ this.#cache.set(resp, resp.dataFeedId);
85
+ }
86
+ this.#logger?.debug(
87
+ `got ${fromPyth.length} new pyth updates and ${fromCache.length} from cache`
88
+ );
89
+ return [...fromCache, ...fromPyth];
90
+ }
91
+ /**
92
+ * Fetches pyth payloads from Hermes API
93
+ * @param dataFeedsIds
94
+ * @returns
95
+ */
96
+ async #fetchPayloads(dataFeedsIds) {
97
+ if (dataFeedsIds.size === 0) {
98
+ return [];
99
+ }
100
+ const ids = Array.from(dataFeedsIds);
101
+ const tsStr = this.#historicalTimestamp ? ` with historical timestamp ${this.#historicalTimestamp}` : "";
102
+ this.#logger?.debug(
103
+ `fetching pyth payloads for ${dataFeedsIds.size} price feeds: ${ids.join(", ")}${tsStr}`
104
+ );
105
+ const url = new URL(this.#api + (this.#historicalTimestamp ?? "latest"));
106
+ if (this.#ignoreMissingFeeds) {
107
+ url.searchParams.append("ignore_invalid_price_ids", "true");
108
+ }
109
+ for (const id of dataFeedsIds) {
110
+ url.searchParams.append("ids[]", id);
111
+ }
112
+ const resp = await retry(
113
+ async () => {
114
+ const resp2 = await fetch(url.toString());
115
+ if (!resp2.ok) {
116
+ const body = await resp2.text();
117
+ throw new Error(
118
+ `failed to fetch pyth payloads: ${resp2.statusText}: ${body}`
119
+ );
120
+ }
121
+ const data = await resp2.json();
122
+ return data;
123
+ },
124
+ { attempts: 3, exponent: 2, interval: 200 }
125
+ );
126
+ return respToCalldata(resp);
127
+ }
128
+ }
129
+ function isPyth(pf) {
130
+ return pf.contractType === "PRICE_FEED::PYTH";
131
+ }
132
+ function respToCalldata(resp) {
133
+ const [datas] = decodeAbiParameters(
134
+ [{ type: "bytes[]" }],
135
+ `0x${resp.binary.data}`
136
+ );
137
+ return resp.parsed.map((pf, i) => {
138
+ return {
139
+ dataFeedId: pf.id,
140
+ data: encodeAbiParameters(
141
+ [{ type: "uint256" }, { type: "bytes" }],
142
+ [BigInt(pf.price.publish_time), datas[i]]
143
+ ),
144
+ timestamp: pf.price.publish_time,
145
+ cached: false
146
+ };
147
+ });
148
+ }
149
+ export {
150
+ PythUpdater
151
+ };
@@ -1,33 +1,12 @@
1
1
  import { DataServiceWrapper } from "@redstone-finance/evm-connector";
2
2
  import { RedstonePayload } from "@redstone-finance/protocol";
3
3
  import { encodeAbiParameters, toBytes } from "viem";
4
- import { SDKConstruct } from "../../base/index.js";
5
- import { AddressMap, childLogger, retry } from "../../utils/index.js";
6
- import { RedstoneCache } from "./RedstoneCache.js";
7
- const MAX_DATA_TIMESTAMP_DELAY_SECONDS = 10n * 60n;
8
- const MAX_DATA_TIMESTAMP_AHEAD_SECONDS = 60n;
9
- class RedstoneUpdateTx {
10
- raw;
11
- data;
12
- constructor(raw, data) {
13
- this.raw = raw;
14
- this.data = data;
15
- }
16
- get pretty() {
17
- const cached = this.data.cached ? " (cached)" : "";
18
- return `redstone feed ${this.data.dataFeedId} at ${this.data.priceFeed} with timestamp ${this.data.timestamp}${cached}`;
19
- }
20
- validateTimestamp(blockTimestamp) {
21
- const { timestamp: expectedPayloadTimestamp } = this.data;
22
- if (blockTimestamp < expectedPayloadTimestamp) {
23
- if (BigInt(expectedPayloadTimestamp) - blockTimestamp > MAX_DATA_TIMESTAMP_AHEAD_SECONDS) {
24
- return "in future";
25
- }
26
- } else if (blockTimestamp - BigInt(expectedPayloadTimestamp) > MAX_DATA_TIMESTAMP_DELAY_SECONDS) {
27
- return "too old";
28
- }
29
- return "valid";
30
- }
4
+ import { SDKConstruct } from "../../../base/index.js";
5
+ import { AddressMap, childLogger, retry } from "../../../utils/index.js";
6
+ import { PriceUpdatesCache } from "./PriceUpdatesCache.js";
7
+ import { PriceUpdateTx } from "./PriceUpdateTx.js";
8
+ class RedstoneUpdateTx extends PriceUpdateTx {
9
+ name = "redstone";
31
10
  }
32
11
  class RedstoneUpdater extends SDKConstruct {
33
12
  #logger;
@@ -47,7 +26,7 @@ class RedstoneUpdater extends SDKConstruct {
47
26
  ts = ts === true ? Number(this.sdk.timestamp) * 1e3 : ts;
48
27
  this.#historicalTimestampMs = 6e4 * Math.floor(ts / 6e4);
49
28
  }
50
- this.#cache = new RedstoneCache({
29
+ this.#cache = new PriceUpdatesCache({
51
30
  // currently staleness period is 240 seconds on all networks, add some buffer
52
31
  // this period of 4 minutes is selected based on time that is required for user to sign transaction with wallet
53
32
  // so it's unlikely to decrease
@@ -63,6 +42,9 @@ class RedstoneUpdater extends SDKConstruct {
63
42
  const groupedFeeds = {};
64
43
  const priceFeeds = /* @__PURE__ */ new Map();
65
44
  for (const feed of feeds) {
45
+ if (!isRedstone(feed)) {
46
+ continue;
47
+ }
66
48
  const key = `${feed.dataServiceId}:${feed.signersThreshold}`;
67
49
  if (!groupedFeeds[key]) {
68
50
  groupedFeeds[key] = /* @__PURE__ */ new Set();
@@ -88,20 +70,13 @@ class RedstoneUpdater extends SDKConstruct {
88
70
  }
89
71
  for (const priceFeed of pfsForDataId.values()) {
90
72
  results.push(
91
- new RedstoneUpdateTx(
92
- priceFeed.createRawTx({
93
- functionName: "updatePrice",
94
- args: [data],
95
- description: `updating price for ${dataFeedId} [${this.labelAddress(priceFeed.address)}]`
96
- }),
97
- {
98
- dataFeedId,
99
- dataServiceId,
100
- priceFeed: priceFeed.address,
101
- timestamp,
102
- cached
103
- }
104
- )
73
+ new RedstoneUpdateTx(priceFeed.createPriceUpdateTx(data), {
74
+ dataFeedId,
75
+ dataServiceId,
76
+ priceFeed: priceFeed.address,
77
+ timestamp,
78
+ cached
79
+ })
105
80
  );
106
81
  }
107
82
  }
@@ -144,7 +119,7 @@ class RedstoneUpdater extends SDKConstruct {
144
119
  uniqueSignersCount
145
120
  );
146
121
  for (const resp of fromRedstone) {
147
- this.#cache.set(dataServiceId, resp.dataFeedId, uniqueSignersCount, resp);
122
+ this.#cache.set(resp, dataServiceId, resp.dataFeedId, uniqueSignersCount);
148
123
  }
149
124
  this.#logger?.debug(
150
125
  `got ${fromRedstone.length} new redstone updates and ${fromCache.length} from cache`
@@ -245,7 +220,9 @@ function getCalldataWithTimestamp(dataFeedId, packages, unsignedMetadata) {
245
220
  cached: false
246
221
  };
247
222
  }
223
+ function isRedstone(pf) {
224
+ return pf.contractType === "PRICE_FEED::REDSTONE";
225
+ }
248
226
  export {
249
- RedstoneUpdateTx,
250
227
  RedstoneUpdater
251
228
  };
@@ -0,0 +1,6 @@
1
+ import { PythUpdater } from "./PythUpdater.js";
2
+ import { RedstoneUpdater } from "./RedstoneUpdater.js";
3
+ export {
4
+ PythUpdater,
5
+ RedstoneUpdater
6
+ };
@@ -1,5 +1,6 @@
1
1
  async function retry(fn, options = {}) {
2
- const { attempts = 3, interval = 200 } = options;
2
+ const { attempts = 3, interval = 200, exponent = 1 } = options;
3
+ let wait = interval;
3
4
  let cause;
4
5
  for (let i = 0; i < attempts; i++) {
5
6
  try {
@@ -8,8 +9,9 @@ async function retry(fn, options = {}) {
8
9
  } catch (e) {
9
10
  cause = e;
10
11
  await new Promise((resolve) => {
11
- setTimeout(resolve, interval);
12
+ setTimeout(resolve, wait);
12
13
  });
14
+ wait = wait * exponent;
13
15
  }
14
16
  }
15
17
  throw new Error(`all attempts failed: ${cause}`);
@@ -8,7 +8,7 @@ import type { IAddressProviderContract } from "./core/index.js";
8
8
  import { BotListContract, GearStakingContract } from "./core/index.js";
9
9
  import { MarketRegister } from "./market/MarketRegister.js";
10
10
  import { PriceFeedRegister } from "./market/pricefeeds/index.js";
11
- import type { RedstoneOptions } from "./market/pricefeeds/RedstoneUpdater.js";
11
+ import type { PythOptions, RedstoneOptions } from "./market/pricefeeds/updates/index.js";
12
12
  import { type PluginsMap } from "./plugins/index.js";
13
13
  import { type IRouterContract } from "./router/index.js";
14
14
  import type { GearboxState, GearboxStateHuman, ILogger, MultiCall } from "./types/index.js";
@@ -51,6 +51,10 @@ export interface SDKOptions<Plugins extends PluginsMap> {
51
51
  * Options related to redstone price feeds
52
52
  */
53
53
  redstone?: RedstoneOptions;
54
+ /**
55
+ * Options related to pyth price feeds
56
+ */
57
+ pyth?: PythOptions;
54
58
  }
55
59
  export type HydrateOptions<Plugins extends PluginsMap> = Omit<SDKOptions<Plugins>, "blockNumber" | "addressProvider" | "marketConfigurators">;
56
60
  export interface SyncStateOptions {