@gearbox-protocol/sdk 3.0.0-next.28 → 3.0.0-next.29

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.
@@ -10,7 +10,7 @@ interface BatchCreditAccountLoadOptions {
10
10
  atBlock?: number;
11
11
  chunkSize?: number;
12
12
  }
13
- export declare class CreditAccountWatcher {
13
+ export declare class CreditAccountWatcherV2 {
14
14
  static IERC20: import("../types/IERC20").IERC20Interface;
15
15
  static creditManagerInterface: import("../types/ICreditManagerV2.sol/ICreditManagerV2").ICreditManagerV2Interface;
16
16
  static creditConfiguratorInterface: import("../types/ICreditConfiguratorV2.sol/ICreditConfiguratorV2").ICreditConfiguratorV2Interface;
@@ -23,7 +23,7 @@ export declare class CreditAccountWatcher {
23
23
  * @returns Arrays of hashes for opened accounts
24
24
  */
25
25
  static getOpenAccounts(creditManager: CreditManagerData, provider: providers.Provider, toBlock?: number): Promise<Array<CreditAccountHash>>;
26
- static batchCreditAccountLoad(accs: Array<CreditAccountHash>, dataCompressor: string, signer: Signer | providers.Provider, options?: BatchCreditAccountLoadOptions | number): Promise<Array<CreditAccountData>>;
26
+ static batchCreditAccountLoad(accs: Array<CreditAccountHash>, dataCompressor210: string, signer: Signer | providers.Provider, options?: BatchCreditAccountLoadOptions | number): Promise<Array<CreditAccountData>>;
27
27
  /**
28
28
  * Tracks block logs and detects whichj acccounts were changed (created / modified) and which were deleted
29
29
  * @param logs Logs from last N blocks
@@ -32,5 +32,6 @@ export declare class CreditAccountWatcher {
32
32
  */
33
33
  static detectChanges(logs: Array<providers.Log>, creditManagers: Array<CreditManagerData>): CreditManagerUpdate;
34
34
  static trackDirectTransfers(freshLogs: Array<providers.Log>, tokensToTrack: Array<string>, accounts: Array<CreditAccountData>): Array<CreditAccountHash>;
35
+ private static assertCMSupported;
35
36
  }
36
37
  export {};
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CreditAccountWatcher = void 0;
3
+ exports.CreditAccountWatcherV2 = void 0;
4
4
  const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
5
5
  const creditAccount_1 = require("../core/creditAccount");
6
6
  const types_1 = require("../types");
7
- class CreditAccountWatcher {
7
+ class CreditAccountWatcherV2 {
8
8
  static IERC20 = types_1.IERC20__factory.createInterface();
9
9
  static creditManagerInterface = types_1.ICreditManagerV2__factory.createInterface();
10
10
  static creditConfiguratorInterface = types_1.ICreditConfiguratorV2__factory.createInterface();
@@ -17,9 +17,7 @@ class CreditAccountWatcher {
17
17
  * @returns Arrays of hashes for opened accounts
18
18
  */
19
19
  static async getOpenAccounts(creditManager, provider, toBlock) {
20
- if (!(creditManager.version === 2 || creditManager.version === 210)) {
21
- throw new Error("Works for V2 only");
22
- }
20
+ CreditAccountWatcherV2.assertCMSupported(creditManager);
23
21
  const eventsByDate = [];
24
22
  const addToEvents = (e, address, operation) => {
25
23
  eventsByDate.push({
@@ -83,7 +81,7 @@ class CreditAccountWatcher {
83
81
  });
84
82
  return Array.from(accounts.values()).map(borrower => creditAccount_1.CreditAccountData.hash(creditManager.address, borrower));
85
83
  }
86
- static async batchCreditAccountLoad(accs, dataCompressor, signer, options) {
84
+ static async batchCreditAccountLoad(accs, dataCompressor210, signer, options) {
87
85
  let chunkSize = 1000;
88
86
  let atBlock;
89
87
  if (typeof options === "object") {
@@ -94,7 +92,7 @@ class CreditAccountWatcher {
94
92
  atBlock = options;
95
93
  }
96
94
  const dcInterface = types_1.IDataCompressorV2_10__factory.createInterface();
97
- const dcmc = new sdk_gov_1.MultiCallContract(dataCompressor, dcInterface, signer);
95
+ const dcmc = new sdk_gov_1.MultiCallContract(dataCompressor210, dcInterface, signer);
98
96
  const calls = [];
99
97
  for (let i = 0; i < accs.length; i++) {
100
98
  const chunk = accs.slice(i * chunkSize, (i + 1) * chunkSize);
@@ -119,7 +117,10 @@ class CreditAccountWatcher {
119
117
  * @returns CreditManagerUpdate which contains updated (created / modified) and deleted accounts
120
118
  */
121
119
  static detectChanges(logs, creditManagers) {
122
- const cms = creditManagers.map(c => c.address.toLowerCase());
120
+ const cms = creditManagers.map(cm => {
121
+ CreditAccountWatcherV2.assertCMSupported(cm);
122
+ return cm.address.toLowerCase();
123
+ });
123
124
  const cfToCm = {};
124
125
  const ccToCm = {};
125
126
  // maps credit manager addr to credit configurator addresses
@@ -135,7 +136,7 @@ class CreditAccountWatcher {
135
136
  for (let log of logs) {
136
137
  const logAddr = log.address.toLowerCase();
137
138
  if (cms.includes(logAddr)) {
138
- const { name, args } = CreditAccountWatcher.creditManagerInterface.parseLog(log);
139
+ const { name, args } = CreditAccountWatcherV2.creditManagerInterface.parseLog(log);
139
140
  if (name === "ExecuteOrder") {
140
141
  const { borrower } = args;
141
142
  if (!borrower)
@@ -151,14 +152,14 @@ class CreditAccountWatcher {
151
152
  }
152
153
  }
153
154
  else if (logAddr in ccToCm) {
154
- const { name, args } = CreditAccountWatcher.creditConfiguratorInterface.parseLog(log);
155
+ const { name, args } = CreditAccountWatcherV2.creditConfiguratorInterface.parseLog(log);
155
156
  if (name === "CreditFacadeUpgraded") {
156
157
  const newCreditFacade = args.newCreditFacade.toLowerCase();
157
158
  cfToCm[newCreditFacade] = ccToCm[logAddr];
158
159
  }
159
160
  }
160
161
  else if (logAddr in cfToCm) {
161
- const { name, args } = CreditAccountWatcher.creditFacadeInterface.parseLog(log);
162
+ const { name, args } = CreditAccountWatcherV2.creditFacadeInterface.parseLog(log);
162
163
  switch (name) {
163
164
  case "OpenCreditAccount":
164
165
  case "AddCollateral": {
@@ -225,7 +226,7 @@ class CreditAccountWatcher {
225
226
  });
226
227
  for (let log of freshLogs) {
227
228
  if (tkns.includes(log.address.toLocaleLowerCase())) {
228
- const { name, args } = CreditAccountWatcher.IERC20.parseLog(log);
229
+ const { name, args } = CreditAccountWatcherV2.IERC20.parseLog(log);
229
230
  if (name === "Transfer" &&
230
231
  accAddresses.includes(args.to.toLowerCase())) {
231
232
  modified.add(accToCa[args.to.toLowerCase()].hash());
@@ -234,5 +235,10 @@ class CreditAccountWatcher {
234
235
  }
235
236
  return Array.from(modified);
236
237
  }
238
+ static assertCMSupported(cm) {
239
+ if (cm.version < 2 || cm.version > 299) {
240
+ throw new Error(`CreditAccountWatcherV2 does not support credit manager version ${cm.version}`);
241
+ }
242
+ }
237
243
  }
238
- exports.CreditAccountWatcher = CreditAccountWatcher;
244
+ exports.CreditAccountWatcherV2 = CreditAccountWatcherV2;
@@ -55,7 +55,7 @@ const newConfiguratorLog = (managerAddr = CREDIT_MANAGER_ADDRESS, configuratorAd
55
55
  ]);
56
56
  describe("CreditAccountTracker test", () => {
57
57
  it("detects update events correctly", () => {
58
- (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([openLog()], [cmDumb])).to.be.eql({
58
+ (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcherV2.detectChanges([openLog()], [cmDumb])).to.be.eql({
59
59
  updated: [expectedHash],
60
60
  deleted: [],
61
61
  });
@@ -63,7 +63,7 @@ describe("CreditAccountTracker test", () => {
63
63
  creditFacadeInterface.getEventTopic("IncreaseBorrowedAmount"),
64
64
  encode("address", BORROWER),
65
65
  ], ethers_1.utils.defaultAbiCoder.encode(["uint256"], [10]));
66
- (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([log], [cmDumb])).to.be.eql({
66
+ (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcherV2.detectChanges([log], [cmDumb])).to.be.eql({
67
67
  updated: [expectedHash],
68
68
  deleted: [],
69
69
  });
@@ -71,7 +71,7 @@ describe("CreditAccountTracker test", () => {
71
71
  creditFacadeInterface.getEventTopic("DecreaseBorrowedAmount"),
72
72
  encode("address", BORROWER),
73
73
  ], ethers_1.utils.defaultAbiCoder.encode(["uint256"], [10]));
74
- (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([log], [cmDumb])).to.be.eql({
74
+ (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcherV2.detectChanges([log], [cmDumb])).to.be.eql({
75
75
  updated: [expectedHash],
76
76
  deleted: [],
77
77
  });
@@ -80,7 +80,7 @@ describe("CreditAccountTracker test", () => {
80
80
  encode("address", BORROWER),
81
81
  encode("address", sdk_gov_1.DUMB_ADDRESS),
82
82
  ], ethers_1.utils.defaultAbiCoder.encode(["uint256"], [10]));
83
- (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([log], [cmDumb])).to.be.eql({
83
+ (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcherV2.detectChanges([log], [cmDumb])).to.be.eql({
84
84
  updated: [expectedHash],
85
85
  deleted: [],
86
86
  });
@@ -88,7 +88,7 @@ describe("CreditAccountTracker test", () => {
88
88
  creditFacadeInterface.getEventTopic("MultiCallStarted"),
89
89
  encode("address", BORROWER),
90
90
  ]);
91
- (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([log], [cmDumb])).to.be.eql({
91
+ (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcherV2.detectChanges([log], [cmDumb])).to.be.eql({
92
92
  updated: [expectedHash],
93
93
  deleted: [],
94
94
  });
@@ -97,7 +97,7 @@ describe("CreditAccountTracker test", () => {
97
97
  encode("address", BORROWER),
98
98
  encode("address", sdk_gov_1.DUMB_ADDRESS),
99
99
  ]);
100
- (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([log], [cmDumb])).to.be.eql({
100
+ (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcherV2.detectChanges([log], [cmDumb])).to.be.eql({
101
101
  updated: [expectedHash],
102
102
  deleted: [],
103
103
  });
@@ -106,7 +106,7 @@ describe("CreditAccountTracker test", () => {
106
106
  encode("address", BORROWER),
107
107
  encode("address", sdk_gov_1.DUMB_ADDRESS),
108
108
  ]);
109
- (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([log], [cmDumb])).to.be.eql({
109
+ (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcherV2.detectChanges([log], [cmDumb])).to.be.eql({
110
110
  updated: [expectedHash],
111
111
  deleted: [],
112
112
  });
@@ -115,7 +115,7 @@ describe("CreditAccountTracker test", () => {
115
115
  encode("address", BORROWER),
116
116
  encode("address", sdk_gov_1.DUMB_ADDRESS),
117
117
  ]);
118
- (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([log], [cmDumb])).to.be.eql({
118
+ (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcherV2.detectChanges([log], [cmDumb])).to.be.eql({
119
119
  updated: [expectedHash],
120
120
  deleted: [],
121
121
  });
@@ -124,7 +124,7 @@ describe("CreditAccountTracker test", () => {
124
124
  // DELETED
125
125
  //
126
126
  it("detects delete events correctly", () => {
127
- (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([closeLog()], [cmDumb])).to.be.eql({
127
+ (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcherV2.detectChanges([closeLog()], [cmDumb])).to.be.eql({
128
128
  updated: [],
129
129
  deleted: [expectedHash],
130
130
  });
@@ -135,7 +135,7 @@ describe("CreditAccountTracker test", () => {
135
135
  encode("address", sdk_gov_1.DUMB_ADDRESS),
136
136
  encode("address", sdk_gov_1.DUMB_ADDRESS),
137
137
  ], ethers_1.utils.defaultAbiCoder.encode(["uint256"], [10]));
138
- (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([log], [cmDumb])).to.be.eql({
138
+ (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcherV2.detectChanges([log], [cmDumb])).to.be.eql({
139
139
  updated: [],
140
140
  deleted: [expectedHash],
141
141
  });
@@ -146,27 +146,27 @@ describe("CreditAccountTracker test", () => {
146
146
  encode("address", sdk_gov_1.DUMB_ADDRESS),
147
147
  encode("address", sdk_gov_1.DUMB_ADDRESS),
148
148
  ], ethers_1.utils.defaultAbiCoder.encode(["uint256"], [10]));
149
- (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([log], [cmDumb])).to.be.eql({
149
+ (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcherV2.detectChanges([log], [cmDumb])).to.be.eql({
150
150
  updated: [],
151
151
  deleted: [expectedHash],
152
152
  });
153
153
  });
154
154
  it("doesn't make duplicated", () => {
155
- (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([openLog(), openLog(), openLog()], [cmDumb])).to.be.eql({
155
+ (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcherV2.detectChanges([openLog(), openLog(), openLog()], [cmDumb])).to.be.eql({
156
156
  updated: [expectedHash],
157
157
  deleted: [],
158
158
  });
159
- (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([closeLog(), closeLog(), closeLog()], [cmDumb])).to.be.eql({
159
+ (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcherV2.detectChanges([closeLog(), closeLog(), closeLog()], [cmDumb])).to.be.eql({
160
160
  updated: [],
161
161
  deleted: [expectedHash],
162
162
  });
163
163
  });
164
164
  it("updates accounts were created and deleted in the batch", () => {
165
- (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([openLog(), closeLog()], [cmDumb])).to.be.eql({
165
+ (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcherV2.detectChanges([openLog(), closeLog()], [cmDumb])).to.be.eql({
166
166
  updated: [],
167
167
  deleted: [expectedHash],
168
168
  });
169
- (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([openLog(), closeLog(), openLog()], [cmDumb])).to.be.eql({
169
+ (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcherV2.detectChanges([openLog(), closeLog(), openLog()], [cmDumb])).to.be.eql({
170
170
  updated: [expectedHash],
171
171
  deleted: [expectedHash],
172
172
  });
@@ -177,7 +177,7 @@ describe("CreditAccountTracker test", () => {
177
177
  encode("address", BORROWER),
178
178
  encode("address", sdk_gov_1.DUMB_ADDRESS),
179
179
  ]);
180
- (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([openLog(), transferLog], [cmDumb])).to.be.eql({
180
+ (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcherV2.detectChanges([openLog(), transferLog], [cmDumb])).to.be.eql({
181
181
  updated: [
182
182
  `${CREDIT_MANAGER_ADDRESS.toLowerCase()}:${sdk_gov_1.DUMB_ADDRESS.toLowerCase()}`,
183
183
  ],
@@ -185,7 +185,7 @@ describe("CreditAccountTracker test", () => {
185
185
  });
186
186
  });
187
187
  it("correctly handles credit configurator change", () => {
188
- (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([
188
+ (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcherV2.detectChanges([
189
189
  openLog(),
190
190
  newConfiguratorLog(),
191
191
  upgradeFacadeLog(),
@@ -194,7 +194,7 @@ describe("CreditAccountTracker test", () => {
194
194
  updated: [],
195
195
  deleted: [expectedHash],
196
196
  });
197
- (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([
197
+ (0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcherV2.detectChanges([
198
198
  openLog(),
199
199
  closeLog(),
200
200
  newConfiguratorLog(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "3.0.0-next.28",
3
+ "version": "3.0.0-next.29",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",