@gearbox-protocol/deploy-tools 5.24.30 → 5.24.31

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 +272 -154
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -369150,9 +369150,7 @@ var chains = {
369150
369150
  ...mainnet,
369151
369151
  network: "Mainnet",
369152
369152
  defaultMarketConfigurators: {
369153
- "0x354fe9f450F60b8547f88BE042E4A45b46128a06": "Chaos Labs"
369154
- },
369155
- testMarketConfigurators: {
369153
+ "0x354fe9f450F60b8547f88BE042E4A45b46128a06": "Chaos Labs",
369156
369154
  "0x4d427D418342d8CE89a7634c3a402851978B680A": "K3"
369157
369155
  },
369158
369156
  isPublic: true,
@@ -370132,7 +370130,8 @@ var iGearboxRouterV310Abi = [
370132
370130
  { name: "token", type: "address", internalType: "address" },
370133
370131
  { name: "balance", type: "uint256", internalType: "uint256" },
370134
370132
  { name: "leftoverBalance", type: "uint256", internalType: "uint256" },
370135
- { name: "numSplits", type: "uint256", internalType: "uint256" }
370133
+ { name: "numSplits", type: "uint256", internalType: "uint256" },
370134
+ { name: "claimRewards", type: "bool", internalType: "bool" }
370136
370135
  ]
370137
370136
  }
370138
370137
  ],
@@ -370240,7 +370239,8 @@ var iGearboxRouterV310Abi = [
370240
370239
  { name: "token", type: "address", internalType: "address" },
370241
370240
  { name: "balance", type: "uint256", internalType: "uint256" },
370242
370241
  { name: "leftoverBalance", type: "uint256", internalType: "uint256" },
370243
- { name: "numSplits", type: "uint256", internalType: "uint256" }
370242
+ { name: "numSplits", type: "uint256", internalType: "uint256" },
370243
+ { name: "claimRewards", type: "bool", internalType: "bool" }
370244
370244
  ]
370245
370245
  }
370246
370246
  ],
@@ -384273,7 +384273,7 @@ var AbstractRouterContract = class extends BaseContract {
384273
384273
  removeHook = this.hooks.removeHook.bind(this.hooks);
384274
384274
  getExpectedAndLeftover(ca, cm, balances) {
384275
384275
  const b = balances || this.getDefaultExpectedAndLeftover(ca);
384276
- const { leftoverBalances, expectedBalances } = b;
384276
+ const { leftoverBalances, expectedBalances, tokensToClaim } = b;
384277
384277
  const expected = new AddressMap();
384278
384278
  const leftover = new AddressMap();
384279
384279
  for (const token of cm.collateralTokens) {
@@ -384284,7 +384284,11 @@ var AbstractRouterContract = class extends BaseContract {
384284
384284
  balance: leftoverBalances.get(token)?.balance || 1n
384285
384285
  });
384286
384286
  }
384287
- return { expectedBalances: expected, leftoverBalances: leftover };
384287
+ return {
384288
+ expectedBalances: expected,
384289
+ leftoverBalances: leftover,
384290
+ tokensToClaim
384291
+ };
384288
384292
  }
384289
384293
  getDefaultExpectedAndLeftover(ca) {
384290
384294
  const expectedBalances = new AddressMap();
@@ -384299,7 +384303,11 @@ var AbstractRouterContract = class extends BaseContract {
384299
384303
  leftoverBalances.upsert(token, { token, balance });
384300
384304
  }
384301
384305
  }
384302
- return { expectedBalances, leftoverBalances };
384306
+ return {
384307
+ expectedBalances,
384308
+ leftoverBalances,
384309
+ tokensToClaim: new AddressMap()
384310
+ };
384303
384311
  }
384304
384312
  };
384305
384313
 
@@ -384557,7 +384565,8 @@ var RouterV300Contract = class extends AbstractRouterContract {
384557
384565
  cm,
384558
384566
  balances ? {
384559
384567
  expectedBalances: assetsMap(balances.expectedBalances),
384560
- leftoverBalances: assetsMap(balances.leftoverBalances)
384568
+ leftoverBalances: assetsMap(balances.leftoverBalances),
384569
+ tokensToClaim: assetsMap(balances.tokensToClaim || [])
384561
384570
  } : void 0
384562
384571
  );
384563
384572
  await this.hooks.triggerHooks("foundPathOptions", {
@@ -384802,7 +384811,8 @@ var RouterV310Contract = class extends AbstractRouterContract {
384802
384811
  token,
384803
384812
  balance: expectedMap.get(token) ?? 0n,
384804
384813
  leftoverBalance: leftoverMap.get(token) ?? 0n,
384805
- numSplits: getNumSplits(token)
384814
+ numSplits: getNumSplits(token),
384815
+ claimRewards: false
384806
384816
  })
384807
384817
  );
