@gearbox-protocol/sdk 16.0.0-next.1 → 16.0.0-next.2

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 (25) hide show
  1. package/dist/cjs/sdk/market/math.js +4 -4
  2. package/dist/esm/dev/AccountOpener.js +1 -1
  3. package/dist/esm/dev/withdrawalUtils.js +1 -1
  4. package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
  5. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  6. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -2
  7. package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -1
  8. package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  9. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  10. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  11. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  12. package/dist/esm/sdk/base/TokensMeta.js +3 -3
  13. package/dist/esm/sdk/chain/detectNetwork.js +1 -1
  14. package/dist/esm/sdk/core/createAddressProvider.js +1 -1
  15. package/dist/esm/sdk/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
  16. package/dist/esm/sdk/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
  17. package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
  18. package/dist/esm/sdk/market/math.js +4 -4
  19. package/dist/esm/sdk/market/pool/PoolV310Contract.js +1 -1
  20. package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
  21. package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
  22. package/dist/esm/sdk/pools/PoolService.js +1 -1
  23. package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
  24. package/dist/types/sdk/market/math.d.ts +3 -3
  25. package/package.json +1 -1
@@ -156,8 +156,8 @@ function calcNetStrategyApy(opportunity, totalCollateralApy, leverage, mode = "s
156
156
  **/
157
157
  const MAX_LEVERAGE_BUFFER_BPS = 500;
158
158
  /**
159
- * Highest total-value leverage a liquidation threshold allows:
160
- * `(100% − buffer) / (100% − liquidationThreshold)`. At HF = 1, debt is
159
+ * Highest total-value leverage a liquidation threshold allows, floored:
160
+ * `floor((100% − buffer) / (100% − liquidationThreshold))`. At HF = 1, debt is
161
161
  * `liquidationThreshold × totalValue`, leaving `1 − liquidationThreshold` of
162
162
  * equity per unit of exposure; the {@link MAX_LEVERAGE_BUFFER_BPS} buffer
163
163
  * keeps the maxed position slightly away from that boundary.
@@ -165,14 +165,14 @@ const MAX_LEVERAGE_BUFFER_BPS = 500;
165
165
  * @example
166
166
  * ```ts
167
167
  * // liquidationThreshold: 9000 bps = 90%
168
- * calcMaxLeverage(9000) // (1 − 0.05) / (1 − 0.9) = 9.5x total exposure
168
+ * calcMaxLeverage(9000) // floor((1 − 0.05) / (1 − 0.9)) = 9x total exposure
169
169
  * ```
170
170
  * @throws If `liquidationThreshold` is 100% or more, which would make
171
171
  * leverage unbounded.
172
172
  **/
173
173
  function calcMaxLeverage(liquidationThreshold) {
174
174
  if (liquidationThreshold >= FULL) throw new Error("cannot compute max leverage: liquidation threshold is 100% or more");
175
- const leverage = (FULL - 500) / (FULL - liquidationThreshold);
175
+ const leverage = Math.floor((FULL - 500) / (FULL - liquidationThreshold));
176
176
  return Math.max(leverage, 1);
177
177
  }
178
178
  /**
@@ -1,9 +1,9 @@
1
+ import { ierc20Abi } from "../abi/iERC20.js";
1
2
  import { iCreditFacadeV310Abi } from "../abi/310/generated.js";
2
3
  import { AddressMap } from "../sdk/utils/AddressMap.js";
3
4
  import { AddressSet } from "../sdk/utils/AddressSet.js";
4
5
  import { AssetsMap } from "../sdk/utils/AssetsMap.js";
5
6
  import { childLogger } from "../sdk/utils/childLogger.js";
6
- import { ierc20Abi } from "../abi/iERC20.js";
7
7
  import "../sdk/constants/addresses.js";
8
8
  import { MAX_UINT256, PERCENTAGE_FACTOR } from "../sdk/constants/math.js";
9
9
  import { SDKConstruct } from "../sdk/base/SDKConstruct.js";
@@ -1,6 +1,6 @@
1
+ import { iWithdrawalCompressorV313Abi } from "../abi/IWithdrawalCompressorV313.js";
1
2
  import { getNetworkType } from "../sdk/chain/chains.js";
2
3
  import { getWithdrawalCompressorAddress } from "../sdk/accounts/withdrawal-compressor/addresses.js";
3
- import { iWithdrawalCompressorV313Abi } from "../abi/IWithdrawalCompressorV313.js";
4
4
  import "../sdk/index.js";
5
5
  import { iMidasDataFeedAbi, iMidasRedemptionVaultAbi, midasGatewayAbi, midasRedeemerAbi, midasRedemptionVaultPhantomTokenAbi, securitizeRedeemerAbi, securitizeRedemptionGatewayAbi, securitizeRedemptionPhantomTokenAbi } from "./withdrawalAbi.js";
6
6
  import { erc20Abi, hexToString, parseAbi, parseEther } from "viem";
@@ -1,5 +1,5 @@
1
- import { iPoolV310Abi } from "../../abi/310/generated.js";
2
1
  import { iZapperAbi } from "../../abi/iZapper.js";
2
+ import { iPoolV310Abi } from "../../abi/310/generated.js";
3
3
  import { asPreviewSimulationError } from "./errors.js";
4
4
  //#region src/preview/simulate/simulatePoolOperation.ts
5
5
  function previewRead(operation) {
@@ -1,6 +1,6 @@
1
+ import { ierc20Abi } from "../../abi/iERC20.js";
1
2
  import { iCreditFacadeV310Abi } from "../../abi/310/generated.js";
2
3
  import { AddressMap } from "../../sdk/utils/AddressMap.js";
3
- import { ierc20Abi } from "../../abi/iERC20.js";
4
4
  import "../../sdk/index.js";
5
5
  import { UnexpectedFacadeEventOrderError } from "./errors.js";
6
6
  import { getAddress, isAddressEqual, parseEventLogs } from "viem";
@@ -1,3 +1,5 @@
1
+ import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
2
+ import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
1
3
  import { AP_REWARDS_COMPRESSOR } from "../constants/address-provider.js";
2
4
  import { ADDRESS_0X0 } from "../constants/addresses.js";
3
5
  import { MAX_UINT256 } from "../constants/math.js";
@@ -8,8 +10,6 @@ import "../base/index.js";
8
10
  import { AccountBotsService } from "./bots/AccountBotsService.js";
9
11
  import "./bots/index.js";
10
12
  import { rewardsCompressorAbi } from "../../abi/compressors/rewardsCompressor.js";
11
- import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
12
- import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
13
13
  import { expectedBalanceDeltas } from "../market/credit/expectedBalanceDeltas.js";
14
14
  import "../market/index.js";
15
15
  import { CreditAccountCompressor } from "./credit-account-compressor/CreditAccountCompressor.js";
@@ -1,3 +1,4 @@
1
+ import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
1
2
  import { AddressSet } from "../../utils/AddressSet.js";
2
3
  import { bytes32ToString } from "../../utils/bytes32ToString.js";
3
4
  import { ADDRESS_0X0 } from "../../constants/addresses.js";
@@ -19,7 +20,6 @@ import { SecuritizeLiquidatorContract } from "../../market/rwa/securitize/Securi
19
20
  import "../../market/rwa/securitize/index.js";
20
21
  import "../../market/index.js";
21
22
  import { LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS } from "./constants.js";
22
- import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
23
23
  //#region src/sdk/accounts/liquidations/LiquidationsService.ts
24
24
  /**
25
25
  * Service for discovering liquidatable credit accounts and previewing manual
@@ -1,7 +1,7 @@
1
+ import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
1
2
  import { BaseContract } from "../../base/BaseContract.js";
2
3
  import "../../base/index.js";
3
4
  import { decodeDelayedIntent } from "./intent-codec.js";
4
- import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
5
5
  import { InvalidDelayedIntentError } from "./errors.js";
6
6
  //#region src/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.ts
7
7
  const abi = iRedemptionLoggerV310Abi;
@@ -1,5 +1,5 @@
1
- import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
2
1
  import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
2
+ import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
3
3
  //#region src/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.ts
4
4
  const abi = iWithdrawalCompressorV310Abi;
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
2
1
  import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
2
+ import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
3
3
  //#region src/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.ts
4
4
  const abi = iWithdrawalCompressorV311Abi;
5
5
  /**
@@ -1,6 +1,6 @@
1
+ import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
1
2
  import { encodeDelayedIntent } from "./intent-codec.js";
2
3
  import { AbstractWithdrawalCompressorContract, iCreditAccountAbi, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal } from "./AbstractWithdrawalCompressorContract.js";
3
- import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
4
4
  import { toWithdrawalStatus } from "./types.js";
5
5
  //#region src/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.ts
6
6
  const abi = iWithdrawalCompressorV313Abi;
@@ -1,12 +1,12 @@
1
+ import { iExpirableAbi } from "../../abi/iExpirable.js";
2
+ import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
3
+ import { iVersionAbi } from "../../abi/iVersion.js";
1
4
  import { AddressMap } from "../utils/AddressMap.js";
2
5
  import { AddressSet } from "../utils/AddressSet.js";
3
6
  import { bytes32ToString } from "../utils/bytes32ToString.js";
4
7
  import { getAssetType } from "../chain/chains.js";
5
8
  import { formatBN } from "../utils/formatter.js";
6
9
  import "../utils/index.js";
7
- import { iExpirableAbi } from "../../abi/iExpirable.js";
8
- import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
9
- import { iVersionAbi } from "../../abi/iVersion.js";
10
10
  import { executeMulticallBatches } from "../utils/viem/executeMulticallBatches.js";
11
11
  //#region src/sdk/base/TokensMeta.ts
12
12
  /**
@@ -1,5 +1,5 @@
1
- import { chains } from "./chains.js";
2
1
  import { ierc20Abi } from "../../abi/iERC20.js";
2
+ import { chains } from "./chains.js";
3
3
  //#region src/sdk/chain/detectNetwork.ts
4
4
  /**
5
5
  * Detects the network type from the given client.
@@ -1,8 +1,8 @@
1
+ import { iVersionAbi } from "../../abi/iVersion.js";
1
2
  import { AP_MARKET_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR } from "../constants/address-provider.js";
2
3
  import { isV310 } from "../constants/versions.js";
3
4
  import "../constants/index.js";
4
5
  import { hexEq } from "../utils/hex.js";
5
- import { iVersionAbi } from "../../abi/iVersion.js";
6
6
  import { AddressProviderV310Contract } from "./AddressProviderV310Contract.js";
7
7
  //#region src/sdk/core/createAddressProvider.ts
8
8
  const OVERRIDE_ADDRESSES = { Mainnet: {
@@ -1,5 +1,5 @@
1
- import { AbstractAdapterContract } from "./AbstractAdapter.js";
2
1
  import { accountMigratorAbi } from "../../../../abi/AccountMigrator.js";
2
+ import { AbstractAdapterContract } from "./AbstractAdapter.js";
3
3
  //#region src/sdk/market/adapters/contracts/AccountMigratorAdapterContract.ts
4
4
  const abi = accountMigratorAbi;
5
5
  const protocolAbi = accountMigratorAbi;
@@ -1,6 +1,6 @@
1
+ import { ierc4626AdapterAbi } from "../../../../abi/ierc4626Adapter.js";
1
2
  import { MissingSerializedParamsError } from "../../../base/errors.js";
2
3
  import "../../../base/index.js";
3
- import { ierc4626AdapterAbi } from "../../../../abi/ierc4626Adapter.js";
4
4
  import { iERC4626Abi } from "../abi/targetContractAbi.js";
5
5
  import { fnSigToName, swapFromTransfers } from "../transferHelpers.js";
6
6
  import { AbstractAdapterContract } from "./AbstractAdapter.js";
@@ -1,7 +1,7 @@
1
+ import { iPausableAbi } from "../../../abi/iPausable.js";
1
2
  import { iCreditFacadeMulticallV310Abi, iCreditFacadeV310Abi } from "../../../abi/310/generated.js";
2
3
  import { BaseContract } from "../../base/BaseContract.js";
3
4
  import "../../base/index.js";
4
- import { iPausableAbi } from "../../../abi/iPausable.js";
5
5
  //#region src/sdk/market/credit/CreditFacadeV310BaseContract.ts
6
6
  const abi = [
7
7
  ...iCreditFacadeV310Abi,
@@ -155,8 +155,8 @@ function calcNetStrategyApy(opportunity, totalCollateralApy, leverage, mode = "s
155
155
  **/
156
156
  const MAX_LEVERAGE_BUFFER_BPS = 500;
157
157
  /**
158
- * Highest total-value leverage a liquidation threshold allows:
159
- * `(100% − buffer) / (100% − liquidationThreshold)`. At HF = 1, debt is
158
+ * Highest total-value leverage a liquidation threshold allows, floored:
159
+ * `floor((100% − buffer) / (100% − liquidationThreshold))`. At HF = 1, debt is
160
160
  * `liquidationThreshold × totalValue`, leaving `1 − liquidationThreshold` of
161
161
  * equity per unit of exposure; the {@link MAX_LEVERAGE_BUFFER_BPS} buffer
162
162
  * keeps the maxed position slightly away from that boundary.
@@ -164,14 +164,14 @@ const MAX_LEVERAGE_BUFFER_BPS = 500;
164
164
  * @example
165
165
  * ```ts
166
166
  * // liquidationThreshold: 9000 bps = 90%
167
- * calcMaxLeverage(9000) // (1 − 0.05) / (1 − 0.9) = 9.5x total exposure
167
+ * calcMaxLeverage(9000) // floor((1 − 0.05) / (1 − 0.9)) = 9x total exposure
168
168
  * ```
169
169
  * @throws If `liquidationThreshold` is 100% or more, which would make
170
170
  * leverage unbounded.
171
171
  **/
172
172
  function calcMaxLeverage(liquidationThreshold) {
173
173
  if (liquidationThreshold >= FULL) throw new Error("cannot compute max leverage: liquidation threshold is 100% or more");
174
- const leverage = (FULL - 500) / (FULL - liquidationThreshold);
174
+ const leverage = Math.floor((FULL - 500) / (FULL - liquidationThreshold));
175
175
  return Math.max(leverage, 1);
176
176
  }
177
177
  /**
@@ -1,3 +1,4 @@
1
+ import { iPausableAbi } from "../../../abi/iPausable.js";
1
2
  import { iPoolV310Abi } from "../../../abi/310/generated.js";
2
3
  import { AddressMap } from "../../utils/AddressMap.js";
3
4
  import { RAY } from "../../constants/math.js";
@@ -6,7 +7,6 @@ import { formatBN, formatBNvalue, percentFmt } from "../../utils/formatter.js";
6
7
  import "../../utils/index.js";
7
8
  import { BaseContract } from "../../base/BaseContract.js";
8
9
  import "../../base/index.js";
9
- import { iPausableAbi } from "../../../abi/iPausable.js";
10
10
  import { calcUtilization } from "../math.js";
11
11
  //#region src/sdk/market/pool/PoolV310Contract.ts
12
12
  const abi = [...iPoolV310Abi, ...iPausableAbi];
@@ -1,5 +1,5 @@
1
- import { ZapperContract } from "./ZapperContract.js";
2
1
  import { iethZapperAbi } from "../../../abi/iETHZapper.js";
2
+ import { ZapperContract } from "./ZapperContract.js";
3
3
  //#region src/sdk/market/zapper/IETHZapperContract.ts
4
4
  const abi = iethZapperAbi;
5
5
  var IETHZapperContract = class extends ZapperContract {
@@ -1,6 +1,6 @@
1
+ import { iZapperAbi } from "../../../abi/iZapper.js";
1
2
  import { BaseContract } from "../../base/BaseContract.js";
2
3
  import "../../base/index.js";
3
- import { iZapperAbi } from "../../../abi/iZapper.js";
4
4
  import { UnsupportedZapperFunctionError } from "./errors.js";
5
5
  //#region src/sdk/market/zapper/ZapperContract.ts
6
6
  /**
@@ -1,5 +1,5 @@
1
- import { AddressSet } from "../utils/AddressSet.js";
2
1
  import { ierc20Abi } from "../../abi/iERC20.js";
2
+ import { AddressSet } from "../utils/AddressSet.js";
3
3
  import "../constants/addresses.js";
4
4
  import { PERCENTAGE_FACTOR, RAY } from "../constants/math.js";
5
5
  import "../constants/index.js";
@@ -1,6 +1,6 @@
1
1
  import { errorAbis } from "../../../abi/errors.js";
2
- import { generateCastTraceCall } from "./cast.js";
3
2
  import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
3
+ import { generateCastTraceCall } from "./cast.js";
4
4
  import { simulateMulticall } from "./simulateMulticall.js";
5
5
  import { BaseError, CallExecutionError, ContractFunctionRevertedError, decodeFunctionData, decodeFunctionResult, encodeFunctionData, parseAbi } from "viem";
6
6
  import { getAction, parseAccount } from "viem/utils";
@@ -127,8 +127,8 @@ declare function calcNetStrategyApy(opportunity: StrategyRateInputs, totalCollat
127
127
  **/
128
128
  declare const MAX_LEVERAGE_BUFFER_BPS = 500;
129
129
  /**
130
- * Highest total-value leverage a liquidation threshold allows:
131
- * `(100% − buffer) / (100% − liquidationThreshold)`. At HF = 1, debt is
130
+ * Highest total-value leverage a liquidation threshold allows, floored:
131
+ * `floor((100% − buffer) / (100% − liquidationThreshold))`. At HF = 1, debt is
132
132
  * `liquidationThreshold × totalValue`, leaving `1 − liquidationThreshold` of
133
133
  * equity per unit of exposure; the {@link MAX_LEVERAGE_BUFFER_BPS} buffer
134
134
  * keeps the maxed position slightly away from that boundary.
@@ -136,7 +136,7 @@ declare const MAX_LEVERAGE_BUFFER_BPS = 500;
136
136
  * @example
137
137
  * ```ts
138
138
  * // liquidationThreshold: 9000 bps = 90%
139
- * calcMaxLeverage(9000) // (1 − 0.05) / (1 − 0.9) = 9.5x total exposure
139
+ * calcMaxLeverage(9000) // floor((1 − 0.05) / (1 − 0.9)) = 9x total exposure
140
140
  * ```
141
141
  * @throws If `liquidationThreshold` is 100% or more, which would make
142
142
  * leverage unbounded.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "16.0.0-next.1",
3
+ "version": "16.0.0-next.2",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {