@gearbox-protocol/sdk 16.0.0-next.14 → 16.0.0-next.16

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 (59) hide show
  1. package/dist/cjs/model/positions.schema.js +1 -1
  2. package/dist/cjs/onchain/accounts/intents/open-strategy.js +12 -3
  3. package/dist/cjs/onchain/accounts/intents/realize.js +11 -0
  4. package/dist/cjs/onchain/accounts/intents/testing/market.js +1 -0
  5. package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +6 -4
  6. package/dist/cjs/onchain/accounts/intents/tests/deposit.fixtures.js +5 -2
  7. package/dist/cjs/onchain/accounts/intents/utils/index.js +4 -0
  8. package/dist/cjs/onchain/accounts/intents/utils/price-impact.js +99 -0
  9. package/dist/cjs/onchain/accounts/intents/utils/router-path.js +98 -40
  10. package/dist/esm/dev/AccountOpener.js +1 -1
  11. package/dist/esm/dev/withdrawalUtils.js +1 -1
  12. package/dist/esm/model/positions.schema.js +1 -1
  13. package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
  14. package/dist/esm/onchain/accounts/intents/open-strategy.js +12 -3
  15. package/dist/esm/onchain/accounts/intents/realize.js +11 -0
  16. package/dist/esm/onchain/accounts/intents/testing/market.js +1 -0
  17. package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +6 -4
  18. package/dist/esm/onchain/accounts/intents/tests/deposit.fixtures.js +5 -2
  19. package/dist/esm/onchain/accounts/intents/utils/index.js +2 -1
  20. package/dist/esm/onchain/accounts/intents/utils/price-impact.js +96 -0
  21. package/dist/esm/onchain/accounts/intents/utils/router-path.js +98 -40
  22. package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
  23. package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  24. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  25. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  26. package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  27. package/dist/esm/onchain/base/TokensMeta.js +3 -3
  28. package/dist/esm/onchain/chain/detectNetwork.js +1 -1
  29. package/dist/esm/onchain/core/createAddressProvider.js +1 -1
  30. package/dist/esm/onchain/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
  31. package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
  32. package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +1 -1
  33. package/dist/esm/onchain/market/pool/PoolV310Contract.js +1 -1
  34. package/dist/esm/onchain/market/zapper/IETHZapperContract.js +1 -1
  35. package/dist/esm/onchain/market/zapper/ZapperContract.js +1 -1
  36. package/dist/esm/onchain/pools/PoolService.js +1 -1
  37. package/dist/esm/onchain/utils/viem/simulateWithPriceUpdates.js +1 -1
  38. package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
  39. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  40. package/dist/types/model/positions.d.ts +2 -2
  41. package/dist/types/model/positions.schema.d.ts +1 -47
  42. package/dist/types/onchain/accounts/index.d.ts +4 -4
  43. package/dist/types/onchain/accounts/intents/index.d.ts +4 -4
  44. package/dist/types/onchain/accounts/intents/open-strategy.d.ts +3 -0
  45. package/dist/types/onchain/accounts/intents/realize.d.ts +1 -1
  46. package/dist/types/onchain/accounts/intents/tail.d.ts +1 -1
  47. package/dist/types/onchain/accounts/intents/testing/expect.d.ts +1 -1
  48. package/dist/types/onchain/accounts/intents/testing/market.d.ts +2 -0
  49. package/dist/types/onchain/accounts/intents/testing/sdk-mock.d.ts +7 -0
  50. package/dist/types/onchain/accounts/intents/tests/deposit.fixtures.d.ts +1 -1
  51. package/dist/types/onchain/accounts/intents/types.d.ts +18 -2
  52. package/dist/types/onchain/accounts/intents/utils/index.d.ts +2 -1
  53. package/dist/types/onchain/accounts/intents/utils/price-impact.d.ts +49 -0
  54. package/dist/types/onchain/accounts/intents/utils/router-path.d.ts +9 -0
  55. package/dist/types/onchain/index.d.ts +4 -4
  56. package/dist/types/sdk/index.d.ts +2 -2
  57. package/dist/types/sdk/prepare/index.d.ts +2 -2
  58. package/dist/types/sdk/prepare/types.d.ts +4 -4
  59. package/package.json +1 -1
