@lifi/compose-spec 0.2.0 → 0.3.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/dist/index.cjs +440 -4
- package/dist/index.d.cts +1259 -121
- package/dist/index.d.ts +1259 -121
- package/dist/index.js +400 -4
- package/package.json +22 -2
- package/src/chainCapabilities.ts +174 -0
- package/src/compile.ts +44 -11
- package/src/constructors.ts +55 -53
- package/src/continuation.ts +278 -0
- package/src/descriptor.ts +151 -0
- package/src/flashloan.ts +8 -8
- package/src/flow.ts +46 -46
- package/src/flowSchema.ts +61 -27
- package/src/hexPatterns.ts +16 -0
- package/src/index.ts +92 -19
- package/src/materialiserMetadata.ts +1 -1
- package/src/ref.ts +21 -21
- package/src/resource.ts +19 -9
- package/src/simulate.ts +7 -9
- package/src/zodSchemas.ts +208 -48
package/src/zodSchemas.ts
CHANGED
|
@@ -1,51 +1,57 @@
|
|
|
1
|
-
import z from
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
|
|
3
|
+
import { BYTES32_LOWER_HEX } from './hexPatterns.js';
|
|
4
|
+
|
|
5
|
+
// A positive integer chain id. Zod mirror of the Effect `ChainIdSchema` in
|
|
6
|
+
// `flowSchema.ts`, single-sourced so the wire schemas stay consistent.
|
|
7
|
+
export const chainIdZod = z.number().int().positive();
|
|
2
8
|
|
|
3
9
|
const SolTypeZod = z.enum([
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
'uint8',
|
|
11
|
+
'uint16',
|
|
12
|
+
'uint32',
|
|
13
|
+
'uint64',
|
|
14
|
+
'uint128',
|
|
15
|
+
'uint256',
|
|
16
|
+
'int128',
|
|
17
|
+
'int256',
|
|
18
|
+
'address',
|
|
19
|
+
'bool',
|
|
20
|
+
'bytes',
|
|
21
|
+
'bytes4',
|
|
22
|
+
'bytes32',
|
|
23
|
+
'string',
|
|
18
24
|
]);
|
|
19
25
|
|
|
20
26
|
export const ResourcePortZod = z.object({
|
|
21
|
-
kind: z.literal(
|
|
27
|
+
kind: z.literal('resource'),
|
|
22
28
|
name: z.string(),
|
|
23
|
-
accepts: z.enum([
|
|
24
|
-
mode: z.enum([
|
|
29
|
+
accepts: z.enum(['erc20', 'native', 'any']),
|
|
30
|
+
mode: z.enum(['linear', 'copy']),
|
|
25
31
|
optional: z.boolean().optional(),
|
|
26
32
|
});
|
|
27
33
|
|
|
28
34
|
export const HANDLE_UNITS = [
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
'raw',
|
|
36
|
+
'wad',
|
|
37
|
+
'ray',
|
|
38
|
+
'bps',
|
|
39
|
+
'token-decimals',
|
|
34
40
|
] as const;
|
|
35
41
|
|
|
36
42
|
// NOTE: the uint members below must stay in sync with the `UintN` union in
|
|
37
43
|
// `ts/packages/lifi_ir1_ts/src/types/ValueHandle.ts`. When adding a new
|
|
38
44
|
// uintN width, update both locations.
|
|
39
45
|
export const STATIC_SOL_TYPES = [
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
'uint256',
|
|
47
|
+
'uint128',
|
|
48
|
+
'uint64',
|
|
49
|
+
'uint32',
|
|
50
|
+
'uint16',
|
|
51
|
+
'uint8',
|
|
52
|
+
'address',
|
|
53
|
+
'bool',
|
|
54
|
+
'bytes32',
|
|
49
55
|
] as const;
|
|
50
56
|
|
|
51
57
|
export const HandleUnitsZod = z.enum(HANDLE_UNITS);
|
|
@@ -58,30 +64,30 @@ export const isStaticSolType = (value: string): value is StaticSolType =>
|
|
|
58
64
|
STATIC_SOL_TYPE_SET.has(value);
|
|
59
65
|
|
|
60
66
|
export const HandlePortZod = z.object({
|
|
61
|
-
kind: z.literal(
|
|
67
|
+
kind: z.literal('handle'),
|
|
62
68
|
name: z.string(),
|
|
63
69
|
type: SolTypeZod,
|
|
64
|
-
mode: z.enum([
|
|
70
|
+
mode: z.enum(['linear', 'copy']),
|
|
65
71
|
expose: z.boolean().optional(),
|
|
66
72
|
units: HandleUnitsZod.optional(),
|
|
67
73
|
});
|
|
68
74
|
|
|
69
|
-
export const InputPortZod = z.discriminatedUnion(
|
|
75
|
+
export const InputPortZod = z.discriminatedUnion('kind', [
|
|
70
76
|
ResourcePortZod,
|
|
71
77
|
HandlePortZod,
|
|
72
78
|
]);
|
|
73
79
|
|
|
74
80
|
export const ResourceOutputPortZod = z.object({
|
|
75
|
-
kind: z.literal(
|
|
81
|
+
kind: z.literal('resource_output'),
|
|
76
82
|
name: z.string(),
|
|
77
|
-
mode: z.enum([
|
|
78
|
-
availability: z.enum([
|
|
83
|
+
mode: z.enum(['linear', 'copy']),
|
|
84
|
+
availability: z.enum(['now', 'future']).optional(),
|
|
79
85
|
providesMinimum: z.boolean().optional(),
|
|
80
86
|
omitIfZero: z.boolean().optional(),
|
|
81
87
|
deliveryAddressInput: z.string().optional(),
|
|
82
88
|
});
|
|
83
89
|
|
|
84
|
-
export const OutputPortZod = z.discriminatedUnion(
|
|
90
|
+
export const OutputPortZod = z.discriminatedUnion('kind', [
|
|
85
91
|
ResourceOutputPortZod,
|
|
86
92
|
HandlePortZod,
|
|
87
93
|
]);
|
|
@@ -94,32 +100,32 @@ export const ManifestOperationZod = z.object({
|
|
|
94
100
|
configSchema: z.unknown().optional(),
|
|
95
101
|
});
|
|
96
102
|
|
|
97
|
-
const PortKindEnum = z.enum([
|
|
103
|
+
const PortKindEnum = z.enum(['resource', 'resource_output', 'handle']);
|
|
98
104
|
|
|
99
105
|
const SelectorMatchZod = z.object({
|
|
100
106
|
kind: z.union([PortKindEnum, z.array(PortKindEnum)]),
|
|
101
|
-
mode: z.enum([
|
|
102
|
-
type: z.enum([
|
|
107
|
+
mode: z.enum(['linear', 'copy']).optional(),
|
|
108
|
+
type: z.enum(['erc20', 'native', 'any']).optional(),
|
|
103
109
|
});
|
|
104
110
|
|
|
105
111
|
const ConfigSelectionZod = z.object({
|
|
106
|
-
kind: z.literal(
|
|
112
|
+
kind: z.literal('config'),
|
|
107
113
|
configKey: z.string(),
|
|
108
|
-
cardinality: z.enum([
|
|
114
|
+
cardinality: z.enum(['one', 'many']),
|
|
109
115
|
});
|
|
110
116
|
|
|
111
117
|
const AllMatchingSelectionZod = z.object({
|
|
112
|
-
kind: z.literal(
|
|
118
|
+
kind: z.literal('all_matching'),
|
|
113
119
|
});
|
|
114
120
|
|
|
115
|
-
const SelectorSelectionZod = z.discriminatedUnion(
|
|
121
|
+
const SelectorSelectionZod = z.discriminatedUnion('kind', [
|
|
116
122
|
ConfigSelectionZod,
|
|
117
123
|
AllMatchingSelectionZod,
|
|
118
124
|
]);
|
|
119
125
|
|
|
120
126
|
export const GuardSelectorZod = z.object({
|
|
121
127
|
binding: z.string(),
|
|
122
|
-
source: z.enum([
|
|
128
|
+
source: z.enum(['inputs', 'outputs']),
|
|
123
129
|
match: SelectorMatchZod,
|
|
124
130
|
selection: SelectorSelectionZod,
|
|
125
131
|
});
|
|
@@ -138,7 +144,7 @@ export const ManifestGuardZod = z.object({
|
|
|
138
144
|
export const ManifestMaterialiserZod = z.object({
|
|
139
145
|
kind: z.string(),
|
|
140
146
|
description: z.string().optional(),
|
|
141
|
-
accepts: z.enum([
|
|
147
|
+
accepts: z.enum(['resource', 'handle', 'any']),
|
|
142
148
|
configSchema: z.unknown().optional(),
|
|
143
149
|
});
|
|
144
150
|
|
|
@@ -158,6 +164,158 @@ export const ComposeManifestZod = z.object({
|
|
|
158
164
|
preconditions: z.array(ManifestPreconditionZod).optional(),
|
|
159
165
|
});
|
|
160
166
|
|
|
167
|
+
// HTTP-layer mirror of `Phase1ArtifactSchema` (the Effect schema in
|
|
168
|
+
// `continuation.ts`). The Effect schema validates the Flow; this Zod schema
|
|
169
|
+
// validates the `/compose` response. `transaction` carries an optional
|
|
170
|
+
// `transactionRequest` only if a venue later needs it; for v1 it is just
|
|
171
|
+
// `{ kind: "transaction" }` and the client funds via the existing
|
|
172
|
+
// response-level `transactionRequest`.
|
|
173
|
+
export const Phase1ArtifactZod = z.discriminatedUnion('kind', [
|
|
174
|
+
z.object({
|
|
175
|
+
kind: z.literal('transaction'),
|
|
176
|
+
transactionRequest: z
|
|
177
|
+
.object({
|
|
178
|
+
to: z.string(),
|
|
179
|
+
data: z.string(),
|
|
180
|
+
value: z.string(),
|
|
181
|
+
})
|
|
182
|
+
.optional(),
|
|
183
|
+
}),
|
|
184
|
+
z.object({
|
|
185
|
+
kind: z.literal('signables'),
|
|
186
|
+
typedData: z.array(z.unknown()),
|
|
187
|
+
}),
|
|
188
|
+
z.object({
|
|
189
|
+
kind: z.literal('none'),
|
|
190
|
+
}),
|
|
191
|
+
]);
|
|
192
|
+
|
|
193
|
+
// HTTP-layer mirror of `CheckSchema` (the Effect schema in `continuation.ts`).
|
|
194
|
+
// A readiness predicate the client can poll and that is also embedded into
|
|
195
|
+
// `nextFlow` as an on-chain assertion. Amounts are decimal strings on the wire.
|
|
196
|
+
// Address/bytes fields require a `0x` prefix (lenient, mirroring `CheckSchema`).
|
|
197
|
+
const hexStringZod = z.string().startsWith('0x');
|
|
198
|
+
|
|
199
|
+
// Mirror of `AssertionOwnerSchema` (continuation.ts): a concrete hex address or
|
|
200
|
+
// one of the two symbolic owners resolved at settlement. Applies ONLY to the
|
|
201
|
+
// derivation-only delta members — the wire `Check` members keep hex-only
|
|
202
|
+
// owners (see the note in continuation.ts).
|
|
203
|
+
const assertionOwnerZod = z.union([
|
|
204
|
+
hexStringZod,
|
|
205
|
+
z.enum(['escrow', 'delivery']),
|
|
206
|
+
]);
|
|
207
|
+
|
|
208
|
+
export const CheckZod = z.discriminatedUnion('kind', [
|
|
209
|
+
z.object({
|
|
210
|
+
kind: z.literal('erc20BalanceGte'),
|
|
211
|
+
chainId: chainIdZod,
|
|
212
|
+
token: hexStringZod,
|
|
213
|
+
owner: hexStringZod,
|
|
214
|
+
minAmount: z.string(),
|
|
215
|
+
}),
|
|
216
|
+
z.object({
|
|
217
|
+
kind: z.literal('nativeBalanceGte'),
|
|
218
|
+
chainId: chainIdZod,
|
|
219
|
+
owner: hexStringZod,
|
|
220
|
+
minAmount: z.string(),
|
|
221
|
+
}),
|
|
222
|
+
z.object({
|
|
223
|
+
kind: z.literal('call'),
|
|
224
|
+
chainId: chainIdZod,
|
|
225
|
+
to: hexStringZod,
|
|
226
|
+
calldata: hexStringZod,
|
|
227
|
+
comparator: z.enum(['gte', 'eq', 'lte']),
|
|
228
|
+
value: z.string(),
|
|
229
|
+
}),
|
|
230
|
+
]);
|
|
231
|
+
|
|
232
|
+
// HTTP-layer mirror of `AssertionSpecSchema` (continuation.ts): the three
|
|
233
|
+
// `Check` members plus the two derivation-only members. Reuses `CheckZod`'s
|
|
234
|
+
// options so the shared members cannot drift from `Check`.
|
|
235
|
+
export const AssertionSpecZod = z.discriminatedUnion('kind', [
|
|
236
|
+
...CheckZod.options,
|
|
237
|
+
z.object({
|
|
238
|
+
kind: z.literal('erc20BalanceDeltaGte'),
|
|
239
|
+
chainId: z.number().int().positive(),
|
|
240
|
+
token: hexStringZod,
|
|
241
|
+
owner: assertionOwnerZod,
|
|
242
|
+
minDelta: z.string(),
|
|
243
|
+
}),
|
|
244
|
+
z.object({
|
|
245
|
+
kind: z.literal('nativeBalanceDeltaGte'),
|
|
246
|
+
chainId: z.number().int().positive(),
|
|
247
|
+
owner: assertionOwnerZod,
|
|
248
|
+
minDelta: z.string(),
|
|
249
|
+
}),
|
|
250
|
+
]);
|
|
251
|
+
|
|
252
|
+
export type AssertionSpecWire = z.infer<typeof AssertionSpecZod>;
|
|
253
|
+
|
|
254
|
+
// HTTP-layer mirror of the GD-3 descriptor union `AssertedPredicateSchema`
|
|
255
|
+
// (descriptor.ts, seam C4). It is the disclosure-path widening of
|
|
256
|
+
// `AssertionSpecZod`: the two balance-`Gte` members accept a symbolic owner
|
|
257
|
+
// (`assertionOwnerZod`) as well as hex, because the derivation resolves symbolic
|
|
258
|
+
// owners to validator-injected slots at settlement. The wire `Check` members
|
|
259
|
+
// stay hex-only (`CheckZod`); this widening is confined to the descriptor. The
|
|
260
|
+
// `call` member and the two derivation-only delta members are reused verbatim by
|
|
261
|
+
// selecting them from `AssertionSpecZod.options` by their `kind` literal, so
|
|
262
|
+
// they cannot drift from the source union.
|
|
263
|
+
const assertionSpecOptionByKind = (kind: string) => {
|
|
264
|
+
const option = AssertionSpecZod.options.find(
|
|
265
|
+
(o) => o.shape.kind.value === kind,
|
|
266
|
+
);
|
|
267
|
+
if (option === undefined) {
|
|
268
|
+
throw new Error(`AssertionSpecZod has no member with kind "${kind}"`);
|
|
269
|
+
}
|
|
270
|
+
return option;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
export const AssertedPredicateZod = z.discriminatedUnion('kind', [
|
|
274
|
+
z.object({
|
|
275
|
+
kind: z.literal('erc20BalanceGte'),
|
|
276
|
+
chainId: z.number().int().positive(),
|
|
277
|
+
token: hexStringZod,
|
|
278
|
+
owner: assertionOwnerZod,
|
|
279
|
+
minAmount: z.string(),
|
|
280
|
+
}),
|
|
281
|
+
z.object({
|
|
282
|
+
kind: z.literal('nativeBalanceGte'),
|
|
283
|
+
chainId: z.number().int().positive(),
|
|
284
|
+
owner: assertionOwnerZod,
|
|
285
|
+
minAmount: z.string(),
|
|
286
|
+
}),
|
|
287
|
+
assertionSpecOptionByKind('call'),
|
|
288
|
+
assertionSpecOptionByKind('erc20BalanceDeltaGte'),
|
|
289
|
+
assertionSpecOptionByKind('nativeBalanceDeltaGte'),
|
|
290
|
+
]);
|
|
291
|
+
|
|
292
|
+
export const VerificationDescriptorZod = z.object({
|
|
293
|
+
validationProgramHash: z.string().regex(BYTES32_LOWER_HEX),
|
|
294
|
+
// The C5 echo's second hash (GD-8): the params-vector content hash
|
|
295
|
+
// (`paramsHash`, C1). Required and jointly necessary with the value-blind
|
|
296
|
+
// `validationProgramHash`.
|
|
297
|
+
paramsHash: z.string().regex(BYTES32_LOWER_HEX),
|
|
298
|
+
assertedPredicate: z.array(AssertedPredicateZod),
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
export type AssertedPredicateWire = z.infer<typeof AssertedPredicateZod>;
|
|
302
|
+
export type VerificationDescriptorWire = z.infer<
|
|
303
|
+
typeof VerificationDescriptorZod
|
|
304
|
+
>;
|
|
305
|
+
|
|
306
|
+
// HTTP-layer mirror of `ContinuationPlanSchema`. `nextFlow` is typed
|
|
307
|
+
// `z.unknown()` rather than mirroring the full Flow schema in Zod: the client
|
|
308
|
+
// treats it as an opaque, re-submittable document and POSTs it back to
|
|
309
|
+
// `/compose`, where the Effect `FlowSchema` validates it. The internal
|
|
310
|
+
// `ContinuationPlan` type keeps `nextFlow: Flow` precisely typed.
|
|
311
|
+
export const ContinuationPlanZod = z.object({
|
|
312
|
+
chainId: chainIdZod,
|
|
313
|
+
nextFlow: z.unknown(),
|
|
314
|
+
check: CheckZod,
|
|
315
|
+
validity: z.object({ expiresAtMs: z.number() }),
|
|
316
|
+
correlationId: z.string().optional(),
|
|
317
|
+
});
|
|
318
|
+
|
|
161
319
|
export type ResourcePort = z.infer<typeof ResourcePortZod>;
|
|
162
320
|
export type HandlePort = z.infer<typeof HandlePortZod>;
|
|
163
321
|
export type HandleUnits = z.infer<typeof HandleUnitsZod>;
|
|
@@ -172,3 +330,5 @@ export type ManifestGuard = z.infer<typeof ManifestGuardZod>;
|
|
|
172
330
|
export type ManifestMaterialiser = z.infer<typeof ManifestMaterialiserZod>;
|
|
173
331
|
export type ManifestPrecondition = z.infer<typeof ManifestPreconditionZod>;
|
|
174
332
|
export type ComposeManifest = z.infer<typeof ComposeManifestZod>;
|
|
333
|
+
export type Phase1ArtifactWire = z.infer<typeof Phase1ArtifactZod>;
|
|
334
|
+
export type ContinuationPlanWire = z.infer<typeof ContinuationPlanZod>;
|