@gearbox-protocol/sdk 15.1.0-next.20 → 15.1.0-next.22

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 (33) hide show
  1. package/dist/cjs/sdk/chain/chains.js +9 -0
  2. package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +11 -0
  3. package/dist/cjs/sdk/positions/PositionsService.js +22 -11
  4. package/dist/cjs/sdk/positions/types.js +2 -4
  5. package/dist/esm/dev/AccountOpener.js +1 -1
  6. package/dist/esm/dev/withdrawalUtils.js +1 -1
  7. package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
  8. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  9. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -2
  10. package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -1
  11. package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  12. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  13. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  14. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  15. package/dist/esm/sdk/base/TokensMeta.js +3 -3
  16. package/dist/esm/sdk/chain/chains.js +9 -0
  17. package/dist/esm/sdk/chain/detectNetwork.js +1 -1
  18. package/dist/esm/sdk/core/createAddressProvider.js +1 -1
  19. package/dist/esm/sdk/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
  20. package/dist/esm/sdk/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
  21. package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
  22. package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +11 -0
  23. package/dist/esm/sdk/market/pool/PoolV310Contract.js +1 -1
  24. package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
  25. package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
  26. package/dist/esm/sdk/pools/PoolService.js +1 -1
  27. package/dist/esm/sdk/positions/PositionsService.js +22 -11
  28. package/dist/esm/sdk/positions/types.js +2 -4
  29. package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
  30. package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +4 -0
  31. package/dist/types/sdk/market/oracle/types.d.ts +9 -0
  32. package/dist/types/sdk/positions/types.d.ts +1 -3
  33. package/package.json +1 -1
@@ -113,6 +113,13 @@ const chains = {
113
113
  address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
114
114
  symbol: "USDC"
115
115
  },
116
+ tokenPrettyNames: require_sdk_utils_AddressMap.AddressMap.fromRecord({
117
+ "0x924d24c238db7ecae2aa3a19430239ed684bde4a": "Beefy WBTC/cbBTC/hemiBTC",
118
+ "0x403cc0d2694ec2639101f32b146b90d766461ce9": "Beefy wstETH/tETH",
119
+ "0x02a4cceed3c400b5ba9fd22ad6ec18d8f7a3d48e": "Beefy ETH+/WETH",
120
+ "0x31454faa1daa04cacf59a6bd37681da9160d092a": "Beefy rETH/WETH",
121
+ "0x1a711a5bc48b5c1352c1882fa65dc14b5b9e829d": "Beefy osETH/WETH"
122
+ }),
116
123
  firstBlock: 22358644n,
117
124
  gasLimit: 550000000n
118
125
  }, "ethereum-rpc"),
@@ -229,6 +236,7 @@ const chains = {
229
236
  address: "0xe7cd86e13AC4309349F30B3435a9d337750fC82D",
230
237
  symbol: "USDT0"
231
238
  },
239
+ tokenPrettyNames: require_sdk_utils_AddressMap.AddressMap.fromRecord({ "0x942644106b073e30d72c2c5d7529d5c296ea91ab": "Curve AUSD/USDC/USDT0" }),
232
240
  firstBlock: 34650262n,
233
241
  gasLimit: 150000000n
234
242
  }),
@@ -302,6 +310,7 @@ const chains = {
302
310
  address: "0x796Ea11Fa2dD751eD01b53C372fFDB4AAa8f00F9",
303
311
  symbol: "USDC"
304
312
  },
313
+ tokenPrettyNames: require_sdk_utils_AddressMap.AddressMap.fromRecord({ "0x5d37f9b272ca7cda2a05245b9a503746eefac88f": "Curve mRe7Yield/USDC" }),
305
314
  firstBlock: 16672963n,
306
315
  gasLimit: 550000000n
307
316
  }),
