@gearbox-protocol/deploy-tools 5.3.26 → 5.3.28

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 +67 -48
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -375989,7 +375989,7 @@ var PoolQuotaKeeperContract = class extends BaseContract {
375989
375989
  quotas: this.quotas.entries().reduce(
375990
375990
  (acc, [address, params]) => ({
375991
375991
  ...acc,
375992
- [address]: {
375992
+ [this.labelAddress(address)]: {
375993
375993
  rate: percentFmt(params.rate, raw),
375994
375994
  quotaIncreaseFee: percentFmt(params.quotaIncreaseFee, raw),
375995
375995
  totalQuoted: formatBNvalue(
@@ -376023,7 +376023,7 @@ var PoolQuotaKeeperContract = class extends BaseContract {
376023
376023
  }
376024
376024
  }
376025
376025
  };
376026
- var PoolFactory = class extends SDKConstruct {
376026
+ var PoolSuite = class extends SDKConstruct {
376027
376027
  pool;
376028
376028
  pqk;
376029
376029
  gauge;
@@ -383422,16 +383422,10 @@ var PriceOracleBaseContract = class extends BaseContract {
383422
383422
  return {
383423
383423
  ...super.stateHuman(raw),
383424
383424
  mainPriceFeeds: Object.fromEntries(
383425
- this.mainPriceFeeds.entries().map(([token, v]) => [
383426
- this.labelAddress(token),
383427
- v.stateHuman(raw)
383428
- ])
383425
+ this.mainPriceFeeds.entries().map(([token, v]) => [this.labelAddress(token), v.stateHuman(raw)])
383429
383426
  ),
383430
383427
  reservePriceFeeds: Object.fromEntries(
383431
- this.reservePriceFeeds.entries().map(([token, v]) => [
383432
- this.labelAddress(token),
383433
- v.stateHuman(raw)
383434
- ])
383428
+ this.reservePriceFeeds.entries().map(([token, v]) => [this.labelAddress(token), v.stateHuman(raw)])
383435
383429
  )
383436
383430
  };
383437
383431
  }
@@ -383512,7 +383506,7 @@ var PriceOracleV310Contract = class extends PriceOracleBaseContract {
383512
383506
  var MarketSuite = class extends SDKConstruct {
383513
383507
  acl;
383514
383508
  configurator;
383515
- poolFactory;
383509
+ pool;
383516
383510
  priceOracle;
383517
383511
  creditManagers = [];
383518
383512
  /**
@@ -383542,7 +383536,7 @@ var MarketSuite = class extends SDKConstruct {
383542
383536
  sdk.tokensMeta.upsert(t.addr, t);
383543
383537
  sdk.provider.addressLabels.set(t.addr, t.symbol);
383544
383538
  }
383545
- this.poolFactory = new PoolFactory(sdk, marketData);
383539
+ this.pool = new PoolSuite(sdk, marketData);
383546
383540
  this.zappers = marketData.zappers;
383547
383541
  for (let i = 0; i < marketData.creditManagers.length; i++) {
383548
383542
  this.creditManagers.push(new CreditSuite(sdk, marketData, i));
@@ -383562,11 +383556,11 @@ var MarketSuite = class extends SDKConstruct {
383562
383556
  }
383563
383557
  }
383564
383558
  get dirty() {
383565
- return this.configurator.dirty || this.poolFactory.dirty || this.priceOracle.dirty || this.creditManagers.some((cm) => cm.dirty);
383559
+ return this.configurator.dirty || this.pool.dirty || this.priceOracle.dirty || this.creditManagers.some((cm) => cm.dirty);
383566
383560
  }
383567
383561
  stateHuman(raw = true) {
383568
383562
  return {
383569
- pool: this.poolFactory.stateHuman(raw),
383563
+ pool: this.pool.stateHuman(raw),
383570
383564
  creditManagers: this.creditManagers.map((cm) => cm.stateHuman(raw)),
383571
383565
  priceOracle: this.priceOracle.stateHuman(raw),
383572
383566
  pausableAdmins: this.state.pausableAdmins.map((a) => this.labelAddress(a)),
@@ -383612,7 +383606,7 @@ var MarketRegister = class extends SDKConstruct {
383612
383606
  await this.#loadMarkets(marketConfigurators, [], ignoreUpdateablePrices);
383613
383607
  }
383614
383608
  async syncState() {
383615
- const pools = this.markets.filter((m) => m.dirty).map((m) => m.poolFactory.pool.address);
383609
+ const pools = this.markets.filter((m) => m.dirty).map((m) => m.pool.pool.address);
383616
383610
  if (pools.length) {
383617
383611
  this.#logger?.debug(`need to reload ${pools.length} markets`);
383618
383612
  await this.#loadMarkets([], pools);
@@ -383697,7 +383691,7 @@ var MarketRegister = class extends SDKConstruct {
383697
383691
  return this.markets.map((market) => market.stateHuman(raw));
383698
383692
  }
383699
383693
  get pools() {
383700
- return this.markets.map((market) => market.poolFactory);
383694
+ return this.markets.map((market) => market.pool);
383701
383695
  }
383702
383696
  get creditManagers() {
383703
383697
  return this.markets.flatMap((market) => market.creditManagers);
@@ -384592,8 +384586,8 @@ var CreditAccountsService = class extends SDKConstruct {
384592
384586
  to,
384593
384587
  calls: openPathCalls
384594
384588
  } = props;
384595
- const cmFactory = this.sdk.marketRegister.findCreditManager(creditManager);
384596
- const cm = cmFactory.creditManager;
384589
+ const cmSuite = this.sdk.marketRegister.findCreditManager(creditManager);
384590
+ const cm = cmSuite.creditManager;
384597
384591
  const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
384598
384592
  cm.address,
384599
384593
  void 0,
@@ -384607,13 +384601,9 @@ var CreditAccountsService = class extends SDKConstruct {
384607
384601
  ...openPathCalls,
384608
384602
  ...withdrawDebt ? [this.#prepareWithdrawToken(cm.creditFacade, cm.underlying, debt, to)] : []
384609
384603
  ];
384610
- const tx = cmFactory.creditFacade.openCreditAccount(
384611
- to,
384612
- calls,
384613
- referralCode
384614
- );
384604
+ const tx = cmSuite.creditFacade.openCreditAccount(to, calls, referralCode);
384615
384605
  tx.value = ethAmount.toString(10);
384616
- return { calls, tx, creditFacade: cmFactory.creditFacade };
384606
+ return { calls, tx, creditFacade: cmSuite.creditFacade };
384617
384607
  }
384618
384608
  /**
384619
384609
  * Internal wrapper for CreditAccountCompressor.getCreditAccounts + price updates wrapped into multicall
@@ -384664,7 +384654,7 @@ var CreditAccountsService = class extends SDKConstruct {
384664
384654
  const market = this.sdk.marketRegister.findByCreditManager(
384665
384655
  acc.creditManager
384666
384656
  );
384667
- const pool = market.poolFactory.pool.address;
384657
+ const pool = market.pool.pool.address;
384668
384658
  oracleByPool.set(pool, market.priceOracle);
384669
384659
  for (const t of acc.tokens) {
384670
384660
  if (t.balance > 10n) {
@@ -384675,9 +384665,9 @@ var CreditAccountsService = class extends SDKConstruct {
384675
384665
  }
384676
384666
  }
384677
384667
  const priceFeeds = [];
384678
- for (const [pool, priceFeedFactory] of oracleByPool.entries()) {
384668
+ for (const [pool, oracle] of oracleByPool.entries()) {
384679
384669
  const tokens = Array.from(tokensByPool.get(pool) ?? []);
384680
- priceFeeds.push(...priceFeedFactory.priceFeedsForTokens(tokens));
384670
+ priceFeeds.push(...oracle.priceFeedsForTokens(tokens));
384681
384671
  }
384682
384672
  return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(priceFeeds);
384683
384673
  }
@@ -384688,7 +384678,7 @@ var CreditAccountsService = class extends SDKConstruct {
384688
384678
  const caBalancesRecord = creditAccount ? assetsMap(creditAccount.tokens) : creditAccount;
384689
384679
  const market = this.sdk.marketRegister.findByCreditManager(creditManager);
384690
384680
  const cm = this.sdk.marketRegister.findCreditManager(creditManager).creditManager;
384691
- const pool = market.poolFactory.pool.address;
384681
+ const pool = market.pool.pool.address;
384692
384682
  oracleByPool.set(pool, market.priceOracle);
384693
384683
  const insertToken = (p, t) => {
384694
384684
  const tokens = tokensByPool.get(p) ?? /* @__PURE__ */ new Set();
@@ -409455,13 +409445,14 @@ async function evmMineDetailed(client, timestamp) {
409455
409445
  return void 0;
409456
409446
  }
409457
409447
  }
409458
- var AccountOpener = class {
409448
+ var AccountOpener = class extends SDKConstruct {
409459
409449
  #service;
409460
409450
  #anvil;
409461
409451
  #logger;
409462
409452
  #borrower;
409463
409453
  #faucet;
409464
409454
  constructor(service, options = {}) {
409455
+ super(service.sdk);
409465
409456
  this.#service = service;
409466
409457
  this.#logger = childLogger("AccountOpener", service.sdk.logger);
409467
409458
  this.#anvil = createAnvilClient({
@@ -409539,22 +409530,23 @@ var AccountOpener = class {
409539
409530
  });
409540
409531
  logger2?.debug(strategy, "found open strategy");
409541
409532
  const debt = minDebt * BigInt(leverage - 1);
409542
- const collateralLT = BigInt(cm.collateralTokens[collateral]);
409543
- const inUnderlying = collateral.toLowerCase() === underlying.toLowerCase();
409533
+ const averageQuota = this.#getCollateralQuota(
409534
+ cm,
409535
+ collateral,
409536
+ strategy.amount,
409537
+ debt
409538
+ );
409539
+ const minQuota = this.#getCollateralQuota(
409540
+ cm,
409541
+ collateral,
409542
+ strategy.minAmount,
409543
+ debt
409544
+ );
409545
+ logger2?.debug({ averageQuota, minQuota }, "calculated quotas");
409544
409546
  const { tx, calls } = await this.#service.openCA({
409545
409547
  creditManager: cm.creditManager.address,
409546
- averageQuota: inUnderlying ? [] : [
409547
- {
409548
- token: collateral,
409549
- balance: this.#calcQuota(strategy.amount, debt, collateralLT)
409550
- }
409551
- ],
409552
- minQuota: inUnderlying ? [] : [
409553
- {
409554
- token: collateral,
409555
- balance: this.#calcQuota(strategy.minAmount, debt, collateralLT)
409556
- }
409557
- ],
409548
+ averageQuota,
409549
+ minQuota,
409558
409550
  collateral: [{ token: underlying, balance: minDebt }],
409559
409551
  debt,
409560
409552
  calls: strategy.calls,
@@ -409749,15 +409741,37 @@ var AccountOpener = class {
409749
409741
  }
409750
409742
  return this.#borrower;
409751
409743
  }
409744
+ #getCollateralQuota(cm, collateral, amount, debt) {
409745
+ const { underlying, collateralTokens } = cm;
409746
+ const inUnderlying = collateral.toLowerCase() === underlying.toLowerCase();
409747
+ if (inUnderlying) {
409748
+ return [];
409749
+ }
409750
+ const collateralLT = BigInt(collateralTokens[collateral]);
409751
+ const market = this.sdk.marketRegister.findByCreditManager(
409752
+ cm.creditManager.address
409753
+ );
409754
+ const quotaInfo = market.pool.pqk.quotas.mustGet(collateral);
409755
+ const availableQuota = quotaInfo.limit - quotaInfo.totalQuoted;
409756
+ if (availableQuota <= 0n) {
409757
+ throw new Error(
409758
+ `quota exceeded for asset ${this.labelAddress(collateral)} in ${cm.name}`
409759
+ );
409760
+ }
409761
+ const desiredQuota = this.#calcQuota(amount, debt, collateralLT);
409762
+ return [
409763
+ {
409764
+ token: collateral,
409765
+ balance: desiredQuota < availableQuota ? desiredQuota : availableQuota
409766
+ }
409767
+ ];
409768
+ }
409752
409769
  #calcQuota(amount, debt, lt) {
409753
409770
  let quota = amount * lt / PERCENTAGE_FACTOR;
409754
409771
  quota = debt < quota ? debt : quota;
409755
409772
  quota = quota * (PERCENTAGE_FACTOR + 500n) / PERCENTAGE_FACTOR;
409756
409773
  return quota / PERCENTAGE_FACTOR * PERCENTAGE_FACTOR;
409757
409774
  }
409758
- get sdk() {
409759
- return this.#service.sdk;
409760
- }
409761
409775
  };
409762
409776
  var SDKExample = class {
409763
409777
  #sdk;
@@ -418122,6 +418136,11 @@ function openAccounts() {
418122
418136
  "stateAfter.human.json"
418123
418137
  )
418124
418138
  });
418139
+ await writeFile5(
418140
+ path8.resolve(sharedDir, "deploy-state", "stateAfter.json"),
418141
+ json_stringify(sdkExample2.sdk.state),
418142
+ "utf-8"
418143
+ );
418125
418144
  const faucetAddr = await sdkExample2.sdk.provider.publicClient.readContract({
418126
418145
  address: ADDRESS_PROVIDER[sdkExample2.sdk.provider.networkType],
418127
418146
  abi: iAddressProviderV3_1Abi,
@@ -418239,7 +418258,7 @@ function getRenderer(opts) {
418239
418258
  var package_default = {
418240
418259
  name: "@gearbox-protocol/deploy-tools",
418241
418260
  description: "Gearbox deploy tools",
418242
- version: "5.3.26",
418261
+ version: "5.3.28",
418243
418262
  homepage: "https://gearbox.fi",
418244
418263
  keywords: [
418245
418264
  "gearbox"
@@ -418282,7 +418301,7 @@ var package_default = {
418282
418301
  "@gearbox-protocol/deploy-tools-node": "0.0.0",
418283
418302
  "@gearbox-protocol/deploy-tools-shared": "0.0.0",
418284
418303
  "@gearbox-protocol/deploy-tools-types": "0.0.0",
418285
- "@gearbox-protocol/sdk": "^3.0.0-vfour.172",
418304
+ "@gearbox-protocol/sdk": "^3.0.0-vfour.174",
418286
418305
  "@gearbox-protocol/sdk-gov": "^2.33.2",
418287
418306
  "@types/lodash-es": "^4.17.12",
418288
418307
  "@types/node": "^22.10.6",
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.3.26",
4
+ "version": "5.3.28",
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.172",
47
+ "@gearbox-protocol/sdk": "^3.0.0-vfour.174",
48
48
  "@gearbox-protocol/sdk-gov": "^2.33.2",
49
49
  "@types/lodash-es": "^4.17.12",
50
50
  "@types/node": "^22.10.6",