@@ -0,0 +1,96 @@
1
+ import { PERCENTAGE_FACTOR_1KK, PRICE_DECIMALS, WAD } from "../../../constants/math.js";
2
+ //#region src/onchain/accounts/intents/utils/price-impact.ts
3
+ /** `b1 = b0 / V0`: a dollar of the basket, the reference implementation's anchor. */
4
+ const PROBE_UNIT_USD_WAD = WAD;
5
+ /**
6
+ * `V0 = Σ b0ᵢ·pᵢ`, then `b1 = b0 / V0`, proportions kept.
7
+ *
8
+ * Refuses only what the reference refuses — a basket worth nothing, or one that
9
+ * rounds away entirely. Stricter guards here would report nothing where the old
10
+ * client reported a number.
11
+ */
12
+ function probeBasket(balances, oracle) {
13
+ if (balances.length === 0) return;
14
+ let basketWad = 0n;
15
+ for (const asset of balances) {
16
+ if (asset.balance <= 0n) continue;
17
+ const usd = oracle.safeConvertToUSD(asset.token, asset.balance);
18
+ if (usd !== null && usd > 0n) basketWad += usd * WAD / PRICE_DECIMALS;
19
+ }
20
+ if (basketWad <= 0n) return;
21
+ const probeWad = PROBE_UNIT_USD_WAD;
22
+ const scaled = balances.map((asset) => ({
23
+ token: asset.token,
24
+ balance: asset.balance * probeWad / basketWad
25
+ }));
26
+ if (!scaled.some((a) => a.balance > 0n)) return;
27
+ return {
28
+ balances: scaled,
29
+ basketWad,
30
+ probeWad
31
+ };
32
+ }
33
+ /** Fires the marginal-price quote for one leg; `undefined` if it cannot be measured. */
34
+ function startProbe(args) {
35
+ const basket = probeBasket(args.basket, args.oracle);
36
+ if (!basket) return;
37
+ return {
38
+ tokenOut: args.tokenOut,
39
+ basketWad: basket.basketWad,
40
+ probeWad: basket.probeWad,
41
+ probe: args.route(basket.balances).catch(() => void 0)
42
+ };
43
+ }
44
+ /** `convert` answers `0` for a negative amount, so convert the magnitude and re-sign. */
45
+ function toUnderlyingSigned(convert, token, amount) {
46
+ if (amount === 0n) return 0n;
47
+ const converted = convert(token, amount < 0n ? -amount : amount);
48
+ if (converted <= 0n) return;
49
+ return amount < 0n ? -converted : converted;
50
+ }
51
+ /**
52
+ * In `PERCENTAGE_FACTOR_1KK` (1_000_000 = 100%), negative for a loss. A base
53
+ * that is not positive falls back to the routed output.
54
+ */
55
+ function lossRate(args) {
56
+ const { lossUnd, expectedUnd, totalValue, netValue } = args;
57
+ const against = (base) => -(PERCENTAGE_FACTOR_1KK * lossUnd / (base > 0n ? base : expectedUnd));
58
+ return {
59
+ pathPriceImpact: against(expectedUnd),
60
+ netValuePriceImpact: against(netValue),
61
+ totalValuePriceImpact: against(totalValue)
62
+ };
63
+ }
64
+ /**
65
+ * Folds every leg into one rate, in the underlying — the unit its bases are in.
66
+ *
67
+ * All or nothing: a partial sum would understate the loss and draw a better
68
+ * price than the route offers.
69
+ */
70
+ async function collectPriceImpact(probes, ctx) {
71
+ if (probes.length === 0) return;
72
+ const quotes = await Promise.all(probes.map((leg) => leg.probe));
73
+ let expectedUnd = 0n;
74
+ let lossUnd = 0n;
75
+ for (const [index, leg] of probes.entries()) {
76
+ const unit = quotes[index];
77
+ if (unit === void 0 || unit <= 0n) return;
78
+ const expected = unit * leg.basketWad / leg.probeWad;
79
+ if (expected <= 0n) return;
80
+ const expectedInUnd = ctx.toUnderlying(leg.tokenOut, expected);
81
+ if (expectedInUnd <= 0n) return;
82
+ const loss = toUnderlyingSigned(ctx.toUnderlying, leg.tokenOut, expected - leg.realAmount);
83
+ if (loss === void 0) return;
84
+ expectedUnd += expectedInUnd;
85
+ lossUnd += loss;
86
+ }
87
+ if (expectedUnd <= 0n) return;
88
+ return lossRate({
89
+ lossUnd,
90
+ expectedUnd,
91
+ totalValue: ctx.totalValue,
92
+ netValue: ctx.netValue
93
+ });
94
+ }
95
+ //#endregion
96
+ export { collectPriceImpact, lossRate, startProbe };
@@ -1,5 +1,6 @@
1
1
  import { toRouterCaSlice } from "./common.js";
2
2
  import { convertAmount } from "./convert-amount.js";
3
+ import { startProbe } from "./price-impact.js";
3
4
  //#region src/onchain/accounts/intents/utils/router-path.ts
