@gearbox-protocol/sdk 12.3.1 → 12.3.3
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/plugins/degen-distributors/DegenDistributorsPlugin.js +12 -6
- package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +69 -37
- package/dist/cjs/sdk/market/MarketConfiguratorContract.js +14 -0
- package/dist/esm/plugins/degen-distributors/DegenDistributorsPlugin.js +12 -6
- package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +69 -37
- package/dist/esm/sdk/market/MarketConfiguratorContract.js +14 -0
- package/dist/types/sdk/market/MarketConfiguratorContract.d.ts +9 -0
- package/package.json +1 -1
|
@@ -22,6 +22,7 @@ __export(DegenDistributorsPlugin_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(DegenDistributorsPlugin_exports);
|
|
24
24
|
var import_sdk = require("../../sdk/index.js");
|
|
25
|
+
var import_MarketConfiguratorContract = require("../../sdk/market/MarketConfiguratorContract.js");
|
|
25
26
|
const MAP_LABEL = "degenDistributors";
|
|
26
27
|
class DegenDistributorsPlugin extends import_sdk.BasePlugin {
|
|
27
28
|
#distributors;
|
|
@@ -39,12 +40,15 @@ class DegenDistributorsPlugin extends import_sdk.BasePlugin {
|
|
|
39
40
|
this.sdk.logger?.debug(
|
|
40
41
|
`loading degen distributors for ${this.sdk.networkType}`
|
|
41
42
|
);
|
|
42
|
-
const distributors = await
|
|
43
|
-
|
|
43
|
+
const distributors = await import_MarketConfiguratorContract.MarketConfiguratorContract.getPeripheryContractBatch(
|
|
44
|
+
Object.values(configurators),
|
|
45
|
+
this.sdk.client,
|
|
46
|
+
"DEGEN_DISTRIBUTOR"
|
|
44
47
|
);
|
|
45
48
|
const distributorByConfigurator = configurators.reduce((acc, cfg, index) => {
|
|
46
49
|
const cfgLC = cfg.address.toLowerCase();
|
|
47
|
-
|
|
50
|
+
const distributor = distributors[index];
|
|
51
|
+
acc[cfgLC] = distributor;
|
|
48
52
|
return acc;
|
|
49
53
|
}, {});
|
|
50
54
|
this.#distributors = new import_sdk.AddressMap(void 0, MAP_LABEL);
|
|
@@ -53,11 +57,13 @@ class DegenDistributorsPlugin extends import_sdk.BasePlugin {
|
|
|
53
57
|
const cfg = m.configurator.address;
|
|
54
58
|
const cfgLC = cfg.toLowerCase();
|
|
55
59
|
const r = distributorByConfigurator?.[cfgLC];
|
|
56
|
-
if (r.status === "
|
|
57
|
-
this.#distributors?.upsert(pool, r.
|
|
60
|
+
if (r.status === "success" && r.result.length > 0) {
|
|
61
|
+
this.#distributors?.upsert(pool, r.result[0]);
|
|
58
62
|
} else {
|
|
59
63
|
this.sdk.logger?.error(
|
|
60
|
-
`failed to load degen distributor for market configurator ${this.labelAddress(
|
|
64
|
+
`failed to load degen distributor for market configurator ${this.labelAddress(
|
|
65
|
+
cfg
|
|
66
|
+
)} and pool ${this.labelAddress(pool)}: ${r.error}`
|
|
61
67
|
);
|
|
62
68
|
}
|
|
63
69
|
});
|
|
@@ -212,9 +212,9 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
212
212
|
* @returns call result of getConnectedBots for each credit account
|
|
213
213
|
*/
|
|
214
214
|
async getConnectedBots(accountsToCheck, legacyMigrationBot, additionalBots) {
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
215
|
+
const allResp = await this.client.multicall({
|
|
216
|
+
contracts: [
|
|
217
|
+
...accountsToCheck.map((o) => {
|
|
218
218
|
const pool = this.sdk.marketRegister.findByCreditManager(
|
|
219
219
|
o.creditManager
|
|
220
220
|
);
|
|
@@ -225,32 +225,71 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
225
225
|
args: [pool.configurator.address, o.creditAccount]
|
|
226
226
|
};
|
|
227
227
|
}),
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
]);
|
|
233
|
-
return {
|
|
234
|
-
legacy: resp,
|
|
235
|
-
additionalBots: additional,
|
|
236
|
-
legacyMigration: migration
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
async getActiveBots(accountsToCheck, bots) {
|
|
240
|
-
const result = await this.client.multicall({
|
|
241
|
-
contracts: accountsToCheck.flatMap((ca) => {
|
|
242
|
-
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
243
|
-
return bots.map((bot) => {
|
|
228
|
+
...legacyMigrationBot ? accountsToCheck.map((ca) => {
|
|
229
|
+
const cm = this.sdk.marketRegister.findCreditManager(
|
|
230
|
+
ca.creditManager
|
|
231
|
+
);
|
|
244
232
|
return {
|
|
245
233
|
abi: (0, import_constants.isV300)(cm.creditFacade.version) ? import_v300.iBotListV300Abi : import_generated.iBotListV310Abi,
|
|
246
234
|
address: cm.creditFacade.botList,
|
|
247
235
|
functionName: "getBotStatus",
|
|
248
|
-
args: (0, import_constants.isV300)(cm.creditFacade.version) ? [
|
|
236
|
+
args: (0, import_constants.isV300)(cm.creditFacade.version) ? [legacyMigrationBot, ca.creditManager, ca.creditAccount] : [legacyMigrationBot, ca.creditAccount]
|
|
249
237
|
};
|
|
250
|
-
})
|
|
251
|
-
|
|
238
|
+
}) : [],
|
|
239
|
+
...accountsToCheck.flatMap((ca) => {
|
|
240
|
+
const cm = this.sdk.marketRegister.findCreditManager(
|
|
241
|
+
ca.creditManager
|
|
242
|
+
);
|
|
243
|
+
return additionalBots.map((bot) => {
|
|
244
|
+
return {
|
|
245
|
+
abi: (0, import_constants.isV300)(cm.creditFacade.version) ? import_v300.iBotListV300Abi : import_generated.iBotListV310Abi,
|
|
246
|
+
address: cm.creditFacade.botList,
|
|
247
|
+
functionName: "getBotStatus",
|
|
248
|
+
args: (0, import_constants.isV300)(cm.creditFacade.version) ? [bot, ca.creditManager, ca.creditAccount] : [bot, ca.creditAccount]
|
|
249
|
+
};
|
|
250
|
+
});
|
|
251
|
+
})
|
|
252
|
+
],
|
|
252
253
|
allowFailure: true
|
|
253
254
|
});
|
|
255
|
+
const legacyStart = 0;
|
|
256
|
+
const legacyEnd = accountsToCheck.length;
|
|
257
|
+
const legacy = allResp.slice(
|
|
258
|
+
legacyStart,
|
|
259
|
+
legacyEnd
|
|
260
|
+
);
|
|
261
|
+
const migrationStart = legacyEnd;
|
|
262
|
+
const migrationEnd = legacyMigrationBot ? migrationStart + accountsToCheck.length : migrationStart;
|
|
263
|
+
const migrationResp = allResp.slice(
|
|
264
|
+
migrationStart,
|
|
265
|
+
migrationEnd
|
|
266
|
+
);
|
|
267
|
+
const additionalStart = migrationEnd;
|
|
268
|
+
const additionalResp = allResp.slice(
|
|
269
|
+
additionalStart
|
|
270
|
+
);
|
|
271
|
+
return {
|
|
272
|
+
legacy,
|
|
273
|
+
additionalBots: this.getActiveBots(
|
|
274
|
+
accountsToCheck,
|
|
275
|
+
additionalBots,
|
|
276
|
+
additionalResp
|
|
277
|
+
),
|
|
278
|
+
legacyMigration: this.getActiveMigrationBots(
|
|
279
|
+
accountsToCheck,
|
|
280
|
+
legacyMigrationBot,
|
|
281
|
+
migrationResp
|
|
282
|
+
)
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
getActiveBots(accountsToCheck, bots, result) {
|
|
286
|
+
if (result.length !== bots.length * accountsToCheck.length) {
|
|
287
|
+
console.error(
|
|
288
|
+
"result length mismatch",
|
|
289
|
+
result.length,
|
|
290
|
+
bots.length * accountsToCheck.length
|
|
291
|
+
);
|
|
292
|
+
}
|
|
254
293
|
const botsByCAIndex = accountsToCheck.reduce((acc, _, index) => {
|
|
255
294
|
const r = result.slice(index * bots.length, (index + 1) * bots.length);
|
|
256
295
|
acc.push({
|
|
@@ -260,22 +299,15 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
260
299
|
}, []);
|
|
261
300
|
return botsByCAIndex;
|
|
262
301
|
}
|
|
263
|
-
|
|
302
|
+
getActiveMigrationBots(accountsToCheck, bot, result) {
|
|
264
303
|
if (bot) {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
address: cm.creditFacade.botList,
|
|
273
|
-
functionName: "getBotStatus",
|
|
274
|
-
args: (0, import_constants.isV300)(cm.creditFacade.version) ? [bot, ca.creditManager, ca.creditAccount] : [bot, ca.creditAccount]
|
|
275
|
-
};
|
|
276
|
-
}),
|
|
277
|
-
allowFailure: true
|
|
278
|
-
});
|
|
304
|
+
if (result.length !== accountsToCheck.length) {
|
|
305
|
+
console.error(
|
|
306
|
+
"result length mismatch for migration bots",
|
|
307
|
+
result.length,
|
|
308
|
+
accountsToCheck.length
|
|
309
|
+
);
|
|
310
|
+
}
|
|
279
311
|
return { result, botAddress: bot };
|
|
280
312
|
}
|
|
281
313
|
return void 0;
|
|
@@ -47,6 +47,20 @@ class MarketConfiguratorContract extends import_base.BaseContract {
|
|
|
47
47
|
`Market configurator ${this.#curatorName}`
|
|
48
48
|
);
|
|
49
49
|
}
|
|
50
|
+
static async getPeripheryContractBatch(configurators, client, contract) {
|
|
51
|
+
const resp = await client.multicall({
|
|
52
|
+
allowFailure: true,
|
|
53
|
+
contracts: configurators.map(
|
|
54
|
+
(cfg) => ({
|
|
55
|
+
address: cfg.address,
|
|
56
|
+
abi: cfg.abi,
|
|
57
|
+
functionName: "getPeripheryContracts",
|
|
58
|
+
args: [(0, import_viem.stringToHex)(contract, { size: 32 })]
|
|
59
|
+
})
|
|
60
|
+
)
|
|
61
|
+
});
|
|
62
|
+
return resp;
|
|
63
|
+
}
|
|
50
64
|
async getPeripheryContract(contract) {
|
|
51
65
|
const resp = await this.client.readContract({
|
|
52
66
|
address: this.address,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AddressMap, BasePlugin } from "../../sdk/index.js";
|
|
2
|
+
import { MarketConfiguratorContract } from "../../sdk/market/MarketConfiguratorContract.js";
|
|
2
3
|
const MAP_LABEL = "degenDistributors";
|
|
3
4
|
class DegenDistributorsPlugin extends BasePlugin {
|
|
4
5
|
#distributors;
|
|
@@ -16,12 +17,15 @@ class DegenDistributorsPlugin extends BasePlugin {
|
|
|
16
17
|
this.sdk.logger?.debug(
|
|
17
18
|
`loading degen distributors for ${this.sdk.networkType}`
|
|
18
19
|
);
|
|
19
|
-
const distributors = await
|
|
20
|
-
|
|
20
|
+
const distributors = await MarketConfiguratorContract.getPeripheryContractBatch(
|
|
21
|
+
Object.values(configurators),
|
|
22
|
+
this.sdk.client,
|
|
23
|
+
"DEGEN_DISTRIBUTOR"
|
|
21
24
|
);
|
|
22
25
|
const distributorByConfigurator = configurators.reduce((acc, cfg, index) => {
|
|
23
26
|
const cfgLC = cfg.address.toLowerCase();
|
|
24
|
-
|
|
27
|
+
const distributor = distributors[index];
|
|
28
|
+
acc[cfgLC] = distributor;
|
|
25
29
|
return acc;
|
|
26
30
|
}, {});
|
|
27
31
|
this.#distributors = new AddressMap(void 0, MAP_LABEL);
|
|
@@ -30,11 +34,13 @@ class DegenDistributorsPlugin extends BasePlugin {
|
|
|
30
34
|
const cfg = m.configurator.address;
|
|
31
35
|
const cfgLC = cfg.toLowerCase();
|
|
32
36
|
const r = distributorByConfigurator?.[cfgLC];
|
|
33
|
-
if (r.status === "
|
|
34
|
-
this.#distributors?.upsert(pool, r.
|
|
37
|
+
if (r.status === "success" && r.result.length > 0) {
|
|
38
|
+
this.#distributors?.upsert(pool, r.result[0]);
|
|
35
39
|
} else {
|
|
36
40
|
this.sdk.logger?.error(
|
|
37
|
-
`failed to load degen distributor for market configurator ${this.labelAddress(
|
|
41
|
+
`failed to load degen distributor for market configurator ${this.labelAddress(
|
|
42
|
+
cfg
|
|
43
|
+
)} and pool ${this.labelAddress(pool)}: ${r.error}`
|
|
38
44
|
);
|
|
39
45
|
}
|
|
40
46
|
});
|
|
@@ -202,9 +202,9 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
202
202
|
* @returns call result of getConnectedBots for each credit account
|
|
203
203
|
*/
|
|
204
204
|
async getConnectedBots(accountsToCheck, legacyMigrationBot, additionalBots) {
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
205
|
+
const allResp = await this.client.multicall({
|
|
206
|
+
contracts: [
|
|
207
|
+
...accountsToCheck.map((o) => {
|
|
208
208
|
const pool = this.sdk.marketRegister.findByCreditManager(
|
|
209
209
|
o.creditManager
|
|
210
210
|
);
|
|
@@ -215,32 +215,71 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
215
215
|
args: [pool.configurator.address, o.creditAccount]
|
|
216
216
|
};
|
|
217
217
|
}),
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
]);
|
|
223
|
-
return {
|
|
224
|
-
legacy: resp,
|
|
225
|
-
additionalBots: additional,
|
|
226
|
-
legacyMigration: migration
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
async getActiveBots(accountsToCheck, bots) {
|
|
230
|
-
const result = await this.client.multicall({
|
|
231
|
-
contracts: accountsToCheck.flatMap((ca) => {
|
|
232
|
-
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
233
|
-
return bots.map((bot) => {
|
|
218
|
+
...legacyMigrationBot ? accountsToCheck.map((ca) => {
|
|
219
|
+
const cm = this.sdk.marketRegister.findCreditManager(
|
|
220
|
+
ca.creditManager
|
|
221
|
+
);
|
|
234
222
|
return {
|
|
235
223
|
abi: isV300(cm.creditFacade.version) ? iBotListV300Abi : iBotListV310Abi,
|
|
236
224
|
address: cm.creditFacade.botList,
|
|
237
225
|
functionName: "getBotStatus",
|
|
238
|
-
args: isV300(cm.creditFacade.version) ? [
|
|
226
|
+
args: isV300(cm.creditFacade.version) ? [legacyMigrationBot, ca.creditManager, ca.creditAccount] : [legacyMigrationBot, ca.creditAccount]
|
|
239
227
|
};
|
|
240
|
-
})
|
|
241
|
-
|
|
228
|
+
}) : [],
|
|
229
|
+
...accountsToCheck.flatMap((ca) => {
|
|
230
|
+
const cm = this.sdk.marketRegister.findCreditManager(
|
|
231
|
+
ca.creditManager
|
|
232
|
+
);
|
|
233
|
+
return additionalBots.map((bot) => {
|
|
234
|
+
return {
|
|
235
|
+
abi: isV300(cm.creditFacade.version) ? iBotListV300Abi : iBotListV310Abi,
|
|
236
|
+
address: cm.creditFacade.botList,
|
|
237
|
+
functionName: "getBotStatus",
|
|
238
|
+
args: isV300(cm.creditFacade.version) ? [bot, ca.creditManager, ca.creditAccount] : [bot, ca.creditAccount]
|
|
239
|
+
};
|
|
240
|
+
});
|
|
241
|
+
})
|
|
242
|
+
],
|
|
242
243
|
allowFailure: true
|
|
243
244
|
});
|
|
245
|
+
const legacyStart = 0;
|
|
246
|
+
const legacyEnd = accountsToCheck.length;
|
|
247
|
+
const legacy = allResp.slice(
|
|
248
|
+
legacyStart,
|
|
249
|
+
legacyEnd
|
|
250
|
+
);
|
|
251
|
+
const migrationStart = legacyEnd;
|
|
252
|
+
const migrationEnd = legacyMigrationBot ? migrationStart + accountsToCheck.length : migrationStart;
|
|
253
|
+
const migrationResp = allResp.slice(
|
|
254
|
+
migrationStart,
|
|
255
|
+
migrationEnd
|
|
256
|
+
);
|
|
257
|
+
const additionalStart = migrationEnd;
|
|
258
|
+
const additionalResp = allResp.slice(
|
|
259
|
+
additionalStart
|
|
260
|
+
);
|
|
261
|
+
return {
|
|
262
|
+
legacy,
|
|
263
|
+
additionalBots: this.getActiveBots(
|
|
264
|
+
accountsToCheck,
|
|
265
|
+
additionalBots,
|
|
266
|
+
additionalResp
|
|
267
|
+
),
|
|
268
|
+
legacyMigration: this.getActiveMigrationBots(
|
|
269
|
+
accountsToCheck,
|
|
270
|
+
legacyMigrationBot,
|
|
271
|
+
migrationResp
|
|
272
|
+
)
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
getActiveBots(accountsToCheck, bots, result) {
|
|
276
|
+
if (result.length !== bots.length * accountsToCheck.length) {
|
|
277
|
+
console.error(
|
|
278
|
+
"result length mismatch",
|
|
279
|
+
result.length,
|
|
280
|
+
bots.length * accountsToCheck.length
|
|
281
|
+
);
|
|
282
|
+
}
|
|
244
283
|
const botsByCAIndex = accountsToCheck.reduce((acc, _, index) => {
|
|
245
284
|
const r = result.slice(index * bots.length, (index + 1) * bots.length);
|
|
246
285
|
acc.push({
|
|
@@ -250,22 +289,15 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
250
289
|
}, []);
|
|
251
290
|
return botsByCAIndex;
|
|
252
291
|
}
|
|
253
|
-
|
|
292
|
+
getActiveMigrationBots(accountsToCheck, bot, result) {
|
|
254
293
|
if (bot) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
address: cm.creditFacade.botList,
|
|
263
|
-
functionName: "getBotStatus",
|
|
264
|
-
args: isV300(cm.creditFacade.version) ? [bot, ca.creditManager, ca.creditAccount] : [bot, ca.creditAccount]
|
|
265
|
-
};
|
|
266
|
-
}),
|
|
267
|
-
allowFailure: true
|
|
268
|
-
});
|
|
294
|
+
if (result.length !== accountsToCheck.length) {
|
|
295
|
+
console.error(
|
|
296
|
+
"result length mismatch for migration bots",
|
|
297
|
+
result.length,
|
|
298
|
+
accountsToCheck.length
|
|
299
|
+
);
|
|
300
|
+
}
|
|
269
301
|
return { result, botAddress: bot };
|
|
270
302
|
}
|
|
271
303
|
return void 0;
|
|
@@ -26,6 +26,20 @@ class MarketConfiguratorContract extends BaseContract {
|
|
|
26
26
|
`Market configurator ${this.#curatorName}`
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
|
+
static async getPeripheryContractBatch(configurators, client, contract) {
|
|
30
|
+
const resp = await client.multicall({
|
|
31
|
+
allowFailure: true,
|
|
32
|
+
contracts: configurators.map(
|
|
33
|
+
(cfg) => ({
|
|
34
|
+
address: cfg.address,
|
|
35
|
+
abi: cfg.abi,
|
|
36
|
+
functionName: "getPeripheryContracts",
|
|
37
|
+
args: [stringToHex(contract, { size: 32 })]
|
|
38
|
+
})
|
|
39
|
+
)
|
|
40
|
+
});
|
|
41
|
+
return resp;
|
|
42
|
+
}
|
|
29
43
|
async getPeripheryContract(contract) {
|
|
30
44
|
const resp = await this.client.readContract({
|
|
31
45
|
address: this.address,
|
|
@@ -1531,6 +1531,15 @@ export declare class MarketConfiguratorContract extends BaseContract<abi> {
|
|
|
1531
1531
|
#private;
|
|
1532
1532
|
constructor(options: ConstructOptions, address: Address);
|
|
1533
1533
|
loadCuratorName(): Promise<void>;
|
|
1534
|
+
static getPeripheryContractBatch(configurators: MarketConfiguratorContract[], client: MarketConfiguratorContract["client"], contract: PeripheryContract): Promise<({
|
|
1535
|
+
error: Error;
|
|
1536
|
+
result?: undefined;
|
|
1537
|
+
status: "failure";
|
|
1538
|
+
} | {
|
|
1539
|
+
error?: undefined;
|
|
1540
|
+
result: readonly `0x${string}`[];
|
|
1541
|
+
status: "success";
|
|
1542
|
+
})[]>;
|
|
1534
1543
|
getPeripheryContract(contract: PeripheryContract): Promise<Address>;
|
|
1535
1544
|
processLog(log: Log<bigint, number, false, undefined, undefined, abi, ContractEventName<abi>>): void;
|
|
1536
1545
|
}
|