@gearbox-protocol/sdk 13.3.3 → 13.4.0-beta.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 (89) hide show
  1. package/dist/cjs/permissionless/utils/price-update/get-price-update-tx.js +3 -15
  2. package/dist/cjs/sdk/GearboxSDK.js +135 -20
  3. package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +196 -340
  4. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +30 -35
  5. package/dist/cjs/sdk/accounts/multicall-utils.js +91 -0
  6. package/dist/cjs/sdk/base/BaseContract.js +26 -6
  7. package/dist/cjs/sdk/base/ChainContractsRegister.js +39 -2
  8. package/dist/cjs/sdk/base/Construct.js +15 -3
  9. package/dist/cjs/sdk/base/TokensMeta.js +23 -0
  10. package/dist/cjs/sdk/constants/address-provider.js +0 -22
  11. package/dist/cjs/sdk/core/AbstractAddressProviderContract.js +15 -0
  12. package/dist/cjs/sdk/market/MarketRegister.js +74 -3
  13. package/dist/cjs/sdk/market/credit/CreditFacadeV310Contract.js +6 -0
  14. package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +31 -50
  15. package/dist/cjs/sdk/market/pricefeeds/PriceFeedRef.js +16 -0
  16. package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +55 -12
  17. package/dist/cjs/sdk/options.js +30 -24
  18. package/dist/cjs/sdk/plugins/BasePlugin.js +24 -0
  19. package/dist/cjs/sdk/pools/AbstractPoolService.js +6 -0
  20. package/dist/cjs/sdk/router/AbstractRouterContract.js +4 -1
  21. package/dist/cjs/sdk/router/RouterV310Contract.js +20 -15
  22. package/dist/cjs/sdk/utils/AddressMap.js +53 -17
  23. package/dist/cjs/sdk/utils/AddressSet.js +9 -0
  24. package/dist/esm/permissionless/utils/price-update/get-price-update-tx.js +6 -20
  25. package/dist/esm/sdk/GearboxSDK.js +135 -20
  26. package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +204 -342
  27. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +30 -35
  28. package/dist/esm/sdk/accounts/multicall-utils.js +69 -0
  29. package/dist/esm/sdk/base/BaseContract.js +26 -6
  30. package/dist/esm/sdk/base/ChainContractsRegister.js +39 -2
  31. package/dist/esm/sdk/base/Construct.js +15 -3
  32. package/dist/esm/sdk/base/TokensMeta.js +23 -0
  33. package/dist/esm/sdk/constants/address-provider.js +0 -21
  34. package/dist/esm/sdk/core/AbstractAddressProviderContract.js +15 -0
  35. package/dist/esm/sdk/market/MarketRegister.js +74 -3
  36. package/dist/esm/sdk/market/credit/CreditFacadeV310Contract.js +6 -0
  37. package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +31 -50
  38. package/dist/esm/sdk/market/pricefeeds/PriceFeedRef.js +16 -0
  39. package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +55 -12
  40. package/dist/esm/sdk/options.js +30 -24
  41. package/dist/esm/sdk/plugins/BasePlugin.js +24 -0
  42. package/dist/esm/sdk/pools/AbstractPoolService.js +6 -0
  43. package/dist/esm/sdk/router/AbstractRouterContract.js +4 -1
  44. package/dist/esm/sdk/router/RouterV310Contract.js +20 -15
  45. package/dist/esm/sdk/utils/AddressMap.js +53 -17
  46. package/dist/esm/sdk/utils/AddressSet.js +9 -0
  47. package/dist/types/permissionless/bindings/price-feed-store.d.ts +1 -2
  48. package/dist/types/permissionless/bindings/types.d.ts +0 -4
  49. package/dist/types/permissionless/utils/price-update/get-price-update-tx.d.ts +1 -3
  50. package/dist/types/sdk/GearboxSDK.d.ts +236 -34
  51. package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +92 -147
  52. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +14 -5
  53. package/dist/types/sdk/accounts/multicall-utils.d.ts +39 -0
  54. package/dist/types/sdk/accounts/types.d.ts +237 -40
  55. package/dist/types/sdk/base/BaseContract.d.ts +67 -6
  56. package/dist/types/sdk/base/ChainContractsRegister.d.ts +51 -2
  57. package/dist/types/sdk/base/Construct.d.ts +31 -0
  58. package/dist/types/sdk/base/PlaceholderContract.d.ts +3 -0
  59. package/dist/types/sdk/base/SDKConstruct.d.ts +10 -0
  60. package/dist/types/sdk/base/TokensMeta.d.ts +59 -2
  61. package/dist/types/sdk/base/types.d.ts +185 -25
  62. package/dist/types/sdk/chain/chains.d.ts +78 -18
  63. package/dist/types/sdk/chain/detectNetwork.d.ts +7 -0
  64. package/dist/types/sdk/constants/address-provider.d.ts +4 -3
  65. package/dist/types/sdk/core/AbstractAddressProviderContract.d.ts +23 -0
  66. package/dist/types/sdk/core/types.d.ts +46 -0
  67. package/dist/types/sdk/market/MarketRegister.d.ts +81 -0
  68. package/dist/types/sdk/market/adapters/PlaceholderAdapterContracts.d.ts +3 -0
  69. package/dist/types/sdk/market/credit/CreditFacadeV310Contract.d.ts +1 -0
  70. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +40 -50
  71. package/dist/types/sdk/market/oracle/types.d.ts +78 -59
  72. package/dist/types/sdk/market/pricefeeds/AbstractLPPriceFeed.d.ts +3 -0
  73. package/dist/types/sdk/market/pricefeeds/AbstractPriceFeed.d.ts +3 -0
  74. package/dist/types/sdk/market/pricefeeds/PriceFeedRef.d.ts +22 -2
  75. package/dist/types/sdk/market/pricefeeds/PriceFeedsRegister.d.ts +80 -16
  76. package/dist/types/sdk/market/pricefeeds/getRawPriceUpdates.d.ts +2 -2
  77. package/dist/types/sdk/market/pricefeeds/types.d.ts +75 -11
  78. package/dist/types/sdk/options.d.ts +13 -4
  79. package/dist/types/sdk/plugins/BasePlugin.d.ts +39 -0
  80. package/dist/types/sdk/plugins/types.d.ts +73 -43
  81. package/dist/types/sdk/pools/AbstractPoolService.d.ts +12 -0
  82. package/dist/types/sdk/pools/types.d.ts +75 -6
  83. package/dist/types/sdk/router/AbstractRouterContract.d.ts +21 -2
  84. package/dist/types/sdk/router/RouterV310Contract.d.ts +27 -15
  85. package/dist/types/sdk/router/types.d.ts +47 -70
  86. package/dist/types/sdk/types/state.d.ts +32 -3
  87. package/dist/types/sdk/utils/AddressMap.d.ts +61 -17
  88. package/dist/types/sdk/utils/AddressSet.d.ts +15 -0
  89. package/package.json +4 -2