4
5
  /**
5
6
  * The engine's only door to the pathfinder.
@@ -17,68 +18,124 @@ function createRouterPaths(args) {
17
18
  collateralTokens: suite.creditManager.collateralTokens.map((t) => t.toLowerCase())
18
19
  };
19
20
  const router = sdk.routerFor({ creditFacade: suite.creditFacade.address });
21
+ const { priceOracle } = sdk.marketRegister.findByCreditManager(creditAccount.creditManager);
22
+ const quoteSwap = (input) => {
23
+ const spending = [{
24
+ token: input.tokenIn,
25
+ balance: input.amount + input.keep
26
+ }];
27
+ return input.keep > 0n ? router.findManyToOnePath({
28
+ creditAccount: toRouterCaSlice(creditAccount, spending),
29
+ creditManager: cmSlice,
30
+ expectedBalances: spending,
31
+ leftoverBalances: [{
32
+ token: input.tokenIn,
33
+ balance: input.keep
34
+ }],
35
+ target: input.tokenOut,
36
+ slippage
37
+ }) : router.findOneTokenPath({
38
+ creditAccount: toRouterCaSlice(creditAccount, spending),
39
+ creditManager: cmSlice,
40
+ tokenIn: input.tokenIn,
41
+ tokenOut: input.tokenOut,
42
+ amount: input.amount,
43
+ slippage
44
+ });
45
+ };
46
+ const quoteClose = (balances) => router.findBestClosePath({
47
+ creditAccount: toRouterCaSlice(creditAccount, balances),
48
+ creditManager: cmSlice,
49
+ balances: {
50
+ expectedBalances: balances,
51
+ leftoverBalances: [],
52
+ tokensToClaim: []
53
+ },
54
+ slippage
55
+ });
56
+ const quoteOpen = (expectedBalances, leftoverBalances, target) => router.findOpenStrategyPath({
57
+ creditManager: cmSlice,
58
+ expectedBalances,
59
+ leftoverBalances,
60
+ target,
61
+ slippage
62
+ });
20
63
  return {
21
64
  async swap({ tokenIn, tokenOut, amount, keep = 0n }) {
22
65
  if (amount <= 0n) return {
23
66
  amount: 0n,
24
67
  minAmount: 0n,
25
- calls: []
68
+ calls: [],
69
+ probe: void 0
26
70
  };
27
71
  if (keep < 0n) throw new Error(`swap: spending ${amount} of ${tokenIn} exceeds its balance`);
28
- if (keep > 0n) {
29
- const expectedBalances = [{
30
- token: tokenIn,
31
- balance: amount + keep
32
- }];
33
- return router.findManyToOnePath({
34
- creditAccount: toRouterCaSlice(creditAccount, expectedBalances),
35
- creditManager: cmSlice,
36
- expectedBalances,
37
- leftoverBalances: [{
38
- token: tokenIn,
39
- balance: keep
40
- }],
41
- target: tokenOut,
42
- slippage
43
- });
44
- }
45
- return router.findOneTokenPath({
46
- creditAccount: toRouterCaSlice(creditAccount, [{
72
+ const probe = startProbe({
73
+ basket: [{
47
74
  token: tokenIn,
48
75
  balance: amount
49
- }]),
50
- creditManager: cmSlice,
76
+ }],
77
+ tokenOut,
78
+ oracle: priceOracle,
79
+ route: async ([only]) => {
80
+ if (!only) return 0n;
81
+ return (await quoteSwap({
82
+ tokenIn: only.token,
83
+ tokenOut,
84
+ amount: only.balance,
85
+ keep: 0n
86
+ })).amount;
87
+ }
88
+ });
89
+ const leg = await quoteSwap({
51
90
  tokenIn,
52
91
  tokenOut,
53
92
  amount,
54
- slippage
93
+ keep
55
94
  });
95
+ return {
96
+ ...leg,
97
+ probe: probe && {
98
+ ...probe,
99
+ realAmount: leg.amount
100
+ }
101
+ };
56
102
  },
57
103
  async closeAll({ balances }) {
58
- const { amount, minAmount, calls } = await router.findBestClosePath({
59
- creditAccount: toRouterCaSlice(creditAccount, balances),
60
- creditManager: cmSlice,
61
- balances: {
62
- expectedBalances: balances,
63
- leftoverBalances: [],
64
- tokensToClaim: []
65
- },
66
- slippage
104
+ const probe = startProbe({
105
+ basket: balances,
106
+ tokenOut: creditAccount.underlying,
107
+ oracle: priceOracle,
108
+ route: async (quoted) => (await quoteClose(quoted)).amount
67
109
  });
68
- return {
110
+ const { amount, minAmount, calls } = await quoteClose(balances);
111
+ const leg = {
69
112
  amount,
70
113
  minAmount,
71
114
  calls: [...calls]
72
115
  };
116
+ return {
117
+ ...leg,
118
+ probe: probe && {
119
+ ...probe,
120
+ realAmount: leg.amount
121
+ }
122
+ };
73
123
  },
74
124
  async openStrategy({ expectedBalances, leftoverBalances, target }) {
75
- return router.findOpenStrategyPath({
76
- creditManager: cmSlice,
77
- expectedBalances,
78
- leftoverBalances,
79
- target,
80
- slippage
125
+ const probe = startProbe({
126
+ basket: expectedBalances,
127
+ tokenOut: target,
128
+ oracle: priceOracle,
129
+ route: async (balances) => (await quoteOpen(balances, [], target)).amount
81
130
  });
131
+ const leg = await quoteOpen(expectedBalances, leftoverBalances, target);
132
+ return {
133
+ ...leg,
134
+ probe: probe && {
135
+ ...probe,
136
+ realAmount: leg.amount
137
+ }
138
+ };
82
139
  }
83
140
  };
84
141
  }
@@ -98,7 +155,8 @@ function createOraclePaths(args) {
98
155
  const estimate = (amount) => ({
99
156
  amount,
100
157
  minAmount: amount,
101
- calls: []
158
+ calls: [],
159
+ probe: void 0
102
160
  });
103
161
  return {
104
162
  async swap({ tokenIn, tokenOut, amount }) {
@@ -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/onchain/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/onchain/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/onchain/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/onchain/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/onchain/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 { SdkRWADataNotLoadedError } from "../core/errors.js";
11
11
  import { executeMulticallBatches } from "../utils/viem/executeMulticallBatches.js";
12
12
  //#region src/onchain/base/TokensMeta.ts
@@ -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/onchain/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/onchain/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/onchain/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/onchain/market/credit/CreditFacadeV310BaseContract.ts
6
6
  const abi = [
7
7
  ...iCreditFacadeV310Abi,
@@ -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";
@@ -8,6 +7,7 @@ import "../../utils/index.js";
8
7
  import { SdkRWADataNotLoadedError } from "../../core/errors.js";
9
8
  import { BaseContract } from "../../base/BaseContract.js";
10
9
  import "../../base/index.js";
10
+ import { iPausableAbi } from "../../../abi/iPausable.js";
11
11
  //#region src/onchain/market/pool/PoolV310Contract.ts
12
12
  const abi = [...iPoolV310Abi, ...iPausableAbi];
13
13
  var PoolV310Contract = class extends BaseContract {
@@ -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/onchain/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/onchain/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";
@@ -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";
@@ -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 "../../onchain/utils/AddressMap.js";
3
+ import { ierc20Abi } from "../../abi/iERC20.js";
4
4
  import "../../onchain/index.js";
5
5
  import { UnexpectedFacadeEventOrderError } from "./errors.js";
6
6
  import { getAddress, isAddressEqual, parseEventLogs } from "viem";
@@ -470,9 +470,9 @@ interface PositionsTotals {
470
470
  **/
