@gearbox-protocol/deploy-tools 5.9.16 → 5.9.17

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 +449 -389
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -366192,14 +366192,37 @@ var CreditManagerV310Contract = class extends BaseContract {
366192
366192
  }
366193
366193
  }
366194
366194
  };
366195
+ function createCreditConfigurator(sdk, data) {
366196
+ const v = data.creditConfigurator.baseParams.version;
366197
+ if (v >= 300 && v < 310) {
366198
+ return new CreditConfiguratorV300Contract(sdk, data);
366199
+ } else if (v === 310n) {
366200
+ return new CreditConfiguratorV310Contract(sdk, data);
366201
+ }
366202
+ throw new Error(`Unsupported credit configurator version: ${v}`);
366203
+ }
366204
+ function createCreditFacade(sdk, data) {
366205
+ const v = data.creditFacade.baseParams.version;
366206
+ if (v >= 300 && v < 310) {
366207
+ return new CreditFacadeV300Contract(sdk, data);
366208
+ } else if (v === 310n) {
366209
+ return new CreditFacadeV310Contract(sdk, data);
366210
+ }
366211
+ throw new Error(`Unsupported credit facade version: ${v}`);
366212
+ }
366213
+ function createCreditManager(sdk, data) {
366214
+ const v = data.creditManager.baseParams.version;
366215
+ if (v >= 300 && v < 310) {
366216
+ return new CreditManagerV300Contract(sdk, data);
366217
+ } else if (v === 310n) {
366218
+ return new CreditManagerV310Contract(sdk, data);
366219
+ }
366220
+ throw new Error(`Unsupported credit manager version: ${v}`);
366221
+ }
366195
366222
  var CreditSuite = class extends SDKConstruct {
366196
366223
  name;
366197
366224
  pool;
366198
366225
  underlying;
366199
- /**
366200
- * Mappning Token Address => Liquidation Threshold
366201
- */
366202
- collateralTokens;
366203
366226
  creditManager;
366204
366227
  creditFacade;
366205
366228
  creditConfigurator;
@@ -366207,34 +366230,13 @@ var CreditSuite = class extends SDKConstruct {
366207
366230
  super(sdk);
366208
366231
  const { creditManagers, pool } = marketData;
366209
366232
  const creditManager = creditManagers[index2];
366210
- const { name, collateralTokens } = creditManager.creditManager;
366233
+ const { name } = creditManager.creditManager;
366211
366234
  this.name = name;
366212
366235
  this.pool = pool.baseParams.addr;
366213
366236
  this.underlying = pool.underlying;
366214
- this.collateralTokens = Object.fromEntries(
366215
- collateralTokens.map((ct) => [ct.token, ct.liquidationThreshold])
366216
- );
366217
- if (creditManager.creditManager.baseParams.version < 310) {
366218
- this.creditManager = new CreditManagerV300Contract(sdk, creditManager);
366219
- } else {
366220
- this.creditManager = new CreditManagerV310Contract(sdk, creditManager);
366221
- }
366222
- if (creditManager.creditFacade.baseParams.version < 310) {
366223
- this.creditFacade = new CreditFacadeV300Contract(sdk, creditManager);
366224
- } else {
366225
- this.creditFacade = new CreditFacadeV310Contract(sdk, creditManager);
366226
- }
366227
- if (creditManager.creditConfigurator.baseParams.version < 310) {
366228
- this.creditConfigurator = new CreditConfiguratorV300Contract(
366229
- sdk,
366230
- creditManager
366231
- );
366232
- } else {
366233
- this.creditConfigurator = new CreditConfiguratorV310Contract(
366234
- sdk,
366235
- creditManager
366236
- );
366237
- }
366237
+ this.creditManager = createCreditManager(sdk, creditManager);
366238
+ this.creditFacade = createCreditFacade(sdk, creditManager);
366239
+ this.creditConfigurator = createCreditConfigurator(sdk, creditManager);
366238
366240
  }
366239
366241
  async tvl() {
366240
366242
  const tvl = 0n;
@@ -366252,143 +366254,6 @@ var CreditSuite = class extends SDKConstruct {
366252
366254
  };
366253
366255
  }
366254
366256
  };
