@lifi/compose-spec 0.4.0 → 0.4.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.
package/dist/index.d.ts CHANGED
@@ -789,7 +789,7 @@ type Resource = {
789
789
  };
790
790
  type SimulatedAmounts = {
791
791
  readonly amountOut: bigint;
792
- readonly amountOutMin: bigint;
792
+ readonly amountOutMin?: bigint;
793
793
  };
794
794
  type ProducedResource = Resource & {
795
795
  readonly availability: Availability;
@@ -879,6 +879,7 @@ declare const HandlePortZod: z.ZodObject<{
879
879
  bps: "bps";
880
880
  "token-decimals": "token-decimals";
881
881
  }>>;
882
+ optional: z.ZodOptional<z.ZodBoolean>;
882
883
  }, z.core.$strip>;
883
884
  declare const InputPortZod: z.ZodDiscriminatedUnion<[z.ZodObject<{
884
885
  kind: z.ZodLiteral<"resource">;
@@ -924,6 +925,7 @@ declare const InputPortZod: z.ZodDiscriminatedUnion<[z.ZodObject<{
924
925
  bps: "bps";
925
926
  "token-decimals": "token-decimals";
926
927
  }>>;
928
+ optional: z.ZodOptional<z.ZodBoolean>;
927
929
  }, z.core.$strip>], "kind">;
928
930
  declare const ResourceOutputPortZod: z.ZodObject<{
929
931
  kind: z.ZodLiteral<"resource_output">;
@@ -985,6 +987,7 @@ declare const OutputPortZod: z.ZodDiscriminatedUnion<[z.ZodObject<{
985
987
  bps: "bps";
986
988
  "token-decimals": "token-decimals";
987
989
  }>>;
990
+ optional: z.ZodOptional<z.ZodBoolean>;
988
991
  }, z.core.$strip>], "kind">;
989
992
  declare const ManifestOperationZod: z.ZodObject<{
990
993
  id: z.ZodString;
@@ -1033,6 +1036,7 @@ declare const ManifestOperationZod: z.ZodObject<{
1033
1036
  bps: "bps";
1034
1037
  "token-decimals": "token-decimals";
1035
1038
  }>>;
1039
+ optional: z.ZodOptional<z.ZodBoolean>;
1036
1040
  }, z.core.$strip>], "kind">>;
1037
1041
  outputs: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
1038
1042
  kind: z.ZodLiteral<"resource_output">;
@@ -1079,6 +1083,7 @@ declare const ManifestOperationZod: z.ZodObject<{
1079
1083
  bps: "bps";
1080
1084
  "token-decimals": "token-decimals";
1081
1085
  }>>;
1086
+ optional: z.ZodOptional<z.ZodBoolean>;
1082
1087
  }, z.core.$strip>], "kind">>;
1083
1088
  configSchema: z.ZodOptional<z.ZodUnknown>;
1084
1089
  }, z.core.$strip>;
@@ -1268,6 +1273,7 @@ declare const ComposeManifestZod: z.ZodObject<{
1268
1273
  bps: "bps";
1269
1274
  "token-decimals": "token-decimals";
1270
1275
  }>>;
1276
+ optional: z.ZodOptional<z.ZodBoolean>;
1271
1277
  }, z.core.$strip>], "kind">>;
1272
1278
  outputs: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
1273
1279
  kind: z.ZodLiteral<"resource_output">;
@@ -1314,6 +1320,7 @@ declare const ComposeManifestZod: z.ZodObject<{
1314
1320
  bps: "bps";
1315
1321
  "token-decimals": "token-decimals";
1316
1322
  }>>;
1323
+ optional: z.ZodOptional<z.ZodBoolean>;
1317
1324
  }, z.core.$strip>], "kind">>;
1318
1325
  configSchema: z.ZodOptional<z.ZodUnknown>;
1319
1326
  }, z.core.$strip>>;
@@ -1893,7 +1900,8 @@ declare const flowInputResource: (input: FlowInput) => Resource | undefined;
1893
1900
  declare const isResourcePort: (port: OpInputPort) => port is ResourcePort;
1894
1901
  declare const isHandlePort: (port: OpInputPort | OpOutputPort) => port is HandlePort;
1895
1902
  declare const isResourceOutputPort: (port: OpInputPort | OpOutputPort) => port is ResourceOutputPort;
