@gearbox-protocol/sdk 16.6.0 → 16.6.2

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 (118) hide show
  1. package/dist/cjs/dev/midasUtils.js +8 -5
  2. package/dist/cjs/onchain/OnchainSDK.js +3 -3
  3. package/dist/cjs/onchain/index.js +49 -38
  4. package/dist/cjs/onchain/market/index.js +49 -38
  5. package/dist/cjs/onchain/market/oracle/PriceOracleBaseContract.js +3 -3
  6. package/dist/cjs/onchain/market/pricefeeds/AbstractPriceFeed.js +0 -5
  7. package/dist/cjs/onchain/market/pricefeeds/PriceFeedRegistry.js +127 -0
  8. package/dist/cjs/onchain/market/pricefeeds/{BalancerStablePriceFeed.js → feeds/BalancerStablePriceFeed.js} +4 -4
  9. package/dist/cjs/onchain/market/pricefeeds/{BalancerWeightedPriceFeed.js → feeds/BalancerWeightedPriceFeed.js} +4 -4
  10. package/dist/cjs/onchain/market/pricefeeds/{BoundedPriceFeed.js → feeds/BoundedPriceFeed.js} +4 -4
  11. package/dist/cjs/onchain/market/pricefeeds/{CompositePriceFeed.js → feeds/CompositePriceFeed.js} +4 -4
  12. package/dist/cjs/onchain/market/pricefeeds/{ConstantPriceFeed.js → feeds/ConstantPriceFeed.js} +3 -3
  13. package/dist/cjs/onchain/market/pricefeeds/{CurveCryptoPriceFeed.js → feeds/CurveCryptoPriceFeed.js} +4 -4
  14. package/dist/cjs/onchain/market/pricefeeds/{CurveStablePriceFeed.js → feeds/CurveStablePriceFeed.js} +4 -4
  15. package/dist/cjs/onchain/market/pricefeeds/{CurveUSDPriceFeed.js → feeds/CurveUSDPriceFeed.js} +4 -4
  16. package/dist/cjs/onchain/market/pricefeeds/{Erc4626PriceFeed.js → feeds/Erc4626PriceFeed.js} +4 -4
  17. package/dist/cjs/onchain/market/pricefeeds/{ExternalPriceFeed.js → feeds/ExternalPriceFeed.js} +4 -4
  18. package/dist/cjs/onchain/market/pricefeeds/{MellowLRTPriceFeed.js → feeds/MellowLRTPriceFeed.js} +4 -4
  19. package/dist/cjs/onchain/market/pricefeeds/{PendleTWAPPTPriceFeed.js → feeds/PendleTWAPPTPriceFeed.js} +4 -4
  20. package/dist/cjs/onchain/market/pricefeeds/{PythPriceFeed.js → feeds/PythPriceFeed.js} +3 -3
  21. package/dist/cjs/onchain/market/pricefeeds/{RedstonePriceFeed.js → feeds/RedstonePriceFeed.js} +6 -6
  22. package/dist/cjs/onchain/market/pricefeeds/{WstETHPriceFeed.js → feeds/WstETHPriceFeed.js} +4 -4
  23. package/dist/cjs/onchain/market/pricefeeds/{YearnPriceFeed.js → feeds/YearnPriceFeed.js} +4 -4
  24. package/dist/cjs/onchain/market/pricefeeds/{ZeroPriceFeed.js → feeds/ZeroPriceFeed.js} +4 -4
  25. package/dist/cjs/onchain/market/pricefeeds/feeds/index.js +35 -0
  26. package/dist/cjs/onchain/market/pricefeeds/index.js +51 -39
  27. package/dist/cjs/onchain/market/pricefeeds/updates/UpdatablePriceFeedRegistry.js +189 -0
  28. package/dist/cjs/onchain/market/pricefeeds/{getRawPriceUpdates.js → updates/getRawPriceUpdates.js} +2 -2
  29. package/dist/cjs/onchain/market/pricefeeds/updates/index.js +8 -0
  30. package/dist/cjs/onchain/market/pricefeeds/{isUpdatablePriceFeed.js → updates/isUpdatablePriceFeed.js} +1 -1
  31. package/dist/cjs/onchain/market/pricefeeds/updates/updatableDependencies.js +14 -0
  32. package/dist/cjs/permissionless/utils/price-update/get-price-update-tx.js +2 -2
  33. package/dist/cjs/permissionless/utils/price-update/get-updatable-feeds.js +2 -2
  34. package/dist/esm/dev/midasUtils.js +8 -5
  35. package/dist/esm/onchain/OnchainSDK.js +3 -3
  36. package/dist/esm/onchain/index.js +25 -20
  37. package/dist/esm/onchain/market/index.js +25 -20
  38. package/dist/esm/onchain/market/oracle/PriceOracleBaseContract.js +1 -1
  39. package/dist/esm/onchain/market/pricefeeds/AbstractPriceFeed.js +0 -5
  40. package/dist/esm/onchain/market/pricefeeds/PriceFeedRegistry.js +126 -0
  41. package/dist/esm/onchain/market/pricefeeds/{BalancerStablePriceFeed.js → feeds/BalancerStablePriceFeed.js} +4 -4
  42. package/dist/esm/onchain/market/pricefeeds/{BalancerWeightedPriceFeed.js → feeds/BalancerWeightedPriceFeed.js} +4 -4
  43. package/dist/esm/onchain/market/pricefeeds/{BoundedPriceFeed.js → feeds/BoundedPriceFeed.js} +4 -4
  44. package/dist/esm/onchain/market/pricefeeds/{CompositePriceFeed.js → feeds/CompositePriceFeed.js} +4 -4
  45. package/dist/esm/onchain/market/pricefeeds/{ConstantPriceFeed.js → feeds/ConstantPriceFeed.js} +3 -3
  46. package/dist/esm/onchain/market/pricefeeds/{CurveCryptoPriceFeed.js → feeds/CurveCryptoPriceFeed.js} +4 -4
  47. package/dist/esm/onchain/market/pricefeeds/{CurveStablePriceFeed.js → feeds/CurveStablePriceFeed.js} +4 -4
  48. package/dist/esm/onchain/market/pricefeeds/{CurveUSDPriceFeed.js → feeds/CurveUSDPriceFeed.js} +4 -4
  49. package/dist/esm/onchain/market/pricefeeds/{Erc4626PriceFeed.js → feeds/Erc4626PriceFeed.js} +4 -4
  50. package/dist/esm/onchain/market/pricefeeds/{ExternalPriceFeed.js → feeds/ExternalPriceFeed.js} +4 -4
  51. package/dist/esm/onchain/market/pricefeeds/{MellowLRTPriceFeed.js → feeds/MellowLRTPriceFeed.js} +4 -4
  52. package/dist/esm/onchain/market/pricefeeds/{PendleTWAPPTPriceFeed.js → feeds/PendleTWAPPTPriceFeed.js} +4 -4
  53. package/dist/esm/onchain/market/pricefeeds/{PythPriceFeed.js → feeds/PythPriceFeed.js} +3 -3
  54. package/dist/esm/onchain/market/pricefeeds/{RedstonePriceFeed.js → feeds/RedstonePriceFeed.js} +6 -6
  55. package/dist/esm/onchain/market/pricefeeds/{WstETHPriceFeed.js → feeds/WstETHPriceFeed.js} +4 -4
  56. package/dist/esm/onchain/market/pricefeeds/{YearnPriceFeed.js → feeds/YearnPriceFeed.js} +4 -4
  57. package/dist/esm/onchain/market/pricefeeds/{ZeroPriceFeed.js → feeds/ZeroPriceFeed.js} +4 -4
  58. package/dist/esm/onchain/market/pricefeeds/feeds/index.js +18 -0
  59. package/dist/esm/onchain/market/pricefeeds/index.js +27 -21
  60. package/dist/esm/onchain/market/pricefeeds/updates/UpdatablePriceFeedRegistry.js +188 -0
  61. package/dist/esm/onchain/market/pricefeeds/{getRawPriceUpdates.js → updates/getRawPriceUpdates.js} +2 -2
  62. package/dist/esm/onchain/market/pricefeeds/updates/index.js +5 -1
  63. package/dist/esm/onchain/market/pricefeeds/{isUpdatablePriceFeed.js → updates/isUpdatablePriceFeed.js} +1 -1
  64. package/dist/esm/onchain/market/pricefeeds/updates/updatableDependencies.js +13 -0
  65. package/dist/esm/permissionless/utils/price-update/get-price-update-tx.js +1 -1
  66. package/dist/esm/permissionless/utils/price-update/get-updatable-feeds.js +1 -1
  67. package/dist/types/dev/midasUtils.d.ts +6 -2
  68. package/dist/types/onchain/OnchainSDK.d.ts +2 -2
  69. package/dist/types/onchain/index.d.ts +27 -22
  70. package/dist/types/onchain/market/index.d.ts +27 -22
  71. package/dist/types/onchain/market/oracle/PriceOracleBaseContract.d.ts +2 -1
  72. package/dist/types/onchain/market/oracle/types.d.ts +2 -1
  73. package/dist/types/onchain/market/pricefeeds/AbstractPriceFeed.d.ts +1 -2
  74. package/dist/types/onchain/market/pricefeeds/PriceFeedRegistry.d.ts +60 -0
  75. package/dist/types/onchain/market/pricefeeds/feeds/BalancerStablePriceFeed.d.ts +12 -0
  76. package/dist/types/onchain/market/pricefeeds/{BalancerWeightedPriceFeed.d.ts → feeds/BalancerWeightedPriceFeed.d.ts} +7 -7
  77. package/dist/types/onchain/market/pricefeeds/feeds/BoundedPriceFeed.d.ts +15 -0
  78. package/dist/types/onchain/market/pricefeeds/{CompositePriceFeed.d.ts → feeds/CompositePriceFeed.d.ts} +6 -6
  79. package/dist/types/onchain/market/pricefeeds/{ConstantPriceFeed.d.ts → feeds/ConstantPriceFeed.d.ts} +6 -6
  80. package/dist/types/onchain/market/pricefeeds/feeds/CurveCryptoPriceFeed.d.ts +12 -0
  81. package/dist/types/onchain/market/pricefeeds/feeds/CurveStablePriceFeed.d.ts +12 -0
  82. package/dist/types/onchain/market/pricefeeds/feeds/CurveUSDPriceFeed.d.ts +12 -0
  83. package/dist/types/onchain/market/pricefeeds/feeds/Erc4626PriceFeed.d.ts +12 -0
  84. package/dist/types/onchain/market/pricefeeds/feeds/ExternalPriceFeed.d.ts +11 -0
  85. package/dist/types/onchain/market/pricefeeds/feeds/MellowLRTPriceFeed.d.ts +12 -0
  86. package/dist/types/onchain/market/pricefeeds/{PendleTWAPPTPriceFeed.d.ts → feeds/PendleTWAPPTPriceFeed.d.ts} +3 -3
  87. package/dist/types/onchain/market/pricefeeds/{PythPriceFeed.d.ts → feeds/PythPriceFeed.d.ts} +3 -3
  88. package/dist/types/onchain/market/pricefeeds/{RedstonePriceFeed.d.ts → feeds/RedstonePriceFeed.d.ts} +9 -9
  89. package/dist/types/onchain/market/pricefeeds/feeds/WstETHPriceFeed.d.ts +12 -0
  90. package/dist/types/onchain/market/pricefeeds/feeds/YearnPriceFeed.d.ts +12 -0
  91. package/dist/types/onchain/market/pricefeeds/feeds/ZeroPriceFeed.d.ts +11 -0
  92. package/dist/types/onchain/market/pricefeeds/feeds/index.d.ts +18 -0
  93. package/dist/types/onchain/market/pricefeeds/index.d.ts +28 -22
  94. package/dist/types/onchain/market/pricefeeds/types.d.ts +1 -31
  95. package/dist/types/onchain/market/pricefeeds/updates/RedstoneUpdater.d.ts +1 -1
  96. package/dist/types/onchain/market/pricefeeds/updates/UpdatablePriceFeedRegistry.d.ts +106 -0
  97. package/dist/types/onchain/market/pricefeeds/updates/getRawPriceUpdates.d.ts +6 -0
  98. package/dist/types/onchain/market/pricefeeds/updates/index.d.ts +7 -3
  99. package/dist/types/onchain/market/pricefeeds/updates/isUpdatablePriceFeed.d.ts +6 -0
  100. package/dist/types/onchain/market/pricefeeds/updates/types.d.ts +56 -2
  101. package/dist/types/onchain/market/pricefeeds/updates/updatableDependencies.d.ts +10 -0
  102. package/package.json +1 -1
  103. package/dist/cjs/onchain/market/pricefeeds/PriceFeedsRegister.js +0 -301
  104. package/dist/esm/onchain/market/pricefeeds/PriceFeedsRegister.js +0 -300
  105. package/dist/types/onchain/market/pricefeeds/BalancerStablePriceFeed.d.ts +0 -12
  106. package/dist/types/onchain/market/pricefeeds/BoundedPriceFeed.d.ts +0 -15
  107. package/dist/types/onchain/market/pricefeeds/CurveCryptoPriceFeed.d.ts +0 -12
  108. package/dist/types/onchain/market/pricefeeds/CurveStablePriceFeed.d.ts +0 -12
  109. package/dist/types/onchain/market/pricefeeds/CurveUSDPriceFeed.d.ts +0 -12
  110. package/dist/types/onchain/market/pricefeeds/Erc4626PriceFeed.d.ts +0 -12
  111. package/dist/types/onchain/market/pricefeeds/ExternalPriceFeed.d.ts +0 -11
  112. package/dist/types/onchain/market/pricefeeds/MellowLRTPriceFeed.d.ts +0 -12
  113. package/dist/types/onchain/market/pricefeeds/PriceFeedsRegister.d.ts +0 -180
  114. package/dist/types/onchain/market/pricefeeds/WstETHPriceFeed.d.ts +0 -12
  115. package/dist/types/onchain/market/pricefeeds/YearnPriceFeed.d.ts +0 -12
  116. package/dist/types/onchain/market/pricefeeds/ZeroPriceFeed.d.ts +0 -11
  117. package/dist/types/onchain/market/pricefeeds/getRawPriceUpdates.d.ts +0 -5
  118. package/dist/types/onchain/market/pricefeeds/isUpdatablePriceFeed.d.ts +0 -5