@@ -138,6 +138,17 @@ var PriceOracleBaseContract = class extends require_sdk_base_BaseContract.BaseCo
138
138
  return amount * 10n ** BigInt(this.tokensMeta.decimals(token)) / price;
139
139
  }
140
140
  /**
141
+ * {@inheritDoc IPriceOracleContract.safeConvert}
142
+ **/
143
+ safeConvert(from, to, amount) {
144
+ try {
145
+ return this.convert(from, to, amount);
146
+ } catch (e) {
147
+ this.logger?.debug(`cannot convert ${this.labelAddress(from)} to ${this.labelAddress(to)}: ${e}`);
148
+ return null;
149
+ }
150
+ }
151
+ /**
141
152
  * {@inheritDoc IPriceOracleContract.safeConvertToUSD}
142
153
  **/
143
154
  safeConvertToUSD(token, amount) {
@@ -154,6 +154,24 @@ var PositionsService = class extends require_sdk_base_SDKConstruct.SDKConstruct
154
154
  const borrowRate = this.borrowRate(snapshot);
155
155
  const timeToLiquidation = this.timeToLiquidation(snapshot);
156
156
  const liquidationPrice = this.liquidationPrice(snapshot);
157
+ const zeroDebt = ca.debt === 0n;
158
+ const collaterals = [];
159
+ let totalValue = zeroDebt ? 0n : ca.totalValue;
160
+ let totalValueUSD = zeroDebt ? 0n : ca.totalValueUSD;
161
+ for (const t of ca.tokens) {
162
+ if (t.balance <= 10n) continue;
163
+ collaterals.push({
164
+ collateral: priceOracle.toTokenAmount(t.token, t.balance),
165
+ quota: priceOracle.toTokenAmount(market.underlying, t.quota),
166
+ withdrawals: withdrawals.get(t.token) ?? []
167
+ });
168
+ if (zeroDebt) {
169
+ const value = priceOracle.safeConvert(t.token, market.underlying, t.balance) || 0n;
170
+ totalValue += value;
171
+ const usd = priceOracle.safeConvertToUSD(t.token, t.balance) || 0n;
172
+ totalValueUSD += usd;
173
+ }
174
+ }
157
175
  return {
158
176
  kind: "strategy",
159
177
  chainId: this.sdk.chainId,
@@ -161,7 +179,7 @@ var PositionsService = class extends require_sdk_base_SDKConstruct.SDKConstruct
161
179
  creditAccount: ca.creditAccount,
162
180
  name: target ? require_sdk_market_strategyName.strategyName(this.sdk.tokensMeta.mustGetToken(target), token, this.sdk.chainId) : token.symbol,
163
181
  targetCollateral: target ? this.sdk.tokensMeta.mustGetToken(target) : null,
164
- leverage: require_sdk_market_math.calcPositionLeverage(ca.totalValue, totalDebtValue),
182
+ leverage: require_sdk_market_math.calcPositionLeverage(totalValue, totalDebtValue),
165
183
  borrowApy: require_sdk_market_math.calcBorrowApy(pool.baseInterestRate, suite.creditManager.feeInterest),
166
184
  totalDebt: {
167
185
  token,
@@ -170,21 +188,14 @@ var PositionsService = class extends require_sdk_base_SDKConstruct.SDKConstruct
170
188
  },
171
189
  totalValue: {
172
190
  token,
173
- value: ca.totalValue,
174
- valueUsd: require_sdk_market_math.usdToNumber(ca.totalValueUSD)
191
+ value: totalValue,
192
+ valueUsd: require_sdk_market_math.usdToNumber(totalValueUSD)
175
193
  },
176
194
  healthFactor: require_sdk_market_math.healthFactorBps(ca.healthFactor),
177
195
  borrowRate,
178
196
  timeToLiquidation,
179
197
  liquidationPrice,
180
- collaterals: ca.tokens.flatMap((t) => {
181
- if ((t.mask & ca.enabledTokensMask) === 0n || t.balance <= 10n) return [];
182
- return [{
183
- collateral: priceOracle.toTokenAmount(t.token, t.balance),
184
- quota: priceOracle.toTokenAmount(market.underlying, t.quota),
185
- withdrawals: withdrawals.get(t.token) ?? []
186
- }];
187
- })
198
+ collaterals
188
199
  };
189
200
  }
