@lifi/compose-spec 0.11.3 → 0.12.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 +42 -87
- package/dist/index.d.cts +171 -501
- package/dist/index.d.ts +171 -501
- package/dist/index.js +43 -83
- package/package.json +1 -1
- package/src/compile.ts +0 -23
- package/src/continuation.ts +87 -81
- package/src/descriptor.ts +20 -72
- package/src/flow.ts +0 -2
- package/src/flowSchema.ts +0 -12
- package/src/hexPatterns.ts +0 -5
- package/src/index.ts +2 -7
- package/src/materialiserMetadata.ts +6 -3
- package/src/route.ts +7 -13
- package/src/zodSchemas.ts +41 -71
package/src/descriptor.ts
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
import { ParseResult, Schema } from 'effect';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
AssertionOwnerSchema,
|
|
5
|
-
CallCheckSpecSchema,
|
|
6
|
-
decodeNativeBalanceGte,
|
|
7
|
-
Erc20BalanceDeltaGteSpecSchema,
|
|
8
|
-
NativeBalanceDeltaGteSpecSchema,
|
|
9
|
-
} from './continuation.js';
|
|
3
|
+
import { AssertionSpecSchema, decodeNativeBalanceGte } from './continuation.js';
|
|
10
4
|
import type { AssertionSpec } from './continuation.js';
|
|
11
|
-
import {
|
|
12
|
-
ChainIdSchema,
|
|
13
|
-
EVMAddressString,
|
|
14
|
-
IntegerString,
|
|
15
|
-
} from './flowSchema.js';
|
|
16
5
|
import { BYTES32_LOWER_HEX } from './hexPatterns.js';
|
|
17
6
|
|
|
18
7
|
// The neutral per-leg verification descriptor (verified continuations, plan
|
|
@@ -20,18 +9,14 @@ import { BYTES32_LOWER_HEX } from './hexPatterns.js';
|
|
|
20
9
|
// validation program enforces, so a user funding phase 1 can give informed
|
|
21
10
|
// consent (PRD goal G8). It is backend-neutral (G7): no validator address, no
|
|
22
11
|
// constraint, no settlement-backend vocabulary — the only escrow-ish term is the
|
|
23
|
-
// symbolic owner `"escrow"
|
|
12
|
+
// symbolic owner `"escrow"` (`AssertionOwnerSchema`), explicitly allowlisted by
|
|
13
|
+
// the boundary check.
|
|
24
14
|
//
|
|
25
15
|
// The design trick that makes disclosure trustworthy-by-construction:
|
|
26
16
|
// `assertedPredicate[]` is NOT a new DSL. It is the canonical JSON serialization
|
|
27
17
|
// of the same `AssertionSpec[]` the validation program is derived from, so
|
|
28
18
|
// disclosure cannot drift from enforcement — both are projections of one array.
|
|
29
19
|
|
|
30
|
-
// `ChainIdSchema`, `EVMAddressString` and `IntegerString` (from
|
|
31
|
-
// `flowSchema.ts`) are reused directly, so the widened members below differ
|
|
32
|
-
// from their `AssertionSpec` counterparts in exactly one field (`owner`) with
|
|
33
|
-
// no risk of a drifting re-declaration.
|
|
34
|
-
|
|
35
20
|
// The `validationProgramHash` (GD-2, seam C1): `keccak256` over the canonical
|
|
36
21
|
// program body. Strict 32-byte lowercase hex (`BYTES32_LOWER_HEX`) — see the
|
|
37
22
|
// rationale in `hexPatterns.ts`.
|
|
@@ -39,48 +24,13 @@ export const Bytes32HexSchema = Schema.String.pipe(
|
|
|
39
24
|
Schema.pattern(BYTES32_LOWER_HEX),
|
|
40
25
|
);
|
|
41
26
|
|
|
42
|
-
// The
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
// a validator-injected slot at settlement (see the `uc1` invariant). The
|
|
47
|
-
// `AssertionSpec` members stay hex-only, so this widening lives in the
|
|
48
|
-
// descriptor union only.
|
|
49
|
-
export const AssertedErc20BalanceGteSpecSchema = Schema.Struct({
|
|
50
|
-
kind: Schema.Literal('erc20BalanceGte'),
|
|
51
|
-
chainId: ChainIdSchema,
|
|
52
|
-
token: EVMAddressString,
|
|
53
|
-
owner: AssertionOwnerSchema,
|
|
54
|
-
minAmount: IntegerString,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
export const AssertedNativeBalanceGteSpecSchema = Schema.Struct({
|
|
58
|
-
kind: Schema.Literal('nativeBalanceGte'),
|
|
59
|
-
chainId: ChainIdSchema,
|
|
60
|
-
owner: AssertionOwnerSchema,
|
|
61
|
-
minAmount: IntegerString,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// The disclosed predicate: the five `AssertionSpec` kinds, with symbolic owners
|
|
65
|
-
// admitted on the two balance-`Gte` members. The `call` member and the two
|
|
66
|
-
// derivation-only delta members are reused verbatim from `continuation.ts` (the
|
|
67
|
-
// delta members already carry `AssertionOwnerSchema`).
|
|
68
|
-
const RawAssertedPredicateSchema = Schema.Union(
|
|
69
|
-
AssertedErc20BalanceGteSpecSchema,
|
|
70
|
-
AssertedNativeBalanceGteSpecSchema,
|
|
71
|
-
CallCheckSpecSchema,
|
|
72
|
-
Erc20BalanceDeltaGteSpecSchema,
|
|
73
|
-
NativeBalanceDeltaGteSpecSchema,
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
// `nativeBalanceGte` handling via `decodeNativeBalanceGte`, applied to the
|
|
77
|
-
// disclosed/committed predicate so settlement derives the identical program.
|
|
78
|
-
// Idempotent on already-normalized predicates; normalizes or refuses a
|
|
79
|
-
// hand-forged committed action that embeds a raw native check. The delta
|
|
80
|
-
// members are untouched — they derive from already-normalized outcomes.
|
|
27
|
+
// The disclosed/committed predicate: an `AssertionSpec` with `nativeBalanceGte`
|
|
28
|
+
// handled via `decodeNativeBalanceGte`, so settlement derives the identical
|
|
29
|
+
// program. Idempotent on already-normalized predicates; normalizes or refuses a
|
|
30
|
+
// hand-forged committed action that embeds a raw native check.
|
|
81
31
|
export const AssertedPredicateSchema = Schema.transformOrFail(
|
|
82
|
-
|
|
83
|
-
Schema.typeSchema(
|
|
32
|
+
AssertionSpecSchema,
|
|
33
|
+
Schema.typeSchema(AssertionSpecSchema),
|
|
84
34
|
{
|
|
85
35
|
strict: true,
|
|
86
36
|
decode: (pred, _options, ast) =>
|
|
@@ -107,16 +57,17 @@ export const VerificationDescriptorSchema = Schema.Struct({
|
|
|
107
57
|
// Deterministic, key-order-pinned JSON serialization of an `AssertionSpec[]`.
|
|
108
58
|
// Canonicalization rules:
|
|
109
59
|
// - Object keys are emitted in recursive lexicographic order (sorted).
|
|
110
|
-
// - Compact separators — no whitespace
|
|
60
|
+
// - Compact separators — no whitespace between tokens (a string value such as
|
|
61
|
+
// a `call` signature keeps its own spaces).
|
|
111
62
|
// - Array element order is PRESERVED, never sorted: it is semantic (derivation
|
|
112
|
-
// order
|
|
113
|
-
// program's assertion order.
|
|
63
|
+
// order, and a `call` member's `args` are positional) and is a faithful
|
|
64
|
+
// projection of the program's assertion order.
|
|
114
65
|
//
|
|
115
|
-
// All `AssertionSpec` leaf values are JSON-safe (
|
|
116
|
-
//
|
|
117
|
-
//
|
|
118
|
-
//
|
|
119
|
-
//
|
|
66
|
+
// All `AssertionSpec` leaf values are JSON-safe (strings, positive-int
|
|
67
|
+
// `chainId`), so lexicographic key sorting is total and stable with no
|
|
68
|
+
// number-canonicalization edge cases, and is self-maintaining when members
|
|
69
|
+
// gain fields. Embedding this string per fixture vector pins the serialization
|
|
70
|
+
// cross-repo (GD-5's consumer asserts it reproduces the string).
|
|
120
71
|
//
|
|
121
72
|
// Boundary-forced local mirror of `@lifi/utils`'s `canonicalJson`: compose-spec
|
|
122
73
|
// is the wire-format leaf and may not import `@lifi/utils` (enforced by the
|
|
@@ -142,9 +93,6 @@ export const canonicalAssertedPredicate = (
|
|
|
142
93
|
|
|
143
94
|
export type VerificationDescriptor = typeof VerificationDescriptorSchema.Type;
|
|
144
95
|
|
|
145
|
-
//
|
|
146
|
-
//
|
|
147
|
-
// changes only schema *decode* behaviour, not the static type. It is therefore
|
|
148
|
-
// exported as a plain alias, keeping `canonicalAssertedPredicate` and the
|
|
149
|
-
// derivation's `specs` array interchangeable without casts.
|
|
96
|
+
// The disclosed predicate is an `AssertionSpec`; the alias names its role in
|
|
97
|
+
// the descriptor.
|
|
150
98
|
export type AssertedPredicate = AssertionSpec;
|
package/src/flow.ts
CHANGED
|
@@ -81,8 +81,6 @@ export type ComposeErrorKind =
|
|
|
81
81
|
| 'compilation_error'
|
|
82
82
|
| 'verification_error'
|
|
83
83
|
| 'price_impact_exceeded'
|
|
84
|
-
| 'fee_resolution_error'
|
|
85
|
-
| 'fee_resolution_unavailable'
|
|
86
84
|
| 'flashloan_unauthorized'
|
|
87
85
|
// A delivery tranche's failure; reasons in `DeliveryErrorReason`.
|
|
88
86
|
| 'delivery_error'
|
package/src/flowSchema.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { normalizeResource } from './chainCapabilities.js';
|
|
|
4
4
|
import {
|
|
5
5
|
DECIMAL_UINT,
|
|
6
6
|
EVM_ADDRESS_HEX,
|
|
7
|
-
HEX_BYTES,
|
|
8
7
|
MAX_DATE_MS,
|
|
9
8
|
MAX_UINT256,
|
|
10
9
|
} from './hexPatterns.js';
|
|
@@ -44,17 +43,6 @@ export const EVMAddressString = Schema.String.pipe(
|
|
|
44
43
|
description: 'EVM address: 0x followed by 40 hex characters',
|
|
45
44
|
});
|
|
46
45
|
|
|
47
|
-
// Whole-byte hex payload (`0x` + an even number of hex digits). Stricter than
|
|
48
|
-
// builtins' `HexDataString`, which keeps odd-length acceptance for op configs:
|
|
49
|
-
// see `HEX_BYTES`.
|
|
50
|
-
export const HexBytesString = Schema.String.pipe(
|
|
51
|
-
Schema.pattern(HEX_BYTES, {
|
|
52
|
-
message: () => 'expected 0x-prefixed hex of whole bytes',
|
|
53
|
-
}),
|
|
54
|
-
).annotations({
|
|
55
|
-
description: 'Hex bytes: 0x followed by an even number of hex characters',
|
|
56
|
-
});
|
|
57
|
-
|
|
58
46
|
// An epoch-millisecond timestamp a `Date` can represent. Pure and
|
|
59
47
|
// clock-independent, so it holds at decode; whether it is still in the future
|
|
60
48
|
// is the consumer's registration-time check.
|
package/src/hexPatterns.ts
CHANGED
|
@@ -21,11 +21,6 @@ export const BYTES32_LOWER_HEX = /^0x[0-9a-f]{64}$/;
|
|
|
21
21
|
// checksums are mixed-case); the prefix itself must be lowercase.
|
|
22
22
|
export const EVM_ADDRESS_HEX = /^0x[0-9a-fA-F]{40}$/;
|
|
23
23
|
|
|
24
|
-
// `0x` followed by whole bytes. Calldata is decoded by `hexToBytes`, which
|
|
25
|
-
// silently drops a trailing odd nibble, so odd-length input is rejected here
|
|
26
|
-
// rather than compiled into a different call.
|
|
27
|
-
export const HEX_BYTES = /^0x(?:[0-9a-fA-F]{2})*$/;
|
|
28
|
-
|
|
29
24
|
// A decimal integer string with no sign, fraction, exponent or hex prefix.
|
|
30
25
|
export const DECIMAL_UINT = /^[0-9]+$/;
|
|
31
26
|
|
package/src/index.ts
CHANGED
|
@@ -42,6 +42,7 @@ export type {
|
|
|
42
42
|
Phase1Artifact,
|
|
43
43
|
AssertionOwner,
|
|
44
44
|
AssertionSpec,
|
|
45
|
+
CallCheckSpec,
|
|
45
46
|
} from './continuation.js';
|
|
46
47
|
export {
|
|
47
48
|
CONTINUATION_COMMITMENT_OP_ID,
|
|
@@ -54,8 +55,6 @@ export {
|
|
|
54
55
|
Erc20BalanceGteSpecSchema,
|
|
55
56
|
NativeBalanceGteSpecSchema,
|
|
56
57
|
CallCheckSpecSchema,
|
|
57
|
-
Erc20BalanceDeltaGteSpecSchema,
|
|
58
|
-
NativeBalanceDeltaGteSpecSchema,
|
|
59
58
|
AssertionSpecSchema,
|
|
60
59
|
settledOutcome,
|
|
61
60
|
} from './continuation.js';
|
|
@@ -66,8 +65,6 @@ export type {
|
|
|
66
65
|
} from './descriptor.js';
|
|
67
66
|
export {
|
|
68
67
|
Bytes32HexSchema,
|
|
69
|
-
AssertedErc20BalanceGteSpecSchema,
|
|
70
|
-
AssertedNativeBalanceGteSpecSchema,
|
|
71
68
|
AssertedPredicateSchema,
|
|
72
69
|
VerificationDescriptorSchema,
|
|
73
70
|
canonicalAssertedPredicate,
|
|
@@ -234,7 +231,6 @@ export type {
|
|
|
234
231
|
ExecutedEpilogue,
|
|
235
232
|
ExecutedForward,
|
|
236
233
|
ComposeFill,
|
|
237
|
-
ComposeFee,
|
|
238
234
|
ComposeUserProgramSimulation,
|
|
239
235
|
ComposeWarning,
|
|
240
236
|
ComposeAction,
|
|
@@ -320,7 +316,6 @@ export {
|
|
|
320
316
|
GuardCompatibilityZod,
|
|
321
317
|
SettlementZod,
|
|
322
318
|
AssertionSpecZod,
|
|
323
|
-
AssertedPredicateZod,
|
|
324
319
|
VerificationDescriptorZod,
|
|
325
320
|
} from './zodSchemas.js';
|
|
326
321
|
export type {
|
|
@@ -328,7 +323,7 @@ export type {
|
|
|
328
323
|
StaticSolType,
|
|
329
324
|
SettlementWire,
|
|
330
325
|
SettlementEscrowWire,
|
|
326
|
+
SettlementBindingWire,
|
|
331
327
|
AssertionSpecWire,
|
|
332
|
-
AssertedPredicateWire,
|
|
333
328
|
VerificationDescriptorWire,
|
|
334
329
|
} from './zodSchemas.js';
|
|
@@ -8,7 +8,10 @@ export type MaterialiserMetadata =
|
|
|
8
8
|
// what was deposited. `min`, when present, is a floor the program asserts
|
|
9
9
|
// on-chain right after the pull, so the deposit never lands below it.
|
|
10
10
|
| { readonly kind: 'capped'; readonly amount: bigint; readonly min?: bigint }
|
|
11
|
-
|
|
11
|
+
// The program pulls whatever the payer holds. `min`, when present, is a
|
|
12
|
+
// floor the program asserts on-chain right after the sweep, and the floor
|
|
13
|
+
// a compile may count on for the input.
|
|
14
|
+
| { readonly kind: 'runtime'; readonly min?: bigint };
|
|
12
15
|
|
|
13
16
|
export interface MaterialiserResolution {
|
|
14
17
|
readonly meta: MaterialiserMetadata;
|
|
@@ -21,11 +24,11 @@ export const foldMaterialiserMetadata = <R>(
|
|
|
21
24
|
readonly exact: (amount: bigint) => R;
|
|
22
25
|
readonly exactNative: (amount: bigint) => R;
|
|
23
26
|
readonly capped: (amount: bigint, min: bigint | undefined) => R;
|
|
24
|
-
readonly runtime: () => R;
|
|
27
|
+
readonly runtime: (min: bigint | undefined) => R;
|
|
25
28
|
},
|
|
26
29
|
): R => {
|
|
27
30
|
if (meta.kind === 'exact') return cases.exact(meta.amount);
|
|
28
31
|
if (meta.kind === 'exact-native') return cases.exactNative(meta.amount);
|
|
29
32
|
if (meta.kind === 'capped') return cases.capped(meta.amount, meta.min);
|
|
30
|
-
return cases.runtime();
|
|
33
|
+
return cases.runtime(meta.min);
|
|
31
34
|
};
|
package/src/route.ts
CHANGED
|
@@ -63,13 +63,13 @@ export interface RouteAmountExact {
|
|
|
63
63
|
* {@link RouteAmountExact} for native inputs.
|
|
64
64
|
*
|
|
65
65
|
* On a route that begins with an aggregator swap the swap's input amount is
|
|
66
|
-
* pinned to the quoted amount derived from `simAmount
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
66
|
+
* pinned to the quoted amount derived from `simAmount`: a runtime balance below
|
|
67
|
+
* that pinned amount reverts, and a balance above it leaves the remainder as
|
|
68
|
+
* `unspentIn`, which may be most of the input and which `sweepTo` receives.
|
|
69
|
+
* Under `EXACT` the deposit and the pinned quote are the same number, so the
|
|
70
|
+
* `unspentIn` output is zero and omitted; any pre-existing dust of the sold
|
|
71
|
+
* token in the proxy is moved to `sweepTo` by the whole-balance sweep
|
|
72
|
+
* independently of that output.
|
|
73
73
|
*/
|
|
74
74
|
export interface RouteAmountAll {
|
|
75
75
|
readonly type: 'ALL';
|
|
@@ -112,12 +112,6 @@ export interface ComposeRouteRequest {
|
|
|
112
112
|
* `0` disables the check.
|
|
113
113
|
*/
|
|
114
114
|
readonly maxPriceImpactBps?: number;
|
|
115
|
-
/**
|
|
116
|
-
* Integrator fee in basis points, taken from the input amount. Range 0–9000.
|
|
117
|
-
* Defaults to `0` server-side when omitted. A non-zero value requires an
|
|
118
|
-
* integration-scoped API key; the server rejects it otherwise.
|
|
119
|
-
*/
|
|
120
|
-
readonly integratorFeeBps?: number;
|
|
121
115
|
/** Opaque referrer tag forwarded to the underlying quote provider. */
|
|
122
116
|
readonly referrer?: string;
|
|
123
117
|
/**
|
package/src/zodSchemas.ts
CHANGED
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
BYTES32_LOWER_HEX,
|
|
5
5
|
DECIMAL_UINT,
|
|
6
6
|
EVM_ADDRESS_HEX,
|
|
7
|
-
HEX_BYTES,
|
|
8
7
|
MAX_UINT256,
|
|
9
8
|
} from './hexPatterns.js';
|
|
10
9
|
|
|
@@ -12,11 +11,10 @@ import {
|
|
|
12
11
|
// `flowSchema.ts`, single-sourced so the wire schemas stay consistent.
|
|
13
12
|
export const chainIdZod = z.number().int().positive();
|
|
14
13
|
|
|
15
|
-
// Zod mirrors of `EVMAddressString
|
|
16
|
-
//
|
|
14
|
+
// Zod mirrors of `EVMAddressString` and `IntegerString` in `flowSchema.ts`,
|
|
15
|
+
// built from the same `hexPatterns.ts` constants.
|
|
17
16
|
// `continuationParity.spec.ts` holds the two sides in lockstep.
|
|
18
17
|
const evmAddressZod = z.string().regex(EVM_ADDRESS_HEX);
|
|
19
|
-
const hexBytesZod = z.string().regex(HEX_BYTES);
|
|
20
18
|
// One refinement, like `IntegerString`'s filter: Zod runs later checks after
|
|
21
19
|
// a failed `.regex`, so a separate bound check would hand `BigInt` a
|
|
22
20
|
// non-digit string and throw.
|
|
@@ -207,7 +205,7 @@ export const ComposeManifestZod = z.object({
|
|
|
207
205
|
});
|
|
208
206
|
|
|
209
207
|
// Prefix-only `0x` check, mirroring `HexStringSchema`; used only by the escrow
|
|
210
|
-
//
|
|
208
|
+
// and binding records, which the settlement service returns.
|
|
211
209
|
const hexStringZod = z.string().startsWith('0x');
|
|
212
210
|
|
|
213
211
|
// Mirror of `Phase1EscrowSchema` (continuation.ts): the escrow a settlement
|
|
@@ -228,115 +226,86 @@ export const SettlementEscrowZod = z.object({
|
|
|
228
226
|
expiresAtMs: z.number().int().positive(),
|
|
229
227
|
});
|
|
230
228
|
|
|
229
|
+
// Mirror of `Phase1BindingSchema` (continuation.ts): the executor binding of
|
|
230
|
+
// an `exact` settle. The settlement service hashed `payload` into the escrow's
|
|
231
|
+
// execute constraint, so a fill runs only that executor call;
|
|
232
|
+
// `payloadHash === keccak256(payload)`. `calldata` is what the executor's
|
|
233
|
+
// proxy runs (the leg's compiled bytes) and `approvals` the allowances it
|
|
234
|
+
// grants first. Absent unless the settle is `exact`. `approvals` is
|
|
235
|
+
// `.readonly()` so the inferred type matches the readonly artifact type
|
|
236
|
+
// without a copy at the handler.
|
|
237
|
+
export const SettlementBindingZod = z.object({
|
|
238
|
+
executionTarget: hexStringZod,
|
|
239
|
+
payload: hexStringZod,
|
|
240
|
+
payloadHash: hexStringZod,
|
|
241
|
+
calldata: hexStringZod,
|
|
242
|
+
approvals: z
|
|
243
|
+
.array(z.object({ token: hexStringZod, spender: hexStringZod }))
|
|
244
|
+
.readonly(),
|
|
245
|
+
});
|
|
246
|
+
|
|
231
247
|
// Mirror of `AssertionOwnerSchema` (continuation.ts): a concrete address or
|
|
232
|
-
// one of the two symbolic owners resolved at settlement.
|
|
233
|
-
// derivation-only delta members — the three absolute members keep
|
|
234
|
-
// address-only owners (see the note in continuation.ts).
|
|
248
|
+
// one of the two symbolic owners resolved at settlement.
|
|
235
249
|
const assertionOwnerZod = z.union([
|
|
236
250
|
evmAddressZod,
|
|
237
251
|
z.enum(['escrow', 'delivery']),
|
|
238
252
|
]);
|
|
239
253
|
|
|
240
|
-
// HTTP-layer mirror of `AssertionSpecSchema` (continuation.ts): the
|
|
241
|
-
//
|
|
242
|
-
//
|
|
254
|
+
// HTTP-layer mirror of `AssertionSpecSchema` (continuation.ts): the two
|
|
255
|
+
// balance members and the `call` member. Amounts are decimal strings on the
|
|
256
|
+
// wire; the `call` member's `signature` / `args` contract is documented on
|
|
257
|
+
// `CallCheckSpecSchema`, and its `args` is `.readonly()` so the inferred type
|
|
258
|
+
// matches the readonly spec type without a copy at the handler. It is also the
|
|
259
|
+
// descriptor's `assertedPredicate` element (`AssertedPredicateSchema` decodes
|
|
260
|
+
// the same shape).
|
|
243
261
|
export const AssertionSpecZod = z.discriminatedUnion('kind', [
|
|
244
262
|
z.object({
|
|
245
263
|
kind: z.literal('erc20BalanceGte'),
|
|
246
264
|
chainId: chainIdZod,
|
|
247
265
|
token: evmAddressZod,
|
|
248
|
-
owner:
|
|
266
|
+
owner: assertionOwnerZod,
|
|
249
267
|
minAmount: uintStringZod,
|
|
250
268
|
}),
|
|
251
269
|
z.object({
|
|
252
270
|
kind: z.literal('nativeBalanceGte'),
|
|
253
271
|
chainId: chainIdZod,
|
|
254
|
-
owner:
|
|
272
|
+
owner: assertionOwnerZod,
|
|
255
273
|
minAmount: uintStringZod,
|
|
256
274
|
}),
|
|
257
275
|
z.object({
|
|
258
276
|
kind: z.literal('call'),
|
|
259
277
|
chainId: chainIdZod,
|
|
260
278
|
to: evmAddressZod,
|
|
261
|
-
|
|
279
|
+
signature: z.string(),
|
|
280
|
+
args: z.array(z.string()).readonly(),
|
|
262
281
|
comparator: z.enum(['gte', 'eq', 'lte']),
|
|
263
|
-
|
|
264
|
-
}),
|
|
265
|
-
z.object({
|
|
266
|
-
kind: z.literal('erc20BalanceDeltaGte'),
|
|
267
|
-
chainId: z.number().int().positive(),
|
|
268
|
-
token: evmAddressZod,
|
|
269
|
-
owner: assertionOwnerZod,
|
|
270
|
-
minDelta: uintStringZod,
|
|
271
|
-
}),
|
|
272
|
-
z.object({
|
|
273
|
-
kind: z.literal('nativeBalanceDeltaGte'),
|
|
274
|
-
chainId: z.number().int().positive(),
|
|
275
|
-
owner: assertionOwnerZod,
|
|
276
|
-
minDelta: uintStringZod,
|
|
282
|
+
threshold: uintStringZod,
|
|
277
283
|
}),
|
|
278
284
|
]);
|
|
279
285
|
|
|
280
286
|
export type AssertionSpecWire = z.infer<typeof AssertionSpecZod>;
|
|
281
287
|
|
|
282
|
-
// HTTP-layer mirror of the GD-3 descriptor union `AssertedPredicateSchema`
|
|
283
|
-
// (descriptor.ts, seam C4). It is the disclosure-path widening of
|
|
284
|
-
// `AssertionSpecZod`: the two balance-`Gte` members accept a symbolic owner
|
|
285
|
-
// (`assertionOwnerZod`) as well as hex, because the derivation resolves symbolic
|
|
286
|
-
// owners to validator-injected slots at settlement. The `AssertionSpecZod`
|
|
287
|
-
// balance members stay hex-only; this widening is confined to the descriptor.
|
|
288
|
-
// The `call` member and the two derivation-only delta members are reused
|
|
289
|
-
// verbatim by selecting them from `AssertionSpecZod.options` by their `kind`
|
|
290
|
-
// literal, so they cannot drift from the source union.
|
|
291
|
-
const assertionSpecOptionByKind = (kind: string) => {
|
|
292
|
-
const option = AssertionSpecZod.options.find(
|
|
293
|
-
(o) => o.shape.kind.value === kind,
|
|
294
|
-
);
|
|
295
|
-
if (option === undefined) {
|
|
296
|
-
throw new Error(`AssertionSpecZod has no member with kind "${kind}"`);
|
|
297
|
-
}
|
|
298
|
-
return option;
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
export const AssertedPredicateZod = z.discriminatedUnion('kind', [
|
|
302
|
-
z.object({
|
|
303
|
-
kind: z.literal('erc20BalanceGte'),
|
|
304
|
-
chainId: z.number().int().positive(),
|
|
305
|
-
token: evmAddressZod,
|
|
306
|
-
owner: assertionOwnerZod,
|
|
307
|
-
minAmount: uintStringZod,
|
|
308
|
-
}),
|
|
309
|
-
z.object({
|
|
310
|
-
kind: z.literal('nativeBalanceGte'),
|
|
311
|
-
chainId: z.number().int().positive(),
|
|
312
|
-
owner: assertionOwnerZod,
|
|
313
|
-
minAmount: uintStringZod,
|
|
314
|
-
}),
|
|
315
|
-
assertionSpecOptionByKind('call'),
|
|
316
|
-
assertionSpecOptionByKind('erc20BalanceDeltaGte'),
|
|
317
|
-
assertionSpecOptionByKind('nativeBalanceDeltaGte'),
|
|
318
|
-
]);
|
|
319
|
-
|
|
320
288
|
export const VerificationDescriptorZod = z.object({
|
|
321
289
|
validationProgramHash: z.string().regex(BYTES32_LOWER_HEX),
|
|
322
290
|
// The C5 echo's second hash (GD-8): the params-vector content hash
|
|
323
291
|
// (`paramsHash`, C1). Required and jointly necessary with the value-blind
|
|
324
292
|
// `validationProgramHash`.
|
|
325
293
|
paramsHash: z.string().regex(BYTES32_LOWER_HEX),
|
|
326
|
-
assertedPredicate: z.array(
|
|
294
|
+
assertedPredicate: z.array(AssertionSpecZod).readonly(),
|
|
327
295
|
});
|
|
328
296
|
|
|
329
|
-
export type AssertedPredicateWire = z.infer<typeof AssertedPredicateZod>;
|
|
330
297
|
export type VerificationDescriptorWire = z.infer<
|
|
331
298
|
typeof VerificationDescriptorZod
|
|
332
299
|
>;
|
|
333
300
|
|
|
334
301
|
// What the response says about how one `continuation.settle` node settles.
|
|
335
|
-
// `escrow` is present when the provider registered an escrow
|
|
336
|
-
//
|
|
337
|
-
//
|
|
302
|
+
// `escrow` is present when the provider registered an escrow and `binding`
|
|
303
|
+
// when the settle is `exact`; a settle node that discloses neither is an empty
|
|
304
|
+
// entry. Carries nothing to submit or sign: that lives in `actions`.
|
|
305
|
+
// `binding.calldata` is what the executor runs, disclosed for checking.
|
|
338
306
|
export const SettlementZod = z.object({
|
|
339
307
|
escrow: SettlementEscrowZod.optional(),
|
|
308
|
+
binding: SettlementBindingZod.optional(),
|
|
340
309
|
});
|
|
341
310
|
|
|
342
311
|
export type ResourcePort = z.infer<typeof ResourcePortZod>;
|
|
@@ -355,4 +324,5 @@ export type ManifestPrecondition = z.infer<typeof ManifestPreconditionZod>;
|
|
|
355
324
|
export type ManifestRouting = z.infer<typeof ManifestRoutingZod>;
|
|
356
325
|
export type ComposeManifest = z.infer<typeof ComposeManifestZod>;
|
|
357
326
|
export type SettlementEscrowWire = z.infer<typeof SettlementEscrowZod>;
|
|
327
|
+
export type SettlementBindingWire = z.infer<typeof SettlementBindingZod>;
|
|
358
328
|
export type SettlementWire = z.infer<typeof SettlementZod>;
|