@@ -29,9 +29,6 @@ var import_viem = require("../utils/viem/index.js");
29
29
  var import_MarketConfiguratorContract = require("./MarketConfiguratorContract.js");
30
30
  var import_MarketSuite = require("./MarketSuite.js");
31
31
  class MarketRegister extends import_base.SDKConstruct {
32
- /**
33
- * Mapping pool.address -> MarketSuite
34
- */
35
32
  #markets = new import_utils.AddressMap(void 0, "markets");
36
33
  #marketFilter;
37
34
  #marketConfigurators = new import_utils.AddressMap(
@@ -39,12 +36,21 @@ class MarketRegister extends import_base.SDKConstruct {
39
36
  "marketConfigurators"
40
37
  );
41
38
  #ignoreMarkets;
39
+ /**
40
+ * @param sdk - Top-level SDK instance.
41
+ * @param ignoreMarkets - Pool addresses of markets to exclude from loading.
42
+ **/
42
43
  constructor(sdk, ignoreMarkets = []) {
43
44
  super(sdk);
44
45
  this.#ignoreMarkets = new Set(
45
46
  ignoreMarkets.map((m) => m.toLowerCase())
46
47
  );
47
48
  }
49
+ /**
50
+ * Restores market state from a previously serialized snapshot,
51
+ * bypassing on-chain reads.
52
+ * @param state - Array of market data snapshots.
53
+ **/
48
54
  hydrate(state) {
49
55
  this.#markets.clear();
50
56
  const configurators = new Set(state.map((m) => m.configurator));
@@ -63,6 +69,13 @@ class MarketRegister extends import_base.SDKConstruct {
63
69
  );
64
70
  }
65
71
  }
