@gearbox-protocol/sdk 16.6.0-next.8 → 16.6.0-next.9

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 (115) hide show
  1. package/dist/cjs/onchain/OnchainSDK.js +3 -3
  2. package/dist/cjs/onchain/index.js +49 -38
  3. package/dist/cjs/onchain/market/index.js +49 -38
  4. package/dist/cjs/onchain/market/oracle/PriceOracleBaseContract.js +3 -3
  5. package/dist/cjs/onchain/market/pricefeeds/AbstractPriceFeed.js +0 -5
  6. package/dist/cjs/onchain/market/pricefeeds/PriceFeedRegistry.js +127 -0
  7. package/dist/cjs/onchain/market/pricefeeds/{BalancerStablePriceFeed.js → feeds/BalancerStablePriceFeed.js} +4 -4
  8. package/dist/cjs/onchain/market/pricefeeds/{BalancerWeightedPriceFeed.js → feeds/BalancerWeightedPriceFeed.js} +4 -4
  9. package/dist/cjs/onchain/market/pricefeeds/{BoundedPriceFeed.js → feeds/BoundedPriceFeed.js} +4 -4
  10. package/dist/cjs/onchain/market/pricefeeds/{CompositePriceFeed.js → feeds/CompositePriceFeed.js} +4 -4
  11. package/dist/cjs/onchain/market/pricefeeds/{ConstantPriceFeed.js → feeds/ConstantPriceFeed.js} +3 -3
  12. package/dist/cjs/onchain/market/pricefeeds/{CurveCryptoPriceFeed.js → feeds/CurveCryptoPriceFeed.js} +4 -4
  13. package/dist/cjs/onchain/market/pricefeeds/{CurveStablePriceFeed.js → feeds/CurveStablePriceFeed.js} +4 -4
  14. package/dist/cjs/onchain/market/pricefeeds/{CurveUSDPriceFeed.js → feeds/CurveUSDPriceFeed.js} +4 -4
  15. package/dist/cjs/onchain/market/pricefeeds/{Erc4626PriceFeed.js → feeds/Erc4626PriceFeed.js} +4 -4
  16. package/dist/cjs/onchain/market/pricefeeds/{ExternalPriceFeed.js → feeds/ExternalPriceFeed.js} +4 -4
  17. package/dist/cjs/onchain/market/pricefeeds/{MellowLRTPriceFeed.js → feeds/MellowLRTPriceFeed.js} +4 -4
  18. package/dist/cjs/onchain/market/pricefeeds/{PendleTWAPPTPriceFeed.js → feeds/PendleTWAPPTPriceFeed.js} +4 -4
  19. package/dist/cjs/onchain/market/pricefeeds/{PythPriceFeed.js → feeds/PythPriceFeed.js} +3 -3
  20. package/dist/cjs/onchain/market/pricefeeds/{RedstonePriceFeed.js → feeds/RedstonePriceFeed.js} +6 -6
  21. package/dist/cjs/onchain/market/pricefeeds/{WstETHPriceFeed.js → feeds/WstETHPriceFeed.js} +4 -4
  22. package/dist/cjs/onchain/market/pricefeeds/{YearnPriceFeed.js → feeds/YearnPriceFeed.js} +4 -4
  23. package/dist/cjs/onchain/market/pricefeeds/{ZeroPriceFeed.js → feeds/ZeroPriceFeed.js} +4 -4
  24. package/dist/cjs/onchain/market/pricefeeds/feeds/index.js +35 -0
  25. package/dist/cjs/onchain/market/pricefeeds/index.js +51 -39
  26. package/dist/cjs/onchain/market/pricefeeds/updates/UpdatablePriceFeedRegistry.js +189 -0
  27. package/dist/cjs/onchain/market/pricefeeds/{getRawPriceUpdates.js → updates/getRawPriceUpdates.js} +2 -2
  28. package/dist/cjs/onchain/market/pricefeeds/updates/index.js +8 -0
  29. package/dist/cjs/onchain/market/pricefeeds/{isUpdatablePriceFeed.js → updates/isUpdatablePriceFeed.js} +1 -1
  30. package/dist/cjs/onchain/market/pricefeeds/updates/updatableDependencies.js +14 -0
  31. package/dist/cjs/permissionless/utils/price-update/get-price-update-tx.js +2 -2
  32. package/dist/cjs/permissionless/utils/price-update/get-updatable-feeds.js +2 -2
  33. package/dist/esm/onchain/OnchainSDK.js +3 -3
  34. package/dist/esm/onchain/index.js +25 -20
  35. package/dist/esm/onchain/market/index.js +25 -20
  36. package/dist/esm/onchain/market/oracle/PriceOracleBaseContract.js +1 -1
  37. package/dist/esm/onchain/market/pricefeeds/AbstractPriceFeed.js +0 -5
  38. package/dist/esm/onchain/market/pricefeeds/PriceFeedRegistry.js +126 -0
  39. package/dist/esm/onchain/market/pricefeeds/{BalancerStablePriceFeed.js → feeds/BalancerStablePriceFeed.js} +4 -4
  40. package/dist/esm/onchain/market/pricefeeds/{BalancerWeightedPriceFeed.js → feeds/BalancerWeightedPriceFeed.js} +4 -4
  41. package/dist/esm/onchain/market/pricefeeds/{BoundedPriceFeed.js → feeds/BoundedPriceFeed.js} +4 -4
  42. package/dist/esm/onchain/market/pricefeeds/{CompositePriceFeed.js → feeds/CompositePriceFeed.js} +4 -4
  43. package/dist/esm/onchain/market/pricefeeds/{ConstantPriceFeed.js → feeds/ConstantPriceFeed.js} +3 -3
  44. package/dist/esm/onchain/market/pricefeeds/{CurveCryptoPriceFeed.js → feeds/CurveCryptoPriceFeed.js} +4 -4
  45. package/dist/esm/onchain/market/pricefeeds/{CurveStablePriceFeed.js → feeds/CurveStablePriceFeed.js} +4 -4
  46. package/dist/esm/onchain/market/pricefeeds/{CurveUSDPriceFeed.js → feeds/CurveUSDPriceFeed.js} +4 -4
  47. package/dist/esm/onchain/market/pricefeeds/{Erc4626PriceFeed.js → feeds/Erc4626PriceFeed.js} +4 -4
  48. package/dist/esm/onchain/market/pricefeeds/{ExternalPriceFeed.js → feeds/ExternalPriceFeed.js} +4 -4
  49. package/dist/esm/onchain/market/pricefeeds/{MellowLRTPriceFeed.js → feeds/MellowLRTPriceFeed.js} +4 -4
  50. package/dist/esm/onchain/market/pricefeeds/{PendleTWAPPTPriceFeed.js → feeds/PendleTWAPPTPriceFeed.js} +4 -4
  51. package/dist/esm/onchain/market/pricefeeds/{PythPriceFeed.js → feeds/PythPriceFeed.js} +3 -3
  52. package/dist/esm/onchain/market/pricefeeds/{RedstonePriceFeed.js → feeds/RedstonePriceFeed.js} +6 -6
  53. package/dist/esm/onchain/market/pricefeeds/{WstETHPriceFeed.js → feeds/WstETHPriceFeed.js} +4 -4
  54. package/dist/esm/onchain/market/pricefeeds/{YearnPriceFeed.js → feeds/YearnPriceFeed.js} +4 -4
  55. package/dist/esm/onchain/market/pricefeeds/{ZeroPriceFeed.js → feeds/ZeroPriceFeed.js} +4 -4
  56. package/dist/esm/onchain/market/pricefeeds/feeds/index.js +18 -0
  57. package/dist/esm/onchain/market/pricefeeds/index.js +27 -21
  58. package/dist/esm/onchain/market/pricefeeds/updates/UpdatablePriceFeedRegistry.js +188 -0
  59. package/dist/esm/onchain/market/pricefeeds/{getRawPriceUpdates.js → updates/getRawPriceUpdates.js} +2 -2
  60. package/dist/esm/onchain/market/pricefeeds/updates/index.js +5 -1
  61. package/dist/esm/onchain/market/pricefeeds/{isUpdatablePriceFeed.js → updates/isUpdatablePriceFeed.js} +1 -1
  62. package/dist/esm/onchain/market/pricefeeds/updates/updatableDependencies.js +13 -0
  63. package/dist/esm/permissionless/utils/price-update/get-price-update-tx.js +1 -1
  64. package/dist/esm/permissionless/utils/price-update/get-updatable-feeds.js +1 -1
  65. package/dist/types/onchain/OnchainSDK.d.ts +2 -2
  66. package/dist/types/onchain/index.d.ts +27 -22
  67. package/dist/types/onchain/market/index.d.ts +27 -22
  68. package/dist/types/onchain/market/oracle/PriceOracleBaseContract.d.ts +2 -1
  69. package/dist/types/onchain/market/oracle/types.d.ts +2 -1
  70. package/dist/types/onchain/market/pricefeeds/AbstractPriceFeed.d.ts +1 -2
  71. package/dist/types/onchain/market/pricefeeds/PriceFeedRegistry.d.ts +60 -0
  72. package/dist/types/onchain/market/pricefeeds/feeds/BalancerStablePriceFeed.d.ts +12 -0
  73. package/dist/types/onchain/market/pricefeeds/{BalancerWeightedPriceFeed.d.ts → feeds/BalancerWeightedPriceFeed.d.ts} +7 -7
  74. package/dist/types/onchain/market/pricefeeds/feeds/BoundedPriceFeed.d.ts +15 -0
  75. package/dist/types/onchain/market/pricefeeds/{CompositePriceFeed.d.ts → feeds/CompositePriceFeed.d.ts} +6 -6
  76. package/dist/types/onchain/market/pricefeeds/{ConstantPriceFeed.d.ts → feeds/ConstantPriceFeed.d.ts} +6 -6
  77. package/dist/types/onchain/market/pricefeeds/feeds/CurveCryptoPriceFeed.d.ts +12 -0
  78. package/dist/types/onchain/market/pricefeeds/feeds/CurveStablePriceFeed.d.ts +12 -0
  79. package/dist/types/onchain/market/pricefeeds/feeds/CurveUSDPriceFeed.d.ts +12 -0
  80. package/dist/types/onchain/market/pricefeeds/feeds/Erc4626PriceFeed.d.ts +12 -0
  81. package/dist/types/onchain/market/pricefeeds/feeds/ExternalPriceFeed.d.ts +11 -0
  82. package/dist/types/onchain/market/pricefeeds/feeds/MellowLRTPriceFeed.d.ts +12 -0
  83. package/dist/types/onchain/market/pricefeeds/{PendleTWAPPTPriceFeed.d.ts → feeds/PendleTWAPPTPriceFeed.d.ts} +3 -3
  84. package/dist/types/onchain/market/pricefeeds/{PythPriceFeed.d.ts → feeds/PythPriceFeed.d.ts} +3 -3
  85. package/dist/types/onchain/market/pricefeeds/{RedstonePriceFeed.d.ts → feeds/RedstonePriceFeed.d.ts} +9 -9
  86. package/dist/types/onchain/market/pricefeeds/feeds/WstETHPriceFeed.d.ts +12 -0
  87. package/dist/types/onchain/market/pricefeeds/feeds/YearnPriceFeed.d.ts +12 -0
  88. package/dist/types/onchain/market/pricefeeds/feeds/ZeroPriceFeed.d.ts +11 -0
  89. package/dist/types/onchain/market/pricefeeds/feeds/index.d.ts +18 -0
  90. package/dist/types/onchain/market/pricefeeds/index.d.ts +28 -22
  91. package/dist/types/onchain/market/pricefeeds/types.d.ts +1 -31
  92. package/dist/types/onchain/market/pricefeeds/updates/RedstoneUpdater.d.ts +1 -1
  93. package/dist/types/onchain/market/pricefeeds/updates/UpdatablePriceFeedRegistry.d.ts +106 -0
  94. package/dist/types/onchain/market/pricefeeds/updates/getRawPriceUpdates.d.ts +6 -0
  95. package/dist/types/onchain/market/pricefeeds/updates/index.d.ts +7 -3
  96. package/dist/types/onchain/market/pricefeeds/updates/isUpdatablePriceFeed.d.ts +6 -0
  97. package/dist/types/onchain/market/pricefeeds/updates/types.d.ts +56 -2
  98. package/dist/types/onchain/market/pricefeeds/updates/updatableDependencies.d.ts +10 -0
  99. package/package.json +1 -1
  100. package/dist/cjs/onchain/market/pricefeeds/PriceFeedsRegister.js +0 -301
  101. package/dist/esm/onchain/market/pricefeeds/PriceFeedsRegister.js +0 -300
  102. package/dist/types/onchain/market/pricefeeds/BalancerStablePriceFeed.d.ts +0 -12
  103. package/dist/types/onchain/market/pricefeeds/BoundedPriceFeed.d.ts +0 -15
  104. package/dist/types/onchain/market/pricefeeds/CurveCryptoPriceFeed.d.ts +0 -12
  105. package/dist/types/onchain/market/pricefeeds/CurveStablePriceFeed.d.ts +0 -12
  106. package/dist/types/onchain/market/pricefeeds/CurveUSDPriceFeed.d.ts +0 -12
  107. package/dist/types/onchain/market/pricefeeds/Erc4626PriceFeed.d.ts +0 -12
  108. package/dist/types/onchain/market/pricefeeds/ExternalPriceFeed.d.ts +0 -11
  109. package/dist/types/onchain/market/pricefeeds/MellowLRTPriceFeed.d.ts +0 -12
  110. package/dist/types/onchain/market/pricefeeds/PriceFeedsRegister.d.ts +0 -180
  111. package/dist/types/onchain/market/pricefeeds/WstETHPriceFeed.d.ts +0 -12
  112. package/dist/types/onchain/market/pricefeeds/YearnPriceFeed.d.ts +0 -12
  113. package/dist/types/onchain/market/pricefeeds/ZeroPriceFeed.d.ts +0 -11
  114. package/dist/types/onchain/market/pricefeeds/getRawPriceUpdates.d.ts +0 -5
  115. package/dist/types/onchain/market/pricefeeds/isUpdatablePriceFeed.d.ts +0 -5
