@gearbox-protocol/sdk 7.9.0 → 7.10.0

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.
@@ -52,6 +52,7 @@ class GearboxSDK {
52
52
  #marketRegister;
53
53
  #priceFeeds;
54
54
  logger;
55
+ gasLimit = 550000000n;
55
56
  /**
56
57
  * Interest rate models can be reused across chain (and SDK operates on chain level)
57
58
  * TODO: use whatever interface is necessary for InterestRateModels
@@ -64,7 +64,9 @@ class CreditAccountsService extends import_base.SDKConstruct {
64
64
  address: this.#compressor,
65
65
  functionName: "getCreditAccountData",
66
66
  args: [account],
67
- blockNumber
67
+ blockNumber,
68
+ // @ts-expect-error
69
+ gas: this.sdk.gasLimit
68
70
  });
69
71
  } catch (e) {
70
72
  return void 0;
@@ -85,7 +87,8 @@ class CreditAccountsService extends import_base.SDKConstruct {
85
87
  args: [account]
86
88
  }
87
89
  ],
88
- blockNumber
90
+ blockNumber,
91
+ gas: this.sdk.gasLimit
89
92
  });
90
93
  return cad;
91
94
  }
@@ -740,7 +743,8 @@ class CreditAccountsService extends import_base.SDKConstruct {
740
743
  args
741
744
  }
742
745
  ],
743
- blockNumber
746
+ blockNumber,
747
+ gas: this.sdk.gasLimit
744
748
  });
745
749
  } else {
746
750
  resp = await this.provider.publicClient.readContract({
@@ -748,7 +752,9 @@ class CreditAccountsService extends import_base.SDKConstruct {
748
752
  address: this.#compressor,
749
753
  functionName: "getCreditAccounts",
750
754
  args,
751
- blockNumber
755
+ blockNumber,
756
+ // @ts-expect-error
757
+ gas: this.sdk.gasLimit
752
758
  });
753
759
  }
754
760
  this.#logger?.debug(
@@ -46,6 +46,11 @@ class MarketRegister extends import_base.SDKConstruct {
46
46
  new import_MarketSuite.MarketSuite(this.sdk, data)
47
47
  );
48
48
  }
49
+ this.#marketFilter = {
50
+ configurators: this.marketConfigurators.map((c) => c.address),
51
+ pools: [],
52
+ underlying: import_constants.ADDRESS_0X0
53
+ };
49
54
  }
50
55
  async loadMarkets(marketConfigurators, ignoreUpdateablePrices) {
51
56
  if (!marketConfigurators.length) {
@@ -76,9 +81,6 @@ class MarketRegister extends import_base.SDKConstruct {
76
81
  dirtyPools.map((p) => p.pool.address)
77
82
  );
78
83
  } else if (!skipPriceUpdate && nonDirtyOracles.length) {
79
- this.#logger?.debug(
80
- `syncing prices on ${nonDirtyOracles.length} oracles`
81
- );
82
84
  await this.updatePrices(nonDirtyOracles);
83
85
  }
84
86
  }
@@ -119,7 +121,8 @@ class MarketRegister extends import_base.SDKConstruct {
119
121
  args: [this.#marketFilter]
120
122
  }
121
123
  ],
122
- blockNumber: this.sdk.currentBlock
124
+ blockNumber: this.sdk.currentBlock,
125
+ gas: this.sdk.gasLimit
123
126
  }
124
127
  );
125
128
  markets = resp;
@@ -129,7 +132,9 @@ class MarketRegister extends import_base.SDKConstruct {
129
132
  address: marketCompressorAddress,
130
133
  functionName: "getMarkets",
131
134
  args: [this.#marketFilter],
132
- blockNumber: this.sdk.currentBlock
135
+ blockNumber: this.sdk.currentBlock,
136
+ // @ts-expect-error
137
+ gas: this.sdk.gasLimit
133
138
  });
134
139
  }
135
140
  for (const data of markets) {
@@ -147,16 +152,24 @@ class MarketRegister extends import_base.SDKConstruct {
147
152
  * Supports v300 and v310 oracles
148
153
  */
149
154
  async updatePrices(oracles) {
150
- const multicalls = this.markets.map((m) => m.priceOracle).filter((o) => !oracles || oracles.includes(o.address)).map((o) => o.syncStateMulticall());
155
+ const uniqOracles = new import_utils.AddressMap();
156
+ for (const m of this.markets) {
157
+ if (!oracles || oracles.includes(m.priceOracle.address)) {
158
+ uniqOracles.upsert(m.priceOracle.address, m.priceOracle);
159
+ }
160
+ }
161
+ const multicalls = uniqOracles.values().map((o) => o.syncStateMulticall());
151
162
  if (!multicalls.length) {
152
163
  return;
153
164
  }
165
+ this.#logger?.debug(`syncing prices on ${multicalls.length} oracles`);
154
166
  const { txs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs();
155
167
  const oraclesStates = await (0, import_viem.simulateWithPriceUpdates)(
156
168
  this.provider.publicClient,
157
169
  {
158
170
  priceUpdates: txs,
159
- contracts: multicalls.map((mc) => mc.call)
171
+ contracts: multicalls.map((mc) => mc.call),
172
+ gas: this.sdk.gasLimit
160
173
  }
161
174
  );
162
175
  for (let i = 0; i < multicalls.length; i++) {
@@ -146,7 +146,9 @@ class PriceFeedRegister extends import_base.SDKConstruct {
146
146
  underlying: import_constants.ADDRESS_0X0
147
147
  }
148
148
  ],
149
- blockNumber: this.sdk.currentBlock
149
+ blockNumber: this.sdk.currentBlock,
150
+ // @ts-expect-error
151
+ gas: this.sdk.gasLimit
150
152
  });
151
153
  this.logger?.debug(
152
154
  `loaded ${result.length} partial updatable price feeds in block ${this.sdk.currentBlock}`
@@ -186,6 +186,9 @@ function extractCallError(result) {
186
186
  if (error instanceof import_viem.ContractFunctionRevertedError) {
187
187
  return "[" + (error.data?.errorName ?? "reverted") + "]";
188
188
  }
189
+ if (err instanceof import_viem.CallExecutionError) {
190
+ return `[${err.name}: ${err.details}]`;
191
+ }
189
192
  return err instanceof import_viem.BaseError ? `[${err.name}]` : "[error]";
190
193
  }
191
194
  class SimulateWithPriceUpdatesError extends import_viem.BaseError {
@@ -50,6 +50,7 @@ class GearboxSDK {
50
50
  #marketRegister;
51
51
  #priceFeeds;
52
52
  logger;
53
+ gasLimit = 550000000n;
53
54
  /**
54
55
  * Interest rate models can be reused across chain (and SDK operates on chain level)
55
56
  * TODO: use whatever interface is necessary for InterestRateModels
@@ -69,7 +69,9 @@ class CreditAccountsService extends SDKConstruct {
69
69
  address: this.#compressor,
70
70
  functionName: "getCreditAccountData",
71
71
  args: [account],
72
- blockNumber
72
+ blockNumber,
73
+ // @ts-expect-error
74
+ gas: this.sdk.gasLimit
73
75
  });
74
76
  } catch (e) {
75
77
  return void 0;
@@ -90,7 +92,8 @@ class CreditAccountsService extends SDKConstruct {
90
92
  args: [account]
91
93
  }
92
94
  ],
93
- blockNumber
95
+ blockNumber,
96
+ gas: this.sdk.gasLimit
94
97
  });
95
98
  return cad;
96
99
  }
@@ -745,7 +748,8 @@ class CreditAccountsService extends SDKConstruct {
745
748
  args
746
749
  }
747
750
  ],
748
- blockNumber
751
+ blockNumber,
752
+ gas: this.sdk.gasLimit
749
753
  });
750
754
  } else {
751
755
  resp = await this.provider.publicClient.readContract({
@@ -753,7 +757,9 @@ class CreditAccountsService extends SDKConstruct {
753
757
  address: this.#compressor,
754
758
  functionName: "getCreditAccounts",
755
759
  args,
756
- blockNumber
760
+ blockNumber,
761
+ // @ts-expect-error
762
+ gas: this.sdk.gasLimit
757
763
  });
758
764
  }
759
765
  this.#logger?.debug(
@@ -27,6 +27,11 @@ class MarketRegister extends SDKConstruct {
27
27
  new MarketSuite(this.sdk, data)
28
28
  );
29
29
  }
30
+ this.#marketFilter = {
31
+ configurators: this.marketConfigurators.map((c) => c.address),
32
+ pools: [],
33
+ underlying: ADDRESS_0X0
34
+ };
30
35
  }
31
36
  async loadMarkets(marketConfigurators, ignoreUpdateablePrices) {
32
37
  if (!marketConfigurators.length) {
@@ -57,9 +62,6 @@ class MarketRegister extends SDKConstruct {
57
62
  dirtyPools.map((p) => p.pool.address)
58
63
  );
59
64
  } else if (!skipPriceUpdate && nonDirtyOracles.length) {
60
- this.#logger?.debug(
61
- `syncing prices on ${nonDirtyOracles.length} oracles`
62
- );
63
65
  await this.updatePrices(nonDirtyOracles);
64
66
  }
65
67
  }
@@ -100,7 +102,8 @@ class MarketRegister extends SDKConstruct {
100
102
  args: [this.#marketFilter]
101
103
  }
102
104
  ],
103
- blockNumber: this.sdk.currentBlock
105
+ blockNumber: this.sdk.currentBlock,
106
+ gas: this.sdk.gasLimit
104
107
  }
105
108
  );
106
109
  markets = resp;
@@ -110,7 +113,9 @@ class MarketRegister extends SDKConstruct {
110
113
  address: marketCompressorAddress,
111
114
  functionName: "getMarkets",
112
115
  args: [this.#marketFilter],
113
- blockNumber: this.sdk.currentBlock
116
+ blockNumber: this.sdk.currentBlock,
117
+ // @ts-expect-error
118
+ gas: this.sdk.gasLimit
114
119
  });
115
120
  }
116
121
  for (const data of markets) {
@@ -128,16 +133,24 @@ class MarketRegister extends SDKConstruct {
128
133
  * Supports v300 and v310 oracles
129
134
  */
130
135
  async updatePrices(oracles) {
131
- const multicalls = this.markets.map((m) => m.priceOracle).filter((o) => !oracles || oracles.includes(o.address)).map((o) => o.syncStateMulticall());
136
+ const uniqOracles = new AddressMap();
137
+ for (const m of this.markets) {
138
+ if (!oracles || oracles.includes(m.priceOracle.address)) {
139
+ uniqOracles.upsert(m.priceOracle.address, m.priceOracle);
140
+ }
141
+ }
142
+ const multicalls = uniqOracles.values().map((o) => o.syncStateMulticall());
132
143
  if (!multicalls.length) {
133
144
  return;
134
145
  }
146
+ this.#logger?.debug(`syncing prices on ${multicalls.length} oracles`);
135
147
  const { txs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs();
136
148
  const oraclesStates = await simulateWithPriceUpdates(
137
149
  this.provider.publicClient,
138
150
  {
139
151
  priceUpdates: txs,
140
- contracts: multicalls.map((mc) => mc.call)
152
+ contracts: multicalls.map((mc) => mc.call),
153
+ gas: this.sdk.gasLimit
141
154
  }
142
155
  );
143
156
  for (let i = 0; i < multicalls.length; i++) {
@@ -129,7 +129,9 @@ class PriceFeedRegister extends SDKConstruct {
129
129
  underlying: ADDRESS_0X0
130
130
  }
131
131
  ],
132
- blockNumber: this.sdk.currentBlock
132
+ blockNumber: this.sdk.currentBlock,
133
+ // @ts-expect-error
134
+ gas: this.sdk.gasLimit
133
135
  });
134
136
  this.logger?.debug(
135
137
  `loaded ${result.length} partial updatable price feeds in block ${this.sdk.currentBlock}`
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  BaseError,
3
+ CallExecutionError,
3
4
  ContractFunctionRevertedError,
4
5
  decodeFunctionData,
5
6
  parseAbi
@@ -166,6 +167,9 @@ function extractCallError(result) {
166
167
  if (error instanceof ContractFunctionRevertedError) {
167
168
  return "[" + (error.data?.errorName ?? "reverted") + "]";
168
169
  }
170
+ if (err instanceof CallExecutionError) {
171
+ return `[${err.name}: ${err.details}]`;
172
+ }
169
173
  return err instanceof BaseError ? `[${err.name}]` : "[error]";
170
174
  }
171
175
  class SimulateWithPriceUpdatesError extends BaseError {
@@ -65,6 +65,7 @@ export declare class GearboxSDK<const Plugins extends PluginsMap = {}> {
65
65
  #private;
66
66
  readonly plugins: Plugins;
67
67
  readonly logger?: ILogger;
68
+ gasLimit: bigint | undefined;
68
69
  /**
69
70
  * Interest rate models can be reused across chain (and SDK operates on chain level)
70
71
  * TODO: use whatever interface is necessary for InterestRateModels
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "7.9.0",
3
+ "version": "7.10.0",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",