@gearbox-protocol/sdk 9.17.0 → 10.0.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/dev/AccountOpener.js +2 -5
- package/dist/cjs/dev/createAnvilClient.js +16 -13
- package/dist/cjs/dev/migrateFaucet.js +3 -6
- package/dist/cjs/plugins/accounts-counter/AccountsCounterPlugin.js +1 -1
- package/dist/cjs/plugins/degen-distributors/DegenDistributorsPlugin.js +1 -1
- package/dist/cjs/plugins/pools-history/Pools7DAgoPlugin.js +2 -2
- package/dist/cjs/plugins/zappers/ZappersPlugin.js +2 -2
- package/dist/cjs/sdk/GearboxSDK.js +70 -39
- package/dist/cjs/sdk/accountMigration/AbstractMigrateCreditAccountsService.js +1 -1
- package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +1 -1
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV300.js +1 -1
- package/dist/cjs/sdk/base/BaseContract.js +6 -9
- package/dist/cjs/sdk/base/SDKConstruct.js +4 -7
- package/dist/cjs/sdk/chain/chains.js +1 -1
- package/dist/cjs/sdk/chain/index.js +1 -3
- package/dist/cjs/sdk/core/BotListV3Contract.js +5 -5
- package/dist/cjs/sdk/core/GearStakingV3Contract.js +1 -1
- package/dist/cjs/sdk/core/address-provider/AbstractAddressProviderContract.js +1 -1
- package/dist/cjs/sdk/core/address-provider/AddressProviderV300Contract.js +2 -2
- package/dist/cjs/sdk/core/address-provider/createAddressProvider.js +1 -1
- package/dist/cjs/sdk/gauges/GaugeStakingService.js +1 -1
- package/dist/cjs/sdk/market/MarketConfiguratorContract.js +3 -3
- package/dist/cjs/sdk/market/MarketRegister.js +20 -26
- package/dist/cjs/sdk/market/MarketSuite.js +1 -1
- package/dist/cjs/sdk/market/credit/CreditConfiguratorV300Contract.js +2 -2
- package/dist/cjs/sdk/market/credit/CreditConfiguratorV310Contract.js +2 -2
- package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +1 -1
- package/dist/cjs/sdk/market/oracle/PriceOracleV300Contract.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/AbstractLPPriceFeed.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/BalancerStablePriceFeed.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/BalancerWeightedPriceFeed.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/CurveCryptoPriceFeed.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/CurveStablePriceFeed.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/CurveUSDPriceFeed.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/Erc4626PriceFeed.js +2 -2
- package/dist/cjs/sdk/market/pricefeeds/MellowLRTPriceFeed.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +2 -2
- package/dist/cjs/sdk/market/pricefeeds/WstETHPriceFeed.js +1 -1
- package/dist/cjs/sdk/market/pricefeeds/YearnPriceFeed.js +1 -1
- package/dist/cjs/sdk/plugins/BasePlugin.js +3 -6
- package/dist/cjs/sdk/plugins/V300StalenessPeriodPlugin.js +1 -1
- package/dist/cjs/sdk/router/RouterV300Contract.js +4 -4
- package/dist/esm/dev/AccountOpener.js +3 -6
- package/dist/esm/dev/createAnvilClient.js +21 -14
- package/dist/esm/dev/migrateFaucet.js +4 -7
- package/dist/esm/plugins/accounts-counter/AccountsCounterPlugin.js +1 -1
- package/dist/esm/plugins/degen-distributors/DegenDistributorsPlugin.js +1 -1
- package/dist/esm/plugins/pools-history/Pools7DAgoPlugin.js +2 -2
- package/dist/esm/plugins/zappers/ZappersPlugin.js +2 -2
- package/dist/esm/sdk/GearboxSDK.js +78 -46
- package/dist/esm/sdk/accountMigration/AbstractMigrateCreditAccountsService.js +1 -1
- package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +1 -1
- package/dist/esm/sdk/accounts/CreditAccountsServiceV300.js +1 -1
- package/dist/esm/sdk/base/BaseContract.js +6 -9
- package/dist/esm/sdk/base/SDKConstruct.js +4 -7
- package/dist/esm/sdk/chain/chains.js +1 -1
- package/dist/esm/sdk/chain/index.js +0 -1
- package/dist/esm/sdk/core/BotListV3Contract.js +5 -5
- package/dist/esm/sdk/core/GearStakingV3Contract.js +1 -1
- package/dist/esm/sdk/core/address-provider/AbstractAddressProviderContract.js +1 -1
- package/dist/esm/sdk/core/address-provider/AddressProviderV300Contract.js +2 -2
- package/dist/esm/sdk/core/address-provider/createAddressProvider.js +1 -1
- package/dist/esm/sdk/gauges/GaugeStakingService.js +1 -1
- package/dist/esm/sdk/market/MarketConfiguratorContract.js +3 -3
- package/dist/esm/sdk/market/MarketRegister.js +20 -26
- package/dist/esm/sdk/market/MarketSuite.js +1 -1
- package/dist/esm/sdk/market/credit/CreditConfiguratorV300Contract.js +2 -2
- package/dist/esm/sdk/market/credit/CreditConfiguratorV310Contract.js +2 -2
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +1 -1
- package/dist/esm/sdk/market/oracle/PriceOracleV300Contract.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/AbstractLPPriceFeed.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/BalancerStablePriceFeed.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/BalancerWeightedPriceFeed.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/CurveCryptoPriceFeed.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/CurveStablePriceFeed.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/CurveUSDPriceFeed.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/Erc4626PriceFeed.js +2 -2
- package/dist/esm/sdk/market/pricefeeds/MellowLRTPriceFeed.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +2 -2
- package/dist/esm/sdk/market/pricefeeds/WstETHPriceFeed.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/YearnPriceFeed.js +1 -1
- package/dist/esm/sdk/plugins/BasePlugin.js +3 -6
- package/dist/esm/sdk/plugins/V300StalenessPeriodPlugin.js +1 -1
- package/dist/esm/sdk/router/RouterV300Contract.js +4 -4
- package/dist/types/dev/createAnvilClient.d.ts +1 -0
- package/dist/types/sdk/GearboxSDK.d.ts +51 -6
- package/dist/types/sdk/base/BaseContract.d.ts +0 -2
- package/dist/types/sdk/base/SDKConstruct.d.ts +2 -3
- package/dist/types/sdk/chain/index.d.ts +0 -1
- package/dist/types/sdk/plugins/BasePlugin.d.ts +1 -2
- package/package.json +1 -1
- package/dist/cjs/sdk/chain/Provider.js +0 -86
- package/dist/esm/sdk/chain/Provider.js +0 -61
- package/dist/types/sdk/chain/Provider.d.ts +0 -51
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { parseEventLogs } from "viem";
|
|
2
|
-
import { TokensMeta } from "./base/index.js";
|
|
3
1
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
createPublicClient,
|
|
3
|
+
defineChain,
|
|
4
|
+
fallback,
|
|
5
|
+
http,
|
|
6
|
+
parseEventLogs
|
|
7
|
+
} from "viem";
|
|
8
|
+
import { AddressLabeller, TokensMeta } from "./base/index.js";
|
|
9
|
+
import { detectNetwork, getChain } from "./chain/index.js";
|
|
9
10
|
import {
|
|
10
11
|
ADDRESS_PROVIDER_V310,
|
|
11
12
|
AP_BOT_LIST,
|
|
@@ -34,11 +35,40 @@ import { Hooks } from "./utils/internal/index.js";
|
|
|
34
35
|
import { getLogsSafe } from "./utils/viem/index.js";
|
|
35
36
|
const ERR_NOT_ATTACHED = new Error("Gearbox SDK not attached");
|
|
36
37
|
const STATE_VERSION = 1;
|
|
38
|
+
function createClient(opts, network) {
|
|
39
|
+
let transport;
|
|
40
|
+
if ("client" in opts) {
|
|
41
|
+
return opts.client;
|
|
42
|
+
}
|
|
43
|
+
if ("transport" in opts) {
|
|
44
|
+
transport = opts.transport;
|
|
45
|
+
} else {
|
|
46
|
+
const rpcs = opts.rpcURLs.map(
|
|
47
|
+
(url) => http(url, { timeout: opts.timeout, retryCount: opts.retryCount })
|
|
48
|
+
);
|
|
49
|
+
transport = rpcs.length > 1 ? fallback(rpcs) : rpcs[0];
|
|
50
|
+
}
|
|
51
|
+
const chain = network ? defineChain({
|
|
52
|
+
...getChain(network.networkType),
|
|
53
|
+
id: network.chainId
|
|
54
|
+
}) : void 0;
|
|
55
|
+
return createPublicClient({ transport, chain });
|
|
56
|
+
}
|
|
57
|
+
async function attachClient(options, network) {
|
|
58
|
+
let { chainId, networkType } = network;
|
|
59
|
+
const attachClient2 = createClient(options);
|
|
60
|
+
if (!networkType) {
|
|
61
|
+
networkType = await detectNetwork(attachClient2);
|
|
62
|
+
}
|
|
63
|
+
if (!chainId) {
|
|
64
|
+
chainId = await attachClient2.getChainId();
|
|
65
|
+
}
|
|
66
|
+
return createClient(options, { networkType, chainId });
|
|
67
|
+
}
|
|
37
68
|
class GearboxSDK {
|
|
38
69
|
#hooks = new Hooks();
|
|
39
|
-
// Represents chain object
|
|
40
|
-
#provider;
|
|
41
70
|
plugins;
|
|
71
|
+
#client;
|
|
42
72
|
// Block which was use for data query
|
|
43
73
|
#currentBlock;
|
|
44
74
|
#timestamp;
|
|
@@ -51,6 +81,7 @@ class GearboxSDK {
|
|
|
51
81
|
#priceFeeds;
|
|
52
82
|
logger;
|
|
53
83
|
gasLimit;
|
|
84
|
+
addressLabels = new AddressLabeller();
|
|
54
85
|
/**
|
|
55
86
|
* Interest rate models can be reused across chain (and SDK operates on chain level)
|
|
56
87
|
* TODO: use whatever interface is necessary for InterestRateModels
|
|
@@ -86,27 +117,14 @@ class GearboxSDK {
|
|
|
86
117
|
strictContractTypes,
|
|
87
118
|
gasLimit
|
|
88
119
|
} = options;
|
|
89
|
-
let {
|
|
90
|
-
const
|
|
91
|
-
if (!networkType) {
|
|
92
|
-
networkType = await detectNetwork(attachClient);
|
|
93
|
-
}
|
|
94
|
-
if (!chainId) {
|
|
95
|
-
chainId = await attachClient.getChainId();
|
|
96
|
-
}
|
|
120
|
+
let { addressProvider } = options;
|
|
121
|
+
const client = await attachClient(options, options);
|
|
97
122
|
if (!addressProvider) {
|
|
98
123
|
addressProvider = ADDRESS_PROVIDER_V310;
|
|
99
124
|
}
|
|
100
|
-
const marketConfigurators = mcs ?? TypedObjectUtils.keys(
|
|
101
|
-
const provider = new Provider({
|
|
102
|
-
...options,
|
|
103
|
-
transport,
|
|
104
|
-
// pass transport to avoid creating a new transport in provider
|
|
105
|
-
chainId,
|
|
106
|
-
networkType
|
|
107
|
-
});
|
|
125
|
+
const marketConfigurators = mcs ?? TypedObjectUtils.keys(client.chain.defaultMarketConfigurators);
|
|
108
126
|
return new GearboxSDK({
|
|
109
|
-
|
|
127
|
+
client,
|
|
110
128
|
logger,
|
|
111
129
|
plugins,
|
|
112
130
|
strictContractTypes,
|
|
@@ -123,13 +141,12 @@ class GearboxSDK {
|
|
|
123
141
|
}
|
|
124
142
|
static hydrate(options, state) {
|
|
125
143
|
const { logger, plugins, strictContractTypes, gasLimit, ...rest } = options;
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
chainId: state.chainId
|
|
129
|
-
networkType: state.network
|
|
144
|
+
const client = createClient(options, {
|
|
145
|
+
networkType: state.network,
|
|
146
|
+
chainId: state.chainId
|
|
130
147
|
});
|
|
131
148
|
return new GearboxSDK({
|
|
132
|
-
|
|
149
|
+
client,
|
|
133
150
|
plugins,
|
|
134
151
|
logger,
|
|
135
152
|
strictContractTypes,
|
|
@@ -137,10 +154,10 @@ class GearboxSDK {
|
|
|
137
154
|
}).#hydrate(rest, state);
|
|
138
155
|
}
|
|
139
156
|
constructor(options) {
|
|
140
|
-
this.#provider = options.provider;
|
|
141
157
|
this.logger = options.logger;
|
|
142
158
|
this.strictContractTypes = options.strictContractTypes ?? false;
|
|
143
159
|
this.plugins = options.plugins ?? {};
|
|
160
|
+
this.#client = options.client;
|
|
144
161
|
for (const plugin of Object.values(this.plugins)) {
|
|
145
162
|
plugin.sdk = this;
|
|
146
163
|
}
|
|
@@ -161,8 +178,8 @@ class GearboxSDK {
|
|
|
161
178
|
const re = this.#attachConfig ? "re" : "";
|
|
162
179
|
this.logger?.info(
|
|
163
180
|
{
|
|
164
|
-
networkType: this.
|
|
165
|
-
chainId: this.
|
|
181
|
+
networkType: this.networkType,
|
|
182
|
+
chainId: this.chainId,
|
|
166
183
|
addressProvider,
|
|
167
184
|
marketConfigurators,
|
|
168
185
|
blockNumber,
|
|
@@ -182,7 +199,7 @@ class GearboxSDK {
|
|
|
182
199
|
}
|
|
183
200
|
this.#attachConfig = opts;
|
|
184
201
|
const time = Date.now();
|
|
185
|
-
const block = await this.
|
|
202
|
+
const block = await this.client.getBlock(
|
|
186
203
|
blockNumber ? { blockNumber: BigInt(blockNumber) } : {
|
|
187
204
|
blockTag: "latest"
|
|
188
205
|
}
|
|
@@ -233,9 +250,7 @@ class GearboxSDK {
|
|
|
233
250
|
}
|
|
234
251
|
const re = this.#attachConfig ? "re" : "";
|
|
235
252
|
this.logger?.info(
|
|
236
|
-
{
|
|
237
|
-
networkType: this.provider.networkType
|
|
238
|
-
},
|
|
253
|
+
{ networkType: this.networkType },
|
|
239
254
|
`${re}hydrating sdk state`
|
|
240
255
|
);
|
|
241
256
|
this.#currentBlock = state.currentBlock;
|
|
@@ -304,6 +319,26 @@ class GearboxSDK {
|
|
|
304
319
|
timestamp: state.timestamp
|
|
305
320
|
});
|
|
306
321
|
}
|
|
322
|
+
get client() {
|
|
323
|
+
return this.#client;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Replaces client inflight
|
|
327
|
+
* You're responsible for all inconsistencies between new and old client
|
|
328
|
+
* @param options
|
|
329
|
+
*/
|
|
330
|
+
replaceClient(options, network) {
|
|
331
|
+
this.#client = createClient(options, network);
|
|
332
|
+
}
|
|
333
|
+
get networkType() {
|
|
334
|
+
return this.client.chain.network;
|
|
335
|
+
}
|
|
336
|
+
get chain() {
|
|
337
|
+
return this.client.chain;
|
|
338
|
+
}
|
|
339
|
+
get chainId() {
|
|
340
|
+
return this.client.chain.id;
|
|
341
|
+
}
|
|
307
342
|
/**
|
|
308
343
|
* Converts contract call into some human-friendly string
|
|
309
344
|
* This method is safe and should not throw
|
|
@@ -374,8 +409,8 @@ class GearboxSDK {
|
|
|
374
409
|
get state() {
|
|
375
410
|
return {
|
|
376
411
|
version: STATE_VERSION,
|
|
377
|
-
network: this.
|
|
378
|
-
chainId: this.
|
|
412
|
+
network: this.networkType,
|
|
413
|
+
chainId: this.chainId,
|
|
379
414
|
currentBlock: this.currentBlock,
|
|
380
415
|
timestamp: this.timestamp,
|
|
381
416
|
addressProvider: this.addressProvider.state,
|
|
@@ -405,7 +440,7 @@ class GearboxSDK {
|
|
|
405
440
|
);
|
|
406
441
|
}
|
|
407
442
|
if (!blockNumber || !timestamp) {
|
|
408
|
-
const block = await this.
|
|
443
|
+
const block = await this.client.getBlock({
|
|
409
444
|
blockTag: "latest"
|
|
410
445
|
});
|
|
411
446
|
blockNumber = block.number;
|
|
@@ -437,7 +472,7 @@ class GearboxSDK {
|
|
|
437
472
|
this.logger?.debug(
|
|
438
473
|
`getting logs from ${watchAddresses.length} addresses in [${fromBlock}:${blockNumber}]`
|
|
439
474
|
);
|
|
440
|
-
const logs = await getLogsSafe(this.
|
|
475
|
+
const logs = await getLogsSafe(this.client, {
|
|
441
476
|
fromBlock,
|
|
442
477
|
toBlock: blockNumber,
|
|
443
478
|
address: watchAddresses
|
|
@@ -494,9 +529,6 @@ class GearboxSDK {
|
|
|
494
529
|
}
|
|
495
530
|
return success;
|
|
496
531
|
}
|
|
497
|
-
get provider() {
|
|
498
|
-
return this.#provider;
|
|
499
|
-
}
|
|
500
532
|
get currentBlock() {
|
|
501
533
|
if (this.#currentBlock === void 0) {
|
|
502
534
|
throw ERR_NOT_ATTACHED;
|
|
@@ -591,7 +623,7 @@ class GearboxSDK {
|
|
|
591
623
|
* @returns
|
|
592
624
|
*/
|
|
593
625
|
labelAddress(address) {
|
|
594
|
-
return this.
|
|
626
|
+
return this.addressLabels.get(address);
|
|
595
627
|
}
|
|
596
628
|
}
|
|
597
629
|
export {
|
|
@@ -57,7 +57,7 @@ class AbstractMigrateCreditAccountsService extends SDKConstruct {
|
|
|
57
57
|
address: previewerAddress,
|
|
58
58
|
abi: accountMigratorPreviewerV310Abi,
|
|
59
59
|
client: {
|
|
60
|
-
public: this.sdk.
|
|
60
|
+
public: this.sdk.client
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
63
|
const { result } = await contract.simulate.previewMigration([
|
|
@@ -216,7 +216,7 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
216
216
|
}
|
|
217
217
|
async getActiveMigrationBots(accountsToCheck) {
|
|
218
218
|
const migrationBot = AbstractMigrateCreditAccountsService.getMigrationBotAddress(
|
|
219
|
-
this.sdk.
|
|
219
|
+
this.sdk.chainId
|
|
220
220
|
);
|
|
221
221
|
if (migrationBot) {
|
|
222
222
|
const result = await this.client.multicall({
|
|
@@ -174,7 +174,7 @@ class CreditAccountServiceV300 extends AbstractCreditAccountService {
|
|
|
174
174
|
* @returns
|
|
175
175
|
*/
|
|
176
176
|
#prepareUnwrapAndWithdrawCallsV3(assets, claim, withdrawAll, creditManager) {
|
|
177
|
-
const network = this.sdk.
|
|
177
|
+
const network = this.sdk.networkType;
|
|
178
178
|
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
179
179
|
const cmAdapters = suite.creditManager.adapters.values().reduce((acc, a) => {
|
|
180
180
|
const contractLc = a.targetContract.toLowerCase();
|
|
@@ -26,7 +26,7 @@ class BaseContract extends SDKConstruct {
|
|
|
26
26
|
// add exceptions for better error decoding
|
|
27
27
|
abi: [...this.abi, ...errorAbis],
|
|
28
28
|
client: {
|
|
29
|
-
public: sdk.
|
|
29
|
+
public: sdk.client
|
|
30
30
|
}
|
|
31
31
|
});
|
|
32
32
|
this.version = Number(args.version || 0);
|
|
@@ -46,7 +46,7 @@ class BaseContract extends SDKConstruct {
|
|
|
46
46
|
throw new Error(`Address can't be changed, currently: ${this.#address}`);
|
|
47
47
|
}
|
|
48
48
|
this.#address = getAddress(address);
|
|
49
|
-
this.addressLabels.set(address, this.#name);
|
|
49
|
+
this.sdk.addressLabels.set(address, this.#name);
|
|
50
50
|
}
|
|
51
51
|
get name() {
|
|
52
52
|
return this.#name;
|
|
@@ -54,12 +54,12 @@ class BaseContract extends SDKConstruct {
|
|
|
54
54
|
set name(name) {
|
|
55
55
|
this.#name = name;
|
|
56
56
|
if (this.#address !== ADDRESS_0X0) {
|
|
57
|
-
this.addressLabels.set(this.#address, name);
|
|
57
|
+
this.sdk.addressLabels.set(this.#address, name);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
stateHuman(_ = true) {
|
|
61
61
|
return {
|
|
62
|
-
address: this.sdk.
|
|
62
|
+
address: this.sdk.labelAddress(this.address),
|
|
63
63
|
version: this.version,
|
|
64
64
|
contractType: this.contractType
|
|
65
65
|
};
|
|
@@ -106,7 +106,7 @@ class BaseContract extends SDKConstruct {
|
|
|
106
106
|
});
|
|
107
107
|
} else if (Array.isArray(decoded.args)) {
|
|
108
108
|
paramsHuman = decoded.args.map((value, i) => {
|
|
109
|
-
return `${abiItem.inputs[i].name}: ${abiItem.inputs[i].type === "address" ? this.
|
|
109
|
+
return `${abiItem.inputs[i].name}: ${abiItem.inputs[i].type === "address" ? this.labelAddress(value) : abiItem.inputs[i].type.startsWith("tuple") ? json_stringify(value) : value}`;
|
|
110
110
|
});
|
|
111
111
|
} else {
|
|
112
112
|
paramsHuman = Object.entries(decoded.args || {}).map(
|
|
@@ -132,7 +132,7 @@ class BaseContract extends SDKConstruct {
|
|
|
132
132
|
}
|
|
133
133
|
async getVersion() {
|
|
134
134
|
this.version = Number(
|
|
135
|
-
await this.sdk.
|
|
135
|
+
await this.sdk.client.readContract({
|
|
136
136
|
abi: iVersionAbi,
|
|
137
137
|
functionName: "version",
|
|
138
138
|
address: this.address
|
|
@@ -153,9 +153,6 @@ class BaseContract extends SDKConstruct {
|
|
|
153
153
|
tx.description = argsDescription || this.parseFunctionData(tx.callData);
|
|
154
154
|
return tx;
|
|
155
155
|
}
|
|
156
|
-
get addressLabels() {
|
|
157
|
-
return this.sdk.provider.addressLabels;
|
|
158
|
-
}
|
|
159
156
|
}
|
|
160
157
|
export {
|
|
161
158
|
BaseContract
|
|
@@ -7,14 +7,11 @@ class SDKConstruct {
|
|
|
7
7
|
constructor(sdk) {
|
|
8
8
|
this.sdk = sdk;
|
|
9
9
|
}
|
|
10
|
-
get
|
|
11
|
-
return this.sdk.
|
|
12
|
-
}
|
|
13
|
-
get network() {
|
|
14
|
-
return this.provider.networkType;
|
|
10
|
+
get networkType() {
|
|
11
|
+
return this.sdk.networkType;
|
|
15
12
|
}
|
|
16
13
|
get client() {
|
|
17
|
-
return this.
|
|
14
|
+
return this.sdk.client;
|
|
18
15
|
}
|
|
19
16
|
/**
|
|
20
17
|
* Indicates that contract state needs to be updated
|
|
@@ -26,7 +23,7 @@ class SDKConstruct {
|
|
|
26
23
|
this.#dirty = value;
|
|
27
24
|
}
|
|
28
25
|
labelAddress(address) {
|
|
29
|
-
return this.
|
|
26
|
+
return this.sdk.labelAddress(address);
|
|
30
27
|
}
|
|
31
28
|
/**
|
|
32
29
|
* Returns list of addresses that should be watched for events to sync state
|
|
@@ -301,7 +301,7 @@ function getChain(chainIdOrNetworkType) {
|
|
|
301
301
|
const network = typeof chainIdOrNetworkType === "string" ? chainIdOrNetworkType : getNetworkType(Number(chainIdOrNetworkType));
|
|
302
302
|
const chain = chains[network];
|
|
303
303
|
if (!chain) {
|
|
304
|
-
throw new Error(
|
|
304
|
+
throw new Error(`Unsupported network: ${network}`);
|
|
305
305
|
}
|
|
306
306
|
return chain;
|
|
307
307
|
}
|
|
@@ -7,19 +7,19 @@ class BotListContract extends BaseContract {
|
|
|
7
7
|
#currentBlock;
|
|
8
8
|
constructor(sdk, address) {
|
|
9
9
|
super(sdk, { addr: address, name: "BotListV3", abi });
|
|
10
|
-
this.#currentBlock = sdk.
|
|
10
|
+
this.#currentBlock = sdk.chain.firstBlock ?? 0n;
|
|
11
11
|
}
|
|
12
12
|
parseFunctionParams(params) {
|
|
13
13
|
switch (params.functionName) {
|
|
14
14
|
case "setCreditManagerApprovedStatus": {
|
|
15
15
|
const [creditManager, status] = params.args;
|
|
16
|
-
return [this.
|
|
16
|
+
return [this.labelAddress(creditManager), `${status}`];
|
|
17
17
|
}
|
|
18
18
|
case "setBotSpecialPermissions": {
|
|
19
19
|
const [bot, creditManager, permissions] = params.args;
|
|
20
20
|
return [
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
21
|
+
this.labelAddress(bot),
|
|
22
|
+
this.labelAddress(creditManager),
|
|
23
23
|
botPermissionsToString(permissions)
|
|
24
24
|
];
|
|
25
25
|
}
|
|
@@ -28,7 +28,7 @@ class BotListContract extends BaseContract {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
async syncState(toBlock) {
|
|
31
|
-
const logs = await this.
|
|
31
|
+
const logs = await this.client.getContractEvents({
|
|
32
32
|
address: this.address,
|
|
33
33
|
abi: this.abi,
|
|
34
34
|
fromBlock: this.#currentBlock,
|
|
@@ -10,7 +10,7 @@ class GearStakingContract extends BaseContract {
|
|
|
10
10
|
switch (params.functionName) {
|
|
11
11
|
case "setVotingContractStatus": {
|
|
12
12
|
const [address, status] = params.args;
|
|
13
|
-
return [this.
|
|
13
|
+
return [this.labelAddress(address), VotingContractStatus[status]];
|
|
14
14
|
}
|
|
15
15
|
default:
|
|
16
16
|
return void 0;
|
|
@@ -52,11 +52,11 @@ class AddressProviderV300Contract extends AbstractAddressProviderContract {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
async syncState(blockNumber) {
|
|
55
|
-
const fromBlock = this.sdk.
|
|
55
|
+
const fromBlock = this.sdk.chain.firstBlock;
|
|
56
56
|
this.logger?.debug(
|
|
57
57
|
`loading events from block ${fromBlock} to ${blockNumber}`
|
|
58
58
|
);
|
|
59
|
-
const events = await getLogsSafe(this.sdk.
|
|
59
|
+
const events = await getLogsSafe(this.sdk.client, {
|
|
60
60
|
address: this.address,
|
|
61
61
|
event: getAbiItem({ abi: this.abi, name: "SetAddress" }),
|
|
62
62
|
fromBlock,
|
|
@@ -3,7 +3,7 @@ import { isV300, isV310 } from "../../constants/index.js";
|
|
|
3
3
|
import { AddressProviderV300Contract } from "./AddressProviderV300Contract.js";
|
|
4
4
|
import { AddressProviderV310Contract } from "./AddressProviderV310Contract.js";
|
|
5
5
|
async function createAddressProvider(sdk, address) {
|
|
6
|
-
const v = await sdk.
|
|
6
|
+
const v = await sdk.client.readContract({
|
|
7
7
|
address,
|
|
8
8
|
abi: iVersionAbi,
|
|
9
9
|
functionName: "version"
|
|
@@ -24,7 +24,7 @@ class GaugeStakingService extends SDKConstruct {
|
|
|
24
24
|
if (!gearStaking) {
|
|
25
25
|
throw new Error("gear staking contract is not set");
|
|
26
26
|
}
|
|
27
|
-
const [gauges, availableBalance, totalBalance, withdrawableAmounts, epoch] = await this.
|
|
27
|
+
const [gauges, availableBalance, totalBalance, withdrawableAmounts, epoch] = await this.client.multicall({
|
|
28
28
|
allowFailure: false,
|
|
29
29
|
contracts: [
|
|
30
30
|
{
|
|
@@ -16,18 +16,18 @@ class MarketConfiguratorContract extends BaseContract {
|
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
async loadCuratorName() {
|
|
19
|
-
this.#curatorName = await this.sdk.
|
|
19
|
+
this.#curatorName = await this.sdk.client.readContract({
|
|
20
20
|
address: this.address,
|
|
21
21
|
abi: this.abi,
|
|
22
22
|
functionName: "curatorName"
|
|
23
23
|
});
|
|
24
|
-
this.sdk.
|
|
24
|
+
this.sdk.addressLabels.set(
|
|
25
25
|
this.address,
|
|
26
26
|
`Market configurator ${this.#curatorName}`
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
29
|
async getPeripheryContract(contract) {
|
|
30
|
-
const resp = await this.sdk.
|
|
30
|
+
const resp = await this.sdk.client.readContract({
|
|
31
31
|
address: this.address,
|
|
32
32
|
abi: this.abi,
|
|
33
33
|
functionName: "getPeripheryContracts",
|
|
@@ -112,25 +112,22 @@ class MarketRegister extends SDKConstruct {
|
|
|
112
112
|
);
|
|
113
113
|
let markets = [];
|
|
114
114
|
if (txs.length) {
|
|
115
|
-
const [resp] = await simulateWithPriceUpdates(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
gas: this.sdk.gasLimit
|
|
129
|
-
}
|
|
130
|
-
);
|
|
115
|
+
const [resp] = await simulateWithPriceUpdates(this.client, {
|
|
116
|
+
priceUpdates: txs,
|
|
117
|
+
contracts: [
|
|
118
|
+
{
|
|
119
|
+
abi: marketCompressorAbi,
|
|
120
|
+
address: marketCompressorAddress,
|
|
121
|
+
functionName: "getMarkets",
|
|
122
|
+
args: [this.marketFilter]
|
|
123
|
+
}
|
|
124
|
+
],
|
|
125
|
+
blockNumber: this.sdk.currentBlock,
|
|
126
|
+
gas: this.sdk.gasLimit
|
|
127
|
+
});
|
|
131
128
|
markets = resp;
|
|
132
129
|
} else {
|
|
133
|
-
markets = await this.
|
|
130
|
+
markets = await this.client.readContract({
|
|
134
131
|
abi: marketCompressorAbi,
|
|
135
132
|
address: marketCompressorAddress,
|
|
136
133
|
functionName: "getMarkets",
|
|
@@ -171,15 +168,12 @@ class MarketRegister extends SDKConstruct {
|
|
|
171
168
|
}
|
|
172
169
|
this.#logger?.debug(`syncing prices on ${multicalls.length} oracles`);
|
|
173
170
|
const { txs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs();
|
|
174
|
-
const oraclesStates = await simulateWithPriceUpdates(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
blockNumber: this.sdk.currentBlock
|
|
181
|
-
}
|
|
182
|
-
);
|
|
171
|
+
const oraclesStates = await simulateWithPriceUpdates(this.client, {
|
|
172
|
+
priceUpdates: txs,
|
|
173
|
+
contracts: multicalls.map((mc) => mc.call),
|
|
174
|
+
gas: this.sdk.gasLimit,
|
|
175
|
+
blockNumber: this.sdk.currentBlock
|
|
176
|
+
});
|
|
183
177
|
for (let i = 0; i < multicalls.length; i++) {
|
|
184
178
|
const handler = multicalls[i].onResult;
|
|
185
179
|
const result = oraclesStates[i];
|
|
@@ -28,7 +28,7 @@ class MarketSuite extends SDKConstruct {
|
|
|
28
28
|
this.treasury = marketData.treasury;
|
|
29
29
|
for (const t of marketData.tokens) {
|
|
30
30
|
sdk.tokensMeta.upsert(t.addr, t);
|
|
31
|
-
sdk.
|
|
31
|
+
sdk.addressLabels.set(t.addr, t.symbol);
|
|
32
32
|
}
|
|
33
33
|
this.pool = new PoolSuite(sdk, marketData);
|
|
34
34
|
for (let i = 0; i < marketData.creditManagers.length; i++) {
|
|
@@ -48,9 +48,9 @@ class CreditConfiguratorV300Contract extends BaseContract {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
async checkRamps() {
|
|
51
|
-
let fromBlock = this.sdk.currentBlock - RAMP_DURATION_BY_NETWORK[this.sdk.
|
|
51
|
+
let fromBlock = this.sdk.currentBlock - RAMP_DURATION_BY_NETWORK[this.sdk.networkType];
|
|
52
52
|
fromBlock = fromBlock < 0n ? 0n : fromBlock;
|
|
53
|
-
const logs = await this.
|
|
53
|
+
const logs = await this.client.getContractEvents({
|
|
54
54
|
address: this.address,
|
|
55
55
|
abi: this.abi,
|
|
56
56
|
fromBlock,
|
|
@@ -35,9 +35,9 @@ class CreditConfiguratorV310Contract extends BaseContract {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
async checkRamps() {
|
|
38
|
-
let fromBlock = this.sdk.currentBlock - RAMP_DURATION_BY_NETWORK[this.sdk.
|
|
38
|
+
let fromBlock = this.sdk.currentBlock - RAMP_DURATION_BY_NETWORK[this.sdk.networkType];
|
|
39
39
|
fromBlock = fromBlock < 0n ? 0n : fromBlock;
|
|
40
|
-
const logs = await this.
|
|
40
|
+
const logs = await this.client.getContractEvents({
|
|
41
41
|
address: this.address,
|
|
42
42
|
abi: this.abi,
|
|
43
43
|
fromBlock,
|
|
@@ -234,7 +234,7 @@ class PriceOracleBaseContract extends BaseContract {
|
|
|
234
234
|
this.dirty = false;
|
|
235
235
|
}
|
|
236
236
|
#labelPriceFeed(address, usage, token) {
|
|
237
|
-
this.sdk.
|
|
237
|
+
this.sdk.addressLabels.set(address, (oldLabel) => {
|
|
238
238
|
const symbol = this.sdk.tokensMeta.symbol(token);
|
|
239
239
|
let pricefeedTag = `${symbol}.${usage}`;
|
|
240
240
|
if (oldLabel) {
|
|
@@ -92,7 +92,7 @@ class PriceOracleV300Contract extends PriceOracleBaseContract {
|
|
|
92
92
|
return [token, reserve];
|
|
93
93
|
}
|
|
94
94
|
const tickers = Object.values(
|
|
95
|
-
tickerInfoTokensByNetwork[this.sdk.
|
|
95
|
+
tickerInfoTokensByNetwork[this.sdk.networkType]
|
|
96
96
|
).flat();
|
|
97
97
|
const ticker = tickers.find(
|
|
98
98
|
(t) => t.priceFeed.toLowerCase() === priceFeed.toLowerCase()
|
|
@@ -70,7 +70,7 @@ class AbstractLPPriceFeedContract extends AbstractPriceFeedContract {
|
|
|
70
70
|
return lowerBound;
|
|
71
71
|
}
|
|
72
72
|
async currentLowerBound() {
|
|
73
|
-
return await this.sdk.
|
|
73
|
+
return await this.sdk.client.readContract({
|
|
74
74
|
abi: ilpPriceFeedAbi,
|
|
75
75
|
address: this.address,
|
|
76
76
|
functionName: "lowerBound"
|
|
@@ -12,7 +12,7 @@ class BalancerStablePriceFeedContract extends AbstractLPPriceFeedContract {
|
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
async getValue() {
|
|
15
|
-
return await this.sdk.
|
|
15
|
+
return await this.sdk.client.readContract({
|
|
16
16
|
abi: iBalancerStablePoolAbi,
|
|
17
17
|
address: this.lpContract,
|
|
18
18
|
functionName: "getRate"
|
|
@@ -32,7 +32,7 @@ class BalancerWeightedPriceFeedContract extends AbstractLPPriceFeedContract {
|
|
|
32
32
|
this.weights = decoded[3];
|
|
33
33
|
}
|
|
34
34
|
async getValue() {
|
|
35
|
-
return await this.sdk.
|
|
35
|
+
return await this.sdk.client.readContract({
|
|
36
36
|
abi: iBalancerWeightedPoolAbi,
|
|
37
37
|
address: this.lpContract,
|
|
38
38
|
functionName: "getRate"
|
|
@@ -9,7 +9,7 @@ class CurveCryptoPriceFeedContract extends AbstractLPPriceFeedContract {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
async getValue() {
|
|
12
|
-
return await this.sdk.
|
|
12
|
+
return await this.sdk.client.readContract({
|
|
13
13
|
abi: iCurvePoolAbi,
|
|
14
14
|
address: this.lpContract,
|
|
15
15
|
functionName: "get_virtual_price"
|
|
@@ -9,7 +9,7 @@ class CurveStablePriceFeedContract extends AbstractLPPriceFeedContract {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
async getValue() {
|
|
12
|
-
return await this.sdk.
|
|
12
|
+
return await this.sdk.client.readContract({
|
|
13
13
|
abi: iCurvePoolAbi,
|
|
14
14
|
address: this.lpContract,
|
|
15
15
|
functionName: "get_virtual_price"
|
|
@@ -9,7 +9,7 @@ class CurveUSDPriceFeedContract extends AbstractLPPriceFeedContract {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
async getValue() {
|
|
12
|
-
return await this.sdk.
|
|
12
|
+
return await this.sdk.client.readContract({
|
|
13
13
|
abi: iCurvePoolAbi,
|
|
14
14
|
address: this.lpContract,
|
|
15
15
|
functionName: "get_virtual_price"
|