@gearbox-protocol/sdk 8.19.3 → 8.19.4
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,
|
|
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 =
|
|
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
|
|
64
|
-
this
|
|
65
|
-
this.#poolDepositMultiplier =
|
|
66
|
-
this.#minDebtMultiplier =
|
|
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
|
|
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 =
|
|
326
|
-
this.#logger?.debug(`
|
|
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
|
|
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)(
|
|
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")
|
|
@@ -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,
|
|
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 =
|
|
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
|
|
56
|
-
this
|
|
57
|
-
this.#poolDepositMultiplier =
|
|
58
|
-
this.#minDebtMultiplier =
|
|
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
|
|
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 =
|
|
318
|
-
this.#logger?.debug(`
|
|
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
|
|
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(
|
|
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")
|
|
@@ -8,10 +8,10 @@ export declare class OpenTxRevertedError extends BaseError {
|
|
|
8
8
|
}
|
|
9
9
|
export interface AccountOpenerOptions {
|
|
10
10
|
faucet?: Address;
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
63
|
-
|
|
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
|
*/
|