@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
@@ -12,8 +12,11 @@ import type {
12
12
  export interface BuildSimulateRequestInput {
13
13
  /**
14
14
  * A result from `builder.compile(...)` / `client.compile(...)`. Both
15
- * `success` and `partial` results carry a `transactionRequest`, so either is
16
- * valid input — the helper does not discriminate on `status`.
15
+ * `success` and `partial` results are valid input — the helper does not
16
+ * discriminate on `status`. A success result for an empty compiled program
17
+ * (a settle-only `funding: 'external'` flow) carries no
18
+ * `transactionRequest`; there is nothing to simulate and this helper
19
+ * throws — submit the result's `actions` entries directly instead.
17
20
  */
18
21
  readonly result: ComposeCompileResult;
19
22
  /** EVM chain id. A compile result does not carry the target chain. */
@@ -65,6 +68,15 @@ export const buildSimulateRequest = (
65
68
  ): SimulateRequest => {
66
69
  const { result, chainId, signer, trackedBalances, requirements, block } =
67
70
  input;
71
+ // A settle-only flow authored with `funding: 'external'` compiles to an
72
+ // empty program: the success response carries no `transactionRequest`, so
73
+ // there is nothing to simulate — the required submissions are the
74
+ // `actions` entries, submitted directly.
75
+ if (result.transactionRequest === undefined) {
76
+ throw new Error(
77
+ 'buildSimulateRequest: the compile result has no transactionRequest (empty compiled program — a settle-only external-funding flow); submit the `actions` entries instead of simulating',
78
+ );
79
+ }
68
80
  return {
69
81
  chainId,
70
82
  from: signer,
package/src/sdk.ts CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  type TypedFlow,
15
15
  } from './authoring/FlowBuilderCore.js';
16
16
  import { type ComposeClient, createComposeClient } from './client.js';
17
+ import type { ChainSummary } from './discovery.js';
17
18
  import {
18
19
  bindGeneratedOps,
19
20
  type GeneratedOps,
@@ -109,6 +110,33 @@ export interface ComposeSdk {
109
110
  chainId: number,
110
111
  options: FlowOptions<T>,
111
112
  ) => FlowBuilder<T>;
113
+ /**
114
+ * Fetches the chains this Compose deployment supports, ascending by
115
+ * `chainId`. Thin pass-through to {@link ComposeClient.getChains}; see it
116
+ * for what "supported" means and for the caching caveat.
117
+ *
118
+ * Each entry pairs the `chainId` with a display `name`, so one call both
119
+ * gates a chain selector and labels it. Key on `chainId`; `name` is a
120
+ * deployment-maintained label that can change.
121
+ *
122
+ * Use it to fail fast before building a flow for a chain the server would
123
+ * reject.
124
+ *
125
+ * @returns The supported chains, ascending by `chainId`.
126
+ * @throws {@link ComposeError} on network or server errors.
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * const chains = await sdk.getSupportedChains();
131
+ * if (!chains.some((c) => c.chainId === 8453)) {
132
+ * throw new Error('Base is not supported');
133
+ * }
134
+ * for (const { chainId, name } of chains) {
135
+ * console.log(`${name} (${chainId})`);
136
+ * }
137
+ * ```
138
+ */
139
+ readonly getSupportedChains: () => Promise<readonly ChainSummary[]>;
112
140
  /**
113
141
  * Builds a raw compile request without sending it. Useful for inspecting the
114
142
  * request payload or submitting it through a custom transport.
@@ -178,6 +206,7 @@ export const createComposeSdk = (options: ComposeSdkOptions): ComposeSdk => {
178
206
  maxPriceImpactBps: run.maxPriceImpactBps,
179
207
  sweepTo: run.sweepTo,
180
208
  simulationPolicy: run.simulationPolicy,
209
+ simulateUserProgram: run.simulateUserProgram,
181
210
  checkOnChainAllowances: run.checkOnChainAllowances,
182
211
  }),
183
212
  });
@@ -203,6 +232,7 @@ export const createComposeSdk = (options: ComposeSdkOptions): ComposeSdk => {
203
232
  return {
204
233
  client: composeClient,
205
234
  flow,
235
+ getSupportedChains: composeClient.getChains,
206
236
  request,
207
237
  route: composeClient.route,
208
238
  simulate: composeClient.simulate,
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Ref } from '@lifi/compose-spec';
1
+ import type { LiteralBinding, Ref } from '@lifi/compose-spec';
2
2
  import {
3
3
  InputSpec,
4
4
  MaterialiserInput,
@@ -58,6 +58,25 @@ export interface TypedRef<T extends OutputKind = OutputKind> extends Ref {
58
58
  readonly __outputKind?: T;
59
59
  }
60
60
 
61
+ /**
62
+ * A literal bind value carrying a phantom type parameter.
63
+ *
64
+ * The wire format accepts a constant in a bind slot as
65
+ * `{ kind: <solType>, value: <string> }`, alongside `$ref` pointers. Use it
66
+ * for a value that must be baked into the flow document rather than supplied
67
+ * at run time — the destination of a flow the backend stores and re-runs
68
+ * later (a `continuation.settle` node's `continuationFlow`) has no run to
69
+ * take an input from.
70
+ *
71
+ * @typeParam T - The Solidity type of the literal (e.g. `'address'`).
72
+ */
73
+ export interface TypedLiteral<
74
+ T extends SolType = SolType,
75
+ > extends LiteralBinding {
76
+ readonly kind: T;
77
+ readonly __outputKind?: T;
78
+ }
79
+
61
80
  /**
62
81
  * An input declaration in a flow schema.
63
82
  * `Resource` values become resource inputs (token amounts);