@gearbox-protocol/sdk 7.9.1 → 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.
- package/dist/cjs/sdk/GearboxSDK.js +1 -0
- package/dist/cjs/sdk/accounts/CreditAccountsService.js +10 -4
- package/dist/cjs/sdk/market/MarketRegister.js +15 -7
- package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +3 -1
- package/dist/cjs/sdk/utils/viem/simulateWithPriceUpdates.js +3 -0
- package/dist/esm/sdk/GearboxSDK.js +1 -0
- package/dist/esm/sdk/accounts/CreditAccountsService.js +10 -4
- package/dist/esm/sdk/market/MarketRegister.js +15 -7
- package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +3 -1
- package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +4 -0
- package/dist/types/sdk/GearboxSDK.d.ts +1 -0
- package/package.json +1 -1
|
@@ -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(
|
|
@@ -81,9 +81,6 @@ class MarketRegister extends import_base.SDKConstruct {
|
|
|
81
81
|
dirtyPools.map((p) => p.pool.address)
|
|
82
82
|
);
|
|
83
83
|
} else if (!skipPriceUpdate && nonDirtyOracles.length) {
|
|
84
|
-
this.#logger?.debug(
|
|
85
|
-
`syncing prices on ${nonDirtyOracles.length} oracles`
|
|
86
|
-
);
|
|
87
84
|
await this.updatePrices(nonDirtyOracles);
|
|
88
85
|
}
|
|
89
86
|
}
|
|
@@ -124,7 +121,8 @@ class MarketRegister extends import_base.SDKConstruct {
|
|
|
124
121
|
args: [this.#marketFilter]
|
|
125
122
|
}
|
|
126
123
|
],
|
|
127
|
-
blockNumber: this.sdk.currentBlock
|
|
124
|
+
blockNumber: this.sdk.currentBlock,
|
|
125
|
+
gas: this.sdk.gasLimit
|
|
128
126
|
}
|
|
129
127
|
);
|
|
130
128
|
markets = resp;
|
|
@@ -134,7 +132,9 @@ class MarketRegister extends import_base.SDKConstruct {
|
|
|
134
132
|
address: marketCompressorAddress,
|
|
135
133
|
functionName: "getMarkets",
|
|
136
134
|
args: [this.#marketFilter],
|
|
137
|
-
blockNumber: this.sdk.currentBlock
|
|
135
|
+
blockNumber: this.sdk.currentBlock,
|
|
136
|
+
// @ts-expect-error
|
|
137
|
+
gas: this.sdk.gasLimit
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
140
|
for (const data of markets) {
|
|
@@ -152,16 +152,24 @@ class MarketRegister extends import_base.SDKConstruct {
|
|
|
152
152
|
* Supports v300 and v310 oracles
|
|
153
153
|
*/
|
|
154
154
|
async updatePrices(oracles) {
|
|
155
|
-
const
|
|
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());
|
|
156
162
|
if (!multicalls.length) {
|
|
157
163
|
return;
|
|
158
164
|
}
|
|
165
|
+
this.#logger?.debug(`syncing prices on ${multicalls.length} oracles`);
|
|
159
166
|
const { txs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs();
|
|
160
167
|
const oraclesStates = await (0, import_viem.simulateWithPriceUpdates)(
|
|
161
168
|
this.provider.publicClient,
|
|
162
169
|
{
|
|
163
170
|
priceUpdates: txs,
|
|
164
|
-
contracts: multicalls.map((mc) => mc.call)
|
|
171
|
+
contracts: multicalls.map((mc) => mc.call),
|
|
172
|
+
gas: this.sdk.gasLimit
|
|
165
173
|
}
|
|
166
174
|
);
|
|
167
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 {
|
|
@@ -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(
|
|
@@ -62,9 +62,6 @@ class MarketRegister extends SDKConstruct {
|
|
|
62
62
|
dirtyPools.map((p) => p.pool.address)
|
|
63
63
|
);
|
|
64
64
|
} else if (!skipPriceUpdate && nonDirtyOracles.length) {
|
|
65
|
-
this.#logger?.debug(
|
|
66
|
-
`syncing prices on ${nonDirtyOracles.length} oracles`
|
|
67
|
-
);
|
|
68
65
|
await this.updatePrices(nonDirtyOracles);
|
|
69
66
|
}
|
|
70
67
|
}
|
|
@@ -105,7 +102,8 @@ class MarketRegister extends SDKConstruct {
|
|
|
105
102
|
args: [this.#marketFilter]
|
|
106
103
|
}
|
|
107
104
|
],
|
|
108
|
-
blockNumber: this.sdk.currentBlock
|
|
105
|
+
blockNumber: this.sdk.currentBlock,
|
|
106
|
+
gas: this.sdk.gasLimit
|
|
109
107
|
}
|
|
110
108
|
);
|
|
111
109
|
markets = resp;
|
|
@@ -115,7 +113,9 @@ class MarketRegister extends SDKConstruct {
|
|
|
115
113
|
address: marketCompressorAddress,
|
|
116
114
|
functionName: "getMarkets",
|
|
117
115
|
args: [this.#marketFilter],
|
|
118
|
-
blockNumber: this.sdk.currentBlock
|
|
116
|
+
blockNumber: this.sdk.currentBlock,
|
|
117
|
+
// @ts-expect-error
|
|
118
|
+
gas: this.sdk.gasLimit
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
121
|
for (const data of markets) {
|
|
@@ -133,16 +133,24 @@ class MarketRegister extends SDKConstruct {
|
|
|
133
133
|
* Supports v300 and v310 oracles
|
|
134
134
|
*/
|
|
135
135
|
async updatePrices(oracles) {
|
|
136
|
-
const
|
|
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());
|
|
137
143
|
if (!multicalls.length) {
|
|
138
144
|
return;
|
|
139
145
|
}
|
|
146
|
+
this.#logger?.debug(`syncing prices on ${multicalls.length} oracles`);
|
|
140
147
|
const { txs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs();
|
|
141
148
|
const oraclesStates = await simulateWithPriceUpdates(
|
|
142
149
|
this.provider.publicClient,
|
|
143
150
|
{
|
|
144
151
|
priceUpdates: txs,
|
|
145
|
-
contracts: multicalls.map((mc) => mc.call)
|
|
152
|
+
contracts: multicalls.map((mc) => mc.call),
|
|
153
|
+
gas: this.sdk.gasLimit
|
|
146
154
|
}
|
|
147
155
|
);
|
|
148
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
|