@lifi/composer-sdk 0.4.1 → 0.5.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 (108) hide show
  1. package/README.md +6 -3
  2. package/dist/authoring/FlowBuilderCore.cjs +1 -5
  3. package/dist/authoring/FlowBuilderCore.cjs.map +1 -1
  4. package/dist/authoring/FlowBuilderCore.d.cts +9 -7
  5. package/dist/authoring/FlowBuilderCore.d.ts +9 -7
  6. package/dist/authoring/FlowBuilderCore.js +2 -6
  7. package/dist/authoring/FlowBuilderCore.js.map +1 -1
  8. package/dist/authoring/handles.cjs +5 -2
  9. package/dist/authoring/handles.cjs.map +1 -1
  10. package/dist/authoring/handles.d.cts +25 -6
  11. package/dist/authoring/handles.d.ts +25 -6
  12. package/dist/authoring/handles.js +3 -1
  13. package/dist/authoring/handles.js.map +1 -1
  14. package/dist/authoring/raw.cjs +3 -0
  15. package/dist/authoring/raw.cjs.map +1 -1
  16. package/dist/authoring/raw.d.cts +33 -3
  17. package/dist/authoring/raw.d.ts +33 -3
  18. package/dist/authoring/raw.js +2 -0
  19. package/dist/authoring/raw.js.map +1 -1
  20. package/dist/authoring/signatureArgs.cjs.map +1 -1
  21. package/dist/authoring/signatureArgs.d.cts +16 -12
  22. package/dist/authoring/signatureArgs.d.ts +16 -12
  23. package/dist/authoring/signatureArgs.js.map +1 -1
  24. package/dist/client.cjs +112 -55
  25. package/dist/client.cjs.map +1 -1
  26. package/dist/client.d.cts +42 -5
  27. package/dist/client.d.ts +42 -5
  28. package/dist/client.js +116 -55
  29. package/dist/client.js.map +1 -1
  30. package/dist/discovery.cjs.map +1 -1
  31. package/dist/discovery.d.cts +18 -2
  32. package/dist/discovery.d.ts +18 -2
  33. package/dist/errors.cjs +42 -3
  34. package/dist/errors.cjs.map +1 -1
  35. package/dist/errors.d.cts +67 -4
  36. package/dist/errors.d.ts +67 -4
  37. package/dist/errors.js +29 -2
  38. package/dist/errors.js.map +1 -1
  39. package/dist/generated/config.generated.cjs.map +1 -1
  40. package/dist/generated/config.generated.d.cts +21 -1
  41. package/dist/generated/config.generated.d.ts +21 -1
  42. package/dist/generated/operations.generated.cjs +6 -0
  43. package/dist/generated/operations.generated.cjs.map +1 -1
  44. package/dist/generated/operations.generated.d.cts +18 -2
  45. package/dist/generated/operations.generated.d.ts +18 -2
  46. package/dist/generated/operations.generated.js +6 -0
  47. package/dist/generated/operations.generated.js.map +1 -1
  48. package/dist/index.cjs +4 -0
  49. package/dist/index.cjs.map +1 -1
  50. package/dist/index.d.cts +7 -7
  51. package/dist/index.d.ts +7 -7
  52. package/dist/index.js +8 -1
  53. package/dist/index.js.map +1 -1
  54. package/dist/{raw-IxCF_bSS.d.ts → raw-BvRghN3r.d.ts} +3 -2
  55. package/dist/{raw-Dj_2rBSQ.d.cts → raw-s1rer8X3.d.cts} +3 -2
  56. package/dist/raw.cjs +2 -0
  57. package/dist/raw.cjs.map +1 -1
  58. package/dist/raw.d.cts +1 -1
  59. package/dist/raw.d.ts +1 -1
  60. package/dist/raw.js +2 -1
  61. package/dist/raw.js.map +1 -1
  62. package/dist/responseSchemas.cjs +3 -0
  63. package/dist/responseSchemas.cjs.map +1 -1
  64. package/dist/responseSchemas.d.cts +3 -0
  65. package/dist/responseSchemas.d.ts +3 -0
  66. package/dist/responseSchemas.js +3 -0
  67. package/dist/responseSchemas.js.map +1 -1
  68. package/dist/run/inputs.cjs +14 -15
  69. package/dist/run/inputs.cjs.map +1 -1
  70. package/dist/run/inputs.d.cts +8 -0
  71. package/dist/run/inputs.d.ts +8 -0
  72. package/dist/run/inputs.js +14 -15
  73. package/dist/run/inputs.js.map +1 -1
  74. package/dist/run/simulate.cjs +5 -0
  75. package/dist/run/simulate.cjs.map +1 -1
  76. package/dist/run/simulate.d.cts +5 -2
  77. package/dist/run/simulate.d.ts +5 -2
  78. package/dist/run/simulate.js +5 -0
  79. package/dist/run/simulate.js.map +1 -1
  80. package/dist/sdk.cjs +2 -0
  81. package/dist/sdk.cjs.map +1 -1
  82. package/dist/sdk.d.cts +28 -1
  83. package/dist/sdk.d.ts +28 -1
  84. package/dist/sdk.js +2 -0
  85. package/dist/sdk.js.map +1 -1
  86. package/dist/types.cjs.map +1 -1
  87. package/dist/types.d.cts +18 -2
  88. package/dist/types.d.ts +18 -2
  89. package/package.json +3 -10
  90. package/src/authoring/FlowBuilderCore.ts +13 -15
  91. package/src/authoring/handles.ts +41 -5
  92. package/src/authoring/raw.ts +36 -2
  93. package/src/authoring/signatureArgs.ts +17 -13
  94. package/src/client.ts +222 -62
  95. package/src/discovery.ts +18 -1
  96. package/src/errors.ts +116 -3
  97. package/src/examples/flySwap.ts +167 -0
  98. package/src/examples/run.ts +35 -13
  99. package/src/examples/supportedChains.ts +122 -0
  100. package/src/generated/config.generated.ts +24 -0
  101. package/src/generated/operations.generated.ts +26 -0
  102. package/src/index.ts +18 -2
  103. package/src/raw.ts +1 -1
  104. package/src/responseSchemas.ts +6 -0
  105. package/src/run/inputs.ts +30 -11
  106. package/src/run/simulate.ts +14 -2
  107. package/src/sdk.ts +30 -0
  108. package/src/types.ts +20 -1