@@ -1,7 +1,7 @@
1
1
  import { IPriceFeedContract } from "../types.js";
2
- import { IPriceUpdateTask, IPriceUpdater } from "./types.js";
3
2
  import { PriceUpdatesCache } from "./PriceUpdatesCache.js";
4
3
  import { PriceUpdateTx } from "./PriceUpdateTx.js";
4
+ import { IPriceUpdateTask, IPriceUpdater } from "./types.js";
5
5
  import { OnchainSDK } from "../../../OnchainSDK.js";
6
6
  import { SDKConstruct } from "../../../base/SDKConstruct.js";
7
7
  import "../../../base/index.js";
@@ -0,0 +1,106 @@
1
+ import { IPriceFeedContract, PriceUpdate } from "../types.js";
2
+ import { LatestUpdate, UpdatablePriceFeedRegistryHooks, UpdatablePriceFeedRegistryOptions, UpdatePriceFeedsResult } from "./types.js";
3
+ import { PriceFeedRegistry } from "../PriceFeedRegistry.js";
4
+ import { IHooks } from "../../../utils/internal/Hooks.js";
5
+ import "../../../utils/internal/index.js";
6
+ import { RawTx } from "../../../types/transactions.js";
7
+ import { OnchainSDK } from "../../../OnchainSDK.js";
8
+ import "../../../types/index.js";
9
+ import { Address, BlockTag } from "viem";
10
+ //#region src/onchain/market/pricefeeds/updates/UpdatablePriceFeedRegistry.d.ts
11
+ /**
12
+ * {@link PriceFeedRegistry} that also orchestrates off-chain price updates
13
+ * (Redstone, etc.).
14
+ **/
15
+ declare class UpdatablePriceFeedRegistry extends PriceFeedRegistry implements IHooks<UpdatablePriceFeedRegistryHooks> {
16
+ #private;
17
+ constructor(sdk: OnchainSDK, opts?: UpdatablePriceFeedRegistryOptions);
18
+ /**
19
+ * @internal
20
+ * Registers a callback for price-feed registry lifecycle events.
21
+ * @param event - Event name.
22
+ * @param handler - Callback to invoke.
23
+ **/
24
+ addHook: <K extends "updatesGenerated">(hookName: K, fn: (...args: UpdatablePriceFeedRegistryHooks[K]) => void | Promise<void>) => void;
25
+ /**
26
+ * @internal
27
+ * Removes a previously registered hook.
28
+ * @param event - Event name.
29
+ * @param handler - Callback to remove.
30
+ **/
31
+ removeHook: <K extends "updatesGenerated">(hookName: K, fn: (...args: UpdatablePriceFeedRegistryHooks[K]) => void | Promise<void>) => void;
32
+ /**
33
+ * Generates transactions to push fresh off-chain prices to updatable feeds.
34
+ *
35
+ * @param priceFeeds - Top-level price feeds whose updatable dependencies
36
+ * will be resolved, or a filter (`{ main: true }` / `{ reserve: true }`)
37
+ * to gather feeds from all oracles. When omitted, all registered feeds
38
+ * are used.
39
+ **/
40
+ generatePriceFeedsUpdateTxs(priceFeeds?: IPriceFeedContract[] | {
41
+ main: true;
42
+ } | {
43
+ reserve: true;
44
+ }): Promise<UpdatePriceFeedsResult>;
45
+ /**
46
+ * Similar to {@link generatePriceFeedsUpdateTxs}, but returns raw structures instead of transactions
47
+ * @param priceFeeds
48
+ * @returns
49
+ */
50
+ generatePriceFeedsUpdates(priceFeeds?: IPriceFeedContract[] | {
51
+ main: true;
52
+ } | {
53
+ reserve: true;
54
+ }): Promise<PriceUpdate[]>;
55
+ /**
56
+ * Similar to {@link generatePriceFeedsUpdates}, but returns raw transaction to PriceFeedStore.updatePrices
57
+ * @param priceFeeds
58
+ * @returns
59
+ */
60
+ getPriceFeedStoreUpdateTx(priceFeeds?: IPriceFeedContract[] | {
61
+ main: true;
62
+ } | {
63
+ reserve: true;
64
+ }): Promise<RawTx>;
65
+ /**
66
+ * Similar to {@link generatePriceFeedsUpdateTxs}, but will generate necessary price update transactions for external price feeds (not known to sdk)
67
+ * This does not add feeds to this registry, so they won't be implicitly included in future generatePriceFeedsUpdateTxs calls
68
+ * @param feeds
69
+ * @param block
70
+ * @returns
71
+ */
72
+ generateExternalPriceFeedsUpdateTxs(feeds: Address[], block?: {
73
+ blockNumber: bigint;
74
+ } | {
75
+ blockTag: BlockTag;
76
+ }): Promise<UpdatePriceFeedsResult>;
77
+ /**
78
+ * Similar to {@link generateExternalPriceFeedsUpdateTxs}, but returns raw structures instead of transactions
79
+ * @param feeds
80
+ * @param block
81
+ * @returns
82
+ */
83
+ generateExternalPriceFeedsUpdates(feeds: Address[], block?: {
84
+ blockNumber: bigint;
85
+ } | {
86
+ blockTag: BlockTag;
87
+ }): Promise<PriceUpdate[]>;
88
+ /**
89
+ * Loads PARTIAL information about all updatable price feeds from MarketCompressor
90
+ * Discovered price feeds are not saved anywhere in PriceFeedRegistry, and can later be used to load price feed updates
91
+ */
92
+ getPartialUpdatablePriceFeeds(configurators: Address[]): Promise<IPriceFeedContract[]>;
93
+ /**
94
+ * @internal
95
+ * Diagnostic snapshot of the most recent price-update round, or
96
+ * `undefined` if no updates have been generated yet.
97
+ **/
98
+ get latestUpdate(): LatestUpdate | undefined;
99
+ /**
100
+ * @internal
101
+ * Returns true if any of the updaters are in historical mode
102
+ */
103
+ get historical(): boolean;
104
+ }
105
+ //#endregion
106
+ export { UpdatablePriceFeedRegistry };
@@ -0,0 +1,6 @@
1
+ import { PriceUpdate } from "../types.js";
2
+ import { UpdatePriceFeedsResult } from "./types.js";
3
+ //#region src/onchain/market/pricefeeds/updates/getRawPriceUpdates.d.ts
4
+ declare function getRawPriceUpdates(updates: UpdatePriceFeedsResult): PriceUpdate[];
5
+ //#endregion
6
+ export { getRawPriceUpdates };
@@ -1,5 +1,9 @@
1
- import { IPriceUpdateTask, IPriceUpdater, TimestampedCalldata, TimestampedCalldataWithPrice } from "./types.js";
2
- import { FetchRedstonePayloadsOptions, fetchRedstonePayloads } from "./fetchRedstonePayloads.js";
3
1
  import { PriceUpdatesCache } from "./PriceUpdatesCache.js";