72
+ /**
73
+ * Fetches all markets from the on-chain for the given market configurators.
74
+ *
75
+ * @param marketConfigurators - Addresses of market configurator contracts to query.
76
+ * @param ignoreUpdateablePrices - When `true`, skips generating off-chain
77
+ * price updates before loading
78
+ **/
66
79
  async loadMarkets(marketConfigurators, ignoreUpdateablePrices) {
67
80
  if (!marketConfigurators.length) {
68
81
  this.logger?.warn(
@@ -85,6 +98,10 @@ class MarketRegister extends import_base.SDKConstruct {
85
98
  underlying: import_constants.ADDRESS_0X0
86
99
  };
87
100
  }
101
+ /**
102
+ * The active filter used to scope market compressor queries.
103
+ * @throws If the register has not been hydrated or attached yet.
104
+ **/
88
105
  get marketFilter() {
89
106
  if (!this.#marketFilter) {
90
107
  throw new Error(
@@ -93,6 +110,15 @@ class MarketRegister extends import_base.SDKConstruct {
93
110
  }
94
111
  return this.#marketFilter;
95
112
  }
113
+ /**
114
+ * Re-synchronizes market state with the chain. If during sdk synchronization
115
+ * we detected that some markets or market configurators were changed,
116
+ * we reload everything.
117
+ *
118
+ * Otherwise only prices are refreshed.
119
+ *
120
+ * @param ignoreUpdateablePrices - When `true`, skips off-chain price updates.
121
+ **/
96
122
  async syncState(ignoreUpdateablePrices) {
97
123
  const dirty = this.markets.some((m) => m.dirty) || this.marketConfigurators.some((c) => c.dirty);
98
124
  if (dirty) {
@@ -203,26 +229,50 @@ class MarketRegister extends import_base.SDKConstruct {
203
229
  ...this.marketFilter.configurators
204
230
  ]);
205
231
  }
232
+ /**
233
+ * Serializable snapshot of all loaded markets, suitable for hydration.
234
+ **/
206
235
  get state() {
207
236
  return this.markets.map((market) => market.state);
208
237
  }
238
+ /**
239
+ * Returns a human-readable snapshot of all markets.
240
+ * @param raw - When `true`, includes raw/unformatted values.
241
+ **/
209
242
  stateHuman(raw = true) {
210
243
  return {
211
244
  markets: this.markets.map((market) => market.stateHuman(raw))
212
245
  };
213
246
  }
247
+ /**
248
+ * All pool suites across loaded markets.
249
+ **/
214
250
  get pools() {
215
251
  return this.markets.map((market) => market.pool);
216
252
  }
253
+ /**
254
+ * All price oracles across loaded markets.
255
+ **/
217
256
  get priceOracles() {
218
257
  return this.markets.map((market) => market.priceOracle);
219
258
  }
259
+ /**
260
+ * All credit manager suites across loaded markets.
261
+ **/
220
262
  get creditManagers() {
221
263
  return this.markets.flatMap((market) => market.creditManagers);
222
264
  }
265
+ /**
266
+ * All known market configurator contracts.
267
+ **/
223
268
  get marketConfigurators() {
224
269
  return this.#marketConfigurators.values();
225
270
  }
271
+ /**
272
+ * Finds a credit manager suite by its on-chain address.
273
+ * @param creditManager - Credit manager contract address.
274
+ * @throws If no loaded market contains the given credit manager.
275
+ **/
226
276
  findCreditManager(creditManager) {
227
277
  const addr = creditManager.toLowerCase();
228
278
  for (const market of this.markets) {
@@ -234,6 +284,11 @@ class MarketRegister extends import_base.SDKConstruct {
234
284
  }
235
285
  throw new Error(`cannot find credit manager ${creditManager}`);
236
286
  }
287
+ /**
288
+ * Finds the market that contains the given credit manager.
289
+ * @param creditManager - Credit manager contract address.
290
+ * @throws If no loaded market contains the given credit manager.
291
+ **/
237
292
  findByCreditManager(creditManager) {
238
293
  const addr = creditManager.toLowerCase();
239
294
  const market = this.markets.find(
@@ -246,6 +301,11 @@ class MarketRegister extends import_base.SDKConstruct {
246
301
  }
247
302
  return market;
248
303
  }
304
+ /**
305
+ * Finds the market that uses the given price oracle.
306
+ * @param address - Price oracle contract address.
307
+ * @throws If no loaded market uses the given oracle.
308
+ **/
249
309
  findByPriceOracle(address) {
250
310
  const addr = address.toLowerCase();
251
311
  for (const market of this.markets) {
@@ -255,6 +315,11 @@ class MarketRegister extends import_base.SDKConstruct {
255
315
  }
256
316
  throw new Error(`cannot find market for price oracle ${address}`);
257
317
  }
318
+ /**
319
+ * Finds the market associated with the given pool.
320
+ * @param address - Pool contract address.
321
+ * @throws If no loaded market uses the given pool.
322
+ **/
258
323
  findByPool(address) {
259
324
  const addr = address.toLowerCase();
260
325
  for (const market of this.markets) {
@@ -264,9 +329,15 @@ class MarketRegister extends import_base.SDKConstruct {
264
329
  }
265
330
  throw new Error(`cannot find market for pool ${address}`);
266
331
  }
332
+ /**
333
+ * Underlying address map of pool address to market suite
334
+ **/
267
335
  get marketsMap() {
268
336
  return this.#markets;
269
337
  }
338
+ /**
339
+ * All loaded market suites.
340
+ **/
270
341
  get markets() {
271
342
  return this.#markets.values();
272
343
  }
@@ -91,6 +91,12 @@ class CreditFacadeV310Contract extends import_CreditFacadeV310BaseContract.Credi
91
91
  args: [ca, calls]
92
92
  });
93
93
  }
94
+ botMulticall(ca, calls) {
95
+ return this.createRawTx({
96
+ functionName: "botMulticall",
97
+ args: [ca, calls]
98
+ });
99
+ }
94
100
  openCreditAccount(to, calls, referralCode) {
95
101
  return this.createRawTx({
96
102
  functionName: "openCreditAccount",
@@ -43,26 +43,26 @@ const ZERO_PRICE_FEED = (0, import_viem.stringToHex)("PRICE_FEED::ZERO", { size:
43
43
  class PriceOracleBaseContract extends import_base.BaseContract {
44
44
  sdk;
45
45
  /**
46
- * Mapping Token => [PriceFeed Address, stalenessPeriod]
47
- */
46
+ * {@inheritDoc IPriceOracleContract.mainPriceFeeds}
47
+ **/
48
48
  mainPriceFeeds = new import_utils.AddressMap(
49
49
  void 0,
50
50
  "mainPriceFeeds"
51
51
  );
52
52
  /**
53
- * Mapping Token => [PriceFeed Address, stalenessPeriod]
54
- */
53
+ * {@inheritDoc IPriceOracleContract.reservePriceFeeds}
54
+ **/
55
55
  reservePriceFeeds = new import_utils.AddressMap(
56
56
  void 0,
57
57
  "reservePriceFeeds"
58
58
  );
59
59
  /**
60
- * Mapping Token => Price in USD
61
- */
60
+ * {@inheritDoc IPriceOracleContract.mainPrices}
61
+ **/
62
62
  mainPrices = new import_PriceFeedAnswerMap.default(void 0, "mainPrices");
63
63
  /**
64
- * Mapping Token => Price in USD
65
- */
64
+ * {@inheritDoc IPriceOracleContract.reservePrices}
65
+ **/
66
66
  reservePrices = new import_PriceFeedAnswerMap.default(
67
67
  void 0,
68
68
  "reservePrices"
@@ -78,11 +78,8 @@ class PriceOracleBaseContract extends import_base.BaseContract {
78
78
  this.#loadState(priceFeedMap, priceFeedTree);
79
79
  }
80
80
  /**
81
- * Returns main and reserve price feeds for given tokens
82
- * @param tokens
83
- * @param opts Option to include main/reserve feeds only, defaults to both
84
- * @returns
85
- */
81
+ * {@inheritDoc IPriceOracleContract.priceFeedsForTokens}
82
+ **/
86
83
  priceFeedsForTokens(tokens, opts) {
87
84
  const main = opts?.main ?? true;
88
85
  const reserve = opts?.reserve ?? true;
@@ -92,39 +89,26 @@ class PriceOracleBaseContract extends import_base.BaseContract {
92
89
  ]).filter((f) => !!f);
93
90
  }
94
91
  /**
95
- * Gets main price for given token
96
- * Throws if token price feed is not found or answer is not successful
97
- * @param token
98
- * @returns
99
- */
92
+ * {@inheritDoc IPriceOracleContract.mainPrice}
93
+ **/
100
94
  mainPrice(token) {
101
95
  return this.mainPrices.price(token);
102
96
  }
103
97
  /**
104
- * Gets reserve price for given token
105
- * Throws if token price feed is not found or answer is not successful
106
- * @param token
107
- * @returns
108
- */
98
+ * {@inheritDoc IPriceOracleContract.reservePrice}
99
+ **/
109
100
  reservePrice(token) {
110
101
  return this.reservePrices.price(token);
111
102
  }
112
103
  /**
113
- * Returns true if oracle's price feed tree contains given price feed
114
- * This feed is not necessary connected to token, but can be a component of composite feed for some token
115
- * @param priceFeed
116
- * @returns
117
- */
104
+ * {@inheritDoc IPriceOracleContract.usesPriceFeed}
105
+ **/
118
106
  usesPriceFeed(priceFeed) {
119
107
  return this.#priceFeedTree.has(priceFeed);
120
108
  }
121
109
  /**
122
- * Tries to convert amount of from one token to another, using latest known prices
123
- * @param from
124
- * @param to
125
- * @param amount
126
- * @param reserve use reserve price feed instead of main
127
- */
110
+ * {@inheritDoc IPriceOracleContract.convert}
111
+ **/
128
112
  convert(from, to, amount, reserve = false) {
129
113
  if (from === to) {
130
114
  return amount;
@@ -136,11 +120,8 @@ class PriceOracleBaseContract extends import_base.BaseContract {
136
120
  return amount * fromPrice * toScale / (toPrice * fromScale);
137
121
  }
138
122
  /**
139
- * Tries to convert amount of token to USD, using latest known prices
140
- * @param from
141
- * @param amount
142
- * @param reserve use reserve price feed instead of main
143
- */
123
+ * {@inheritDoc IPriceOracleContract.convertToUSD}
124
+ **/
144
125
  convertToUSD(from, amount, reserve = false) {
145
126
  if (amount === 0n) {
146
127
  return 0n;
@@ -150,11 +131,8 @@ class PriceOracleBaseContract extends import_base.BaseContract {
150
131
  return amount * price / scale;
151
132
  }
152
133
  /**
153
- * Tries to convert amount of USD to token, using latest known prices
154
- * @param to
155
- * @param amount
156
- * @param reserve use reserve price feed instead of main
157
- */
134
+ * {@inheritDoc IPriceOracleContract.convertFromUSD}
135
+ **/
158
136
  convertFromUSD(to, amount, reserve = false) {
159
137
  if (amount === 0n) {
160
138
  return 0n;
@@ -164,14 +142,14 @@ class PriceOracleBaseContract extends import_base.BaseContract {
164
142
  return amount * scale / price;
165
143
  }
166
144
  /**
167
- * All price feed tree nodes known to this oracle
168
- */
145
+ * {@inheritDoc IPriceOracleContract.priceFeeds}
146
+ **/
169
147
  get priceFeeds() {
170
148
  return this.#priceFeedTree.values().map((node) => this.sdk.priceFeeds.mustGet(node.baseParams.addr));
171
149
  }
172
150
  /**
173
- * Paired method to updatePrices, helps to update prices on all oracles in one multicall
174
- */
151
+ * {@inheritDoc IPriceOracleContract.syncStateMulticall}
152
+ **/
175
153
  syncStateMulticall() {
176
154
  const args = [this.address];
177
155
  const [address] = this.sdk.addressProvider.mustGetLatest(
@@ -237,11 +215,14 @@ class PriceOracleBaseContract extends import_base.BaseContract {
237
215
  });
238
216
  }
239
217
  /**
240
- * Returns list of addresses that should be watched for events to sync state
241
- */
218
+ * {@inheritDoc IPriceOracleContract.watchAddresses}
219
+ **/
242
220
  get watchAddresses() {
243
221
  return /* @__PURE__ */ new Set([this.address]);
244
222
  }
223
+ /**
224
+ * {@inheritDoc IPriceOracleContract.stateHuman}
225
+ **/
245
226
  stateHuman(raw = true) {
246
227
  return {
247
228
  ...super.stateHuman(raw),
@@ -24,7 +24,14 @@ module.exports = __toCommonJS(PriceFeedRef_exports);
24
24
  var import_base = require("../../base/index.js");
25
25
  var import_utils = require("../../utils/index.js");
26
26
  class PriceFeedRef extends import_base.Construct {
27
+ /**
28
+ * On-chain address of the referenced price feed contract.
29
+ **/
27
30
  address;
31
+ /**
32
+ * Maximum allowed age (in seconds) of the feed's answer before the
33
+ * oracle considers it stale.
34
+ **/
28
35
  stalenessPeriod;
29
36
  #priceFeed;
30
37
  constructor(options, address, stalenessPeriod) {
@@ -32,6 +39,10 @@ class PriceFeedRef extends import_base.Construct {
32
39
  this.address = address;
33
40
  this.stalenessPeriod = stalenessPeriod;
34
41
  }
42
+ /**
43
+ * Lazily resolved price feed contract instance.
44
+ * @throws If the feed is not registered in the contracts register.
45
+ **/
35
46
  get priceFeed() {
36
47
  if (!this.#priceFeed) {
37
48
  this.#priceFeed = this.register.mustGetContract(
@@ -40,6 +51,11 @@ class PriceFeedRef extends import_base.Construct {
40
51
  }
41
52
  return this.#priceFeed;
42
53
  }
54
+ /**
55
+ * Returns a human-readable snapshot of the feed state, including the
56
+ * staleness period formatted as a duration string.
57
+ * @param raw - When `true`, includes raw/unformatted values.
58
+ **/
43
59
  stateHuman(raw = true) {
44
60
  return {
45
61
  ...this.priceFeed.stateHuman(raw),
@@ -49,17 +49,29 @@ var import_YearnPriceFeed = require("./YearnPriceFeed.js");
49
49
  var import_ZeroPriceFeed = require("./ZeroPriceFeed.js");
50
50
  class PriceFeedRegister extends import_base.SDKConstruct {
51
51
  #hooks = new import_internal.Hooks();
52
+ #updaters;
52
53
  #feeds = new import_utils.AddressMap(void 0, "priceFeeds");
53
54
  #latestUpdate;
54
- updaters;
55
55
  constructor(sdk, opts = {}) {
56
56
  super(sdk);
57
- this.updaters = [
57
+ this.#updaters = [
58
58
  new import_updates.PythUpdater(sdk, opts?.pyth),
59
59
  new import_updates.RedstoneUpdater(sdk, opts?.redstone)
60
60
  ];
61
61
  }
62
+ /**
63
+ * @internal
64
+ * Registers a callback for price-feed register lifecycle events.
65
+ * @param event - Event name.
66
+ * @param handler - Callback to invoke.
67
+ **/
62
68
  addHook = this.#hooks.addHook.bind(this.#hooks);
69
+ /**
70
+ * @internal
71
+ * Removes a previously registered hook.
72
+ * @param event - Event name.
73
+ * @param handler - Callback to remove.
74
+ **/
63
75
  removeHook = this.#hooks.removeHook.bind(this.#hooks);
64
76
  /**
65
77
  * Returns all price feeds known to sdk
@@ -68,12 +80,13 @@ class PriceFeedRegister extends import_base.SDKConstruct {
68
80
  return this.#feeds.values();
69
81
  }
70
82
  /**
71
- * Returns RawTxs to update price feeds
72
- * @param priceFeeds Array oftop-level price feeds, actual updatable price feeds will be derived.
73
- * Or filter criteria, that will gather all main or reserve price feeds from all oracles
74
- * If not provided will use all price feeds that are attached
75
- * @returns
76
- */
83
+ * Generates transactions to push fresh off-chain prices to updatable feeds.
84
+ *
85
+ * @param priceFeeds - Top-level price feeds whose updatable dependencies
86
+ * will be resolved, or a filter (`{ main: true }` / `{ reserve: true }`)
87
+ * to gather feeds from all oracles. When omitted, all registered feeds
88
+ * are used.
89
+ **/
77
90
  async generatePriceFeedsUpdateTxs(priceFeeds) {
78
91
  let updateables = this.#feeds.values();
79
92
  let filterRemark = "";
@@ -94,7 +107,7 @@ class PriceFeedRegister extends import_base.SDKConstruct {
94
107
  timestamp: Math.floor(Date.now() / 1e3)
95
108
  };
96
109
  const updates = (await Promise.all(
97
- this.updaters.map((u) => u.getUpdateTxs(updateables).catch(() => []))
110
+ this.#updaters.map((u) => u.getUpdateTxs(updateables).catch(() => []))
98
111
  )).flat();
99
112
  let maxTimestamp = 0;
100
113
  for (const tx of updates) {
@@ -144,7 +157,7 @@ class PriceFeedRegister extends import_base.SDKConstruct {
144
157
  });
145
158
  }
146
159
  /**
147
- * Similar to {@link generatePriceFeedsUpdateTxs}, but will generate necessary price update transactions for external price feeds
160
+ * Similar to {@link generatePriceFeedsUpdateTxs}, but will generate necessary price update transactions for external price feeds (not known to sdk)
148
161
  * This does not add feeds to this register, so they won't be implicitly included in future generatePriceFeedsUpdateTxs calls
149
162
  * @param feeds
150
163
  * @param block
@@ -181,12 +194,32 @@ class PriceFeedRegister extends import_base.SDKConstruct {
181
194
  );
182
195
  return (0, import_getRawPriceUpdates.getRawPriceUpdates)(updates);
183
196
  }
197
+ /**
198
+ * Checks whether a price feed is already registered at the given address.
199
+ * @param address - On-chain address to look up.
200
+ **/
184
201
  has(address) {
185
202
  return this.#feeds.has(address);
186
203
  }
204
+ /**
205
+ * Returns the cached price feed contract at the given address.
206
+ * @param address - On-chain address to look up.
207
+ * @throws If no feed is registered at that address.
208
+ **/
187
209
  mustGet(address) {
188
210
  return this.#feeds.mustGet(address);
189
211
  }
212
+ /**
213
+ * Inserts or updates a price feed from a full tree node.
214
+ *
215
+ * If a fully loaded feed already exists at the same address, only the
216
+ * answer is refreshed. Otherwise a new contract wrapper is created and
217
+ * cached.
218
+ *
219
+ * @param data - Full price feed tree node from the compressor.
220
+ * @returns The cached (or newly created) feed instance.
221
+ * @throws If the created feed is only partially initialized.
222
+ **/
190
223
  upsert(data) {
191
224
  const existing = this.#feeds.get(data.baseParams.addr);
192
225
  if (existing?.loaded) {
@@ -233,6 +266,14 @@ class PriceFeedRegister extends import_base.SDKConstruct {
233
266
  );
234
267
  return result.map((baseParams) => this.#createUpdatableProxy({ baseParams }));
235
268
  }
269
+ /**
270
+ * Instantiates the appropriate price feed contract wrapper based on
271
+ * the `contractType` discriminator in the node's base params.
272
+ *
273
+ * @param data - Partial or full price feed tree node.
274
+ * @returns A new (uncached) feed contract instance.
275
+ * @throws If the contract type is unsupported and strict mode is enabled.
276
+ **/
236
277
  create(data) {
237
278
  const contractType = (0, import_utils.bytes32ToString)(
238
279
  data.baseParams.contractType
@@ -296,8 +337,10 @@ class PriceFeedRegister extends import_base.SDKConstruct {
296
337
  });
297
338
  }
298
339
  /**
299
- * Information update latest update of updatable price feeds, for diagnostic purposes
300
- */
340
+ * @internal
341
+ * Diagnostic snapshot of the most recent price-update round, or
342
+ * `undefined` if no updates have been generated yet.
343
+ **/
301
344
  get latestUpdate() {
302
345
  return this.#latestUpdate;
303
346
  }
@@ -26,50 +26,56 @@ var import_updates = require("./market/pricefeeds/updates/index.js");
26
26
  var import_utils = require("./utils/index.js");
27
27
  const SDKOptions = import_v4.z.object({
28
28
  /**
29
- * If not set, address provider address is determinted automatically from networkType
30
- */
29
+ * Override address of the Gearbox AddressProvider contract.
30
+ * If not set, uses default universal address provider address {@link ADDRESS_PROVIDER_V310}
31
+ **/
31
32
  addressProvider: (0, import_utils.ZodAddress)().optional(),
32
33
  /**
33
- * Market configurators
34
- */
34
+ * Addresses of market configurator contracts to load.
35
+ * If not set, all default market configurators for the chain are loaded
36
+ * (from {@link GearboxChain.defaultMarketConfigurators})
37
+ **/
35
38
  marketConfigurators: import_v4.z.array((0, import_utils.ZodAddress)()).optional(),
36
39
  /**
37
- * Attach and load state at this specific block number
38
- */
40
+ * Pin SDK to a specific block number during attach.
41
+ * When set, all on-chain reads use this block instead of `latest`.
42
+ **/
39
43
  blockNumber: import_v4.z.union([import_v4.z.bigint().nonnegative(), import_v4.z.number().int().nonnegative()]).optional(),
40
44
  /**
41
- * Will skip updateable prices on attach and sync
42
- * Makes things faster when your service is not intereseted in prices
43
- */
45
+ * Skip fetching updatable price feeds on attach and sync.
46
+ * Speeds up initialisation when prices are not needed.
47
+ **/
44
48
  ignoreUpdateablePrices: import_v4.z.boolean().optional(),
45
49
  /**
46
- * Will skip loading markets for these pools on attach/hydrate/sync
47
- */
50
+ * Pool addresses whose markets should be skipped during attach/hydrate/sync.
51
+ **/
48
52
  ignoreMarkets: import_v4.z.array((0, import_utils.ZodAddress)()).optional(),
49
53
  /**
50
- * Will throw an error if contract type is not supported, otherwise will try to use generic contract first, if possible
51
- */
54
+ * When `true`, throw on unrecognised contract types instead of falling
55
+ * back to a generic contract wrapper.
56
+ **/
52
57
  strictContractTypes: import_v4.z.boolean().optional(),
53
58
  /**
54
- * Plugins to extends SDK functionality
55
- */
59
+ * Plugins that extend SDK functionality.
60
+ **/
56
61
  plugins: import_v4.z.record(import_v4.z.string(), import_v4.z.any()).optional(),
57
62
  /**
58
- * Bring your own logger
59
- */
63
+ * Custom logger implementation.
64
+ **/
60
65
  logger: import_v4.z.any(),
61
66
  /**
62
- * Options related to redstone price feeds
63
- */
67
+ * Options for Redstone price-feed updates.
68
+ **/
64
69
  redstone: import_updates.RedstoneOptions.optional(),
65
70
  /**
66
- * Options related to pyth price feeds
67
- */
71
+ * Options for Pyth price-feed updates.
72
+ **/
68
73
  pyth: import_updates.PythOptions.optional(),
69
74
  /**
70
- * Explicit gas limit for read eth_calls
71
- * Null to disable explicitly setting gas limit, undefined to use default sdk value
72
- */
75
+ * Explicit gas limit for read-only `eth_call` requests.
76
+ * `null` disables the gas limit entirely; `undefined` uses the SDK default.
77
+ * Default gas limit is 550_000_000 (550M).
78
+ **/
73
79
  gasLimit: import_v4.z.bigint().nonnegative().nullable().optional()
74
80
  });
75
81
  // Annotate the CommonJS export names for ESM import in node:
@@ -24,11 +24,23 @@ module.exports = __toCommonJS(BasePlugin_exports);
24
24
  class BasePlugin {
25
25
  #sdk;
26
26
  logger;
27
+ /**
28
+ * Plugin state version for hydration compatibility checks.
29
+ * @default 1
30
+ **/
27
31
  version = 1;
32
+ /**
33
+ * When `true`, state is fetched eagerly during the `attach` phase
34
+ * rather than waiting for an explicit `load` call.
35
+ **/
28
36
  loadOnAttach;
29
37
  constructor(loadOnAttach = false) {
30
38
  this.loadOnAttach = loadOnAttach;
31
39
  }
40
+ /**
41
+ * Reference to the parent SDK instance.
42
+ * @throws Error if the SDK has not been attached yet.
43
+ **/
32
44
  get sdk() {
33
45
  if (!this.#sdk) {
34
46
  throw new Error("SDK is not attached");
@@ -42,17 +54,29 @@ class BasePlugin {
42
54
  this.#sdk = sdk;
43
55
  this.logger = sdk.logger?.child?.({ name: this.constructor.name }) ?? sdk.logger;
44
56
  }
57
+ /**
58
+ * {@inheritDoc IGearboxSDKPlugin.attach}
59
+ **/
45
60
  async attach() {
46
61
  if (this.loadOnAttach) {
47
62
  await this.load(true);
48
63
  }
49
64
  }
65
+ /**
66
+ * {@inheritDoc IGearboxSDKPlugin.syncState}
67
+ **/
50
68
  async syncState() {
51
69
  await this.load(false);
52
70
  }
71
+ /**
72
+ * Network type of the connected chain (e.g. `"Mainnet"`, `"Arbitrum"`).
73
+ **/
53
74
  get network() {
54
75
  return this.sdk.networkType;
55
76
  }
77
+ /**
78
+ * Viem public client for read-only chain interactions.
79
+ **/
56
80
  get client() {
57
81
  return this.sdk.client;
58
82
  }
@@ -33,6 +33,9 @@ class AbstractPoolService extends import_base.SDKConstruct {
33
33
  this.#version = version;
34
34
  this.logger?.debug(`Created PoolService with version: ${this.#version}`);
35
35
  }
36
+ /**
37
+ * {@inheritDoc IPoolsService.addLiquidity}
38
+ **/
36
39
  addLiquidity({
37
40
  collateral,
38
41
  pool,
@@ -89,6 +92,9 @@ class AbstractPoolService extends import_base.SDKConstruct {
89
92
  ];
90
93
  }
91
94
  }
95
+ /**
96
+ * {@inheritDoc IPoolsService.removeLiquidity}
97
+ **/
92
98
  removeLiquidity({
93
99
  pool,
94
100
  amount,