@gearbox-protocol/sdk 1.20.4 → 1.20.6
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/lib/contracts/contractsRegister.d.ts +2 -1
- package/lib/contracts/contractsRegister.js +4 -1
- package/lib/oracles/priceFeeds.js +10 -0
- package/lib/tokens/decimals.js +1 -0
- package/lib/tokens/gear.d.ts +1 -1
- package/lib/tokens/gear.js +5 -0
- package/lib/tokens/token.js +2 -0
- package/lib/watchers/creditAccountWatcher.d.ts +1 -0
- package/lib/watchers/creditAccountWatcher.js +51 -24
- package/lib/watchers/creditAccountWatcher.spec.js +66 -18
- package/package.json +1 -1
|
@@ -5,11 +5,12 @@ export declare const CREDIT_MANAGER_USDC_V2_MAINNET: string;
|
|
|
5
5
|
export declare const CREDIT_MANAGER_WETH_V2_MAINNET: string;
|
|
6
6
|
export declare const CREDIT_MANAGER_WSTETH_V2_MAINNET: string;
|
|
7
7
|
export declare const CREDIT_MANAGER_WBTC_V2_MAINNET: string;
|
|
8
|
+
export declare const CREDIT_MANAGER_FRAX_V2_MAINNET: string;
|
|
8
9
|
export declare const CREDIT_MANAGER_DAI_V2_GOERLI: string;
|
|
9
10
|
export declare const CREDIT_MANAGER_USDC_V2_GOERLI: string;
|
|
10
11
|
export declare const CREDIT_MANAGER_WETH_V2_GOERLI: string;
|
|
11
12
|
export declare const CREDIT_MANAGER_WSTETH_V2_GOERLI: string;
|
|
12
13
|
export declare const CREDIT_MANAGER_WBTC_V2_GOERLI: string;
|
|
13
|
-
export declare type CreditManagersV2 = typeof CREDIT_MANAGER_DAI_V2_MAINNET | typeof CREDIT_MANAGER_USDC_V2_MAINNET | typeof CREDIT_MANAGER_WETH_V2_MAINNET | typeof CREDIT_MANAGER_WSTETH_V2_MAINNET | typeof CREDIT_MANAGER_WBTC_V2_MAINNET | typeof CREDIT_MANAGER_DAI_V2_GOERLI | typeof CREDIT_MANAGER_USDC_V2_GOERLI | typeof CREDIT_MANAGER_WETH_V2_GOERLI | typeof CREDIT_MANAGER_WSTETH_V2_GOERLI | typeof CREDIT_MANAGER_WBTC_V2_GOERLI;
|
|
14
|
+
export declare type CreditManagersV2 = typeof CREDIT_MANAGER_DAI_V2_MAINNET | typeof CREDIT_MANAGER_USDC_V2_MAINNET | typeof CREDIT_MANAGER_WETH_V2_MAINNET | typeof CREDIT_MANAGER_WSTETH_V2_MAINNET | typeof CREDIT_MANAGER_WBTC_V2_MAINNET | typeof CREDIT_MANAGER_DAI_V2_GOERLI | typeof CREDIT_MANAGER_USDC_V2_GOERLI | typeof CREDIT_MANAGER_WETH_V2_GOERLI | typeof CREDIT_MANAGER_WSTETH_V2_GOERLI | typeof CREDIT_MANAGER_WBTC_V2_GOERLI | typeof CREDIT_MANAGER_FRAX_V2_MAINNET;
|
|
14
15
|
export declare const deployedContracts: Record<string, string>;
|
|
15
16
|
export declare function getContractName(address: string): string;
|
|
@@ -12,7 +12,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
};
|
|
13
13
|
var _a;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getContractName = exports.deployedContracts = exports.CREDIT_MANAGER_WBTC_V2_GOERLI = exports.CREDIT_MANAGER_WSTETH_V2_GOERLI = exports.CREDIT_MANAGER_WETH_V2_GOERLI = exports.CREDIT_MANAGER_USDC_V2_GOERLI = exports.CREDIT_MANAGER_DAI_V2_GOERLI = exports.CREDIT_MANAGER_WBTC_V2_MAINNET = exports.CREDIT_MANAGER_WSTETH_V2_MAINNET = exports.CREDIT_MANAGER_WETH_V2_MAINNET = exports.CREDIT_MANAGER_USDC_V2_MAINNET = exports.CREDIT_MANAGER_DAI_V2_MAINNET = exports.stEthPoolWrapper = void 0;
|
|
15
|
+
exports.getContractName = exports.deployedContracts = exports.CREDIT_MANAGER_WBTC_V2_GOERLI = exports.CREDIT_MANAGER_WSTETH_V2_GOERLI = exports.CREDIT_MANAGER_WETH_V2_GOERLI = exports.CREDIT_MANAGER_USDC_V2_GOERLI = exports.CREDIT_MANAGER_DAI_V2_GOERLI = exports.CREDIT_MANAGER_FRAX_V2_MAINNET = exports.CREDIT_MANAGER_WBTC_V2_MAINNET = exports.CREDIT_MANAGER_WSTETH_V2_MAINNET = exports.CREDIT_MANAGER_WETH_V2_MAINNET = exports.CREDIT_MANAGER_USDC_V2_MAINNET = exports.CREDIT_MANAGER_DAI_V2_MAINNET = exports.stEthPoolWrapper = void 0;
|
|
16
16
|
var mappers_1 = require("../utils/mappers");
|
|
17
17
|
var contracts_1 = require("./contracts");
|
|
18
18
|
exports.stEthPoolWrapper = {
|
|
@@ -24,6 +24,7 @@ exports.CREDIT_MANAGER_USDC_V2_MAINNET = "0x95357303f995e184A7998dA6C6eA35cC728A
|
|
|
24
24
|
exports.CREDIT_MANAGER_WETH_V2_MAINNET = "0x5887ad4cb2352e7f01527035faa3ae0ef2ce2b9b".toLowerCase();
|
|
25
25
|
exports.CREDIT_MANAGER_WSTETH_V2_MAINNET = "0xe0bce4460795281d39c91da9b0275bca968293de".toLowerCase();
|
|
26
26
|
exports.CREDIT_MANAGER_WBTC_V2_MAINNET = "0xc62bf8a7889adf1c5dc4665486c7683ae6e74e0f".toLowerCase();
|
|
27
|
+
exports.CREDIT_MANAGER_FRAX_V2_MAINNET = "0xa3e1e0d58fe8dd8c9dd48204699a1178f1b274d8".toLowerCase();
|
|
27
28
|
// GOERLI
|
|
28
29
|
exports.CREDIT_MANAGER_DAI_V2_GOERLI = "0xf7ba434952acaa2e12035a2c3643ca327914a470".toLowerCase();
|
|
29
30
|
exports.CREDIT_MANAGER_USDC_V2_GOERLI = "0x2144a7785baecbab32295188285717cad6c1a11c".toLowerCase();
|
|
@@ -36,6 +37,7 @@ exports.deployedContracts = (_a = {
|
|
|
36
37
|
"0x2664cc24CBAd28749B3Dd6fC97A6B402484De527": "USDC",
|
|
37
38
|
"0x968f9a68a98819E2e6Bb910466e191A7b6cf02F0": "WETH",
|
|
38
39
|
"0xC38478B0A4bAFE964C3526EEFF534d70E1E09017": "WBTC",
|
|
40
|
+
"0x79012c8d491dcf3a30db20d1f449b14caf01da6c": "FRAX",
|
|
39
41
|
// MAINNET POOLS
|
|
40
42
|
"0x24946bCbBd028D5ABb62ad9B635EB1b1a67AF668": "DAI",
|
|
41
43
|
"0x86130bDD69143D8a4E5fc50bf4323D48049E98E4": "USDC",
|
|
@@ -49,6 +51,7 @@ exports.deployedContracts = (_a = {
|
|
|
49
51
|
_a[exports.CREDIT_MANAGER_WETH_V2_MAINNET] = "WETH",
|
|
50
52
|
_a[exports.CREDIT_MANAGER_WSTETH_V2_MAINNET] = "wstETH",
|
|
51
53
|
_a[exports.CREDIT_MANAGER_WBTC_V2_MAINNET] = "WBTC",
|
|
54
|
+
_a[exports.CREDIT_MANAGER_FRAX_V2_MAINNET] = "FRAX",
|
|
52
55
|
// GOERLI CM
|
|
53
56
|
_a[exports.CREDIT_MANAGER_DAI_V2_GOERLI] = "DAI",
|
|
54
57
|
_a[exports.CREDIT_MANAGER_USDC_V2_GOERLI] = "USDC",
|
|
@@ -567,6 +567,16 @@ exports.priceFeedsByNetwork = {
|
|
|
567
567
|
address: { Mainnet: "", Goerli: "" },
|
|
568
568
|
},
|
|
569
569
|
},
|
|
570
|
+
dFRAX: {
|
|
571
|
+
priceFeedETH: {
|
|
572
|
+
type: oracles_1.OracleType.CHAINLINK_ORACLE,
|
|
573
|
+
address: { Mainnet: "", Goerli: "" },
|
|
574
|
+
},
|
|
575
|
+
priceFeedUSD: {
|
|
576
|
+
type: oracles_1.OracleType.CHAINLINK_ORACLE,
|
|
577
|
+
address: { Mainnet: "", Goerli: "" },
|
|
578
|
+
},
|
|
579
|
+
},
|
|
570
580
|
GEAR: {
|
|
571
581
|
priceFeedETH: {
|
|
572
582
|
type: oracles_1.OracleType.CHAINLINK_ORACLE,
|
package/lib/tokens/decimals.js
CHANGED
package/lib/tokens/gear.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TradeAction } from "../pathfinder/tradeTypes";
|
|
2
2
|
import type { TokenBase } from "./token";
|
|
3
3
|
import { TokenType } from "./tokenType";
|
|
4
|
-
export declare type DieselTokenTypes = "dDAI" | "dUSDC" | "dWBTC" | "dWETH" | "dwstETH";
|
|
4
|
+
export declare type DieselTokenTypes = "dDAI" | "dUSDC" | "dWBTC" | "dWETH" | "dwstETH" | "dFRAX";
|
|
5
5
|
export declare type GearboxToken = "GEAR";
|
|
6
6
|
export declare type DieselTokenData = {
|
|
7
7
|
symbol: DieselTokenTypes;
|
package/lib/tokens/gear.js
CHANGED
package/lib/tokens/token.js
CHANGED
|
@@ -88,6 +88,7 @@ exports.tokenDataByNetwork = {
|
|
|
88
88
|
dWBTC: "0xe753260F1955e8678DCeA8887759e07aa57E8c54",
|
|
89
89
|
dWETH: "0xF21fc650C1B34eb0FDE786D52d23dA99Db3D6278",
|
|
90
90
|
dwstETH: "0x2158034dB06f06dcB9A786D2F1F8c38781bA779d",
|
|
91
|
+
dFRAX: "0x8a1112afef7f4fc7c066a77aabbc01b3fff31d47",
|
|
91
92
|
GEAR: "0xBa3335588D9403515223F109EdC4eB7269a9Ab5D",
|
|
92
93
|
},
|
|
93
94
|
///
|
|
@@ -159,6 +160,7 @@ exports.tokenDataByNetwork = {
|
|
|
159
160
|
dWBTC: "0xd7f208de8d5b5301e7018dcc6D312A4305382330",
|
|
160
161
|
dWETH: "0xfb906E19E71ED61bcb5eA0E11d77941A058eafBD",
|
|
161
162
|
dwstETH: "0xAB20D04aF0f79aB21cC66431F6BAc03b74003d4d",
|
|
163
|
+
dFRAX: "deploy me",
|
|
162
164
|
GEAR: "0x3321F5dA65165042903eDe71617F912942f4E70F",
|
|
163
165
|
},
|
|
164
166
|
};
|
|
@@ -13,6 +13,7 @@ interface BatchCreditAccountLoadOptions {
|
|
|
13
13
|
export declare class CreditAccountWatcher {
|
|
14
14
|
static IERC20: import("../types/@openzeppelin/contracts/token/ERC20/IERC20").IERC20Interface;
|
|
15
15
|
static creditManagerInterface: import("../types/@gearbox-protocol/core-v2/contracts/interfaces/ICreditManagerV2.sol/ICreditManagerV2").ICreditManagerV2Interface;
|
|
16
|
+
static creditConfiguratorInterface: import("../types/@gearbox-protocol/core-v2/contracts/interfaces/ICreditConfigurator.sol/ICreditConfigurator").ICreditConfiguratorInterface;
|
|
16
17
|
static creditFacadeInterface: import("../types/@gearbox-protocol/core-v2/contracts/interfaces/ICreditFacade.sol/ICreditFacade").ICreditFacadeInterface;
|
|
17
18
|
/**
|
|
18
19
|
* Gets hashes of all opened credit accounts at toBlock (or "latest" by default)
|
|
@@ -52,7 +52,8 @@ var CreditAccountWatcher = /** @class */ (function () {
|
|
|
52
52
|
*/
|
|
53
53
|
CreditAccountWatcher.getOpenAccounts = function (creditManager, provider, toBlock) {
|
|
54
54
|
return __awaiter(this, void 0, void 0, function () {
|
|
55
|
-
var eventsByDate, addToEvents, accounts,
|
|
55
|
+
var eventsByDate, addToEvents, accounts, cm, ccAddrs, cfUpgraded, _loop_1, _i, cfUpgraded_1, creditFacade;
|
|
56
|
+
var _this = this;
|
|
56
57
|
return __generator(this, function (_a) {
|
|
57
58
|
switch (_a.label) {
|
|
58
59
|
case 0:
|
|
@@ -67,11 +68,25 @@ var CreditAccountWatcher = /** @class */ (function () {
|
|
|
67
68
|
});
|
|
68
69
|
};
|
|
69
70
|
accounts = new Set();
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return [4 /*yield*/, cc.queryFilter(cc.filters.CreditFacadeUpgraded(), undefined, toBlock)];
|
|
71
|
+
cm = types_1.ICreditManagerV2__factory.connect(creditManager.address, provider);
|
|
72
|
+
return [4 /*yield*/, cm.queryFilter(cm.filters.NewConfigurator(), undefined, toBlock)];
|
|
73
73
|
case 1:
|
|
74
|
-
|
|
74
|
+
ccAddrs = (_a.sent()).map(function (e) { return e.args.newConfigurator; });
|
|
75
|
+
return [4 /*yield*/, Promise.all(ccAddrs.map(function (ccAddr) { return __awaiter(_this, void 0, void 0, function () {
|
|
76
|
+
var cc, cfUpgradedEvents;
|
|
77
|
+
return __generator(this, function (_a) {
|
|
78
|
+
switch (_a.label) {
|
|
79
|
+
case 0:
|
|
80
|
+
cc = types_1.ICreditConfigurator__factory.connect(ccAddr, provider);
|
|
81
|
+
return [4 /*yield*/, cc.queryFilter(cc.filters.CreditFacadeUpgraded(), undefined, toBlock)];
|
|
82
|
+
case 1:
|
|
83
|
+
cfUpgradedEvents = _a.sent();
|
|
84
|
+
return [2 /*return*/, cfUpgradedEvents.map(function (e) { return e.args.newCreditFacade; })];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}); }))];
|
|
88
|
+
case 2:
|
|
89
|
+
cfUpgraded = (_a.sent()).flat();
|
|
75
90
|
_loop_1 = function (creditFacade) {
|
|
76
91
|
var cf, topics, logs;
|
|
77
92
|
return __generator(this, function (_b) {
|
|
@@ -113,18 +128,18 @@ var CreditAccountWatcher = /** @class */ (function () {
|
|
|
113
128
|
});
|
|
114
129
|
};
|
|
115
130
|
_i = 0, cfUpgraded_1 = cfUpgraded;
|
|
116
|
-
_a.label =
|
|
117
|
-
case
|
|
118
|
-
if (!(_i < cfUpgraded_1.length)) return [3 /*break*/,
|
|
131
|
+
_a.label = 3;
|
|
132
|
+
case 3:
|
|
133
|
+
if (!(_i < cfUpgraded_1.length)) return [3 /*break*/, 6];
|
|
119
134
|
creditFacade = cfUpgraded_1[_i];
|
|
120
135
|
return [5 /*yield**/, _loop_1(creditFacade)];
|
|
121
|
-
case 3:
|
|
122
|
-
_a.sent();
|
|
123
|
-
_a.label = 4;
|
|
124
136
|
case 4:
|
|
125
|
-
|
|
126
|
-
|
|
137
|
+
_a.sent();
|
|
138
|
+
_a.label = 5;
|
|
127
139
|
case 5:
|
|
140
|
+
_i++;
|
|
141
|
+
return [3 /*break*/, 3];
|
|
142
|
+
case 6:
|
|
128
143
|
eventsByDate
|
|
129
144
|
.sort(function (a, b) {
|
|
130
145
|
return a.time > b.time ? 1 : -1;
|
|
@@ -196,18 +211,18 @@ var CreditAccountWatcher = /** @class */ (function () {
|
|
|
196
211
|
* @returns CreditManagerUpdate which contains updated (created / modified) and deleted accounts
|
|
197
212
|
*/
|
|
198
213
|
CreditAccountWatcher.detectChanges = function (logs, creditManagers) {
|
|
199
|
-
var cms = creditManagers.map(function (c) { return c.address; });
|
|
200
|
-
var
|
|
201
|
-
var
|
|
202
|
-
|
|
203
|
-
return acc;
|
|
204
|
-
}, {});
|
|
214
|
+
var cms = creditManagers.map(function (c) { return c.address.toLowerCase(); });
|
|
215
|
+
var cfToCm = {};
|
|
216
|
+
var ccToCm = {};
|
|
217
|
+
// maps credit manager addr to credit configurator addresses
|
|
205
218
|
var trackers = {};
|
|
206
|
-
|
|
207
|
-
trackers[cm] = {
|
|
219
|
+
creditManagers.forEach(function (cm) {
|
|
220
|
+
trackers[cm.address.toLowerCase()] = {
|
|
208
221
|
updated: new Set(),
|
|
209
222
|
deleted: new Set(),
|
|
210
223
|
};
|
|
224
|
+
ccToCm[cm.creditConfigurator.toLowerCase()] = cm.address.toLowerCase();
|
|
225
|
+
cfToCm[cm.creditFacade.toLowerCase()] = cm.address.toLowerCase();
|
|
211
226
|
});
|
|
212
227
|
for (var _i = 0, logs_1 = logs; _i < logs_1.length; _i++) {
|
|
213
228
|
var log = logs_1[_i];
|
|
@@ -219,13 +234,24 @@ var CreditAccountWatcher = /** @class */ (function () {
|
|
|
219
234
|
if (!borrower)
|
|
220
235
|
throw new Error("Cant parser event ".concat(log));
|
|
221
236
|
/// Excludes credit facade which represents borrower in multicall
|
|
222
|
-
if (!
|
|
237
|
+
if (!(borrower.toLowerCase() in cfToCm)) {
|
|
223
238
|
trackers[logAddr].updated.add(borrower);
|
|
224
239
|
}
|
|
225
240
|
}
|
|
241
|
+
else if (name === "NewConfigurator") {
|
|
242
|
+
var newConfigurator = args.newConfigurator.toLowerCase();
|
|
243
|
+
ccToCm[newConfigurator] = logAddr;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
else if (logAddr in ccToCm) {
|
|
247
|
+
var _b = CreditAccountWatcher.creditConfiguratorInterface.parseLog(log), name = _b.name, args = _b.args;
|
|
248
|
+
if (name === "CreditFacadeUpgraded") {
|
|
249
|
+
var newCreditFacade = args.newCreditFacade.toLowerCase();
|
|
250
|
+
cfToCm[newCreditFacade] = ccToCm[logAddr];
|
|
251
|
+
}
|
|
226
252
|
}
|
|
227
|
-
else if (
|
|
228
|
-
var
|
|
253
|
+
else if (logAddr in cfToCm) {
|
|
254
|
+
var _c = CreditAccountWatcher.creditFacadeInterface.parseLog(log), name = _c.name, args = _c.args;
|
|
229
255
|
switch (name) {
|
|
230
256
|
case "OpenCreditAccount":
|
|
231
257
|
case "AddCollateral": {
|
|
@@ -304,6 +330,7 @@ var CreditAccountWatcher = /** @class */ (function () {
|
|
|
304
330
|
};
|
|
305
331
|
CreditAccountWatcher.IERC20 = types_1.IERC20__factory.createInterface();
|
|
306
332
|
CreditAccountWatcher.creditManagerInterface = types_1.ICreditManagerV2__factory.createInterface();
|
|
333
|
+
CreditAccountWatcher.creditConfiguratorInterface = types_1.ICreditConfigurator__factory.createInterface();
|
|
307
334
|
CreditAccountWatcher.creditFacadeInterface = types_1.ICreditFacade__factory.createInterface();
|
|
308
335
|
return CreditAccountWatcher;
|
|
309
336
|
}());
|
|
@@ -7,13 +7,18 @@ var types_1 = require("../types");
|
|
|
7
7
|
var creditAccountWatcher_1 = require("./creditAccountWatcher");
|
|
8
8
|
var CREDIT_MANAGER_ADDRESS = constants_1.DUMB_ADDRESS;
|
|
9
9
|
var CREDIT_FACADE_ADDRESS = "0xcb9a588a47dd0393af3d0d5f86e6f1c8fd252c48";
|
|
10
|
+
var CREDIT_FACADE_NEW = "0xcb9a588a47dd0393af3d0d5f86e6f1c8fd252ccc";
|
|
11
|
+
var CREDIT_CONFIGURATOR_ADDRESS = "0xcb9a588a47dd0393af3d0d5f86e6f1c8fd252aaa";
|
|
12
|
+
var CREDIT_CONFIGURATOR_NEW = "0xcb9a588a47dd0393af3d0d5f86e6f1c8fd252000";
|
|
10
13
|
var BORROWER = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266";
|
|
11
14
|
var expectedHash = "".concat(CREDIT_MANAGER_ADDRESS.toLowerCase(), ":").concat(BORROWER.toLowerCase());
|
|
12
15
|
var creditManagerInterface = types_1.ICreditManagerV2__factory.createInterface();
|
|
13
16
|
var creditFacadeInterface = types_1.ICreditFacade__factory.createInterface();
|
|
17
|
+
var creditConfiguratorInterface = types_1.ICreditConfigurator__factory.createInterface();
|
|
14
18
|
var cmDumb = {
|
|
15
19
|
address: CREDIT_MANAGER_ADDRESS.toLowerCase(),
|
|
16
20
|
creditFacade: CREDIT_FACADE_ADDRESS.toLowerCase(),
|
|
21
|
+
creditConfigurator: CREDIT_CONFIGURATOR_ADDRESS.toLowerCase(),
|
|
17
22
|
};
|
|
18
23
|
var encode = function (abiType, value) {
|
|
19
24
|
return ethers_1.utils.defaultAbiCoder.encode([abiType], [value]);
|
|
@@ -32,20 +37,42 @@ var makeLog = function (address, topics, data) {
|
|
|
32
37
|
logIndex: 0,
|
|
33
38
|
};
|
|
34
39
|
};
|
|
35
|
-
var openLog =
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
var openLog = function (facadeAddr) {
|
|
41
|
+
if (facadeAddr === void 0) { facadeAddr = CREDIT_FACADE_ADDRESS; }
|
|
42
|
+
return makeLog(facadeAddr, [
|
|
43
|
+
creditFacadeInterface.getEventTopic("OpenCreditAccount"),
|
|
44
|
+
encode("address", BORROWER),
|
|
45
|
+
encode("address", constants_1.DUMB_ADDRESS),
|
|
46
|
+
], ethers_1.utils.defaultAbiCoder.encode(["uint256", "uint16"], [10, 10]));
|
|
47
|
+
};
|
|
48
|
+
var closeLog = function (facadeAddr) {
|
|
49
|
+
if (facadeAddr === void 0) { facadeAddr = CREDIT_FACADE_ADDRESS; }
|
|
50
|
+
return makeLog(facadeAddr, [
|
|
51
|
+
creditFacadeInterface.getEventTopic("CloseCreditAccount"),
|
|
52
|
+
encode("address", BORROWER),
|
|
53
|
+
encode("address", constants_1.DUMB_ADDRESS),
|
|
54
|
+
encode("address", constants_1.DUMB_ADDRESS),
|
|
55
|
+
]);
|
|
56
|
+
};
|
|
57
|
+
var upgradeFacadeLog = function (configuratorAddr, facadeAddr) {
|
|
58
|
+
if (configuratorAddr === void 0) { configuratorAddr = CREDIT_CONFIGURATOR_NEW; }
|
|
59
|
+
if (facadeAddr === void 0) { facadeAddr = CREDIT_FACADE_NEW; }
|
|
60
|
+
return makeLog(configuratorAddr, [
|
|
61
|
+
creditConfiguratorInterface.getEventTopic("CreditFacadeUpgraded"),
|
|
62
|
+
encode("address", facadeAddr),
|
|
63
|
+
]);
|
|
64
|
+
};
|
|
65
|
+
var newConfiguratorLog = function (managerAddr, configuratorAddr) {
|
|
66
|
+
if (managerAddr === void 0) { managerAddr = CREDIT_MANAGER_ADDRESS; }
|
|
67
|
+
if (configuratorAddr === void 0) { configuratorAddr = CREDIT_CONFIGURATOR_NEW; }
|
|
68
|
+
return makeLog(managerAddr, [
|
|
69
|
+
creditManagerInterface.getEventTopic("NewConfigurator"),
|
|
70
|
+
encode("address", configuratorAddr),
|
|
71
|
+
]);
|
|
72
|
+
};
|
|
46
73
|
describe("CreditAccountTracker test", function () {
|
|
47
74
|
it("detects update events correctly", function () {
|
|
48
|
-
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([openLog], [cmDumb])).to.be.eql({
|
|
75
|
+
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([openLog()], [cmDumb])).to.be.eql({
|
|
49
76
|
updated: [expectedHash],
|
|
50
77
|
deleted: [],
|
|
51
78
|
});
|
|
@@ -114,7 +141,7 @@ describe("CreditAccountTracker test", function () {
|
|
|
114
141
|
// DELETED
|
|
115
142
|
//
|
|
116
143
|
it("detects delete events correctly", function () {
|
|
117
|
-
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([closeLog], [cmDumb])).to.be.eql({
|
|
144
|
+
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([closeLog()], [cmDumb])).to.be.eql({
|
|
118
145
|
updated: [],
|
|
119
146
|
deleted: [expectedHash],
|
|
120
147
|
});
|
|
@@ -142,21 +169,21 @@ describe("CreditAccountTracker test", function () {
|
|
|
142
169
|
});
|
|
143
170
|
});
|
|
144
171
|
it("doesn't make duplicated", function () {
|
|
145
|
-
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([openLog, openLog, openLog], [cmDumb])).to.be.eql({
|
|
172
|
+
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([openLog(), openLog(), openLog()], [cmDumb])).to.be.eql({
|
|
146
173
|
updated: [expectedHash],
|
|
147
174
|
deleted: [],
|
|
148
175
|
});
|
|
149
|
-
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([closeLog, closeLog, closeLog], [cmDumb])).to.be.eql({
|
|
176
|
+
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([closeLog(), closeLog(), closeLog()], [cmDumb])).to.be.eql({
|
|
150
177
|
updated: [],
|
|
151
178
|
deleted: [expectedHash],
|
|
152
179
|
});
|
|
153
180
|
});
|
|
154
181
|
it("updates accounts were created and deleted in the batch", function () {
|
|
155
|
-
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([openLog, closeLog], [cmDumb])).to.be.eql({
|
|
182
|
+
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([openLog(), closeLog()], [cmDumb])).to.be.eql({
|
|
156
183
|
updated: [],
|
|
157
184
|
deleted: [expectedHash],
|
|
158
185
|
});
|
|
159
|
-
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([openLog, closeLog, openLog], [cmDumb])).to.be.eql({
|
|
186
|
+
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([openLog(), closeLog(), openLog()], [cmDumb])).to.be.eql({
|
|
160
187
|
updated: [expectedHash],
|
|
161
188
|
deleted: [expectedHash],
|
|
162
189
|
});
|
|
@@ -167,11 +194,32 @@ describe("CreditAccountTracker test", function () {
|
|
|
167
194
|
encode("address", BORROWER),
|
|
168
195
|
encode("address", constants_1.DUMB_ADDRESS),
|
|
169
196
|
]);
|
|
170
|
-
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([openLog, transferLog], [cmDumb])).to.be.eql({
|
|
197
|
+
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([openLog(), transferLog], [cmDumb])).to.be.eql({
|
|
171
198
|
updated: [
|
|
172
199
|
"".concat(CREDIT_MANAGER_ADDRESS.toLowerCase(), ":").concat(constants_1.DUMB_ADDRESS.toLowerCase()),
|
|
173
200
|
],
|
|
174
201
|
deleted: [expectedHash],
|
|
175
202
|
});
|
|
176
203
|
});
|
|
204
|
+
it("correctly handles credit configurator change", function () {
|
|
205
|
+
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([
|
|
206
|
+
openLog(),
|
|
207
|
+
newConfiguratorLog(),
|
|
208
|
+
upgradeFacadeLog(),
|
|
209
|
+
closeLog(CREDIT_FACADE_NEW),
|
|
210
|
+
], [cmDumb])).to.be.eql({
|
|
211
|
+
updated: [],
|
|
212
|
+
deleted: [expectedHash],
|
|
213
|
+
});
|
|
214
|
+
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([
|
|
215
|
+
openLog(),
|
|
216
|
+
closeLog(),
|
|
217
|
+
newConfiguratorLog(),
|
|
218
|
+
upgradeFacadeLog(),
|
|
219
|
+
openLog(CREDIT_FACADE_NEW),
|
|
220
|
+
], [cmDumb])).to.be.eql({
|
|
221
|
+
updated: [expectedHash],
|
|
222
|
+
deleted: [expectedHash],
|
|
223
|
+
});
|
|
224
|
+
});
|
|
177
225
|
});
|