@lifi/composer-sdk 0.3.0 → 0.4.0-staging.1

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 (54) hide show
  1. package/README.md +21 -0
  2. package/dist/client.cjs +1 -1
  3. package/dist/client.cjs.map +1 -1
  4. package/dist/client.js +1 -1
  5. package/dist/client.js.map +1 -1
  6. package/dist/errors.cjs +26 -3
  7. package/dist/errors.cjs.map +1 -1
  8. package/dist/errors.d.cts +46 -2
  9. package/dist/errors.d.ts +46 -2
  10. package/dist/errors.js +24 -2
  11. package/dist/errors.js.map +1 -1
  12. package/dist/generated/materialisers.generated.cjs +8 -2
  13. package/dist/generated/materialisers.generated.cjs.map +1 -1
  14. package/dist/generated/materialisers.generated.d.cts +1 -1
  15. package/dist/generated/materialisers.generated.d.ts +1 -1
  16. package/dist/generated/materialisers.generated.js +6 -1
  17. package/dist/generated/materialisers.generated.js.map +1 -1
  18. package/dist/generated/operations.generated.cjs +39 -1
  19. package/dist/generated/operations.generated.cjs.map +1 -1
  20. package/dist/generated/operations.generated.d.cts +111 -2
  21. package/dist/generated/operations.generated.d.ts +111 -2
  22. package/dist/generated/operations.generated.js +39 -1
  23. package/dist/generated/operations.generated.js.map +1 -1
  24. package/dist/index.cjs +2 -0
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +3 -3
  27. package/dist/index.d.ts +3 -3
  28. package/dist/index.js +2 -1
  29. package/dist/index.js.map +1 -1
  30. package/dist/{materialisers.generated-BMkBQgWZ.d.ts → materialisers.generated-BfWJ-g7t.d.ts} +8 -3
  31. package/dist/{materialisers.generated-BWq5oePO.d.cts → materialisers.generated-DaJRwiRe.d.cts} +8 -3
  32. package/dist/responseSchemas.cjs +10 -1
  33. package/dist/responseSchemas.cjs.map +1 -1
  34. package/dist/responseSchemas.d.cts +15 -1
  35. package/dist/responseSchemas.d.ts +15 -1
  36. package/dist/responseSchemas.js +10 -1
  37. package/dist/responseSchemas.js.map +1 -1
  38. package/package.json +3 -4
  39. package/src/errors.ts +67 -1
  40. package/src/examples/staged/aaveBorrow.ts +128 -0
  41. package/src/examples/staged/aaveDebtRebalanceExactOut.ts +301 -0
  42. package/src/examples/staged/aaveHealthFactorExplode.ts +70 -0
  43. package/src/examples/staged/aaveToMorphoDebtMigration.ts +200 -0
  44. package/src/examples/staged/aaveToMorphoDebtMigrationWithSwap.ts +231 -0
  45. package/src/examples/staged/aaveToMorphoDebtMigrationWithSwapExactOut.ts +307 -0
  46. package/src/examples/staged/flashloanRepay.ts +142 -0
  47. package/src/examples/staged/manualRelayContinuation.ts +161 -0
  48. package/src/examples/staged/morphoBlueBorrow.ts +93 -0
  49. package/src/examples/staged/morphoBlueRepay.ts +132 -0
  50. package/src/examples/staged/registry.ts +89 -0
  51. package/src/generated/materialisers.generated.ts +12 -0
  52. package/src/generated/operations.generated.ts +214 -0
  53. package/src/index.ts +7 -2
  54. package/src/responseSchemas.ts +29 -0
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { AbiTypeToOutputKind, Address, InputDecl, InputSchema, InputSpecOf, IntegerString, IntegerStringInput, OutputKind, TypedGuard, TypedRef } from './types.js';
2
2
  export { GetZapPacksOptions, ZapPackEdge, ZapPackOverview } from './discovery.js';
3
- export { ComposeError, ComposeErrorCode, isComposeError } from './errors.js';
4
- export { AppliedGuard, ApprovalEntry, Call, Check, CheckComparator, ComposeCompilePartialData, ComposeCompileRequest, ComposeCompileResult, ComposeCompileSuccessData, ComposeContinuation, ComposeErrorKind, ComposeTransactionRequest, ContinuationIntent, ContinuationOutcome, ContinuationPlanWire, Erc20AllowanceRequirement, Erc20BalanceRequirement, Flow, InputSpec, MaterialiserConfigOf, MaterialiserInput, NativeBalanceRequirement, Phase1ArtifactWire, Precondition, PreconditionConfigOf, PriceImpact, Ref, Resource, SIMULATE_MAX_REQUIREMENTS, SIMULATE_MAX_TRACKED_BALANCES, SimulateBalanceEntry, SimulateOkResult, SimulateRequest, SimulateResult, SimulateRevertDecodeResult, SimulateRevertResult, SimulateSetupErrorResult, SimulationPolicy, SimulationRevert, SlotFinderRequirement, SolType, SweepTo, TrackedBalance } from '@lifi/compose-spec';
3
+ export { ComposeError, ComposeErrorCode, ComposePreparationOps, isComposeError, isComposePreparationError } from './errors.js';
4
+ export { AppliedGuard, ApprovalEntry, Call, Check, CheckComparator, ComposeCompilePartialData, ComposeCompileRequest, ComposeCompileResult, ComposeCompileSuccessData, ComposeContinuation, ComposeErrorKind, ComposeTransactionRequest, ContinuationIntent, ContinuationOutcome, ContinuationPlanWire, Erc20AllowanceRequirement, Erc20BalanceRequirement, FailedPreparedOp, Flow, InputSpec, MaterialiserConfigOf, MaterialiserInput, NativeBalanceRequirement, Phase1ArtifactWire, Precondition, PreconditionConfigOf, PriceImpact, Ref, Resource, SIMULATE_MAX_REQUIREMENTS, SIMULATE_MAX_TRACKED_BALANCES, SimulateBalanceEntry, SimulateOkResult, SimulateRequest, SimulateResult, SimulateRevertDecodeResult, SimulateRevertResult, SimulateSetupErrorResult, SimulationPolicy, SimulationRevert, SlotFinderRequirement, SolType, SweepTo, TrackedBalance } from '@lifi/compose-spec';
5
5
  export { AnyHandle, Bindable, InputHandle, OutputHandle, ResourceInputHandle, isInputHandle, isOutputHandle } from './authoring/handles.js';
6
6
  export { ref } from './authoring/raw.js';
7
7
  export { AnyBindable, FlowOptions, TypedFlow } from './authoring/FlowBuilderCore.js';
@@ -9,7 +9,7 @@ export { ComposeRunInput, materialiser } from './run/inputs.js';
9
9
  export { BuildSimulateRequestInput, buildSimulateRequest } from './run/simulate.js';
10
10
  export { ComposeSdk, ComposeSdkOptions, FlowBuilder, createComposeSdk } from './sdk.js';
11
11
  import { g as guardsMod } from './guards.generated-BPLFwe7y.js';
12
- import { m as materialisersMod } from './materialisers.generated-BMkBQgWZ.js';
12
+ import { m as materialisersMod } from './materialisers.generated-BfWJ-g7t.js';
13
13
  import { p as preconditionsMod } from './preconditions.generated-U7YpVh30.js';
14
14
  import { r as rawMod } from './raw-IxCF_bSS.js';
15
15
  import { r as resourcesMod } from './resources-CYis1_DS.js';
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  SIMULATE_MAX_TRACKED_BALANCES,
3
3
  SIMULATE_MAX_REQUIREMENTS
4
4
  } from "@lifi/compose-spec";
5
- import { isComposeError } from "./errors.js";
5
+ import { isComposeError, isComposePreparationError } from "./errors.js";
6
6
  import { isInputHandle, isOutputHandle } from "./authoring/handles.js";
7
7
  import { ref } from "./authoring/raw.js";
8
8
  import { materialiser } from "./run/inputs.js";