190
201
  /**
@@ -2,15 +2,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("../constants/math.js");
3
3
  //#region src/sdk/positions/types.ts
4
4
  /**
5
- * Builds an {@link AccountSnapshot} from on-chain credit account data: the
6
- * enabled, above-dust tokens become assets and quotas, and `totalDebt` is
7
- * principal plus accrued interest and fees.
5
+ * Builds an {@link AccountSnapshot} from on-chain credit account data
8
6
  **/
9
7
  function accountSnapshotFromCreditAccountData(ca) {
10
8
  const assets = [];
11
9
  const quotas = [];
12
10
  for (const t of ca.tokens) {
13
- if ((t.mask & ca.enabledTokensMask) === 0n || t.balance <= 10n) continue;
11
+ if (t.balance <= 10n) continue;
14
12
  assets.push({
15
13
  token: t.token,
16
14
  balance: t.balance
@@ -1,9 +1,9 @@
1
- import { ierc20Abi } from "../abi/iERC20.js";
2
1
  import { iCreditFacadeV310Abi } from "../abi/310/generated.js";
3
2
  import { AddressMap } from "../sdk/utils/AddressMap.js";
4
3
  import { AddressSet } from "../sdk/utils/AddressSet.js";
5
4
  import { AssetsMap } from "../sdk/utils/AssetsMap.js";
6
5
  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";
2
1
  import { getNetworkType } from "../sdk/chain/chains.js";
3
2
  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 { iZapperAbi } from "../../abi/iZapper.js";
2
1
  import { iPoolV310Abi } from "../../abi/310/generated.js";
2
+ import { iZapperAbi } from "../../abi/iZapper.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";
2
1
  import { iCreditFacadeV310Abi } from "../../abi/310/generated.js";
3
2
  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,5 +1,3 @@
1
- import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
2
- import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
3
1
  import { AP_REWARDS_COMPRESSOR } from "../constants/address-provider.js";
4
2
  import { ADDRESS_0X0 } from "../constants/addresses.js";
5
3
  import { MAX_UINT256 } from "../constants/math.js";
@@ -10,6 +8,8 @@ import "../base/index.js";
10
8
  import { AccountBotsService } from "./bots/AccountBotsService.js";
11
9
  import "./bots/index.js";
12
10
  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,4 +1,3 @@
1
- import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
2
1
  import { AddressSet } from "../../utils/AddressSet.js";
3
2
  import { bytes32ToString } from "../../utils/bytes32ToString.js";
4
3
  import { ADDRESS_0X0 } from "../../constants/addresses.js";
@@ -20,6 +19,7 @@ import { SecuritizeLiquidatorContract } from "../../market/rwa/securitize/Securi
20
19
  import "../../market/rwa/securitize/index.js";
21
20
  import "../../market/index.js";
22
21
  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";
2
1
  import { BaseContract } from "../../base/BaseContract.js";
3
2
  import "../../base/index.js";
4
3
  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 { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
2
1
  import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
2
+ import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
3
3
  //#region src/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.ts
4
4
  const abi = iWithdrawalCompressorV310Abi;
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
2
1
  import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
2
+ import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.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";
2
1
  import { encodeDelayedIntent } from "./intent-codec.js";
3
2
  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";
4
1
  import { AddressMap } from "../utils/AddressMap.js";
5
2
  import { AddressSet } from "../utils/AddressSet.js";
6
3
  import { bytes32ToString } from "../utils/bytes32ToString.js";
7
4
  import { getAssetType } from "../chain/chains.js";
8
5
  import { formatBN } from "../utils/formatter.js";
9
6
  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
  /**
@@ -112,6 +112,13 @@ const chains = {
112
112
  address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
113
113
  symbol: "USDC"
114
114
  },
115
+ tokenPrettyNames: AddressMap.fromRecord({
116
+ "0x924d24c238db7ecae2aa3a19430239ed684bde4a": "Beefy WBTC/cbBTC/hemiBTC",
117
+ "0x403cc0d2694ec2639101f32b146b90d766461ce9": "Beefy wstETH/tETH",
118
+ "0x02a4cceed3c400b5ba9fd22ad6ec18d8f7a3d48e": "Beefy ETH+/WETH",
119
+ "0x31454faa1daa04cacf59a6bd37681da9160d092a": "Beefy rETH/WETH",
120
+ "0x1a711a5bc48b5c1352c1882fa65dc14b5b9e829d": "Beefy osETH/WETH"
121
+ }),
115
122
  firstBlock: 22358644n,
116
123
  gasLimit: 550000000n
117
124
  }, "ethereum-rpc"),
@@ -228,6 +235,7 @@ const chains = {
228
235
  address: "0xe7cd86e13AC4309349F30B3435a9d337750fC82D",
229
236
  symbol: "USDT0"
230
237
  },
238
+ tokenPrettyNames: AddressMap.fromRecord({ "0x942644106b073e30d72c2c5d7529d5c296ea91ab": "Curve AUSD/USDC/USDT0" }),
231
239
  firstBlock: 34650262n,
232
240
  gasLimit: 150000000n
233
241
  }),
@@ -301,6 +309,7 @@ const chains = {
301
309
  address: "0x796Ea11Fa2dD751eD01b53C372fFDB4AAa8f00F9",
302
310
  symbol: "USDC"
303
311
  },
312
+ tokenPrettyNames: AddressMap.fromRecord({ "0x5d37f9b272ca7cda2a05245b9a503746eefac88f": "Curve mRe7Yield/USDC" }),
304
313
  firstBlock: 16672963n,
305
314
  gasLimit: 550000000n
306
315
  }),
@@ -1,5 +1,5 @@
1
- import { ierc20Abi } from "../../abi/iERC20.js";
2
1
  import { chains } from "./chains.js";
2
+ import { ierc20Abi } from "../../abi/iERC20.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";
2
1
  import { AP_MARKET_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR } from "../constants/address-provider.js";
3
2
  import { isV310 } from "../constants/versions.js";
4
3
  import "../constants/index.js";
5
4
  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 { accountMigratorAbi } from "../../../../abi/AccountMigrator.js";
2
1
  import { AbstractAdapterContract } from "./AbstractAdapter.js";
2
+ import { accountMigratorAbi } from "../../../../abi/AccountMigrator.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";
2
1
  import { MissingSerializedParamsError } from "../../../base/errors.js";
3
2
  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";
2
1
  import { iCreditFacadeMulticallV310Abi, iCreditFacadeV310Abi } from "../../../abi/310/generated.js";
3
2
  import { BaseContract } from "../../base/BaseContract.js";
4
3
  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,
@@ -137,6 +137,17 @@ var PriceOracleBaseContract = class extends BaseContract {
137
137
  return amount * 10n ** BigInt(this.tokensMeta.decimals(token)) / price;
138
138
  }
139
139
  /**
140
+ * {@inheritDoc IPriceOracleContract.safeConvert}
141
+ **/
142
+ safeConvert(from, to, amount) {
143
+ try {
144
+ return this.convert(from, to, amount);
145
+ } catch (e) {
146
+ this.logger?.debug(`cannot convert ${this.labelAddress(from)} to ${this.labelAddress(to)}: ${e}`);
147
+ return null;
148
+ }
149
+ }
150
+ /**
140
151
  * {@inheritDoc IPriceOracleContract.safeConvertToUSD}
141
152
  **/
142
153
  safeConvertToUSD(token, amount) {
@@ -1,4 +1,3 @@
1
- import { iPausableAbi } from "../../../abi/iPausable.js";
2
1
  import { iPoolV310Abi } from "../../../abi/310/generated.js";
3
2
  import { AddressMap } from "../../utils/AddressMap.js";
4
3
  import { RAY } from "../../constants/math.js";
@@ -7,6 +6,7 @@ import { formatBN, formatBNvalue, percentFmt } from "../../utils/formatter.js";
7
6
  import "../../utils/index.js";
8
7
  import { BaseContract } from "../../base/BaseContract.js";
9
8
  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 { iethZapperAbi } from "../../../abi/iETHZapper.js";
2
1
  import { ZapperContract } from "./ZapperContract.js";
2
+ import { iethZapperAbi } from "../../../abi/iETHZapper.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";
2
1
  import { BaseContract } from "../../base/BaseContract.js";
3
2
  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 { ierc20Abi } from "../../abi/iERC20.js";
2
1
  import { AddressSet } from "../utils/AddressSet.js";
2
+ import { ierc20Abi } from "../../abi/iERC20.js";
3
3
  import "../constants/addresses.js";
4
4
  import { PERCENTAGE_FACTOR, RAY } from "../constants/math.js";
5
5
  import "../constants/index.js";
@@ -153,6 +153,24 @@ var PositionsService = class extends SDKConstruct {
153
153
  const borrowRate = this.borrowRate(snapshot);
154
154
  const timeToLiquidation = this.timeToLiquidation(snapshot);
155
155
  const liquidationPrice = this.liquidationPrice(snapshot);
156
+ const zeroDebt = ca.debt === 0n;
157
+ const collaterals = [];
158
+ let totalValue = zeroDebt ? 0n : ca.totalValue;
159
+ let totalValueUSD = zeroDebt ? 0n : ca.totalValueUSD;
160
+ for (const t of ca.tokens) {
161
+ if (t.balance <= 10n) continue;
162
+ collaterals.push({
163
+ collateral: priceOracle.toTokenAmount(t.token, t.balance),
164
+ quota: priceOracle.toTokenAmount(market.underlying, t.quota),
165
+ withdrawals: withdrawals.get(t.token) ?? []
166
+ });
167
+ if (zeroDebt) {
168
+ const value = priceOracle.safeConvert(t.token, market.underlying, t.balance) || 0n;
169
+ totalValue += value;
170
+ const usd = priceOracle.safeConvertToUSD(t.token, t.balance) || 0n;
171
+ totalValueUSD += usd;
172
+ }
173
+ }
156
174
  return {
157
175
  kind: "strategy",
158
176
  chainId: this.sdk.chainId,
@@ -160,7 +178,7 @@ var PositionsService = class extends SDKConstruct {
160
178
  creditAccount: ca.creditAccount,
161
179
  name: target ? strategyName(this.sdk.tokensMeta.mustGetToken(target), token, this.sdk.chainId) : token.symbol,
162
180
  targetCollateral: target ? this.sdk.tokensMeta.mustGetToken(target) : null,
163
- leverage: calcPositionLeverage(ca.totalValue, totalDebtValue),
181
+ leverage: calcPositionLeverage(totalValue, totalDebtValue),
164
182
  borrowApy: calcBorrowApy(pool.baseInterestRate, suite.creditManager.feeInterest),
165
183
  totalDebt: {
166
184
  token,
@@ -169,21 +187,14 @@ var PositionsService = class extends SDKConstruct {
169
187
  },
170
188
  totalValue: {
171
189
  token,
172
- value: ca.totalValue,
173
- valueUsd: usdToNumber(ca.totalValueUSD)
190
+ value: totalValue,
191
+ valueUsd: usdToNumber(totalValueUSD)
174
192
  },
175
193
  healthFactor: healthFactorBps(ca.healthFactor),
176
194
  borrowRate,
177
195
  timeToLiquidation,
178
196
  liquidationPrice,
179
- collaterals: ca.tokens.flatMap((t) => {
180
- if ((t.mask & ca.enabledTokensMask) === 0n || t.balance <= 10n) return [];
181
- return [{
182
- collateral: priceOracle.toTokenAmount(t.token, t.balance),
183
- quota: priceOracle.toTokenAmount(market.underlying, t.quota),
184
- withdrawals: withdrawals.get(t.token) ?? []
185
- }];
186
- })
197
+ collaterals
187
198
  };
188
199
  }
189
200
  /**
@@ -1,15 +1,13 @@
1
1
  import "../constants/math.js";
2
2
  //#region src/sdk/positions/types.ts
3
3
  /**
4
- * Builds an {@link AccountSnapshot} from on-chain credit account data: the
5
- * enabled, above-dust tokens become assets and quotas, and `totalDebt` is
6
- * principal plus accrued interest and fees.
4
+ * Builds an {@link AccountSnapshot} from on-chain credit account data
7
5
  **/
8
6
  function accountSnapshotFromCreditAccountData(ca) {
9
7
  const assets = [];
10
8
  const quotas = [];
11
9
  for (const t of ca.tokens) {
12
- if ((t.mask & ca.enabledTokensMask) === 0n || t.balance <= 10n) continue;
10
+ if (t.balance <= 10n) continue;
13
11
  assets.push({
14
12
  token: t.token,
15
13
  balance: t.balance
@@ -1,6 +1,6 @@
1
1
  import { errorAbis } from "../../../abi/errors.js";
2
- import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
3
2
  import { generateCastTraceCall } from "./cast.js";
3
+ import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.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";
@@ -92,6 +92,10 @@ declare abstract class PriceOracleBaseContract<abi extends Abi | readonly unknow
92
92
  * {@inheritDoc IPriceOracleContract.convertFromUSD}
93
93
  **/
94
94
  convertFromUSD(to: Address, amount: bigint, reserve?: boolean): bigint;
95
+ /**
96
+ * {@inheritDoc IPriceOracleContract.safeConvert}
97
+ **/
98
+ safeConvert(from: Address, to: Address, amount: bigint): bigint | null;
95
99
  /**
96
100
  * {@inheritDoc IPriceOracleContract.safeConvertToUSD}
97
101
  **/
@@ -131,6 +131,15 @@ interface IPriceOracleContract extends IBaseContract {
131
131
  * @param reserve - Use reserve feeds instead of main.
132
132
  **/
133
133
  convert: (from: Address, to: Address, amount: bigint, reserve?: boolean) => bigint;
134
+ /**
135
+ * Like {@link convert}, but returns `null` instead of throwing when either
136
+ * token cannot be priced (missing or unsuccessful feed).
137
+ *
138
+ * @param from - Source token address.
139
+ * @param to - Destination token address.
140
+ * @param amount - Amount in source-token decimals.
141
+ **/
142
+ safeConvert: (from: Address, to: Address, amount: bigint) => bigint | null;
134
143
  /**
135
144
  * Converts a token amount to its USD value using latest known prices.
136
145
  *
@@ -82,9 +82,7 @@ interface AccountSnapshot {
82
82
  totalValue: bigint;
83
83
  }
84
84
  /**
85
- * Builds an {@link AccountSnapshot} from on-chain credit account data: the
86
- * enabled, above-dust tokens become assets and quotas, and `totalDebt` is
87
- * principal plus accrued interest and fees.
85
+ * Builds an {@link AccountSnapshot} from on-chain credit account data
88
86
  **/
89
87
  declare function accountSnapshotFromCreditAccountData(ca: CreditAccountData): AccountSnapshot;
90
88
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "15.1.0-next.20",
3
+ "version": "15.1.0-next.22",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {