@gearbox-protocol/sdk 15.1.0-next.8 → 15.1.0-next.9

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 (41) hide show
  1. package/dist/cjs/common-utils/utils/creditAccount/get-time-to-liquidation.js +3 -1
  2. package/dist/cjs/sdk/accounts/intents/intents/resume/add-collateral/add-collateral.fixtures.js +23 -23
  3. package/dist/cjs/sdk/accounts/intents/intents/resume/close/close.fixtures.js +14 -14
  4. package/dist/cjs/sdk/accounts/intents/intents/resume/decrease-leverage/decrease-leverage.fixtures.js +12 -12
  5. package/dist/cjs/sdk/accounts/intents/intents/resume/deposit/deposit.fixtures.js +17 -17
  6. package/dist/cjs/sdk/accounts/intents/intents/resume/increase-leverage/increase-leverage.fixtures.js +12 -12
  7. package/dist/cjs/sdk/accounts/intents/intents/resume/withdraw/withdraw.fixtures.js +9 -9
  8. package/dist/cjs/sdk/accounts/intents/testing/resume.js +3 -18
  9. package/dist/cjs/sdk/accounts/intents/testing/sdk-mock.js +0 -1
  10. package/dist/cjs/sdk/positions/calcTimeToLiquidationMs.js +6 -5
  11. package/dist/esm/common-utils/utils/creditAccount/get-time-to-liquidation.js +3 -1
  12. package/dist/esm/dev/AccountOpener.js +1 -1
  13. package/dist/esm/dev/withdrawalUtils.js +1 -1
  14. package/dist/esm/plugins/adapters/contracts/ERC4626AdapterContract.js +1 -1
  15. package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
  16. package/dist/esm/preview/trace/extractTransfers.js +1 -1
  17. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -2
  18. package/dist/esm/sdk/accounts/intents/testing/resume.js +1 -13
  19. package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -1
  20. package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
  21. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
  22. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
  23. package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
  24. package/dist/esm/sdk/base/TokensMeta.js +3 -3
  25. package/dist/esm/sdk/chain/detectNetwork.js +1 -1
  26. package/dist/esm/sdk/core/createAddressProvider.js +1 -1
  27. package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
  28. package/dist/esm/sdk/market/pool/PoolV310Contract.js +1 -1
  29. package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
  30. package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
  31. package/dist/esm/sdk/pools/PoolService.js +1 -1
  32. package/dist/esm/sdk/positions/calcTimeToLiquidationMs.js +7 -6
  33. package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
  34. package/dist/types/common-utils/utils/creditAccount/get-time-to-liquidation.d.ts +3 -1
  35. package/dist/types/sdk/accounts/intents/testing/expect.d.ts +1 -1
  36. package/dist/types/sdk/accounts/intents/testing/resume.d.ts +1 -1
  37. package/dist/types/sdk/positions/calcTimeToLiquidationMs.d.ts +5 -4
  38. package/package.json +1 -1
  39. package/dist/cjs/sdk/accounts/intents/testing/expect.js +0 -167
  40. package/dist/esm/sdk/accounts/intents/testing/expect.js +0 -162
  41. package/dist/types/sdk/accounts/intents/testing/sdk-mock.d.ts +0 -96
@@ -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,18 +1,6 @@
1
1
  import { toBN } from "../../../utils/formatter.js";
2
2
  import "../../../index.js";
3
3
  import { MOCK_CLAIM_CALL, buildMockSdk } from "./sdk-mock.js";
4
- //#region src/sdk/accounts/intents/testing/resume.ts
5
- /**
6
- * Shared kit for claim-only resume fixtures (add collateral, increase
7
- * leverage, deposit, deposit+increase).
8
- *
9
- * Unlike the legacy props (which echoed `creditAccount.totalValue`), the
10
- * service computes totalValue from CA token balances via the price oracle.
11
- * Each case's base balance is therefore `postClaimTotalValue − claimed value
12
- * in UND`, so the derived totalValue matches the legacy expectation exactly.
13
- */
14
- const UND_DECIMALS = 8;
15
- const TOK_DECIMALS = 18;
16
4
  const UND = "0x3333333333333333333333333333333333333333";
17
5
  const ANY = "0x1111111111111111111111111111111111111111";
18
6
  const ANY2 = "0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
@@ -154,4 +142,4 @@ function buildClaimResumeProps(args) {
154
142
  };
155
143
  }
156
144
  //#endregion
157
- export { ANY, ANY2, CREDIT_ACCOUNT, CREDIT_FACADE, CREDIT_MANAGER, RESUME_FIXTURE_PHANTOM, RWA_ASSET, TOK_DECIMALS, UND, UND_DECIMALS, buildClaimResumeProps, buildOffchainOptions, buildOnchainOptions, buildResumeSdk, claimedValueInUnd };
145
+ export { ANY, ANY2, CREDIT_ACCOUNT, CREDIT_FACADE, CREDIT_MANAGER, RESUME_FIXTURE_PHANTOM, RWA_ASSET, UND, buildClaimResumeProps, buildOffchainOptions, buildOnchainOptions, buildResumeSdk, claimedValueInUnd };
@@ -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,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,
@@ -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 { RAY } from "../constants/math.js";
5
5
  import "../constants/index.js";
@@ -1,17 +1,18 @@
1
- import { PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, SECONDS_PER_YEAR } from "../constants/math.js";
1
+ import { PERCENTAGE_FACTOR, SECONDS_PER_YEAR } from "../constants/math.js";
2
2
  //#region src/sdk/positions/calcTimeToLiquidationMs.ts
3
3
  /**
4
4
  * Estimated milliseconds until `healthFactorBps` decays to `10000` (1.0)
5
- * while the debt grows at `totalBorrowRateOnDebt` (basis points relative to
6
- * the debt, as {@link BorrowRateBreakdown.totalOnDebt} reports it).
5
+ * while the debt grows at `totalBorrowRateOnDebt`, in the same `Bps` scale
6
+ * (`10000` = 100%) as {@link BorrowRateBreakdown.totalOnDebt} reports it —
7
+ * not the legacy `PERCENTAGE_FACTOR_1KK` (`1_000_000` = 100%) scale the
8
+ * pre-rewrite frontend fed into its own `getTimeToLiquidation`.
7
9
  *
8
10
  * `null` when the account is already at or under the liquidation threshold,
9
- * or when the debt carries no borrow rate at all. Formula is in parity with
10
- * the legacy `getTimeToLiquidation`.
11
+ * or when the debt carries no borrow rate at all.
11
12
  **/
12
13
  function calcTimeToLiquidationMs(healthFactorBps, totalBorrowRateOnDebt) {
13
14
  if (BigInt(healthFactorBps) <= 10000n || totalBorrowRateOnDebt === 0n) return null;
14
- return (BigInt(healthFactorBps) - PERCENTAGE_FACTOR) * (BigInt(SECONDS_PER_YEAR) * PERCENTAGE_FACTOR * PERCENTAGE_DECIMALS / totalBorrowRateOnDebt) * 1000n / PERCENTAGE_FACTOR;
15
+ return (BigInt(healthFactorBps) - PERCENTAGE_FACTOR) * (BigInt(SECONDS_PER_YEAR) * PERCENTAGE_FACTOR / totalBorrowRateOnDebt) * 1000n / PERCENTAGE_FACTOR;
15
16
  }
16
17
  //#endregion
17
18
  export { calcTimeToLiquidationMs };
@@ -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";
@@ -10,7 +10,9 @@ interface TimeToLiquidationProps {
10
10
  * and returns a millisecond duration until `healthFactor` decays to `1.0`
11
11
  * (`PERCENTAGE_FACTOR` in internal scale).
12
12
  *
13
- * @param props Current health factor and `totalBorrowRate * debt` term.
13
+ * @param props Current health factor and `totalBorrowRate_debt`, both `Bps`
14
+ * (`10000` = 100%) — not the legacy `PERCENTAGE_FACTOR_1KK` (`1_000_000` =
15
+ * 100%) scale the pre-rewrite frontend fed this under the same name.
14
16
  * @returns Milliseconds to liquidation as `bigint`, or `null` when already at/under
15
17
  * liquidation threshold or when borrow-rate exposure is zero.
16
18
  *
@@ -49,4 +49,4 @@ declare function assetBalance(assets: Array<{
49
49
  balance: bigint;
50
50
  }>, token: Address): bigint;
51
51
  //#endregion
52
- export { ExpectedFlowOp, assetBalance, expectAdjustResumePreview, expectCallsArrayExact, expectOpsArrayExact, withOnchainOpCalls };
52
+ export { ExpectedFlowOp };
@@ -81,4 +81,4 @@ declare function buildClaimResumeProps<T extends DelayedIntent>(args: {
81
81
  slippage: undefined;
82
82
  };
83
83
  //#endregion
84
- export { ANY, ANY2, CREDIT_ACCOUNT, CREDIT_FACADE, CREDIT_MANAGER, RESUME_FIXTURE_PHANTOM, RWA_ASSET, ResumeCase, TOK_DECIMALS, UND, UND_DECIMALS, buildClaimResumeProps, buildOffchainOptions, buildOnchainOptions, buildResumeSdk, claimedValueInUnd };
84
+ export { ANY, CREDIT_ACCOUNT, RWA_ASSET, ResumeCase, UND, buildOffchainOptions, buildOnchainOptions, buildResumeSdk };
@@ -3,12 +3,13 @@ import "../../model/index.js";
3
3
  //#region src/sdk/positions/calcTimeToLiquidationMs.d.ts
4
4
  /**
5
5
  * Estimated milliseconds until `healthFactorBps` decays to `10000` (1.0)
6
- * while the debt grows at `totalBorrowRateOnDebt` (basis points relative to
7
- * the debt, as {@link BorrowRateBreakdown.totalOnDebt} reports it).
6
+ * while the debt grows at `totalBorrowRateOnDebt`, in the same `Bps` scale
7
+ * (`10000` = 100%) as {@link BorrowRateBreakdown.totalOnDebt} reports it —
8
+ * not the legacy `PERCENTAGE_FACTOR_1KK` (`1_000_000` = 100%) scale the
9
+ * pre-rewrite frontend fed into its own `getTimeToLiquidation`.
8
10
  *
9
11
  * `null` when the account is already at or under the liquidation threshold,
10
- * or when the debt carries no borrow rate at all. Formula is in parity with
11
- * the legacy `getTimeToLiquidation`.
12
+ * or when the debt carries no borrow rate at all.
12
13
  **/
13
14
  declare function calcTimeToLiquidationMs(healthFactorBps: Bps, totalBorrowRateOnDebt: bigint): bigint | null;
14
15
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "15.1.0-next.8",
3
+ "version": "15.1.0-next.9",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,167 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_sdk_accounts_intents_testing_sdk_mock = require("./sdk-mock.js");
3
- let vitest = require("vitest");
4
- //#region src/sdk/accounts/intents/testing/expect.ts
5
- function expectedCalls(expected) {
6
- return expected.calls ?? [];
7
- }
8
- /**
9
- * Fills sentinel `calls` for onchain resume expectations. Shared fixtures keep
10
- * `calls: []` for offchain; onchain tests map through this helper.
11
- */
12
- function withOnchainOpCalls(ops) {
13
- return ops.map((op) => {
14
- switch (op.type) {
15
- case "claimDelayedWithdrawal": return {
16
- ...op,
17
- calls: [require_sdk_accounts_intents_testing_sdk_mock.MOCK_CLAIM_CALL]
18
- };
19
- case "changeQuota": return {
20
- ...op,
21
- calls: [require_sdk_accounts_intents_testing_sdk_mock.CA_OP_CALLS.changeQuota]
22
- };
23
- case "decreaseDebt": return {
24
- ...op,
25
- calls: [require_sdk_accounts_intents_testing_sdk_mock.CA_OP_CALLS.decreaseDebt]
26
- };
27
- case "withdrawCollateral": return {
28
- ...op,
29
- calls: [require_sdk_accounts_intents_testing_sdk_mock.CA_OP_CALLS.withdrawCollateral]
30
- };
31
- case "swap": return {
32
- ...op,
33
- calls: op.calls?.length ? op.calls : [require_sdk_accounts_intents_testing_sdk_mock.MOCK_ROUTER_CALL]
34
- };
35
- case "wrapRwaCollateral": return {
36
- ...op,
37
- calls: op.calls?.length ? op.calls : [require_sdk_accounts_intents_testing_sdk_mock.MOCK_RWA_WRAP_CALL]
38
- };
39
- case "unwrapRwaCollateral": return {
40
- ...op,
41
- calls: op.calls?.length ? op.calls : [require_sdk_accounts_intents_testing_sdk_mock.MOCK_RWA_UNWRAP_CALL]
42
- };
43
- case "closeCreditAccount": return {
44
- ...op,
45
- calls: op.calls?.length ? op.calls : [require_sdk_accounts_intents_testing_sdk_mock.MOCK_CLOSE_CALL]
46
- };
47
- default: return op;
48
- }
49
- });
50
- }
51
- function matchOp(actual, expected, index) {
52
- (0, vitest.expect)(actual.type, `op[${index}].type`).toBe(expected.type);
53
- switch (expected.type) {
54
- case "claimDelayedWithdrawal":
55
- if (actual.type !== "claimDelayedWithdrawal") return;
56
- (0, vitest.expect)(actual.token, `op[${index}].token`).toBe(expected.token);
57
- (0, vitest.expect)(actual.withdrawalPhantomToken, `op[${index}].withdrawalPhantomToken`).toBe(expected.withdrawalPhantomToken);
58
- (0, vitest.expect)(actual.withdrawalTokenSpent, `op[${index}].withdrawalTokenSpent`).toBe(expected.withdrawalTokenSpent);
59
- (0, vitest.expect)(actual.outputs, `op[${index}].outputs`).toEqual(expected.outputs);
60
- (0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
61
- break;
62
- case "changeQuota":
63
- if (actual.type !== "changeQuota") return;
64
- (0, vitest.expect)(actual.quotaIncrease, `op[${index}].quotaIncrease`).toEqual(expected.quotaIncrease);
65
- (0, vitest.expect)(actual.quotaDecrease, `op[${index}].quotaDecrease`).toEqual(expected.quotaDecrease);
66
- (0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
67
- break;
68
- case "closeCreditAccount":
69
- if (actual.type !== "closeCreditAccount") return;
70
- (0, vitest.expect)(actual.amount, `op[${index}].amount`).toBe(expected.amount);
71
- (0, vitest.expect)(actual.minAmount, `op[${index}].minAmount`).toBe(expected.minAmount);
72
- (0, vitest.expect)(actual.underlyingBalance, `op[${index}].underlyingBalance`).toBe(expected.underlyingBalance);
73
- (0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
74
- break;
75
- case "swap":
76
- if (actual.type !== "swap") return;
77
- (0, vitest.expect)(actual.from, `op[${index}].from`).toEqual(expected.from);
78
- (0, vitest.expect)(actual.tokenOut, `op[${index}].tokenOut`).toBe(expected.tokenOut);
79
- (0, vitest.expect)(actual.amountOut, `op[${index}].amountOut`).toBe(expected.amountOut);
80
- (0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
81
- break;
82
- case "decreaseDebt":
83
- if (actual.type !== "decreaseDebt") return;
84
- (0, vitest.expect)(actual.amount, `op[${index}].amount`).toBe(expected.amount);
85
- (0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
86
- break;
87
- case "withdrawCollateral":
88
- if (actual.type !== "withdrawCollateral") return;
89
- (0, vitest.expect)(actual.token, `op[${index}].token`).toBe(expected.token);
90
- (0, vitest.expect)(actual.amount, `op[${index}].amount`).toBe(expected.amount);
91
- (0, vitest.expect)(actual.to, `op[${index}].to`).toBe(expected.to);
92
- (0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
93
- break;
94
- case "unwrapRwaCollateral":
95
- if (actual.type !== "unwrapRwaCollateral") return;
96
- (0, vitest.expect)(actual.tokenIn, `op[${index}].tokenIn`).toBe(expected.tokenIn);
97
- (0, vitest.expect)(actual.tokenOut, `op[${index}].tokenOut`).toBe(expected.tokenOut);
98
- (0, vitest.expect)(actual.amount, `op[${index}].amount`).toBe(expected.amount);
99
- (0, vitest.expect)(actual.amountOut, `op[${index}].amountOut`).toBe(expected.amountOut);
100
- (0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
101
- break;
102
- case "wrapRwaCollateral":
103
- if (actual.type !== "wrapRwaCollateral") return;
104
- (0, vitest.expect)(actual.tokenIn, `op[${index}].tokenIn`).toBe(expected.tokenIn);
105
- (0, vitest.expect)(actual.tokenOut, `op[${index}].tokenOut`).toBe(expected.tokenOut);
106
- (0, vitest.expect)(actual.amount, `op[${index}].amount`).toBe(expected.amount);
107
- (0, vitest.expect)(actual.amountOut, `op[${index}].amountOut`).toBe(expected.amountOut);
108
- (0, vitest.expect)(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
109
- }
110
- }
111
- /** Asserts exact operations on a raw op array (type + tokens + amounts). */
112
- function expectOpsArrayExact(ops, expected) {
113
- (0, vitest.expect)(ops.length, "operations.length").toBe(expected.length);
114
- for (let i = 0; i < expected.length; i++) {
115
- const actual = ops[i];
116
- const exp = expected[i];
117
- if (actual === void 0 || exp === void 0) {
118
- vitest.expect.fail(`missing op at index ${i}`);
119
- return;
120
- }
121
- matchOp(actual, exp, i);
122
- }
123
- }
124
- /** Asserts exact calls on a raw MultiCall array (target + callData). */
125
- function expectCallsArrayExact(calls, expected, label = "calls") {
126
- (0, vitest.expect)(calls.length, `${label}.length`).toBe(expected.length);
127
- for (let i = 0; i < expected.length; i++) {
128
- const actual = calls[i];
129
- const exp = expected[i];
130
- if (actual === void 0 || exp === void 0) {
131
- vitest.expect.fail(`missing call at index ${i}`);
132
- return;
133
- }
134
- (0, vitest.expect)(actual.target, `${label}[${i}].target`).toBe(exp.target);
135
- (0, vitest.expect)(actual.callData, `${label}[${i}].callData`).toBe(exp.callData);
136
- }
137
- }
138
- /**
139
- * Asserts a successful adjust-style resume preview: ok, instant branch present,
140
- * exact calls (empty unless `expectedCalls` is provided), metrics from the
141
- * post-claim CA, and exact operations (incl. changeQuota).
142
- * Returns the adjust preview state for further asset/quota assertions.
143
- */
144
- function expectAdjustResumePreview(result, args) {
145
- (0, vitest.expect)(result.ok).toBe(true);
146
- if (!result.ok) throw new Error("expected ok resume preview");
147
- (0, vitest.expect)(result.instant, "instant branch").toBeDefined();
148
- if (!result.instant) throw new Error("expected instant branch");
149
- if (args.expectedCalls) expectCallsArrayExact(result.instant.calls, args.expectedCalls);
150
- else (0, vitest.expect)(result.instant.calls).toEqual([]);
151
- const state = result.instant.preview.min;
152
- (0, vitest.expect)(state.kind).toBe("adjust");
153
- if (state.kind !== "adjust") throw new Error("expected adjust preview state");
154
- (0, vitest.expect)(state.totalValue).toBe(args.totalValue);
155
- (0, vitest.expect)(state.accountDebt).toBe(args.accountDebt);
156
- expectOpsArrayExact(result.instant.operations, args.expectedOps);
157
- return state;
158
- }
159
- function assetBalance(assets, token) {
160
- return assets.find((a) => a.token === token)?.balance ?? 0n;
161
- }
162
- //#endregion
163
- exports.assetBalance = assetBalance;
164
- exports.expectAdjustResumePreview = expectAdjustResumePreview;
165
- exports.expectCallsArrayExact = expectCallsArrayExact;
166
- exports.expectOpsArrayExact = expectOpsArrayExact;
167
- exports.withOnchainOpCalls = withOnchainOpCalls;
@@ -1,162 +0,0 @@
1
- import { CA_OP_CALLS, MOCK_CLAIM_CALL, MOCK_CLOSE_CALL, MOCK_ROUTER_CALL, MOCK_RWA_UNWRAP_CALL, MOCK_RWA_WRAP_CALL } from "./sdk-mock.js";
2
- import { expect } from "vitest";
3
- //#region src/sdk/accounts/intents/testing/expect.ts
4
- function expectedCalls(expected) {
5
- return expected.calls ?? [];
6
- }
7
- /**
8
- * Fills sentinel `calls` for onchain resume expectations. Shared fixtures keep
9
- * `calls: []` for offchain; onchain tests map through this helper.
10
- */
11
- function withOnchainOpCalls(ops) {
12
- return ops.map((op) => {
13
- switch (op.type) {
14
- case "claimDelayedWithdrawal": return {
15
- ...op,
16
- calls: [MOCK_CLAIM_CALL]
17
- };
18
- case "changeQuota": return {
19
- ...op,
20
- calls: [CA_OP_CALLS.changeQuota]
21
- };
22
- case "decreaseDebt": return {
23
- ...op,
24
- calls: [CA_OP_CALLS.decreaseDebt]
25
- };
26
- case "withdrawCollateral": return {
27
- ...op,
28
- calls: [CA_OP_CALLS.withdrawCollateral]
29
- };
30
- case "swap": return {
31
- ...op,
32
- calls: op.calls?.length ? op.calls : [MOCK_ROUTER_CALL]
33
- };
34
- case "wrapRwaCollateral": return {
35
- ...op,
36
- calls: op.calls?.length ? op.calls : [MOCK_RWA_WRAP_CALL]
37
- };
38
- case "unwrapRwaCollateral": return {
39
- ...op,
40
- calls: op.calls?.length ? op.calls : [MOCK_RWA_UNWRAP_CALL]
41
- };
42
- case "closeCreditAccount": return {
43
- ...op,
44
- calls: op.calls?.length ? op.calls : [MOCK_CLOSE_CALL]
45
- };
46
- default: return op;
47
- }
48
- });
49
- }
50
- function matchOp(actual, expected, index) {
51
- expect(actual.type, `op[${index}].type`).toBe(expected.type);
52
- switch (expected.type) {
53
- case "claimDelayedWithdrawal":
54
- if (actual.type !== "claimDelayedWithdrawal") return;
55
- expect(actual.token, `op[${index}].token`).toBe(expected.token);
56
- expect(actual.withdrawalPhantomToken, `op[${index}].withdrawalPhantomToken`).toBe(expected.withdrawalPhantomToken);
57
- expect(actual.withdrawalTokenSpent, `op[${index}].withdrawalTokenSpent`).toBe(expected.withdrawalTokenSpent);
58
- expect(actual.outputs, `op[${index}].outputs`).toEqual(expected.outputs);
59
- expect(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
60
- break;
61
- case "changeQuota":
62
- if (actual.type !== "changeQuota") return;
63
- expect(actual.quotaIncrease, `op[${index}].quotaIncrease`).toEqual(expected.quotaIncrease);
64
- expect(actual.quotaDecrease, `op[${index}].quotaDecrease`).toEqual(expected.quotaDecrease);
65
- expect(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
66
- break;
67
- case "closeCreditAccount":
68
- if (actual.type !== "closeCreditAccount") return;
69
- expect(actual.amount, `op[${index}].amount`).toBe(expected.amount);
70
- expect(actual.minAmount, `op[${index}].minAmount`).toBe(expected.minAmount);
71
- expect(actual.underlyingBalance, `op[${index}].underlyingBalance`).toBe(expected.underlyingBalance);
72
- expect(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
73
- break;
74
- case "swap":
75
- if (actual.type !== "swap") return;
76
- expect(actual.from, `op[${index}].from`).toEqual(expected.from);
77
- expect(actual.tokenOut, `op[${index}].tokenOut`).toBe(expected.tokenOut);
78
- expect(actual.amountOut, `op[${index}].amountOut`).toBe(expected.amountOut);
79
- expect(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
80
- break;
81
- case "decreaseDebt":
82
- if (actual.type !== "decreaseDebt") return;
83
- expect(actual.amount, `op[${index}].amount`).toBe(expected.amount);
84
- expect(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
85
- break;
86
- case "withdrawCollateral":
87
- if (actual.type !== "withdrawCollateral") return;
88
- expect(actual.token, `op[${index}].token`).toBe(expected.token);
89
- expect(actual.amount, `op[${index}].amount`).toBe(expected.amount);
90
- expect(actual.to, `op[${index}].to`).toBe(expected.to);
91
- expect(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
92
- break;
93
- case "unwrapRwaCollateral":
94
- if (actual.type !== "unwrapRwaCollateral") return;
95
- expect(actual.tokenIn, `op[${index}].tokenIn`).toBe(expected.tokenIn);
96
- expect(actual.tokenOut, `op[${index}].tokenOut`).toBe(expected.tokenOut);
97
- expect(actual.amount, `op[${index}].amount`).toBe(expected.amount);
98
- expect(actual.amountOut, `op[${index}].amountOut`).toBe(expected.amountOut);
99
- expect(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
100
- break;
101
- case "wrapRwaCollateral":
102
- if (actual.type !== "wrapRwaCollateral") return;
103
- expect(actual.tokenIn, `op[${index}].tokenIn`).toBe(expected.tokenIn);
104
- expect(actual.tokenOut, `op[${index}].tokenOut`).toBe(expected.tokenOut);
105
- expect(actual.amount, `op[${index}].amount`).toBe(expected.amount);
106
- expect(actual.amountOut, `op[${index}].amountOut`).toBe(expected.amountOut);
107
- expect(actual.calls, `op[${index}].calls`).toEqual(expectedCalls(expected));
108
- }
109
- }
110
- /** Asserts exact operations on a raw op array (type + tokens + amounts). */
111
- function expectOpsArrayExact(ops, expected) {
112
- expect(ops.length, "operations.length").toBe(expected.length);
113
- for (let i = 0; i < expected.length; i++) {
114
- const actual = ops[i];
115
- const exp = expected[i];
116
- if (actual === void 0 || exp === void 0) {
117
- expect.fail(`missing op at index ${i}`);
118
- return;
119
- }
120
- matchOp(actual, exp, i);
121
- }
122
- }
123
- /** Asserts exact calls on a raw MultiCall array (target + callData). */
124
- function expectCallsArrayExact(calls, expected, label = "calls") {
125
- expect(calls.length, `${label}.length`).toBe(expected.length);
126
- for (let i = 0; i < expected.length; i++) {
127
- const actual = calls[i];
128
- const exp = expected[i];
129
- if (actual === void 0 || exp === void 0) {
130
- expect.fail(`missing call at index ${i}`);
131
- return;
132
- }
133
- expect(actual.target, `${label}[${i}].target`).toBe(exp.target);
134
- expect(actual.callData, `${label}[${i}].callData`).toBe(exp.callData);
135
- }
136
- }
137
- /**
138
- * Asserts a successful adjust-style resume preview: ok, instant branch present,
139
- * exact calls (empty unless `expectedCalls` is provided), metrics from the
140
- * post-claim CA, and exact operations (incl. changeQuota).
141
- * Returns the adjust preview state for further asset/quota assertions.
142
- */
143
- function expectAdjustResumePreview(result, args) {
144
- expect(result.ok).toBe(true);
145
- if (!result.ok) throw new Error("expected ok resume preview");
146
- expect(result.instant, "instant branch").toBeDefined();
147
- if (!result.instant) throw new Error("expected instant branch");
148
- if (args.expectedCalls) expectCallsArrayExact(result.instant.calls, args.expectedCalls);
149
- else expect(result.instant.calls).toEqual([]);
150
- const state = result.instant.preview.min;
151
- expect(state.kind).toBe("adjust");
152
- if (state.kind !== "adjust") throw new Error("expected adjust preview state");
153
- expect(state.totalValue).toBe(args.totalValue);
154
- expect(state.accountDebt).toBe(args.accountDebt);
155
- expectOpsArrayExact(result.instant.operations, args.expectedOps);
156
- return state;
157
- }
158
- function assetBalance(assets, token) {
159
- return assets.find((a) => a.token === token)?.balance ?? 0n;
160
- }
161
- //#endregion
162
- export { assetBalance, expectAdjustResumePreview, expectCallsArrayExact, expectOpsArrayExact, withOnchainOpCalls };