471
471
  currentYield: ApyBreakdown | null;
472
472
  /**
473
- * Profit and loss over every position, in USD terms of {@link PnlBreakdown}.
473
+ * Profit and loss over every position in USD.
474
474
  **/
475
- pnl: PnlBreakdown | null;
475
+ pnlUsd: number | null;
476
476
  /**
477
477
  * Net value of every position in US dollars.
478
478
  **/
@@ -1020,53 +1020,7 @@ declare const positionsTotalsSchema: z.ZodObject<{
1020
1020
  }, z.core.$strip>>;
1021
1021
  }, z.core.$strip>], "kind">>>;
1022
1022
  }, z.core.$strip>>;
1023
- pnl: z.ZodNullable<z.ZodObject<{
1024
- organic: z.ZodObject<{
1025
- value: z.ZodCodec<z.ZodUnion<[z.ZodString, z.ZodBigInt]>, z.ZodBigInt>;
1026
- valueUsd: z.ZodNullable<z.ZodNumber>;
1027
- token: z.ZodObject<{
1028
- chainId: z.ZodNumber;
1029
- address: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
1030
- symbol: z.ZodString;
1031
- name: z.ZodString;
1032
- decimals: z.ZodNumber;
1033
- assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
1034
- }, z.core.$strip>;
1035
- }, z.core.$strip>;
1036
- total: z.ZodObject<{
1037
- value: z.ZodCodec<z.ZodUnion<[z.ZodString, z.ZodBigInt]>, z.ZodBigInt>;
1038
- valueUsd: z.ZodNullable<z.ZodNumber>;
1039
- token: z.ZodObject<{
1040
- chainId: z.ZodNumber;
1041
- address: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
1042
- symbol: z.ZodString;
1043
- name: z.ZodString;
1044
- decimals: z.ZodNumber;
1045
- assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
1046
- }, z.core.$strip>;
1047
- }, z.core.$strip>;
1048
- rewards: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
1049
- value: z.ZodCodec<z.ZodUnion<[z.ZodString, z.ZodBigInt]>, z.ZodBigInt>;
1050
- valueUsd: z.ZodNullable<z.ZodNumber>;
1051
- token: z.ZodObject<{
1052
- chainId: z.ZodNumber;
1053
- address: z.ZodCodec<z.ZodString, z.ZodCustom<`0x${string}`, `0x${string}`>>;
1054
- symbol: z.ZodString;
1055
- name: z.ZodString;
1056
- decimals: z.ZodNumber;
1057
- assetType: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"Stable">, z.ZodLiteral<"ETH">, z.ZodLiteral<"BTC">]>>;
1058
- }, z.core.$strip>;
1059
- kind: z.ZodLiteral<"token">;
1060
- }, z.core.$strip>, z.ZodObject<{
1061
- kind: z.ZodLiteral<"point">;
1062
- points: z.ZodArray<z.ZodObject<{
1063
- id: z.ZodString;
1064
- name: z.ZodString;
1065
- multiplier: z.ZodNullable<z.ZodNumber>;
1066
- value: z.ZodNumber;
1067
- }, z.core.$strip>>;
1068
- }, z.core.$strip>], "kind">>;
1069
- }, z.core.$strip>>;
1023
+ pnlUsd: z.ZodNullable<z.ZodNumber>;
1070
1024
  netValueUsd: z.ZodNullable<z.ZodNumber>;
