@gearbox-protocol/deploy-tools 5.10.13 → 5.11.0
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/dist/index.mjs +97 -22
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -405570,6 +405570,7 @@ async function evmMineDetailed(client, timestamp) {
|
|
|
405570
405570
|
return void 0;
|
|
405571
405571
|
}
|
|
405572
405572
|
}
|
|
405573
|
+
var DEFAULT_LEVERAGE = 4;
|
|
405573
405574
|
var AccountOpener = class extends SDKConstruct {
|
|
405574
405575
|
#service;
|
|
405575
405576
|
#anvil;
|
|
@@ -405596,7 +405597,14 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
405596
405597
|
/**
|
|
405597
405598
|
* Tries to open account with underlying only in each CM
|
|
405598
405599
|
*/
|
|
405599
|
-
async openCreditAccounts(targets) {
|
|
405600
|
+
async openCreditAccounts(targets, depositIntoPools = true) {
|
|
405601
|
+
if (depositIntoPools) {
|
|
405602
|
+
try {
|
|
405603
|
+
await this.#depositIntoPools(targets);
|
|
405604
|
+
} catch (e) {
|
|
405605
|
+
this.#logger?.warn(`failed to deposit into pools: ${e}`);
|
|
405606
|
+
}
|
|
405607
|
+
}
|
|
405600
405608
|
await this.#prepareBorrower(targets);
|
|
405601
405609
|
const toApprove = new AddressMap();
|
|
405602
405610
|
for (const c of targets) {
|
|
@@ -405630,7 +405638,12 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
405630
405638
|
return results;
|
|
405631
405639
|
}
|
|
405632
405640
|
async #openAccount(input, index2, total) {
|
|
405633
|
-
const {
|
|
405641
|
+
const {
|
|
405642
|
+
creditManager,
|
|
405643
|
+
collateral,
|
|
405644
|
+
leverage = DEFAULT_LEVERAGE,
|
|
405645
|
+
slippage = 50
|
|
405646
|
+
} = input;
|
|
405634
405647
|
const borrower = await this.#getBorrower();
|
|
405635
405648
|
const cm = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
405636
405649
|
const symbol = this.sdk.tokensMeta.symbol(collateral);
|
|
@@ -405750,6 +405763,60 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
405750
405763
|
owner: this.borrower
|
|
405751
405764
|
});
|
|
405752
405765
|
}
|
|
405766
|
+
async #depositIntoPools(targets, multiplier = 10500n) {
|
|
405767
|
+
this.#logger?.debug("checking and topping up pools if necessary");
|
|
405768
|
+
const minAvailableByPool = {};
|
|
405769
|
+
for (const { leverage = DEFAULT_LEVERAGE, creditManager } of targets) {
|
|
405770
|
+
const cm = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
405771
|
+
const { minDebt } = cm.creditFacade;
|
|
405772
|
+
minAvailableByPool[cm.pool] = (minAvailableByPool[cm.pool] ?? 0n) + minDebt * BigInt(leverage - 1) * multiplier / PERCENTAGE_FACTOR;
|
|
405773
|
+
}
|
|
405774
|
+
let totalUSD = 0n;
|
|
405775
|
+
let deposits = [];
|
|
405776
|
+
for (const [p, minAvailable] of Object.entries(minAvailableByPool)) {
|
|
405777
|
+
const market = this.sdk.marketRegister.findByPool(p);
|
|
405778
|
+
const pool = market.pool.pool;
|
|
405779
|
+
let diff = minAvailable - pool.availableLiquidity;
|
|
405780
|
+
diff = diff < 0n ? 0n : diff;
|
|
405781
|
+
const [minS, availableS, diffS] = [
|
|
405782
|
+
minAvailable,
|
|
405783
|
+
pool.availableLiquidity,
|
|
405784
|
+
diff
|
|
405785
|
+
].map((v) => this.sdk.tokensMeta.formatBN(pool.underlying, v));
|
|
405786
|
+
this.#logger?.debug(
|
|
405787
|
+
`Pool ${this.labelAddress(pool.address)} has ${availableS} liquidity, needs ${diffS} more for the minimum of ${minS} ${this.sdk.tokensMeta.symbol(pool.underlying)}`
|
|
405788
|
+
);
|
|
405789
|
+
if (diff > 0n) {
|
|
405790
|
+
deposits.push([pool, diff]);
|
|
405791
|
+
totalUSD += market.priceOracle.convertToUSD(pool.underlying, diff);
|
|
405792
|
+
}
|
|
405793
|
+
}
|
|
405794
|
+
totalUSD = totalUSD * 105n / 100n;
|
|
405795
|
+
this.#logger?.debug(
|
|
405796
|
+
`total USD to claim from faucet: ${formatBN(totalUSD, 8)}`
|
|
405797
|
+
);
|
|
405798
|
+
const depositor = await this.#createAccount();
|
|
405799
|
+
this.#logger?.debug(`created depositor ${depositor.address}`);
|
|
405800
|
+
await this.#claimFromFaucet(depositor, totalUSD);
|
|
405801
|
+
for (const [pool, amount] of deposits) {
|
|
405802
|
+
const poolName = this.sdk.provider.addressLabels.get(pool.address);
|
|
405803
|
+
const amnt = this.sdk.tokensMeta.formatBN(pool.underlying, amount) + " " + this.sdk.tokensMeta.symbol(pool.underlying);
|
|
405804
|
+
this.#logger?.debug(`depositing ${amnt} into pool ${poolName}`);
|
|
405805
|
+
try {
|
|
405806
|
+
await this.#anvil.writeContract({
|
|
405807
|
+
account: depositor,
|
|
405808
|
+
chain: this.#anvil.chain,
|
|
405809
|
+
address: pool.address,
|
|
405810
|
+
abi: iPoolV300Abi,
|
|
405811
|
+
functionName: "deposit",
|
|
405812
|
+
args: [amount, depositor.address]
|
|
405813
|
+
});
|
|
405814
|
+
this.#logger?.debug(`deposited ${amnt} into ${poolName}`);
|
|
405815
|
+
} catch (e) {
|
|
405816
|
+
this.#logger?.warn(`failed to deposit ${amnt} into ${poolName}: ${e}`);
|
|
405817
|
+
}
|
|
405818
|
+
}
|
|
405819
|
+
}
|
|
405753
405820
|
/**
|
|
405754
405821
|
* Creates borrower wallet,
|
|
405755
405822
|
* Sets ETH balance,
|
|
@@ -405775,9 +405842,18 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
405775
405842
|
}
|
|
405776
405843
|
}
|
|
405777
405844
|
claimUSD = claimUSD * 11n / 10n;
|
|
405778
|
-
this.#
|
|
405779
|
-
|
|
405780
|
-
|
|
405845
|
+
await this.#claimFromFaucet(borrower, claimUSD);
|
|
405846
|
+
for (const [degenNFT, amount] of Object.entries(degenNFTS)) {
|
|
405847
|
+
await this.#mintDegenNft(degenNFT, borrower.address, amount);
|
|
405848
|
+
}
|
|
405849
|
+
this.#logger?.debug("prepared borrower");
|
|
405850
|
+
return borrower;
|
|
405851
|
+
}
|
|
405852
|
+
async #claimFromFaucet(claimer, amountUSD) {
|
|
405853
|
+
const [usr, amnt] = [claimer.address, formatBN(amountUSD, 8)];
|
|
405854
|
+
this.#logger?.debug(`account ${usr} claiming ${amnt} USD from faucet`);
|
|
405855
|
+
const hash2 = await this.#anvil.writeContract({
|
|
405856
|
+
account: claimer,
|
|
405781
405857
|
address: this.#faucet,
|
|
405782
405858
|
abi: [
|
|
405783
405859
|
{
|
|
@@ -405791,25 +405867,20 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
405791
405867
|
}
|
|
405792
405868
|
],
|
|
405793
405869
|
functionName: "claim",
|
|
405794
|
-
args: [
|
|
405870
|
+
args: [amountUSD],
|
|
405795
405871
|
chain: this.#anvil.chain
|
|
405796
405872
|
});
|
|
405797
|
-
|
|
405873
|
+
const receipt = await this.#anvil.waitForTransactionReceipt({
|
|
405798
405874
|
hash: hash2
|
|
405799
405875
|
});
|
|
405800
405876
|
if (receipt.status === "reverted") {
|
|
405801
405877
|
throw new Error(
|
|
405802
|
-
`
|
|
405878
|
+
`account ${usr} failed to claimed equivalent of ${amnt} USD from faucet, tx: ${hash2}`
|
|
405803
405879
|
);
|
|
405804
405880
|
}
|
|
405805
405881
|
this.#logger?.debug(
|
|
405806
|
-
`
|
|
405882
|
+
`account ${usr} claimed equivalent of ${amnt} USD from faucet, tx: ${hash2}`
|
|
405807
405883
|
);
|
|
405808
|
-
for (const [degenNFT, amount] of Object.entries(degenNFTS)) {
|
|
405809
|
-
await this.#mintDegenNft(degenNFT, borrower.address, amount);
|
|
405810
|
-
}
|
|
405811
|
-
this.#logger?.debug("prepared borrower");
|
|
405812
|
-
return borrower;
|
|
405813
405884
|
}
|
|
405814
405885
|
async #approve(token, cm) {
|
|
405815
405886
|
const borrower = await this.#getBorrower();
|
|
@@ -405904,15 +405975,19 @@ var AccountOpener = class extends SDKConstruct {
|
|
|
405904
405975
|
}
|
|
405905
405976
|
async #getBorrower() {
|
|
405906
405977
|
if (!this.#borrower) {
|
|
405907
|
-
this.#borrower =
|
|
405908
|
-
await this.#anvil.setBalance({
|
|
405909
|
-
address: this.#borrower.address,
|
|
405910
|
-
value: parseEther("100")
|
|
405911
|
-
});
|
|
405978
|
+
this.#borrower = await this.#createAccount();
|
|
405912
405979
|
this.#logger?.info(`created borrower ${this.#borrower.address}`);
|
|
405913
405980
|
}
|
|
405914
405981
|
return this.#borrower;
|
|
405915
405982
|
}
|
|
405983
|
+
async #createAccount() {
|
|
405984
|
+
const acc = privateKeyToAccount(generatePrivateKey());
|
|
405985
|
+
await this.#anvil.setBalance({
|
|
405986
|
+
address: acc.address,
|
|
405987
|
+
value: parseEther("100")
|
|
405988
|
+
});
|
|
405989
|
+
return acc;
|
|
405990
|
+
}
|
|
405916
405991
|
#getCollateralQuota(cm, collateral, amount, debt) {
|
|
405917
405992
|
const {
|
|
405918
405993
|
underlying,
|
|
@@ -414026,7 +414101,7 @@ function openAccounts() {
|
|
|
414026
414101
|
// DAI
|
|
414027
414102
|
});
|
|
414028
414103
|
}
|
|
414029
|
-
const results = await accountOpener.openCreditAccounts(accounts);
|
|
414104
|
+
const results = await accountOpener.openCreditAccounts(accounts, true);
|
|
414030
414105
|
const destDir = path9.resolve(sharedDir, "open-accounts");
|
|
414031
414106
|
await mkdir2(destDir, { recursive: true });
|
|
414032
414107
|
await writeFile6(
|
|
@@ -414132,7 +414207,7 @@ function getRenderer(opts) {
|
|
|
414132
414207
|
var package_default = {
|
|
414133
414208
|
name: "@gearbox-protocol/deploy-tools",
|
|
414134
414209
|
description: "Gearbox deploy tools",
|
|
414135
|
-
version: "5.
|
|
414210
|
+
version: "5.11.0",
|
|
414136
414211
|
homepage: "https://gearbox.fi",
|
|
414137
414212
|
keywords: [
|
|
414138
414213
|
"gearbox"
|
|
@@ -414175,7 +414250,7 @@ var package_default = {
|
|
|
414175
414250
|
"@gearbox-protocol/deploy-tools-node": "0.0.0",
|
|
414176
414251
|
"@gearbox-protocol/deploy-tools-shared": "0.0.0",
|
|
414177
414252
|
"@gearbox-protocol/deploy-tools-types": "0.0.0",
|
|
414178
|
-
"@gearbox-protocol/sdk": "3.0.0-vfour.
|
|
414253
|
+
"@gearbox-protocol/sdk": "3.0.0-vfour.243",
|
|
414179
414254
|
"@gearbox-protocol/sdk-gov": "^2.34.1",
|
|
414180
414255
|
"@types/lodash-es": "^4.17.12",
|
|
414181
414256
|
"@types/node": "^22.13.1",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gearbox-protocol/deploy-tools",
|
|
3
3
|
"description": "Gearbox deploy tools",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.11.0",
|
|
5
5
|
"homepage": "https://gearbox.fi",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"gearbox"
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@gearbox-protocol/deploy-tools-node": "0.0.0",
|
|
45
45
|
"@gearbox-protocol/deploy-tools-shared": "0.0.0",
|
|
46
46
|
"@gearbox-protocol/deploy-tools-types": "0.0.0",
|
|
47
|
-
"@gearbox-protocol/sdk": "3.0.0-vfour.
|
|
47
|
+
"@gearbox-protocol/sdk": "3.0.0-vfour.243",
|
|
48
48
|
"@gearbox-protocol/sdk-gov": "^2.34.1",
|
|
49
49
|
"@types/lodash-es": "^4.17.12",
|
|
50
50
|
"@types/node": "^22.13.1",
|