@@ -26,6 +26,7 @@ export {
26
26
  createComposeSdk,
27
27
  guards,
28
28
  isComposeError,
29
+ isComposePreparationError,
29
30
  isInputHandle,
30
31
  isOutputHandle,
31
32
  materialiser,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * `@lifi/composer-sdk` — TypeScript SDK for building and compiling\n * Compose flows into executable EVM calldata.\n *\n * Start by creating an SDK instance with {@link createComposeSdk}, then use\n * {@link ComposeSdk.flow} to build flows and compile them.\n *\n * @packageDocumentation\n */\n\nexport type {\n AbiTypeToOutputKind,\n Address,\n InputDecl,\n InputSchema,\n InputSpecOf,\n IntegerString,\n IntegerStringInput,\n OutputKind,\n TypedGuard,\n TypedRef,\n} from './types.js';\n\nexport type {\n GetZapPacksOptions,\n ZapPackEdge,\n ZapPackOverview,\n} from './discovery.js';\nexport type { ComposeError, ComposeErrorCode } from './errors.js';\nexport type {\n AppliedGuard,\n ApprovalEntry,\n Call,\n ComposeCompilePartialData,\n ComposeCompileRequest,\n ComposeCompileResult,\n ComposeCompileSuccessData,\n ComposeContinuation,\n ComposeErrorKind,\n ComposeTransactionRequest,\n Flow,\n InputSpec,\n MaterialiserConfigOf,\n MaterialiserInput,\n Precondition,\n PreconditionConfigOf,\n PriceImpact,\n Ref,\n Resource,\n SimulationPolicy,\n SimulationRevert,\n SolType,\n SweepTo,\n SimulateRequest,\n SimulateResult,\n SimulateOkResult,\n SimulateRevertResult,\n SimulateRevertDecodeResult,\n SimulateSetupErrorResult,\n SimulateBalanceEntry,\n TrackedBalance,\n SlotFinderRequirement,\n Erc20BalanceRequirement,\n NativeBalanceRequirement,\n Erc20AllowanceRequirement,\n ContinuationIntent,\n ContinuationOutcome,\n Check,\n CheckComparator,\n Phase1ArtifactWire,\n ContinuationPlanWire,\n} from '@lifi/compose-spec';\nexport {\n SIMULATE_MAX_TRACKED_BALANCES,\n SIMULATE_MAX_REQUIREMENTS,\n} from '@lifi/compose-spec';\nexport { isComposeError } from './errors.js';\n\nexport type {\n Bindable,\n InputHandle,\n ResourceInputHandle,\n OutputHandle,\n AnyHandle,\n} from './authoring/handles.js';\nexport { isInputHandle, isOutputHandle } from './authoring/handles.js';\nexport { ref } from './authoring/raw.js';\n\nexport type { AnyBindable } from './authoring/FlowBuilderCore.js';\nexport type { TypedFlow, FlowOptions } from './authoring/FlowBuilderCore.js';\n\nexport type { ComposeRunInput } from './run/inputs.js';\nexport { materialiser } from './run/inputs.js';\n\nexport { buildSimulateRequest } from './run/simulate.js';\nexport type { BuildSimulateRequestInput } from './run/simulate.js';\n\nexport { createComposeSdk } from './sdk.js';\nexport type { ComposeSdk, ComposeSdkOptions, FlowBuilder } from './sdk.js';\n\nimport * as guardsMod from './generated/guards.generated.js';\nimport * as materialisersMod from './generated/materialisers.generated.js';\nimport * as preconditionsMod from './generated/preconditions.generated.js';\nimport * as rawMod from './raw.js';\nimport * as resourcesMod from './resources.js';\n\n/**\n * Guard factories for protecting operation outputs (e.g. slippage tolerance).\n * Pass guards to an operation's `guards` array.\n *\n * @example\n * ```ts\n * builder.lifi.swap('swap1', {\n * bind: { amountIn: builder.inputs.token },\n * config: { resourceOut: resources.native(1) },\n * guards: [guards.slippage({ port: 'amountOut', bps: 300 })],\n * });\n * ```\n */\nexport const guards: typeof guardsMod = guardsMod;\n/**\n * Materialiser factories that tell the runtime how to resolve token input\n * amounts on-chain (e.g. read a wallet balance, accept a direct deposit).\n *\n * @example\n * ```ts\n * await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * signer: '0x...',\n * });\n * ```\n */\nexport const materialisers: typeof materialisersMod = materialisersMod;\n/**\n * Precondition factories for asserting on-chain state before a flow executes\n * (e.g. minimum token balances, ERC-20 allowances).\n *\n * @example\n * ```ts\n * await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * preconditions: [\n * preconditions.erc20Balance({ wallet: '0x...', token: '0x...', balance: 1000n }),\n * ],\n * signer: '0x...',\n * });\n * ```\n */\nexport const preconditions: typeof preconditionsMod = preconditionsMod;\n/**\n * Resource declaration helpers for defining token inputs in a flow schema.\n * Use {@link resources.erc20} for ERC-20 tokens and {@link resources.native}\n * for the chain's native coin (ETH, MATIC, etc.).\n *\n * @example\n * ```ts\n * const builder = sdk.flow(1, {\n * inputs: {\n * usdc: resources.erc20('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 1),\n * eth: resources.native(1),\n * },\n * });\n * ```\n */\nexport const resources: typeof resourcesMod = resourcesMod;\nexport * from './generated/config.generated.js';\n\n/**\n * Low-level escape hatch for constructing flow nodes, guards, and materialiser\n * inputs without the typed builder API. Prefer the generated operation methods\n * on {@link FlowBuilder} and the typed `guards`/`materialisers` namespaces\n * for most use cases.\n */\nexport const raw: typeof rawMod = rawMod;\n"],"mappings":"AAwEA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAS/B,SAAS,eAAe,sBAAsB;AAC9C,SAAS,WAAW;AAMpB,SAAS,oBAAoB;AAE7B,SAAS,4BAA4B;AAGrC,SAAS,wBAAwB;AAGjC,YAAY,eAAe;AAC3B,YAAY,sBAAsB;AAClC,YAAY,sBAAsB;AAClC,YAAY,YAAY;AACxB,YAAY,kBAAkB;AAevB,MAAM,SAA2B;AAajC,MAAM,gBAAyC;AAgB/C,MAAM,gBAAyC;AAgB/C,MAAM,YAAiC;AAC9C,cAAc;AAQP,MAAM,MAAqB;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * `@lifi/composer-sdk` — TypeScript SDK for building and compiling\n * Compose flows into executable EVM calldata.\n *\n * Start by creating an SDK instance with {@link createComposeSdk}, then use\n * {@link ComposeSdk.flow} to build flows and compile them.\n *\n * @packageDocumentation\n */\n\nexport type {\n AbiTypeToOutputKind,\n Address,\n InputDecl,\n InputSchema,\n InputSpecOf,\n IntegerString,\n IntegerStringInput,\n OutputKind,\n TypedGuard,\n TypedRef,\n} from './types.js';\n\nexport type {\n GetZapPacksOptions,\n ZapPackEdge,\n ZapPackOverview,\n} from './discovery.js';\nexport type {\n ComposeError,\n ComposeErrorCode,\n ComposePreparationOps,\n} from './errors.js';\nexport type {\n AppliedGuard,\n ApprovalEntry,\n Call,\n ComposeCompilePartialData,\n ComposeCompileRequest,\n ComposeCompileResult,\n ComposeCompileSuccessData,\n ComposeContinuation,\n ComposeErrorKind,\n ComposeTransactionRequest,\n FailedPreparedOp,\n Flow,\n InputSpec,\n MaterialiserConfigOf,\n MaterialiserInput,\n Precondition,\n PreconditionConfigOf,\n PriceImpact,\n Ref,\n Resource,\n SimulationPolicy,\n SimulationRevert,\n SolType,\n SweepTo,\n SimulateRequest,\n SimulateResult,\n SimulateOkResult,\n SimulateRevertResult,\n SimulateRevertDecodeResult,\n SimulateSetupErrorResult,\n SimulateBalanceEntry,\n TrackedBalance,\n SlotFinderRequirement,\n Erc20BalanceRequirement,\n NativeBalanceRequirement,\n Erc20AllowanceRequirement,\n ContinuationIntent,\n ContinuationOutcome,\n Check,\n CheckComparator,\n Phase1ArtifactWire,\n ContinuationPlanWire,\n} from '@lifi/compose-spec';\nexport {\n SIMULATE_MAX_TRACKED_BALANCES,\n SIMULATE_MAX_REQUIREMENTS,\n} from '@lifi/compose-spec';\nexport { isComposeError, isComposePreparationError } from './errors.js';\n\nexport type {\n Bindable,\n InputHandle,\n ResourceInputHandle,\n OutputHandle,\n AnyHandle,\n} from './authoring/handles.js';\nexport { isInputHandle, isOutputHandle } from './authoring/handles.js';\nexport { ref } from './authoring/raw.js';\n\nexport type { AnyBindable } from './authoring/FlowBuilderCore.js';\nexport type { TypedFlow, FlowOptions } from './authoring/FlowBuilderCore.js';\n\nexport type { ComposeRunInput } from './run/inputs.js';\nexport { materialiser } from './run/inputs.js';\n\nexport { buildSimulateRequest } from './run/simulate.js';\nexport type { BuildSimulateRequestInput } from './run/simulate.js';\n\nexport { createComposeSdk } from './sdk.js';\nexport type { ComposeSdk, ComposeSdkOptions, FlowBuilder } from './sdk.js';\n\nimport * as guardsMod from './generated/guards.generated.js';\nimport * as materialisersMod from './generated/materialisers.generated.js';\nimport * as preconditionsMod from './generated/preconditions.generated.js';\nimport * as rawMod from './raw.js';\nimport * as resourcesMod from './resources.js';\n\n/**\n * Guard factories for protecting operation outputs (e.g. slippage tolerance).\n * Pass guards to an operation's `guards` array.\n *\n * @example\n * ```ts\n * builder.lifi.swap('swap1', {\n * bind: { amountIn: builder.inputs.token },\n * config: { resourceOut: resources.native(1) },\n * guards: [guards.slippage({ port: 'amountOut', bps: 300 })],\n * });\n * ```\n */\nexport const guards: typeof guardsMod = guardsMod;\n/**\n * Materialiser factories that tell the runtime how to resolve token input\n * amounts on-chain (e.g. read a wallet balance, accept a direct deposit).\n *\n * @example\n * ```ts\n * await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * signer: '0x...',\n * });\n * ```\n */\nexport const materialisers: typeof materialisersMod = materialisersMod;\n/**\n * Precondition factories for asserting on-chain state before a flow executes\n * (e.g. minimum token balances, ERC-20 allowances).\n *\n * @example\n * ```ts\n * await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * preconditions: [\n * preconditions.erc20Balance({ wallet: '0x...', token: '0x...', balance: 1000n }),\n * ],\n * signer: '0x...',\n * });\n * ```\n */\nexport const preconditions: typeof preconditionsMod = preconditionsMod;\n/**\n * Resource declaration helpers for defining token inputs in a flow schema.\n * Use {@link resources.erc20} for ERC-20 tokens and {@link resources.native}\n * for the chain's native coin (ETH, MATIC, etc.).\n *\n * @example\n * ```ts\n * const builder = sdk.flow(1, {\n * inputs: {\n * usdc: resources.erc20('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 1),\n * eth: resources.native(1),\n * },\n * });\n * ```\n */\nexport const resources: typeof resourcesMod = resourcesMod;\nexport * from './generated/config.generated.js';\n\n/**\n * Low-level escape hatch for constructing flow nodes, guards, and materialiser\n * inputs without the typed builder API. Prefer the generated operation methods\n * on {@link FlowBuilder} and the typed `guards`/`materialisers` namespaces\n * for most use cases.\n */\nexport const raw: typeof rawMod = rawMod;\n"],"mappings":"AA6EA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB,iCAAiC;AAS1D,SAAS,eAAe,sBAAsB;AAC9C,SAAS,WAAW;AAMpB,SAAS,oBAAoB;AAE7B,SAAS,4BAA4B;AAGrC,SAAS,wBAAwB;AAGjC,YAAY,eAAe;AAC3B,YAAY,sBAAsB;AAClC,YAAY,sBAAsB;AAClC,YAAY,YAAY;AACxB,YAAY,kBAAkB;AAevB,MAAM,SAA2B;AAajC,MAAM,gBAAyC;AAgB/C,MAAM,gBAAyC;AAgB/C,MAAM,YAAiC;AAC9C,cAAc;AAQP,MAAM,MAAqB;","names":[]}
@@ -1,5 +1,5 @@
1
1
  import { MaterialiserConfigOf, MaterialiserInput } from '@lifi/compose-spec';
2
- import { BalanceOfMaterialiserConfig as BalanceOfMaterialiserConfig$1, CallMaterialiserConfig as CallMaterialiserConfig$1, DirectDepositMaterialiserConfig as DirectDepositMaterialiserConfig$1 } from './generated/config.generated.js';
2
+ import { BalanceOfMaterialiserConfig as BalanceOfMaterialiserConfig$1, CallMaterialiserConfig as CallMaterialiserConfig$1, DirectDepositMaterialiserConfig as DirectDepositMaterialiserConfig$1, FlashloanMaterialiserConfig as FlashloanMaterialiserConfig$1 } from './generated/config.generated.js';
3
3
 
4
4
  type BalanceOfMaterialiserConfig = MaterialiserConfigOf<BalanceOfMaterialiserConfig$1>;
5
5
  /** Read the on-chain token balance of an address as the input amount — accepts: resource */
@@ -10,15 +10,20 @@ declare const directDeposit: (config: DirectDepositMaterialiserConfig) => Materi
10
10
  type CallMaterialiserConfig = MaterialiserConfigOf<CallMaterialiserConfig$1>;
11
11
  /** Execute an arbitrary contract call and measure the resulting token balance diff — accepts: resource */
12
12
  declare const call: (config: CallMaterialiserConfig) => MaterialiserInput;
13
+ type FlashloanMaterialiserConfig = MaterialiserConfigOf<FlashloanMaterialiserConfig$1>;
14
+ /** Borrow tokens from a flashloan provider; amount becomes a register populated by the proxy at callback time — accepts: resource */
15
+ declare const flashloan: (config: FlashloanMaterialiserConfig) => MaterialiserInput;
13
16
 
14
17
  type materialisersMod_BalanceOfMaterialiserConfig = BalanceOfMaterialiserConfig;
15
18
  type materialisersMod_CallMaterialiserConfig = CallMaterialiserConfig;
16
19
  type materialisersMod_DirectDepositMaterialiserConfig = DirectDepositMaterialiserConfig;
20
+ type materialisersMod_FlashloanMaterialiserConfig = FlashloanMaterialiserConfig;
17
21
  declare const materialisersMod_balanceOf: typeof balanceOf;
18
22
  declare const materialisersMod_call: typeof call;
19
23
  declare const materialisersMod_directDeposit: typeof directDeposit;
24
+ declare const materialisersMod_flashloan: typeof flashloan;
20
25
  declare namespace materialisersMod {
21
- export { type materialisersMod_BalanceOfMaterialiserConfig as BalanceOfMaterialiserConfig, type materialisersMod_CallMaterialiserConfig as CallMaterialiserConfig, type materialisersMod_DirectDepositMaterialiserConfig as DirectDepositMaterialiserConfig, materialisersMod_balanceOf as balanceOf, materialisersMod_call as call, materialisersMod_directDeposit as directDeposit };
26
+ export { type materialisersMod_BalanceOfMaterialiserConfig as BalanceOfMaterialiserConfig, type materialisersMod_CallMaterialiserConfig as CallMaterialiserConfig, type materialisersMod_DirectDepositMaterialiserConfig as DirectDepositMaterialiserConfig, type materialisersMod_FlashloanMaterialiserConfig as FlashloanMaterialiserConfig, materialisersMod_balanceOf as balanceOf, materialisersMod_call as call, materialisersMod_directDeposit as directDeposit, materialisersMod_flashloan as flashloan };
22
27
  }
23
28
 
24
- export { type BalanceOfMaterialiserConfig as B, type CallMaterialiserConfig as C, type DirectDepositMaterialiserConfig as D, balanceOf as b, call as c, directDeposit as d, materialisersMod as m };
29
+ export { type BalanceOfMaterialiserConfig as B, type CallMaterialiserConfig as C, type DirectDepositMaterialiserConfig as D, type FlashloanMaterialiserConfig as F, balanceOf as b, call as c, directDeposit as d, flashloan as f, materialisersMod as m };
@@ -1,5 +1,5 @@
1
1
  import { MaterialiserConfigOf, MaterialiserInput } from '@lifi/compose-spec';
2
- import { BalanceOfMaterialiserConfig as BalanceOfMaterialiserConfig$1, CallMaterialiserConfig as CallMaterialiserConfig$1, DirectDepositMaterialiserConfig as DirectDepositMaterialiserConfig$1 } from './generated/config.generated.cjs';
2
+ import { BalanceOfMaterialiserConfig as BalanceOfMaterialiserConfig$1, CallMaterialiserConfig as CallMaterialiserConfig$1, DirectDepositMaterialiserConfig as DirectDepositMaterialiserConfig$1, FlashloanMaterialiserConfig as FlashloanMaterialiserConfig$1 } from './generated/config.generated.cjs';
3
3
 
4
4
  type BalanceOfMaterialiserConfig = MaterialiserConfigOf<BalanceOfMaterialiserConfig$1>;
5
5
  /** Read the on-chain token balance of an address as the input amount — accepts: resource */
@@ -10,15 +10,20 @@ declare const directDeposit: (config: DirectDepositMaterialiserConfig) => Materi
10
10
  type CallMaterialiserConfig = MaterialiserConfigOf<CallMaterialiserConfig$1>;
11
11
  /** Execute an arbitrary contract call and measure the resulting token balance diff — accepts: resource */
12
12
  declare const call: (config: CallMaterialiserConfig) => MaterialiserInput;
13
+ type FlashloanMaterialiserConfig = MaterialiserConfigOf<FlashloanMaterialiserConfig$1>;
14
+ /** Borrow tokens from a flashloan provider; amount becomes a register populated by the proxy at callback time — accepts: resource */
15
+ declare const flashloan: (config: FlashloanMaterialiserConfig) => MaterialiserInput;
13
16
 
14
17
  type materialisersMod_BalanceOfMaterialiserConfig = BalanceOfMaterialiserConfig;
15
18
  type materialisersMod_CallMaterialiserConfig = CallMaterialiserConfig;
16
19
  type materialisersMod_DirectDepositMaterialiserConfig = DirectDepositMaterialiserConfig;
20
+ type materialisersMod_FlashloanMaterialiserConfig = FlashloanMaterialiserConfig;
17
21
  declare const materialisersMod_balanceOf: typeof balanceOf;
18
22
  declare const materialisersMod_call: typeof call;
19
23
  declare const materialisersMod_directDeposit: typeof directDeposit;
24
+ declare const materialisersMod_flashloan: typeof flashloan;
20
25
  declare namespace materialisersMod {
21
- export { type materialisersMod_BalanceOfMaterialiserConfig as BalanceOfMaterialiserConfig, type materialisersMod_CallMaterialiserConfig as CallMaterialiserConfig, type materialisersMod_DirectDepositMaterialiserConfig as DirectDepositMaterialiserConfig, materialisersMod_balanceOf as balanceOf, materialisersMod_call as call, materialisersMod_directDeposit as directDeposit };
26
+ export { type materialisersMod_BalanceOfMaterialiserConfig as BalanceOfMaterialiserConfig, type materialisersMod_CallMaterialiserConfig as CallMaterialiserConfig, type materialisersMod_DirectDepositMaterialiserConfig as DirectDepositMaterialiserConfig, type materialisersMod_FlashloanMaterialiserConfig as FlashloanMaterialiserConfig, materialisersMod_balanceOf as balanceOf, materialisersMod_call as call, materialisersMod_directDeposit as directDeposit, materialisersMod_flashloan as flashloan };
22
27
  }
23
28
 
24
- export { type BalanceOfMaterialiserConfig as B, type CallMaterialiserConfig as C, type DirectDepositMaterialiserConfig as D, balanceOf as b, call as c, directDeposit as d, materialisersMod as m };
29
+ export { type BalanceOfMaterialiserConfig as B, type CallMaterialiserConfig as C, type DirectDepositMaterialiserConfig as D, type FlashloanMaterialiserConfig as F, balanceOf as b, call as c, directDeposit as d, flashloan as f, materialisersMod as m };
@@ -89,12 +89,21 @@ const parseCompilePartialEnvelope = (body) => {
89
89
  const parsed = compilePartialEnvelopeSchema.safeParse(body);
90
90
  return parsed.success ? parsed.data : null;
91
91
  };
92
+ const failedPreparedOpSchema = import_zod.default.object({
93
+ callId: import_zod.default.string(),
94
+ op: import_zod.default.string(),
95
+ kind: import_zod.default.string(),
96
+ message: import_zod.default.string(),
97
+ path: import_zod.default.string().optional()
98
+ });
92
99
  const serverErrorBodySchema = import_zod.default.object({
93
100
  error: import_zod.default.object({
94
101
  kind: import_zod.default.string().optional(),
95
102
  message: import_zod.default.string().optional(),
96
103
  path: import_zod.default.string().optional(),
97
- details: import_zod.default.custom().optional()
104
+ details: import_zod.default.custom().optional(),
105
+ failedOps: import_zod.default.array(failedPreparedOpSchema).readonly().optional(),
106
+ succeededOps: import_zod.default.array(import_zod.default.string()).readonly().optional()
98
107
  }).optional()
99
108
  });
100
109
  const parseServerErrorBody = (json) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/responseSchemas.ts"],"sourcesContent":["import type { SimulateResult, SimulationRevert } from '@lifi/compose-spec';\nimport z from 'zod';\n\n/**\n * Zod-backed parsers for Compose API response bodies.\n *\n * Server responses are untrusted input crossing into the SDK, so the shapes the\n * client reads back are validated here rather than asserted with `as` casts. The\n * schemas are module-private (the package builds with `--isolatedDeclarations`,\n * which forbids exporting un-annotated complex values); the public surface is\n * the typed `parse*` helpers, whose explicit return types double as the contract.\n *\n * The simulate union is the one response the SDK fully owns and parses itself\n * (it is un-enveloped, unlike `/compose`), so it gets a complete schema kept in\n * lockstep with the canonical `SimulateResult` in `@lifi/compose-spec` by the\n * compile-time assertion below — the same anchoring `@lifi/api-schemas` uses for\n * its server-side simulate schema, so the two cannot silently drift.\n */\n\nconst balanceEntrySchema = z.object({\n token: z.string(),\n owner: z.string(),\n amount: z.string(),\n});\n\nconst simulateOkSchema = z.object({\n status: z.literal('ok'),\n block: z.number(),\n timestamp: z.number(),\n balancesBefore: z.array(balanceEntrySchema),\n balancesAfter: z.array(balanceEntrySchema),\n deltas: z.array(balanceEntrySchema),\n gasUsed: z.string(),\n});\n\nconst simulateRevertDecodeResultSchema = z.object({\n errorCandidates: z\n .array(\n z.object({\n decodedErrorSignature: z.string(),\n decodedParams: z.array(z.string()),\n }),\n )\n .optional(),\n error: z.string().optional(),\n});\n\nconst simulateRevertSchema = z.object({\n status: z.literal('revert'),\n block: z.number(),\n timestamp: z.number(),\n revertReason: z.string().optional(),\n code: z.number().optional(),\n rawErrorBytes: z.string().optional(),\n decodeResult: simulateRevertDecodeResultSchema.optional(),\n});\n\nconst simulateSetupErrorSchema = z.object({\n status: z.literal('error'),\n message: z.string(),\n});\n\nconst simulateResultSchema = z.discriminatedUnion('status', [\n simulateOkSchema,\n simulateRevertSchema,\n simulateSetupErrorSchema,\n]);\n\n// The type the schema actually parses out. Kept private (referencing it from an\n// exported declaration would break `--isolatedDeclarations`) and pinned to the\n// canonical `SimulateResult` inside `parseSimulateResult` below.\ntype SimulateResultWire = z.infer<typeof simulateResultSchema>;\n\n/**\n * Parses a `POST /simulate` body into a {@link SimulateResult}. Returns `null`\n * when the body does not match the `ok`/`revert`/`error` union, letting the\n * caller raise a transport-level error.\n */\nexport const parseSimulateResult = (body: unknown): SimulateResult | null => {\n const parsed = simulateResultSchema.safeParse(body);\n if (!parsed.success) return null;\n // Pin the schema to the canonical contract in both directions, so it cannot\n // silently drift (mirroring the conformance assertion `@lifi/api-schemas` runs\n // on its server-side simulate schema). Assigning the inferred wire value to a\n // `SimulateResult` checks wire→spec; `satisfies SimulateResultWire` checks\n // spec→wire. A missing or mistyped field on either side fails to compile.\n const result: SimulateResult = parsed.data;\n return result satisfies SimulateResultWire;\n};\n\n/**\n * The validated members of an HTTP 206 partial compile envelope. `data` is\n * verified to be an object but kept untyped — compose-spec owns its full shape\n * (`ComposeCompilePartialData`) as a hand-authored type, so the caller narrows\n * it. `error` is fully validated.\n */\nexport interface CompilePartialEnvelope {\n readonly data: Record<string, unknown>;\n readonly error: { readonly kind: string; readonly message: string };\n}\n\nconst compilePartialEnvelopeSchema = z.object({\n data: z.record(z.string(), z.unknown()),\n error: z.object({ kind: z.string(), message: z.string() }),\n});\n\n/** Parses an HTTP 206 partial compile envelope; `null` when it does not match. */\nexport const parseCompilePartialEnvelope = (\n body: unknown,\n): CompilePartialEnvelope | null => {\n const parsed = compilePartialEnvelopeSchema.safeParse(body);\n return parsed.success ? parsed.data : null;\n};\n\n/** Error envelope returned on non-2xx responses. */\nexport interface ServerErrorBody {\n readonly error?: {\n readonly kind?: string;\n readonly message?: string;\n readonly path?: string;\n readonly details?: SimulationRevert;\n };\n}\n\n// `details` is passed through (`z.custom`) rather than parsed: the SDK does not\n// own the `SimulationRevert` schema and forwards the field verbatim onto\n// `ComposeError`.\nconst serverErrorBodySchema = z.object({\n error: z\n .object({\n kind: z.string().optional(),\n message: z.string().optional(),\n path: z.string().optional(),\n details: z.custom<SimulationRevert>().optional(),\n })\n .optional(),\n});\n\n/** Validates an already-parsed error envelope; `null` when it does not match. */\nexport const parseServerErrorBody = (json: unknown): ServerErrorBody | null => {\n const parsed = serverErrorBodySchema.safeParse(json);\n return parsed.success ? parsed.data : null;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAAc;AAkBd,MAAM,qBAAqB,WAAAA,QAAE,OAAO;AAAA,EAClC,OAAO,WAAAA,QAAE,OAAO;AAAA,EAChB,OAAO,WAAAA,QAAE,OAAO;AAAA,EAChB,QAAQ,WAAAA,QAAE,OAAO;AACnB,CAAC;AAED,MAAM,mBAAmB,WAAAA,QAAE,OAAO;AAAA,EAChC,QAAQ,WAAAA,QAAE,QAAQ,IAAI;AAAA,EACtB,OAAO,WAAAA,QAAE,OAAO;AAAA,EAChB,WAAW,WAAAA,QAAE,OAAO;AAAA,EACpB,gBAAgB,WAAAA,QAAE,MAAM,kBAAkB;AAAA,EAC1C,eAAe,WAAAA,QAAE,MAAM,kBAAkB;AAAA,EACzC,QAAQ,WAAAA,QAAE,MAAM,kBAAkB;AAAA,EAClC,SAAS,WAAAA,QAAE,OAAO;AACpB,CAAC;AAED,MAAM,mCAAmC,WAAAA,QAAE,OA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O,EAAE,CAAC;AAC3D,CAAC;AAGM,MAAM,8BAA8B,CACzC,SACkC;AAClC,QAAM,SAAS,6BAA6B,UAAU,IAAI;AAC1D,SAAO,OAAO,UAAU,OAAO,OAAO;AACxC;AAeA,MAAM,wBAAwB,WAAAA,QAAE,OAAO;AAAA,EACrC,OAAO,WAAAA,QACJ,OAAO;AAAA,IACN,MAAM,WAAAA,QAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,SAAS,WAAAA,QAAE,OAAO,EAAE,SAAS;AAAA,IAC7B,MAAM,WAAAA,QAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,SAAS,WAAAA,QAAE,OAAyB,EAAE,SAAS;AAAA,EACjD,CAAC,EACA,SAAS;AACd,CAAC;AAGM,MAAM,uBAAuB,CAAC,SAA0C;AAC7E,QAAM,SAAS,sBAAsB,UAAU,IAAI;AACnD,SAAO,OAAO,UAAU,OAAO,OAAO;AACxC;","names":["z"]}
1
+ {"version":3,"sources":["../src/responseSchemas.ts"],"sourcesContent":["import type { SimulateResult, SimulationRevert } from '@lifi/compose-spec';\nimport z from 'zod';\n\n/**\n * Zod-backed parsers for Compose API response bodies.\n *\n * Server responses are untrusted input crossing into the SDK, so the shapes the\n * client reads back are validated here rather than asserted with `as` casts. The\n * schemas are module-private (the package builds with `--isolatedDeclarations`,\n * which forbids exporting un-annotated complex values); the public surface is\n * the typed `parse*` helpers, whose explicit return types double as the contract.\n *\n * The simulate union is the one response the SDK fully owns and parses itself\n * (it is un-enveloped, unlike `/compose`), so it gets a complete schema kept in\n * lockstep with the canonical `SimulateResult` in `@lifi/compose-spec` by the\n * compile-time assertion below — the same anchoring `@lifi/api-schemas` uses for\n * its server-side simulate schema, so the two cannot silently drift.\n */\n\nconst balanceEntrySchema = z.object({\n token: z.string(),\n owner: z.string(),\n amount: z.string(),\n});\n\nconst simulateOkSchema = z.object({\n status: z.literal('ok'),\n block: z.number(),\n timestamp: z.number(),\n balancesBefore: z.array(balanceEntrySchema),\n balancesAfter: z.array(balanceEntrySchema),\n deltas: z.array(balanceEntrySchema),\n gasUsed: z.string(),\n});\n\nconst simulateRevertDecodeResultSchema = z.object({\n errorCandidates: z\n .array(\n z.object({\n decodedErrorSignature: z.string(),\n decodedParams: z.array(z.string()),\n }),\n )\n .optional(),\n error: z.string().optional(),\n});\n\nconst simulateRevertSchema = z.object({\n status: z.literal('revert'),\n block: z.number(),\n timestamp: z.number(),\n revertReason: z.string().optional(),\n code: z.number().optional(),\n rawErrorBytes: z.string().optional(),\n decodeResult: simulateRevertDecodeResultSchema.optional(),\n});\n\nconst simulateSetupErrorSchema = z.object({\n status: z.literal('error'),\n message: z.string(),\n});\n\nconst simulateResultSchema = z.discriminatedUnion('status', [\n simulateOkSchema,\n simulateRevertSchema,\n simulateSetupErrorSchema,\n]);\n\n// The type the schema actually parses out. Kept private (referencing it from an\n// exported declaration would break `--isolatedDeclarations`) and pinned to the\n// canonical `SimulateResult` inside `parseSimulateResult` below.\ntype SimulateResultWire = z.infer<typeof simulateResultSchema>;\n\n/**\n * Parses a `POST /simulate` body into a {@link SimulateResult}. Returns `null`\n * when the body does not match the `ok`/`revert`/`error` union, letting the\n * caller raise a transport-level error.\n */\nexport const parseSimulateResult = (body: unknown): SimulateResult | null => {\n const parsed = simulateResultSchema.safeParse(body);\n if (!parsed.success) return null;\n // Pin the schema to the canonical contract in both directions, so it cannot\n // silently drift (mirroring the conformance assertion `@lifi/api-schemas` runs\n // on its server-side simulate schema). Assigning the inferred wire value to a\n // `SimulateResult` checks wire→spec; `satisfies SimulateResultWire` checks\n // spec→wire. A missing or mistyped field on either side fails to compile.\n const result: SimulateResult = parsed.data;\n return result satisfies SimulateResultWire;\n};\n\n/**\n * The validated members of an HTTP 206 partial compile envelope. `data` is\n * verified to be an object but kept untyped — compose-spec owns its full shape\n * (`ComposeCompilePartialData`) as a hand-authored type, so the caller narrows\n * it. `error` is fully validated.\n */\nexport interface CompilePartialEnvelope {\n readonly data: Record<string, unknown>;\n readonly error: { readonly kind: string; readonly message: string };\n}\n\nconst compilePartialEnvelopeSchema = z.object({\n data: z.record(z.string(), z.unknown()),\n error: z.object({ kind: z.string(), message: z.string() }),\n});\n\n/** Parses an HTTP 206 partial compile envelope; `null` when it does not match. */\nexport const parseCompilePartialEnvelope = (\n body: unknown,\n): CompilePartialEnvelope | null => {\n const parsed = compilePartialEnvelopeSchema.safeParse(body);\n return parsed.success ? parsed.data : null;\n};\n\n/**\n * A single prepared-op failure inside a `preparation_error` envelope. `kind` is\n * kept as `string` here — the narrowing to `GenericComposeErrorKind` happens in\n * `errorFromHttpResponse`, where the value is lifted onto `ComposeError`.\n */\nexport interface ServerFailedPreparedOp {\n readonly callId: string;\n readonly op: string;\n readonly kind: string;\n readonly message: string;\n readonly path?: string;\n}\n\n/** Error envelope returned on non-2xx responses. */\nexport interface ServerErrorBody {\n readonly error?: {\n readonly kind?: string;\n readonly message?: string;\n readonly path?: string;\n readonly details?: SimulationRevert;\n readonly failedOps?: readonly ServerFailedPreparedOp[];\n readonly succeededOps?: readonly string[];\n };\n}\n\nconst failedPreparedOpSchema = z.object({\n callId: z.string(),\n op: z.string(),\n kind: z.string(),\n message: z.string(),\n path: z.string().optional(),\n});\n\n// `details` is passed through (`z.custom`) rather than parsed: the SDK does not\n// own the `SimulationRevert` schema and forwards the field verbatim onto\n// `ComposeError`.\n//\n// `failedOps`/`succeededOps` are optional here because every error kind shares\n// this envelope; they are only populated for `preparation_error` (422). Zod\n// strips undeclared keys, so omitting them would silently drop them.\nconst serverErrorBodySchema = z.object({\n error: z\n .object({\n kind: z.string().optional(),\n message: z.string().optional(),\n path: z.string().optional(),\n details: z.custom<SimulationRevert>().optional(),\n failedOps: z.array(failedPreparedOpSchema).readonly().optional(),\n succeededOps: z.array(z.string()).readonly().optional(),\n })\n .optional(),\n});\n\n/** Validates an already-parsed error envelope; `null` when it does not match. */\nexport const parseServerErrorBody = (json: unknown): ServerErrorBody | null => {\n const parsed = serverErrorBodySchema.safeParse(json);\n return parsed.success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;AAAA,IAC7B,MAAM,WAAAA,QAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,SAAS,WAAAA,QAAE,OAAyB,EAAE,SAAS;AAAA,IAC/C,WAAW,WAAAA,QAAE,MAAM,sBAAsB,EAAE,SAAS,EAAE,SAAS;AAAA,IAC/D,cAAc,WAAAA,QAAE,MAAM,WAAAA,QAAE,OAAO,CAAC,EAAE,SAAS,EAAE,SAAS;AAAA,EACxD,CAAC,EACA,SAAS;AACd,CAAC;AAGM,MAAM,uBAAuB,CAAC,SAA0C;AAC7E,QAAM,SAAS,sBAAsB,UAAU,IAAI;AACnD,SAAO,OAAO,UAAU,OAAO,OAAO;AACxC;","names":["z"]}
@@ -21,6 +21,18 @@ interface CompilePartialEnvelope {
21
21
  }
22
22
  /** Parses an HTTP 206 partial compile envelope; `null` when it does not match. */
23
23
  declare const parseCompilePartialEnvelope: (body: unknown) => CompilePartialEnvelope | null;
24
+ /**
25
+ * A single prepared-op failure inside a `preparation_error` envelope. `kind` is
26
+ * kept as `string` here — the narrowing to `GenericComposeErrorKind` happens in
27
+ * `errorFromHttpResponse`, where the value is lifted onto `ComposeError`.
28
+ */
29
+ interface ServerFailedPreparedOp {
30
+ readonly callId: string;
31
+ readonly op: string;
32
+ readonly kind: string;
33
+ readonly message: string;
34
+ readonly path?: string;
35
+ }
24
36
  /** Error envelope returned on non-2xx responses. */
25
37
  interface ServerErrorBody {
26
38
  readonly error?: {
@@ -28,9 +40,11 @@ interface ServerErrorBody {
28
40
  readonly message?: string;
29
41
  readonly path?: string;
30
42
  readonly details?: SimulationRevert;
43
+ readonly failedOps?: readonly ServerFailedPreparedOp[];
44
+ readonly succeededOps?: readonly string[];
31
45
  };
32
46
  }
33
47
  /** Validates an already-parsed error envelope; `null` when it does not match. */
34
48
  declare const parseServerErrorBody: (json: unknown) => ServerErrorBody | null;
35
49
 
36
- export { type CompilePartialEnvelope, type ServerErrorBody, parseCompilePartialEnvelope, parseServerErrorBody, parseSimulateResult };
50
+ export { type CompilePartialEnvelope, type ServerErrorBody, type ServerFailedPreparedOp, parseCompilePartialEnvelope, parseServerErrorBody, parseSimulateResult };
@@ -21,6 +21,18 @@ interface CompilePartialEnvelope {
21
21
  }
22
22
  /** Parses an HTTP 206 partial compile envelope; `null` when it does not match. */
23
23
  declare const parseCompilePartialEnvelope: (body: unknown) => CompilePartialEnvelope | null;
24
+ /**
25
+ * A single prepared-op failure inside a `preparation_error` envelope. `kind` is
26
+ * kept as `string` here — the narrowing to `GenericComposeErrorKind` happens in
27
+ * `errorFromHttpResponse`, where the value is lifted onto `ComposeError`.
28
+ */
29
+ interface ServerFailedPreparedOp {
30
+ readonly callId: string;
31
+ readonly op: string;
32
+ readonly kind: string;
33
+ readonly message: string;
34
+ readonly path?: string;
35
+ }
24
36
  /** Error envelope returned on non-2xx responses. */
25
37
  interface ServerErrorBody {
26
38
  readonly error?: {
@@ -28,9 +40,11 @@ interface ServerErrorBody {
28
40
  readonly message?: string;
29
41
  readonly path?: string;
30
42
  readonly details?: SimulationRevert;
43
+ readonly failedOps?: readonly ServerFailedPreparedOp[];
44
+ readonly succeededOps?: readonly string[];
31
45
  };
32
46
  }
33
47
  /** Validates an already-parsed error envelope; `null` when it does not match. */
34
48
  declare const parseServerErrorBody: (json: unknown) => ServerErrorBody | null;
35
49
 
36
- export { type CompilePartialEnvelope, type ServerErrorBody, parseCompilePartialEnvelope, parseServerErrorBody, parseSimulateResult };
50
+ export { type CompilePartialEnvelope, type ServerErrorBody, type ServerFailedPreparedOp, parseCompilePartialEnvelope, parseServerErrorBody, parseSimulateResult };
@@ -54,12 +54,21 @@ const parseCompilePartialEnvelope = (body) => {
54
54
  const parsed = compilePartialEnvelopeSchema.safeParse(body);
55
55
  return parsed.success ? parsed.data : null;
56
56
  };
57
+ const failedPreparedOpSchema = z.object({
58
+ callId: z.string(),
59
+ op: z.string(),
60
+ kind: z.string(),
61
+ message: z.string(),
62
+ path: z.string().optional()
63
+ });
57
64
  const serverErrorBodySchema = z.object({
58
65
  error: z.object({
59
66
  kind: z.string().optional(),
60
67
  message: z.string().optional(),
61
68
  path: z.string().optional(),
62
- details: z.custom().optional()
69
+ details: z.custom().optional(),
70
+ failedOps: z.array(failedPreparedOpSchema).readonly().optional(),
71
+ succeededOps: z.array(z.string()).readonly().optional()
63
72
  }).optional()
64
73
  });
65
74
  const parseServerErrorBody = (json) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/responseSchemas.ts"],"sourcesContent":["import type { SimulateResult, SimulationRevert } from '@lifi/compose-spec';\nimport z from 'zod';\n\n/**\n * Zod-backed parsers for Compose API response bodies.\n *\n * Server responses are untrusted input crossing into the SDK, so the shapes the\n * client reads back are validated here rather than asserted with `as` casts. The\n * schemas are module-private (the package builds with `--isolatedDeclarations`,\n * which forbids exporting un-annotated complex values); the public surface is\n * the typed `parse*` helpers, whose explicit return types double as the contract.\n *\n * The simulate union is the one response the SDK fully owns and parses itself\n * (it is un-enveloped, unlike `/compose`), so it gets a complete schema kept in\n * lockstep with the canonical `SimulateResult` in `@lifi/compose-spec` by the\n * compile-time assertion below — the same anchoring `@lifi/api-schemas` uses for\n * its server-side simulate schema, so the two cannot silently drift.\n */\n\nconst balanceEntrySchema = z.object({\n token: z.string(),\n owner: z.string(),\n amount: z.string(),\n});\n\nconst simulateOkSchema = z.object({\n status: z.literal('ok'),\n block: z.number(),\n timestamp: z.number(),\n balancesBefore: z.array(balanceEntrySchema),\n balancesAfter: z.array(balanceEntrySchema),\n deltas: z.array(balanceEntrySchema),\n gasUsed: z.string(),\n});\n\nconst simulateRevertDecodeResultSchema = z.object({\n errorCandidates: z\n .array(\n z.object({\n decodedErrorSignature: z.string(),\n decodedParams: z.array(z.string()),\n }),\n )\n .optional(),\n error: z.string().optional(),\n});\n\nconst simulateRevertSchema = z.object({\n status: z.literal('revert'),\n block: z.number(),\n timestamp: z.number(),\n revertReason: z.string().optional(),\n code: z.number().optional(),\n rawErrorBytes: z.string().optional(),\n decodeResult: simulateRevertDecodeResultSchema.optional(),\n});\n\nconst simulateSetupErrorSchema = z.object({\n status: z.literal('error'),\n message: z.string(),\n});\n\nconst simulateResultSchema = z.discriminatedUnion('status', [\n simulateOkSchema,\n simulateRevertSchema,\n simulateSetupErrorSchema,\n]);\n\n// The type the schema actually parses out. Kept private (referencing it from an\n// exported declaration would break `--isolatedDeclarations`) and pinned to the\n// canonical `SimulateResult` inside `parseSimulateResult` below.\ntype SimulateResultWire = z.infer<typeof simulateResultSchema>;\n\n/**\n * Parses a `POST /simulate` body into a {@link SimulateResult}. Returns `null`\n * when the body does not match the `ok`/`revert`/`error` union, letting the\n * caller raise a transport-level error.\n */\nexport const parseSimulateResult = (body: unknown): SimulateResult | null => {\n const parsed = simulateResultSchema.safeParse(body);\n if (!parsed.success) return null;\n // Pin the schema to the canonical contract in both directions, so it cannot\n // silently drift (mirroring the conformance assertion `@lifi/api-schemas` runs\n // on its server-side simulate schema). Assigning the inferred wire value to a\n // `SimulateResult` checks wire→spec; `satisfies SimulateResultWire` checks\n // spec→wire. A missing or mistyped field on either side fails to compile.\n const result: SimulateResult = parsed.data;\n return result satisfies SimulateResultWire;\n};\n\n/**\n * The validated members of an HTTP 206 partial compile envelope. `data` is\n * verified to be an object but kept untyped — compose-spec owns its full shape\n * (`ComposeCompilePartialData`) as a hand-authored type, so the caller narrows\n * it. `error` is fully validated.\n */\nexport interface CompilePartialEnvelope {\n readonly data: Record<string, unknown>;\n readonly error: { readonly kind: string; readonly message: string };\n}\n\nconst compilePartialEnvelopeSchema = z.object({\n data: z.record(z.string(), z.unknown()),\n error: z.object({ kind: z.string(), message: z.string() }),\n});\n\n/** Parses an HTTP 206 partial compile envelope; `null` when it does not match. */\nexport const parseCompilePartialEnvelope = (\n body: unknown,\n): CompilePartialEnvelope | null => {\n const parsed = compilePartialEnvelopeSchema.safeParse(body);\n return parsed.success ? parsed.data : null;\n};\n\n/** Error envelope returned on non-2xx responses. */\nexport interface ServerErrorBody {\n readonly error?: {\n readonly kind?: string;\n readonly message?: string;\n readonly path?: string;\n readonly details?: SimulationRevert;\n };\n}\n\n// `details` is passed through (`z.custom`) rather than parsed: the SDK does not\n// own the `SimulationRevert` schema and forwards the field verbatim onto\n// `ComposeError`.\nconst serverErrorBodySchema = z.object({\n error: z\n .object({\n kind: z.string().optional(),\n message: z.string().optional(),\n path: z.string().optional(),\n details: z.custom<SimulationRevert>().optional(),\n })\n .optional(),\n});\n\n/** Validates an already-parsed error envelope; `null` when it does not match. */\nexport const parseServerErrorBody = (json: unknown): ServerErrorBody | null => {\n const parsed = serverErrorBodySchema.safeParse(json);\n return parsed.success ? parsed.data : null;\n};\n"],"mappings":"AACA,OAAO,OAAO;AAkBd,MAAM,qBAAqB,EAAE,OAAO;AAAA,EAClC,OAAO,EAAE,OAAO;AAAA,EAChB,OAAO,EAAE,OAAO;AAAA,EAChB,QAAQ,EAAE,OAAO;AACnB,CAAC;AAED,MAAM,mBAAmB,EAAE,OAAO;AAAA,EAChC,QAAQ,EAAE,QAAQ,IAAI;AAAA,EACtB,OAAO,EAAE,OAAO;AAAA,EAChB,WAAW,EAAE,OAAO;AAAA,EACpB,gBAAgB,EAAE,MAAM,kBAAkB;AAAA,EAC1C,eAAe,EAAE,MAAM,kBAAkB;AAAA,EACzC,QAAQ,EAAE,MAAM,kBAAkB;AAAA,EAClC,SAAS,EAAE,OAAO;AACpB,CAAC;AAED,MAAM,mCAAmC,EAAE,OAAO;AAAA,EAChD,iBAAiB,EACd;AAAA,IACC,EAAE,OAAO;AAAA,MACP,uBAAuB,EAAE,OAAO;AAAA,MAChC,eAAe,EAAE,MAAM,EAAE,OAAO,CAAC;AAAA,IACnC,CAAC;AAAA,EACH,EACC,SAAS;AAAA,EACZ,OAAO,EAAE,OAAO,EAAE,SAAS;AAC7B,CAAC;AAED,MAAM,uBAAuB,EAAE,OAAO;AAAA,EACpC,QAAQ,EAAE,QAAQ,QAAQ;AAAA,EAC1B,OAAO,EAAE,OAAO;AAAA,EAChB,WAAW,EAAE,OAAO;AAA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[]}
1
+ {"version":3,"sources":["../src/responseSchemas.ts"],"sourcesContent":["import type { SimulateResult, SimulationRevert } from '@lifi/compose-spec';\nimport z from 'zod';\n\n/**\n * Zod-backed parsers for Compose API response bodies.\n *\n * Server responses are untrusted input crossing into the SDK, so the shapes the\n * client reads back are validated here rather than asserted with `as` casts. The\n * schemas are module-private (the package builds with `--isolatedDeclarations`,\n * which forbids exporting un-annotated complex values); the public surface is\n * the typed `parse*` helpers, whose explicit return types double as the contract.\n *\n * The simulate union is the one response the SDK fully owns and parses itself\n * (it is un-enveloped, unlike `/compose`), so it gets a complete schema kept in\n * lockstep with the canonical `SimulateResult` in `@lifi/compose-spec` by the\n * compile-time assertion below — the same anchoring `@lifi/api-schemas` uses for\n * its server-side simulate schema, so the two cannot silently drift.\n */\n\nconst balanceEntrySchema = z.object({\n token: z.string(),\n owner: z.string(),\n amount: z.string(),\n});\n\nconst simulateOkSchema = z.object({\n status: z.literal('ok'),\n block: z.number(),\n timestamp: z.number(),\n balancesBefore: z.array(balanceEntrySchema),\n balancesAfter: z.array(balanceEntrySchema),\n deltas: z.array(balanceEntrySchema),\n gasUsed: z.string(),\n});\n\nconst simulateRevertDecodeResultSchema = z.object({\n errorCandidates: z\n .array(\n z.object({\n decodedErrorSignature: z.string(),\n decodedParams: z.array(z.string()),\n }),\n )\n .optional(),\n error: z.string().optional(),\n});\n\nconst simulateRevertSchema = z.object({\n status: z.literal('revert'),\n block: z.number(),\n timestamp: z.number(),\n revertReason: z.string().optional(),\n code: z.number().optional(),\n rawErrorBytes: z.string().optional(),\n decodeResult: simulateRevertDecodeResultSchema.optional(),\n});\n\nconst simulateSetupErrorSchema = z.object({\n status: z.literal('error'),\n message: z.string(),\n});\n\nconst simulateResultSchema = z.discriminatedUnion('status', [\n simulateOkSchema,\n simulateRevertSchema,\n simulateSetupErrorSchema,\n]);\n\n// The type the schema actually parses out. Kept private (referencing it from an\n// exported declaration would break `--isolatedDeclarations`) and pinned to the\n// canonical `SimulateResult` inside `parseSimulateResult` below.\ntype SimulateResultWire = z.infer<typeof simulateResultSchema>;\n\n/**\n * Parses a `POST /simulate` body into a {@link SimulateResult}. Returns `null`\n * when the body does not match the `ok`/`revert`/`error` union, letting the\n * caller raise a transport-level error.\n */\nexport const parseSimulateResult = (body: unknown): SimulateResult | null => {\n const parsed = simulateResultSchema.safeParse(body);\n if (!parsed.success) return null;\n // Pin the schema to the canonical contract in both directions, so it cannot\n // silently drift (mirroring the conformance assertion `@lifi/api-schemas` runs\n // on its server-side simulate schema). Assigning the inferred wire value to a\n // `SimulateResult` checks wire→spec; `satisfies SimulateResultWire` checks\n // spec→wire. A missing or mistyped field on either side fails to compile.\n const result: SimulateResult = parsed.data;\n return result satisfies SimulateResultWire;\n};\n\n/**\n * The validated members of an HTTP 206 partial compile envelope. `data` is\n * verified to be an object but kept untyped — compose-spec owns its full shape\n * (`ComposeCompilePartialData`) as a hand-authored type, so the caller narrows\n * it. `error` is fully validated.\n */\nexport interface CompilePartialEnvelope {\n readonly data: Record<string, unknown>;\n readonly error: { readonly kind: string; readonly message: string };\n}\n\nconst compilePartialEnvelopeSchema = z.object({\n data: z.record(z.string(), z.unknown()),\n error: z.object({ kind: z.string(), message: z.string() }),\n});\n\n/** Parses an HTTP 206 partial compile envelope; `null` when it does not match. */\nexport const parseCompilePartialEnvelope = (\n body: unknown,\n): CompilePartialEnvelope | null => {\n const parsed = compilePartialEnvelopeSchema.safeParse(body);\n return parsed.success ? parsed.data : null;\n};\n\n/**\n * A single prepared-op failure inside a `preparation_error` envelope. `kind` is\n * kept as `string` here — the narrowing to `GenericComposeErrorKind` happens in\n * `errorFromHttpResponse`, where the value is lifted onto `ComposeError`.\n */\nexport interface ServerFailedPreparedOp {\n readonly callId: string;\n readonly op: string;\n readonly kind: string;\n readonly message: string;\n readonly path?: string;\n}\n\n/** Error envelope returned on non-2xx responses. */\nexport interface ServerErrorBody {\n readonly error?: {\n readonly kind?: string;\n readonly message?: string;\n readonly path?: string;\n readonly details?: SimulationRevert;\n readonly failedOps?: readonly ServerFailedPreparedOp[];\n readonly succeededOps?: readonly string[];\n };\n}\n\nconst failedPreparedOpSchema = z.object({\n callId: z.string(),\n op: z.string(),\n kind: z.string(),\n message: z.string(),\n path: z.string().optional(),\n});\n\n// `details` is passed through (`z.custom`) rather than parsed: the SDK does not\n// own the `SimulationRevert` schema and forwards the field verbatim onto\n// `ComposeError`.\n//\n// `failedOps`/`succeededOps` are optional here because every error kind shares\n// this envelope; they are only populated for `preparation_error` (422). Zod\n// strips undeclared keys, so omitting them would silently drop them.\nconst serverErrorBodySchema = z.object({\n error: z\n .object({\n kind: z.string().optional(),\n message: z.string().optional(),\n path: z.string().optional(),\n details: z.custom<SimulationRevert>().optional(),\n failedOps: z.array(failedPreparedOpSchema).readonly().optional(),\n succeededOps: z.array(z.string()).readonly().optional(),\n })\n .optional(),\n});\n\n/** Validates an already-parsed error envelope; `null` when it does not match. */\nexport const parseServerErrorBody = (json: unknown): ServerErrorBody | null => {\n const parsed = serverErrorBodySchema.safeParse(json);\n return parsed.success ? parsed.data : null;\n};\n"],"mappings":"AACA,OAAO,OAAO;AAkBd,MAAM,qBAAqB,EAAE,OAAO;AAAA,EAClC,OAAO,EAAE,OAAO;AAAA,EAChB,OAAO,EAAE,OAAO;AAAA,EAChB,QAAQ,EAAE,OAAO;AACnB,CAAC;AAED,MAAM,mBAAmB,EAAE,OAAO;AAAA,EAChC,QAAQ,EAAE,QAAQ,IAAI;AAAA,EACtB,OAAO,EAAE,OAAO;AAAA,EAChB,WAAW,EAAE,OAAO;AAAA,EACpB,gBAAgB,EAAE,MAAM,kBAAkB;AAAA,EAC1C,eAAe,EAAE,MAAM,kBAAkB;AAAA,EACzC,QAAQ,EAAE,MAAM,kBAAkB;AAAA,EAClC,SAAS,EAAE,OAAO;AACpB,CAAC;AAED,MAAM,mCAAmC,EAAE,OAAO;AAAA,EAChD,iBAAiB,EACd;AAAA,IACC,EAAE,OAAO;AAAA,MACP,uBAAuB,EAAE,OA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,EAAE,OAAO;AAAA,EACf,SAAS,EAAE,OAAO;AAAA,EAClB,MAAM,EAAE,OAAO,EAAE,SAAS;AAC5B,CAAC;AASD,MAAM,wBAAwB,EAAE,OAAO;AAAA,EACrC,OAAO,EACJ,OAAO;AAAA,IACN,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,IAC7B,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,SAAS,EAAE,OAAyB,EAAE,SAAS;AAAA,IAC/C,WAAW,EAAE,MAAM,sBAAsB,EAAE,SAAS,EAAE,SAAS;AAAA,IAC/D,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS,EAAE,SAAS;AAAA,EACxD,CAAC,EACA,SAAS;AACd,CAAC;AAGM,MAAM,uBAAuB,CAAC,SAA0C;AAC7E,QAAM,SAAS,sBAAsB,UAAU,IAAI;AACnD,SAAO,OAAO,UAAU,OAAO,OAAO;AACxC;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/composer-sdk",
3
- "version": "0.3.0",
3
+ "version": "0.4.0-staging.1",
4
4
  "description": "Public Composer SDK for building and submitting flows",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -51,7 +51,7 @@
51
51
  "example:staged": "tsx src/examples/run.ts --staged"
52
52
  },
53
53
  "peerDependencies": {
54
- "@lifi/compose-spec": "0.3.0"
54
+ "@lifi/compose-spec": "0.4.0-staging.1"
55
55
  },
56
56
  "dependencies": {
57
57
  "abitype": "^1.2.3",
@@ -85,7 +85,6 @@
85
85
  "!src/**/*.test.ts",
86
86
  "!src/**/*.mock.ts",
87
87
  "!src/**/*.typecheck.ts",
88
- "!dist/**/*.typecheck.*",
89
- "!src/examples/staged/**"
88
+ "!dist/**/*.typecheck.*"
90
89
  ]
91
90
  }
package/src/errors.ts CHANGED
@@ -1,4 +1,9 @@
1
- import type { ComposeErrorKind, SimulationRevert } from '@lifi/compose-spec';
1
+ import type {
2
+ ComposeErrorKind,
3
+ FailedPreparedOp,
4
+ GenericComposeErrorKind,
5
+ SimulationRevert,
6
+ } from '@lifi/compose-spec';
2
7
 
3
8
  import {
4
9
  parseServerErrorBody,
@@ -62,6 +67,17 @@ export class ComposeError extends Error {
62
67
  * backend can parse the revert reason.
63
68
  */
64
69
  readonly details?: SimulationRevert;
70
+ /**
71
+ * The prepared ops that failed, attached to `preparation_error` errors.
72
+ * Each entry carries the `callId` of the failing node so callers can drop
73
+ * the unroutable legs and resubmit a smaller flow.
74
+ */
75
+ readonly failedOps?: readonly FailedPreparedOp[];
76
+ /**
77
+ * The `callId`s of the prepared ops that succeeded, attached to
78
+ * `preparation_error` errors alongside {@link ComposeError.failedOps}.
79
+ */
80
+ readonly succeededOps?: readonly string[];
65
81
 
66
82
  constructor(
67
83
  code: ComposeErrorCode,
@@ -73,6 +89,8 @@ export class ComposeError extends Error {
73
89
  kind?: ComposeErrorKind;
74
90
  path?: string;
75
91
  details?: SimulationRevert;
92
+ failedOps?: readonly FailedPreparedOp[];
93
+ succeededOps?: readonly string[];
76
94
  },
77
95
  ) {
78
96
  super(message, { cause: options?.cause });
@@ -82,9 +100,21 @@ export class ComposeError extends Error {
82
100
  this.kind = options?.kind;
83
101
  this.path = options?.path;
84
102
  this.details = options?.details;
103
+ this.failedOps = options?.failedOps;
104
+ this.succeededOps = options?.succeededOps;
85
105
  }
86
106
  }
87
107
 
108
+ /**
109
+ * The per-op preparation diagnostics carried by `preparation_error` responses,
110
+ * with both arrays known to be present. Produced by narrowing with
111
+ * {@link isComposePreparationError}.
112
+ */
113
+ export interface ComposePreparationOps {
114
+ readonly failedOps: readonly FailedPreparedOp[];
115
+ readonly succeededOps: readonly string[];
116
+ }
117
+
88
118
  /**
89
119
  * Type guard that narrows an unknown error to {@link ComposeError}.
90
120
  * @param e - The value to check.
@@ -94,6 +124,35 @@ export const isComposeError = (e: unknown): e is ComposeError =>
94
124
  e instanceof ComposeError ||
95
125
  (e instanceof Error && e.name === 'ComposeError' && 'code' in e);
96
126
 
127
+ /**
128
+ * Type guard for `preparation_error` failures (HTTP 422): a mixed basket where
129
+ * some prepared ops failed and others succeeded. Narrows both
130
+ * {@link ComposeError.failedOps} and {@link ComposeError.succeededOps} to
131
+ * present, so callers can read them without a cast or a truthiness check.
132
+ *
133
+ * @param e - The value to check.
134
+ * @returns `true` if `e` is a `ComposeError` carrying per-op preparation diagnostics.
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * try {
139
+ * await builder.compile(run);
140
+ * } catch (e) {
141
+ * if (isComposePreparationError(e)) {
142
+ * console.error('Failed ops:', e.failedOps);
143
+ * console.error('Succeeded ops:', e.succeededOps);
144
+ * }
145
+ * }
146
+ * ```
147
+ */
148
+ export const isComposePreparationError = (
149
+ e: unknown,
150
+ ): e is ComposeError & ComposePreparationOps =>
151
+ isComposeError(e) &&
152
+ e.kind === 'preparation_error' &&
153
+ Array.isArray(e.failedOps) &&
154
+ Array.isArray(e.succeededOps);
155
+
97
156
  const STATUS_TO_CODE: ReadonlyMap<number, ComposeErrorCode> = new Map<
98
157
  number,
99
158
  ComposeErrorCode
@@ -143,6 +202,13 @@ export const errorFromHttpResponse = (
143
202
  kind: serverError?.kind as ComposeErrorKind | undefined,
144
203
  path: serverError?.path,
145
204
  details: serverError?.details,
205
+ // The wire schema types `kind` as a bare string; the server only ever
206
+ // reports generic kinds for individual ops.
207
+ failedOps: serverError?.failedOps?.map((op) => ({
208
+ ...op,
209
+ kind: op.kind as GenericComposeErrorKind,
210
+ })),
211
+ succeededOps: serverError?.succeededOps,
146
212
  },
147
213
  );
148
214
  };
@@ -0,0 +1,128 @@
1
+ import type { ComposeCompileRequest, Flow } from '@lifi/compose-spec';
2
+
3
+ import {
4
+ createComposeSdk,
5
+ guards,
6
+ materialisers,
7
+ resources,
8
+ } from '../../index.js';
9
+ import type { Address } from '../../types.js';
10
+ import { API_KEY, BASE_URL } from '../config.js';
11
+
12
+ // Aave v3 contracts on Ethereum mainnet.
13
+ const AAVE_V3_POOL = '0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2';
14
+ const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
15
+ // Aave v3 aEthUSDC receipt token and variable-debt USDC token.
16
+ const A_ETH_USDC = '0x98C23E9d8f34FEFb1B7BD6a91B7FF122F4e16F5c';
17
+ const VDEBT_USDC = '0x72E95b8931767C79bA4EeE721354d6E99a61D004';
18
+
19
+ // 1.05 WAD (1e18) — minimum acceptable Aave health factor after the borrow.
20
+ // The on-chain VM reverts the run if the post-borrow HF drops below this.
21
+ const MIN_HEALTH_FACTOR_WAD = '1050000000000000000';
22
+
23
+ export interface AaveBorrowInput {
24
+ readonly owner: Address;
25
+ readonly recipient: Address;
26
+ /** USDC supplied as collateral so the proxy can borrow (6 dp). */
27
+ readonly collateralAmount: `${bigint}`;
28
+ /** USDC borrowed against the collateral and sent to the recipient (6 dp). */
29
+ readonly borrowAmount: `${bigint}`;
30
+ }
31
+
32
+ /**
33
+ * Supply USDC to Aave v3, borrow USDC against it, and transfer the borrowed
34
+ * funds to a recipient — with an on-chain health-factor guard that reverts
35
+ * if the post-borrow position is too thin.
36
+ *
37
+ * The in-flow supply makes the example self-contained: the borrow is backed
38
+ * by collateral created in the same transaction, so it simulates cleanly
39
+ * for a fresh proxy. Keep `borrowAmount` comfortably below the collateral's
40
+ * borrowing power or the health-factor guard reverts the run.
41
+ *
42
+ * Demonstrates:
43
+ * - `lifi.zap` to supply USDC into Aave (USDC → aEthUSDC routing edge)
44
+ * - `aave.borrow` with no resource input — the borrowed asset materialises
45
+ * as the `borrowed` resource output.
46
+ * - Chaining the borrow output into a `core.transfer` to forward funds.
47
+ * - `aave.getHealthFactor` + `core.numericInvariant` guard asserts that
48
+ * `healthFactor >= MIN_HEALTH_FACTOR_WAD` after the borrow; the run reverts
49
+ * on-chain if the threshold is violated.
50
+ *
51
+ * The supplied aEthUSDC stays on the proxy: it backs the open debt, and
52
+ * Aave rejects aToken transfers that would break the position's health
53
+ * factor, so it cannot be swept while the borrow is outstanding.
54
+ */
55
+ export const buildAaveBorrow = ({
56
+ owner,
57
+ recipient,
58
+ collateralAmount,
59
+ borrowAmount,
60
+ }: AaveBorrowInput): {
61
+ flow: Flow;
62
+ request: ComposeCompileRequest;
63
+ } => {
64
+ const sdk = createComposeSdk({ baseUrl: BASE_URL, apiKey: API_KEY });
65
+
66
+ const builder = sdk.flow(1, {
67
+ name: 'aave-borrow-usdc',
68
+ inputs: {
69
+ collateralIn: resources.erc20(USDC, 1),
70
+ recipient: 'address',
71
+ },
72
+ });
73
+
74
+ // Supply USDC as collateral (USDC → aEthUSDC) so the proxy can borrow.
75
+ builder.lifi.zap('supply', {
76
+ bind: { amountIn: builder.inputs.collateralIn },
77
+ config: { resourceOut: resources.erc20(A_ETH_USDC, 1) },
78
+ });
79
+
80
+ const borrowOut = builder.aave.borrow('borrow', {
81
+ bind: {},
82
+ config: {
83
+ pool: AAVE_V3_POOL,
84
+ asset: USDC,
85
+ variableDebtToken: VDEBT_USDC,
86
+ amount: borrowAmount,
87
+ },
88
+ });
89
+
90
+ // Read the post-borrow Aave health factor and assert it stays above the
91
+ // minimum threshold. The numericInvariant guard lowers to an on-chain
92
+ // `AssertRawInvariant` IR1 instruction; the run reverts if HF < threshold.
93
+ builder.aave.getHealthFactor('hf', {
94
+ bind: {},
95
+ config: { pool: AAVE_V3_POOL },
96
+ guards: [
97
+ guards.coreNumericInvariant({
98
+ port: 'healthFactor',
99
+ op: 'gte',
100
+ threshold: MIN_HEALTH_FACTOR_WAD,
101
+ }),
102
+ ],
103
+ });
104
+
105
+ // Forward the freshly borrowed USDC to the recipient.
106
+ builder.core.transfer('send-borrowed', {
107
+ bind: {
108
+ amount: borrowOut.borrowed,
109
+ recipient: builder.inputs.recipient,
110
+ },
111
+ config: {},
112
+ });
113
+
114
+ const flow = builder.build();
115
+
116
+ // No sweepTo: the aEthUSDC collateral must stay on the proxy while the
117
+ // debt is open — Aave blocks aToken transfers that would leave the
118
+ // position undercollateralized.
119
+ const request = sdk.request(flow, {
120
+ signer: owner,
121
+ inputs: {
122
+ collateralIn: materialisers.directDeposit({ amount: collateralAmount }),
123
+ recipient,
124
+ },
125
+ });
126
+
127
+ return { flow, request };
128
+ };