@@ -0,0 +1,126 @@
1
+ import { AddressMap } from "../../utils/AddressMap.js";
2
+ import { bytes32ToString } from "../../utils/bytes32ToString.js";
3
+ import "../../utils/index.js";
4
+ import { SDKConstruct } from "../../base/SDKConstruct.js";
5
+ import "../../base/index.js";
6
+ import { PartialPriceFeedInitError } from "./AbstractPriceFeed.js";
7
+ import { BalancerStablePriceFeedContract } from "./feeds/BalancerStablePriceFeed.js";
8
+ import { BalancerWeightedPriceFeedContract } from "./feeds/BalancerWeightedPriceFeed.js";
9
+ import { BoundedPriceFeedContract } from "./feeds/BoundedPriceFeed.js";
10
+ import { CompositePriceFeedContract } from "./feeds/CompositePriceFeed.js";
11
+ import { ConstantPriceFeedContract } from "./feeds/ConstantPriceFeed.js";
12
+ import { CurveCryptoPriceFeedContract } from "./feeds/CurveCryptoPriceFeed.js";
13
+ import { CurveStablePriceFeedContract } from "./feeds/CurveStablePriceFeed.js";
14
+ import { CurveUSDPriceFeedContract } from "./feeds/CurveUSDPriceFeed.js";
15
+ import { Erc4626PriceFeedContract } from "./feeds/Erc4626PriceFeed.js";
16
+ import { ExternalPriceFeedContract } from "./feeds/ExternalPriceFeed.js";
17
+ import { MellowLRTPriceFeedContract } from "./feeds/MellowLRTPriceFeed.js";
18
+ import { PendleTWAPPTPriceFeed } from "./feeds/PendleTWAPPTPriceFeed.js";
19
+ import { PythPriceFeed } from "./feeds/PythPriceFeed.js";
20
+ import { RedstonePriceFeedContract } from "./feeds/RedstonePriceFeed.js";
21
+ import { WstETHPriceFeedContract } from "./feeds/WstETHPriceFeed.js";
22
+ import { YearnPriceFeedContract } from "./feeds/YearnPriceFeed.js";
23
+ import { ZeroPriceFeedContract } from "./feeds/ZeroPriceFeed.js";
24
+ //#region src/onchain/market/pricefeeds/PriceFeedRegistry.ts
25
+ /**
26
+ * Chain-level cache of price feed contract instances.
27
+ *
28
+ * All {@link IPriceOracleContract}s across different markets share a single
29
+ * `PriceFeedRegistry`, avoiding duplicate contract wrappers for the same
30
+ * on-chain feed.
31
+ **/
32
+ var PriceFeedRegistry = class extends SDKConstruct {
33
+ #feeds = new AddressMap(void 0, "priceFeeds");
34
+ /**
35
+ * Returns all price feeds known to sdk
36
+ */
37
+ get feeds() {
38
+ return this.#feeds.values();
39
+ }
40
+ /**
41
+ * Checks whether a price feed is already registered at the given address.
42
+ * @param address - On-chain address to look up.
43
+ **/
44
+ has(address) {
45
+ return this.#feeds.has(address);
46
+ }
47
+ /**
48
+ * Returns the cached price feed contract at the given address, if any.
49
+ * @param address - On-chain address to look up.
50
+ **/
51
+ get(address) {
52
+ return this.#feeds.get(address);
53
+ }
54
+ /**
55
+ * Returns the cached price feed contract at the given address.
56
+ * @param address - On-chain address to look up.
57
+ * @throws If no feed is registered at that address.
58
+ **/
59
+ mustGet(address) {
60
+ return this.#feeds.mustGet(address);
61
+ }
62
+ /**
63
+ * Inserts or updates a price feed from a full tree node.
64
+ *
65
+ * If a fully loaded feed already exists at the same address, only the
66
+ * answer is refreshed. Otherwise a new contract wrapper is created and
67
+ * cached.
68
+ *
69
+ * @param data - Full price feed tree node from the compressor.
70
+ * @returns The cached (or newly created) feed instance.
71
+ * @throws If the created feed is only partially initialized.
72
+ **/
73
+ upsert(data) {
74
+ const existing = this.#feeds.get(data.baseParams.addr);
75
+ if (existing?.loaded) {
76
+ existing.updateAnswer(data.answer);
77
+ return existing;
78
+ }
79
+ const feed = this.create(data);
80
+ if (!feed.loaded) throw new PartialPriceFeedInitError({
81
+ ...data,
82
+ abi: [],
83
+ name: ""
84
+ });
85
+ this.#feeds.upsert(data.baseParams.addr, feed);
86
+ return feed;
87
+ }
88
+ /**
89
+ * Instantiates the appropriate price feed contract wrapper based on
90
+ * the `contractType` discriminator in the node's base params.
91
+ *
92
+ * @param data - Partial or full price feed tree node.
93
+ * @returns A new (uncached) feed contract instance.
94
+ * @throws If the contract type is unsupported and strict mode is enabled.
95
+ **/
96
+ create(data) {
97
+ const contractType = bytes32ToString(data.baseParams.contractType);
98
+ switch (contractType) {
99
+ case "PRICE_FEED::BALANCER_STABLE": return new BalancerStablePriceFeedContract(this.sdk, data);
100
+ case "PRICE_FEED::BALANCER_WEIGHTED": return new BalancerWeightedPriceFeedContract(this.sdk, data);
101
+ case "PRICE_FEED::BOUNDED": return new BoundedPriceFeedContract(this.sdk, data);
102
+ case "PRICE_FEED::COMPOSITE": return new CompositePriceFeedContract(this.sdk, data);
103
+ case "PRICE_FEED::CONSTANT": return new ConstantPriceFeedContract(this.sdk, data);
104
+ case "PRICE_FEED::CURVE_CRYPTO": return new CurveCryptoPriceFeedContract(this.sdk, data);
105
+ case "PRICE_FEED::CURVE_STABLE": return new CurveStablePriceFeedContract(this.sdk, data);
106
+ case "PRICE_FEED::CURVE_USD": return new CurveUSDPriceFeedContract(this.sdk, data);
107
+ case "PRICE_FEED::ERC4626": return new Erc4626PriceFeedContract(this.sdk, data);
108
+ case "PRICE_FEED::EXTERNAL": return new ExternalPriceFeedContract(this.sdk, data);
109
+ case "PRICE_FEED::MELLOW_LRT": return new MellowLRTPriceFeedContract(this.sdk, data);
110
+ case "PRICE_FEED::PENDLE_PT_TWAP": return new PendleTWAPPTPriceFeed(this.sdk, data);
111
+ case "PRICE_FEED::PYTH": return new PythPriceFeed(this.sdk, data);
112
+ case "PRICE_FEED::REDSTONE": return new RedstonePriceFeedContract(this.sdk, data);
113
+ case "PRICE_FEED::WSTETH": return new WstETHPriceFeedContract(this.sdk, data);
114
+ case "PRICE_FEED::YEARN": return new YearnPriceFeedContract(this.sdk, data);
115
+ case "PRICE_FEED::ZERO": return new ZeroPriceFeedContract(this.sdk, data);
116
+ default: {
117
+ const err = /* @__PURE__ */ new Error(`Price feed type ${contractType} not supported for price feed at ${data.baseParams.addr}`);
118
+ if (this.sdk.strictContractTypes) throw err;
119
+ this.logger?.error(err);
120
+ return new ExternalPriceFeedContract(this.sdk, data);
121
+ }
122
+ }
123
+ }
124
+ };
125
+ //#endregion
126
+ export { PriceFeedRegistry };
@@ -1,7 +1,7 @@
1
- import { AbstractLPPriceFeedContract } from "./AbstractLPPriceFeed.js";
2
- import { bptStablePriceFeedAbi } from "../../abi/oracles.js";
3
- import "../../abi/index.js";
4
- //#region src/onchain/market/pricefeeds/BalancerStablePriceFeed.ts
1
+ import { AbstractLPPriceFeedContract } from "../AbstractLPPriceFeed.js";
2
+ import { bptStablePriceFeedAbi } from "../../../abi/oracles.js";
3
+ import "../../../abi/index.js";
4
+ //#region src/onchain/market/pricefeeds/feeds/BalancerStablePriceFeed.ts
5
5
  var BalancerStablePriceFeedContract = class extends AbstractLPPriceFeedContract {
6
6
  constructor(options, args) {
7
7
  super(options, {
@@ -1,8 +1,8 @@
1
- import { AbstractLPPriceFeedContract } from "./AbstractLPPriceFeed.js";
2
- import { bptWeightedPriceFeedAbi } from "../../abi/oracles.js";
3
- import "../../abi/index.js";
1
+ import { AbstractLPPriceFeedContract } from "../AbstractLPPriceFeed.js";
2
+ import { bptWeightedPriceFeedAbi } from "../../../abi/oracles.js";
3
+ import "../../../abi/index.js";
4
4
  import { decodeAbiParameters, hexToBytes } from "viem";
5
- //#region src/onchain/market/pricefeeds/BalancerWeightedPriceFeed.ts
5
+ //#region src/onchain/market/pricefeeds/feeds/BalancerWeightedPriceFeed.ts
6
6
  var BalancerWeightedPriceFeedContract = class extends AbstractLPPriceFeedContract {
7
7
  vault;
8
8
  poolId;
@@ -1,8 +1,8 @@
1
- import { AbstractPriceFeedContract } from "./AbstractPriceFeed.js";
2
- import { boundedPriceFeedAbi } from "../../abi/oracles.js";
3
- import "../../abi/index.js";
1
+ import { AbstractPriceFeedContract } from "../AbstractPriceFeed.js";
2
+ import { boundedPriceFeedAbi } from "../../../abi/oracles.js";
3
+ import "../../../abi/index.js";
4
4
  import { decodeAbiParameters } from "viem";
5
- //#region src/onchain/market/pricefeeds/BoundedPriceFeed.ts
5
+ //#region src/onchain/market/pricefeeds/feeds/BoundedPriceFeed.ts
6
6
  var BoundedPriceFeedContract = class extends AbstractPriceFeedContract {
7
7
  upperBound;
8
8
  constructor(options, args) {
@@ -1,7 +1,7 @@
1
- import { AbstractPriceFeedContract } from "./AbstractPriceFeed.js";
2
- import { compositePriceFeedAbi } from "../../abi/oracles.js";
3
- import "../../abi/index.js";
4
- //#region src/onchain/market/pricefeeds/CompositePriceFeed.ts
1
+ import { AbstractPriceFeedContract } from "../AbstractPriceFeed.js";
2
+ import { compositePriceFeedAbi } from "../../../abi/oracles.js";
3
+ import "../../../abi/index.js";
4
+ //#region src/onchain/market/pricefeeds/feeds/CompositePriceFeed.ts
5
5
  var CompositePriceFeedContract = class extends AbstractPriceFeedContract {
6
6
  constructor(options, args) {
7
7
  super(options, {
@@ -1,7 +1,7 @@
1
- import { AbstractPriceFeedContract } from "./AbstractPriceFeed.js";
2
- import { constantPriceFeedAbi } from "../../abi/oracles.js";
1
+ import { AbstractPriceFeedContract } from "../AbstractPriceFeed.js";
2
+ import { constantPriceFeedAbi } from "../../../abi/oracles.js";
3
3
  import { decodeAbiParameters } from "viem";
4
- //#region src/onchain/market/pricefeeds/ConstantPriceFeed.ts
4
+ //#region src/onchain/market/pricefeeds/feeds/ConstantPriceFeed.ts
5
5
  var ConstantPriceFeedContract = class extends AbstractPriceFeedContract {
6
6
  price;
7
7
  constructor(options, args) {
@@ -1,7 +1,7 @@
1
- import { AbstractLPPriceFeedContract } from "./AbstractLPPriceFeed.js";
2
- import { curveCryptoLpPriceFeedAbi } from "../../abi/oracles.js";
3
- import "../../abi/index.js";
4
- //#region src/onchain/market/pricefeeds/CurveCryptoPriceFeed.ts
1
+ import { AbstractLPPriceFeedContract } from "../AbstractLPPriceFeed.js";
2
+ import { curveCryptoLpPriceFeedAbi } from "../../../abi/oracles.js";
3
+ import "../../../abi/index.js";
4
+ //#region src/onchain/market/pricefeeds/feeds/CurveCryptoPriceFeed.ts
5
5
  var CurveCryptoPriceFeedContract = class extends AbstractLPPriceFeedContract {
6
6
  constructor(options, args) {
7
7
  super(options, {
@@ -1,7 +1,7 @@
1
- import { AbstractLPPriceFeedContract } from "./AbstractLPPriceFeed.js";
2
- import { curveStableLpPriceFeedAbi } from "../../abi/oracles.js";
3
- import "../../abi/index.js";
4
- //#region src/onchain/market/pricefeeds/CurveStablePriceFeed.ts
1
+ import { AbstractLPPriceFeedContract } from "../AbstractLPPriceFeed.js";
2
+ import { curveStableLpPriceFeedAbi } from "../../../abi/oracles.js";
3
+ import "../../../abi/index.js";
4
+ //#region src/onchain/market/pricefeeds/feeds/CurveStablePriceFeed.ts
5
5
  var CurveStablePriceFeedContract = class extends AbstractLPPriceFeedContract {
6
6
  constructor(options, args) {
7
7
  super(options, {
@@ -1,7 +1,7 @@
1
- import { AbstractLPPriceFeedContract } from "./AbstractLPPriceFeed.js";
2
- import { curveUsdPriceFeedAbi } from "../../abi/oracles.js";
3
- import "../../abi/index.js";
4
- //#region src/onchain/market/pricefeeds/CurveUSDPriceFeed.ts
1
+ import { AbstractLPPriceFeedContract } from "../AbstractLPPriceFeed.js";
2
+ import { curveUsdPriceFeedAbi } from "../../../abi/oracles.js";
3
+ import "../../../abi/index.js";
4
+ //#region src/onchain/market/pricefeeds/feeds/CurveUSDPriceFeed.ts
5
5
  var CurveUSDPriceFeedContract = class extends AbstractLPPriceFeedContract {
6
6
  constructor(options, args) {
7
7
  super(options, {
@@ -1,7 +1,7 @@
1
- import { AbstractLPPriceFeedContract } from "./AbstractLPPriceFeed.js";
2
- import { erc4626PriceFeedAbi } from "../../abi/oracles.js";
3
- import "../../abi/index.js";
4
- //#region src/onchain/market/pricefeeds/Erc4626PriceFeed.ts
1
+ import { AbstractLPPriceFeedContract } from "../AbstractLPPriceFeed.js";
2
+ import { erc4626PriceFeedAbi } from "../../../abi/oracles.js";
3
+ import "../../../abi/index.js";
4
+ //#region src/onchain/market/pricefeeds/feeds/Erc4626PriceFeed.ts
5
5
  var Erc4626PriceFeedContract = class extends AbstractLPPriceFeedContract {
6
6
  constructor(options, args) {
7
7
  super(options, {
@@ -1,7 +1,7 @@
1
- import { AbstractPriceFeedContract } from "./AbstractPriceFeed.js";
2
- import { chainlinkReadableAggregatorAbi } from "../../abi/oracles.js";
3
- import "../../abi/index.js";
4
- //#region src/onchain/market/pricefeeds/ExternalPriceFeed.ts
1
+ import { AbstractPriceFeedContract } from "../AbstractPriceFeed.js";
2
+ import { chainlinkReadableAggregatorAbi } from "../../../abi/oracles.js";
3
+ import "../../../abi/index.js";
4
+ //#region src/onchain/market/pricefeeds/feeds/ExternalPriceFeed.ts
5
5
  var ExternalPriceFeedContract = class extends AbstractPriceFeedContract {
6
6
  constructor(options, args) {
7
7
  super(options, {
@@ -1,7 +1,7 @@
1
- import { AbstractLPPriceFeedContract } from "./AbstractLPPriceFeed.js";
2
- import { mellowLrtPriceFeedAbi } from "../../abi/oracles.js";
3
- import "../../abi/index.js";
4
- //#region src/onchain/market/pricefeeds/MellowLRTPriceFeed.ts
1
+ import { AbstractLPPriceFeedContract } from "../AbstractLPPriceFeed.js";
2
+ import { mellowLrtPriceFeedAbi } from "../../../abi/oracles.js";
3
+ import "../../../abi/index.js";
4
+ //#region src/onchain/market/pricefeeds/feeds/MellowLRTPriceFeed.ts
5
5
  var MellowLRTPriceFeedContract = class extends AbstractLPPriceFeedContract {
6
6
  constructor(options, args) {
7
7
  super(options, {
@@ -1,8 +1,8 @@
1
- import { AbstractPriceFeedContract } from "./AbstractPriceFeed.js";
2
- import { pendleTWAPPTPriceFeedAbi } from "../../abi/oracles.js";
3
- import "../../abi/index.js";
1
+ import { AbstractPriceFeedContract } from "../AbstractPriceFeed.js";
2
+ import { pendleTWAPPTPriceFeedAbi } from "../../../abi/oracles.js";
3
+ import "../../../abi/index.js";
4
4
  import { decodeAbiParameters } from "viem";
5
- //#region src/onchain/market/pricefeeds/PendleTWAPPTPriceFeed.ts
5
+ //#region src/onchain/market/pricefeeds/feeds/PendleTWAPPTPriceFeed.ts
6
6
  const abi = pendleTWAPPTPriceFeedAbi;
7
7
  var PendleTWAPPTPriceFeed = class extends AbstractPriceFeedContract {
8
8
  market;
@@ -1,7 +1,7 @@
1
- import { AbstractPriceFeedContract } from "./AbstractPriceFeed.js";
2
- import { pythPriceFeedAbi } from "../../abi/oracles.js";
1
+ import { AbstractPriceFeedContract } from "../AbstractPriceFeed.js";
2
+ import { pythPriceFeedAbi } from "../../../abi/oracles.js";
3
3
  import { decodeAbiParameters } from "viem";
4
- //#region src/onchain/market/pricefeeds/PythPriceFeed.ts
4
+ //#region src/onchain/market/pricefeeds/feeds/PythPriceFeed.ts
5
5
  const abi = pythPriceFeedAbi;
6
6
  var PythPriceFeed = class extends AbstractPriceFeedContract {
7
7
  token;
@@ -1,10 +1,10 @@
1
- import { ADDRESS_0X0 } from "../../constants/addresses.js";
2
- import "../../constants/index.js";
3
- import { AbstractPriceFeedContract } from "./AbstractPriceFeed.js";
4
- import { redstonePriceFeedAbi } from "../../abi/oracles.js";
5
- import "../../abi/index.js";
1
+ import { ADDRESS_0X0 } from "../../../constants/addresses.js";
2
+ import "../../../constants/index.js";
3
+ import { AbstractPriceFeedContract } from "../AbstractPriceFeed.js";
4
+ import { redstonePriceFeedAbi } from "../../../abi/oracles.js";
5
+ import "../../../abi/index.js";
6
6
  import { bytesToString, decodeAbiParameters, toBytes } from "viem";
7
- //#region src/onchain/market/pricefeeds/RedstonePriceFeed.ts
7
+ //#region src/onchain/market/pricefeeds/feeds/RedstonePriceFeed.ts
8
8
  var RedstonePriceFeedContract = class extends AbstractPriceFeedContract {
9
9
  token;
10
10
  dataServiceId;
@@ -1,7 +1,7 @@
1
- import { AbstractLPPriceFeedContract } from "./AbstractLPPriceFeed.js";
2
- import { wstEthPriceFeedAbi } from "../../abi/oracles.js";
3
- import "../../abi/index.js";
4
- //#region src/onchain/market/pricefeeds/WstETHPriceFeed.ts
1
+ import { AbstractLPPriceFeedContract } from "../AbstractLPPriceFeed.js";
2
+ import { wstEthPriceFeedAbi } from "../../../abi/oracles.js";
3
+ import "../../../abi/index.js";
4
+ //#region src/onchain/market/pricefeeds/feeds/WstETHPriceFeed.ts
5
5
  var WstETHPriceFeedContract = class extends AbstractLPPriceFeedContract {
6
6
  constructor(options, args) {
7
7
  super(options, {
@@ -1,7 +1,7 @@
1
- import { AbstractLPPriceFeedContract } from "./AbstractLPPriceFeed.js";
2
- import { yearnPriceFeedAbi } from "../../abi/oracles.js";
3
- import "../../abi/index.js";
4
- //#region src/onchain/market/pricefeeds/YearnPriceFeed.ts
1
+ import { AbstractLPPriceFeedContract } from "../AbstractLPPriceFeed.js";
2
+ import { yearnPriceFeedAbi } from "../../../abi/oracles.js";
3
+ import "../../../abi/index.js";
4
+ //#region src/onchain/market/pricefeeds/feeds/YearnPriceFeed.ts
5
5
  var YearnPriceFeedContract = class extends AbstractLPPriceFeedContract {
6
6
  constructor(options, args) {
7
7
  super(options, {
@@ -1,7 +1,7 @@
1
- import { AbstractPriceFeedContract } from "./AbstractPriceFeed.js";
2
- import { zeroPriceFeedAbi } from "../../abi/oracles.js";
3
- import "../../abi/index.js";
4
- //#region src/onchain/market/pricefeeds/ZeroPriceFeed.ts
1
+ import { AbstractPriceFeedContract } from "../AbstractPriceFeed.js";
2
+ import { zeroPriceFeedAbi } from "../../../abi/oracles.js";
3
+ import "../../../abi/index.js";
4
+ //#region src/onchain/market/pricefeeds/feeds/ZeroPriceFeed.ts
5
5
  var ZeroPriceFeedContract = class extends AbstractPriceFeedContract {
6
6
  constructor(options, args) {
7
7
  super(options, {
@@ -0,0 +1,18 @@
1
+ import { BalancerStablePriceFeedContract } from "./BalancerStablePriceFeed.js";
2
+ import { BalancerWeightedPriceFeedContract } from "./BalancerWeightedPriceFeed.js";
3
+ import { BoundedPriceFeedContract } from "./BoundedPriceFeed.js";
4
+ import { CompositePriceFeedContract } from "./CompositePriceFeed.js";
5
+ import { ConstantPriceFeedContract } from "./ConstantPriceFeed.js";
6
+ import { CurveCryptoPriceFeedContract } from "./CurveCryptoPriceFeed.js";
7
+ import { CurveStablePriceFeedContract } from "./CurveStablePriceFeed.js";
8
+ import { CurveUSDPriceFeedContract } from "./CurveUSDPriceFeed.js";
9
+ import { Erc4626PriceFeedContract } from "./Erc4626PriceFeed.js";
10
+ import { ExternalPriceFeedContract } from "./ExternalPriceFeed.js";
11
+ import { MellowLRTPriceFeedContract } from "./MellowLRTPriceFeed.js";
12
+ import { PendleTWAPPTPriceFeed } from "./PendleTWAPPTPriceFeed.js";
13
+ import { PythPriceFeed } from "./PythPriceFeed.js";
14
+ import { RedstonePriceFeedContract } from "./RedstonePriceFeed.js";
15
+ import { WstETHPriceFeedContract } from "./WstETHPriceFeed.js";
16
+ import { YearnPriceFeedContract } from "./YearnPriceFeed.js";
17
+ import { ZeroPriceFeedContract } from "./ZeroPriceFeed.js";
18
+ export { BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BoundedPriceFeedContract, CompositePriceFeedContract, ConstantPriceFeedContract, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, Erc4626PriceFeedContract, ExternalPriceFeedContract, MellowLRTPriceFeedContract, PendleTWAPPTPriceFeed, PythPriceFeed, RedstonePriceFeedContract, WstETHPriceFeedContract, YearnPriceFeedContract, ZeroPriceFeedContract };
@@ -1,26 +1,32 @@
1
- import { isUpdatablePriceFeed } from "./isUpdatablePriceFeed.js";
2
1
  import { PriceFeedRef } from "./PriceFeedRef.js";
3
2
  import { AbstractPriceFeedContract, PartialPriceFeedInitError } from "./AbstractPriceFeed.js";
4
3
  import { AbstractLPPriceFeedContract, isLPPriceFeed } from "./AbstractLPPriceFeed.js";
5
- import { BalancerStablePriceFeedContract } from "./BalancerStablePriceFeed.js";
6
- import { BalancerWeightedPriceFeedContract } from "./BalancerWeightedPriceFeed.js";
7
- import { BoundedPriceFeedContract } from "./BoundedPriceFeed.js";
8
- import { CompositePriceFeedContract } from "./CompositePriceFeed.js";
9
- import { CurveCryptoPriceFeedContract } from "./CurveCryptoPriceFeed.js";
10
- import { CurveStablePriceFeedContract } from "./CurveStablePriceFeed.js";
11
- import { CurveUSDPriceFeedContract } from "./CurveUSDPriceFeed.js";
12
- import { Erc4626PriceFeedContract } from "./Erc4626PriceFeed.js";
13
- import { ExternalPriceFeedContract } from "./ExternalPriceFeed.js";
14
- import { getRawPriceUpdates } from "./getRawPriceUpdates.js";
15
- import { MellowLRTPriceFeedContract } from "./MellowLRTPriceFeed.js";
16
- import { PendleTWAPPTPriceFeed } from "./PendleTWAPPTPriceFeed.js";
17
- import { PythPriceFeed } from "./PythPriceFeed.js";
18
- import { RedstonePriceFeedContract } from "./RedstonePriceFeed.js";
4
+ import { BalancerStablePriceFeedContract } from "./feeds/BalancerStablePriceFeed.js";
5
+ import { BalancerWeightedPriceFeedContract } from "./feeds/BalancerWeightedPriceFeed.js";
6
+ import { BoundedPriceFeedContract } from "./feeds/BoundedPriceFeed.js";
7
+ import { CompositePriceFeedContract } from "./feeds/CompositePriceFeed.js";
8
+ import { ConstantPriceFeedContract } from "./feeds/ConstantPriceFeed.js";
9
+ import { CurveCryptoPriceFeedContract } from "./feeds/CurveCryptoPriceFeed.js";
10
+ import { CurveStablePriceFeedContract } from "./feeds/CurveStablePriceFeed.js";
11
+ import { CurveUSDPriceFeedContract } from "./feeds/CurveUSDPriceFeed.js";
12
+ import { Erc4626PriceFeedContract } from "./feeds/Erc4626PriceFeed.js";
13
+ import { ExternalPriceFeedContract } from "./feeds/ExternalPriceFeed.js";
14
+ import { MellowLRTPriceFeedContract } from "./feeds/MellowLRTPriceFeed.js";
15
+ import { PendleTWAPPTPriceFeed } from "./feeds/PendleTWAPPTPriceFeed.js";
16
+ import { PythPriceFeed } from "./feeds/PythPriceFeed.js";
17
+ import { RedstonePriceFeedContract } from "./feeds/RedstonePriceFeed.js";
18
+ import { WstETHPriceFeedContract } from "./feeds/WstETHPriceFeed.js";
19
+ import { YearnPriceFeedContract } from "./feeds/YearnPriceFeed.js";
20
+ import { ZeroPriceFeedContract } from "./feeds/ZeroPriceFeed.js";
21
+ import "./feeds/index.js";
22
+ import { PriceFeedRegistry } from "./PriceFeedRegistry.js";
23
+ import "./types.js";
19
24
  import { fetchRedstonePayloads } from "./updates/fetchRedstonePayloads.js";
25
+ import { getRawPriceUpdates } from "./updates/getRawPriceUpdates.js";
26
+ import { isUpdatablePriceFeed } from "./updates/isUpdatablePriceFeed.js";
27
+ import { PriceUpdatesCache } from "./updates/PriceUpdatesCache.js";
28
+ import { RedstoneOptions, RedstoneUpdater } from "./updates/RedstoneUpdater.js";
29
+ import { updatableDependencies } from "./updates/updatableDependencies.js";
30
+ import { UpdatablePriceFeedRegistry } from "./updates/UpdatablePriceFeedRegistry.js";
20
31
  import "./updates/index.js";
21
- import { WstETHPriceFeedContract } from "./WstETHPriceFeed.js";
22
- import { YearnPriceFeedContract } from "./YearnPriceFeed.js";
23
- import { ZeroPriceFeedContract } from "./ZeroPriceFeed.js";
24
- import { PriceFeedRegister } from "./PriceFeedsRegister.js";
25
- import "./types.js";
26
- export { AbstractLPPriceFeedContract, AbstractPriceFeedContract, BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BoundedPriceFeedContract, CompositePriceFeedContract, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, Erc4626PriceFeedContract, ExternalPriceFeedContract, MellowLRTPriceFeedContract, PartialPriceFeedInitError, PendleTWAPPTPriceFeed, PriceFeedRef, PriceFeedRegister, PythPriceFeed, RedstonePriceFeedContract, WstETHPriceFeedContract, YearnPriceFeedContract, ZeroPriceFeedContract, fetchRedstonePayloads, getRawPriceUpdates, isLPPriceFeed, isUpdatablePriceFeed };
32
+ export { AbstractLPPriceFeedContract, AbstractPriceFeedContract, BalancerStablePriceFeedContract, BalancerWeightedPriceFeedContract, BoundedPriceFeedContract, CompositePriceFeedContract, ConstantPriceFeedContract, CurveCryptoPriceFeedContract, CurveStablePriceFeedContract, CurveUSDPriceFeedContract, Erc4626PriceFeedContract, ExternalPriceFeedContract, MellowLRTPriceFeedContract, PartialPriceFeedInitError, PendleTWAPPTPriceFeed, PriceFeedRef, PriceFeedRegistry, PriceUpdatesCache, PythPriceFeed, RedstoneOptions, RedstonePriceFeedContract, RedstoneUpdater, UpdatablePriceFeedRegistry, WstETHPriceFeedContract, YearnPriceFeedContract, ZeroPriceFeedContract, fetchRedstonePayloads, getRawPriceUpdates, isLPPriceFeed, isUpdatablePriceFeed, updatableDependencies };
@@ -0,0 +1,188 @@
1
+ import { createRawTx } from "../../../utils/createRawTx.js";
2
+ import { AP_PRICE_FEED_COMPRESSOR, AP_PRICE_FEED_STORE } from "../../../constants/address-provider.js";
3
+ import { ADDRESS_0X0 } from "../../../constants/addresses.js";
4
+ import { VERSION_RANGE_310 } from "../../../constants/versions.js";
5
+ import "../../../constants/index.js";
6
+ import "../../../utils/index.js";
7
+ import { priceFeedCompressorAbi } from "../../../../abi/compressors/priceFeedCompressor.js";
8
+ import { PriceFeedRegistry } from "../PriceFeedRegistry.js";
9
+ import { getRawPriceUpdates } from "./getRawPriceUpdates.js";
10
+ import { isUpdatablePriceFeed } from "./isUpdatablePriceFeed.js";
11
+ import { RedstoneUpdater } from "./RedstoneUpdater.js";
12
+ import { Hooks } from "../../../utils/internal/Hooks.js";
13
+ import "../../../utils/internal/index.js";
14
+ import { updatableDependencies } from "./updatableDependencies.js";
15
+ import { parseAbi } from "viem";
16
+ //#region src/onchain/market/pricefeeds/updates/UpdatablePriceFeedRegistry.ts
17
+ /**
18
+ * {@link PriceFeedRegistry} that also orchestrates off-chain price updates
19
+ * (Redstone, etc.).
20
+ **/
21
+ var UpdatablePriceFeedRegistry = class extends PriceFeedRegistry {
22
+ #hooks = new Hooks();
23
+ #updaters;
24
+ #latestUpdate;
25
+ constructor(sdk, opts = {}) {
26
+ super(sdk);
27
+ this.#updaters = [new RedstoneUpdater(sdk, opts.redstone)];
28
+ }
29
+ /**
30
+ * @internal
31
+ * Registers a callback for price-feed registry lifecycle events.
32
+ * @param event - Event name.
33
+ * @param handler - Callback to invoke.
34
+ **/
35
+ addHook = this.#hooks.addHook.bind(this.#hooks);
36
+ /**
37
+ * @internal
38
+ * Removes a previously registered hook.
39
+ * @param event - Event name.
40
+ * @param handler - Callback to remove.
41
+ **/
42
+ removeHook = this.#hooks.removeHook.bind(this.#hooks);
43
+ /**
44
+ * Generates transactions to push fresh off-chain prices to updatable feeds.
45
+ *
46
+ * @param priceFeeds - Top-level price feeds whose updatable dependencies
47
+ * will be resolved, or a filter (`{ main: true }` / `{ reserve: true }`)
48
+ * to gather feeds from all oracles. When omitted, all registered feeds
49
+ * are used.
50
+ **/
51
+ async generatePriceFeedsUpdateTxs(priceFeeds) {
52
+ let updateables = this.feeds;
53
+ let filterRemark = "";
54
+ if (priceFeeds) {
55
+ if (Array.isArray(priceFeeds)) updateables = priceFeeds.flatMap((pf) => updatableDependencies(pf));
56
+ else if ("main" in priceFeeds && priceFeeds.main) {
57
+ filterRemark = " main";
58
+ updateables = this.sdk.marketRegister.priceOracles.flatMap((o) => o.mainPriceFeeds.values()).flatMap((pf) => updatableDependencies(pf.priceFeed));
59
+ } else if ("reserve" in priceFeeds && priceFeeds.reserve) {
60
+ filterRemark = " reserve";
61
+ updateables = this.sdk.marketRegister.priceOracles.flatMap((o) => o.reservePriceFeeds.values()).flatMap((pf) => updatableDependencies(pf.priceFeed));
62
+ }
63
+ }
64
+ return this.#generateUpdateTxs(updateables, filterRemark);
65
+ }
66
+ /**
67
+ * Similar to {@link generatePriceFeedsUpdateTxs}, but returns raw structures instead of transactions
68
+ * @param priceFeeds
69
+ * @returns
70
+ */
71
+ async generatePriceFeedsUpdates(priceFeeds) {
72
+ const updates = await this.generatePriceFeedsUpdateTxs(priceFeeds);
73
+ return getRawPriceUpdates(updates);
74
+ }
75
+ /**
76
+ * Similar to {@link generatePriceFeedsUpdates}, but returns raw transaction to PriceFeedStore.updatePrices
77
+ * @param priceFeeds
78
+ * @returns
79
+ */
80
+ async getPriceFeedStoreUpdateTx(priceFeeds) {
81
+ const pfs = this.sdk.addressProvider.getAddress(AP_PRICE_FEED_STORE);
82
+ const updates = await this.generatePriceFeedsUpdates(priceFeeds);
83
+ return createRawTx(pfs, {
84
+ abi: parseAbi(["function updatePrices((address,bytes)[])"]),
85
+ functionName: "updatePrices",
86
+ args: [updates.map((u) => [u.priceFeed, u.data])]
87
+ });
88
+ }
89
+ /**
90
+ * Similar to {@link generatePriceFeedsUpdateTxs}, but will generate necessary price update transactions for external price feeds (not known to sdk)
91
+ * This does not add feeds to this registry, so they won't be implicitly included in future generatePriceFeedsUpdateTxs calls
92
+ * @param feeds
93
+ * @param block
94
+ * @returns
95
+ */
96
+ async generateExternalPriceFeedsUpdateTxs(feeds, block) {
97
+ const [priceFeedCompressorAddress] = this.sdk.addressProvider.mustGetLatest(AP_PRICE_FEED_COMPRESSOR, VERSION_RANGE_310);
98
+ const blockParam = block ?? { blockNumber: this.sdk.currentBlock };
99
+ const leaves = (await this.client.readContract({
100
+ address: priceFeedCompressorAddress,
101
+ abi: priceFeedCompressorAbi,
102
+ functionName: "loadPriceFeedTree",
103
+ args: [feeds],
104
+ ...blockParam,
105
+ gas: this.sdk.gasLimit
106
+ })).map((node) => this.get(node.baseParams.addr) ?? this.create(node)).filter(isUpdatablePriceFeed);
107
+ return this.#generateUpdateTxs(leaves, "");
108
+ }
109
+ /**
110
+ * Similar to {@link generateExternalPriceFeedsUpdateTxs}, but returns raw structures instead of transactions
111
+ * @param feeds
112
+ * @param block
113
+ * @returns
114
+ */
115
+ async generateExternalPriceFeedsUpdates(feeds, block) {
116
+ const updates = await this.generateExternalPriceFeedsUpdateTxs(feeds, block);
117
+ return getRawPriceUpdates(updates);
118
+ }
119
+ /**
120
+ * Loads PARTIAL information about all updatable price feeds from MarketCompressor
121
+ * Discovered price feeds are not saved anywhere in PriceFeedRegistry, and can later be used to load price feed updates
122
+ */
123
+ async getPartialUpdatablePriceFeeds(configurators) {
124
+ const [priceFeedCompressorAddress] = this.sdk.addressProvider.mustGetLatest(AP_PRICE_FEED_COMPRESSOR, VERSION_RANGE_310);
125
+ this.logger?.debug({ configurators }, `calling getUpdatablePriceFeeds in block ${this.sdk.currentBlock}`);
126
+ const result = await this.client.readContract({
127
+ address: priceFeedCompressorAddress,
128
+ abi: priceFeedCompressorAbi,
129
+ functionName: "getUpdatablePriceFeeds",
130
+ args: [{
131
+ configurators,
132
+ pools: [],
133
+ underlying: ADDRESS_0X0
134
+ }],
135
+ blockNumber: this.sdk.currentBlock,
136
+ gas: this.sdk.gasLimit
137
+ });
138
+ this.logger?.debug(`loaded ${result.length} partial updatable price feeds in block ${this.sdk.currentBlock}`);
139
+ return result.map((baseParams) => this.create({ baseParams }));
140
+ }
141
+ /**
142
+ * @internal
143
+ * Diagnostic snapshot of the most recent price-update round, or
144
+ * `undefined` if no updates have been generated yet.
145
+ **/
146
+ get latestUpdate() {
147
+ return this.#latestUpdate;
148
+ }
149
+ /**
150
+ * @internal
151
+ * Returns true if any of the updaters are in historical mode
152
+ */
153
+ get historical() {
154
+ return this.#updaters.some((u) => u.historical);
155
+ }
156
+ async #generateUpdateTxs(updateables, filterRemark) {
157
+ if (updateables.length === 0) return {
158
+ txs: [],
159
+ timestamp: 0
160
+ };
161
+ const txs = [];
162
+ const latestUpdate = {
163
+ updates: [],
164
+ timestamp: Math.floor(Date.now() / 1e3)
165
+ };
166
+ const updates = (await Promise.all(this.#updaters.map((u) => u.getUpdateTxs([...updateables]).catch(() => [])))).flat();
167
+ let maxTimestamp = 0;
168
+ for (const tx of updates) {
169
+ const { data } = tx;
170
+ const { timestamp } = data;
171
+ if (timestamp > maxTimestamp) maxTimestamp = timestamp;
172
+ txs.push(tx);
173
+ latestUpdate.updates.push(data);
174
+ }
175
+ txs.sort((a, b) => a.raw.to.toLowerCase().localeCompare(b.raw.to.toLowerCase()));
176
+ const result = {
177
+ txs,
178
+ timestamp: maxTimestamp
179
+ };
180
+ const tsDelta = BigInt(maxTimestamp) - this.sdk.timestamp;
181
+ this.logger?.debug(`generated ${txs.length}${filterRemark} price feed update transactions, timestamp: ${maxTimestamp} (delta ${tsDelta})`);
182
+ if (txs.length) await this.#hooks.triggerHooks("updatesGenerated", result);
183
+ this.#latestUpdate = latestUpdate;
184
+ return result;
185
+ }
186
+ };
187
+ //#endregion
188
+ export { UpdatablePriceFeedRegistry };
@@ -1,6 +1,6 @@
1
- import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
1
+ import { iUpdatablePriceFeedAbi } from "../../../../abi/iUpdatablePriceFeed.js";
2
2
  import { decodeFunctionData } from "viem";
3
- //#region src/onchain/market/pricefeeds/getRawPriceUpdates.ts
3
+ //#region src/onchain/market/pricefeeds/updates/getRawPriceUpdates.ts
4
4
  function getRawPriceUpdates(updates) {
5
5
  return updates.txs.map((tx) => {
6
6
  const data = decodeFunctionData({