@gearbox-protocol/deploy-tools 5.10.13 → 5.11.1

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.
Files changed (2) hide show
  1. package/dist/index.mjs +131 -22
  2. 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 { creditManager, collateral, leverage = 4, slippage = 50 } = input;
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,94 @@ 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
+ try {
405803
+ await this.#depositToPool(pool, depositor, amount);
405804
+ } catch (e) {
405805
+ this.#logger?.warn(`failed to deposit into ${pool.name}: ${e}`);
405806
+ }
405807
+ }
405808
+ }
405809
+ async #depositToPool(pool, depositor, amount) {
405810
+ const { underlying, address } = pool;
405811
+ const poolName = this.sdk.provider.addressLabels.get(address);
405812
+ const amnt = this.sdk.tokensMeta.formatBN(pool.underlying, amount) + " " + this.sdk.tokensMeta.symbol(pool.underlying);
405813
+ this.#logger?.debug(`depositing ${amnt} into pool ${poolName}`);
405814
+ const allowance = await this.#anvil.readContract({
405815
+ address: underlying,
405816
+ abi: ierc20Abi,
405817
+ functionName: "balanceOf",
405818
+ args: [depositor.address]
405819
+ });
405820
+ this.#logger?.debug(
405821
+ `depositor balance in underlying: ${this.sdk.tokensMeta.formatBN(pool.underlying, allowance)}`
405822
+ );
405823
+ let hash2 = await this.#anvil.writeContract({
405824
+ account: depositor,
405825
+ address: underlying,
405826
+ abi: ierc20Abi,
405827
+ functionName: "approve",
405828
+ args: [address, allowance],
405829
+ chain: this.#anvil.chain
405830
+ });
405831
+ let receipt = await this.#anvil.waitForTransactionReceipt({ hash: hash2 });
405832
+ if (receipt.status === "reverted") {
405833
+ throw new Error(
405834
+ `tx ${hash2} that approves underlying from depositor for pool ${poolName} reverted`
405835
+ );
405836
+ }
405837
+ this.#logger?.debug(
405838
+ `depositor approved underlying for pool ${poolName}: ${hash2}`
405839
+ );
405840
+ hash2 = await this.#anvil.writeContract({
405841
+ account: depositor,
405842
+ address,
405843
+ abi: iPoolV300Abi,
405844
+ functionName: "deposit",
405845
+ args: [amount, depositor.address],
405846
+ chain: this.#anvil.chain
405847
+ });
405848
+ receipt = await this.#anvil.waitForTransactionReceipt({ hash: hash2 });
405849
+ if (receipt.status === "reverted") {
405850
+ throw new Error(`tx ${hash2} that deposits to pool ${poolName} reverted`);
405851
+ }
405852
+ this.#logger?.debug(`deposited ${amnt} into ${poolName}`);
405853
+ }
405753
405854
  /**
405754
405855
  * Creates borrower wallet,
405755
405856
  * Sets ETH balance,
@@ -405775,9 +405876,18 @@ var AccountOpener = class extends SDKConstruct {
405775
405876
  }
405776
405877
  }
405777
405878
  claimUSD = claimUSD * 11n / 10n;
405778
- this.#logger?.debug(`claiming ${formatBN(claimUSD, 8)} USD from faucet`);
405779
- let hash2 = await this.#anvil.writeContract({
405780
- account: borrower,
405879
+ await this.#claimFromFaucet(borrower, claimUSD);
405880
+ for (const [degenNFT, amount] of Object.entries(degenNFTS)) {
405881
+ await this.#mintDegenNft(degenNFT, borrower.address, amount);
405882
+ }
405883
+ this.#logger?.debug("prepared borrower");
405884
+ return borrower;
405885
+ }
405886
+ async #claimFromFaucet(claimer, amountUSD) {
405887
+ const [usr, amnt] = [claimer.address, formatBN(amountUSD, 8)];
405888
+ this.#logger?.debug(`account ${usr} claiming ${amnt} USD from faucet`);
405889
+ const hash2 = await this.#anvil.writeContract({
405890
+ account: claimer,
405781
405891
  address: this.#faucet,
405782
405892
  abi: [
405783
405893
  {
@@ -405791,25 +405901,20 @@ var AccountOpener = class extends SDKConstruct {
405791
405901
  }
405792
405902
  ],
405793
405903
  functionName: "claim",
405794
- args: [claimUSD],
405904
+ args: [amountUSD],
405795
405905
  chain: this.#anvil.chain
405796
405906
  });
405797
- let receipt = await this.#anvil.waitForTransactionReceipt({
405907
+ const receipt = await this.#anvil.waitForTransactionReceipt({
405798
405908
  hash: hash2
405799
405909
  });
405800
405910
  if (receipt.status === "reverted") {
405801
405911
  throw new Error(
405802
- `borrower ${borrower.address} failed to claimed equivalent of ${formatBN(claimUSD, 8)} USD from faucet, tx: ${hash2}`
405912
+ `account ${usr} failed to claimed equivalent of ${amnt} USD from faucet, tx: ${hash2}`
405803
405913
  );
405804
405914
  }
405805
405915
  this.#logger?.debug(
405806
- `borrower ${borrower.address} claimed equivalent of ${formatBN(claimUSD, 8)} USD from faucet, tx: ${hash2}`
405916
+ `account ${usr} claimed equivalent of ${amnt} USD from faucet, tx: ${hash2}`
405807
405917
  );
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
405918
  }
405814
405919
  async #approve(token, cm) {
405815
405920
  const borrower = await this.#getBorrower();
@@ -405904,15 +406009,19 @@ var AccountOpener = class extends SDKConstruct {
405904
406009
  }
405905
406010
  async #getBorrower() {
405906
406011
  if (!this.#borrower) {
405907
- this.#borrower = privateKeyToAccount(generatePrivateKey());
405908
- await this.#anvil.setBalance({
405909
- address: this.#borrower.address,
405910
- value: parseEther("100")
405911
- });
406012
+ this.#borrower = await this.#createAccount();
405912
406013
  this.#logger?.info(`created borrower ${this.#borrower.address}`);
405913
406014
  }
405914
406015
  return this.#borrower;
405915
406016
  }
406017
+ async #createAccount() {
406018
+ const acc = privateKeyToAccount(generatePrivateKey());
406019
+ await this.#anvil.setBalance({
406020
+ address: acc.address,
406021
+ value: parseEther("100")
406022
+ });
406023
+ return acc;
406024
+ }
405916
406025
  #getCollateralQuota(cm, collateral, amount, debt) {
405917
406026
  const {
405918
406027
  underlying,
@@ -414026,7 +414135,7 @@ function openAccounts() {
414026
414135
  // DAI
414027
414136
  });
414028
414137
  }
414029
- const results = await accountOpener.openCreditAccounts(accounts);
414138
+ const results = await accountOpener.openCreditAccounts(accounts, true);
414030
414139
  const destDir = path9.resolve(sharedDir, "open-accounts");
414031
414140
  await mkdir2(destDir, { recursive: true });
414032
414141
  await writeFile6(
@@ -414132,7 +414241,7 @@ function getRenderer(opts) {
414132
414241
  var package_default = {
414133
414242
  name: "@gearbox-protocol/deploy-tools",
414134
414243
  description: "Gearbox deploy tools",
414135
- version: "5.10.13",
414244
+ version: "5.11.1",
414136
414245
  homepage: "https://gearbox.fi",
414137
414246
  keywords: [
414138
414247
  "gearbox"
@@ -414175,7 +414284,7 @@ var package_default = {
414175
414284
  "@gearbox-protocol/deploy-tools-node": "0.0.0",
414176
414285
  "@gearbox-protocol/deploy-tools-shared": "0.0.0",
414177
414286
  "@gearbox-protocol/deploy-tools-types": "0.0.0",
414178
- "@gearbox-protocol/sdk": "3.0.0-vfour.242",
414287
+ "@gearbox-protocol/sdk": "3.0.0-vfour.244",
414179
414288
  "@gearbox-protocol/sdk-gov": "^2.34.1",
414180
414289
  "@types/lodash-es": "^4.17.12",
414181
414290
  "@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.10.13",
4
+ "version": "5.11.1",
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.242",
47
+ "@gearbox-protocol/sdk": "3.0.0-vfour.244",
48
48
  "@gearbox-protocol/sdk-gov": "^2.34.1",
49
49
  "@types/lodash-es": "^4.17.12",
50
50
  "@types/node": "^22.13.1",