@gearbox-protocol/sdk 3.0.0-vfour.323 → 3.0.0-vfour.324

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.
@@ -21,7 +21,6 @@ __export(PriceFeedsRegister_exports, {
21
21
  PriceFeedRegister: () => PriceFeedRegister
22
22
  });
23
23
  module.exports = __toCommonJS(PriceFeedsRegister_exports);
24
- var import_viem = require("viem");
25
24
  var import_compressors = require("../../../abi/compressors.js");
26
25
  var import_base = require("../../base/index.js");
27
26
  var import_constants = require("../../constants/index.js");
@@ -49,6 +48,7 @@ class PriceFeedRegister extends import_base.SDKConstruct {
49
48
  logger;
50
49
  #hooks = new import_internal.Hooks();
51
50
  #feeds = new import_utils.AddressMap(void 0, "priceFeeds");
51
+ #latestUpdate;
52
52
  redstoneUpdater;
53
53
  constructor(sdk) {
54
54
  super(sdk);
@@ -114,42 +114,13 @@ class PriceFeedRegister extends import_base.SDKConstruct {
114
114
  this.logger?.debug(`loaded ${result.length} partial updatable price feeds`);
115
115
  return result.map((baseParams) => this.#createUpdatableProxy({ baseParams }));
116
116
  }
117
- /**
118
- * Generates price update transaction via multicall3 without any market data knowledge
119
- *
120
- * @deprecated TODO: seems that it's not used anywhere
121
- *
122
- * @param marketConfigurators
123
- * @param pools
124
- * @returns
125
- */
126
- async getUpdatePriceFeedsTx(marketConfigurators, pools) {
127
- const feeds = await this.getPartialUpdatablePriceFeeds(
128
- marketConfigurators,
129
- pools
130
- );
131
- const updates = await this.#generatePriceFeedsUpdateTxs(feeds);
132
- return (0, import_utils.createRawTx)(
133
- (0, import_viem.getChainContractAddress)({
134
- chain: this.sdk.provider.chain,
135
- contract: "multicall3"
136
- }),
137
- {
138
- abi: import_viem.multicall3Abi,
139
- functionName: "aggregate3",
140
- args: [
141
- updates.txs.map((tx) => ({
142
- target: tx.to,
143
- allowFailure: false,
144
- callData: tx.callData
145
- }))
146
- ]
147
- }
148
- );
149
- }
150
117
  async #generatePriceFeedsUpdateTxs(updateables, logContext = {}) {
151
118
  const txs = [];
152
119
  const redstonePFs = [];
120
+ const latestUpdate = {
121
+ redstone: [],
122
+ timestamp: Date.now()
123
+ };
153
124
  for (const pf of updateables) {
154
125
  if ((0, import_RedstonePriceFeed.isRedstone)(pf)) {
155
126
  redstonePFs.push(pf);
@@ -161,11 +132,12 @@ class PriceFeedRegister extends import_base.SDKConstruct {
161
132
  redstonePFs,
162
133
  logContext
163
134
  );
164
- for (const { tx, timestamp } of redstoneUpdates) {
135
+ for (const { tx, timestamp, ...rest } of redstoneUpdates) {
165
136
  if (timestamp > maxTimestamp) {
166
137
  maxTimestamp = timestamp;
167
138
  }
168
139
  txs.push(tx);
140
+ latestUpdate.redstone.push({ ...rest, timestamp });
169
141
  }
170
142
  }
171
143
  const result = { txs, timestamp: maxTimestamp };
@@ -176,6 +148,7 @@ class PriceFeedRegister extends import_base.SDKConstruct {
176
148
  if (txs.length) {
177
149
  await this.#hooks.triggerHooks("updatesGenerated", result);
178
150
  }
151
+ this.#latestUpdate = latestUpdate;
179
152
  return result;
180
153
  }
181
154
  create(data) {
@@ -237,6 +210,12 @@ class PriceFeedRegister extends import_base.SDKConstruct {
237
210
  }
238
211
  });
239
212
  }
213
+ /**
214
+ * Information update latest update of updatable price feeds, for diagnostic purposes
215
+ */
216
+ get latestUpdate() {
217
+ return this.#latestUpdate;
218
+ }
240
219
  }
241
220
  // Annotate the CommonJS export names for ESM import in node:
242
221
  0 && (module.exports = {
@@ -71,19 +71,22 @@ class RedstoneUpdater extends import_base.SDKConstruct {
71
71
  group,
72
72
  uniqueSignersCount
73
73
  );
74
- for (const { dataFeedId, data, timestamp } of payloads) {
74
+ for (const { dataFeedId, data, timestamp, cached } of payloads) {
75
75
  const priceFeed = priceFeeds.get(dataFeedId);
76
76
  if (!priceFeed) {
77
77
  throw new Error(`cannot get price feed address for ${dataFeedId}`);
78
78
  }
79
79
  results.push({
80
+ dataFeedId,
81
+ dataServiceId,
80
82
  priceFeed: priceFeed.address.toLowerCase(),
81
83
  tx: priceFeed.createRawTx({
82
84
  functionName: "updatePrice",
83
85
  args: [data],
84
86
  description: `updating price for ${dataFeedId} [${this.sdk.provider.addressLabels.get(priceFeed.address)}]`
85
87
  }),
86
- timestamp
88
+ timestamp,
89
+ cached
87
90
  });
88
91
  }
89
92
  }
@@ -116,7 +119,7 @@ class RedstoneUpdater extends import_base.SDKConstruct {
116
119
  );
117
120
  const cached = this.#cache.get(key);
118
121
  if (this.#historicalTimestampMs && !!cached) {
119
- fromCache.push(cached);
122
+ fromCache.push({ ...cached, cached: true });
120
123
  } else {
121
124
  uncached.push(dataFeedId);
122
125
  }
@@ -233,7 +236,8 @@ function getCalldataWithTimestamp(dataFeedId, packages, unsignedMetadata) {
233
236
  [{ type: "uint256" }, { type: "bytes" }],
234
237
  [BigInt(timestamp), `0x${payload}`]
235
238
  ),
236
- timestamp
239
+ timestamp,
240
+ cached: false
237
241
  };
238
242
  }
239
243
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,16 +1,7 @@
1
- import {
2
- getChainContractAddress,
3
- multicall3Abi
4
- } from "viem";
5
1
  import { iMarketCompressorAbi } from "../../../abi/compressors.js";
6
2
  import { SDKConstruct } from "../../base/index.js";
7
3
  import { ADDRESS_0X0, AP_MARKET_COMPRESSOR } from "../../constants/index.js";
8
- import {
9
- AddressMap,
10
- bytes32ToString,
11
- childLogger,
12
- createRawTx
13
- } from "../../utils/index.js";
4
+ import { AddressMap, bytes32ToString, childLogger } from "../../utils/index.js";
14
5
  import { Hooks } from "../../utils/internal/index.js";
15
6
  import {
16
7
  PartialPriceFeedInitError
@@ -36,6 +27,7 @@ class PriceFeedRegister extends SDKConstruct {
36
27
  logger;
37
28
  #hooks = new Hooks();
38
29
  #feeds = new AddressMap(void 0, "priceFeeds");
30
+ #latestUpdate;
39
31
  redstoneUpdater;
40
32
  constructor(sdk) {
41
33
  super(sdk);
@@ -101,42 +93,13 @@ class PriceFeedRegister extends SDKConstruct {
101
93
  this.logger?.debug(`loaded ${result.length} partial updatable price feeds`);
102
94
  return result.map((baseParams) => this.#createUpdatableProxy({ baseParams }));
103
95
  }
104
- /**
105
- * Generates price update transaction via multicall3 without any market data knowledge
106
- *
107
- * @deprecated TODO: seems that it's not used anywhere
108
- *
109
- * @param marketConfigurators
110
- * @param pools
111
- * @returns
112
- */
113
- async getUpdatePriceFeedsTx(marketConfigurators, pools) {
114
- const feeds = await this.getPartialUpdatablePriceFeeds(
115
- marketConfigurators,
116
- pools
117
- );
118
- const updates = await this.#generatePriceFeedsUpdateTxs(feeds);
119
- return createRawTx(
120
- getChainContractAddress({
121
- chain: this.sdk.provider.chain,
122
- contract: "multicall3"
123
- }),
124
- {
125
- abi: multicall3Abi,
126
- functionName: "aggregate3",
127
- args: [
128
- updates.txs.map((tx) => ({
129
- target: tx.to,
130
- allowFailure: false,
131
- callData: tx.callData
132
- }))
133
- ]
134
- }
135
- );
136
- }
137
96
  async #generatePriceFeedsUpdateTxs(updateables, logContext = {}) {
138
97
  const txs = [];
139
98
  const redstonePFs = [];
99
+ const latestUpdate = {
100
+ redstone: [],
101
+ timestamp: Date.now()
102
+ };
140
103
  for (const pf of updateables) {
141
104
  if (isRedstone(pf)) {
142
105
  redstonePFs.push(pf);
@@ -148,11 +111,12 @@ class PriceFeedRegister extends SDKConstruct {
148
111
  redstonePFs,
149
112
  logContext
150
113
  );
151
- for (const { tx, timestamp } of redstoneUpdates) {
114
+ for (const { tx, timestamp, ...rest } of redstoneUpdates) {
152
115
  if (timestamp > maxTimestamp) {
153
116
  maxTimestamp = timestamp;
154
117
  }
155
118
  txs.push(tx);
119
+ latestUpdate.redstone.push({ ...rest, timestamp });
156
120
  }
157
121
  }
158
122
  const result = { txs, timestamp: maxTimestamp };
@@ -163,6 +127,7 @@ class PriceFeedRegister extends SDKConstruct {
163
127
  if (txs.length) {
164
128
  await this.#hooks.triggerHooks("updatesGenerated", result);
165
129
  }
130
+ this.#latestUpdate = latestUpdate;
166
131
  return result;
167
132
  }
168
133
  create(data) {
@@ -224,6 +189,12 @@ class PriceFeedRegister extends SDKConstruct {
224
189
  }
225
190
  });
226
191
  }
192
+ /**
193
+ * Information update latest update of updatable price feeds, for diagnostic purposes
194
+ */
195
+ get latestUpdate() {
196
+ return this.#latestUpdate;
197
+ }
227
198
  }
228
199
  export {
229
200
  PriceFeedRegister
@@ -48,19 +48,22 @@ class RedstoneUpdater extends SDKConstruct {
48
48
  group,
49
49
  uniqueSignersCount
50
50
  );
51
- for (const { dataFeedId, data, timestamp } of payloads) {
51
+ for (const { dataFeedId, data, timestamp, cached } of payloads) {
52
52
  const priceFeed = priceFeeds.get(dataFeedId);
53
53
  if (!priceFeed) {
54
54
  throw new Error(`cannot get price feed address for ${dataFeedId}`);
55
55
  }
56
56
  results.push({
57
+ dataFeedId,
58
+ dataServiceId,
57
59
  priceFeed: priceFeed.address.toLowerCase(),
58
60
  tx: priceFeed.createRawTx({
59
61
  functionName: "updatePrice",
60
62
  args: [data],
61
63
  description: `updating price for ${dataFeedId} [${this.sdk.provider.addressLabels.get(priceFeed.address)}]`
62
64
  }),
63
- timestamp
65
+ timestamp,
66
+ cached
64
67
  });
65
68
  }
66
69
  }
@@ -93,7 +96,7 @@ class RedstoneUpdater extends SDKConstruct {
93
96
  );
94
97
  const cached = this.#cache.get(key);
95
98
  if (this.#historicalTimestampMs && !!cached) {
96
- fromCache.push(cached);
99
+ fromCache.push({ ...cached, cached: true });
97
100
  } else {
98
101
  uncached.push(dataFeedId);
99
102
  }
@@ -210,7 +213,8 @@ function getCalldataWithTimestamp(dataFeedId, packages, unsignedMetadata) {
210
213
  [{ type: "uint256" }, { type: "bytes" }],
211
214
  [BigInt(timestamp), `0x${payload}`]
212
215
  ),
213
- timestamp
216
+ timestamp,
217
+ cached: false
214
218
  };
215
219
  }
216
220
  export {
@@ -1,10 +1,11 @@
1
- import { type Address } from "viem";
1
+ import type { Address } from "viem";
2
2
  import type { PriceFeedTreeNode } from "../../base/index.js";
3
3
  import { SDKConstruct } from "../../base/index.js";
4
4
  import type { GearboxSDK } from "../../GearboxSDK.js";
5
- import type { ILogger, RawTx } from "../../types/index.js";
5
+ import type { ILogger } from "../../types/index.js";
6
6
  import type { IHooks } from "../../utils/internal/index.js";
7
7
  import { type PartialPriceFeedTreeNode } from "./AbstractPriceFeed.js";
8
+ import type { RedstoneUpdateTask } from "./RedstoneUpdater.js";
8
9
  import { RedstoneUpdater } from "./RedstoneUpdater.js";
9
10
  import type { IPriceFeedContract, UpdatePriceFeedsResult } from "./types.js";
10
11
  export type PriceFeedRegisterHooks = {
@@ -13,6 +14,10 @@ export type PriceFeedRegisterHooks = {
13
14
  */
14
15
  updatesGenerated: [UpdatePriceFeedsResult];
15
16
  };
17
+ export interface LatestUpdate {
18
+ timestamp: number;
19
+ redstone: Omit<RedstoneUpdateTask, "tx">[];
20
+ }
16
21
  /**
17
22
  * PriceFeedRegister acts as a chain-level cache to avoid creating multiple contract instances.
18
23
  * It's reused by PriceOracles belonging to different markets
@@ -40,15 +45,9 @@ export declare class PriceFeedRegister extends SDKConstruct implements IHooks<Pr
40
45
  * This is not saved anywhere in PriceFeedRegister, and can later be used to load price feed updates
41
46
  */
42
47
  getPartialUpdatablePriceFeeds(marketConfigurators?: Address[], pools?: Address[]): Promise<IPriceFeedContract[]>;
48
+ create(data: PartialPriceFeedTreeNode): IPriceFeedContract;
43
49
  /**
44
- * Generates price update transaction via multicall3 without any market data knowledge
45
- *
46
- * @deprecated TODO: seems that it's not used anywhere
47
- *
48
- * @param marketConfigurators
49
- * @param pools
50
- * @returns
50
+ * Information update latest update of updatable price feeds, for diagnostic purposes
51
51
  */
52
- getUpdatePriceFeedsTx(marketConfigurators?: Address[], pools?: Address[]): Promise<RawTx>;
53
- create(data: PartialPriceFeedTreeNode): IPriceFeedContract;
52
+ get latestUpdate(): LatestUpdate | undefined;
54
53
  }
@@ -3,10 +3,13 @@ import { SDKConstruct } from "../../base/index.js";
3
3
  import type { GearboxSDK } from "../../GearboxSDK.js";
4
4
  import type { RawTx } from "../../types/index.js";
5
5
  import type { RedstonePriceFeedContract } from "./RedstonePriceFeed.js";
6
- interface UpdatePFTask {
6
+ export interface RedstoneUpdateTask {
7
+ dataFeedId: string;
8
+ dataServiceId: string;
7
9
  priceFeed: Address;
8
10
  tx: RawTx;
9
11
  timestamp: number;
12
+ cached: boolean;
10
13
  }
11
14
  /**
12
15
  * Class to update multiple redstone price feeds at once
@@ -22,6 +25,5 @@ export declare class RedstoneUpdater extends SDKConstruct {
22
25
  * Set redstone gateways
23
26
  */
24
27
  set gateways(gateways: string[]);
25
- getUpdateTxs(feeds: RedstonePriceFeedContract[], logContext?: Record<string, any>): Promise<UpdatePFTask[]>;
28
+ getUpdateTxs(feeds: RedstonePriceFeedContract[], logContext?: Record<string, any>): Promise<RedstoneUpdateTask[]>;
26
29
  }
27
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "3.0.0-vfour.323",
3
+ "version": "3.0.0-vfour.324",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",