@gearbox-protocol/sdk 8.19.3 → 8.19.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.
@@ -39,6 +39,8 @@ class OpenTxRevertedError extends import_viem.BaseError {
39
39
  }
40
40
  }
41
41
  class AccountOpener extends import_sdk.SDKConstruct {
42
+ borrowerKey;
43
+ depositorKey;
42
44
  #service;
43
45
  #anvil;
44
46
  #logger;
@@ -47,8 +49,15 @@ class AccountOpener extends import_sdk.SDKConstruct {
47
49
  #faucet;
48
50
  #poolDepositMultiplier;
49
51
  #minDebtMultiplier;
50
- constructor(service, options = {}) {
52
+ constructor(service, options_ = {}) {
51
53
  super(service.sdk);
54
+ const {
55
+ borrowerKey,
56
+ depositorKey,
57
+ faucet,
58
+ poolDepositMultiplier = 30000n,
59
+ minDebtMultiplier = 10100n
60
+ } = options_;
52
61
  this.#service = service;
53
62
  this.#logger = (0, import_sdk.childLogger)("AccountOpener", service.sdk.logger);
54
63
  this.#anvil = (0, import_createAnvilClient.createAnvilClient)({
@@ -56,20 +65,26 @@ class AccountOpener extends import_sdk.SDKConstruct {
56
65
  transport: service.sdk.provider.transport
57
66
  });
58
67
  try {
59
- this.#faucet = options.faucet ?? service.sdk.addressProvider.getAddress("FAUCET");
68
+ this.#faucet = faucet ?? service.sdk.addressProvider.getAddress("FAUCET");
60
69
  } catch (_e) {
61
70
  this.#logger?.warn("faucet not found, will not claim from faucet");
62
71
  }
63
- this.#borrower = options.borrower;
64
- this.#depositor = options.depositor;
65
- this.#poolDepositMultiplier = options.poolDepositMultiplier ?? 11000n;
66
- this.#minDebtMultiplier = options.minDebtMultiplier ?? 10100n;
72
+ this.borrowerKey = borrowerKey ?? (0, import_accounts.generatePrivateKey)();
73
+ this.depositorKey = depositorKey ?? (0, import_accounts.generatePrivateKey)();
74
+ this.#poolDepositMultiplier = BigInt(poolDepositMultiplier);
75
+ this.#minDebtMultiplier = BigInt(minDebtMultiplier);
67
76
  }
68
77
  get borrower() {
69
78
  if (!this.#borrower) {
70
79
  throw new Error("borrower can be used only after openCreditAccounts");
71
80
  }
72
- return this.#borrower.address;
81
+ return this.#borrower;
82
+ }
83
+ get depositor() {
84
+ if (!this.#depositor) {
85
+ throw new Error("depositor can be used only after openCreditAccounts");
86
+ }
87
+ return this.#depositor;
73
88
  }
74
89
  /**
75
90
  * Tries to open account with underlying only in each CM
@@ -280,7 +295,7 @@ class AccountOpener extends import_sdk.SDKConstruct {
280
295
  }
281
296
  async getOpenedAccounts() {
282
297
  return await this.#service.getCreditAccounts({
283
- owner: this.borrower
298
+ owner: this.borrower.address
284
299
  });
285
300
  }
286
301
  async #depositIntoPools(targets) {
@@ -322,8 +337,8 @@ class AccountOpener extends import_sdk.SDKConstruct {
322
337
  this.#logger?.debug(
323
338
  `total USD to claim from faucet: ${(0, import_sdk.formatBN)(totalUSD, 8)}`
324
339
  );
325
- const depositor = this.#depositor ?? await this.#createAccount();
326
- this.#logger?.debug(`created depositor ${depositor.address}`);
340
+ const depositor = await this.#getDepositor();
341
+ this.#logger?.debug(`depositor: ${depositor.address}`);
327
342
  await this.#claimFromFaucet(depositor, "depositor", totalUSD);
328
343
  const results = [];
329
344
  for (const [pool, amount] of deposits) {
@@ -538,13 +553,20 @@ class AccountOpener extends import_sdk.SDKConstruct {
538
553
  }
539
554
  async #getBorrower() {
540
555
  if (!this.#borrower) {
541
- this.#borrower = await this.#createAccount();
556
+ this.#borrower = await this.#createAccount(this.borrowerKey);
542
557
  this.#logger?.info(`created borrower ${this.#borrower.address}`);
543
558
  }
544
- return this.#borrower;
559
+ return this.borrower;
560
+ }
561
+ async #getDepositor() {
562
+ if (!this.#depositor) {
563
+ this.#depositor = await this.#createAccount(this.depositorKey);
564
+ this.#logger?.info(`created depositor ${this.#depositor.address}`);
565
+ }
566
+ return this.depositor;
545
567
  }
546
- async #createAccount() {
547
- const acc = (0, import_accounts.privateKeyToAccount)((0, import_accounts.generatePrivateKey)());
568
+ async #createAccount(privateKey) {
569
+ const acc = (0, import_accounts.privateKeyToAccount)(privateKey);
548
570
  await this.#anvil.setBalance({
549
571
  address: acc.address,
550
572
  value: (0, import_viem.parseEther)("100")
@@ -21,7 +21,9 @@ __export(PriceFeedsRegister_exports, {
21
21
  PriceFeedRegister: () => PriceFeedRegister
22
22
  });
23
23
  module.exports = __toCommonJS(PriceFeedsRegister_exports);
24
+ var import_viem = require("viem");
24
25
  var import_compressors = require("../../../abi/compressors.js");
26
+ var import_iUpdatablePriceFeed = require("../../../abi/iUpdatablePriceFeed.js");
25
27
  var import_base = require("../../base/index.js");
26
28
  var import_constants = require("../../constants/index.js");
27
29
  var import_utils = require("../../utils/index.js");
@@ -135,10 +137,16 @@ class PriceFeedRegister extends import_base.SDKConstruct {
135
137
  feeds,
136
138
  block
137
139
  );
138
- return txs.map((tx) => ({
139
- priceFeed: tx.data.priceFeed,
140
- data: tx.raw.callData
141
- }));
140
+ return txs.map((tx) => {
141
+ const data = (0, import_viem.decodeFunctionData)({
142
+ abi: import_iUpdatablePriceFeed.iUpdatablePriceFeedAbi,
143
+ data: tx.raw.callData
144
+ });
145
+ return {
146
+ priceFeed: tx.raw.to,
147
+ data: data.args[0]
148
+ };
149
+ });
142
150
  }
143
151
  has(address) {
144
152
  return this.#feeds.has(address);
@@ -31,6 +31,8 @@ class OpenTxRevertedError extends BaseError {
31
31
  }
32
32
  }
33
33
  class AccountOpener extends SDKConstruct {
34
+ borrowerKey;
35
+ depositorKey;
34
36
  #service;
35
37
  #anvil;
36
38
  #logger;
@@ -39,8 +41,15 @@ class AccountOpener extends SDKConstruct {
39
41
  #faucet;
40
42
  #poolDepositMultiplier;
41
43
  #minDebtMultiplier;
42
- constructor(service, options = {}) {
44
+ constructor(service, options_ = {}) {
43
45
  super(service.sdk);
46
+ const {
47
+ borrowerKey,
48
+ depositorKey,
49
+ faucet,
50
+ poolDepositMultiplier = 30000n,
51
+ minDebtMultiplier = 10100n
52
+ } = options_;
44
53
  this.#service = service;
45
54
  this.#logger = childLogger("AccountOpener", service.sdk.logger);
46
55
  this.#anvil = createAnvilClient({
@@ -48,20 +57,26 @@ class AccountOpener extends SDKConstruct {
48
57
  transport: service.sdk.provider.transport
49
58
  });
50
59
  try {
51
- this.#faucet = options.faucet ?? service.sdk.addressProvider.getAddress("FAUCET");
60
+ this.#faucet = faucet ?? service.sdk.addressProvider.getAddress("FAUCET");
52
61
  } catch (_e) {
53
62
  this.#logger?.warn("faucet not found, will not claim from faucet");
54
63
  }
55
- this.#borrower = options.borrower;
56
- this.#depositor = options.depositor;
57
- this.#poolDepositMultiplier = options.poolDepositMultiplier ?? 11000n;
58
- this.#minDebtMultiplier = options.minDebtMultiplier ?? 10100n;
64
+ this.borrowerKey = borrowerKey ?? generatePrivateKey();
65
+ this.depositorKey = depositorKey ?? generatePrivateKey();
66
+ this.#poolDepositMultiplier = BigInt(poolDepositMultiplier);
67
+ this.#minDebtMultiplier = BigInt(minDebtMultiplier);
59
68
  }
60
69
  get borrower() {
61
70
  if (!this.#borrower) {
62
71
  throw new Error("borrower can be used only after openCreditAccounts");
63
72
  }
64
- return this.#borrower.address;
73
+ return this.#borrower;
74
+ }
75
+ get depositor() {
76
+ if (!this.#depositor) {
77
+ throw new Error("depositor can be used only after openCreditAccounts");
78
+ }
79
+ return this.#depositor;
65
80
  }
66
81
  /**
67
82
  * Tries to open account with underlying only in each CM
@@ -272,7 +287,7 @@ class AccountOpener extends SDKConstruct {
272
287
  }
273
288
  async getOpenedAccounts() {
274
289
  return await this.#service.getCreditAccounts({
275
- owner: this.borrower
290
+ owner: this.borrower.address
276
291
  });
277
292
  }
278
293
  async #depositIntoPools(targets) {
@@ -314,8 +329,8 @@ class AccountOpener extends SDKConstruct {
314
329
  this.#logger?.debug(
315
330
  `total USD to claim from faucet: ${formatBN(totalUSD, 8)}`
316
331
  );
317
- const depositor = this.#depositor ?? await this.#createAccount();
318
- this.#logger?.debug(`created depositor ${depositor.address}`);
332
+ const depositor = await this.#getDepositor();
333
+ this.#logger?.debug(`depositor: ${depositor.address}`);
319
334
  await this.#claimFromFaucet(depositor, "depositor", totalUSD);
320
335
  const results = [];
321
336
  for (const [pool, amount] of deposits) {
@@ -530,13 +545,20 @@ class AccountOpener extends SDKConstruct {
530
545
  }
531
546
  async #getBorrower() {
532
547
  if (!this.#borrower) {
533
- this.#borrower = await this.#createAccount();
548
+ this.#borrower = await this.#createAccount(this.borrowerKey);
534
549
  this.#logger?.info(`created borrower ${this.#borrower.address}`);
535
550
  }
536
- return this.#borrower;
551
+ return this.borrower;
552
+ }
553
+ async #getDepositor() {
554
+ if (!this.#depositor) {
555
+ this.#depositor = await this.#createAccount(this.depositorKey);
556
+ this.#logger?.info(`created depositor ${this.#depositor.address}`);
557
+ }
558
+ return this.depositor;
537
559
  }
538
- async #createAccount() {
539
- const acc = privateKeyToAccount(generatePrivateKey());
560
+ async #createAccount(privateKey) {
561
+ const acc = privateKeyToAccount(privateKey);
540
562
  await this.#anvil.setBalance({
541
563
  address: acc.address,
542
564
  value: parseEther("100")
@@ -1,4 +1,8 @@
1
+ import {
2
+ decodeFunctionData
3
+ } from "viem";
1
4
  import { iPriceFeedCompressorAbi } from "../../../abi/compressors.js";
5
+ import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
2
6
  import { SDKConstruct } from "../../base/index.js";
3
7
  import {
4
8
  ADDRESS_0X0,
@@ -118,10 +122,16 @@ class PriceFeedRegister extends SDKConstruct {
118
122
  feeds,
119
123
  block
120
124
  );
121
- return txs.map((tx) => ({
122
- priceFeed: tx.data.priceFeed,
123
- data: tx.raw.callData
124
- }));
125
+ return txs.map((tx) => {
126
+ const data = decodeFunctionData({
127
+ abi: iUpdatablePriceFeedAbi,
128
+ data: tx.raw.callData
129
+ });
130
+ return {
131
+ priceFeed: tx.raw.to,
132
+ data: data.args[0]
133
+ };
134
+ });
125
135
  }
126
136
  has(address) {
127
137
  return this.#feeds.has(address);
@@ -8,10 +8,10 @@ export declare class OpenTxRevertedError extends BaseError {
8
8
  }
9
9
  export interface AccountOpenerOptions {
10
10
  faucet?: Address;
11
- borrower?: PrivateKeyAccount;
12
- depositor?: PrivateKeyAccount;
13
- poolDepositMultiplier?: bigint;
14
- minDebtMultiplier?: bigint;
11
+ borrowerKey?: Hex;
12
+ depositorKey?: Hex;
13
+ poolDepositMultiplier?: bigint | string | number;
14
+ minDebtMultiplier?: bigint | string | number;
15
15
  }
16
16
  export interface TargetAccount {
17
17
  creditManager: Address;
@@ -59,8 +59,11 @@ export interface OpenAccountsResult {
59
59
  }
60
60
  export declare class AccountOpener extends SDKConstruct {
61
61
  #private;
62
- constructor(service: ICreditAccountsService, options?: AccountOpenerOptions);
63
- get borrower(): Address;
62
+ readonly borrowerKey: Hex;
63
+ readonly depositorKey: Hex;
64
+ constructor(service: ICreditAccountsService, options_?: AccountOpenerOptions);
65
+ get borrower(): PrivateKeyAccount;
66
+ get depositor(): PrivateKeyAccount;
64
67
  /**
65
68
  * Tries to open account with underlying only in each CM
66
69
  */
@@ -1,4 +1,4 @@
1
- import type { Address, BlockTag, Hex } from "viem";
1
+ import { type Address, type BlockTag, type Hex } from "viem";
2
2
  import type { PriceFeedTreeNode } from "../../base/index.js";
3
3
  import { SDKConstruct } from "../../base/index.js";
4
4
  import type { GearboxSDK } from "../../GearboxSDK.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "8.19.3",
3
+ "version": "8.19.5",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",