1896
- type ComposeErrorKind = 'decode_error' | 'validation_error' | 'linearity_error' | 'resolve_error' | 'preparation_error' | 'provider_error' | 'no_route_error' | 'resolution_error' | 'lowering_error' | 'empty_program' | 'simulation_error' | 'simulation_setup_error' | 'simulation_rpc_error' | 'simulation_revert' | 'subgraph_simulation_revert' | 'guard_error' | 'continuation_error' | 'compilation_error' | 'verification_error' | 'price_impact_exceeded' | 'fee_resolution_error' | 'fee_resolution_unavailable' | 'flashloan_unauthorized';
1903
+ declare const isFutureResourceOutput: (port: OpInputPort | OpOutputPort) => boolean;
1904
+ type ComposeErrorKind = 'decode_error' | 'validation_error' | 'linearity_error' | 'resolve_error' | 'preparation_error' | 'provider_error' | 'no_route_error' | 'resolution_error' | 'resolution_rejected' | 'lowering_error' | 'empty_program' | 'simulation_error' | 'simulation_setup_error' | 'simulation_insufficient_funds' | 'simulation_gas_limit' | 'simulation_rpc_error' | 'simulation_revert' | 'subgraph_simulation_revert' | 'guard_error' | 'continuation_error' | 'compilation_error' | 'verification_error' | 'price_impact_exceeded' | 'fee_resolution_error' | 'fee_resolution_unavailable' | 'flashloan_unauthorized' | 'deadline_exceeded';
1897
1905
  type GenericComposeErrorKind = Exclude<ComposeErrorKind, 'preparation_error' | 'simulation_revert'>;