366255
- var GaugeContract = class extends BaseContract {
366256
- quotaParams;
366257
- epochFrozen;
366258
- epochLastUpdate;
366259
- rates;
366260
- constructor(sdk, pool, gauge) {
366261
- super(sdk, {
366262
- ...gauge.baseParams,
366263
- name: `Gauge(${pool.name})`,
366264
- abi: gaugeV3Abi
366265
- });
366266
- const [_voter, epochLastUpdate, epochFrozen, gaugeTokens, gaugeParams] = decodeAbiParameters(
366267
- [
366268
- { name: "voter", type: "address" },
366269
- { name: "epochLastUpdate", type: "uint16" },
366270
- { name: "epochFrozen", type: "bool" },
366271
- { name: "tokens", type: "address[]" },
366272
- {
366273
- name: "quotaParams",
366274
- type: "tuple[]",
366275
- components: [
366276
- { name: "minRate", type: "uint16" },
366277
- { name: "maxRate", type: "uint16" },
366278
- { name: "totalVotesLpSide", type: "uint96" },
366279
- { name: "totalVotesCaSide", type: "uint96" }
366280
- ]
366281
- }
366282
- ],
366283
- gauge.baseParams.serializedParams
366284
- );
366285
- this.epochFrozen = epochFrozen;
366286
- this.epochLastUpdate = epochLastUpdate;
366287
- this.rates = new AddressMap(gauge.rates.map((r) => [r.token, r.rate]));
366288
- this.quotaParams = new AddressMap();
366289
- for (let i = 0; i < gaugeParams.length; i++) {
366290
- const token = gaugeTokens[i];
366291
- const params = gaugeParams[i];
366292
- this.quotaParams.upsert(token, {
366293
- minRate: params.minRate,
366294
- maxRate: params.maxRate,
366295
- totalVotesLpSide: params.totalVotesLpSide,
366296
- totalVotesCaSide: params.totalVotesCaSide,
366297
- rate: this.rates.get(token) ?? 0
366298
- });
366299
- }
366300
- }
366301
- processLog(log2) {
366302
- switch (log2.eventName) {
366303
- case "AddQuotaToken":
366304
- case "NewController":
366305
- case "Paused":
366306
- case "SetFrozenEpoch":
366307
- case "SetQuotaTokenParams":
366308
- case "Unpaused":
366309
- case "Unvote":
366310
- case "UpdateEpoch":
366311
- case "Vote":
366312
- this.dirty = true;
366313
- break;
366314
- }
366315
- }
366316
- stateHuman(raw) {
366317
- return {
366318
- ...super.stateHuman(raw),
366319
- epochLastUpdate: Number(this.epochLastUpdate),
366320
- epochFrozen: this.epochFrozen,
366321
- quotaParams: this.quotaParams.entries().reduce(
366322
- (acc, [address, params]) => ({
366323
- ...acc,
366324
- [this.labelAddress(address)]: {
366325
- minRate: percentFmt(params.minRate, raw),
366326
- maxRate: percentFmt(params.maxRate, raw),
366327
- totalVotesLpSide: params.totalVotesLpSide / WAD,
366328
- totalVotesCaSide: params.totalVotesCaSide / WAD,
366329
- rate: percentFmt(params.rate, raw)
366330
- }
366331
- }),
366332
- {}
366333
- )
366334
- };
366335
- }
366336
- };
366337
- var LinearModelContract = class extends BaseContract {
366338
- U1;
366339
- U2;
366340
- Rbase;
366341
- Rslope1;
366342
- Rslope2;
366343
- Rslope3;
366344
- isBorrowingMoreU2Forbidden;
366345
- constructor(sdk, { interestRateModel }) {
366346
- super(sdk, {
366347
- ...interestRateModel.baseParams,
366348
- name: "LinearInterestRateModel",
366349
- abi: linearInterestRateModelV3Abi
366350
- });
366351
- const [
366352
- U1,
366353
- U2,
366354
- Rbase,
366355
- Rslope1,
366356
- Rslope2,
366357
- Rslope3,
366358
- isBorrowingMoreU2Forbidden
366359
- ] = decodeAbiParameters(
366360
- [
366361
- { type: "uint16", name: "U1" },
366362
- { type: "uint16", name: "U2" },
366363
- { type: "uint16", name: "Rbase" },
366364
- { type: "uint16", name: "Rslope1" },
366365
- { type: "uint16", name: "Rslope2" },
366366
- { type: "uint16", name: "Rslope3" },
366367
- { type: "bool", name: "isBorrowingMoreU2Forbidden" }
366368
- ],
366369
- interestRateModel.baseParams.serializedParams
366370
- );
366371
- this.U1 = U1;
366372
- this.U2 = U2;
366373
- this.Rbase = Rbase;
366374
- this.Rslope1 = Rslope1;
366375
- this.Rslope2 = Rslope2;
366376
- this.Rslope3 = Rslope3;
366377
- this.isBorrowingMoreU2Forbidden = isBorrowingMoreU2Forbidden;
366378
- }
366379
- stateHuman(raw) {
366380
- return {
366381
- ...super.stateHuman(raw),
366382
- U1: percentFmt(this.U1, raw),
366383
- U2: percentFmt(this.U2, raw),
366384
- Rbase: percentFmt(this.Rbase, raw),
366385
- Rslope1: percentFmt(this.Rslope1, raw),
366386
- Rslope2: percentFmt(this.Rslope2, raw),
366387
- Rslope3: percentFmt(this.Rslope3, raw),
366388
- isBorrowingMoreU2Forbidden: this.isBorrowingMoreU2Forbidden
366389
- };
366390
- }
366391
- };
366392
366257
  var SUPPORTED_CHAINS = [
366393
366258
  "Mainnet",
366394
366259
  "Arbitrum",
@@ -366655,209 +366520,6 @@ var MarketConfiguratorContract = class extends BaseContract {
366655
366520
  }
366656
366521
  }
366657
366522
  };
