@gearbox-protocol/sdk 1.20.3 → 1.20.5
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/core/creditManager.d.ts +12 -3
- package/lib/core/creditManager.js +46 -9
- package/lib/core/pool.d.ts +12 -4
- package/lib/core/pool.js +59 -1
- package/lib/payload/creditManager.d.ts +34 -14
- package/lib/payload/pool.d.ts +44 -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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BigNumber, ethers, Signer } from "ethers";
|
|
2
2
|
import { MultiCall } from "../pathfinder/core";
|
|
3
|
-
import {
|
|
3
|
+
import { ChartsCreditManagerPayload, CreditManagerDataPayload } from "../payload/creditManager";
|
|
4
4
|
import { ICreditManager } from "../types";
|
|
5
5
|
import { Asset } from "./assets";
|
|
6
6
|
export declare class CreditManagerData {
|
|
@@ -42,7 +42,7 @@ export declare class CreditManagerData {
|
|
|
42
42
|
protected validateOpenAccountV2(debt: BigNumber): true;
|
|
43
43
|
get id(): string;
|
|
44
44
|
}
|
|
45
|
-
export declare class
|
|
45
|
+
export declare class ChartsCreditManagerData extends CreditManagerData {
|
|
46
46
|
readonly uniqueUsers: number;
|
|
47
47
|
readonly openedAccountsCount: number;
|
|
48
48
|
readonly totalOpenedAccounts: number;
|
|
@@ -54,7 +54,16 @@ export declare class CreditManagerStat extends CreditManagerData {
|
|
|
54
54
|
readonly totalRepaid: BigNumber;
|
|
55
55
|
readonly totalProfit: BigNumber;
|
|
56
56
|
readonly totalLosses: BigNumber;
|
|
57
|
-
|
|
57
|
+
readonly totalBorrowedInUSD: number;
|
|
58
|
+
readonly totalLossesInUSD: number;
|
|
59
|
+
readonly totalProfitInUSD: number;
|
|
60
|
+
readonly totalRepaidInUSD: number;
|
|
61
|
+
readonly availableLiquidityInUSD: number;
|
|
62
|
+
readonly openedAccountsCountChange: number;
|
|
63
|
+
readonly totalOpenedAccountsChange: number;
|
|
64
|
+
readonly totalClosedAccountsChange: number;
|
|
65
|
+
readonly totalLiquidatedAccountsChange: number;
|
|
66
|
+
constructor(payload: ChartsCreditManagerPayload);
|
|
58
67
|
}
|
|
59
68
|
export interface CalcHealthFactorProps {
|
|
60
69
|
assets: Array<Asset>;
|
|
@@ -26,7 +26,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
26
26
|
return __assign.apply(this, arguments);
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.calcHealthFactor = exports.
|
|
29
|
+
exports.calcHealthFactor = exports.ChartsCreditManagerData = exports.CreditManagerData = void 0;
|
|
30
30
|
var ethers_1 = require("ethers");
|
|
31
31
|
var txParser_1 = require("../parsers/txParser");
|
|
32
32
|
var decimals_1 = require("../tokens/decimals");
|
|
@@ -154,26 +154,63 @@ var CreditManagerData = /** @class */ (function () {
|
|
|
154
154
|
return CreditManagerData;
|
|
155
155
|
}());
|
|
156
156
|
exports.CreditManagerData = CreditManagerData;
|
|
157
|
-
var
|
|
158
|
-
__extends(
|
|
159
|
-
function
|
|
160
|
-
var _this = _super.call(this,
|
|
161
|
-
|
|
157
|
+
var ChartsCreditManagerData = /** @class */ (function (_super) {
|
|
158
|
+
__extends(ChartsCreditManagerData, _super);
|
|
159
|
+
function ChartsCreditManagerData(payload) {
|
|
160
|
+
var _this = _super.call(this, {
|
|
161
|
+
canBorrow: true,
|
|
162
|
+
adapters: [],
|
|
163
|
+
liquidationThresholds: [],
|
|
164
|
+
collateralTokens: [],
|
|
165
|
+
creditFacade: "",
|
|
166
|
+
creditConfigurator: "",
|
|
167
|
+
isDegenMode: false,
|
|
168
|
+
degenNFT: "",
|
|
169
|
+
isIncreaseDebtForbidden: false,
|
|
170
|
+
forbiddenTokenMask: ethers_1.BigNumber.from(0),
|
|
171
|
+
maxEnabledTokensLength: 12,
|
|
172
|
+
feeInterest: payload.feeInterest,
|
|
173
|
+
feeLiquidation: payload.feeLiquidation,
|
|
174
|
+
liquidationDiscount: 0,
|
|
175
|
+
feeLiquidationExpired: payload.feeLiquidationExpired,
|
|
176
|
+
liquidationDiscountExpired: 0,
|
|
177
|
+
pool: payload.poolAddress,
|
|
178
|
+
version: payload.version,
|
|
179
|
+
addr: payload.addr,
|
|
180
|
+
isWETH: payload.isWeth,
|
|
181
|
+
availableLiquidity: ethers_1.BigNumber.from(payload.availableLiquidity || 0),
|
|
182
|
+
borrowRate: ethers_1.BigNumber.from(payload.borrowRate || 0),
|
|
183
|
+
maxAmount: ethers_1.BigNumber.from(payload.maxAmount || 0),
|
|
184
|
+
minAmount: ethers_1.BigNumber.from(payload.minAmount || 0),
|
|
185
|
+
maxLeverageFactor: ethers_1.BigNumber.from(payload.maxLeverageFactor || 0),
|
|
186
|
+
underlying: payload.underlyingToken,
|
|
187
|
+
}) || this;
|
|
188
|
+
_this.uniqueUsers = 0;
|
|
162
189
|
_this.openedAccountsCount = payload.openedAccountsCount || 0;
|
|
163
190
|
_this.totalOpenedAccounts = payload.totalOpenedAccounts || 0;
|
|
164
191
|
_this.totalClosedAccounts = payload.totalClosedAccounts || 0;
|
|
165
192
|
_this.totalRepaidAccounts = payload.totalRepaidAccounts || 0;
|
|
166
193
|
_this.totalLiquidatedAccounts = payload.totalLiquidatedAccounts || 0;
|
|
167
194
|
_this.totalBorrowed = ethers_1.BigNumber.from(payload.totalBorrowed || 0);
|
|
168
|
-
_this.cumulativeBorrowed = ethers_1.BigNumber.from(
|
|
195
|
+
_this.cumulativeBorrowed = ethers_1.BigNumber.from(0);
|
|
169
196
|
_this.totalRepaid = ethers_1.BigNumber.from(payload.totalRepaid || 0);
|
|
170
197
|
_this.totalProfit = ethers_1.BigNumber.from(payload.totalProfit || 0);
|
|
171
198
|
_this.totalLosses = ethers_1.BigNumber.from(payload.totalLosses || 0);
|
|
199
|
+
_this.totalBorrowedInUSD = payload.totalBorrowedInUSD || 0;
|
|
200
|
+
_this.totalLossesInUSD = payload.totalLossesInUSD || 0;
|
|
201
|
+
_this.totalProfitInUSD = payload.totalProfitInUSD || 0;
|
|
202
|
+
_this.totalRepaidInUSD = payload.totalRepaidInUSD || 0;
|
|
203
|
+
_this.availableLiquidityInUSD = payload.availableLiquidityInUSD || 0;
|
|
204
|
+
_this.openedAccountsCountChange = payload.openedAccountsCountChange || 0;
|
|
205
|
+
_this.totalOpenedAccountsChange = payload.totalOpenedAccountsChange || 0;
|
|
206
|
+
_this.totalClosedAccountsChange = payload.totalClosedAccountsChange || 0;
|
|
207
|
+
_this.totalLiquidatedAccountsChange =
|
|
208
|
+
payload.totalLiquidatedAccountsChange || 0;
|
|
172
209
|
return _this;
|
|
173
210
|
}
|
|
174
|
-
return
|
|
211
|
+
return ChartsCreditManagerData;
|
|
175
212
|
}(CreditManagerData));
|
|
176
|
-
exports.
|
|
213
|
+
exports.ChartsCreditManagerData = ChartsCreditManagerData;
|
|
177
214
|
function calcHealthFactor(_a) {
|
|
178
215
|
var assets = _a.assets, prices = _a.prices, liquidationThresholds = _a.liquidationThresholds, underlyingToken = _a.underlyingToken, borrowed = _a.borrowed;
|
|
179
216
|
var assetLTMoney = assets.reduce(function (acc, _a) {
|
package/lib/core/pool.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BigNumber, Signer } from "ethers";
|
|
2
|
-
import { PoolDataPayload } from "../payload/pool";
|
|
2
|
+
import { ChartsPoolDataPayload, PoolDataPayload } from "../payload/pool";
|
|
3
3
|
import { IPoolService } from "../types";
|
|
4
4
|
export declare class PoolData {
|
|
5
5
|
readonly id: string;
|
|
@@ -23,7 +23,15 @@ export declare class PoolData {
|
|
|
23
23
|
constructor(payload: PoolDataPayload);
|
|
24
24
|
getContractETH(signer: Signer): IPoolService;
|
|
25
25
|
}
|
|
26
|
-
export
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
export declare class ChartsPoolData extends PoolData {
|
|
27
|
+
readonly expectedLiquidityInUSD: number;
|
|
28
|
+
readonly expectedLiquidityLimitInUSD: number;
|
|
29
|
+
readonly availableLiquidityInUSD: number;
|
|
30
|
+
readonly caLockedValueInUSD: number;
|
|
31
|
+
readonly totalBorrowedInUSD: number;
|
|
32
|
+
readonly uniqueLPs: number;
|
|
33
|
+
readonly depositAPY7D: number;
|
|
34
|
+
readonly depositAPY30D: number;
|
|
35
|
+
readonly lmAPY: number;
|
|
36
|
+
constructor({ expectedLiquidityInUSD, expectedLiquidityLimitInUSD, availableLiquidityInUSD, totalBorrowedInUSD, caLockedValueInUSD, uniqueLPs, dieselAPY7D, dieselAPY30D, lmAPY, ...restPayload }: ChartsPoolDataPayload);
|
|
29
37
|
}
|
package/lib/core/pool.js
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
29
|
+
var t = {};
|
|
30
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
31
|
+
t[p] = s[p];
|
|
32
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
33
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
34
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
35
|
+
t[p[i]] = s[p[i]];
|
|
36
|
+
}
|
|
37
|
+
return t;
|
|
38
|
+
};
|
|
2
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PoolData = void 0;
|
|
40
|
+
exports.ChartsPoolData = exports.PoolData = void 0;
|
|
4
41
|
var ethers_1 = require("ethers");
|
|
5
42
|
var types_1 = require("../types");
|
|
6
43
|
var formatter_1 = require("../utils/formatter");
|
|
@@ -33,3 +70,24 @@ var PoolData = /** @class */ (function () {
|
|
|
33
70
|
return PoolData;
|
|
34
71
|
}());
|
|
35
72
|
exports.PoolData = PoolData;
|
|
73
|
+
var ChartsPoolData = /** @class */ (function (_super) {
|
|
74
|
+
__extends(ChartsPoolData, _super);
|
|
75
|
+
function ChartsPoolData(_a) {
|
|
76
|
+
var _this = this;
|
|
77
|
+
var expectedLiquidityInUSD = _a.expectedLiquidityInUSD, expectedLiquidityLimitInUSD = _a.expectedLiquidityLimitInUSD, availableLiquidityInUSD = _a.availableLiquidityInUSD, totalBorrowedInUSD = _a.totalBorrowedInUSD, caLockedValueInUSD = _a.caLockedValueInUSD, uniqueLPs = _a.uniqueLPs, _b = _a.dieselAPY7D, dieselAPY7D = _b === void 0 ? 0 : _b, _c = _a.dieselAPY30D, dieselAPY30D = _c === void 0 ? 0 : _c, lmAPY = _a.lmAPY, restPayload = __rest(_a, ["expectedLiquidityInUSD", "expectedLiquidityLimitInUSD", "availableLiquidityInUSD", "totalBorrowedInUSD", "caLockedValueInUSD", "uniqueLPs", "dieselAPY7D", "dieselAPY30D", "lmAPY"]);
|
|
78
|
+
var _d = restPayload.underlying, underlying = _d === void 0 ? restPayload.underlyingToken : _d, _e = restPayload.linearCumulativeIndex, linearCumulativeIndex = _e === void 0 ? 0 : _e, _f = restPayload.cumulativeIndex_RAY, cumulativeIndexRAY = _f === void 0 ? 0 : _f, _g = restPayload.timestampLU, timestampLU = _g === void 0 ? 0 : _g, _h = restPayload.version, version = _h === void 0 ? 1 : _h, v1Props = __rest(restPayload, ["underlying", "linearCumulativeIndex", "cumulativeIndex_RAY", "timestampLU", "version"]);
|
|
79
|
+
_this = _super.call(this, __assign(__assign({}, v1Props), { underlying: underlying, linearCumulativeIndex: linearCumulativeIndex, cumulativeIndex_RAY: cumulativeIndexRAY, timestampLU: timestampLU, version: version })) || this;
|
|
80
|
+
_this.expectedLiquidityInUSD = expectedLiquidityInUSD;
|
|
81
|
+
_this.expectedLiquidityLimitInUSD = expectedLiquidityLimitInUSD;
|
|
82
|
+
_this.availableLiquidityInUSD = availableLiquidityInUSD;
|
|
83
|
+
_this.totalBorrowedInUSD = totalBorrowedInUSD;
|
|
84
|
+
_this.uniqueLPs = uniqueLPs;
|
|
85
|
+
_this.depositAPY7D = dieselAPY7D / constants_1.PERCENTAGE_DECIMALS;
|
|
86
|
+
_this.depositAPY30D = dieselAPY30D / constants_1.PERCENTAGE_DECIMALS;
|
|
87
|
+
_this.caLockedValueInUSD = caLockedValueInUSD;
|
|
88
|
+
_this.lmAPY = lmAPY / constants_1.PERCENTAGE_FACTOR;
|
|
89
|
+
return _this;
|
|
90
|
+
}
|
|
91
|
+
return ChartsPoolData;
|
|
92
|
+
}(PoolData));
|
|
93
|
+
exports.ChartsPoolData = ChartsPoolData;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { BigNumberish } from "ethers";
|
|
2
1
|
import { CreditManagerDataStructOutput } from "../types/@gearbox-protocol/core-v2/contracts/interfaces/IDataCompressor.sol/IDataCompressor";
|
|
3
2
|
import { ExcludeArrayProps } from "../utils/types";
|
|
4
3
|
export interface AdapterPayload {
|
|
@@ -6,17 +5,38 @@ export interface AdapterPayload {
|
|
|
6
5
|
adapter: string;
|
|
7
6
|
}
|
|
8
7
|
export declare type CreditManagerDataPayload = ExcludeArrayProps<CreditManagerDataStructOutput>;
|
|
9
|
-
export interface
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
totalLosses
|
|
8
|
+
export interface ChartsCreditManagerPayload {
|
|
9
|
+
addr: string;
|
|
10
|
+
availableLiquidity: string;
|
|
11
|
+
borrowRate: string;
|
|
12
|
+
isWeth: boolean;
|
|
13
|
+
maxAmount: string;
|
|
14
|
+
maxLeverageFactor: number;
|
|
15
|
+
minAmount: string;
|
|
16
|
+
openedAccountsCount: number;
|
|
17
|
+
totalBorrowed: string;
|
|
18
|
+
totalClosedAccounts: number;
|
|
19
|
+
totalLiquidatedAccounts: number;
|
|
20
|
+
totalLosses: string;
|
|
21
|
+
totalOpenedAccounts: number;
|
|
22
|
+
totalProfit: string;
|
|
23
|
+
totalRepaid: string;
|
|
24
|
+
totalRepaidAccounts: number;
|
|
25
|
+
poolAddress: string;
|
|
26
|
+
underlyingToken: string;
|
|
27
|
+
availableLiquidityInUSD: number;
|
|
28
|
+
totalBorrowedInUSD: number;
|
|
29
|
+
totalLossesInUSD: number;
|
|
30
|
+
totalProfitInUSD: number;
|
|
31
|
+
totalRepaidInUSD: number;
|
|
32
|
+
openedAccountsCountChange: number;
|
|
33
|
+
totalOpenedAccountsChange: number;
|
|
34
|
+
totalClosedAccountsChange: number;
|
|
35
|
+
totalLiquidatedAccountsChange: number;
|
|
36
|
+
feeInterest: number;
|
|
37
|
+
feeLiquidation: number;
|
|
38
|
+
feeLiquidationExpired: number;
|
|
39
|
+
liquidationPremium: number;
|
|
40
|
+
liquidationPremiumExpired: number;
|
|
41
|
+
version: number;
|
|
22
42
|
}
|
package/lib/payload/pool.d.ts
CHANGED
|
@@ -1,3 +1,47 @@
|
|
|
1
|
+
import { BigNumberish } from "ethers";
|
|
1
2
|
import { PoolDataStruct } from "../types/@gearbox-protocol/core-v2/contracts/interfaces/IDataCompressor.sol/IDataCompressor";
|
|
2
3
|
import { ExcludeArrayProps } from "../utils/types";
|
|
3
4
|
export declare type PoolDataPayload = ExcludeArrayProps<PoolDataStruct>;
|
|
5
|
+
export interface ChartsPoolDataPayload {
|
|
6
|
+
addr: string;
|
|
7
|
+
underlyingToken: string;
|
|
8
|
+
dieselToken: string;
|
|
9
|
+
isWETH: boolean;
|
|
10
|
+
expectedLiquidity: string;
|
|
11
|
+
expectedLiquidityLimit: string;
|
|
12
|
+
availableLiquidity: string;
|
|
13
|
+
totalBorrowed: string;
|
|
14
|
+
depositAPY_RAY: string;
|
|
15
|
+
borrowAPY_RAY: string;
|
|
16
|
+
dieselRate_RAY: string;
|
|
17
|
+
withdrawFee: number;
|
|
18
|
+
lmAPY: number;
|
|
19
|
+
underlying: string;
|
|
20
|
+
linearCumulativeIndex: BigNumberish;
|
|
21
|
+
cumulativeIndex_RAY: BigNumberish;
|
|
22
|
+
timestampLU: BigNumberish;
|
|
23
|
+
version: number;
|
|
24
|
+
expectedLiquidityInUSD: number;
|
|
25
|
+
expectedLiquidityLimitInUSD: number;
|
|
26
|
+
availableLiquidityInUSD: number;
|
|
27
|
+
totalBorrowedInUSD: number;
|
|
28
|
+
uniqueLPs: number;
|
|
29
|
+
dieselAPY7D?: number;
|
|
30
|
+
dieselAPY30D?: number;
|
|
31
|
+
addLiqCount: number;
|
|
32
|
+
addedLiquidity: number;
|
|
33
|
+
caLockedValue: number;
|
|
34
|
+
caLockedValueInUSD: number;
|
|
35
|
+
earned7D: number;
|
|
36
|
+
earned7DInUSD: number;
|
|
37
|
+
expectedLiqWeekAgo: number;
|
|
38
|
+
removeLiqCount: number;
|
|
39
|
+
removedLiquidity: number;
|
|
40
|
+
}
|
|
41
|
+
export interface ChartsAggregatedStats {
|
|
42
|
+
uniqueLPs: number;
|
|
43
|
+
earned7D: number;
|
|
44
|
+
}
|
|
45
|
+
export interface ChartsAggregatedPoolPayload extends ChartsAggregatedStats {
|
|
46
|
+
pools: Array<ChartsPoolDataPayload>;
|
|
47
|
+
}
|
|
@@ -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
|
});
|