@gearbox-protocol/sdk 13.0.0-next.13 → 13.0.0-next.14
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.
|
@@ -52,6 +52,7 @@ class AccountOpener extends import_sdk.SDKConstruct {
|
|
|
52
52
|
#minDebtMultiplier;
|
|
53
53
|
#allowMint;
|
|
54
54
|
#leverageDelta;
|
|
55
|
+
#poolService;
|
|
55
56
|
constructor(service, options_ = {}) {
|
|
56
57
|
super(service.sdk);
|
|
57
58
|
const {
|
|
@@ -77,6 +78,7 @@ class AccountOpener extends import_sdk.SDKConstruct {
|
|
|
77
78
|
this.#poolDepositMultiplier = BigInt(poolDepositMultiplier);
|
|
78
79
|
this.#minDebtMultiplier = BigInt(minDebtMultiplier);
|
|
79
80
|
this.#leverageDelta = BigInt(leverageDelta);
|
|
81
|
+
this.#poolService = new import_sdk.PoolService(service.sdk);
|
|
80
82
|
this.#logger?.info(
|
|
81
83
|
{
|
|
82
84
|
borrower: (0, import_accounts.privateKeyToAccount)(this.borrowerKey).address,
|
|
@@ -114,6 +116,10 @@ class AccountOpener extends import_sdk.SDKConstruct {
|
|
|
114
116
|
},
|
|
115
117
|
"opening credit accounts"
|
|
116
118
|
);
|
|
119
|
+
await Promise.all([
|
|
120
|
+
this.sdk.tokensMeta.loadTokenData(),
|
|
121
|
+
this.sdk.marketRegister.loadZappers()
|
|
122
|
+
]);
|
|
117
123
|
let deposits = [];
|
|
118
124
|
if (depositIntoPools) {
|
|
119
125
|
try {
|
|
@@ -465,9 +471,30 @@ class AccountOpener extends import_sdk.SDKConstruct {
|
|
|
465
471
|
this.#logger?.debug(
|
|
466
472
|
`depositor balance in underlying: ${this.sdk.tokensMeta.formatBN(pool.underlying, allowance, { symbol: true })}`
|
|
467
473
|
);
|
|
474
|
+
const tokensOut = this.#poolService.getDepositTokensOut(
|
|
475
|
+
address,
|
|
476
|
+
underlying
|
|
477
|
+
);
|
|
478
|
+
if (tokensOut.length === 0) {
|
|
479
|
+
throw new Error(`no tokens out found for pool ${poolName}`);
|
|
480
|
+
}
|
|
481
|
+
const tokenOut = tokensOut[0];
|
|
482
|
+
const metadata = this.#poolService.getDepositMetadata(
|
|
483
|
+
address,
|
|
484
|
+
underlying,
|
|
485
|
+
tokenOut
|
|
486
|
+
);
|
|
487
|
+
this.logger?.debug(
|
|
488
|
+
{
|
|
489
|
+
underlying,
|
|
490
|
+
tokenOut,
|
|
491
|
+
...metadata
|
|
492
|
+
},
|
|
493
|
+
"pool deposit metadata"
|
|
494
|
+
);
|
|
468
495
|
txHash = await this.#anvil.writeContract({
|
|
469
496
|
account: depositor,
|
|
470
|
-
address:
|
|
497
|
+
address: metadata.approveTarget,
|
|
471
498
|
abi: import_iERC20.ierc20Abi,
|
|
472
499
|
functionName: "approve",
|
|
473
500
|
args: [address, allowance],
|
|
@@ -484,12 +511,21 @@ class AccountOpener extends import_sdk.SDKConstruct {
|
|
|
484
511
|
this.#logger?.debug(
|
|
485
512
|
`depositor approved underlying for pool ${poolName}: ${txHash}`
|
|
486
513
|
);
|
|
514
|
+
const depositCall = this.#poolService.addLiquidity({
|
|
515
|
+
collateral: { token: underlying, balance: amount },
|
|
516
|
+
pool: address,
|
|
517
|
+
wallet: depositor.address,
|
|
518
|
+
meta: metadata
|
|
519
|
+
});
|
|
520
|
+
if (!depositCall) {
|
|
521
|
+
throw new Error(`no deposit call could be created for ${poolName}`);
|
|
522
|
+
}
|
|
487
523
|
txHash = await this.#anvil.writeContract({
|
|
488
524
|
account: depositor,
|
|
489
|
-
address,
|
|
490
|
-
abi:
|
|
491
|
-
functionName:
|
|
492
|
-
args:
|
|
525
|
+
address: depositCall.target,
|
|
526
|
+
abi: depositCall.abi,
|
|
527
|
+
functionName: depositCall.functionName,
|
|
528
|
+
args: depositCall.args,
|
|
493
529
|
chain: this.#anvil.chain
|
|
494
530
|
});
|
|
495
531
|
receipt = await this.#anvil.waitForTransactionReceipt({ hash: txHash });
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "viem";
|
|
8
8
|
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
|
|
9
9
|
import { ierc20Abi } from "../abi/iERC20.js";
|
|
10
|
-
import { iCreditFacadeV300Abi
|
|
10
|
+
import { iCreditFacadeV300Abi } from "../abi/v300.js";
|
|
11
11
|
import {
|
|
12
12
|
ADDRESS_0X0,
|
|
13
13
|
AddressMap,
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
childLogger,
|
|
16
16
|
MAX_UINT256,
|
|
17
17
|
PERCENTAGE_FACTOR,
|
|
18
|
+
PoolService,
|
|
18
19
|
SDKConstruct,
|
|
19
20
|
sendRawTx
|
|
20
21
|
} from "../sdk/index.js";
|
|
@@ -43,6 +44,7 @@ class AccountOpener extends SDKConstruct {
|
|
|
43
44
|
#minDebtMultiplier;
|
|
44
45
|
#allowMint;
|
|
45
46
|
#leverageDelta;
|
|
47
|
+
#poolService;
|
|
46
48
|
constructor(service, options_ = {}) {
|
|
47
49
|
super(service.sdk);
|
|
48
50
|
const {
|
|
@@ -68,6 +70,7 @@ class AccountOpener extends SDKConstruct {
|
|
|
68
70
|
this.#poolDepositMultiplier = BigInt(poolDepositMultiplier);
|
|
69
71
|
this.#minDebtMultiplier = BigInt(minDebtMultiplier);
|
|
70
72
|
this.#leverageDelta = BigInt(leverageDelta);
|
|
73
|
+
this.#poolService = new PoolService(service.sdk);
|
|
71
74
|
this.#logger?.info(
|
|
72
75
|
{
|
|
73
76
|
borrower: privateKeyToAccount(this.borrowerKey).address,
|
|
@@ -105,6 +108,10 @@ class AccountOpener extends SDKConstruct {
|
|
|
105
108
|
},
|
|
106
109
|
"opening credit accounts"
|
|
107
110
|
);
|
|
111
|
+
await Promise.all([
|
|
112
|
+
this.sdk.tokensMeta.loadTokenData(),
|
|
113
|
+
this.sdk.marketRegister.loadZappers()
|
|
114
|
+
]);
|
|
108
115
|
let deposits = [];
|
|
109
116
|
if (depositIntoPools) {
|
|
110
117
|
try {
|
|
@@ -456,9 +463,30 @@ class AccountOpener extends SDKConstruct {
|
|
|
456
463
|
this.#logger?.debug(
|
|
457
464
|
`depositor balance in underlying: ${this.sdk.tokensMeta.formatBN(pool.underlying, allowance, { symbol: true })}`
|
|
458
465
|
);
|
|
466
|
+
const tokensOut = this.#poolService.getDepositTokensOut(
|
|
467
|
+
address,
|
|
468
|
+
underlying
|
|
469
|
+
);
|
|
470
|
+
if (tokensOut.length === 0) {
|
|
471
|
+
throw new Error(`no tokens out found for pool ${poolName}`);
|
|
472
|
+
}
|
|
473
|
+
const tokenOut = tokensOut[0];
|
|
474
|
+
const metadata = this.#poolService.getDepositMetadata(
|
|
475
|
+
address,
|
|
476
|
+
underlying,
|
|
477
|
+
tokenOut
|
|
478
|
+
);
|
|
479
|
+
this.logger?.debug(
|
|
480
|
+
{
|
|
481
|
+
underlying,
|
|
482
|
+
tokenOut,
|
|
483
|
+
...metadata
|
|
484
|
+
},
|
|
485
|
+
"pool deposit metadata"
|
|
486
|
+
);
|
|
459
487
|
txHash = await this.#anvil.writeContract({
|
|
460
488
|
account: depositor,
|
|
461
|
-
address:
|
|
489
|
+
address: metadata.approveTarget,
|
|
462
490
|
abi: ierc20Abi,
|
|
463
491
|
functionName: "approve",
|
|
464
492
|
args: [address, allowance],
|
|
@@ -475,12 +503,21 @@ class AccountOpener extends SDKConstruct {
|
|
|
475
503
|
this.#logger?.debug(
|
|
476
504
|
`depositor approved underlying for pool ${poolName}: ${txHash}`
|
|
477
505
|
);
|
|
506
|
+
const depositCall = this.#poolService.addLiquidity({
|
|
507
|
+
collateral: { token: underlying, balance: amount },
|
|
508
|
+
pool: address,
|
|
509
|
+
wallet: depositor.address,
|
|
510
|
+
meta: metadata
|
|
511
|
+
});
|
|
512
|
+
if (!depositCall) {
|
|
513
|
+
throw new Error(`no deposit call could be created for ${poolName}`);
|
|
514
|
+
}
|
|
478
515
|
txHash = await this.#anvil.writeContract({
|
|
479
516
|
account: depositor,
|
|
480
|
-
address,
|
|
481
|
-
abi:
|
|
482
|
-
functionName:
|
|
483
|
-
args:
|
|
517
|
+
address: depositCall.target,
|
|
518
|
+
abi: depositCall.abi,
|
|
519
|
+
functionName: depositCall.functionName,
|
|
520
|
+
args: depositCall.args,
|
|
484
521
|
chain: this.#anvil.chain
|
|
485
522
|
});
|
|
486
523
|
receipt = await this.#anvil.waitForTransactionReceipt({ hash: txHash });
|