366658
- var abi29 = poolV3Abi;
366659
- var PoolContract = class extends BaseContract {
366660
- creditManagerDebtParams;
366661
- constructor(sdk, data) {
366662
- const { baseParams, creditManagerDebtParams, ...rest2 } = data;
366663
- super(sdk, {
366664
- ...data.baseParams,
366665
- name: `PoolV3(${data.name})`,
366666
- abi: abi29
366667
- });
366668
- Object.assign(this, rest2);
366669
- this.creditManagerDebtParams = new AddressMap(
366670
- creditManagerDebtParams.map((p) => [p.creditManager, p])
366671
- );
366672
- sdk.tokensMeta.upsert(data.baseParams.addr, {
366673
- addr: data.baseParams.addr,
366674
- decimals: data.decimals,
366675
- name: data.name,
366676
- symbol: data.symbol
366677
- });
366678
- }
366679
- stateHuman(raw = true) {
366680
- return {
366681
- ...super.stateHuman(raw),
366682
- underlying: this.labelAddress(this.underlying),
366683
- symbol: this.symbol,
366684
- name: this.name,
366685
- decimals: this.decimals,
366686
- availableLiquidity: formatBNvalue(
366687
- this.availableLiquidity,
366688
- this.decimals,
366689
- 2,
366690
- raw
366691
- ),
366692
- expectedLiquidity: formatBNvalue(
366693
- this.expectedLiquidity,
366694
- this.decimals,
366695
- 2,
366696
- raw
366697
- ),
366698
- totalBorrowed: formatBNvalue(this.totalBorrowed, this.decimals, 2, raw),
366699
- totalDebtLimit: formatBNvalue(this.totalDebtLimit, this.decimals, 2, raw),
366700
- creditManagerDebtParams: Object.fromEntries(
366701
- this.creditManagerDebtParams.values().map(({ creditManager, borrowed, limit, available }) => [
366702
- this.labelAddress(creditManager),
366703
- {
366704
- borrowed: formatBNvalue(borrowed, this.decimals, 2, raw),
366705
- limit: formatBNvalue(limit, this.decimals, 2, raw),
366706
- availableToBorrow: formatBNvalue(
366707
- available,
366708
- this.decimals,
366709
- 2,
366710
- raw
366711
- )
366712
- }
366713
- ])
366714
- ),
366715
- totalSupply: formatBNvalue(this.totalSupply, this.decimals, 2, raw),
366716
- supplyRate: `${formatBNvalue(this.supplyRate, 25, 2, raw)}%`,
366717
- baseInterestIndex: `${formatBNvalue(this.totalSupply, 25, 2, raw)}%`,
366718
- baseInterestRate: `${formatBNvalue(this.totalSupply, 25, 2, raw)}%`,
366719
- withdrawFee: percentFmt(this.withdrawFee),
366720
- lastBaseInterestUpdate: this.lastBaseInterestUpdate.toString(),
366721
- baseInterestIndexLU: this.lastBaseInterestUpdate.toString(),
366722
- isPaused: this.isPaused
366723
- };
366724
- }
366725
- processLog(log2) {
366726
- switch (log2.eventName) {
366727
- case "Paused":
366728
- this.isPaused = true;
366729
- break;
366730
- case "Unpaused":
366731
- this.isPaused = false;
366732
- break;
366733
- // TODO: do we really mark all events?
366734
- case "SetCreditManagerDebtLimit":
366735
- case "Repay":
366736
- case "Borrow":
366737
- case "Deposit":
366738
- case "Withdraw":
366739
- case "SetTotalDebtLimit":
366740
- case "SetWithdrawFee":
366741
- case "AddCreditManager":
366742
- case "Approval":
366743
- case "EIP712DomainChanged":
366744
- case "IncurUncoveredLoss":
366745
- case "NewController":
366746
- case "Refer":
366747
- case "SetInterestRateModel":
366748
- case "SetPoolQuotaKeeper":
366749
- case "Transfer":
366750
- this.dirty = true;
366751
- break;
366752
- }
366753
- }
366754
- parseFunctionParams(params) {
366755
- switch (params.functionName) {
366756
- case "deposit": {
366757
- const [amount, onBehalfOf] = params.args;
366758
- return [formatBN(amount, this.decimals), this.labelAddress(onBehalfOf)];
366759
- }
366760
- default:
366761
- return void 0;
366762
- }
366763
- }
366764
- };
366765
- var PoolQuotaKeeperContract = class extends BaseContract {
366766
- decimals;
366767
- quotas;
366768
- constructor(sdk, pool, pqk) {
366769
- super(sdk, {
366770
- ...pqk.baseParams,
366771
- name: `PoolQuotaKeeper(${pool.name})`,
366772
- abi: poolQuotaKeeperV3Abi
366773
- });
366774
- this.decimals = pool.decimals;
366775
- this.quotas = new AddressMap(
366776
- pqk.quotas.map((q) => {
366777
- return [q.token, q];
366778
- })
366779
- );
366780
- }
366781
- stateHuman(raw = true) {
366782
- return {
366783
- ...super.stateHuman(raw),
366784
- quotas: this.quotas.entries().reduce(
366785
- (acc, [address, params]) => ({
366786
- ...acc,
366787
- [this.labelAddress(address)]: {
366788
- rate: percentFmt(params.rate, raw),
366789
- quotaIncreaseFee: percentFmt(params.quotaIncreaseFee, raw),
366790
- totalQuoted: formatBNvalue(
366791
- params.totalQuoted,
366792
- this.decimals,
366793
- 2,
366794
- raw
366795
- ),
366796
- limit: formatBNvalue(params.limit, this.decimals, 2, raw),
366797
- isActive: params.isActive
366798
- }
366799
- }),
366800
- {}
366801
- )
366802
- };
366803
- }
366804
- processLog(log2) {
366805
- switch (log2.eventName) {
366806
- case "AddCreditManager":
366807
- case "AddQuotaToken":
366808
- case "NewController":
366809
- case "Paused":
366810
- case "SetGauge":
366811
- case "SetQuotaIncreaseFee":
366812
- case "SetTokenLimit":
366813
- case "Unpaused":
366814
- case "UpdateQuota":
366815
- case "UpdateTokenQuotaRate":
366816
- this.dirty = true;
366817
- break;
366818
- }
366819
- }
366820
- };
366821
- var PoolSuite = class extends SDKConstruct {
366822
- pool;
366823
- pqk;
366824
- gauge;
366825
- linearModel;
366826
- constructor(sdk, data) {
366827
- super(sdk);
366828
- this.pool = new PoolContract(sdk, data.pool);
366829
- this.pqk = new PoolQuotaKeeperContract(
366830
- sdk,
366831
- data.pool,
366832
- data.poolQuotaKeeper
366833
- );
366834
- this.gauge = new GaugeContract(sdk, data.pool, data.rateKeeper);
366835
- const irModelAddr = data.interestRateModel.baseParams.addr;
366836
- if (sdk.interestRateModels.has(irModelAddr)) {
366837
- this.linearModel = sdk.interestRateModels.mustGet(
366838
- irModelAddr
366839
- );
366840
- } else {
366841
- const linearModel = new LinearModelContract(sdk, data);
366842
- sdk.interestRateModels.insert(irModelAddr, linearModel);
366843
- this.linearModel = linearModel;
366844
- }
366845
- }
366846
- get underlying() {
366847
- return this.pool.underlying;
366848
- }
366849
- get dirty() {
366850
- return this.pool.dirty || this.gauge.dirty || this.pqk.dirty || this.linearModel.dirty;
366851
- }
366852
- stateHuman(raw = true) {
366853
- return {
366854
- pool: this.pool.stateHuman(raw),
366855
- poolQuotaKeeper: this.pqk.stateHuman(raw),
366856
- linearModel: this.linearModel.stateHuman(raw),
366857
- gauge: this.gauge.stateHuman(raw)
366858
- };
366859
- }
366860
- };
366861
366523
  var AdapterInterface = /* @__PURE__ */ ((AdapterInterface2) => {
366862
366524
  AdapterInterface2[AdapterInterface2["ABSTRACT"] = 0] = "ABSTRACT";
366863
366525
  AdapterInterface2[AdapterInterface2["UNISWAP_V2_ROUTER"] = 1] = "UNISWAP_V2_ROUTER";
@@ -374361,7 +374023,7 @@ var MellowLRTPriceFeedContract = class extends AbstractLPPriceFeedContract {
374361
374023
  return stack.totalValue * BigInt(1e18) / stack.totalSupply;
374362
374024
  }
374363
374025
  };
374364
- var abi30 = pendleTWAPPTPriceFeedAbi;
374026
+ var abi29 = pendleTWAPPTPriceFeedAbi;
374365
374027
  var PendleTWAPPTPriceFeed = class extends AbstractPriceFeedContract {
374366
374028
  market;
374367
374029
  sy;
@@ -374373,7 +374035,7 @@ var PendleTWAPPTPriceFeed = class extends AbstractPriceFeedContract {
374373
374035
  super(sdk, {
374374
374036
  ...args,
374375
374037
  name: "PendleTWAPPTPriceFeed",
374376
- abi: abi30
374038
+ abi: abi29
374377
374039
  });
374378
374040
  const decoded = decodeAbiParameters(
374379
374041
  [
@@ -375251,6 +374913,409 @@ var PriceOracleV310Contract = class extends PriceOracleBaseContract {
375251
374913
  }
375252
374914
  }
375253
374915
  };
374916
+ function createPriceOracle(sdk, data, underlying) {
374917
+ const v = data.baseParams.version;
374918
+ if (v >= 300n && v < 310n) {
374919
+ return new PriceOracleV300Contract(sdk, data, underlying);
374920
+ }
374921
+ if (v === 310n) {
374922
+ return new PriceOracleV310Contract(sdk, data, underlying);
374923
+ }
374924
+ throw new Error(`Unsupported oracle version ${v}`);
374925
+ }
374926
+ var GaugeContract = class extends BaseContract {
374927
+ quotaParams;
374928
+ epochFrozen;
374929
+ epochLastUpdate;
374930
+ rates;
374931
+ constructor(sdk, pool, gauge) {
374932
+ super(sdk, {
374933
+ ...gauge.baseParams,
374934
+ name: `Gauge(${pool.name})`,
374935
+ abi: gaugeV3Abi
374936
+ });
374937
+ const [_voter, epochLastUpdate, epochFrozen, gaugeTokens, gaugeParams] = decodeAbiParameters(
374938
+ [
374939
+ { name: "voter", type: "address" },
374940
+ { name: "epochLastUpdate", type: "uint16" },
374941
+ { name: "epochFrozen", type: "bool" },
374942
+ { name: "tokens", type: "address[]" },
374943
+ {
374944
+ name: "quotaParams",
374945
+ type: "tuple[]",
374946
+ components: [
374947
+ { name: "minRate", type: "uint16" },
374948
+ { name: "maxRate", type: "uint16" },
374949
+ { name: "totalVotesLpSide", type: "uint96" },
374950
+ { name: "totalVotesCaSide", type: "uint96" }
374951
+ ]
374952
+ }
374953
+ ],
374954
+ gauge.baseParams.serializedParams
374955
+ );
374956
+ this.epochFrozen = epochFrozen;
374957
+ this.epochLastUpdate = epochLastUpdate;
374958
+ this.rates = new AddressMap(gauge.rates.map((r) => [r.token, r.rate]));
374959
+ this.quotaParams = new AddressMap();
374960
+ for (let i = 0; i < gaugeParams.length; i++) {
374961
+ const token = gaugeTokens[i];
374962
+ const params = gaugeParams[i];
374963
+ this.quotaParams.upsert(token, {
374964
+ minRate: params.minRate,
374965
+ maxRate: params.maxRate,
374966
+ totalVotesLpSide: params.totalVotesLpSide,
374967
+ totalVotesCaSide: params.totalVotesCaSide,
374968
+ rate: this.rates.get(token) ?? 0
374969
+ });
374970
+ }
374971
+ }
374972
+ processLog(log2) {
374973
+ switch (log2.eventName) {
374974
+ case "AddQuotaToken":
374975
+ case "NewController":
374976
+ case "Paused":
374977
+ case "SetFrozenEpoch":
374978
+ case "SetQuotaTokenParams":
374979
+ case "Unpaused":
374980
+ case "Unvote":
374981
+ case "UpdateEpoch":
374982
+ case "Vote":
374983
+ this.dirty = true;
374984
+ break;
374985
+ }
374986
+ }
374987
+ stateHuman(raw) {
374988
+ return {
374989
+ ...super.stateHuman(raw),
374990
+ epochLastUpdate: Number(this.epochLastUpdate),
374991
+ epochFrozen: this.epochFrozen,
374992
+ quotaParams: this.quotaParams.entries().reduce(
374993
+ (acc, [address, params]) => ({
374994
+ ...acc,
374995
+ [this.labelAddress(address)]: {
374996
+ minRate: percentFmt(params.minRate, raw),
374997
+ maxRate: percentFmt(params.maxRate, raw),
374998
+ totalVotesLpSide: params.totalVotesLpSide / WAD,
374999
+ totalVotesCaSide: params.totalVotesCaSide / WAD,
375000
+ rate: percentFmt(params.rate, raw)
375001
+ }
375002
+ }),
375003
+ {}
375004
+ )
375005
+ };
375006
+ }
375007
+ };
375008
+ var LinearInterestRateModelContract = class extends BaseContract {
375009
+ U1;
375010
+ U2;
375011
+ Rbase;
375012
+ Rslope1;
375013
+ Rslope2;
375014
+ Rslope3;
375015
+ isBorrowingMoreU2Forbidden;
375016
+ constructor(sdk, params) {
375017
+ super(sdk, {
375018
+ ...params.baseParams,
375019
+ name: "LinearInterestRateModel",
375020
+ abi: linearInterestRateModelV3Abi
375021
+ });
375022
+ const [
375023
+ U1,
375024
+ U2,
375025
+ Rbase,
375026
+ Rslope1,
375027
+ Rslope2,
375028
+ Rslope3,
375029
+ isBorrowingMoreU2Forbidden
375030
+ ] = decodeAbiParameters(
375031
+ [
375032
+ { type: "uint16", name: "U1" },
375033
+ { type: "uint16", name: "U2" },
375034
+ { type: "uint16", name: "Rbase" },
375035
+ { type: "uint16", name: "Rslope1" },
375036
+ { type: "uint16", name: "Rslope2" },
375037
+ { type: "uint16", name: "Rslope3" },
375038
+ { type: "bool", name: "isBorrowingMoreU2Forbidden" }
375039
+ ],
375040
+ params.baseParams.serializedParams
375041
+ );
375042
+ this.U1 = U1;
375043
+ this.U2 = U2;
375044
+ this.Rbase = Rbase;
375045
+ this.Rslope1 = Rslope1;
375046
+ this.Rslope2 = Rslope2;
375047
+ this.Rslope3 = Rslope3;
375048
+ this.isBorrowingMoreU2Forbidden = isBorrowingMoreU2Forbidden;
375049
+ }
375050
+ stateHuman(raw) {
375051
+ return {
375052
+ ...super.stateHuman(raw),
375053
+ U1: percentFmt(this.U1, raw),
375054
+ U2: percentFmt(this.U2, raw),
375055
+ Rbase: percentFmt(this.Rbase, raw),
375056
+ Rslope1: percentFmt(this.Rslope1, raw),
375057
+ Rslope2: percentFmt(this.Rslope2, raw),
375058
+ Rslope3: percentFmt(this.Rslope3, raw),
375059
+ isBorrowingMoreU2Forbidden: this.isBorrowingMoreU2Forbidden
375060
+ };
375061
+ }
375062
+ };
375063
+ var PoolQuotaKeeperV300Contract = class extends BaseContract {
375064
+ decimals;
375065
+ quotas;
375066
+ constructor(sdk, pool, pqk) {
375067
+ super(sdk, {
375068
+ ...pqk.baseParams,
375069
+ name: `PoolQuotaKeeper(${pool.name})`,
375070
+ abi: poolQuotaKeeperV3Abi
375071
+ });
375072
+ this.decimals = pool.decimals;
375073
+ this.quotas = new AddressMap(
375074
+ pqk.quotas.map((q) => {
375075
+ return [q.token, q];
375076
+ })
375077
+ );
375078
+ }
375079
+ stateHuman(raw = true) {
375080
+ return {
375081
+ ...super.stateHuman(raw),
375082
+ quotas: this.quotas.entries().reduce(
375083
+ (acc, [address, params]) => ({
375084
+ ...acc,
375085
+ [this.labelAddress(address)]: {
375086
+ rate: percentFmt(params.rate, raw),
375087
+ quotaIncreaseFee: percentFmt(params.quotaIncreaseFee, raw),
375088
+ totalQuoted: formatBNvalue(
375089
+ params.totalQuoted,
375090
+ this.decimals,
375091
+ 2,
375092
+ raw
375093
+ ),
375094
+ limit: formatBNvalue(params.limit, this.decimals, 2, raw),
375095
+ isActive: params.isActive
375096
+ }
375097
+ }),
375098
+ {}
375099
+ )
375100
+ };
375101
+ }
375102
+ processLog(log2) {
375103
+ switch (log2.eventName) {
375104
+ case "AddCreditManager":
375105
+ case "AddQuotaToken":
375106
+ case "NewController":
375107
+ case "Paused":
375108
+ case "SetGauge":
375109
+ case "SetQuotaIncreaseFee":
375110
+ case "SetTokenLimit":
375111
+ case "Unpaused":
375112
+ case "UpdateQuota":
375113
+ case "UpdateTokenQuotaRate":
375114
+ this.dirty = true;
375115
+ break;
375116
+ }
375117
+ }
375118
+ };
375119
+ function createInterestRateModel(sdk, data) {
375120
+ const { addr, contractType } = data.baseParams;
375121
+ if (sdk.interestRateModels.has(addr)) {
375122
+ return sdk.interestRateModels.mustGet(
375123
+ addr
375124
+ );
375125
+ } else {
375126
+ const modelType = bytes32ToString(contractType);
375127
+ switch (modelType) {
375128
+ case "IRM::LINEAR": {
375129
+ const linearModel = new LinearInterestRateModelContract(sdk, data);
375130
+ sdk.interestRateModels.insert(addr, linearModel);
375131
+ return linearModel;
375132
+ }
375133
+ default: {
375134
+ throw new Error(`Unknown interest rate model type: ${modelType}`);
375135
+ }
375136
+ }
375137
+ }
375138
+ }
375139
+ var abi30 = poolV3Abi;
375140
+ var PoolV300Contract = class extends BaseContract {
375141
+ creditManagerDebtParams;
375142
+ constructor(sdk, data) {
375143
+ const { baseParams, creditManagerDebtParams, ...rest2 } = data;
375144
+ super(sdk, {
375145
+ ...data.baseParams,
375146
+ name: `PoolV3(${data.name})`,
375147
+ abi: abi30
375148
+ });
375149
+ Object.assign(this, rest2);
375150
+ this.creditManagerDebtParams = new AddressMap(
375151
+ creditManagerDebtParams.map((p) => [p.creditManager, p])
375152
+ );
375153
+ sdk.tokensMeta.upsert(data.baseParams.addr, {
375154
+ addr: data.baseParams.addr,
375155
+ decimals: data.decimals,
375156
+ name: data.name,
375157
+ symbol: data.symbol
375158
+ });
375159
+ }
375160
+ stateHuman(raw = true) {
375161
+ return {
375162
+ ...super.stateHuman(raw),
375163
+ underlying: this.labelAddress(this.underlying),
375164
+ symbol: this.symbol,
375165
+ name: this.name,
375166
+ decimals: this.decimals,
375167
+ availableLiquidity: formatBNvalue(
375168
+ this.availableLiquidity,
375169
+ this.decimals,
375170
+ 2,
375171
+ raw
375172
+ ),
375173
+ expectedLiquidity: formatBNvalue(
375174
+ this.expectedLiquidity,
375175
+ this.decimals,
375176
+ 2,
375177
+ raw
375178
+ ),
375179
+ totalBorrowed: formatBNvalue(this.totalBorrowed, this.decimals, 2, raw),
375180
+ totalDebtLimit: formatBNvalue(this.totalDebtLimit, this.decimals, 2, raw),
375181
+ creditManagerDebtParams: Object.fromEntries(
375182
+ this.creditManagerDebtParams.values().map(({ creditManager, borrowed, limit, available }) => [
375183
+ this.labelAddress(creditManager),
375184
+ {
375185
+ borrowed: formatBNvalue(borrowed, this.decimals, 2, raw),
375186
+ limit: formatBNvalue(limit, this.decimals, 2, raw),
375187
+ availableToBorrow: formatBNvalue(
375188
+ available,
375189
+ this.decimals,
375190
+ 2,
375191
+ raw
375192
+ )
375193
+ }
375194
+ ])
375195
+ ),
375196
+ totalSupply: formatBNvalue(this.totalSupply, this.decimals, 2, raw),
375197
+ supplyRate: `${formatBNvalue(this.supplyRate, 25, 2, raw)}%`,
375198
+ baseInterestIndex: `${formatBNvalue(this.totalSupply, 25, 2, raw)}%`,
375199
+ baseInterestRate: `${formatBNvalue(this.totalSupply, 25, 2, raw)}%`,
375200
+ withdrawFee: percentFmt(this.withdrawFee),
375201
+ lastBaseInterestUpdate: this.lastBaseInterestUpdate.toString(),
375202
+ baseInterestIndexLU: this.lastBaseInterestUpdate.toString(),
375203
+ isPaused: this.isPaused
375204
+ };
375205
+ }
375206
+ processLog(log2) {
375207
+ switch (log2.eventName) {
375208
+ case "Paused":
375209
+ this.isPaused = true;
375210
+ break;
375211
+ case "Unpaused":
375212
+ this.isPaused = false;
375213
+ break;
375214
+ // TODO: do we really mark all events?
375215
+ case "SetCreditManagerDebtLimit":
375216
+ case "Repay":
375217
+ case "Borrow":
375218
+ case "Deposit":
375219
+ case "Withdraw":
375220
+ case "SetTotalDebtLimit":
375221
+ case "SetWithdrawFee":
375222
+ case "AddCreditManager":
375223
+ case "Approval":
375224
+ case "EIP712DomainChanged":
375225
+ case "IncurUncoveredLoss":
375226
+ case "NewController":
375227
+ case "Refer":
375228
+ case "SetInterestRateModel":
375229
+ case "SetPoolQuotaKeeper":
375230
+ case "Transfer":
375231
+ this.dirty = true;
375232
+ break;
375233
+ }
375234
+ }
375235
+ parseFunctionParams(params) {
375236
+ switch (params.functionName) {
375237
+ case "deposit": {
375238
+ const [amount, onBehalfOf] = params.args;
375239
+ return [formatBN(amount, this.decimals), this.labelAddress(onBehalfOf)];
375240
+ }
375241
+ default:
375242
+ return void 0;
375243
+ }
375244
+ }
375245
+ };
375246
+ function createPool(sdk, data) {
375247
+ const v = data.baseParams.version;
375248
+ if (v >= 300n && v < 310n) {
375249
+ return new PoolV300Contract(sdk, data);
375250
+ }
375251
+ throw new Error(`Unsupported pool version ${v}`);
375252
+ }
375253
+ function createPoolQuotaKeeper(sdk, pool, pqk) {
375254
+ const v = pqk.baseParams.version;
375255
+ if (v >= 300n && v < 310n) {
375256
+ return new PoolQuotaKeeperV300Contract(sdk, pool, pqk);
375257
+ }
375258
+ throw new Error(`Unsupported pool quota keeper version ${v}`);
375259
+ }
375260
+ function createRateKeeper(sdk, pool, data) {
375261
+ const rateKeeperType = bytes32ToString(
375262
+ data.baseParams.contractType
375263
+ );
375264
+ switch (rateKeeperType) {
375265
+ case "RATE_KEEPER::GAUGE":
375266
+ return new GaugeContract(sdk, pool, data);
375267
+ // case "RATE_KEEPER::TUMBLER":
375268
+ // return new GaugeV2Contract(sdk, pool, data);
375269
+ default:
375270
+ throw new Error(`Unknown rate keeper type: ${rateKeeperType}`);
375271
+ }
375272
+ }
375273
+ var PoolSuite = class extends SDKConstruct {
375274
+ pool;
375275
+ pqk;
375276
+ rateKeeper;
375277
+ interestRateModel;
375278
+ constructor(sdk, data) {
375279
+ super(sdk);
375280
+ this.pool = createPool(sdk, data.pool);
375281
+ this.pqk = createPoolQuotaKeeper(sdk, data.pool, data.poolQuotaKeeper);
375282
+ this.rateKeeper = createRateKeeper(sdk, data.pool, data.rateKeeper);
375283
+ this.interestRateModel = createInterestRateModel(
375284
+ sdk,
375285
+ data.interestRateModel
375286
+ );
375287
+ }
375288
+ get gauge() {
375289
+ if (this.rateKeeper instanceof GaugeContract) {
375290
+ return this.rateKeeper;
375291
+ }
375292
+ throw new Error(
375293
+ "Rate keeper is not a gauge, but a " + this.rateKeeper.contractType
375294
+ );
375295
+ }
375296
+ get linearModel() {
375297
+ if (this.interestRateModel instanceof LinearInterestRateModelContract) {
375298
+ return this.interestRateModel;
375299
+ }
375300
+ throw new Error(
375301
+ `Interest rate model is not a linear model, but a ${this.interestRateModel.contractType}`
375302
+ );
375303
+ }
375304
+ get underlying() {
375305
+ return this.pool.underlying;
375306
+ }
375307
+ get dirty() {
375308
+ return this.pool.dirty || this.gauge.dirty || this.pqk.dirty || this.interestRateModel.dirty;
375309
+ }
375310
+ stateHuman(raw = true) {
375311
+ return {
375312
+ pool: this.pool.stateHuman(raw),
375313
+ poolQuotaKeeper: this.pqk.stateHuman(raw),
375314
+ interestRateModel: this.interestRateModel.stateHuman(raw),
375315
+ rateKeeper: this.rateKeeper.stateHuman(raw)
375316
+ };
375317
+ }
375318
+ };
375254
375319
  var MarketSuite = class extends SDKConstruct {
375255
375320
  acl;
375256
375321
  configurator;
@@ -375283,19 +375348,11 @@ var MarketSuite = class extends SDKConstruct {
375283
375348
  for (let i = 0; i < marketData.creditManagers.length; i++) {
375284
375349
  this.creditManagers.push(new CreditSuite(sdk, marketData, i));
375285
375350
  }
375286
- if (marketData.priceOracleData.baseParams.version < 310) {
375287
- this.priceOracle = new PriceOracleV300Contract(
375288
- sdk,
375289
- marketData.priceOracleData,
375290
- marketData.pool.underlying
375291
- );
375292
- } else {
375293
- this.priceOracle = new PriceOracleV310Contract(
375294
- sdk,
375295
- marketData.priceOracleData,
375296
- marketData.pool.underlying
375297
- );
375298
- }
375351
+ this.priceOracle = createPriceOracle(
375352
+ sdk,
375353
+ marketData.priceOracleData,
375354
+ marketData.pool.underlying
375355
+ );
375299
375356
  }
375300
375357
  get dirty() {
375301
375358
  return this.configurator.dirty || this.pool.dirty || this.priceOracle.dirty || this.creditManagers.some((cm) => cm.dirty);
@@ -401665,7 +401722,7 @@ var AccountOpener = class extends SDKConstruct {
401665
401722
  const { minDebt, underlying } = cm.creditFacade;
401666
401723
  const expectedBalances = [];
401667
401724
  const leftoverBalances = [];
401668
- for (const t of Object.keys(cm.collateralTokens)) {
401725
+ for (const t of cm.creditManager.collateralTokens) {
401669
401726
  const token = t;
401670
401727
  expectedBalances.push({
401671
401728
  token,
@@ -401898,12 +401955,15 @@ var AccountOpener = class extends SDKConstruct {
401898
401955
  return this.#borrower;
401899
401956
  }
401900
401957
  #getCollateralQuota(cm, collateral, amount, debt) {
401901
- const { underlying, collateralTokens } = cm;
401958
+ const {
401959
+ underlying,
401960
+ creditManager: { liquidationThresholds }
401961
+ } = cm;
401902
401962
  const inUnderlying = collateral.toLowerCase() === underlying.toLowerCase();
401903
401963
  if (inUnderlying) {
401904
401964
  return [];
401905
401965
  }
401906
- const collateralLT = BigInt(collateralTokens[collateral]);
401966
+ const collateralLT = BigInt(liquidationThresholds.mustGet(collateral));
401907
401967
  const market = this.sdk.marketRegister.findByCreditManager(
401908
401968
  cm.creditManager.address
401909
401969
  );
@@ -410624,7 +410684,7 @@ function getRenderer(opts) {
410624
410684
  var package_default = {
410625
410685
  name: "@gearbox-protocol/deploy-tools",
410626
410686
  description: "Gearbox deploy tools",
410627
- version: "5.9.16",
410687
+ version: "5.9.17",
410628
410688
  homepage: "https://gearbox.fi",
410629
410689
  keywords: [
410630
410690
  "gearbox"
@@ -410667,7 +410727,7 @@ var package_default = {
410667
410727
  "@gearbox-protocol/deploy-tools-node": "0.0.0",
410668
410728
  "@gearbox-protocol/deploy-tools-shared": "0.0.0",
410669
410729
  "@gearbox-protocol/deploy-tools-types": "0.0.0",
410670
- "@gearbox-protocol/sdk": "3.0.0-vfour.225",
410730
+ "@gearbox-protocol/sdk": "3.0.0-vfour.226",
410671
410731
  "@gearbox-protocol/sdk-gov": "^2.34.0",
410672
410732
  "@types/lodash-es": "^4.17.12",
410673
410733
  "@types/node": "^22.12.0",
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.9.16",
4
+ "version": "5.9.17",
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.225",
47
+ "@gearbox-protocol/sdk": "3.0.0-vfour.226",
48
48
  "@gearbox-protocol/sdk-gov": "^2.34.0",
49
49
  "@types/lodash-es": "^4.17.12",
50
50
  "@types/node": "^22.12.0",