4
2
  import { RedstoneOptions, RedstoneUpdater } from "./RedstoneUpdater.js";
5
- export { FetchRedstonePayloadsOptions, type IPriceUpdateTask, type IPriceUpdater, PriceUpdatesCache, RedstoneOptions, RedstoneUpdater, type TimestampedCalldata, type TimestampedCalldataWithPrice, fetchRedstonePayloads };
3
+ import { IPriceUpdateTask, IPriceUpdater, IUpdatablePriceFeedContract, LatestUpdate, TimestampedCalldata, TimestampedCalldataWithPrice, UpdatablePriceFeedRegistryHooks, UpdatablePriceFeedRegistryOptions, UpdatePriceFeedsResult } from "./types.js";
4
+ import { FetchRedstonePayloadsOptions, fetchRedstonePayloads } from "./fetchRedstonePayloads.js";
5
+ import { getRawPriceUpdates } from "./getRawPriceUpdates.js";
6
+ import { isUpdatablePriceFeed } from "./isUpdatablePriceFeed.js";
7
+ import { UpdatablePriceFeedRegistry } from "./UpdatablePriceFeedRegistry.js";
8
+ import { updatableDependencies } from "./updatableDependencies.js";
9
+ export { FetchRedstonePayloadsOptions, type IPriceUpdateTask, type IPriceUpdater, type IUpdatablePriceFeedContract, type LatestUpdate, PriceUpdatesCache, RedstoneOptions, RedstoneUpdater, type TimestampedCalldata, type TimestampedCalldataWithPrice, UpdatablePriceFeedRegistry, type UpdatablePriceFeedRegistryHooks, type UpdatablePriceFeedRegistryOptions, type UpdatePriceFeedsResult, fetchRedstonePayloads, getRawPriceUpdates, isUpdatablePriceFeed, updatableDependencies };
@@ -0,0 +1,6 @@
1
+ import { IPriceFeedContract } from "../types.js";
2
+ import { IUpdatablePriceFeedContract } from "./types.js";
3
+ //#region src/onchain/market/pricefeeds/updates/isUpdatablePriceFeed.d.ts
4
+ declare function isUpdatablePriceFeed(pf: IPriceFeedContract): pf is IUpdatablePriceFeedContract;
5
+ //#endregion
6
+ export { isUpdatablePriceFeed };
@@ -1,5 +1,6 @@
1
1
  import { IPriceFeedContract } from "../types.js";