1071
1025
  claimableUsd: z.ZodNullable<z.ZodNumber>;
1072
1026
  }, z.core.$strip>;
@@ -21,10 +21,10 @@ import { PeripheryCompressorV310Contract } from "./bots/PeripheryCompressorV310C
21
21
  import "./bots/index.js";
22
22
  import { CreditAccountsServiceV310 } from "./CreditAccountsServiceV310.js";
23
23
  import { LeverageBand } from "./intents/leverage-band.js";
24
- import { OpenStrategyPreview, OpenStrategyProps } from "./intents/open-strategy.js";
25
- import { IntentPreviewError, PreviewErrorDetails, PreviewErrorReason, PreviewRefusal, refuse } from "./intents/refusal.js";
26
- import { AddCollateralIntent, AdjustLeverageIntent, CreditAccountSlice, DelayableIntent, DelayedRoute, DelayedStart, DelayedStartResult, DepositStrategyIntent, FinishIntentProps, InstantRoute, IntentPreviewResult, IntentRoutesResult, OperationState, RepayStrategyIntent, ResumableIntent, RouteRefusals, StartIntent, WithdrawAssetIntent, WithdrawStrategyIntent } from "./intents/types.js";
27
24
  import { AccountCalculatorOperation } from "./intents/operations.js";
25
+ import { IntentPreviewError, PreviewErrorDetails, PreviewErrorReason, PreviewRefusal, refuse } from "./intents/refusal.js";
26
+ import { AddCollateralIntent, AdjustLeverageIntent, CreditAccountSlice, DelayableIntent, DelayedRoute, DelayedStart, DelayedStartResult, DepositStrategyIntent, FinishIntentProps, InstantRoute, IntentPreviewResult, IntentRoutesResult, OperationState, PathLossRate, RepayStrategyIntent, ResumableIntent, RouteRefusals, StartIntent, WithdrawAssetIntent, WithdrawStrategyIntent } from "./intents/types.js";
27
+ import { OpenStrategyPreview, OpenStrategyProps } from "./intents/open-strategy.js";
28
28
  import { fetchCreditAccountSlice, toCreditAccountSlice } from "./intents/utils/credit-account-slice.js";
29
29
  import { CreditAccountOperationsService, OpenStrategyPreviewResult } from "./intents/index.js";
30
30
  import { LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS } from "./liquidations/constants.js";
