@gearbox-protocol/sdk 3.0.0-next.27 → 3.0.0-next.28
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.
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { providers, Signer } from "ethers";
|
|
2
2
|
import { CreditManagerData } from "../core/creditManager";
|
|
3
3
|
export declare class CreditManagerWatcher {
|
|
4
|
-
static
|
|
5
|
-
static
|
|
6
|
-
static
|
|
4
|
+
private static newConfiguratorV2Topic;
|
|
5
|
+
private static newConfiguratorV3Topic;
|
|
6
|
+
static getAllCreditManagers(addressProvider: string, signer: Signer | providers.Provider, atBlock?: number): Promise<Record<string, CreditManagerData>>;
|
|
7
|
+
static getV2CreditManagers(dataCompressorV210: string, signer: Signer | providers.Provider, atBlock?: number): Promise<Record<string, CreditManagerData>>;
|
|
8
|
+
static getV3CreditManagers(dataCompressorV300: string, signer: Signer | providers.Provider, atBlock?: number): Promise<Record<string, CreditManagerData>>;
|
|
7
9
|
static detectConfigChanges(freshLogs: Array<providers.Log>, creditManagers: Array<CreditManagerData>): boolean;
|
|
8
10
|
}
|
|
@@ -1,18 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CreditManagerWatcher = void 0;
|
|
4
|
-
const
|
|
4
|
+
const utils_1 = require("ethers/lib/utils");
|
|
5
5
|
const creditManager_1 = require("../core/creditManager");
|
|
6
6
|
const types_1 = require("../types");
|
|
7
7
|
class CreditManagerWatcher {
|
|
8
|
-
static
|
|
9
|
-
static
|
|
10
|
-
static async
|
|
8
|
+
static newConfiguratorV2Topic = types_1.ICreditManagerV2__factory.createInterface().getEventTopic("NewConfigurator");
|
|
9
|
+
static newConfiguratorV3Topic = types_1.ICreditManagerV3__factory.createInterface().getEventTopic("SetCreditConfigurator");
|
|
10
|
+
static async getAllCreditManagers(addressProvider, signer, atBlock) {
|
|
11
|
+
const ap = types_1.IAddressProviderV3__factory.connect(addressProvider, signer);
|
|
12
|
+
const [dc210, dc300] = await Promise.all([
|
|
13
|
+
ap.getAddressOrRevert((0, utils_1.formatBytes32String)("DATA_COMPRESSOR"), 210, {
|
|
14
|
+
blockTag: atBlock,
|
|
15
|
+
}),
|
|
16
|
+
ap.getAddressOrRevert((0, utils_1.formatBytes32String)("DATA_COMPRESSOR"), 300, {
|
|
17
|
+
blockTag: atBlock,
|
|
18
|
+
}),
|
|
19
|
+
]);
|
|
20
|
+
const [cms2, cms3] = await Promise.all([
|
|
21
|
+
CreditManagerWatcher.getV2CreditManagers(dc210, signer, atBlock),
|
|
22
|
+
CreditManagerWatcher.getV3CreditManagers(dc300, signer, atBlock),
|
|
23
|
+
]);
|
|
24
|
+
return { ...cms2, ...cms3 };
|
|
25
|
+
}
|
|
26
|
+
static async getV2CreditManagers(dataCompressorV210, signer, atBlock) {
|
|
27
|
+
const creditManagers = {};
|
|
28
|
+
const creditManagersPayload = await types_1.IDataCompressorV2_10__factory.connect(dataCompressorV210, signer).getCreditManagersV2List({ blockTag: atBlock });
|
|
29
|
+
creditManagersPayload.forEach(c => {
|
|
30
|
+
creditManagers[c.addr.toLowerCase()] = new creditManager_1.CreditManagerData(c);
|
|
31
|
+
});
|
|
32
|
+
return creditManagers;
|
|
33
|
+
}
|
|
34
|
+
static async getV3CreditManagers(dataCompressorV300, signer, atBlock) {
|
|
11
35
|
const creditManagers = {};
|
|
12
|
-
const creditManagersPayload = await types_1.
|
|
13
|
-
creditManagersPayload
|
|
14
|
-
.filter(c => (0, sdk_gov_1.toBigInt)(c.cfVersion) === 2n || (0, sdk_gov_1.toBigInt)(c.cfVersion) === 210n)
|
|
15
|
-
.forEach(c => {
|
|
36
|
+
const creditManagersPayload = await types_1.IDataCompressorV3_00__factory.connect(dataCompressorV300, signer).getCreditManagersV3List({ blockTag: atBlock });
|
|
37
|
+
creditManagersPayload.forEach(c => {
|
|
16
38
|
creditManagers[c.addr.toLowerCase()] = new creditManager_1.CreditManagerData(c);
|
|
17
39
|
});
|
|
18
40
|
return creditManagers;
|
|
@@ -22,8 +44,8 @@ class CreditManagerWatcher {
|
|
|
22
44
|
const ccs = creditManagers.map(c => c.creditConfigurator);
|
|
23
45
|
for (let log of freshLogs) {
|
|
24
46
|
if (cms.includes(log.address.toLowerCase())) {
|
|
25
|
-
|
|
26
|
-
|
|
47
|
+
if (log.topics[0] === CreditManagerWatcher.newConfiguratorV2Topic ||
|
|
48
|
+
log.topics[0] === CreditManagerWatcher.newConfiguratorV3Topic) {
|
|
27
49
|
return true;
|
|
28
50
|
}
|
|
29
51
|
}
|
|
@@ -26,20 +26,28 @@ const makeLog = (address, topics, data = sdk_gov_1.ADDRESS_0X0) => {
|
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
describe("CreditManagerTracker test", () => {
|
|
29
|
-
it("detects
|
|
30
|
-
const
|
|
29
|
+
it("detects CreditManagerV2 events correctly", () => {
|
|
30
|
+
const cmV2Interface = types_1.ICreditManagerV2__factory.createInterface();
|
|
31
31
|
let log = makeLog(CREDIT_MANAGER_ADDRESS, [
|
|
32
|
-
|
|
32
|
+
cmV2Interface.getEventTopic("NewConfigurator"),
|
|
33
33
|
encode("address", sdk_gov_1.DUMB_ADDRESS),
|
|
34
34
|
]);
|
|
35
35
|
(0, chai_1.expect)(creditManagerWatcher_1.CreditManagerWatcher.detectConfigChanges([log], [cmDumb])).to.be.eq(true);
|
|
36
36
|
log = makeLog(CREDIT_MANAGER_ADDRESS, [
|
|
37
|
-
|
|
37
|
+
cmV2Interface.getEventTopic("ExecuteOrder"),
|
|
38
38
|
encode("address", sdk_gov_1.DUMB_ADDRESS),
|
|
39
39
|
encode("address", sdk_gov_1.DUMB_ADDRESS),
|
|
40
40
|
]);
|
|
41
41
|
(0, chai_1.expect)(creditManagerWatcher_1.CreditManagerWatcher.detectConfigChanges([log], [cmDumb])).to.be.eq(false);
|
|
42
42
|
});
|
|
43
|
+
it("detects CreditManagerV3 events correctly", () => {
|
|
44
|
+
const cmV3Interface = types_1.ICreditManagerV3__factory.createInterface();
|
|
45
|
+
let log = makeLog(CREDIT_MANAGER_ADDRESS, [
|
|
46
|
+
cmV3Interface.getEventTopic("SetCreditConfigurator"),
|
|
47
|
+
encode("address", sdk_gov_1.DUMB_ADDRESS),
|
|
48
|
+
]);
|
|
49
|
+
(0, chai_1.expect)(creditManagerWatcher_1.CreditManagerWatcher.detectConfigChanges([log], [cmDumb])).to.be.eq(true);
|
|
50
|
+
});
|
|
43
51
|
it("detects CreditConfigurator events correctly", () => {
|
|
44
52
|
const ccInterface = types_1.ICreditConfiguratorV2__factory.createInterface();
|
|
45
53
|
let log = makeLog(CREDIT_CONFIGIURATOR_ADDRESS, [
|