@lifi/compose-spec 0.6.3 → 0.7.0

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/src/zodSchemas.ts CHANGED
@@ -1,11 +1,33 @@
1
1
  import z from 'zod';
2
2
 
3
- import { BYTES32_LOWER_HEX } from './hexPatterns.js';
3
+ import {
4
+ BYTES32_LOWER_HEX,
5
+ DECIMAL_UINT,
6
+ EVM_ADDRESS_HEX,
7
+ HEX_BYTES,
8
+ MAX_DATE_MS,
9
+ MAX_UINT256,
10
+ } from './hexPatterns.js';
4
11
 
5
12
  // A positive integer chain id. Zod mirror of the Effect `ChainIdSchema` in
6
13
  // `flowSchema.ts`, single-sourced so the wire schemas stay consistent.
7
14
  export const chainIdZod = z.number().int().positive();
8
15
 
16
+ // Zod mirrors of `EVMAddressString`, `HexBytesString`, `IntegerString` and
17
+ // `EpochMsSchema` in `flowSchema.ts`, built from the same `hexPatterns.ts`
18
+ // constants. `continuationParity.spec.ts` holds the two sides in lockstep.
19
+ const evmAddressZod = z.string().regex(EVM_ADDRESS_HEX);
20
+ const hexBytesZod = z.string().regex(HEX_BYTES);
21
+ // One refinement, like `IntegerString`'s filter: Zod runs later checks after
22
+ // a failed `.regex`, so a separate bound check would hand `BigInt` a
23
+ // non-digit string and throw.
24
+ const uintStringZod = z
25
+ .string()
26
+ .refine((value) => DECIMAL_UINT.test(value) && BigInt(value) <= MAX_UINT256, {
27
+ message: 'expected a uint256 decimal integer string',
28
+ });
29
+ const epochMsZod = z.number().int().min(-MAX_DATE_MS).max(MAX_DATE_MS);
30
+
9
31
  const SolTypeZod = z.enum([
10
32
  'uint8',
11
33
  'uint16',
@@ -86,6 +108,12 @@ export const ResourceOutputPortZod = z.object({
86
108
  providesMinimum: z.boolean().optional(),
87
109
  omitIfZero: z.boolean().optional(),
88
110
  deliveryAddressInput: z.string().optional(),
111
+ // Declares an output *family*: the port expands, when a call's config is
112
+ // bound, into one instance per element of the config array named here, or
113
+ // into as many instances as the non-negative integer named here. Instances
114
+ // are ordinary ports named `<name>.<index>`; see
115
+ // `outputFamilies.ts:expandOutputPorts`.
116
+ countFrom: z.string().optional(),
89
117
  });
90
118
 
91
119
  export const OutputPortZod = z.discriminatedUnion('kind', [
@@ -165,59 +193,60 @@ export const ComposeManifestZod = z.object({
165
193
  preconditions: z.array(ManifestPreconditionZod).optional(),
166
194
  });
167
195
 
168
- // Metadata-only HTTP projection of `Phase1ArtifactSchema`. The authoritative
169
- // funding and action contract lives on `ComposeActionsSchema` in
170
- // `@lifi/api-schemas`.
171
- export const Phase1ArtifactZod = z.discriminatedUnion('kind', [
172
- z.object({
173
- kind: z.literal('transaction'),
174
- funding: z.enum(['inline', 'external']),
175
- }),
176
- z.object({
177
- kind: z.literal('signables'),
178
- typedData: z.array(z.unknown()),
179
- }),
180
- z.object({
181
- kind: z.literal('none'),
182
- }),
183
- ]);
184
-
185
- // HTTP-layer mirror of `CheckSchema` (the Effect schema in `continuation.ts`).
186
- // A readiness predicate the client can poll and that is also embedded into
187
- // `nextFlow` as an on-chain assertion. Amounts are decimal strings on the wire.
188
- // Address/bytes fields require a `0x` prefix (lenient, mirroring `CheckSchema`).
196
+ // Prefix-only `0x` check, mirroring `HexStringSchema`; used only by the escrow
197
+ // record, which the settlement service returns.
189
198
  const hexStringZod = z.string().startsWith('0x');
190
199
 
191
- // Mirror of `AssertionOwnerSchema` (continuation.ts): a concrete hex address or
200
+ // Mirror of `Phase1EscrowSchema` (continuation.ts): the escrow a settlement
201
+ // provider registered for a settle node, disclosed as named fields so a client
202
+ // reads the terms without decoding the `fundEscrow` calldata. `chainId` +
203
+ // `address` identify the funding user's escrow on that chain. Amounts are
204
+ // raw-unit decimal strings. `expiresAtMs` is the effective expiry in epoch
205
+ // milliseconds; `fill.validUntilMs` is never later than it.
206
+ export const SettlementEscrowZod = z.object({
207
+ chainId: chainIdZod,
208
+ address: hexStringZod,
209
+ token: hexStringZod,
210
+ amount: z.string(),
211
+ cap: z.string(),
212
+ owner: hexStringZod,
213
+ refund: hexStringZod,
214
+ expiresAtMs: z.number().int().positive(),
215
+ });
216
+
217
+ // Mirror of `AssertionOwnerSchema` (continuation.ts): a concrete address or
192
218
  // one of the two symbolic owners resolved at settlement. Applies ONLY to the
193
- // derivation-only delta members — the wire `Check` members keep hex-only
219
+ // derivation-only delta members — the wire `Check` members keep address-only
194
220
  // owners (see the note in continuation.ts).
195
221
  const assertionOwnerZod = z.union([
196
- hexStringZod,
222
+ evmAddressZod,
197
223
  z.enum(['escrow', 'delivery']),
198
224
  ]);
199
225
 
226
+ // HTTP-layer mirror of `CheckSchema` (the Effect schema in `continuation.ts`).
227
+ // A readiness predicate the client can poll and that is also embedded into
228
+ // `nextFlow` as an on-chain assertion. Amounts are decimal strings on the wire.
200
229
  export const CheckZod = z.discriminatedUnion('kind', [
201
230
  z.object({
202
231
  kind: z.literal('erc20BalanceGte'),
203
232
  chainId: chainIdZod,
204
- token: hexStringZod,
205
- owner: hexStringZod,
206
- minAmount: z.string(),
233
+ token: evmAddressZod,
234
+ owner: evmAddressZod,
235
+ minAmount: uintStringZod,
207
236
  }),
208
237
  z.object({
209
238
  kind: z.literal('nativeBalanceGte'),
210
239
  chainId: chainIdZod,
211
- owner: hexStringZod,
212
- minAmount: z.string(),
240
+ owner: evmAddressZod,
241
+ minAmount: uintStringZod,
213
242
  }),
214
243
  z.object({
215
244
  kind: z.literal('call'),
216
245
  chainId: chainIdZod,
217
- to: hexStringZod,
218
- calldata: hexStringZod,
246
+ to: evmAddressZod,
247
+ calldata: hexBytesZod,
219
248
  comparator: z.enum(['gte', 'eq', 'lte']),
220
- value: z.string(),
249
+ value: uintStringZod,
221
250
  }),
222
251
  ]);
223
252
 
@@ -229,15 +258,15 @@ export const AssertionSpecZod = z.discriminatedUnion('kind', [
229
258
  z.object({
230
259
  kind: z.literal('erc20BalanceDeltaGte'),
231
260
  chainId: z.number().int().positive(),
232
- token: hexStringZod,
261
+ token: evmAddressZod,
233
262
  owner: assertionOwnerZod,
234
- minDelta: z.string(),
263
+ minDelta: uintStringZod,
235
264
  }),
236
265
  z.object({
237
266
  kind: z.literal('nativeBalanceDeltaGte'),
238
267
  chainId: z.number().int().positive(),
239
268
  owner: assertionOwnerZod,
240
- minDelta: z.string(),
269
+ minDelta: uintStringZod,
241
270
  }),
242
271
  ]);
243
272
 
@@ -266,15 +295,15 @@ export const AssertedPredicateZod = z.discriminatedUnion('kind', [
266
295
  z.object({
267
296
  kind: z.literal('erc20BalanceGte'),
268
297
  chainId: z.number().int().positive(),
269
- token: hexStringZod,
298
+ token: evmAddressZod,
270
299
  owner: assertionOwnerZod,
271
- minAmount: z.string(),
300
+ minAmount: uintStringZod,
272
301
  }),
273
302
  z.object({
274
303
  kind: z.literal('nativeBalanceGte'),
275
304
  chainId: z.number().int().positive(),
276
305
  owner: assertionOwnerZod,
277
- minAmount: z.string(),
306
+ minAmount: uintStringZod,
278
307
  }),
279
308
  assertionSpecOptionByKind('call'),
280
309
  assertionSpecOptionByKind('erc20BalanceDeltaGte'),
@@ -304,10 +333,20 @@ export const ContinuationPlanZod = z.object({
304
333
  chainId: chainIdZod,
305
334
  nextFlow: z.unknown(),
306
335
  check: CheckZod,
307
- validity: z.object({ expiresAtMs: z.number() }),
336
+ validity: z.object({ expiresAtMs: epochMsZod }),
308
337
  correlationId: z.string().optional(),
309
338
  });
310
339
 
340
+ // What the response says about how one `continuation.settle` node settles.
341
+ // `escrow` is present when the provider registered an escrow; `continuation`
342
+ // when it handed the next leg back to the caller. A settle node that
343
+ // discloses neither is an empty entry. Carries no calldata and no typed data:
344
+ // what to submit or sign lives in `actions`.
345
+ export const SettlementZod = z.object({
346
+ escrow: SettlementEscrowZod.optional(),
347
+ continuation: ContinuationPlanZod.optional(),
348
+ });
349
+
311
350
  export type ResourcePort = z.infer<typeof ResourcePortZod>;
312
351
  export type HandlePort = z.infer<typeof HandlePortZod>;
313
352
  export type HandleUnits = z.infer<typeof HandleUnitsZod>;
@@ -322,5 +361,6 @@ export type ManifestGuard = z.infer<typeof ManifestGuardZod>;
322
361
  export type ManifestMaterialiser = z.infer<typeof ManifestMaterialiserZod>;
323
362
  export type ManifestPrecondition = z.infer<typeof ManifestPreconditionZod>;
324
363
  export type ComposeManifest = z.infer<typeof ComposeManifestZod>;
325
- export type Phase1ArtifactWire = z.infer<typeof Phase1ArtifactZod>;
364
+ export type SettlementEscrowWire = z.infer<typeof SettlementEscrowZod>;
365
+ export type SettlementWire = z.infer<typeof SettlementZod>;
326
366
  export type ContinuationPlanWire = z.infer<typeof ContinuationPlanZod>;