@@ -32,4 +32,4 @@ import { BuildLiquidationTxProps, BuildLiquidationTxPropsBase, GetLiquidatableAc
32
32
  import { LiquidationsService } from "./liquidations/LiquidationsService.js";
33
33
  import { MultichainLiquidationsService } from "./liquidations/MultichainLiquidationsService.js";
34
34
  import "./liquidations/index.js";
35
- export { AbstractWithdrawalCompressorContract, AccountBotsService, type AccountCalculatorOperation, AccountToCheck, type AddCollateralIntent, type AdjustLeverageIntent, AssembleCaOperationsProps, AssembleClaimDelayedCallsProps, AssembleCloseCreditAccountCallsProps, AssembleRepayCreditAccountCallsProps, AssembleStartDelayedWithdrawalCallsProps, BotStatusCall, BotsDirectResponse, BuildLiquidationTxProps, BuildLiquidationTxPropsBase, CMSlice, ClaimFarmRewardsProps, ClaimableWithdrawal, CloseCreditAccountResult, ConnectedBotsCall, ConnectedBotsPerAccount, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountDataCall, CreditAccountFilter, CreditAccountOperationResult, CreditAccountOperationsService, CreditAccountReadOptions, type CreditAccountSlice, CreditAccountsCall, CreditAccountsQuery, CreditAccountsReadOptions, CreditAccountsServiceV310, CreditAccountsTarget, CreditManagerFilter, CreditManagerOperationResult, CurrentWithdrawals, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, type DelayableIntent, DelayedIntentExtended, type DelayedRoute, type DelayedStart, type DelayedStartResult, type DepositStrategyIntent, EncodableCreditAccountOperation, type FinishIntentProps, FullyLiquidateProps, FullyLiquidateResult, GetApprovalAddressProps, GetConnectedBotsResponse, GetConnectedBotsResult, GetConnectedMigrationBotsResult, GetCreditAccountsArgs, GetCreditAccountsOptions, GetExternalAccountCurrentWithdrawalsProps, GetLiquidatableAccountsProps, GetLiquidationDetailsProps, GetLiquidationDetailsPropsBase, GetLiquidationPositionsProps, GetLiquidationPositionsPropsBase, GetPendingWithdrawalsProps, GetPendingWithdrawalsResult, GetWithdrawalRequestResultProps, ICreditAccountsService, IRedemptionLoggerContract, IWithdrawalCompressorContract, type InstantRoute, IntentPreviewError, type IntentPreviewResult, type IntentRoutesResult, InvalidDelayedIntentError, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, type LeverageBand, LiquidationsService, LoadRWALiquidatorsProps, MulticallWithFailure, MultichainLiquidationsService, OnchainLiquidationCall, OnchainLiquidationData, OnchainLiquidationOutput, OnchainRequestableWithdrawal, OpenCAProps, type OpenStrategyPreview, OpenStrategyPreviewResult, type OpenStrategyProps, type OperationState, PartiallyLiquidateProps, PendingWithdrawal, PeripheryCompressorV310Contract, PreviewDelayedWithdrawalProps, type PreviewErrorDetails, type PreviewErrorReason, type PreviewRefusal, RWALiquidatorInfo, RedemptionLog, RedemptionLoggerV310Contract, type RepayStrategyIntent, RequestableWithdrawal, type ResumableIntent, Rewards, type RouteRefusals, SetBotProps, SetBotResult, type StartIntent, type WithdrawAssetIntent, type WithdrawStrategyIntent, WithdrawableAsset, WithdrawalCompressorLocation, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, WithdrawalCompressorVersion, WithdrawalOutput, WithdrawalStatus, WithdrawalsState, createRedemptionLogger, createWithdrawalCompressor, decodeDelayedIntent, encodeDelayedIntent, fetchCreditAccountSlice, getWithdrawalCompressorAddress, iCreditAccountAbi, refuse, toClaimableWithdrawal, toCreditAccountSlice, toPendingWithdrawal, toRequestableWithdrawal, toWithdrawalStatus };
35
+ export { AbstractWithdrawalCompressorContract, AccountBotsService, type AccountCalculatorOperation, AccountToCheck, type AddCollateralIntent, type AdjustLeverageIntent, AssembleCaOperationsProps, AssembleClaimDelayedCallsProps, AssembleCloseCreditAccountCallsProps, AssembleRepayCreditAccountCallsProps, AssembleStartDelayedWithdrawalCallsProps, BotStatusCall, BotsDirectResponse, BuildLiquidationTxProps, BuildLiquidationTxPropsBase, CMSlice, ClaimFarmRewardsProps, ClaimableWithdrawal, CloseCreditAccountResult, ConnectedBotsCall, ConnectedBotsPerAccount, CreditAccountCompressor, CreditAccountCompressorV310Contract, CreditAccountDataCall, CreditAccountFilter, CreditAccountOperationResult, CreditAccountOperationsService, CreditAccountReadOptions, type CreditAccountSlice, CreditAccountsCall, CreditAccountsQuery, CreditAccountsReadOptions, CreditAccountsServiceV310, CreditAccountsTarget, CreditManagerFilter, CreditManagerOperationResult, CurrentWithdrawals, DELAYED_INTENT_TYPES, DELAYED_INTENT_VERSION, type DelayableIntent, DelayedIntentExtended, type DelayedRoute, type DelayedStart, type DelayedStartResult, type DepositStrategyIntent, EncodableCreditAccountOperation, type FinishIntentProps, FullyLiquidateProps, FullyLiquidateResult, GetApprovalAddressProps, GetConnectedBotsResponse, GetConnectedBotsResult, GetConnectedMigrationBotsResult, GetCreditAccountsArgs, GetCreditAccountsOptions, GetExternalAccountCurrentWithdrawalsProps, GetLiquidatableAccountsProps, GetLiquidationDetailsProps, GetLiquidationDetailsPropsBase, GetLiquidationPositionsProps, GetLiquidationPositionsPropsBase, GetPendingWithdrawalsProps, GetPendingWithdrawalsResult, GetWithdrawalRequestResultProps, ICreditAccountsService, IRedemptionLoggerContract, IWithdrawalCompressorContract, type InstantRoute, IntentPreviewError, type IntentPreviewResult, type IntentRoutesResult, InvalidDelayedIntentError, LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS, type LeverageBand, LiquidationsService, LoadRWALiquidatorsProps, MulticallWithFailure, MultichainLiquidationsService, OnchainLiquidationCall, OnchainLiquidationData, OnchainLiquidationOutput, OnchainRequestableWithdrawal, OpenCAProps, type OpenStrategyPreview, OpenStrategyPreviewResult, type OpenStrategyProps, type OperationState, PartiallyLiquidateProps, type PathLossRate, PendingWithdrawal, PeripheryCompressorV310Contract, PreviewDelayedWithdrawalProps, type PreviewErrorDetails, type PreviewErrorReason, type PreviewRefusal, RWALiquidatorInfo, RedemptionLog, RedemptionLoggerV310Contract, type RepayStrategyIntent, RequestableWithdrawal, type ResumableIntent, Rewards, type RouteRefusals, SetBotProps, SetBotResult, type StartIntent, type WithdrawAssetIntent, type WithdrawStrategyIntent, WithdrawableAsset, WithdrawalCompressorLocation, WithdrawalCompressorV310Contract, WithdrawalCompressorV311Contract, WithdrawalCompressorV313Contract, WithdrawalCompressorVersion, WithdrawalOutput, WithdrawalStatus, WithdrawalsState, createRedemptionLogger, createWithdrawalCompressor, decodeDelayedIntent, encodeDelayedIntent, fetchCreditAccountSlice, getWithdrawalCompressorAddress, iCreditAccountAbi, refuse, toClaimableWithdrawal, toCreditAccountSlice, toPendingWithdrawal, toRequestableWithdrawal, toWithdrawalStatus };
@@ -1,9 +1,9 @@
1
1
  import { SDKConstruct } from "../../base/SDKConstruct.js";
2
2
  import { LeverageBand, LeverageBandProps } from "./leverage-band.js";
3
- import { OpenStrategyPreview, OpenStrategyProps } from "./open-strategy.js";
4
- import { IntentPreviewError, PreviewErrorDetails, PreviewErrorReason, PreviewRefusal, refuse } from "./refusal.js";
5
- import { AddCollateralIntent, AdjustLeverageIntent, CreditAccountSlice, DelayableIntent, DelayedRoute, DelayedStart, DelayedStartResult, DepositStrategyIntent, FinishIntentProps, InstantRoute, IntentPreviewResult, IntentRoutesResult, OperationState, RepayStrategyIntent, ResumableIntent, RouteRefusals, StartIntent, StartIntentProps, WithdrawAssetIntent, WithdrawStrategyIntent } from "./types.js";
6
3
  import { AccountCalculatorOperation } from "./operations.js";
4
+ import { IntentPreviewError, PreviewErrorDetails, PreviewErrorReason, PreviewRefusal, refuse } from "./refusal.js";
5
+ import { AddCollateralIntent, AdjustLeverageIntent, CreditAccountSlice, DelayableIntent, DelayedRoute, DelayedStart, DelayedStartResult, DepositStrategyIntent, FinishIntentProps, InstantRoute, IntentPreviewResult, IntentRoutesResult, OperationState, PathLossRate, RepayStrategyIntent, ResumableIntent, RouteRefusals, StartIntent, StartIntentProps, WithdrawAssetIntent, WithdrawStrategyIntent } from "./types.js";
6
+ import { OpenStrategyPreview, OpenStrategyProps } from "./open-strategy.js";
7
7
  import { fetchCreditAccountSlice, toCreditAccountSlice } from "./utils/credit-account-slice.js";
8
8
  import { Address } from "viem";
9
9
  //#region src/onchain/accounts/intents/index.d.ts
@@ -172,4 +172,4 @@ declare class CreditAccountOperationsService extends SDKConstruct {
172
172
  openStrategyIntent(props: OpenStrategyProps): Promise<OpenStrategyPreviewResult>;
173
173
  }
174
174
  //#endregion
175
- export { type AccountCalculatorOperation, type AddCollateralIntent, type AdjustLeverageIntent, CreditAccountOperationsService, type CreditAccountSlice, type DelayableIntent, type DelayedRoute, type DelayedStart, type DelayedStartResult, type DepositStrategyIntent, type FinishIntentProps, type InstantRoute, IntentPreviewError, type IntentPreviewResult, type IntentRoutesResult, type LeverageBand, type OpenStrategyPreview, OpenStrategyPreviewResult, type OpenStrategyProps, type OperationState, type PreviewErrorDetails, type PreviewErrorReason, type PreviewRefusal, type RepayStrategyIntent, type ResumableIntent, type RouteRefusals, type StartIntent, type WithdrawAssetIntent, type WithdrawStrategyIntent, fetchCreditAccountSlice, refuse, toCreditAccountSlice };
175
+ export { type AccountCalculatorOperation, type AddCollateralIntent, type AdjustLeverageIntent, CreditAccountOperationsService, type CreditAccountSlice, type DelayableIntent, type DelayedRoute, type DelayedStart, type DelayedStartResult, type DepositStrategyIntent, type FinishIntentProps, type InstantRoute, IntentPreviewError, type IntentPreviewResult, type IntentRoutesResult, type LeverageBand, type OpenStrategyPreview, OpenStrategyPreviewResult, type OpenStrategyProps, type OperationState, type PathLossRate, type PreviewErrorDetails, type PreviewErrorReason, type PreviewRefusal, type RepayStrategyIntent, type ResumableIntent, type RouteRefusals, type StartIntent, type WithdrawAssetIntent, type WithdrawStrategyIntent, fetchCreditAccountSlice, refuse, toCreditAccountSlice };
@@ -4,6 +4,7 @@ import "../../../model/index.js";
4
4
  import { Asset } from "../../base/types.js";
5
5
  import { MultiCall } from "../../types/transactions.js";
6
6
  import { OnchainSDK } from "../../OnchainSDK.js";
7
+ import { PathLossRate } from "./types.js";
7
8
  import "../../index.js";
8
9
  import { Address } from "viem";
9
10
  //#region src/onchain/accounts/intents/open-strategy.d.ts
@@ -60,6 +61,8 @@ interface OpenStrategyPreview {
60
61
  collateral: bigint;
61
62
  /** Position size — collateral plus debt, in underlying. */
62
63
  totalValue: bigint;
64
+ /** What the routed leg lost to market depth; `undefined` if not measured. */
65
+ priceImpact: PathLossRate | undefined;
63
66
  /** Expected post-open balances. */
64
67
  averageAssets: TokenAmount[];
65
68
  /** Floor post-open balances after slippage. */
@@ -1,7 +1,7 @@
1
1
  import { MultiCall } from "../../types/transactions.js";
2
2
  import { OnchainSDK } from "../../OnchainSDK.js";
3
- import { CreditAccountSlice, DelayedStart, OperationState } from "./types.js";
4
3
  import { AccountCalculatorOperation } from "./operations.js";
4
+ import { CreditAccountSlice, DelayedStart, OperationState } from "./types.js";
5
5
  import "../../index.js";
6
6
  import { Step } from "./plan.js";
7
7
  import { RouterPaths } from "./utils/router-path.js";
@@ -1,7 +1,7 @@
1
1
  import { ClaimableWithdrawal } from "../withdrawal-compressor/types.js";
2
2
  import { OnchainSDK } from "../../OnchainSDK.js";
3
- import { CreditAccountSlice, DelayedStart, OperationState, ResumableIntent } from "./types.js";
4
3
  import { AccountCalculatorOperation, StartDelayedWithdrawalOperation } from "./operations.js";
4
+ import { CreditAccountSlice, DelayedStart, OperationState, ResumableIntent } from "./types.js";
5
5
  import "../../index.js";
6
6
  import { AccountView, Step } from "./plan.js";
7
7
  //#region src/onchain/accounts/intents/tail.d.ts
@@ -1,8 +1,8 @@
1
1
  import { TokenAmount } from "../../../../model/primitives.js";
2
2
  import "../../../../model/index.js";
3
3
  import { MultiCall } from "../../../types/transactions.js";
4
- import { DelayedStartResult, IntentPreviewResult, OperationState } from "../types.js";
5
4
  import { AccountCalculatorOperation } from "../operations.js";
5
+ import { DelayedStartResult, IntentPreviewResult, OperationState } from "../types.js";
6
6
  import "../../../index.js";
7
7
  import { Address } from "viem";
8
8
  //#region src/onchain/accounts/intents/testing/expect.d.ts
@@ -72,6 +72,8 @@ interface MarketSdkExtras {
72
72
  maxDebtPerBlockMultiplier?: number;
73
73
  /** Tokens the facade forbids. */
74
74
  forbiddenTokens?: Address[];
75
+ /** What a routed swap returns; linear when omitted. */
76
+ routeQuote?: (amount: bigint) => bigint;
75
77
  }
76
78
  /** Mock SDK on the shared fixture market. */
77
79
  declare function buildMarketSdk(extras?: MarketSdkExtras): OnchainSDK;