@@ -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/**\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":"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","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 sdkVersion?: string;\n readonly serverVersion?: string;\n readonly minimumSdkVersion?: 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 sdkVersion: z.string().optional(),\n serverVersion: z.string().optional(),\n minimumSdkVersion: 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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,OAAO;AAAA,EAChD,iBAAiB,WAAAA,QACd;AAAA,IACC,WAAAA,QAAE,OAAO;AAAA,MACP,uBAAuB,WAAAA,QAAE,OAAO;AAAA,MAChC,eAAe,WAAAA,QAAE,MAAM,WAAAA,QAAE,OAAO,CAAC;AAAA,IACnC,CAAC;AAAA,EACH,EACC,SAAS;AAAA,EACZ,OAAO,WAAAA,QAAE,OAAO,EAAE,SAAS;AAC7B,CAAC;AAED,MAAM,uBAAuB,WAAAA,QAAE,OAAO;AAAA,EACpC,QAAQ,WAAAA,QAAE,QAAQ,QAAQ;AAAA,EAC1B,OAAO,WAAAA,QAAE,OAAO;AAAA,EAChB,WAAW,WAAAA,QAAE,OAAO;AAAA,EACpB,cAAc,WAAAA,QAAE,OAAO,EAAE,SAAS;AAAA,EAClC,MAAM,WAAAA,QAAE,OAAO,EAAE,SAAS;AAAA,EAC1B,eAAe,WAAAA,QAAE,OAAO,EAAE,SAAS;AAAA,EACnC,cAAc,iCAAiC,SAAS;AAC1D,CAAC;AAED,MAAM,2BAA2B,WAAAA,QAAE,OAAO;AAAA,EACxC,QAAQ,WAAAA,QAAE,QAAQ,OAAO;AAAA,EACzB,SAAS,WAAAA,QAAE,OAAO;AACpB,CAAC;AAED,MAAM,uBAAuB,WAAAA,QAAE,mBAAmB,UAAU;AAAA,EAC1D;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAYM,MAAM,sBAAsB,CAAC,SAAyC;AAC3E,QAAM,SAAS,qBAAqB,UAAU,IAAI;AAClD,MAAI,CAAC,OAAO,QAAS,QAAO;AAM5B,QAAM,SAAyB,OAAO;AACtC,SAAO;AACT;AAaA,MAAM,+BAA+B,WAAAA,QAAE,OAAO;AAAA,EAC5C,MAAM,WAAAA,QAAE,OAAO,WAAAA,QAAE,OAAO,GAAG,WAAAA,QAAE,QAAQ,CAAC;AAAA,EACtC,OAAO,WAAAA,QAAE,OAAO,EAAE,MAAM,WAAAA,QAAE,OAAO,GAAG,SAAS,WAAAA,QAAE,OAAO,EAAE,CAAC;AAC3D,CAAC;AAGM,MAAM,8BAA8B,CACzC,SACkC;AAClC,QAAM,SAAS,6BAA6B,UAAU,IAAI;AAC1D,SAAO,OAAO,UAAU,OAAO,OAAO;AACxC;AA8BA,MAAM,yBAAyB,WAAAA,QAAE,OAAO;AAAA,EACtC,QAAQ,WAAAA,QAAE,OAAO;AAAA,EACjB,IAAI,WAAAA,QAAE,OAAO;AAAA,EACb,MAAM,WAAAA,QAAE,OAAO;AAAA,EACf,SAAS,WAAAA,QAAE,OAAO;AAAA,EAClB,MAAM,WAAAA,QAAE,OAAO,EAAE,SAAS;AAC5B,CAAC;AASD,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,YAAY,WAAAA,QAAE,OAAO,EAAE,SAAS;AAAA,IAChC,eAAe,WAAAA,QAAE,OAAO,EAAE,SAAS;AAAA,IACnC,mBAAmB,WAAAA,QAAE,OAAO,EAAE,SAAS;AAAA,IACvC,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"]}
@@ -39,6 +39,9 @@ interface ServerErrorBody {
39
39
  readonly kind?: string;
40
40
  readonly message?: string;
41
41
  readonly path?: string;
42
+ readonly sdkVersion?: string;
43
+ readonly serverVersion?: string;
44
+ readonly minimumSdkVersion?: string;
42
45
  readonly details?: SimulationRevert;
43
46
  readonly failedOps?: readonly ServerFailedPreparedOp[];
44
47
  readonly succeededOps?: readonly string[];
@@ -39,6 +39,9 @@ interface ServerErrorBody {
39
39
  readonly kind?: string;
40
40
  readonly message?: string;
41
41
  readonly path?: string;
42
+ readonly sdkVersion?: string;
43
+ readonly serverVersion?: string;
44
+ readonly minimumSdkVersion?: string;
42
45
  readonly details?: SimulationRevert;
43
46
  readonly failedOps?: readonly ServerFailedPreparedOp[];
44
47
  readonly succeededOps?: readonly string[];
@@ -66,6 +66,9 @@ const serverErrorBodySchema = z.object({
66
66
  kind: z.string().optional(),
67
67
  message: z.string().optional(),
68
68
  path: z.string().optional(),
69
+ sdkVersion: z.string().optional(),
70
+ serverVersion: z.string().optional(),
71
+ minimumSdkVersion: z.string().optional(),
69
72
  details: z.custom().optional(),
70
73
  failedOps: z.array(failedPreparedOpSchema).readonly().optional(),
71
74
  succeededOps: z.array(z.string()).readonly().optional()
@@ -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/**\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":"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","names":[]}
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 sdkVersion?: string;\n readonly serverVersion?: string;\n readonly minimumSdkVersion?: 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 sdkVersion: z.string().optional(),\n serverVersion: z.string().optional(),\n minimumSdkVersion: 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":"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","names":[]}
@@ -26,25 +26,24 @@ const materialiser = (kind, config = {}) => ({
26
26
  kind,
27
27
  ...config
28
28
  });
29
+ const pickDefined = (obj) => Object.fromEntries(
30
+ Object.entries(obj).filter(([, value]) => value !== void 0)
31
+ );
29
32
  const buildRun = (run) => ({
30
33
  inputs: run.inputs,
31
- ...run.preconditions?.length && { preconditions: run.preconditions },
32
34
  signer: run.signer,
33
- ...run.assumptions && { assumptions: run.assumptions },
34
- ...run.referrer !== void 0 && { referrer: run.referrer },
35
- ...run.integratorFeeBps !== void 0 && {
36
- integratorFeeBps: run.integratorFeeBps
37
- },
38
- ...run.maxPriceImpactBps !== void 0 && {
39
- maxPriceImpactBps: run.maxPriceImpactBps
40
- },
41
- ...run.sweepTo !== void 0 && { sweepTo: run.sweepTo },
42
- ...run.simulationPolicy !== void 0 && {
43
- simulationPolicy: run.simulationPolicy
44
- },
45
- ...run.checkOnChainAllowances !== void 0 && {
35
+ ...pickDefined({
36
+ // An empty precondition list is the same as none, so drop it too.
37
+ preconditions: run.preconditions?.length ? run.preconditions : void 0,
38
+ assumptions: run.assumptions,
39
+ referrer: run.referrer,
40
+ integratorFeeBps: run.integratorFeeBps,
41
+ maxPriceImpactBps: run.maxPriceImpactBps,
42
+ sweepTo: run.sweepTo,
43
+ simulationPolicy: run.simulationPolicy,
44
+ simulateUserProgram: run.simulateUserProgram,
46
45
  checkOnChainAllowances: run.checkOnChainAllowances
47
- }
46
+ })
48
47
  });
49
48
  // Annotate the CommonJS export names for ESM import in node:
50
49
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/run/inputs.ts"],"sourcesContent":["import type {\n ComposeRun,\n InputSpec,\n MaterialiserInput,\n Precondition,\n SimulationPolicy,\n SweepTo,\n} from '@lifi/compose-spec';\n\nimport type { Address, InputSchema, InputSpecOf } from '../types.js';\n\n/**\n * Runtime inputs for compiling a flow. Passed to `builder.compile()` or `sdk.request()`.\n *\n * @typeParam T - The flow's input schema, used to type-check `inputs` and `assumptions`.\n */\nexport interface ComposeRunInput<T extends InputSchema = InputSchema> {\n /**\n * Concrete values for each declared flow input. Resource inputs accept a\n * materialiser or a literal integer amount; scalar inputs accept the matching type.\n */\n readonly inputs: { readonly [K in keyof T]: InputSpecOf<T[K]> };\n /** Optional preconditions that must hold before the flow executes (e.g. minimum balances). */\n readonly preconditions?: readonly Precondition[];\n /** The `0x`-prefixed address of the transaction signer. */\n readonly signer: Address;\n /**\n * Optional assumed token amounts for resource inputs, keyed by input name.\n * When a materialiser resolves amounts at execution time rather than upfront,\n * assumptions let the compiler plan routes using estimated values. The keys\n * must match the input names declared in the flow schema.\n */\n readonly assumptions?: { readonly [K in keyof T]?: bigint };\n /** Optional integrator referrer identifier. */\n readonly referrer?: string;\n /**\n * Optional integrator fee in basis points (1bp = 0.01%, max `9000` = 90%).\n * A non-zero value requires the request to be authenticated with an\n * integration-scoped API key — the integration is derived from the key, not\n * this field. Defaults to `0` (no fee) when omitted.\n */\n readonly integratorFeeBps?: number;\n /** Maximum acceptable price impact in basis points (e.g. `300` = 3%). */\n readonly maxPriceImpactBps?: number;\n /**\n * Destination for sweeping all proxy-held terminal resources after execution.\n * Pass a literal `0x`-prefixed address or `{ $ref: \"context.sender\" }` to\n * send remaining tokens to the signer.\n */\n readonly sweepTo?: SweepTo;\n /**\n * Controls behavior when simulation detects a revert.\n * `'strict'` (default) returns an error; `'allow-revert'` returns a partial\n * result with the transaction and revert diagnostics.\n */\n readonly simulationPolicy?: SimulationPolicy;\n /**\n * When `true`, the server checks on-chain ERC-20 allowances and omits\n * approvals that are already sufficient. Defaults to `false`.\n */\n readonly checkOnChainAllowances?: boolean;\n}\n\n/**\n * Creates an untyped materialiser input spec. This is a low-level escape hatch\n * for materialiser kinds not yet covered by the generated helpers.\n *\n * Prefer the typed helpers in the `materialisers` namespace (e.g.\n * `materialisers.balanceOf()`, `materialisers.directDeposit()`) which provide\n * compile-time config validation.\n *\n * @param kind - The materialiser type (e.g. `\"balanceOf\"`, `\"directDeposit\"`).\n * @param config - Optional materialiser-specific configuration.\n * @returns A {@link MaterialiserInput} for use in {@link ComposeRunInput.inputs}.\n *\n * @example\n * ```ts\n * const run = {\n * inputs: { token: materialiser('customKind', { myParam: '0x...' }) },\n * signer: '0x...',\n * };\n * ```\n */\nexport const materialiser = (\n kind: string,\n config: Record<string, unknown> = {},\n): MaterialiserInput => ({\n kind,\n ...config,\n});\n\n/**\n * Assembles a {@link ComposeRun} object from individual parameters.\n * Used internally by the SDK; prefer {@link ComposeRunInput} for external use.\n *\n * @internal\n */\nexport const buildRun = (run: {\n inputs: Record<string, InputSpec>;\n preconditions?: readonly Precondition[];\n signer: string;\n assumptions?: Record<string, bigint>;\n referrer?: string;\n integratorFeeBps?: number;\n maxPriceImpactBps?: number;\n sweepTo?: SweepTo;\n simulationPolicy?: SimulationPolicy;\n checkOnChainAllowances?: boolean;\n}): ComposeRun => ({\n inputs: run.inputs,\n ...(run.preconditions?.length && { preconditions: run.preconditions }),\n signer: run.signer,\n ...(run.assumptions && { assumptions: run.assumptions }),\n ...(run.referrer !== undefined && { referrer: run.referrer }),\n ...(run.integratorFeeBps !== undefined && {\n integratorFeeBps: run.integratorFeeBps,\n }),\n ...(run.maxPriceImpactBps !== undefined && {\n maxPriceImpactBps: run.maxPriceImpactBps,\n }),\n ...(run.sweepTo !== undefined && { sweepTo: run.sweepTo }),\n ...(run.simulationPolicy !== undefined && {\n simulationPolicy: run.simulationPolicy,\n }),\n ...(run.checkOnChainAllowances !== undefined && {\n checkOnChainAllowances: run.checkOnChainAllowances,\n }),\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmFO,MAAM,eAAe,CAC1B,MACA,SAAkC,CAAC,OACZ;AAAA,EACvB;AAAA,EACA,GAAG;AACL;AAQO,MAAM,WAAW,CAAC,SAWN;AAAA,EACjB,QAAQ,IAAI;AAAA,EACZ,GAAI,IAAI,eAAe,UAAU,EAAE,eAAe,IAAI,cAAc;AAAA,EACpE,QAAQ,IAAI;AAAA,EACZ,GAAI,IAAI,eAAe,EAAE,aAAa,IAAI,YAAY;AAAA,EACtD,GAAI,IAAI,aAAa,UAAa,EAAE,UAAU,IAAI,SAAS;AAAA,EAC3D,GAAI,IAAI,qBAAqB,UAAa;AAAA,IACxC,kBAAkB,IAAI;AAAA,EACxB;AAAA,EACA,GAAI,IAAI,sBAAsB,UAAa;AAAA,IACzC,mBAAmB,IAAI;AAAA,EACzB;AAAA,EACA,GAAI,IAAI,YAAY,UAAa,EAAE,SAAS,IAAI,QAAQ;AAAA,EACxD,GAAI,IAAI,qBAAqB,UAAa;AAAA,IACxC,kBAAkB,IAAI;AAAA,EACxB;AAAA,EACA,GAAI,IAAI,2BAA2B,UAAa;AAAA,IAC9C,wBAAwB,IAAI;AAAA,EAC9B;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/run/inputs.ts"],"sourcesContent":["import type {\n ComposeRun,\n InputSpec,\n MaterialiserInput,\n Precondition,\n SimulationPolicy,\n SweepTo,\n} from '@lifi/compose-spec';\n\nimport type { Address, InputSchema, InputSpecOf } from '../types.js';\n\n/**\n * Runtime inputs for compiling a flow. Passed to `builder.compile()` or `sdk.request()`.\n *\n * @typeParam T - The flow's input schema, used to type-check `inputs` and `assumptions`.\n */\nexport interface ComposeRunInput<T extends InputSchema = InputSchema> {\n /**\n * Concrete values for each declared flow input. Resource inputs accept a\n * materialiser or a literal integer amount; scalar inputs accept the matching type.\n */\n readonly inputs: { readonly [K in keyof T]: InputSpecOf<T[K]> };\n /** Optional preconditions that must hold before the flow executes (e.g. minimum balances). */\n readonly preconditions?: readonly Precondition[];\n /** The `0x`-prefixed address of the transaction signer. */\n readonly signer: Address;\n /**\n * Optional assumed token amounts for resource inputs, keyed by input name.\n * When a materialiser resolves amounts at execution time rather than upfront,\n * assumptions let the compiler plan routes using estimated values. The keys\n * must match the input names declared in the flow schema.\n */\n readonly assumptions?: { readonly [K in keyof T]?: bigint };\n /** Optional integrator referrer identifier. */\n readonly referrer?: string;\n /**\n * Optional integrator fee in basis points (1bp = 0.01%, max `9000` = 90%).\n * A non-zero value requires the request to be authenticated with an\n * integration-scoped API key — the integration is derived from the key, not\n * this field. Defaults to `0` (no fee) when omitted.\n */\n readonly integratorFeeBps?: number;\n /** Maximum acceptable price impact in basis points (e.g. `300` = 3%). */\n readonly maxPriceImpactBps?: number;\n /**\n * Destination for sweeping all proxy-held terminal resources after execution.\n * Pass a literal `0x`-prefixed address or `{ $ref: \"context.sender\" }` to\n * send remaining tokens to the signer.\n */\n readonly sweepTo?: SweepTo;\n /**\n * Controls behavior when simulation detects a revert.\n * `'strict'` (default) returns an error; `'allow-revert'` returns a partial\n * result with the transaction and revert diagnostics.\n */\n readonly simulationPolicy?: SimulationPolicy;\n /**\n * When `true`, the server also simulates the final user-facing transaction\n * after the structured simulation succeeds; reverts honour\n * `simulationPolicy`. On success the result is echoed back on the response as\n * `userProgramSimulation`. Defaults to `false`.\n */\n readonly simulateUserProgram?: boolean;\n /**\n * When `true`, the server checks on-chain ERC-20 allowances and omits\n * approvals that are already sufficient. Defaults to `false`.\n */\n readonly checkOnChainAllowances?: boolean;\n}\n\n/**\n * Creates an untyped materialiser input spec. This is a low-level escape hatch\n * for materialiser kinds not yet covered by the generated helpers.\n *\n * Prefer the typed helpers in the `materialisers` namespace (e.g.\n * `materialisers.balanceOf()`, `materialisers.directDeposit()`) which provide\n * compile-time config validation.\n *\n * @param kind - The materialiser type (e.g. `\"balanceOf\"`, `\"directDeposit\"`).\n * @param config - Optional materialiser-specific configuration.\n * @returns A {@link MaterialiserInput} for use in {@link ComposeRunInput.inputs}.\n *\n * @example\n * ```ts\n * const run = {\n * inputs: { token: materialiser('customKind', { myParam: '0x...' }) },\n * signer: '0x...',\n * };\n * ```\n */\nexport const materialiser = (\n kind: string,\n config: Record<string, unknown> = {},\n): MaterialiserInput => ({\n kind,\n ...config,\n});\n\n/**\n * Drops the keys whose value is `undefined`, so optional fields are omitted\n * from the wire payload rather than serialized as `null`.\n *\n * A local copy of `pickDefined` from `@lifi/utils`: this package is published\n * to npm and `@lifi/utils` is a private workspace package, so it cannot be a\n * runtime dependency here.\n */\nconst pickDefined = <S extends Record<string, unknown>>(\n obj: S,\n): Partial<{ [K in keyof S]: Exclude<S[K], undefined> }> =>\n Object.fromEntries(\n Object.entries(obj).filter(([, value]) => value !== undefined),\n ) as Partial<{ [K in keyof S]: Exclude<S[K], undefined> }>;\n\n/**\n * Assembles a {@link ComposeRun} object from individual parameters.\n * Used internally by the SDK; prefer {@link ComposeRunInput} for external use.\n *\n * @internal\n */\nexport const buildRun = (run: {\n inputs: Record<string, InputSpec>;\n preconditions?: readonly Precondition[];\n signer: string;\n assumptions?: Record<string, bigint>;\n referrer?: string;\n integratorFeeBps?: number;\n maxPriceImpactBps?: number;\n sweepTo?: SweepTo;\n simulationPolicy?: SimulationPolicy;\n simulateUserProgram?: boolean;\n checkOnChainAllowances?: boolean;\n}): ComposeRun => ({\n inputs: run.inputs,\n signer: run.signer,\n ...pickDefined({\n // An empty precondition list is the same as none, so drop it too.\n preconditions: run.preconditions?.length ? run.preconditions : undefined,\n assumptions: run.assumptions,\n referrer: run.referrer,\n integratorFeeBps: run.integratorFeeBps,\n maxPriceImpactBps: run.maxPriceImpactBps,\n sweepTo: run.sweepTo,\n simulationPolicy: run.simulationPolicy,\n simulateUserProgram: run.simulateUserProgram,\n checkOnChainAllowances: run.checkOnChainAllowances,\n }),\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0FO,MAAM,eAAe,CAC1B,MACA,SAAkC,CAAC,OACZ;AAAA,EACvB;AAAA,EACA,GAAG;AACL;AAUA,MAAM,cAAc,CAClB,QAEA,OAAO;AAAA,EACL,OAAO,QAAQ,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,MAAM,UAAU,MAAS;AAC/D;AAQK,MAAM,WAAW,CAAC,SAYN;AAAA,EACjB,QAAQ,IAAI;AAAA,EACZ,QAAQ,IAAI;AAAA,EACZ,GAAG,YAAY;AAAA;AAAA,IAEb,eAAe,IAAI,eAAe,SAAS,IAAI,gBAAgB;AAAA,IAC/D,aAAa,IAAI;AAAA,IACjB,UAAU,IAAI;AAAA,IACd,kBAAkB,IAAI;AAAA,IACtB,mBAAmB,IAAI;AAAA,IACvB,SAAS,IAAI;AAAA,IACb,kBAAkB,IAAI;AAAA,IACtB,qBAAqB,IAAI;AAAA,IACzB,wBAAwB,IAAI;AAAA,EAC9B,CAAC;AACH;","names":[]}
@@ -50,6 +50,13 @@ interface ComposeRunInput<T extends InputSchema = InputSchema> {
50
50
  * result with the transaction and revert diagnostics.
51
51
  */
52
52
  readonly simulationPolicy?: SimulationPolicy;
53
+ /**
54
+ * When `true`, the server also simulates the final user-facing transaction
55
+ * after the structured simulation succeeds; reverts honour
56
+ * `simulationPolicy`. On success the result is echoed back on the response as
57
+ * `userProgramSimulation`. Defaults to `false`.
58
+ */
59
+ readonly simulateUserProgram?: boolean;
53
60
  /**
54
61
  * When `true`, the server checks on-chain ERC-20 allowances and omits
55
62
  * approvals that are already sufficient. Defaults to `false`.
@@ -93,6 +100,7 @@ declare const buildRun: (run: {
93
100
  maxPriceImpactBps?: number;
94
101
  sweepTo?: SweepTo;
95
102
  simulationPolicy?: SimulationPolicy;
103
+ simulateUserProgram?: boolean;
96
104
  checkOnChainAllowances?: boolean;
97
105
  }) => ComposeRun;
98
106
 
@@ -50,6 +50,13 @@ interface ComposeRunInput<T extends InputSchema = InputSchema> {
50
50
  * result with the transaction and revert diagnostics.
51
51
  */
52
52
  readonly simulationPolicy?: SimulationPolicy;
53
+ /**
54
+ * When `true`, the server also simulates the final user-facing transaction
55
+ * after the structured simulation succeeds; reverts honour
56
+ * `simulationPolicy`. On success the result is echoed back on the response as
57
+ * `userProgramSimulation`. Defaults to `false`.
58
+ */
59
+ readonly simulateUserProgram?: boolean;
53
60
  /**
54
61
  * When `true`, the server checks on-chain ERC-20 allowances and omits
55
62
  * approvals that are already sufficient. Defaults to `false`.
@@ -93,6 +100,7 @@ declare const buildRun: (run: {
93
100
  maxPriceImpactBps?: number;
94
101
  sweepTo?: SweepTo;
95
102
  simulationPolicy?: SimulationPolicy;
103
+ simulateUserProgram?: boolean;
96
104
  checkOnChainAllowances?: boolean;
97
105
  }) => ComposeRun;
98
106
 
@@ -2,25 +2,24 @@ const materialiser = (kind, config = {}) => ({
2
2
  kind,
3
3
  ...config
4
4
  });
5
+ const pickDefined = (obj) => Object.fromEntries(
6
+ Object.entries(obj).filter(([, value]) => value !== void 0)
7
+ );
5
8
  const buildRun = (run) => ({
6
9
  inputs: run.inputs,
7
- ...run.preconditions?.length && { preconditions: run.preconditions },
8
10
  signer: run.signer,
9
- ...run.assumptions && { assumptions: run.assumptions },
10
- ...run.referrer !== void 0 && { referrer: run.referrer },
11
- ...run.integratorFeeBps !== void 0 && {
12
- integratorFeeBps: run.integratorFeeBps
13
- },
14
- ...run.maxPriceImpactBps !== void 0 && {
15
- maxPriceImpactBps: run.maxPriceImpactBps
16
- },
17
- ...run.sweepTo !== void 0 && { sweepTo: run.sweepTo },
18
- ...run.simulationPolicy !== void 0 && {
19
- simulationPolicy: run.simulationPolicy
20
- },
21
- ...run.checkOnChainAllowances !== void 0 && {
11
+ ...pickDefined({
12
+ // An empty precondition list is the same as none, so drop it too.
13
+ preconditions: run.preconditions?.length ? run.preconditions : void 0,
14
+ assumptions: run.assumptions,
15
+ referrer: run.referrer,
16
+ integratorFeeBps: run.integratorFeeBps,
17
+ maxPriceImpactBps: run.maxPriceImpactBps,
18
+ sweepTo: run.sweepTo,
19
+ simulationPolicy: run.simulationPolicy,
20
+ simulateUserProgram: run.simulateUserProgram,
22
21
  checkOnChainAllowances: run.checkOnChainAllowances
23
- }
22
+ })
24
23
  });
25
24
  export {
26
25
  buildRun,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/run/inputs.ts"],"sourcesContent":["import type {\n ComposeRun,\n InputSpec,\n MaterialiserInput,\n Precondition,\n SimulationPolicy,\n SweepTo,\n} from '@lifi/compose-spec';\n\nimport type { Address, InputSchema, InputSpecOf } from '../types.js';\n\n/**\n * Runtime inputs for compiling a flow. Passed to `builder.compile()` or `sdk.request()`.\n *\n * @typeParam T - The flow's input schema, used to type-check `inputs` and `assumptions`.\n */\nexport interface ComposeRunInput<T extends InputSchema = InputSchema> {\n /**\n * Concrete values for each declared flow input. Resource inputs accept a\n * materialiser or a literal integer amount; scalar inputs accept the matching type.\n */\n readonly inputs: { readonly [K in keyof T]: InputSpecOf<T[K]> };\n /** Optional preconditions that must hold before the flow executes (e.g. minimum balances). */\n readonly preconditions?: readonly Precondition[];\n /** The `0x`-prefixed address of the transaction signer. */\n readonly signer: Address;\n /**\n * Optional assumed token amounts for resource inputs, keyed by input name.\n * When a materialiser resolves amounts at execution time rather than upfront,\n * assumptions let the compiler plan routes using estimated values. The keys\n * must match the input names declared in the flow schema.\n */\n readonly assumptions?: { readonly [K in keyof T]?: bigint };\n /** Optional integrator referrer identifier. */\n readonly referrer?: string;\n /**\n * Optional integrator fee in basis points (1bp = 0.01%, max `9000` = 90%).\n * A non-zero value requires the request to be authenticated with an\n * integration-scoped API key — the integration is derived from the key, not\n * this field. Defaults to `0` (no fee) when omitted.\n */\n readonly integratorFeeBps?: number;\n /** Maximum acceptable price impact in basis points (e.g. `300` = 3%). */\n readonly maxPriceImpactBps?: number;\n /**\n * Destination for sweeping all proxy-held terminal resources after execution.\n * Pass a literal `0x`-prefixed address or `{ $ref: \"context.sender\" }` to\n * send remaining tokens to the signer.\n */\n readonly sweepTo?: SweepTo;\n /**\n * Controls behavior when simulation detects a revert.\n * `'strict'` (default) returns an error; `'allow-revert'` returns a partial\n * result with the transaction and revert diagnostics.\n */\n readonly simulationPolicy?: SimulationPolicy;\n /**\n * When `true`, the server checks on-chain ERC-20 allowances and omits\n * approvals that are already sufficient. Defaults to `false`.\n */\n readonly checkOnChainAllowances?: boolean;\n}\n\n/**\n * Creates an untyped materialiser input spec. This is a low-level escape hatch\n * for materialiser kinds not yet covered by the generated helpers.\n *\n * Prefer the typed helpers in the `materialisers` namespace (e.g.\n * `materialisers.balanceOf()`, `materialisers.directDeposit()`) which provide\n * compile-time config validation.\n *\n * @param kind - The materialiser type (e.g. `\"balanceOf\"`, `\"directDeposit\"`).\n * @param config - Optional materialiser-specific configuration.\n * @returns A {@link MaterialiserInput} for use in {@link ComposeRunInput.inputs}.\n *\n * @example\n * ```ts\n * const run = {\n * inputs: { token: materialiser('customKind', { myParam: '0x...' }) },\n * signer: '0x...',\n * };\n * ```\n */\nexport const materialiser = (\n kind: string,\n config: Record<string, unknown> = {},\n): MaterialiserInput => ({\n kind,\n ...config,\n});\n\n/**\n * Assembles a {@link ComposeRun} object from individual parameters.\n * Used internally by the SDK; prefer {@link ComposeRunInput} for external use.\n *\n * @internal\n */\nexport const buildRun = (run: {\n inputs: Record<string, InputSpec>;\n preconditions?: readonly Precondition[];\n signer: string;\n assumptions?: Record<string, bigint>;\n referrer?: string;\n integratorFeeBps?: number;\n maxPriceImpactBps?: number;\n sweepTo?: SweepTo;\n simulationPolicy?: SimulationPolicy;\n checkOnChainAllowances?: boolean;\n}): ComposeRun => ({\n inputs: run.inputs,\n ...(run.preconditions?.length && { preconditions: run.preconditions }),\n signer: run.signer,\n ...(run.assumptions && { assumptions: run.assumptions }),\n ...(run.referrer !== undefined && { referrer: run.referrer }),\n ...(run.integratorFeeBps !== undefined && {\n integratorFeeBps: run.integratorFeeBps,\n }),\n ...(run.maxPriceImpactBps !== undefined && {\n maxPriceImpactBps: run.maxPriceImpactBps,\n }),\n ...(run.sweepTo !== undefined && { sweepTo: run.sweepTo }),\n ...(run.simulationPolicy !== undefined && {\n simulationPolicy: run.simulationPolicy,\n }),\n ...(run.checkOnChainAllowances !== undefined && {\n checkOnChainAllowances: run.checkOnChainAllowances,\n }),\n});\n"],"mappings":"AAmFO,MAAM,eAAe,CAC1B,MACA,SAAkC,CAAC,OACZ;AAAA,EACvB;AAAA,EACA,GAAG;AACL;AAQO,MAAM,WAAW,CAAC,SAWN;AAAA,EACjB,QAAQ,IAAI;AAAA,EACZ,GAAI,IAAI,eAAe,UAAU,EAAE,eAAe,IAAI,cAAc;AAAA,EACpE,QAAQ,IAAI;AAAA,EACZ,GAAI,IAAI,eAAe,EAAE,aAAa,IAAI,YAAY;AAAA,EACtD,GAAI,IAAI,aAAa,UAAa,EAAE,UAAU,IAAI,SAAS;AAAA,EAC3D,GAAI,IAAI,qBAAqB,UAAa;AAAA,IACxC,kBAAkB,IAAI;AAAA,EACxB;AAAA,EACA,GAAI,IAAI,sBAAsB,UAAa;AAAA,IACzC,mBAAmB,IAAI;AAAA,EACzB;AAAA,EACA,GAAI,IAAI,YAAY,UAAa,EAAE,SAAS,IAAI,QAAQ;AAAA,EACxD,GAAI,IAAI,qBAAqB,UAAa;AAAA,IACxC,kBAAkB,IAAI;AAAA,EACxB;AAAA,EACA,GAAI,IAAI,2BAA2B,UAAa;AAAA,IAC9C,wBAAwB,IAAI;AAAA,EAC9B;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/run/inputs.ts"],"sourcesContent":["import type {\n ComposeRun,\n InputSpec,\n MaterialiserInput,\n Precondition,\n SimulationPolicy,\n SweepTo,\n} from '@lifi/compose-spec';\n\nimport type { Address, InputSchema, InputSpecOf } from '../types.js';\n\n/**\n * Runtime inputs for compiling a flow. Passed to `builder.compile()` or `sdk.request()`.\n *\n * @typeParam T - The flow's input schema, used to type-check `inputs` and `assumptions`.\n */\nexport interface ComposeRunInput<T extends InputSchema = InputSchema> {\n /**\n * Concrete values for each declared flow input. Resource inputs accept a\n * materialiser or a literal integer amount; scalar inputs accept the matching type.\n */\n readonly inputs: { readonly [K in keyof T]: InputSpecOf<T[K]> };\n /** Optional preconditions that must hold before the flow executes (e.g. minimum balances). */\n readonly preconditions?: readonly Precondition[];\n /** The `0x`-prefixed address of the transaction signer. */\n readonly signer: Address;\n /**\n * Optional assumed token amounts for resource inputs, keyed by input name.\n * When a materialiser resolves amounts at execution time rather than upfront,\n * assumptions let the compiler plan routes using estimated values. The keys\n * must match the input names declared in the flow schema.\n */\n readonly assumptions?: { readonly [K in keyof T]?: bigint };\n /** Optional integrator referrer identifier. */\n readonly referrer?: string;\n /**\n * Optional integrator fee in basis points (1bp = 0.01%, max `9000` = 90%).\n * A non-zero value requires the request to be authenticated with an\n * integration-scoped API key — the integration is derived from the key, not\n * this field. Defaults to `0` (no fee) when omitted.\n */\n readonly integratorFeeBps?: number;\n /** Maximum acceptable price impact in basis points (e.g. `300` = 3%). */\n readonly maxPriceImpactBps?: number;\n /**\n * Destination for sweeping all proxy-held terminal resources after execution.\n * Pass a literal `0x`-prefixed address or `{ $ref: \"context.sender\" }` to\n * send remaining tokens to the signer.\n */\n readonly sweepTo?: SweepTo;\n /**\n * Controls behavior when simulation detects a revert.\n * `'strict'` (default) returns an error; `'allow-revert'` returns a partial\n * result with the transaction and revert diagnostics.\n */\n readonly simulationPolicy?: SimulationPolicy;\n /**\n * When `true`, the server also simulates the final user-facing transaction\n * after the structured simulation succeeds; reverts honour\n * `simulationPolicy`. On success the result is echoed back on the response as\n * `userProgramSimulation`. Defaults to `false`.\n */\n readonly simulateUserProgram?: boolean;\n /**\n * When `true`, the server checks on-chain ERC-20 allowances and omits\n * approvals that are already sufficient. Defaults to `false`.\n */\n readonly checkOnChainAllowances?: boolean;\n}\n\n/**\n * Creates an untyped materialiser input spec. This is a low-level escape hatch\n * for materialiser kinds not yet covered by the generated helpers.\n *\n * Prefer the typed helpers in the `materialisers` namespace (e.g.\n * `materialisers.balanceOf()`, `materialisers.directDeposit()`) which provide\n * compile-time config validation.\n *\n * @param kind - The materialiser type (e.g. `\"balanceOf\"`, `\"directDeposit\"`).\n * @param config - Optional materialiser-specific configuration.\n * @returns A {@link MaterialiserInput} for use in {@link ComposeRunInput.inputs}.\n *\n * @example\n * ```ts\n * const run = {\n * inputs: { token: materialiser('customKind', { myParam: '0x...' }) },\n * signer: '0x...',\n * };\n * ```\n */\nexport const materialiser = (\n kind: string,\n config: Record<string, unknown> = {},\n): MaterialiserInput => ({\n kind,\n ...config,\n});\n\n/**\n * Drops the keys whose value is `undefined`, so optional fields are omitted\n * from the wire payload rather than serialized as `null`.\n *\n * A local copy of `pickDefined` from `@lifi/utils`: this package is published\n * to npm and `@lifi/utils` is a private workspace package, so it cannot be a\n * runtime dependency here.\n */\nconst pickDefined = <S extends Record<string, unknown>>(\n obj: S,\n): Partial<{ [K in keyof S]: Exclude<S[K], undefined> }> =>\n Object.fromEntries(\n Object.entries(obj).filter(([, value]) => value !== undefined),\n ) as Partial<{ [K in keyof S]: Exclude<S[K], undefined> }>;\n\n/**\n * Assembles a {@link ComposeRun} object from individual parameters.\n * Used internally by the SDK; prefer {@link ComposeRunInput} for external use.\n *\n * @internal\n */\nexport const buildRun = (run: {\n inputs: Record<string, InputSpec>;\n preconditions?: readonly Precondition[];\n signer: string;\n assumptions?: Record<string, bigint>;\n referrer?: string;\n integratorFeeBps?: number;\n maxPriceImpactBps?: number;\n sweepTo?: SweepTo;\n simulationPolicy?: SimulationPolicy;\n simulateUserProgram?: boolean;\n checkOnChainAllowances?: boolean;\n}): ComposeRun => ({\n inputs: run.inputs,\n signer: run.signer,\n ...pickDefined({\n // An empty precondition list is the same as none, so drop it too.\n preconditions: run.preconditions?.length ? run.preconditions : undefined,\n assumptions: run.assumptions,\n referrer: run.referrer,\n integratorFeeBps: run.integratorFeeBps,\n maxPriceImpactBps: run.maxPriceImpactBps,\n sweepTo: run.sweepTo,\n simulationPolicy: run.simulationPolicy,\n simulateUserProgram: run.simulateUserProgram,\n checkOnChainAllowances: run.checkOnChainAllowances,\n }),\n});\n"],"mappings":"AA0FO,MAAM,eAAe,CAC1B,MACA,SAAkC,CAAC,OACZ;AAAA,EACvB;AAAA,EACA,GAAG;AACL;AAUA,MAAM,cAAc,CAClB,QAEA,OAAO;AAAA,EACL,OAAO,QAAQ,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,KAAK,MAAM,UAAU,MAAS;AAC/D;AAQK,MAAM,WAAW,CAAC,SAYN;AAAA,EACjB,QAAQ,IAAI;AAAA,EACZ,QAAQ,IAAI;AAAA,EACZ,GAAG,YAAY;AAAA;AAAA,IAEb,eAAe,IAAI,eAAe,SAAS,IAAI,gBAAgB;AAAA,IAC/D,aAAa,IAAI;AAAA,IACjB,UAAU,IAAI;AAAA,IACd,kBAAkB,IAAI;AAAA,IACtB,mBAAmB,IAAI;AAAA,IACvB,SAAS,IAAI;AAAA,IACb,kBAAkB,IAAI;AAAA,IACtB,qBAAqB,IAAI;AAAA,IACzB,wBAAwB,IAAI;AAAA,EAC9B,CAAC;AACH;","names":[]}
@@ -23,6 +23,11 @@ __export(simulate_exports, {
23
23
  module.exports = __toCommonJS(simulate_exports);
24
24
  const buildSimulateRequest = (input) => {
25
25
  const { result, chainId, signer, trackedBalances, requirements, block } = input;
26
+ if (result.transactionRequest === void 0) {
27
+ throw new Error(
28
+ "buildSimulateRequest: the compile result has no transactionRequest (empty compiled program \u2014 a settle-only external-funding flow); submit the `actions` entries instead of simulating"
29
+ );
30
+ }
26
31
  return {
27
32
  chainId,
28
33
  from: signer,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/run/simulate.ts"],"sourcesContent":["import type {\n ComposeCompileResult,\n SimulateRequest,\n SlotFinderRequirement,\n TrackedBalance,\n} from '@lifi/compose-spec';\n\n/**\n * Input for {@link buildSimulateRequest}: a compile result plus the fields a\n * simulation needs that a compiled flow does not carry.\n */\nexport interface BuildSimulateRequestInput {\n /**\n * A result from `builder.compile(...)` / `client.compile(...)`. Both\n * `success` and `partial` results carry a `transactionRequest`, so either is\n * valid input — the helper does not discriminate on `status`.\n */\n readonly result: ComposeCompileResult;\n /** EVM chain id. A compile result does not carry the target chain. */\n readonly chainId: number;\n /**\n * The transaction sender (`from`). A compile result does not carry the\n * signer, so it must be supplied here.\n */\n readonly signer: string;\n /**\n * Balances to watch across the simulation. These cannot be inferred from a\n * flow and must be supplied by the caller.\n */\n readonly trackedBalances: readonly TrackedBalance[];\n /** Optional funding instructions applied before simulation. */\n readonly requirements?: readonly SlotFinderRequirement[];\n /** Optional block to pin the simulation to. Omitted ⇒ chain head. */\n readonly block?: number;\n /**\n * Optional native value override. Defaults to the compiled\n * `transactionRequest.value` when omitted.\n */\n readonly value?: bigint | string;\n}\n\n/**\n * Assembles a {@link SimulateRequest} from a compile result and the\n * caller-supplied chain, signer, and tracked balances. Pure: performs no\n * network I/O, does not mutate its input, and returns a fresh object.\n *\n * Bridges the common case — simulate the transaction you just compiled —\n * without coupling raw-transaction simulation to the flow builder. The\n * `value` defaults to the compiled transaction's value unless overridden.\n *\n * @example\n * ```ts\n * const compiled = await builder.compile({ inputs: { ... }, signer: '0x1111...' });\n * const req = buildSimulateRequest({\n * result: compiled,\n * chainId: 1,\n * signer: '0x1111111111111111111111111111111111111111',\n * trackedBalances: [{ token: '0xA0b8...', owner: '0x1111...' }],\n * });\n * const sim = await sdk.client.simulate(req);\n * ```\n */\nexport const buildSimulateRequest = (\n input: BuildSimulateRequestInput,\n): SimulateRequest => {\n const { result, chainId, signer, trackedBalances, requirements, block } =\n input;\n return {\n chainId,\n from: signer,\n to: result.transactionRequest.to,\n data: result.transactionRequest.data,\n value: input.value ?? result.transactionRequest.value,\n block,\n requirements,\n trackedBalances,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8DO,MAAM,uBAAuB,CAClC,UACoB;AACpB,QAAM,EAAE,QAAQ,SAAS,QAAQ,iBAAiB,cAAc,MAAM,IACpE;AACF,SAAO;AAAA,IACL;AAAA,IACA,MAAM;AAAA,IACN,IAAI,OAAO,mBAAmB;AAAA,IAC9B,MAAM,OAAO,mBAAmB;AAAA,IAChC,OAAO,MAAM,SAAS,OAAO,mBAAmB;AAAA,IAChD;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/run/simulate.ts"],"sourcesContent":["import type {\n ComposeCompileResult,\n SimulateRequest,\n SlotFinderRequirement,\n TrackedBalance,\n} from '@lifi/compose-spec';\n\n/**\n * Input for {@link buildSimulateRequest}: a compile result plus the fields a\n * simulation needs that a compiled flow does not carry.\n */\nexport interface BuildSimulateRequestInput {\n /**\n * A result from `builder.compile(...)` / `client.compile(...)`. Both\n * `success` and `partial` results are valid input — the helper does not\n * discriminate on `status`. A success result for an empty compiled program\n * (a settle-only `funding: 'external'` flow) carries no\n * `transactionRequest`; there is nothing to simulate and this helper\n * throws — submit the result's `actions` entries directly instead.\n */\n readonly result: ComposeCompileResult;\n /** EVM chain id. A compile result does not carry the target chain. */\n readonly chainId: number;\n /**\n * The transaction sender (`from`). A compile result does not carry the\n * signer, so it must be supplied here.\n */\n readonly signer: string;\n /**\n * Balances to watch across the simulation. These cannot be inferred from a\n * flow and must be supplied by the caller.\n */\n readonly trackedBalances: readonly TrackedBalance[];\n /** Optional funding instructions applied before simulation. */\n readonly requirements?: readonly SlotFinderRequirement[];\n /** Optional block to pin the simulation to. Omitted ⇒ chain head. */\n readonly block?: number;\n /**\n * Optional native value override. Defaults to the compiled\n * `transactionRequest.value` when omitted.\n */\n readonly value?: bigint | string;\n}\n\n/**\n * Assembles a {@link SimulateRequest} from a compile result and the\n * caller-supplied chain, signer, and tracked balances. Pure: performs no\n * network I/O, does not mutate its input, and returns a fresh object.\n *\n * Bridges the common case — simulate the transaction you just compiled —\n * without coupling raw-transaction simulation to the flow builder. The\n * `value` defaults to the compiled transaction's value unless overridden.\n *\n * @example\n * ```ts\n * const compiled = await builder.compile({ inputs: { ... }, signer: '0x1111...' });\n * const req = buildSimulateRequest({\n * result: compiled,\n * chainId: 1,\n * signer: '0x1111111111111111111111111111111111111111',\n * trackedBalances: [{ token: '0xA0b8...', owner: '0x1111...' }],\n * });\n * const sim = await sdk.client.simulate(req);\n * ```\n */\nexport const buildSimulateRequest = (\n input: BuildSimulateRequestInput,\n): SimulateRequest => {\n const { result, chainId, signer, trackedBalances, requirements, block } =\n input;\n // A settle-only flow authored with `funding: 'external'` compiles to an\n // empty program: the success response carries no `transactionRequest`, so\n // there is nothing to simulate — the required submissions are the\n // `actions` entries, submitted directly.\n if (result.transactionRequest === undefined) {\n throw new Error(\n 'buildSimulateRequest: the compile result has no transactionRequest (empty compiled program — a settle-only external-funding flow); submit the `actions` entries instead of simulating',\n );\n }\n return {\n chainId,\n from: signer,\n to: result.transactionRequest.to,\n data: result.transactionRequest.data,\n value: input.value ?? result.transactionRequest.value,\n block,\n requirements,\n trackedBalances,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiEO,MAAM,uBAAuB,CAClC,UACoB;AACpB,QAAM,EAAE,QAAQ,SAAS,QAAQ,iBAAiB,cAAc,MAAM,IACpE;AAKF,MAAI,OAAO,uBAAuB,QAAW;AAC3C,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AAAA,IACL;AAAA,IACA,MAAM;AAAA,IACN,IAAI,OAAO,mBAAmB;AAAA,IAC9B,MAAM,OAAO,mBAAmB;AAAA,IAChC,OAAO,MAAM,SAAS,OAAO,mBAAmB;AAAA,IAChD;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -7,8 +7,11 @@ import { ComposeCompileResult, TrackedBalance, SlotFinderRequirement, SimulateRe
7
7
  interface BuildSimulateRequestInput {
8
8
  /**
9
9
  * A result from `builder.compile(...)` / `client.compile(...)`. Both
10
- * `success` and `partial` results carry a `transactionRequest`, so either is
11
- * valid input — the helper does not discriminate on `status`.
10
+ * `success` and `partial` results are valid input — the helper does not
11
+ * discriminate on `status`. A success result for an empty compiled program
12
+ * (a settle-only `funding: 'external'` flow) carries no
13
+ * `transactionRequest`; there is nothing to simulate and this helper
14
+ * throws — submit the result's `actions` entries directly instead.
12
15
  */
13
16
  readonly result: ComposeCompileResult;
14
17
  /** EVM chain id. A compile result does not carry the target chain. */
@@ -7,8 +7,11 @@ import { ComposeCompileResult, TrackedBalance, SlotFinderRequirement, SimulateRe
7
7
  interface BuildSimulateRequestInput {
8
8
  /**
9
9
  * A result from `builder.compile(...)` / `client.compile(...)`. Both
10
- * `success` and `partial` results carry a `transactionRequest`, so either is
11
- * valid input — the helper does not discriminate on `status`.
10
+ * `success` and `partial` results are valid input — the helper does not
11
+ * discriminate on `status`. A success result for an empty compiled program
12
+ * (a settle-only `funding: 'external'` flow) carries no
13
+ * `transactionRequest`; there is nothing to simulate and this helper
14
+ * throws — submit the result's `actions` entries directly instead.
12
15
  */
13
16
  readonly result: ComposeCompileResult;
14
17
  /** EVM chain id. A compile result does not carry the target chain. */
@@ -1,5 +1,10 @@
1
1
  const buildSimulateRequest = (input) => {
2
2
  const { result, chainId, signer, trackedBalances, requirements, block } = input;
3
+ if (result.transactionRequest === void 0) {
4
+ throw new Error(
5
+ "buildSimulateRequest: the compile result has no transactionRequest (empty compiled program \u2014 a settle-only external-funding flow); submit the `actions` entries instead of simulating"
6
+ );
7
+ }
3
8
  return {
4
9
  chainId,
5
10
  from: signer,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/run/simulate.ts"],"sourcesContent":["import type {\n ComposeCompileResult,\n SimulateRequest,\n SlotFinderRequirement,\n TrackedBalance,\n} from '@lifi/compose-spec';\n\n/**\n * Input for {@link buildSimulateRequest}: a compile result plus the fields a\n * simulation needs that a compiled flow does not carry.\n */\nexport interface BuildSimulateRequestInput {\n /**\n * A result from `builder.compile(...)` / `client.compile(...)`. Both\n * `success` and `partial` results carry a `transactionRequest`, so either is\n * valid input — the helper does not discriminate on `status`.\n */\n readonly result: ComposeCompileResult;\n /** EVM chain id. A compile result does not carry the target chain. */\n readonly chainId: number;\n /**\n * The transaction sender (`from`). A compile result does not carry the\n * signer, so it must be supplied here.\n */\n readonly signer: string;\n /**\n * Balances to watch across the simulation. These cannot be inferred from a\n * flow and must be supplied by the caller.\n */\n readonly trackedBalances: readonly TrackedBalance[];\n /** Optional funding instructions applied before simulation. */\n readonly requirements?: readonly SlotFinderRequirement[];\n /** Optional block to pin the simulation to. Omitted ⇒ chain head. */\n readonly block?: number;\n /**\n * Optional native value override. Defaults to the compiled\n * `transactionRequest.value` when omitted.\n */\n readonly value?: bigint | string;\n}\n\n/**\n * Assembles a {@link SimulateRequest} from a compile result and the\n * caller-supplied chain, signer, and tracked balances. Pure: performs no\n * network I/O, does not mutate its input, and returns a fresh object.\n *\n * Bridges the common case — simulate the transaction you just compiled —\n * without coupling raw-transaction simulation to the flow builder. The\n * `value` defaults to the compiled transaction's value unless overridden.\n *\n * @example\n * ```ts\n * const compiled = await builder.compile({ inputs: { ... }, signer: '0x1111...' });\n * const req = buildSimulateRequest({\n * result: compiled,\n * chainId: 1,\n * signer: '0x1111111111111111111111111111111111111111',\n * trackedBalances: [{ token: '0xA0b8...', owner: '0x1111...' }],\n * });\n * const sim = await sdk.client.simulate(req);\n * ```\n */\nexport const buildSimulateRequest = (\n input: BuildSimulateRequestInput,\n): SimulateRequest => {\n const { result, chainId, signer, trackedBalances, requirements, block } =\n input;\n return {\n chainId,\n from: signer,\n to: result.transactionRequest.to,\n data: result.transactionRequest.data,\n value: input.value ?? result.transactionRequest.value,\n block,\n requirements,\n trackedBalances,\n };\n};\n"],"mappings":"AA8DO,MAAM,uBAAuB,CAClC,UACoB;AACpB,QAAM,EAAE,QAAQ,SAAS,QAAQ,iBAAiB,cAAc,MAAM,IACpE;AACF,SAAO;AAAA,IACL;AAAA,IACA,MAAM;AAAA,IACN,IAAI,OAAO,mBAAmB;AAAA,IAC9B,MAAM,OAAO,mBAAmB;AAAA,IAChC,OAAO,MAAM,SAAS,OAAO,mBAAmB;AAAA,IAChD;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/run/simulate.ts"],"sourcesContent":["import type {\n ComposeCompileResult,\n SimulateRequest,\n SlotFinderRequirement,\n TrackedBalance,\n} from '@lifi/compose-spec';\n\n/**\n * Input for {@link buildSimulateRequest}: a compile result plus the fields a\n * simulation needs that a compiled flow does not carry.\n */\nexport interface BuildSimulateRequestInput {\n /**\n * A result from `builder.compile(...)` / `client.compile(...)`. Both\n * `success` and `partial` results are valid input — the helper does not\n * discriminate on `status`. A success result for an empty compiled program\n * (a settle-only `funding: 'external'` flow) carries no\n * `transactionRequest`; there is nothing to simulate and this helper\n * throws — submit the result's `actions` entries directly instead.\n */\n readonly result: ComposeCompileResult;\n /** EVM chain id. A compile result does not carry the target chain. */\n readonly chainId: number;\n /**\n * The transaction sender (`from`). A compile result does not carry the\n * signer, so it must be supplied here.\n */\n readonly signer: string;\n /**\n * Balances to watch across the simulation. These cannot be inferred from a\n * flow and must be supplied by the caller.\n */\n readonly trackedBalances: readonly TrackedBalance[];\n /** Optional funding instructions applied before simulation. */\n readonly requirements?: readonly SlotFinderRequirement[];\n /** Optional block to pin the simulation to. Omitted ⇒ chain head. */\n readonly block?: number;\n /**\n * Optional native value override. Defaults to the compiled\n * `transactionRequest.value` when omitted.\n */\n readonly value?: bigint | string;\n}\n\n/**\n * Assembles a {@link SimulateRequest} from a compile result and the\n * caller-supplied chain, signer, and tracked balances. Pure: performs no\n * network I/O, does not mutate its input, and returns a fresh object.\n *\n * Bridges the common case — simulate the transaction you just compiled —\n * without coupling raw-transaction simulation to the flow builder. The\n * `value` defaults to the compiled transaction's value unless overridden.\n *\n * @example\n * ```ts\n * const compiled = await builder.compile({ inputs: { ... }, signer: '0x1111...' });\n * const req = buildSimulateRequest({\n * result: compiled,\n * chainId: 1,\n * signer: '0x1111111111111111111111111111111111111111',\n * trackedBalances: [{ token: '0xA0b8...', owner: '0x1111...' }],\n * });\n * const sim = await sdk.client.simulate(req);\n * ```\n */\nexport const buildSimulateRequest = (\n input: BuildSimulateRequestInput,\n): SimulateRequest => {\n const { result, chainId, signer, trackedBalances, requirements, block } =\n input;\n // A settle-only flow authored with `funding: 'external'` compiles to an\n // empty program: the success response carries no `transactionRequest`, so\n // there is nothing to simulate — the required submissions are the\n // `actions` entries, submitted directly.\n if (result.transactionRequest === undefined) {\n throw new Error(\n 'buildSimulateRequest: the compile result has no transactionRequest (empty compiled program — a settle-only external-funding flow); submit the `actions` entries instead of simulating',\n );\n }\n return {\n chainId,\n from: signer,\n to: result.transactionRequest.to,\n data: result.transactionRequest.data,\n value: input.value ?? result.transactionRequest.value,\n block,\n requirements,\n trackedBalances,\n };\n};\n"],"mappings":"AAiEO,MAAM,uBAAuB,CAClC,UACoB;AACpB,QAAM,EAAE,QAAQ,SAAS,QAAQ,iBAAiB,cAAc,MAAM,IACpE;AAKF,MAAI,OAAO,uBAAuB,QAAW;AAC3C,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AAAA,IACL;AAAA,IACA,MAAM;AAAA,IACN,IAAI,OAAO,mBAAmB;AAAA,IAC9B,MAAM,OAAO,mBAAmB;AAAA,IAChC,OAAO,MAAM,SAAS,OAAO,mBAAmB;AAAA,IAChD;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
package/dist/sdk.cjs CHANGED
@@ -39,6 +39,7 @@ const createComposeSdk = (options) => {
39
39
  maxPriceImpactBps: run.maxPriceImpactBps,
40
40
  sweepTo: run.sweepTo,
41
41
  simulationPolicy: run.simulationPolicy,
42
+ simulateUserProgram: run.simulateUserProgram,
42
43
  checkOnChainAllowances: run.checkOnChainAllowances
43
44
  })
44
45
  });
@@ -55,6 +56,7 @@ const createComposeSdk = (options) => {
55
56
  return {
56
57
  client: composeClient,
57
58
  flow,
59
+ getSupportedChains: composeClient.getChains,
58
60
  request,
59
61
  route: composeClient.route,
60
62
  simulate: composeClient.simulate
package/dist/sdk.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/sdk.ts"],"sourcesContent":["import type {\n ComposeCompileRequest,\n ComposeCompileResult,\n ComposeRouteRequest,\n InputSpec,\n SimulateRequest,\n SimulateResult,\n} from '@lifi/compose-spec';\n\nimport {\n createFlowBuilderCore,\n type FlowBuilderCore,\n type FlowOptions,\n type TypedFlow,\n} from './authoring/FlowBuilderCore.js';\nimport { type ComposeClient, createComposeClient } from './client.js';\nimport {\n bindGeneratedOps,\n type GeneratedOps,\n} from './generated/operations.generated.js';\nimport { buildRun, type ComposeRunInput } from './run/inputs.js';\nimport type { InputSchema } from './types.js';\n\nexport type { ComposeRunInput };\n\n/**\n * A flow builder augmented with generated operation methods and a `compile` method\n * that submits the flow to the Compose backend for compilation.\n *\n * Created via {@link ComposeSdk.flow}.\n *\n * @typeParam T - The input schema describing the flow's required inputs.\n */\nexport type FlowBuilder<T extends InputSchema = InputSchema> =\n FlowBuilderCore<T> &\n GeneratedOps & {\n /**\n * Builds the flow document from the current builder state and submits it\n * to the Compose API for compilation.\n *\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns The compiled transaction calldata and metadata.\n * @throws {@link ComposeError} on network, validation, or server errors.\n *\n * @example\n * ```ts\n * const result = await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * console.log(result.calldata);\n * ```\n */\n readonly compile: (\n run: ComposeRunInput<T>,\n ) => Promise<ComposeCompileResult>;\n };\n\n/**\n * Configuration for creating a Compose SDK instance.\n */\nexport interface ComposeSdkOptions {\n /** Base URL of the Compose API (e.g. `\"https://li.quest\"`). */\n readonly baseUrl: string;\n /** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */\n readonly fetch?: typeof globalThis.fetch;\n /** LI.FI API key, sent as the `x-lifi-api-key` header on every request. Required — the Compose API rejects unauthenticated requests. */\n readonly apiKey: string;\n}\n\n/**\n * The top-level Compose SDK interface.\n *\n * Provides methods to build flows, compile them into executable calldata, and\n * interact with the Compose API directly.\n *\n * @example\n * ```ts\n * import { createComposeSdk, resources, materialisers } from '@lifi/composer-sdk';\n *\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n *\n * const builder = sdk.flow(1, {\n * inputs: { usdc: resources.erc20('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 1) },\n * });\n *\n * builder.lifi.swap('swap1', {\n * bind: { amountIn: builder.inputs.usdc },\n * config: { resourceOut: resources.native(1) },\n * });\n *\n * const result = await builder.compile({\n * inputs: { usdc: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * ```\n */\nexport interface ComposeSdk {\n /** Low-level HTTP client for the Compose API. */\n readonly client: ComposeClient;\n /**\n * Creates a new flow builder targeting the given chain.\n * @param chainId - The EVM chain ID (e.g. `1` for Ethereum mainnet).\n * @param options - Flow configuration including input declarations.\n * @returns A {@link FlowBuilder} with generated operation methods and a `compile` method.\n * @throws Error if any resource input's `chainId` doesn't match the flow's `chainId`.\n */\n readonly flow: <T extends InputSchema>(\n chainId: number,\n options: FlowOptions<T>,\n ) => FlowBuilder<T>;\n /**\n * Builds a raw compile request without sending it. Useful for inspecting the\n * request payload or submitting it through a custom transport.\n * @param flow - A built flow document (from `builder.build()`).\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns A {@link ComposeCompileRequest} ready to send to the Compose API.\n */\n readonly request: <T extends InputSchema>(\n flow: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ) => ComposeCompileRequest;\n /**\n * Compiles a token pair on one chain — as of today a single zap step over\n * one routing-catalog edge. Thin pass-through to\n * {@link ComposeClient.route}; see it for the current single-step limit,\n * when to prefer `flow(...).compile(...)`, the `success` / `partial`\n * discrimination, and error behaviour. Build the `amount` with\n * `routeAmount.exact(...)` / `routeAmount.all(...)`.\n *\n * @param request - The from/to token pair, amount, signer, and route options.\n * @returns A discriminated result: `status: 'success'` or `status: 'partial'`.\n * @throws {@link ComposeError} on network, validation, or server errors.\n */\n readonly route: (\n request: ComposeRouteRequest,\n ) => Promise<ComposeCompileResult>;\n /**\n * Simulates a raw, pre-encoded transaction. Thin pass-through to\n * {@link ComposeClient.simulate}; see it for the `ok` / `revert` / `error`\n * result discrimination and error behaviour. Pair with `buildSimulateRequest`\n * to assemble the request from a compile result.\n *\n * @param request - The raw transaction plus funding `requirements` and\n * `trackedBalances`.\n * @returns A {@link SimulateResult} (`ok` / `revert` / `error`).\n * @throws {@link ComposeError} on network, validation, or server errors.\n */\n readonly simulate: (request: SimulateRequest) => Promise<SimulateResult>;\n}\n\n/**\n * Creates a new Compose SDK instance.\n *\n * @param options - SDK configuration including the API base URL, required API key, and optional fetch implementation.\n * @returns A {@link ComposeSdk} instance.\n *\n * @example\n * ```ts\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n * ```\n */\nexport const createComposeSdk = (options: ComposeSdkOptions): ComposeSdk => {\n const composeClient = createComposeClient(options);\n\n const request = <T extends InputSchema>(\n flowDoc: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ): ComposeCompileRequest => ({\n flow: flowDoc,\n run: buildRun({\n inputs: run.inputs as Record<string, InputSpec>,\n preconditions: run.preconditions,\n signer: run.signer,\n assumptions: run.assumptions as Record<string, bigint> | undefined,\n referrer: run.referrer,\n integratorFeeBps: run.integratorFeeBps,\n maxPriceImpactBps: run.maxPriceImpactBps,\n sweepTo: run.sweepTo,\n simulationPolicy: run.simulationPolicy,\n checkOnChainAllowances: run.checkOnChainAllowances,\n }),\n });\n\n const flow = <T extends InputSchema>(\n chainId: number,\n opts: FlowOptions<T>,\n ): FlowBuilder<T> => {\n const core = createFlowBuilderCore(chainId, opts);\n const builder = Object.assign(core, bindGeneratedOps(core));\n\n const compile = async (\n run: ComposeRunInput<T>,\n ): Promise<ComposeCompileResult> => {\n const flowDoc = builder.build();\n const req = request(flowDoc, run);\n return composeClient.compile(req);\n };\n\n return Object.assign(builder, { compile });\n };\n\n return {\n client: composeClient,\n flow,\n request,\n route: composeClient.route,\n simulate: composeClient.simulate,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,6BAKO;AACP,oBAAwD;AACxD,kCAGO;AACP,oBAA+C;AA8IxC,MAAM,mBAAmB,CAAC,YAA2C;AAC1E,QAAM,oBAAgB,mCAAoB,OAAO;AAEjD,QAAM,UAAU,CACd,SACA,SAC2B;AAAA,IAC3B,MAAM;AAAA,IACN,SAAK,wBAAS;AAAA,MACZ,QAAQ,IAAI;AAAA,MACZ,eAAe,IAAI;AAAA,MACnB,QAAQ,IAAI;AAAA,MACZ,aAAa,IAAI;AAAA,MACjB,UAAU,IAAI;AAAA,MACd,kBAAkB,IAAI;AAAA,MACtB,mBAAmB,IAAI;AAAA,MACvB,SAAS,IAAI;AAAA,MACb,kBAAkB,IAAI;AAAA,MACtB,wBAAwB,IAAI;AAAA,IAC9B,CAAC;AAAA,EACH;AAEA,QAAM,OAAO,CACX,SACA,SACmB;AACnB,UAAM,WAAO,8CAAsB,SAAS,IAAI;AAChD,UAAM,UAAU,OAAO,OAAO,UAAM,8CAAiB,IAAI,CAAC;AAE1D,UAAM,UAAU,OACd,QACkC;AAClC,YAAM,UAAU,QAAQ,MAAM;AAC9B,YAAM,MAAM,QAAQ,SAAS,GAAG;AAChC,aAAO,cAAc,QAAQ,GAAG;AAAA,IAClC;AAEA,WAAO,OAAO,OAAO,SAAS,EAAE,QAAQ,CAAC;AAAA,EAC3C;AAEA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA,OAAO,cAAc;AAAA,IACrB,UAAU,cAAc;AAAA,EAC1B;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/sdk.ts"],"sourcesContent":["import type {\n ComposeCompileRequest,\n ComposeCompileResult,\n ComposeRouteRequest,\n InputSpec,\n SimulateRequest,\n SimulateResult,\n} from '@lifi/compose-spec';\n\nimport {\n createFlowBuilderCore,\n type FlowBuilderCore,\n type FlowOptions,\n type TypedFlow,\n} from './authoring/FlowBuilderCore.js';\nimport { type ComposeClient, createComposeClient } from './client.js';\nimport type { ChainSummary } from './discovery.js';\nimport {\n bindGeneratedOps,\n type GeneratedOps,\n} from './generated/operations.generated.js';\nimport { buildRun, type ComposeRunInput } from './run/inputs.js';\nimport type { InputSchema } from './types.js';\n\nexport type { ComposeRunInput };\n\n/**\n * A flow builder augmented with generated operation methods and a `compile` method\n * that submits the flow to the Compose backend for compilation.\n *\n * Created via {@link ComposeSdk.flow}.\n *\n * @typeParam T - The input schema describing the flow's required inputs.\n */\nexport type FlowBuilder<T extends InputSchema = InputSchema> =\n FlowBuilderCore<T> &\n GeneratedOps & {\n /**\n * Builds the flow document from the current builder state and submits it\n * to the Compose API for compilation.\n *\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns The compiled transaction calldata and metadata.\n * @throws {@link ComposeError} on network, validation, or server errors.\n *\n * @example\n * ```ts\n * const result = await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * console.log(result.calldata);\n * ```\n */\n readonly compile: (\n run: ComposeRunInput<T>,\n ) => Promise<ComposeCompileResult>;\n };\n\n/**\n * Configuration for creating a Compose SDK instance.\n */\nexport interface ComposeSdkOptions {\n /** Base URL of the Compose API (e.g. `\"https://li.quest\"`). */\n readonly baseUrl: string;\n /** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */\n readonly fetch?: typeof globalThis.fetch;\n /** LI.FI API key, sent as the `x-lifi-api-key` header on every request. Required — the Compose API rejects unauthenticated requests. */\n readonly apiKey: string;\n}\n\n/**\n * The top-level Compose SDK interface.\n *\n * Provides methods to build flows, compile them into executable calldata, and\n * interact with the Compose API directly.\n *\n * @example\n * ```ts\n * import { createComposeSdk, resources, materialisers } from '@lifi/composer-sdk';\n *\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n *\n * const builder = sdk.flow(1, {\n * inputs: { usdc: resources.erc20('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 1) },\n * });\n *\n * builder.lifi.swap('swap1', {\n * bind: { amountIn: builder.inputs.usdc },\n * config: { resourceOut: resources.native(1) },\n * });\n *\n * const result = await builder.compile({\n * inputs: { usdc: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * ```\n */\nexport interface ComposeSdk {\n /** Low-level HTTP client for the Compose API. */\n readonly client: ComposeClient;\n /**\n * Creates a new flow builder targeting the given chain.\n * @param chainId - The EVM chain ID (e.g. `1` for Ethereum mainnet).\n * @param options - Flow configuration including input declarations.\n * @returns A {@link FlowBuilder} with generated operation methods and a `compile` method.\n * @throws Error if any resource input's `chainId` doesn't match the flow's `chainId`.\n */\n readonly flow: <T extends InputSchema>(\n chainId: number,\n options: FlowOptions<T>,\n ) => FlowBuilder<T>;\n /**\n * Fetches the chains this Compose deployment supports, ascending by\n * `chainId`. Thin pass-through to {@link ComposeClient.getChains}; see it\n * for what \"supported\" means and for the caching caveat.\n *\n * Each entry pairs the `chainId` with a display `name`, so one call both\n * gates a chain selector and labels it. Key on `chainId`; `name` is a\n * deployment-maintained label that can change.\n *\n * Use it to fail fast before building a flow for a chain the server would\n * reject.\n *\n * @returns The supported chains, ascending by `chainId`.\n * @throws {@link ComposeError} on network or server errors.\n *\n * @example\n * ```ts\n * const chains = await sdk.getSupportedChains();\n * if (!chains.some((c) => c.chainId === 8453)) {\n * throw new Error('Base is not supported');\n * }\n * for (const { chainId, name } of chains) {\n * console.log(`${name} (${chainId})`);\n * }\n * ```\n */\n readonly getSupportedChains: () => Promise<readonly ChainSummary[]>;\n /**\n * Builds a raw compile request without sending it. Useful for inspecting the\n * request payload or submitting it through a custom transport.\n * @param flow - A built flow document (from `builder.build()`).\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns A {@link ComposeCompileRequest} ready to send to the Compose API.\n */\n readonly request: <T extends InputSchema>(\n flow: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ) => ComposeCompileRequest;\n /**\n * Compiles a token pair on one chain — as of today a single zap step over\n * one routing-catalog edge. Thin pass-through to\n * {@link ComposeClient.route}; see it for the current single-step limit,\n * when to prefer `flow(...).compile(...)`, the `success` / `partial`\n * discrimination, and error behaviour. Build the `amount` with\n * `routeAmount.exact(...)` / `routeAmount.all(...)`.\n *\n * @param request - The from/to token pair, amount, signer, and route options.\n * @returns A discriminated result: `status: 'success'` or `status: 'partial'`.\n * @throws {@link ComposeError} on network, validation, or server errors.\n */\n readonly route: (\n request: ComposeRouteRequest,\n ) => Promise<ComposeCompileResult>;\n /**\n * Simulates a raw, pre-encoded transaction. Thin pass-through to\n * {@link ComposeClient.simulate}; see it for the `ok` / `revert` / `error`\n * result discrimination and error behaviour. Pair with `buildSimulateRequest`\n * to assemble the request from a compile result.\n *\n * @param request - The raw transaction plus funding `requirements` and\n * `trackedBalances`.\n * @returns A {@link SimulateResult} (`ok` / `revert` / `error`).\n * @throws {@link ComposeError} on network, validation, or server errors.\n */\n readonly simulate: (request: SimulateRequest) => Promise<SimulateResult>;\n}\n\n/**\n * Creates a new Compose SDK instance.\n *\n * @param options - SDK configuration including the API base URL, required API key, and optional fetch implementation.\n * @returns A {@link ComposeSdk} instance.\n *\n * @example\n * ```ts\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n * ```\n */\nexport const createComposeSdk = (options: ComposeSdkOptions): ComposeSdk => {\n const composeClient = createComposeClient(options);\n\n const request = <T extends InputSchema>(\n flowDoc: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ): ComposeCompileRequest => ({\n flow: flowDoc,\n run: buildRun({\n inputs: run.inputs as Record<string, InputSpec>,\n preconditions: run.preconditions,\n signer: run.signer,\n assumptions: run.assumptions as Record<string, bigint> | undefined,\n referrer: run.referrer,\n integratorFeeBps: run.integratorFeeBps,\n maxPriceImpactBps: run.maxPriceImpactBps,\n sweepTo: run.sweepTo,\n simulationPolicy: run.simulationPolicy,\n simulateUserProgram: run.simulateUserProgram,\n checkOnChainAllowances: run.checkOnChainAllowances,\n }),\n });\n\n const flow = <T extends InputSchema>(\n chainId: number,\n opts: FlowOptions<T>,\n ): FlowBuilder<T> => {\n const core = createFlowBuilderCore(chainId, opts);\n const builder = Object.assign(core, bindGeneratedOps(core));\n\n const compile = async (\n run: ComposeRunInput<T>,\n ): Promise<ComposeCompileResult> => {\n const flowDoc = builder.build();\n const req = request(flowDoc, run);\n return composeClient.compile(req);\n };\n\n return Object.assign(builder, { compile });\n };\n\n return {\n client: composeClient,\n flow,\n getSupportedChains: composeClient.getChains,\n request,\n route: composeClient.route,\n simulate: composeClient.simulate,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,6BAKO;AACP,oBAAwD;AAExD,kCAGO;AACP,oBAA+C;AAyKxC,MAAM,mBAAmB,CAAC,YAA2C;AAC1E,QAAM,oBAAgB,mCAAoB,OAAO;AAEjD,QAAM,UAAU,CACd,SACA,SAC2B;AAAA,IAC3B,MAAM;AAAA,IACN,SAAK,wBAAS;AAAA,MACZ,QAAQ,IAAI;AAAA,MACZ,eAAe,IAAI;AAAA,MACnB,QAAQ,IAAI;AAAA,MACZ,aAAa,IAAI;AAAA,MACjB,UAAU,IAAI;AAAA,MACd,kBAAkB,IAAI;AAAA,MACtB,mBAAmB,IAAI;AAAA,MACvB,SAAS,IAAI;AAAA,MACb,kBAAkB,IAAI;AAAA,MACtB,qBAAqB,IAAI;AAAA,MACzB,wBAAwB,IAAI;AAAA,IAC9B,CAAC;AAAA,EACH;AAEA,QAAM,OAAO,CACX,SACA,SACmB;AACnB,UAAM,WAAO,8CAAsB,SAAS,IAAI;AAChD,UAAM,UAAU,OAAO,OAAO,UAAM,8CAAiB,IAAI,CAAC;AAE1D,UAAM,UAAU,OACd,QACkC;AAClC,YAAM,UAAU,QAAQ,MAAM;AAC9B,YAAM,MAAM,QAAQ,SAAS,GAAG;AAChC,aAAO,cAAc,QAAQ,GAAG;AAAA,IAClC;AAEA,WAAO,OAAO,OAAO,SAAS,EAAE,QAAQ,CAAC;AAAA,EAC3C;AAEA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR;AAAA,IACA,oBAAoB,cAAc;AAAA,IAClC;AAAA,IACA,OAAO,cAAc;AAAA,IACrB,UAAU,cAAc;AAAA,EAC1B;AACF;","names":[]}
package/dist/sdk.d.cts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { ComposeCompileResult, ComposeCompileRequest, ComposeRouteRequest, SimulateRequest, SimulateResult } from '@lifi/compose-spec';
2
2
  import { FlowOptions, FlowBuilderCore, TypedFlow } from './authoring/FlowBuilderCore.cjs';
3
3
  import { ComposeClient } from './client.cjs';
4
+ import { ChainSummary } from './discovery.cjs';
4
5
  import { GeneratedOps } from './generated/operations.generated.cjs';
5
6
  import { ComposeRunInput } from './run/inputs.cjs';
6
7
  import { InputSchema } from './types.cjs';
7
8
  import './authoring/handles.cjs';
8
- import './discovery.cjs';
9
9
  import './authoring/signatureArgs.cjs';
10
10
  import 'abitype';
11
11
  import './generated/config.generated.cjs';
@@ -87,6 +87,33 @@ interface ComposeSdk {
87
87
  * @throws Error if any resource input's `chainId` doesn't match the flow's `chainId`.
88
88
  */
89
89
  readonly flow: <T extends InputSchema>(chainId: number, options: FlowOptions<T>) => FlowBuilder<T>;
90
+ /**
91
+ * Fetches the chains this Compose deployment supports, ascending by
92
+ * `chainId`. Thin pass-through to {@link ComposeClient.getChains}; see it
93
+ * for what "supported" means and for the caching caveat.
94
+ *
95
+ * Each entry pairs the `chainId` with a display `name`, so one call both
96
+ * gates a chain selector and labels it. Key on `chainId`; `name` is a
97
+ * deployment-maintained label that can change.
98
+ *
99
+ * Use it to fail fast before building a flow for a chain the server would
100
+ * reject.
101
+ *
102
+ * @returns The supported chains, ascending by `chainId`.
103
+ * @throws {@link ComposeError} on network or server errors.
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * const chains = await sdk.getSupportedChains();
108
+ * if (!chains.some((c) => c.chainId === 8453)) {
109
+ * throw new Error('Base is not supported');
110
+ * }
111
+ * for (const { chainId, name } of chains) {
112
+ * console.log(`${name} (${chainId})`);
113
+ * }
114
+ * ```
115
+ */
116
+ readonly getSupportedChains: () => Promise<readonly ChainSummary[]>;
90
117
  /**
91
118
  * Builds a raw compile request without sending it. Useful for inspecting the
92
119
  * request payload or submitting it through a custom transport.
package/dist/sdk.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { ComposeCompileResult, ComposeCompileRequest, ComposeRouteRequest, SimulateRequest, SimulateResult } from '@lifi/compose-spec';
2
2
  import { FlowOptions, FlowBuilderCore, TypedFlow } from './authoring/FlowBuilderCore.js';
3
3
  import { ComposeClient } from './client.js';
4
+ import { ChainSummary } from './discovery.js';
4
5
  import { GeneratedOps } from './generated/operations.generated.js';
5
6
  import { ComposeRunInput } from './run/inputs.js';
6
7
  import { InputSchema } from './types.js';
7
8
  import './authoring/handles.js';
8
- import './discovery.js';
9
9
  import './authoring/signatureArgs.js';
10
10
  import 'abitype';
11
11
  import './generated/config.generated.js';
@@ -87,6 +87,33 @@ interface ComposeSdk {
87
87
  * @throws Error if any resource input's `chainId` doesn't match the flow's `chainId`.
88
88
  */
89
89
  readonly flow: <T extends InputSchema>(chainId: number, options: FlowOptions<T>) => FlowBuilder<T>;
90
+ /**
91
+ * Fetches the chains this Compose deployment supports, ascending by
92
+ * `chainId`. Thin pass-through to {@link ComposeClient.getChains}; see it
93
+ * for what "supported" means and for the caching caveat.
94
+ *
95
+ * Each entry pairs the `chainId` with a display `name`, so one call both
96
+ * gates a chain selector and labels it. Key on `chainId`; `name` is a
97
+ * deployment-maintained label that can change.
98
+ *
99
+ * Use it to fail fast before building a flow for a chain the server would
100
+ * reject.
101
+ *
102
+ * @returns The supported chains, ascending by `chainId`.
103
+ * @throws {@link ComposeError} on network or server errors.
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * const chains = await sdk.getSupportedChains();
108
+ * if (!chains.some((c) => c.chainId === 8453)) {
109
+ * throw new Error('Base is not supported');
110
+ * }
111
+ * for (const { chainId, name } of chains) {
112
+ * console.log(`${name} (${chainId})`);
113
+ * }
114
+ * ```
115
+ */
116
+ readonly getSupportedChains: () => Promise<readonly ChainSummary[]>;
90
117
  /**
91
118
  * Builds a raw compile request without sending it. Useful for inspecting the
92
119
  * request payload or submitting it through a custom transport.
package/dist/sdk.js CHANGED
@@ -20,6 +20,7 @@ const createComposeSdk = (options) => {
20
20
  maxPriceImpactBps: run.maxPriceImpactBps,
21
21
  sweepTo: run.sweepTo,
22
22
  simulationPolicy: run.simulationPolicy,
23
+ simulateUserProgram: run.simulateUserProgram,
23
24
  checkOnChainAllowances: run.checkOnChainAllowances
24
25
  })
25
26
  });
@@ -36,6 +37,7 @@ const createComposeSdk = (options) => {
36
37
  return {
37
38
  client: composeClient,
38
39
  flow,
40
+ getSupportedChains: composeClient.getChains,
39
41
  request,
40
42
  route: composeClient.route,
41
43
  simulate: composeClient.simulate