2
- import { IPriceUpdateTx } from "../../../types/transactions.js";
2
+ import { RedstoneOptions } from "./RedstoneUpdater.js";
3
+ import { IPriceUpdateTx, RawTx } from "../../../types/transactions.js";
3
4
  import "../../../types/index.js";
4
5
  import { Address } from "viem";
5
6
  //#region src/onchain/market/pricefeeds/updates/types.d.ts
@@ -29,5 +30,58 @@ interface TimestampedCalldataWithPrice extends TimestampedCalldata {
29
30
  price: bigint;
30
31
  decimals: number;
31
32
  }
33
+ /**
34
+ * Extended price feed interface for feeds whose price can be refreshed
35
+ * via an off-chain data push (e.g. Pyth or Redstone feeds).
36
+ **/
37
+ interface IUpdatablePriceFeedContract extends IPriceFeedContract {
38
+ /**
39
+ * Builds a raw transaction that pushes new price data to the on-chain feed.
40
+ * @param data - ABI-encoded update payload.
41
+ **/
42
+ createPriceUpdateTx: (data: `0x${string}`) => RawTx;
43
+ }
44
+ /**
45
+ * Result of generating price-feed update transactions.
46
+ **/
47
+ interface UpdatePriceFeedsResult {
48
+ /**
49
+ * Transactions that push fresh prices to updatable feeds.
50
+ **/
51
+ txs: IPriceUpdateTx[];
52
+ /**
53
+ * Latest timestamp among all fetched price updates (unix seconds).
54
+ **/
55
+ timestamp: number;
56
+ }
57
+ type UpdatablePriceFeedRegistryHooks = {
58
+ /**
59
+ * Emitted when transactions to update price feeds have been generated, but before they're used anywhere
60
+ */
61
+ updatesGenerated: [UpdatePriceFeedsResult];
62
+ };
63
+ /**
64
+ * Configuration for external price-update providers supported by the registry.
65
+ **/
66
+ interface UpdatablePriceFeedRegistryOptions {
67
+ /**
68
+ * Redstone price-update provider options.
69
+ **/
70
+ redstone?: RedstoneOptions;
71
+ }
72
+ /**
73
+ * @internal
74
+ * Diagnostic snapshot of the most recent price-update round.
75
+ **/
76
+ interface LatestUpdate {
77
+ /**
78
+ * Unix timestamp (seconds) of the most recent update.
79
+ **/
80
+ timestamp: number;
81
+ /**
82
+ * Individual update tasks that were executed.
83
+ **/
84
+ updates: IPriceUpdateTask[];
85
+ }
32
86
  //#endregion