384808
384818
  this.logger?.debug(
@@ -384843,12 +384853,13 @@ var RouterV310Contract = class extends AbstractRouterContract {
384843
384853
  */
384844
384854
  async findBestClosePath(props) {
384845
384855
  const { creditAccount: ca, creditManager: cm, slippage, balances } = props;
384846
- const { expectedBalances, leftoverBalances } = this.getExpectedAndLeftover(
384856
+ const { expectedBalances, leftoverBalances, tokensToClaim } = this.getExpectedAndLeftover(
384847
384857
  ca,
384848
384858
  cm,
384849
384859
  balances ? {
384850
384860
  expectedBalances: assetsMap(balances.expectedBalances),
384851
- leftoverBalances: assetsMap(balances.leftoverBalances)
384861
+ leftoverBalances: assetsMap(balances.leftoverBalances),
384862
+ tokensToClaim: assetsMap(balances.tokensToClaim || [])
384852
384863
  } : void 0
384853
384864
  );
384854
384865
  const getNumSplits = this.#numSplitsGetter(cm, expectedBalances.values());
@@ -384858,7 +384869,8 @@ var RouterV310Contract = class extends AbstractRouterContract {
384858
384869
  token,
384859
384870
  balance: expectedBalances.get(token)?.balance || 0n,
384860
384871
  leftoverBalance: leftoverBalances.get(token)?.balance || 0n,
384861
- numSplits: getNumSplits(token)
384872
+ numSplits: getNumSplits(token),
384873
+ claimRewards: !!tokensToClaim.get(token)
384862
384874
  });
384863
384875
  }
384864
384876
  this.logger?.debug(
@@ -384871,12 +384883,23 @@ var RouterV310Contract = class extends AbstractRouterContract {
384871
384883
  },
384872
384884
  "calling routeManyToOne"
384873
384885
  );
384874
- const { result } = await this.contract.simulate.routeManyToOne([
384875
- cm.address,
384876
- ca.underlying,
384886
+ const targetToken = ca.underlying;
384887
+ const filtered = tData.filter((b) => {
384888
+ return b.balance > 10 && b.balance - b.leftoverBalance > 1 || !!b.claimRewards;
384889
+ });
384890
+ const skipSwap = filtered.length === 0 || filtered.length === 1 && filtered[0].token.toLowerCase() === targetToken.toLowerCase();
384891
+ const { result } = await (skipSwap ? {
384892
+ result: {
384893
+ amount: 0n,
384894
+ minAmount: 0n,
384895
+ calls: []
384896
+ }
384897
+ } : this.contract.simulate.routeManyToOne([
384898
+ ca.creditAccount,
384899
+ targetToken,
384877
384900
  BigInt(slippage),
384878
384901
  tData
384879
- ]);
384902
+ ]));
384880
384903
  const underlyingBalance = ca.tokens.find((t) => t.token === ca.underlying)?.balance ?? 0n;
384881
384904
  return {
384882
384905
  underlyingBalance: underlyingBalance + result.minAmount,
@@ -384899,8 +384922,15 @@ var RouterV310Contract = class extends AbstractRouterContract {
384899
384922
  balance: priceOracle.convertToUSD(token, balance)
384900
384923
  };
384901
384924
  }).sort((a, b) => {
384902
- return b.balance > a.balance ? -1 : 1;
384925
+ return a.balance > b.balance ? -1 : 1;
384903
384926
  });
384927
+ this.logger?.debug(
384928
+ inUSD.map((v) => ({
384929
+ token: this.labelAddress(v.token),
384930
+ balance: formatBN(v.balance, 8) + ` (${v.balance})`
384931
+ })),
384932
+ "balances in usd"
384933
+ );
384904
384934
  const map = new AddressMap(
384905
384935
  inUSD.map(({ token }, i) => [token, i === 0 ? 4n : 1n])
384906
384936
  );
@@ -384909,9 +384939,10 @@ var RouterV310Contract = class extends AbstractRouterContract {
384909
384939
  #debugTokenData(tData) {
384910
384940
  return tData.map((t) => ({
384911
384941
  token: this.labelAddress(t.token),
384912
- balance: this.sdk.tokensMeta.formatBN(t.token, t.balance),
384913
- leftoverBalance: this.sdk.tokensMeta.formatBN(t.token, t.leftoverBalance),
384914
- numSplits: t.numSplits
384942
+ balance: this.sdk.tokensMeta.formatBN(t.token, t.balance) + ` (${t.balance})`,
384943
+ leftoverBalance: this.sdk.tokensMeta.formatBN(t.token, t.leftoverBalance) + ` (${t.leftoverBalance})`,
384944
+ numSplits: t.numSplits,
384945
+ claimRewards: t.claimRewards
384915
384946
  }));
384916
384947
  }
384917
384948
  /**
@@ -384946,7 +384977,7 @@ function balancesAfterOpen(target, targetAmount, expected, leftover) {
384946
384977
  ]);
384947
384978
  for (const t of tokens) {
384948
384979
  if (t === targetAddr) {
384949
- result[t] = expected.get(t) ?? 0n + targetAmount;
384980
+ result[t] = (expected.get(t) ?? 0n) + targetAmount;
384950
384981
  } else {
384951
384982
  result[t] = BigIntMath.min(expected.get(t) ?? 0n, leftover.get(t) ?? 0n);
384952
384983
  }
@@ -385703,13 +385734,7 @@ var CreditAccountsService = class extends SDKConstruct {
385703
385734
  averageQuota
385704
385735
  })
385705
385736
  ];
385706
- const tx = cm.creditFacade.multicall(creditAccount.creditAccount, [
385707
- ...priceUpdates,
385708
- ...this.#prepareUpdateQuotas(creditAccount.creditFacade, {
385709
- minQuota,
385710
- averageQuota
385711
- })
385712
- ]);
385737
+ const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
385713
385738
  return { tx, calls, creditFacade: cm.creditFacade };
385714
385739
  }
385715
385740
  /**
@@ -385967,12 +385992,12 @@ var CreditAccountsService = class extends SDKConstruct {
385967
385992
  ...priceUpdatesCalls,
385968
385993
  this.#prepareIncreaseDebt(cm.creditFacade, debt),
385969
385994
  ...this.#prepareAddCollateral(cm.creditFacade, collateral, permits),
385995
+ ...openPathCalls,
385996
+ ...withdrawDebt ? [this.#prepareWithdrawToken(cm.creditFacade, cm.underlying, debt, to)] : [],
385970
385997
  ...this.#prepareUpdateQuotas(cm.creditFacade, {
385971
385998
  minQuota,
385972
385999
  averageQuota
385973
- }),
385974
- ...openPathCalls,
385975
- ...withdrawDebt ? [this.#prepareWithdrawToken(cm.creditFacade, cm.underlying, debt, to)] : []
386000
+ })
385976
386001
  ];
385977
386002
  const tx = cmSuite.creditFacade.openCreditAccount(to, calls, referralCode);
385978
386003
  tx.value = ethAmount.toString(10);
@@ -386014,6 +386039,8 @@ var CreditAccountsService = class extends SDKConstruct {
386014
386039
  }
386015
386040
  /**
386016
386041
  * Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
386042
+ *
386043
+ * This can be used by batch liquidator
386017
386044
  * @param accounts
386018
386045
  * @returns
386019
386046
  */
@@ -386042,19 +386069,11 @@ var CreditAccountsService = class extends SDKConstruct {
386042
386069
  return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(priceFeeds);
386043
386070
  }
386044
386071
  async getUpdateForAccount(creditManager, creditAccount, desiredQuotas) {
386045
- const tokensByPool = /* @__PURE__ */ new Map();
386046
- const oracleByPool = /* @__PURE__ */ new Map();
386047
386072
  const quotaRecord = desiredQuotas ? assetsMap(desiredQuotas) : desiredQuotas;
386048
386073
  const caBalancesRecord = creditAccount ? assetsMap(creditAccount.tokens) : creditAccount;
386049
386074
  const market = this.sdk.marketRegister.findByCreditManager(creditManager);
386050
386075
  const cm = this.sdk.marketRegister.findCreditManager(creditManager).creditManager;
386051
- const pool = market.pool.pool.address;
386052
- oracleByPool.set(pool, market.priceOracle);
386053
- const insertToken = (p, t) => {
386054
- const tokens = tokensByPool.get(p) ?? /* @__PURE__ */ new Set();
386055
- tokens.add(t);
386056
- tokensByPool.set(pool, tokens);
386057
- };
386076
+ const tokens = /* @__PURE__ */ new Set([getAddress(cm.underlying)]);
386058
386077
  for (const t of cm.collateralTokens) {
386059
386078
  if (creditAccount && caBalancesRecord && quotaRecord) {
386060
386079
  const balanceAsset = caBalancesRecord.get(t);
@@ -386063,28 +386082,30 @@ var CreditAccountsService = class extends SDKConstruct {
386063
386082
  const isEnabled = (mask & creditAccount.enabledTokensMask) !== 0n;
386064
386083
  const quotaAsset = quotaRecord.get(t);
386065
386084
  const quotaBalance = quotaAsset?.balance || 0n;
386066
- if (balance > 10n && isEnabled || quotaBalance > 0)
386067
- insertToken(pool, t);
386085
+ if (balance > 10n && isEnabled || quotaBalance > 0) {
386086
+ tokens.add(getAddress(t));
386087
+ }
386068
386088
  } else if (creditAccount && caBalancesRecord) {
386069
386089
  const balanceAsset = caBalancesRecord.get(t);
386070
386090
  const balance = balanceAsset?.balance || 0n;
386071
386091
  const mask = balanceAsset?.mask || 0n;
386072
386092
  const isEnabled = (mask & creditAccount.enabledTokensMask) !== 0n;
386073
- if (balance > 10n && isEnabled) insertToken(pool, t);
386093
+ if (balance > 10n && isEnabled) {
386094
+ tokens.add(getAddress(t));
386095
+ }
386074
386096
  } else if (quotaRecord) {
386075
386097
  const quotaAsset = quotaRecord.get(t);
386076
386098
  const quotaBalance = quotaAsset?.balance || 0n;
386077
- if (quotaBalance > 0) insertToken(pool, t);
386099
+ if (quotaBalance > 0) {
386100
+ tokens.add(getAddress(t));
386101
+ }
386078
386102
  }
386079
386103
  }
386080
- const priceFeeds = [];
386081
- for (const [pool2, oracle] of oracleByPool.entries()) {
386082
- const tokens = Array.from(tokensByPool.get(pool2) ?? []);
386083
- priceFeeds.push(...oracle.priceFeedsForTokens(tokens));
386084
- }
386104
+ const priceFeeds = market.priceOracle.priceFeedsForTokens(Array.from(tokens));
386105
+ const tStr = Array.from(tokens).map((t) => this.labelAddress(t)).join(", ");
386085
386106
  this.#logger?.debug(
386086
386107
  { account: creditAccount?.creditAccount, manager: cm.name },
386087
- `generating price feed updates for ${priceFeeds.length} price feeds`
386108
+ `generating price feed updates for ${tStr} from ${priceFeeds.length} price feeds`
386088
386109
  );
386089
386110
  return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(
386090
386111
  priceFeeds,
@@ -386478,6 +386499,24 @@ var AbstractAddressProviderContract = class extends BaseContract {
386478
386499
  }
386479
386500
  return [this.getAddress(contract, version4), version4];
386480
386501
  }
386502
+ getLatestInRange(contract, range2) {
386503
+ const allVersions = this.#addresses[contract];
386504
+ if (!allVersions) {
386505
+ return void 0;
386506
+ }
386507
+ let version4 = 0;
386508
+ let address;
386509
+ for (const [v, a] of TypedObjectUtils.entries(allVersions)) {
386510
+ if (v >= range2[0] && v <= range2[1] && v >= version4) {
386511
+ version4 = v;
386512
+ address = a;
386513
+ }
386514
+ }
386515
+ if (!address) {
386516
+ return void 0;
386517
+ }
386518
+ return [address, version4];
386519
+ }
386481
386520
  get state() {
386482
386521
  return {
386483
386522
  baseParams: {
@@ -386566,6 +386605,9 @@ var AddressProviderContractV3_1 = class extends AbstractAddressProviderContract
386566
386605
  const entries = await this.contract.read.getAllEntries({
386567
386606
  blockNumber
386568
386607
  });
386608
+ this.logger?.debug(
386609
+ `loaded ${entries.length} events in block ${blockNumber}`
386610
+ );
386569
386611
  for (const { key, ver, value } of entries) {
386570
386612
  this.setInternalAddress(key, value, Number(ver));
386571
386613
  }
@@ -386623,10 +386665,14 @@ var AddressProviderContractV3 = class extends AbstractAddressProviderContract {
386623
386665
  }
386624
386666
  }
386625
386667
  async syncState(blockNumber) {
386668
+ const fromBlock = ADDRESS_PROVIDER_BLOCK[this.sdk.provider.networkType];
386669
+ this.logger?.debug(
386670
+ `loading events from block ${fromBlock} to ${blockNumber}`
386671
+ );
386626
386672
  const events = await this.sdk.provider.publicClient.getLogs({
386627
386673
  address: this.address,
386628
386674
  event: getAbiItem({ abi: this.abi, name: "SetAddress" }),
386629
- fromBlock: ADDRESS_PROVIDER_BLOCK[this.sdk.provider.networkType],
386675
+ fromBlock,
386630
386676
  toBlock: blockNumber,
386631
386677
  strict: true
386632
386678
  });
@@ -387506,17 +387552,18 @@ var CreditSuite = class extends SDKConstruct {
387506
387552
  creditManager;
387507
387553
  creditFacade;
387508
387554
  creditConfigurator;
387555
+ state;
387509
387556
  constructor(sdk, marketData, index2) {
387510
387557
  super(sdk);
387511
387558
  const { creditManagers, pool } = marketData;
387512
- const creditManager = creditManagers[index2];
387513
- const { name } = creditManager.creditManager;
387559
+ this.state = creditManagers[index2];
387560
+ const { name } = this.state.creditManager;
387514
387561
  this.name = name;
387515
387562
  this.pool = pool.baseParams.addr;
387516
387563
  this.underlying = pool.underlying;
387517
- this.creditManager = createCreditManager(sdk, creditManager);
387518
- this.creditFacade = createCreditFacade(sdk, creditManager);
387519
- this.creditConfigurator = createCreditConfigurator(sdk, creditManager);
387564
+ this.creditManager = createCreditManager(sdk, this.state);
387565
+ this.creditFacade = createCreditFacade(sdk, this.state);
387566
+ this.creditConfigurator = createCreditConfigurator(sdk, this.state);
387520
387567
  }
387521
387568
  async tvl() {
387522
387569
  const tvl = 0n;
@@ -393009,9 +393056,10 @@ var PriceFeedRegister = class extends SDKConstruct {
393009
393056
  }
393010
393057
  }
393011
393058
  const result = { txs, timestamp: maxTimestamp };
393059
+ const tsDelta = BigInt(maxTimestamp) - this.sdk.timestamp;
393012
393060
  this.logger?.debug(
393013
393061
  logContext,
393014
- `generated ${txs.length} price feed update transactions, timestamp: ${maxTimestamp}`
393062
+ `generated ${txs.length} price feed update transactions, timestamp: ${maxTimestamp} (delta ${tsDelta})`
393015
393063
  );
393016
393064
  if (txs.length) {
393017
393065
  await this.#hooks.triggerHooks("updatesGenerated", result);
@@ -393049,7 +393097,7 @@ var PriceFeedRegister = class extends SDKConstruct {
393049
393097
  const configurators = marketConfigurators ?? this.sdk.marketRegister.marketConfigurators.map((mc) => mc.address);
393050
393098
  this.logger?.debug(
393051
393099
  { configurators, pools },
393052
- "calling getUpdatablePriceFeeds"
393100
+ `calling getUpdatablePriceFeeds in block ${this.sdk.currentBlock}`
393053
393101
  );
393054
393102
  const result = await this.provider.publicClient.readContract({
393055
393103
  address: marketCompressorAddress,
@@ -393061,9 +393109,12 @@ var PriceFeedRegister = class extends SDKConstruct {
393061
393109
  pools: pools ?? [],
393062
393110
  underlying: ADDRESS_0X0
393063
393111
  }
393064
- ]
393112
+ ],
393113
+ blockNumber: this.sdk.currentBlock
393065
393114
  });
393066
- this.logger?.debug(`loaded ${result.length} partial updatable price feeds`);
393115
+ this.logger?.debug(
393116
+ `loaded ${result.length} partial updatable price feeds in block ${this.sdk.currentBlock}`
393117
+ );
393067
393118
  return result.map((baseParams) => this.#createUpdatableProxy({ baseParams }));
393068
393119
  }
393069
393120
  create(data) {
@@ -394169,6 +394220,14 @@ var PoolSuite = class extends SDKConstruct {
394169
394220
  "Rate keeper is not a gauge, but a " + this.rateKeeper.contractType
394170
394221
  );
394171
394222
  }
394223
+ get tumbler() {
394224
+ if (this.rateKeeper instanceof TumblerContract) {
394225
+ return this.rateKeeper;
394226
+ }
394227
+ throw new Error(
394228
+ "Rate keeper is not a tumbler, but a " + this.rateKeeper.contractType
394229
+ );
394230
+ }
394172
394231
  get linearModel() {
394173
394232
  if (this.interestRateModel instanceof LinearInterestRateModelContract) {
394174
394233
  return this.interestRateModel;
@@ -394181,7 +394240,7 @@ var PoolSuite = class extends SDKConstruct {
394181
394240
  return this.pool.underlying;
394182
394241
  }
394183
394242
  get dirty() {
394184
- return this.pool.dirty || this.gauge.dirty || this.pqk.dirty || this.interestRateModel.dirty;
394243
+ return this.pool.dirty || this.rateKeeper.dirty || this.pqk.dirty || this.interestRateModel.dirty;
394185
394244
  }
394186
394245
  get watchAddresses() {
394187
394246
  return /* @__PURE__ */ new Set([
@@ -394340,7 +394399,7 @@ var MarketRegister = class extends SDKConstruct {
394340
394399
  }
394341
394400
  this.#logger?.debug(
394342
394401
  { configurators, pools },
394343
- `calling getMarkets with ${txs.length} price updates`
394402
+ `calling getMarkets with ${txs.length} price updates in block ${this.sdk.currentBlock}`
394344
394403
  );
394345
394404
  let markets = [];
394346
394405
  if (txs.length) {
@@ -394355,7 +394414,8 @@ var MarketRegister = class extends SDKConstruct {
394355
394414
  functionName: "getMarkets",
394356
394415
  args: [this.#marketFilter]
394357
394416
  }
394358
- ]
394417
+ ],
394418
+ blockNumber: this.sdk.currentBlock
394359
394419
  }
394360
394420
  );
394361
394421
  markets = resp;
@@ -394364,8 +394424,8 @@ var MarketRegister = class extends SDKConstruct {
394364
394424
  abi: iMarketCompressorAbi,
394365
394425
  address: marketCompressorAddress,
394366
394426
  functionName: "getMarkets",
394367
- args: [this.#marketFilter]
394368
- // gas: 550_000_000n,
394427
+ args: [this.#marketFilter],
394428
+ blockNumber: this.sdk.currentBlock
394369
394429
  });
394370
394430
  }
394371
394431
  for (const data of markets) {
@@ -394374,7 +394434,9 @@ var MarketRegister = class extends SDKConstruct {
394374
394434
  new MarketSuite(this.sdk, data)
394375
394435
  );
394376
394436
  }
394377
- this.#logger?.info(`loaded ${markets.length} markets`);
394437
+ this.#logger?.info(
394438
+ `loaded ${markets.length} markets in block ${this.sdk.currentBlock}`
394439
+ );
394378
394440
  }
394379
394441
  /**
394380
394442
  * Loads new prices and price feeds for given oracles from PriceFeedCompressor, defaults to all oracles
@@ -394512,10 +394574,16 @@ var V300StalenessPeriodPlugin = class extends SDKConstruct {
394512
394574
  }
394513
394575
  const events = await this.client.getLogs({
394514
394576
  address: addresses,
394515
- event: getAbiItem({
394516
- abi: iPriceOracleV300Abi,
394517
- name: "SetReservePriceFeed"
394518
- }),
394577
+ events: [
394578
+ getAbiItem({
394579
+ abi: iPriceOracleV300Abi,
394580
+ name: "SetReservePriceFeed"
394581
+ }),
394582
+ getAbiItem({
394583
+ abi: iPriceOracleV300Abi,
394584
+ name: "SetPriceFeed"
394585
+ })
394586
+ ],
394519
394587
  fromBlock,
394520
394588
  toBlock,
394521
394589
  strict: true
@@ -394529,9 +394597,10 @@ var V300StalenessPeriodPlugin = class extends SDKConstruct {
394529
394597
  const token = getAddress(e.args.token);
394530
394598
  const stalenessPeriod = e.args.stalenessPeriod;
394531
394599
  for (const o of oracles) {
394532
- const pf = o.reservePriceFeeds.get(token);
394600
+ const map = e.eventName === "SetReservePriceFeed" ? o.reservePriceFeeds : o.mainPriceFeeds;
394601
+ const pf = map.get(token);
394533
394602
  if (hexEq(pf?.address, priceFeed) && hexEq(o.address, oracle)) {
394534
- o.reservePriceFeeds.upsert(
394603
+ map.upsert(
394535
394604
  token,
394536
394605
  new PriceFeedRef(this.sdk, priceFeed, stalenessPeriod)
394537
394606
  );
@@ -394667,6 +394736,11 @@ var GearboxSDK = class _GearboxSDK {
394667
394736
  },
394668
394737
  `${re}attaching gearbox sdk`
394669
394738
  );
394739
+ if (!!blockNumber && !redstoneHistoricTimestamp) {
394740
+ this.logger?.warn(
394741
+ `${re}attaching to fixed block number, but redstoneHistoricTimestamp is not set. price updates might fail`
394742
+ );
394743
+ }
394670
394744
  this.#attachConfig = opts;
394671
394745
  const time = Date.now();
394672
394746
  const block = await this.provider.publicClient.getBlock(
@@ -394683,11 +394757,7 @@ var GearboxSDK = class _GearboxSDK {
394683
394757
  this.priceFeeds.redstoneUpdater.gateways = redstoneGateways;
394684
394758
  }
394685
394759
  this.logger?.debug(
394686
- {
394687
- number: block.number,
394688
- timestamp: block.timestamp
394689
- },
394690
- `${re}attach block`
394760
+ `${re}attach block number ${this.currentBlock} timestamp ${this.timestamp}`
394691
394761
  );
394692
394762
  this.#addressProvider = await createAddressProvider(this, addressProvider);
394693
394763
  this.logger?.debug(
@@ -394839,6 +394909,11 @@ var GearboxSDK = class _GearboxSDK {
394839
394909
  */
394840
394910
  async syncState(opts) {
394841
394911
  let { blockNumber, timestamp, skipPriceUpdate } = opts ?? {};
394912
+ if (this.#attachConfig?.redstoneHistoricTimestamp) {
394913
+ throw new Error(
394914
+ "syncState is not supported with redstoneHistoricTimestamp"
394915
+ );
394916
+ }
394842
394917
  if (!blockNumber || !timestamp) {
394843
394918
  const block = await this.provider.publicClient.getBlock({
394844
394919
  blockTag: "latest"
@@ -394877,16 +394952,16 @@ var GearboxSDK = class _GearboxSDK {
394877
394952
  contract.processLog(event);
394878
394953
  }
394879
394954
  }
394880
- await this.marketRegister.syncState(skipPriceUpdate);
394881
394955
  this.#currentBlock = blockNumber;
394882
394956
  this.#timestamp = timestamp;
394957
+ await this.marketRegister.syncState(skipPriceUpdate);
394883
394958
  await this.#hooks.triggerHooks("syncState", { blockNumber, timestamp });
394884
394959
  const pluginsList = TypedObjectUtils.entries(this.plugins);
394885
394960
  const pluginResponse = await Promise.allSettled(
394886
394961
  pluginsList.map(([name, plugin]) => {
394887
- if (plugin.attach) {
394962
+ if (plugin.syncState) {
394888
394963
  this.logger?.debug(`syncing plugin ${name}`);
394889
- return plugin.attach();
394964
+ return plugin.syncState();
394890
394965
  }
394891
394966
  return void 0;
394892
394967
  })
@@ -416185,7 +416260,11 @@ var AccountOpener = class extends SDKConstruct {
416185
416260
  chain: service.sdk.provider.chain,
416186
416261
  transport: service.sdk.provider.transport
416187
416262
  });
416188
- this.#faucet = options.faucet ?? service.sdk.addressProvider.getAddress("FAUCET");
416263
+ try {
416264
+ this.#faucet = options.faucet ?? service.sdk.addressProvider.getAddress("FAUCET");
416265
+ } catch (e) {
416266
+ this.#logger?.warn("faucet not found, will not claim from faucet");
416267
+ }
416189
416268
  this.#borrower = options.borrower;
416190
416269
  this.#poolDepositMultiplier = options.poolDepositMultiplier ?? 11000n;
416191
416270
  }
@@ -416198,7 +416277,7 @@ var AccountOpener = class extends SDKConstruct {
416198
416277
  /**
416199
416278
  * Tries to open account with underlying only in each CM
416200
416279
  */
416201
- async openCreditAccounts(targets, depositIntoPools = true) {
416280
+ async openCreditAccounts(targets, depositIntoPools = true, claimFromFaucet = true) {
416202
416281
  if (depositIntoPools) {
416203
416282
  try {
416204
416283
  await this.#depositIntoPools(targets);
@@ -416206,7 +416285,9 @@ var AccountOpener = class extends SDKConstruct {
416206
416285
  this.#logger?.warn(`failed to deposit into pools: ${e}`);
416207
416286
  }
416208
416287
  }
416209
- await this.#prepareBorrower(targets);
416288
+ if (claimFromFaucet) {
416289
+ await this.#prepareBorrower(targets);
416290
+ }
416210
416291
  const toApprove = new AddressMap();
416211
416292
  for (const c of targets) {
416212
416293
  const cm = this.sdk.marketRegister.findCreditManager(c.creditManager);
@@ -416239,20 +416320,80 @@ var AccountOpener = class extends SDKConstruct {
416239
416320
  return results;
416240
416321
  }
416241
416322
  async #openAccount(input, index2, total) {
416323
+ const { creditManager, target: collateral } = input;
416324
+ const cm = this.sdk.marketRegister.findCreditManager(creditManager);
416325
+ const symbol = this.sdk.tokensMeta.symbol(collateral);
416326
+ const logger2 = this.#logger?.child?.({
416327
+ creditManager: cm.name,
416328
+ collateral: symbol
416329
+ });
416330
+ logger2?.debug(`opening account #${index2}/${total}`);
416331
+ const borrower = await this.#getBorrower();
416332
+ const tx = await this.prepareOpen(input);
416333
+ let hash2;
416334
+ try {
416335
+ hash2 = await sendRawTx(this.#anvil, {
416336
+ tx,
416337
+ account: borrower
416338
+ });
416339
+ logger2?.debug(`send transaction ${hash2}`);
416340
+ } catch (e) {
416341
+ return {
416342
+ input,
416343
+ error: `${e}`,
416344
+ rawTx: tx
416345
+ };
416346
+ }
416347
+ const receipt = await this.#anvil.waitForTransactionReceipt({ hash: hash2 });
416348
+ if (receipt.status === "reverted") {
416349
+ return {
416350
+ input,
416351
+ error: `open credit account tx reverted`,
416352
+ txHash: hash2,
416353
+ rawTx: tx
416354
+ };
416355
+ }
416356
+ logger2?.info(`opened credit account ${index2}/${total}`);
416357
+ const logs = parseEventLogs({
416358
+ abi: iCreditFacadeV300Abi,
416359
+ logs: receipt.logs,
416360
+ eventName: "OpenCreditAccount"
416361
+ });
416362
+ logger2?.info(`found ${logs.length} logs`);
416363
+ let account;
416364
+ if (logs.length > 0) {
416365
+ try {
416366
+ logger2?.debug(
416367
+ `getting credit account data for ${logs[0].args.creditAccount}`
416368
+ );
416369
+ account = await this.#service.getCreditAccountData(
416370
+ logs[0].args.creditAccount
416371
+ );
416372
+ } catch (e) {
416373
+ logger2?.error(`failed to get credit account data: ${e}`);
416374
+ }
416375
+ }
416376
+ return {
416377
+ input,
416378
+ txHash: hash2,
416379
+ rawTx: tx,
416380
+ account
416381
+ };
416382
+ }
416383
+ async prepareOpen(input) {
416242
416384
  const {
416243
416385
  creditManager,
416244
- collateral,
416386
+ target,
416245
416387
  leverage = DEFAULT_LEVERAGE,
416246
416388
  slippage = 50
416247
416389
  } = input;
416248
416390
  const borrower = await this.#getBorrower();
416249
416391
  const cm = this.sdk.marketRegister.findCreditManager(creditManager);
416250
- const symbol = this.sdk.tokensMeta.symbol(collateral);
416392
+ const symbol = this.sdk.tokensMeta.symbol(target);
416251
416393
  const logger2 = this.#logger?.child?.({
416252
416394
  creditManager: cm.name,
416253
- collateral: symbol
416395
+ target: symbol
416254
416396
  });
416255
- logger2?.debug(`opening account #${index2}/${total}`);
416256
416397
  const { minDebt, underlying } = cm.creditFacade;
416257
416398
  const expectedBalances = [];
416258
416399
  const leftoverBalances = [];
@@ -416273,19 +416414,19 @@ var AccountOpener = class extends SDKConstruct {
416273
416414
  expectedBalances,
416274
416415
  leftoverBalances,
416275
416416
  slippage,
416276
- target: collateral
416417
+ target
416277
416418
  });
416278
416419
  logger2?.debug(strategy, "found open strategy");
416279
416420
  const debt = minDebt * BigInt(leverage - 1);
416280
416421
  const averageQuota = this.#getCollateralQuota(
416281
416422
  cm,
416282
- collateral,
416423
+ target,
416283
416424
  strategy.amount,
416284
416425
  debt
416285
416426
  );
416286
416427
  const minQuota = this.#getCollateralQuota(
416287
416428
  cm,
416288
- collateral,
416429
+ target,
416289
416430
  strategy.minAmount,
416290
416431
  debt
416291
416432
  );
@@ -416309,55 +416450,7 @@ var AccountOpener = class extends SDKConstruct {
416309
416450
  );
416310
416451
  }
416311
416452
  logger2?.debug("prepared open account transaction");
416312
- let hash2;
416313
- try {
416314
- hash2 = await sendRawTx(this.#anvil, {
416315
- tx,
416316
- account: borrower
416317
- });
416318
- logger2?.debug(`send transaction ${hash2}`);
416319
- } catch (e) {
416320
- return {
416321
- input,
416322
- error: `${e}`,
416323
- rawTx: tx
416324
- };
416325
- }
416326
- const receipt = await this.#anvil.waitForTransactionReceipt({ hash: hash2 });
416327
- if (receipt.status === "reverted") {
416328
- return {
416329
- input,
416330
- error: `open credit account tx reverted`,
416331
- txHash: hash2,
416332
- rawTx: tx
416333
- };
416334
- }
416335
- logger2?.info(`opened credit account ${index2}/${total}`);
416336
- const logs = parseEventLogs({
416337
- abi: iCreditFacadeV300Abi,
416338
- logs: receipt.logs,
416339
- eventName: "OpenCreditAccount"
416340
- });
416341
- logger2?.info(`found ${logs.length} logs`);
416342
- let account;
416343
- if (logs.length > 0) {
416344
- try {
416345
- logger2?.debug(
416346
- `getting credit account data for ${logs[0].args.creditAccount}`
416347
- );
416348
- account = await this.#service.getCreditAccountData(
416349
- logs[0].args.creditAccount
416350
- );
416351
- } catch (e) {
416352
- logger2?.error(`failed to get credit account data: ${e}`);
416353
- }
416354
- }
416355
- return {
416356
- input,
416357
- txHash: hash2,
416358
- rawTx: tx,
416359
- account
416360
- };
416453
+ return tx;
416361
416454
  }
416362
416455
  async getOpenedAccounts() {
416363
416456
  return await this.#service.getCreditAccounts({
@@ -416456,7 +416549,6 @@ var AccountOpener = class extends SDKConstruct {
416456
416549
  * Creates borrower wallet,
416457
416550
  * Sets ETH balance,
416458
416551
  * Gets tokens from faucet,
416459
- * Approves collateral tokens to credit manager,
416460
416552
  * Gets DEGEN_NFT,
416461
416553
  */
416462
416554
  async #prepareBorrower(targets) {
@@ -416493,7 +416585,7 @@ var AccountOpener = class extends SDKConstruct {
416493
416585
  }
416494
416586
  const hash2 = await this.#anvil.writeContract({
416495
416587
  account: claimer,
416496
- address: this.#faucet,
416588
+ address: this.faucet,
416497
416589
  abi: [
416498
416590
  {
416499
416591
  type: "function",
@@ -416661,6 +416753,12 @@ var AccountOpener = class extends SDKConstruct {
416661
416753
  quota = quota * (PERCENTAGE_FACTOR + 500n) / PERCENTAGE_FACTOR;
416662
416754
  return quota / PERCENTAGE_FACTOR * PERCENTAGE_FACTOR;
416663
416755
  }
416756
+ get faucet() {
416757
+ if (!this.#faucet) {
416758
+ throw new Error("faucet not found");
416759
+ }
416760
+ return this.#faucet;
416761
+ }
416664
416762
  };
416665
416763
 
416666
416764
  // ../../node_modules/@gearbox-protocol/sdk/dist/esm/dev/detectChain.js
@@ -423644,6 +423742,26 @@ var UniswapV2AdapterContract = class extends AbstractAdapterContract {
423644
423742
  abi: abi43
423645
423743
  });
423646
423744
  }
423745
+ parseFunctionParams(params) {
423746
+ switch (params.functionName) {
423747
+ case "swapDiffTokensForTokens": {
423748
+ const [leftoverAmount, rateMinRAY, path12, _deadline] = params.args;
423749
+ const leftoverAmountStr = this.sdk.tokensMeta.formatBN(
423750
+ path12[0],
423751
+ leftoverAmount
423752
+ );
423753
+ const pathStr = path12.map((t) => this.labelAddress(t)).join(" => ");
423754
+ return [
423755
+ `(leftoverAmount: ${leftoverAmountStr}, rate: ${formatBN(
423756
+ rateMinRAY,
423757
+ 27
423758
+ )}, path: ${pathStr}`
423759
+ ];
423760
+ }
423761
+ default:
423762
+ return void 0;
423763
+ }
423764
+ }
423647
423765
  };
423648
423766
 
423649
423767
  // ../../node_modules/@gearbox-protocol/sdk/dist/esm/adapters/UniswapV3AdapterContract.js
@@ -423951,31 +424069,31 @@ function openAccounts() {
423951
424069
  {
423952
424070
  creditManager: "0x50ba483272484fc5eebe8676dc87d814a11faef6",
423953
424071
  // restaking weth
423954
- collateral: "0xbf5495Efe5DB9ce00f80364C8B423567e58d2110"
424072
+ target: "0xbf5495Efe5DB9ce00f80364C8B423567e58d2110"
423955
424073
  // ezETH
423956
424074
  },
423957
424075
  {
423958
424076
  creditManager: "0x50ba483272484fc5eebe8676dc87d814a11faef6",
423959
424077
  // restaking weth
423960
- collateral: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
424078
+ target: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
423961
424079
  // WETH
423962
424080
  },
423963
424081
  {
423964
424082
  creditManager: "0x3EB95430FdB99439A86d3c6D7D01C3c561393556",
423965
424083
  // [Trade USDC Tier 1]
423966
- collateral: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599"
424084
+ target: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599"
423967
424085
  // WBTC
423968
424086
  },
423969
424087
  {
423970
424088
  creditManager: "0x3EB95430FdB99439A86d3c6D7D01C3c561393556",
423971
424089
  // [Trade USDC Tier 1]
423972
- collateral: "0x6B175474E89094C44Da98b954EedeAC495271d0F"
424090
+ target: "0x6B175474E89094C44Da98b954EedeAC495271d0F"
423973
424091
  // DAI
423974
424092
  },
423975
424093
  {
423976
424094
  creditManager: "0x3EB95430FdB99439A86d3c6D7D01C3c561393556",
423977
424095
  // [Trade USDC Tier 1]
423978
- collateral: "0x9D39A5DE30e57443BfF2A8307A4256c8797A3497"
424096
+ target: "0x9D39A5DE30e57443BfF2A8307A4256c8797A3497"
423979
424097
  // sUSDe
423980
424098
  }
423981
424099
  ];
@@ -423984,7 +424102,7 @@ function openAccounts() {
423984
424102
  {
423985
424103
  creditManager: "0x3EB95430FdB99439A86d3c6D7D01C3c561393556",
423986
424104
  // [Trade USDC Tier 1]
423987
- collateral: "0x6B175474E89094C44Da98b954EedeAC495271d0F"
424105
+ target: "0x6B175474E89094C44Da98b954EedeAC495271d0F"
423988
424106
  // DAI
423989
424107
  }
423990
424108
  ];
@@ -424011,9 +424129,9 @@ function openAccounts() {
424011
424129
  collateralTokens.delete(getAddress(cm.underlying));
424012
424130
  accounts.push(
424013
424131
  ...Array.from(collateralTokens).map(
424014
- (collateral) => ({
424132
+ (target) => ({
424015
424133
  creditManager: cmAddr,
424016
- collateral,
424134
+ target,
424017
424135
  leverage: 3
424018
424136
  })
424019
424137
  )
@@ -424031,11 +424149,11 @@ function openAccounts() {
424031
424149
  )
424032
424150
  );
424033
424151
  log_default.debug(
424034
- `found ${cms.length} cms with stkcvxRLUSDUSDC as collateral: ${cms.map((cm) => cm.name)}`
424152
+ `found ${cms.length} cms with stkcvxRLUSDUSDC as target: ${cms.map((cm) => cm.name)}`
424035
424153
  );
424036
424154
  accounts = cms.map((cm) => ({
424037
424155
  creditManager: cm.creditManager.address,
424038
- collateral: t.addr
424156
+ target: t.addr
424039
424157
  }));
424040
424158
  }
424041
424159
  const results = await accountOpener.openCreditAccounts(accounts, true);
@@ -424151,7 +424269,7 @@ function getRenderer(opts) {
424151
424269
  var package_default = {
424152
424270
  name: "@gearbox-protocol/deploy-tools",
424153
424271
  description: "Gearbox deploy tools",
424154
- version: "5.24.30",
424272
+ version: "5.24.31",
424155
424273
  homepage: "https://gearbox.fi",
424156
424274
  keywords: [
424157
424275
  "gearbox"
@@ -424194,7 +424312,7 @@ var package_default = {
424194
424312
  "@gearbox-protocol/deploy-tools-node": "0.0.0",
424195
424313
  "@gearbox-protocol/deploy-tools-shared": "0.0.0",
424196
424314
  "@gearbox-protocol/deploy-tools-types": "0.0.0",
424197
- "@gearbox-protocol/sdk": "3.0.0-vfour.359",
424315
+ "@gearbox-protocol/sdk": "3.0.0-vfour.388",
424198
424316
  "@gearbox-protocol/sdk-gov": "^2.37.0",
424199
424317
  "@types/lodash-es": "^4.17.12",
424200
424318
  "@types/node": "^22.13.14",
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.24.30",
4
+ "version": "5.24.31",
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.359",
47
+ "@gearbox-protocol/sdk": "3.0.0-vfour.388",
48
48
  "@gearbox-protocol/sdk-gov": "^2.37.0",
49
49
  "@types/lodash-es": "^4.17.12",
50
50
  "@types/node": "^22.13.14",