1898
1906
  interface FailedPreparedOp {
1899
1907
  readonly callId: string;
@@ -1950,9 +1958,10 @@ interface FlashloanMaterialiserInput {
1950
1958
  readonly amount: string;
1951
1959
  }
1952
1960
 
1953
- interface OpHandleOptions {
1961
+ interface OpHandleOptions<Opt extends boolean = boolean> {
1954
1962
  readonly expose?: boolean;
1955
1963
  readonly units?: HandleUnits;
1964
+ readonly optional?: Opt;
1956
1965
  }
1957
1966
  declare const inputRef: (port: string) => Ref;
1958
1967
  declare const outputRef: (node: string, port: string) => Ref;
@@ -1977,26 +1986,32 @@ declare const erc20: <N extends string>(name: N, token: string, chainId: number)
1977
1986
  readonly name: N;
1978
1987
  };
1979
1988
  declare const resource: <N extends string, Opt extends boolean = false>(name: N, accepts: "erc20" | "native" | "any", options?: {
1980
- optional?: Opt;
1989
+ readonly optional?: Opt;
1981
1990
  }) => ResourcePort & {
1982
1991
  readonly name: N;
1983
- readonly optional: Opt;
1992
+ readonly optional: NoInfer<Opt>;
1984
1993
  };
1985
1994
  declare const readResource: <N extends string>(name: N, accepts: "erc20" | "native" | "any") => ResourcePort & {
1986
1995
  readonly name: N;
1987
1996
  readonly mode: "copy";
1988
1997
  };
1989
- declare const opHandle: <N extends string, T extends SolType>(name: N, type: T, options?: OpHandleOptions) => HandlePort & {
1998
+ declare const opHandle: <N extends string, T extends SolType, Opt extends boolean = false>(name: N, type: T, options?: OpHandleOptions<Opt>) => HandlePort & {
1990
1999
  readonly name: N;
1991
2000
  readonly type: T;
2001
+ readonly optional: NoInfer<Opt>;
2002
+ };
2003
+ type ResourceOutputOptions = Availability | {
2004
+ readonly availability?: Availability;
2005
+ readonly providesMinimum?: boolean;
2006
+ readonly omitIfZero?: boolean;
2007
+ readonly deliveryAddressInput?: string;
1992
2008
  };
1993
- declare const resourceOutput: <N extends string>(name: N, options?: Availability | {
1994
- availability?: Availability;
1995
- providesMinimum?: boolean;
1996
- omitIfZero?: boolean;
1997
- deliveryAddressInput?: string;
1998
- }) => ResourceOutputPort & {
2009
+ type OutputAvailability<O> = [O] extends ['future'] ? 'future' : [O] extends ['now'] ? 'now' : [O] extends [string] ? Availability : O extends {
2010
+ readonly availability: infer A;
2011
+ } ? [A] extends ['future'] ? 'future' : [A] extends ['now'] ? 'now' : Availability : 'now';
2012
+ declare const resourceOutput: <N extends string, const O extends ResourceOutputOptions = "now">(name: N, options?: O) => ResourceOutputPort & {
1999
2013
  readonly name: N;
2014
+ readonly availability: OutputAvailability<O>;
2000
2015
  };
2001
2016
 
2002
2017
  type ParsedRef = {
@@ -2133,6 +2148,162 @@ declare const normalizeResource: (r: Resource) => Resource;
2133
2148
  */
2134
2149
  declare const normalizeNativeTokenAddress: (token: string, chainId: number) => string;
2135
2150
 
2151
+ /**
2152
+ * Canonical request types for the `POST /compose/route` convenience endpoint.
2153
+ * Amounts accept `bigint | string` for authoring convenience; the JSON wire
2154
+ * format is always a decimal string, which the SDK serialises for you.
2155
+ *
2156
+ * `/compose/route` trades authoring power for brevity. Instead of a full flow
2157
+ * document it takes a single from/to token pair; the server builds a
2158
+ * `lifi.zap` flow with a `directDeposit` input on the caller's behalf and runs
2159
+ * it through the same compile pipeline as `POST /compose`. As of today the flow
2160
+ * it builds is a single zap step — one edge of the server's routing catalog —
2161
+ * and it is meant to author richer flows later, which this request shape is
2162
+ * deliberately agnostic about. Its response body is byte-identical to that of
2163
+ * `POST /compose` — the enveloped `ComposeCompileSuccessData` on HTTP 200 and
2164
+ * `ComposeCompilePartialData` on HTTP 206 — so this file declares only the
2165
+ * request shape and reuses `ComposeCompileResult` from `./compile.js` for the
2166
+ * result.
2167
+ *
2168
+ * These are the single source of truth for the request shape, hand-authored
2169
+ * here for the same reason as `./compile.ts` and `./simulate.ts` rather than
2170
+ * derived from the validating schema: that schema is the Zod one in
2171
+ * `@lifi/api-schemas` (`src/routes/composeRoute.ts`), a package that depends on
2172
+ * this one, so importing its inferred types here would invert the dependency —
2173
+ * and the public SDK ships this package as its only peer dependency, never the
2174
+ * server's schema package. The two definitions are held in lockstep by a
2175
+ * compile-time conformance assertion
2176
+ * (`api-schemas/src/routes/composeRoute.typecheck.ts`), which fails the build
2177
+ * if either side drifts.
2178
+ */
2179
+
2180
+ /**
2181
+ * Spend an exact amount of `fromToken`.
2182
+ *
2183
+ * `amount` is in the token's smallest unit. Accepts `bigint | string`; the wire
2184
+ * format is a non-negative decimal string.
2185
+ */
2186
+ interface RouteAmountExact {
2187
+ readonly type: 'EXACT';
2188
+ readonly amount: bigint | string;
2189
+ }
2190
+ /**
2191
+ * Spend the signer's entire `fromToken` balance, whatever it is at execution
2192
+ * time.
2193
+ *
2194
+ * The on-chain amount is resolved by a deposit-all materialiser, so it is not
2195
+ * known when the route is compiled. `simAmount` is the stand-in the server
2196
+ * quotes and simulates against — make it a realistic estimate of the balance,
2197
+ * because it determines the quote and the derived preconditions, not the amount
2198
+ * actually moved. Accepts `bigint | string`; the wire format is a non-negative
2199
+ * decimal string.
2200
+ *
2201
+ * Not supported when `fromToken` is the chain's native sentinel: a gas coin
2202
+ * arrives via `msg.value`, so there is no on-chain balance to sweep, and the
2203
+ * server rejects the combination with a `validation_error`. Use
2204
+ * {@link RouteAmountExact} for native inputs.
2205
+ */
2206
+ interface RouteAmountAll {
2207
+ readonly type: 'ALL';
2208
+ readonly simAmount: bigint | string;
2209
+ }
2210
+ /**
2211
+ * How much of `fromToken` a route spends. Two variants, discriminated by
2212
+ * `type`.
2213
+ */
2214
+ type RouteAmount = RouteAmountExact | RouteAmountAll;
2215
+ /** Request body for `POST /compose/route`. */
2216
+ interface ComposeRouteRequest {
2217
+ /** EVM chain id. Both tokens must live on this chain — routes are same-chain. */
2218
+ readonly chainId: number;
2219
+ /**
2220
+ * Token to spend. Use the chain's native sentinel address for the gas coin
2221
+ * (the zero address on EVM-native chains).
2222
+ */
2223
+ readonly fromToken: string;
2224
+ /** Token to receive. */
2225
+ readonly toToken: string;
2226
+ /** How much of `fromToken` to spend — an exact amount or the whole balance. */
2227
+ readonly amount: RouteAmount;
2228
+ /** Address that funds the route and, by default, owns its output. */
2229
+ readonly signer: string;
2230
+ /**
2231
+ * Slippage tolerance in basis points, applied as a guard on the route's
2232
+ * output. Range 0–10000. Defaults to `100` (1%) server-side when omitted.
2233
+ */
2234
+ readonly slippageBps?: number;
2235
+ /**
2236
+ * Reject the route when its quoted price impact exceeds this many basis
2237
+ * points. Range 0–10000. Omitted ⇒ no price-impact guard is installed.
2238
+ */
2239
+ readonly maxPriceImpactBps?: number;
2240
+ /**
2241
+ * Integrator fee in basis points, taken from the input amount. Range 0–9000.
2242
+ * Defaults to `0` server-side when omitted. A non-zero value requires an
2243
+ * integration-scoped API key; the server rejects it otherwise.
2244
+ */
2245
+ readonly integratorFeeBps?: number;
2246
+ /** Opaque referrer tag forwarded to the underlying quote provider. */
2247
+ readonly referrer?: string;
2248
+ /**
2249
+ * Owner of the route's output; defaults to `signer`. Routes whose protocol
2250
+ * mints to a named receiver (surfaced as `recipient: 'required'` by
2251
+ * `GET /compose/zap-packs`) bind this address at mint time rather than
2252
+ * transferring afterwards. Accepts an address or `{ $ref: 'context.sender' }`;
2253
+ * `{ $ref: 'context.executionAddress' }` is rejected.
2254
+ */
2255
+ readonly sweepTo?: SweepTo;
2256
+ /**
2257
+ * `'strict'` (the default) fails the request when simulation detects a
2258
+ * revert; `'allow-revert'` returns a partial result with revert diagnostics
2259
+ * instead.
2260
+ */
2261
+ readonly simulationPolicy?: SimulationPolicy;
2262
+ /**
2263
+ * Also simulate the final user-facing transaction after the structured
2264
+ * simulation succeeds. Reverts honour `simulationPolicy`. Defaults to `false`.
2265
+ */
2266
+ readonly simulateUserProgram?: boolean;
2267
+ /**
2268
+ * Filter the returned `approvals` against current on-chain allowances,
2269
+ * omitting approvals that are already sufficient. Defaults to `false`.
2270
+ */
2271
+ readonly checkOnChainAllowances?: boolean;
2272
+ }
2273
+
2274
+ /**
2275
+ * The three concrete precondition shapes the stack exchanges today. One
2276
+ * definition serves every producer and consumer: op/materialiser declarations,
2277
+ * `rewritePreconditions`, the simulator's funding requirements (`simulate.ts`
2278
+ * aliases these as `*Requirement`), and the zap-backend approval derivation.
2279
+ *
2280
+ * Amounts accept `bigint | string`: the SDK serialises `bigint` to a decimal
2281
+ * string; the string side covers values already stringified.
2282
+ */
2283
+ type Erc20BalancePrecondition = {
2284
+ readonly type: 'Erc20Balance';
2285
+ readonly wallet: string;
2286
+ readonly token: string;
2287
+ readonly balance: bigint | string;
2288
+ };
2289
+ type NativeBalancePrecondition = {
2290
+ readonly type: 'NativeBalance';
2291
+ readonly wallet: string;
2292
+ readonly balance: bigint | string;
2293
+ };
2294
+ type Erc20AllowancePrecondition = {
2295
+ readonly type: 'Erc20Allowance';
2296
+ readonly owner: string;
2297
+ readonly spender: string;
2298
+ readonly token: string;
2299
+ readonly allowance: bigint | string;
2300
+ };
2301
+ declare const erc20Balance: (config: Omit<Erc20BalancePrecondition, "type">) => Erc20BalancePrecondition;
2302
+ declare const nativeBalance: (config: Omit<NativeBalancePrecondition, "type">) => NativeBalancePrecondition;
2303
+ declare const erc20Allowance: (config: Omit<Erc20AllowancePrecondition, "type">) => Erc20AllowancePrecondition;
2304
+ declare const isErc20AllowancePrecondition: (p: Precondition) => p is Erc20AllowancePrecondition;
2305
+ declare const isNativeBalancePrecondition: (p: Precondition) => p is NativeBalancePrecondition;
2306
+
2136
2307
  /**
2137
2308
  * Canonical wire-format types for the standalone `POST /simulate` endpoint.
2138
2309
  *
@@ -2150,6 +2321,7 @@ declare const normalizeNativeTokenAddress: (token: string, chainId: number) => s
2150
2321
  *
2151
2322
  * Mirrors the hand-authored style of `src/compile.ts`.
2152
2323
  */
2324
+
2153
2325
  /**
2154
2326
  * Maximum number of watched `(token, owner)` pairs accepted by `POST /simulate`.
2155
2327
  *
@@ -2178,31 +2350,12 @@ interface TrackedBalance {
2178
2350
  /** Account whose balance of `token` is watched. */
2179
2351
  readonly owner: string;
2180
2352
  }
2181
- /**
2182
- * Funding instruction: seed an ERC-20 balance on a wallet before simulation.
2183
- * Amounts accept `bigint | string` — the SDK serialises `bigint` to a decimal
2184
- * string; the string side covers values already stringified.
2185
- */
2186
- interface Erc20BalanceRequirement {
2187
- readonly type: 'Erc20Balance';
2188
- readonly wallet: string;
2189
- readonly token: string;
2190
- readonly balance: bigint | string;
2191
- }
2353
+ /** Funding instruction: seed an ERC-20 balance on a wallet before simulation. */
2354
+ type Erc20BalanceRequirement = Erc20BalancePrecondition;
2192
2355
  /** Funding instruction: seed a native balance on a wallet before simulation. */
2193
- interface NativeBalanceRequirement {
2194
- readonly type: 'NativeBalance';
2195
- readonly wallet: string;
2196
- readonly balance: bigint | string;
2197
- }
2356
+ type NativeBalanceRequirement = NativeBalancePrecondition;
2198
2357
  /** Funding instruction: seed an ERC-20 allowance before simulation. */
2199
- interface Erc20AllowanceRequirement {
2200
- readonly type: 'Erc20Allowance';
2201
- readonly owner: string;
2202
- readonly spender: string;
2203
- readonly token: string;
2204
- readonly allowance: bigint | string;
2205
- }
2358
+ type Erc20AllowanceRequirement = Erc20AllowancePrecondition;
2206
2359
  /**
2207
2360
  * The funding-instruction union applied before a simulation. Three variants,
2208
2361
  * discriminated by `type`.
@@ -2318,4 +2471,4 @@ declare const foldMaterialiserMetadata: <R>(meta: MaterialiserMetadata, cases: {
2318
2471
  readonly runtime: () => R;
2319
2472
  }) => R;
2320
2473
 
2321
- export { type AppliedGuard, AppliedGuardSchema, type ApprovalEntry, AssertedErc20BalanceGteSpecSchema, AssertedNativeBalanceGteSpecSchema, type AssertedPredicate, AssertedPredicateSchema, type AssertedPredicateWire, AssertedPredicateZod, type AssertionOwner, AssertionOwnerSchema, type AssertionSpec, AssertionSpecSchema, type AssertionSpecWire, AssertionSpecZod, type Availability, type BindValue, BindValueSchema, Bytes32HexSchema, CONTINUATION_COMMITMENT_OP_ID, type Call, CallCheckSpecSchema, CallSchema, type ChainCapabilities, type Check, type CheckComparator, CheckSchema, CheckZod, type ComposeCompilePartialData, type ComposeCompileRequest, type ComposeCompileResult, type ComposeCompileSuccessData, type ComposeContinuation, type ComposeError, type ComposeErrorKind, type ComposeManifest, ComposeManifestZod, type ComposeRun, type ComposeTransactionRequest, type ContextKey, type Continuation, type ContinuationIntent, ContinuationIntentSchema, type ContinuationOutcome, ContinuationOutcomeSchema, type ContinuationPlan, ContinuationPlanSchema, type ContinuationPlanWire, ContinuationPlanZod, ContinuationSchema, EVM_NATIVE_SENTINEL, type Erc20AllowanceRequirement, Erc20BalanceDeltaGteSpecSchema, Erc20BalanceGteSpecSchema, type Erc20BalanceRequirement, type FailedPreparedOp, type FlashloanMaterialiserInput, type Flow, type FlowInput, FlowInputSchema, FlowSchema, type GenericComposeError, type GenericComposeErrorKind, type GuardCompatibility, GuardCompatibilityZod, type GuardSelector, GuardSelectorZod, HANDLE_UNITS, type HandleInput, HandleInputSchema, type HandlePort, HandlePortZod, type HandleUnits, HandleUnitsZod, HexStringSchema, InputPortZod, type InputSpec, type LiteralBinding, LiteralBindingSchema, type ManifestGuard, ManifestGuardZod, type ManifestMaterialiser, ManifestMaterialiserZod, type ManifestOperation, ManifestOperationZod, type ManifestPrecondition, ManifestPreconditionZod, type MaterialiserConfigOf, type MaterialiserInput, type MaterialiserInputBase, type MaterialiserInputOf, type MaterialiserMetadata, type MaterialiserResolution, NativeBalanceDeltaGteSpecSchema, NativeBalanceGteSpecSchema, type NativeBalanceRequirement, type NativeErc20, type OpInputPort, type OpOutputPort, type OutputAmount, OutputPortZod, PROVIDER_KIND, type ParsedRef, type Phase1Artifact, Phase1ArtifactSchema, type Phase1ArtifactWire, Phase1ArtifactZod, type Port, type Precondition, type PreconditionBase, type PreconditionConfigOf, type PreconditionOf, type PreparationComposeError, type PriceImpact, type ProducedResource, type ProviderKindName, RESERVED_REF_SCOPES, type Ref, RefSchema, type RefScope, type Resource, type ResourceInput, ResourceInputSchema, type ResourceOutputPort, ResourceOutputPortZod, type ResourcePort, ResourcePortZod, ResourceSchema, SIMULATE_MAX_REQUIREMENTS, SIMULATE_MAX_TRACKED_BALANCES, STATIC_SOL_TYPES, type SimulateBalanceEntry, type SimulateOkResult, type SimulateRequest, type SimulateResult, type SimulateRevertDecodeResult, type SimulateRevertResult, type SimulateSetupErrorResult, type SimulatedAmounts, type SimulationPolicy, type SimulationRevert, type SimulationRevertComposeError, type SlotFinderRequirement, type SolType, SolTypeSchema, type SpendEntry, type StaticSolType, StaticSolTypeZod, type SweepTo, TEMPO_CHAIN_ID, TEMPO_NATIVE_ERC20, type TrackedBalance, type VerificationDescriptor, VerificationDescriptorSchema, type VerificationDescriptorWire, VerificationDescriptorZod, canonicalAssertedPredicate, canonicalNativeAddress, copy, erc20, erc20Resource, erc20Token, flowInputMode, flowInputResource, flowInputType, foldMaterialiserMetadata, foldRef, foldResource, getChainCapabilities, handle, inputRef, isAsErc20Chain, isContextKey, isEQCheck, isERC20Resource, isGTECheck, isHandlePort, isLTECheck, isMaterialiserInput, isMsgValueNative, isNativeAddressForChain, isNativeResource, isRef, isResourceInput, isResourceOutputPort, isResourcePort, isStaticSolType, linear, native, nativeResource, normalizeNativeTokenAddress, normalizeResource, opHandle, outputRef, parseRef, providerKindByName, providerKindNames, readResource, refKey, resource, resourceKey, resourceOutput, resourceToken, resourcesEqual };
2474
+ export { type AppliedGuard, AppliedGuardSchema, type ApprovalEntry, AssertedErc20BalanceGteSpecSchema, AssertedNativeBalanceGteSpecSchema, type AssertedPredicate, AssertedPredicateSchema, type AssertedPredicateWire, AssertedPredicateZod, type AssertionOwner, AssertionOwnerSchema, type AssertionSpec, AssertionSpecSchema, type AssertionSpecWire, AssertionSpecZod, type Availability, type BindValue, BindValueSchema, Bytes32HexSchema, CONTINUATION_COMMITMENT_OP_ID, type Call, CallCheckSpecSchema, CallSchema, type ChainCapabilities, type Check, type CheckComparator, CheckSchema, CheckZod, type ComposeCompilePartialData, type ComposeCompileRequest, type ComposeCompileResult, type ComposeCompileSuccessData, type ComposeContinuation, type ComposeError, type ComposeErrorKind, type ComposeManifest, ComposeManifestZod, type ComposeRouteRequest, type ComposeRun, type ComposeTransactionRequest, type ContextKey, type Continuation, type ContinuationIntent, ContinuationIntentSchema, type ContinuationOutcome, ContinuationOutcomeSchema, type ContinuationPlan, ContinuationPlanSchema, type ContinuationPlanWire, ContinuationPlanZod, ContinuationSchema, EVM_NATIVE_SENTINEL, type Erc20AllowancePrecondition, type Erc20AllowanceRequirement, Erc20BalanceDeltaGteSpecSchema, Erc20BalanceGteSpecSchema, type Erc20BalancePrecondition, type Erc20BalanceRequirement, type FailedPreparedOp, type FlashloanMaterialiserInput, type Flow, type FlowInput, FlowInputSchema, FlowSchema, type GenericComposeError, type GenericComposeErrorKind, type GuardCompatibility, GuardCompatibilityZod, type GuardSelector, GuardSelectorZod, HANDLE_UNITS, type HandleInput, HandleInputSchema, type HandlePort, HandlePortZod, type HandleUnits, HandleUnitsZod, HexStringSchema, InputPortZod, type InputSpec, type LiteralBinding, LiteralBindingSchema, type ManifestGuard, ManifestGuardZod, type ManifestMaterialiser, ManifestMaterialiserZod, type ManifestOperation, ManifestOperationZod, type ManifestPrecondition, ManifestPreconditionZod, type MaterialiserConfigOf, type MaterialiserInput, type MaterialiserInputBase, type MaterialiserInputOf, type MaterialiserMetadata, type MaterialiserResolution, NativeBalanceDeltaGteSpecSchema, NativeBalanceGteSpecSchema, type NativeBalancePrecondition, type NativeBalanceRequirement, type NativeErc20, type OpInputPort, type OpOutputPort, type OutputAmount, OutputPortZod, PROVIDER_KIND, type ParsedRef, type Phase1Artifact, Phase1ArtifactSchema, type Phase1ArtifactWire, Phase1ArtifactZod, type Port, type Precondition, type PreconditionBase, type PreconditionConfigOf, type PreconditionOf, type PreparationComposeError, type PriceImpact, type ProducedResource, type ProviderKindName, RESERVED_REF_SCOPES, type Ref, RefSchema, type RefScope, type Resource, type ResourceInput, ResourceInputSchema, type ResourceOutputPort, ResourceOutputPortZod, type ResourcePort, ResourcePortZod, ResourceSchema, type RouteAmount, type RouteAmountAll, type RouteAmountExact, SIMULATE_MAX_REQUIREMENTS, SIMULATE_MAX_TRACKED_BALANCES, STATIC_SOL_TYPES, type SimulateBalanceEntry, type SimulateOkResult, type SimulateRequest, type SimulateResult, type SimulateRevertDecodeResult, type SimulateRevertResult, type SimulateSetupErrorResult, type SimulatedAmounts, type SimulationPolicy, type SimulationRevert, type SimulationRevertComposeError, type SlotFinderRequirement, type SolType, SolTypeSchema, type SpendEntry, type StaticSolType, StaticSolTypeZod, type SweepTo, TEMPO_CHAIN_ID, TEMPO_NATIVE_ERC20, type TrackedBalance, type VerificationDescriptor, VerificationDescriptorSchema, type VerificationDescriptorWire, VerificationDescriptorZod, canonicalAssertedPredicate, canonicalNativeAddress, copy, erc20, erc20Allowance, erc20Balance, erc20Resource, erc20Token, flowInputMode, flowInputResource, flowInputType, foldMaterialiserMetadata, foldRef, foldResource, getChainCapabilities, handle, inputRef, isAsErc20Chain, isContextKey, isEQCheck, isERC20Resource, isErc20AllowancePrecondition, isFutureResourceOutput, isGTECheck, isHandlePort, isLTECheck, isMaterialiserInput, isMsgValueNative, isNativeAddressForChain, isNativeBalancePrecondition, isNativeResource, isRef, isResourceInput, isResourceOutputPort, isResourcePort, isStaticSolType, linear, native, nativeBalance, nativeResource, normalizeNativeTokenAddress, normalizeResource, opHandle, outputRef, parseRef, providerKindByName, providerKindNames, readResource, refKey, resource, resourceKey, resourceOutput, resourceToken, resourcesEqual };
package/dist/index.js CHANGED
@@ -335,6 +335,7 @@ var flowInputResource = (input) => isResourceInput(input) ? input.resource : voi
335
335
  var isResourcePort = (port) => port.kind === "resource";
336
336
  var isHandlePort = (port) => port.kind === "handle";
337
337
  var isResourceOutputPort = (port) => port.kind === "resource_output";
338
+ var isFutureResourceOutput = (port) => isResourceOutputPort(port) && port.availability === "future";
338
339
  var isMaterialiserInput = (s) => typeof s === "object" && s !== null && "kind" in s;
339
340
 
340
341
  // src/resource.ts
@@ -399,11 +400,27 @@ var outputRef = (node, port) => ({
399
400
  $ref: `${node}.${port}`
400
401
  });
401
402
  var optionalProp = (key, value) => value !== void 0 && value !== null ? { [key]: value } : {};
402
- var linear = (name, type) => ({ name, type, mode: "linear", availability: "now" });
403
- var copy = (name, type) => ({ name, type, mode: "copy", availability: "now" });
403
+ var linear = (name, type) => ({
404
+ name,
405
+ type,
406
+ mode: "linear",
407
+ availability: "now"
408
+ });
409
+ var copy = (name, type) => ({
410
+ name,
411
+ type,
412
+ mode: "copy",
413
+ availability: "now"
414
+ });
404
415
  var handle = (name, type) => ({ name, type });
405
- var native = (name, chainId) => ({ name, resource: nativeResource(chainId) });
406
- var erc20 = (name, token, chainId) => ({ name, resource: erc20Resource(token, chainId) });
416
+ var native = (name, chainId) => ({
417
+ name,
418
+ resource: nativeResource(chainId)
419
+ });
420
+ var erc20 = (name, token, chainId) => ({
421
+ name,
422
+ resource: erc20Resource(token, chainId)
423
+ });
407
424
  var resource = (name, accepts, options) => ({
408
425
  kind: "resource",
409
426
  name,
@@ -411,17 +428,24 @@ var resource = (name, accepts, options) => ({
411
428
  mode: "linear",
412
429
  ...optionalProp("optional", options?.optional)
413
430
  });
414
- var readResource = (name, accepts) => ({ kind: "resource", name, accepts, mode: "copy" });
431
+ var readResource = (name, accepts) => ({
432
+ kind: "resource",
433
+ name,
434
+ accepts,
435
+ mode: "copy"
436
+ });
415
437
  var opHandle = (name, type, options) => ({
416
438
  kind: "handle",
417
439
  name,
418
440
  type,
419
441
  mode: "copy",
420
442
  ...optionalProp("expose", options?.expose),
421
- ...optionalProp("units", options?.units)
443
+ ...optionalProp("units", options?.units),
444
+ ...optionalProp("optional", options?.optional)
422
445
  });
423
446
  var resourceOutput = (name, options) => {
424
- const opts = typeof options === "string" ? { availability: options } : options;
447
+ const raw = options;
448
+ const opts = typeof raw === "string" ? { availability: raw } : raw;
425
449
  return {
426
450
  kind: "resource_output",
427
451
  name,
@@ -466,6 +490,13 @@ var refKey = (ref) => foldRef(parseRef(ref), {
466
490
  output: (node, port) => `output:${node}:${port}`
467
491
  });
468
492
 
493
+ // src/preconditions.ts
494
+ var erc20Balance = (config) => ({ type: "Erc20Balance", ...config });
495
+ var nativeBalance = (config) => ({ type: "NativeBalance", ...config });
496
+ var erc20Allowance = (config) => ({ type: "Erc20Allowance", ...config });
497
+ var isErc20AllowancePrecondition = (p) => p.type === "Erc20Allowance";
498
+ var isNativeBalancePrecondition = (p) => p.type === "NativeBalance";
499
+
469
500
  // src/simulate.ts
470
501
  var SIMULATE_MAX_TRACKED_BALANCES = 40;
471
502
  var SIMULATE_MAX_REQUIREMENTS = 40;
@@ -531,7 +562,8 @@ var HandlePortZod = z.object({
531
562
  type: SolTypeZod,
532
563
  mode: z.enum(["linear", "copy"]),
533
564
  expose: z.boolean().optional(),
534
- units: HandleUnitsZod.optional()
565
+ units: HandleUnitsZod.optional(),
566
+ optional: z.boolean().optional()
535
567
  });
536
568
  var InputPortZod = z.discriminatedUnion("kind", [
537
569
  ResourcePortZod,
@@ -778,6 +810,8 @@ export {
778
810
  canonicalNativeAddress,
779
811
  copy,
780
812
  erc20,
813
+ erc20Allowance,
814
+ erc20Balance,
781
815
  erc20Resource,
782
816
  erc20Token,
783
817
  flowInputMode,
@@ -793,12 +827,15 @@ export {
793
827
  isContextKey,
794
828
  isEQCheck,
795
829
  isERC20Resource,
830
+ isErc20AllowancePrecondition,
831
+ isFutureResourceOutput,
796
832
  isGTECheck,
797
833
  isHandlePort,
798
834
  isLTECheck,
799
835
  isMaterialiserInput,
800
836
  isMsgValueNative,
801
837
  isNativeAddressForChain,
838
+ isNativeBalancePrecondition,
802
839
  isNativeResource,
803
840
  isRef,
804
841
  isResourceInput,
@@ -807,6 +844,7 @@ export {
807
844
  isStaticSolType,
808
845
  linear,
809
846
  native,
847
+ nativeBalance,
810
848
  nativeResource,
811
849
  normalizeNativeTokenAddress,
812
850
  normalizeResource,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/compose-spec",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Public wire-format types and schemas for Compose flows",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -51,8 +51,8 @@
51
51
  "devDependencies": {
52
52
  "@eslint/compat": "^1.4.0",
53
53
  "@lifi/eslint-plugin": "workspace:^",
54
- "@typescript-eslint/eslint-plugin": "^8.44.1",
55
- "@typescript-eslint/parser": "^8.44.1",
54
+ "@typescript-eslint/eslint-plugin": "^8.68.0",
55
+ "@typescript-eslint/parser": "^8.68.0",
56
56
  "eslint": "^9.36.0",
57
57
  "eslint-config-prettier": "^9.0.0",
58
58
  "eslint-plugin-eslint-comments": "^3.2.0",
@@ -61,7 +61,7 @@
61
61
  "npm-run-all": "^4.1.5",
62
62
  "prettier": "^3.9.4",
63
63
  "tsup": "^8.5.1",
64
- "typescript": "^5.9.2",
64
+ "typescript": "^6.0.3",
65
65
  "vitest": "^3.2.4"
66
66
  },
67
67
  "files": [