33
- export { IPriceUpdateTask, IPriceUpdater, TimestampedCalldata, TimestampedCalldataWithPrice };
87
+ export { IPriceUpdateTask, IPriceUpdater, IUpdatablePriceFeedContract, LatestUpdate, TimestampedCalldata, TimestampedCalldataWithPrice, UpdatablePriceFeedRegistryHooks, UpdatablePriceFeedRegistryOptions, UpdatePriceFeedsResult };
@@ -0,0 +1,10 @@
1
+ import { IPriceFeedContract } from "../types.js";
2
+ import { IUpdatablePriceFeedContract } from "./types.js";
3
+ //#region src/onchain/market/pricefeeds/updates/updatableDependencies.d.ts
4
+ /**
5
+ * Collects updatable feeds in this feed's dependency tree, including this
6
+ * feed itself when it is updatable.
7
+ **/
8
+ declare function updatableDependencies(feed: IPriceFeedContract): IUpdatablePriceFeedContract[];
9
+ //#endregion
10
+ export { updatableDependencies };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "16.6.0-next.8",
3
+ "version": "16.6.0-next.9",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,301 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_onchain_utils_AddressMap = require("../../utils/AddressMap.js");
3
- const require_onchain_utils_bytes32ToString = require("../../utils/bytes32ToString.js");
4
- const require_onchain_utils_createRawTx = require("../../utils/createRawTx.js");
5
- const require_onchain_constants_address_provider = require("../../constants/address-provider.js");
6
- const require_onchain_constants_addresses = require("../../constants/addresses.js");
7
- const require_onchain_constants_versions = require("../../constants/versions.js");
8
- require("../../constants/index.js");
9
- require("../../utils/index.js");
10
- const require_onchain_base_SDKConstruct = require("../../base/SDKConstruct.js");
11
- require("../../base/index.js");
12
- const require_abi_compressors_priceFeedCompressor = require("../../../abi/compressors/priceFeedCompressor.js");
13
- const require_onchain_market_pricefeeds_AbstractPriceFeed = require("./AbstractPriceFeed.js");
14
- const require_onchain_market_pricefeeds_BalancerStablePriceFeed = require("./BalancerStablePriceFeed.js");
15
- const require_onchain_market_pricefeeds_BalancerWeightedPriceFeed = require("./BalancerWeightedPriceFeed.js");
16
- const require_onchain_market_pricefeeds_BoundedPriceFeed = require("./BoundedPriceFeed.js");
17
- const require_onchain_market_pricefeeds_CompositePriceFeed = require("./CompositePriceFeed.js");
18
- const require_onchain_market_pricefeeds_CurveCryptoPriceFeed = require("./CurveCryptoPriceFeed.js");
19
- const require_onchain_market_pricefeeds_CurveStablePriceFeed = require("./CurveStablePriceFeed.js");
20
- const require_onchain_market_pricefeeds_CurveUSDPriceFeed = require("./CurveUSDPriceFeed.js");
21
- const require_onchain_market_pricefeeds_Erc4626PriceFeed = require("./Erc4626PriceFeed.js");
22
- const require_onchain_market_pricefeeds_ExternalPriceFeed = require("./ExternalPriceFeed.js");
23
- const require_onchain_market_pricefeeds_getRawPriceUpdates = require("./getRawPriceUpdates.js");
24
- const require_onchain_market_pricefeeds_MellowLRTPriceFeed = require("./MellowLRTPriceFeed.js");
25
- const require_onchain_market_pricefeeds_PendleTWAPPTPriceFeed = require("./PendleTWAPPTPriceFeed.js");
26
- const require_onchain_utils_internal_Hooks = require("../../utils/internal/Hooks.js");
27
- require("../../utils/internal/index.js");
28
- const require_onchain_market_pricefeeds_ConstantPriceFeed = require("./ConstantPriceFeed.js");
29
- const require_onchain_market_pricefeeds_PythPriceFeed = require("./PythPriceFeed.js");
30
- const require_onchain_market_pricefeeds_RedstonePriceFeed = require("./RedstonePriceFeed.js");
31
- const require_onchain_market_pricefeeds_updates_RedstoneUpdater = require("./updates/RedstoneUpdater.js");
32
- require("./updates/index.js");
33
- const require_onchain_market_pricefeeds_WstETHPriceFeed = require("./WstETHPriceFeed.js");
34
- const require_onchain_market_pricefeeds_YearnPriceFeed = require("./YearnPriceFeed.js");
35
- const require_onchain_market_pricefeeds_ZeroPriceFeed = require("./ZeroPriceFeed.js");
36
- let viem = require("viem");
37
- //#region src/onchain/market/pricefeeds/PriceFeedsRegister.ts
38
- /**
39
- * Chain-level cache of price feed contract instances.
40
- *
41
- * All {@link IPriceOracleContract}s across different markets share a single
42
- * `PriceFeedRegister`, avoiding duplicate contract wrappers for the same
43
- * on-chain feed. The register also orchestrates off-chain price updates
44
- * (Redstone, etc.).
45
- **/
46
- var PriceFeedRegister = class extends require_onchain_base_SDKConstruct.SDKConstruct {
47
- #hooks = new require_onchain_utils_internal_Hooks.Hooks();
48
- #updaters;
49
- #feeds = new require_onchain_utils_AddressMap.AddressMap(void 0, "priceFeeds");
50
- #latestUpdate;
51
- constructor(sdk, opts = {}) {
52
- super(sdk);
53
- this.#updaters = [new require_onchain_market_pricefeeds_updates_RedstoneUpdater.RedstoneUpdater(sdk, opts?.redstone)];
54
- }
55
- /**
56
- * @internal
57
- * Registers a callback for price-feed register lifecycle events.
58
- * @param event - Event name.
59
- * @param handler - Callback to invoke.
60
- **/
61
- addHook = this.#hooks.addHook.bind(this.#hooks);
62
- /**
63
- * @internal
64
- * Removes a previously registered hook.
65
- * @param event - Event name.
66
- * @param handler - Callback to remove.
67
- **/
68
- removeHook = this.#hooks.removeHook.bind(this.#hooks);
69
- /**
70
- * Returns all price feeds known to sdk
71
- */
72
- get feeds() {
73
- return this.#feeds.values();
74
- }
75
- /**
76
- * Generates transactions to push fresh off-chain prices to updatable feeds.
77
- *
78
- * @param priceFeeds - Top-level price feeds whose updatable dependencies
79
- * will be resolved, or a filter (`{ main: true }` / `{ reserve: true }`)
80
- * to gather feeds from all oracles. When omitted, all registered feeds
81
- * are used.
82
- **/
83
- async generatePriceFeedsUpdateTxs(priceFeeds) {
84
- let updateables = this.#feeds.values();
85
- let filterRemark = "";
86
- if (priceFeeds) {
87
- if (Array.isArray(priceFeeds)) updateables = priceFeeds.flatMap((pf) => pf.updatableDependencies());
88
- else if ("main" in priceFeeds && priceFeeds.main) {
89
- filterRemark = " main";
90
- updateables = this.sdk.marketRegister.priceOracles.flatMap((o) => o.mainPriceFeeds.values()).flatMap((pf) => pf.priceFeed.updatableDependencies());
91
- } else if ("reserve" in priceFeeds && priceFeeds.reserve) {
92
- filterRemark = " reserve";
93
- updateables = this.sdk.marketRegister.priceOracles.flatMap((o) => o.reservePriceFeeds.values()).flatMap((pf) => pf.priceFeed.updatableDependencies());
94
- }
95
- }
96
- if (updateables.length === 0) return {
97
- txs: [],
98
- timestamp: 0
99
- };
100
- const txs = [];
101
- const latestUpdate = {
102
- updates: [],
103
- timestamp: Math.floor(Date.now() / 1e3)
104
- };
105
- const updates = (await Promise.all(this.#updaters.map((u) => u.getUpdateTxs(updateables).catch(() => [])))).flat();
106
- let maxTimestamp = 0;
107
- for (const tx of updates) {
108
- const { data } = tx;
109
- const { timestamp } = data;
110
- if (timestamp > maxTimestamp) maxTimestamp = timestamp;
111
- txs.push(tx);
112
- latestUpdate.updates.push(data);
113
- }
114
- txs.sort((a, b) => a.raw.to.toLowerCase().localeCompare(b.raw.to.toLowerCase()));
115
- const result = {
116
- txs,
117
- timestamp: maxTimestamp
118
- };
119
- const tsDelta = BigInt(maxTimestamp) - this.sdk.timestamp;
120
- this.logger?.debug(`generated ${txs.length}${filterRemark} price feed update transactions, timestamp: ${maxTimestamp} (delta ${tsDelta})`);
121
- if (txs.length) await this.#hooks.triggerHooks("updatesGenerated", result);
122
- this.#latestUpdate = latestUpdate;
123
- return result;
124
- }
125
- /**
126
- * Similar to {@link generatePriceFeedsUpdateTxs}, but returns raw structures instead of transactions
127
- * @param priceFeeds
128
- * @returns
129
- */
130
- async generatePriceFeedsUpdates(priceFeeds) {
131
- const updates = await this.generatePriceFeedsUpdateTxs(priceFeeds);
132
- return require_onchain_market_pricefeeds_getRawPriceUpdates.getRawPriceUpdates(updates);
133
- }
134
- /**
135
- * Similar to {@link generatePriceFeedsUpdates}, but returns raw transaction to PriceFeedStore.updatePrices
136
- * @param priceFeeds
137
- * @returns
138
- */
139
- async getPriceFeedStoreUpdateTx(priceFeeds) {
140
- const pfs = this.sdk.addressProvider.getAddress(require_onchain_constants_address_provider.AP_PRICE_FEED_STORE);
141
- const updates = await this.generatePriceFeedsUpdates(priceFeeds);
142
- return require_onchain_utils_createRawTx.createRawTx(pfs, {
143
- abi: (0, viem.parseAbi)(["function updatePrices((address,bytes)[])"]),
144
- functionName: "updatePrices",
145
- args: [updates.map((u) => [u.priceFeed, u.data])]
146
- });
147
- }
148
- /**
149
- * Similar to {@link generatePriceFeedsUpdateTxs}, but will generate necessary price update transactions for external price feeds (not known to sdk)
150
- * This does not add feeds to this register, so they won't be implicitly included in future generatePriceFeedsUpdateTxs calls
151
- * @param feeds
152
- * @param block
153
- * @returns
154
- */
155
- async generateExternalPriceFeedsUpdateTxs(feeds, block) {
156
- const [priceFeedCompressorAddress] = this.sdk.addressProvider.mustGetLatest(require_onchain_constants_address_provider.AP_PRICE_FEED_COMPRESSOR, require_onchain_constants_versions.VERSION_RANGE_310);
157
- const blockParam = block ?? { blockNumber: this.sdk.currentBlock };
158
- const feedContracts = (await this.client.readContract({
159
- address: priceFeedCompressorAddress,
160
- abi: require_abi_compressors_priceFeedCompressor.priceFeedCompressorAbi,
161
- functionName: "loadPriceFeedTree",
162
- args: [feeds],
163
- ...blockParam,
164
- gas: this.sdk.gasLimit
165
- })).map((data) => this.#createUpdatableProxy(data));
166
- return this.generatePriceFeedsUpdateTxs(feedContracts);
167
- }
168
- /**
169
- * Similar to {@link generateExternalPriceFeedsUpdateTxs}, but returns raw structures instead of transactions
170
- * @param feeds
171
- * @param block
172
- * @returns
173
- */
174
- async generateExternalPriceFeedsUpdates(feeds, block) {
175
- const updates = await this.generateExternalPriceFeedsUpdateTxs(feeds, block);
176
- return require_onchain_market_pricefeeds_getRawPriceUpdates.getRawPriceUpdates(updates);
177
- }
178
- /**
179
- * Checks whether a price feed is already registered at the given address.
180
- * @param address - On-chain address to look up.
181
- **/
182
- has(address) {
183
- return this.#feeds.has(address);
184
- }
185
- /**
186
- * Returns the cached price feed contract at the given address.
187
- * @param address - On-chain address to look up.
188
- * @throws If no feed is registered at that address.
189
- **/
190
- mustGet(address) {
191
- return this.#feeds.mustGet(address);
192
- }
193
- /**
194
- * Inserts or updates a price feed from a full tree node.
195
- *
196
- * If a fully loaded feed already exists at the same address, only the
197
- * answer is refreshed. Otherwise a new contract wrapper is created and
198
- * cached.
199
- *
200
- * @param data - Full price feed tree node from the compressor.
201
- * @returns The cached (or newly created) feed instance.
202
- * @throws If the created feed is only partially initialized.
203
- **/
204
- upsert(data) {
205
- const existing = this.#feeds.get(data.baseParams.addr);
206
- if (existing?.loaded) {
207
- existing.updateAnswer(data.answer);
208
- return existing;
209
- }
210
- const feed = this.create(data);
211
- if (!feed.loaded) throw new require_onchain_market_pricefeeds_AbstractPriceFeed.PartialPriceFeedInitError({
212
- ...data,
213
- abi: [],
214
- name: ""
215
- });
216
- this.#feeds.upsert(data.baseParams.addr, feed);
217
- return feed;
218
- }
219
- /**
220
- * Loads PARTIAL information about all updatable price feeds from MarketCompressor
221
- * Discovered price feeds are not saved anywhere in PriceFeedRegister, and can later be used to load price feed updates
222
- */
223
- async getPartialUpdatablePriceFeeds(configurators) {
224
- const [priceFeedCompressorAddress] = this.sdk.addressProvider.mustGetLatest(require_onchain_constants_address_provider.AP_PRICE_FEED_COMPRESSOR, require_onchain_constants_versions.VERSION_RANGE_310);
225
- this.logger?.debug({ configurators }, `calling getUpdatablePriceFeeds in block ${this.sdk.currentBlock}`);
226
- const result = await this.client.readContract({
227
- address: priceFeedCompressorAddress,
228
- abi: require_abi_compressors_priceFeedCompressor.priceFeedCompressorAbi,
229
- functionName: "getUpdatablePriceFeeds",
230
- args: [{
231
- configurators,
232
- pools: [],
233
- underlying: require_onchain_constants_addresses.ADDRESS_0X0
234
- }],
235
- blockNumber: this.sdk.currentBlock,
236
- gas: this.sdk.gasLimit
237
- });
238
- this.logger?.debug(`loaded ${result.length} partial updatable price feeds in block ${this.sdk.currentBlock}`);
239
- return result.map((baseParams) => this.#createUpdatableProxy({ baseParams }));
240
- }
241
- /**
242
- * Instantiates the appropriate price feed contract wrapper based on
243
- * the `contractType` discriminator in the node's base params.
244
- *
245
- * @param data - Partial or full price feed tree node.
246
- * @returns A new (uncached) feed contract instance.
247
- * @throws If the contract type is unsupported and strict mode is enabled.
248
- **/
249
- create(data) {
250
- const contractType = require_onchain_utils_bytes32ToString.bytes32ToString(data.baseParams.contractType);
251
- switch (contractType) {
252
- case "PRICE_FEED::BALANCER_STABLE": return new require_onchain_market_pricefeeds_BalancerStablePriceFeed.BalancerStablePriceFeedContract(this.sdk, data);
253
- case "PRICE_FEED::BALANCER_WEIGHTED": return new require_onchain_market_pricefeeds_BalancerWeightedPriceFeed.BalancerWeightedPriceFeedContract(this.sdk, data);
254
- case "PRICE_FEED::BOUNDED": return new require_onchain_market_pricefeeds_BoundedPriceFeed.BoundedPriceFeedContract(this.sdk, data);
255
- case "PRICE_FEED::COMPOSITE": return new require_onchain_market_pricefeeds_CompositePriceFeed.CompositePriceFeedContract(this.sdk, data);
256
- case "PRICE_FEED::CONSTANT": return new require_onchain_market_pricefeeds_ConstantPriceFeed.ConstantPriceFeedContract(this.sdk, data);
257
- case "PRICE_FEED::CURVE_CRYPTO": return new require_onchain_market_pricefeeds_CurveCryptoPriceFeed.CurveCryptoPriceFeedContract(this.sdk, data);
258
- case "PRICE_FEED::CURVE_STABLE": return new require_onchain_market_pricefeeds_CurveStablePriceFeed.CurveStablePriceFeedContract(this.sdk, data);
259
- case "PRICE_FEED::CURVE_USD": return new require_onchain_market_pricefeeds_CurveUSDPriceFeed.CurveUSDPriceFeedContract(this.sdk, data);
260
- case "PRICE_FEED::ERC4626": return new require_onchain_market_pricefeeds_Erc4626PriceFeed.Erc4626PriceFeedContract(this.sdk, data);
261
- case "PRICE_FEED::EXTERNAL": return new require_onchain_market_pricefeeds_ExternalPriceFeed.ExternalPriceFeedContract(this.sdk, data);
262
- case "PRICE_FEED::MELLOW_LRT": return new require_onchain_market_pricefeeds_MellowLRTPriceFeed.MellowLRTPriceFeedContract(this.sdk, data);
263
- case "PRICE_FEED::PENDLE_PT_TWAP": return new require_onchain_market_pricefeeds_PendleTWAPPTPriceFeed.PendleTWAPPTPriceFeed(this.sdk, data);
264
- case "PRICE_FEED::PYTH": return new require_onchain_market_pricefeeds_PythPriceFeed.PythPriceFeed(this.sdk, data);
265
- case "PRICE_FEED::REDSTONE": return new require_onchain_market_pricefeeds_RedstonePriceFeed.RedstonePriceFeedContract(this.sdk, data);
266
- case "PRICE_FEED::WSTETH": return new require_onchain_market_pricefeeds_WstETHPriceFeed.WstETHPriceFeedContract(this.sdk, data);
267
- case "PRICE_FEED::YEARN": return new require_onchain_market_pricefeeds_YearnPriceFeed.YearnPriceFeedContract(this.sdk, data);
268
- case "PRICE_FEED::ZERO": return new require_onchain_market_pricefeeds_ZeroPriceFeed.ZeroPriceFeedContract(this.sdk, data);
269
- default: {
270
- const err = /* @__PURE__ */ new Error(`Price feed type ${contractType} not supported for price feed at ${data.baseParams.addr}`);
271
- if (this.sdk.strictContractTypes) throw err;
272
- this.logger?.error(err);
273
- return new require_onchain_market_pricefeeds_ExternalPriceFeed.ExternalPriceFeedContract(this.sdk, data);
274
- }
275
- }
276
- }
277
- #createUpdatableProxy(data) {
278
- const contract = this.#feeds.get(data.baseParams.addr) ?? this.create(data);
279
- return new Proxy(contract, { get(target, prop) {
280
- if (prop === "updatableDependencies") return () => [target];
281
- return target[prop];
282
- } });
283
- }
284
- /**
285
- * @internal
286
- * Diagnostic snapshot of the most recent price-update round, or
287
- * `undefined` if no updates have been generated yet.
288
- **/
289
- get latestUpdate() {
290
- return this.#latestUpdate;
291
- }
292
- /**
293
- * @internal
294
- * Returns true if any of the updaters are in historical mode
295
- */
296
- get historical() {
297
- return this.#updaters.some((u) => u.historical);
298
- }
299
- };
300
- //#endregion
301
- exports.PriceFeedRegister = PriceFeedRegister;