@lifi/compose-spec 0.11.3 → 0.13.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 +63 -98
- package/dist/index.d.cts +132 -436
- package/dist/index.d.ts +132 -436
- package/dist/index.js +64 -94
- package/package.json +1 -1
- package/src/chainCapabilities.ts +13 -0
- package/src/compile.ts +0 -23
- package/src/continuation.ts +100 -89
- 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 +3 -7
- package/src/materialiserMetadata.ts +6 -3
- package/src/route.ts +7 -13
- package/src/simulate.ts +30 -2
- package/src/zodSchemas.ts +41 -71
package/src/continuation.ts
CHANGED
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
EpochMsSchema,
|
|
11
11
|
EVMAddressString,
|
|
12
12
|
FlowSchema,
|
|
13
|
-
HexBytesString,
|
|
14
13
|
IntegerString,
|
|
15
14
|
} from './flowSchema.js';
|
|
16
15
|
|
|
@@ -83,7 +82,7 @@ export const CommittedOutcomeSchema = normalizingOutcome(
|
|
|
83
82
|
// Backend-neutral config for the `continuation.settle` op. Note: the funding
|
|
84
83
|
// input is NOT a config field — the deferred step's funding resource/amount is
|
|
85
84
|
// wired via the node's `bind.input` (see M3b). Only the committed terms below
|
|
86
|
-
// (`outcomes`/`continuationFlow`/`validity`/`
|
|
85
|
+
// (`outcomes`/`continuationFlow`/`validity`/`provider`) are the
|
|
87
86
|
// node's `config`.
|
|
88
87
|
//
|
|
89
88
|
// `continuationFlow` is an inlined Flow document that the settlement backend
|
|
@@ -92,11 +91,13 @@ export const CommittedOutcomeSchema = normalizingOutcome(
|
|
|
92
91
|
// pointer. `FlowSchema` lives in the same package, so importing it here keeps
|
|
93
92
|
// `compose-spec` dependency-free.
|
|
94
93
|
export const ContinuationIntentSchema = Schema.Struct({
|
|
95
|
-
//
|
|
96
|
-
|
|
94
|
+
// Zero outcomes are admitted only for an exact settle, whose bound leg is its
|
|
95
|
+
// only enforcement; compose-core's first two capability gates
|
|
96
|
+
// (`resolveContinuationProvider.ts:CAPABILITY_CHECKS`) enforce that pairing
|
|
97
|
+
// and the one-outcome maximum, since the schema cannot see `exact`.
|
|
98
|
+
outcomes: Schema.Array(ContinuationOutcomeSchema),
|
|
97
99
|
continuationFlow: Schema.optional(FlowSchema),
|
|
98
100
|
validity: Schema.Struct({ expiresAtMs: EpochMsSchema }),
|
|
99
|
-
perpetual: Schema.optional(Schema.Boolean),
|
|
100
101
|
provider: Schema.optional(Schema.String),
|
|
101
102
|
// Funding-path mode. The HTTP wire contract is documented by
|
|
102
103
|
// `ComposeActionsSchema` in `@lifi/api-schemas`. A settle funded by a
|
|
@@ -112,12 +113,17 @@ export const ContinuationIntentSchema = Schema.Struct({
|
|
|
112
113
|
}),
|
|
113
114
|
),
|
|
114
115
|
),
|
|
116
|
+
// Bind the settlement to the leg's compiled bytes: the fill runs exactly the
|
|
117
|
+
// calldata the compile proved, so the solver chooses nothing. Needs a
|
|
118
|
+
// `continuationFlow` and a provider that advertises the capability.
|
|
119
|
+
exact: Schema.optional(Schema.Boolean),
|
|
115
120
|
});
|
|
116
121
|
|
|
117
122
|
// A `0x`-prefixed string, prefix checked only. Continuation vocabulary no
|
|
118
123
|
// longer uses it for addresses (those take `EVMAddressString`); it remains
|
|
119
|
-
// for the escrow
|
|
120
|
-
// op configs not yet tightened. `zodSchemas.ts` mirrors it
|
|
124
|
+
// for the escrow and binding records below, which the settlement service
|
|
125
|
+
// returns, and for op configs not yet tightened. `zodSchemas.ts` mirrors it
|
|
126
|
+
// as `hexStringZod`.
|
|
121
127
|
export const HexStringSchema = Schema.String.pipe(Schema.startsWith('0x'));
|
|
122
128
|
|
|
123
129
|
// The escrow a settlement provider registered for a settle node, disclosed on
|
|
@@ -126,9 +132,9 @@ export const HexStringSchema = Schema.String.pipe(Schema.startsWith('0x'));
|
|
|
126
132
|
// providers that fund no escrow never set it. Every field is present whenever
|
|
127
133
|
// the record is. Mirrored by `SettlementEscrowZod`.
|
|
128
134
|
//
|
|
129
|
-
// - `chainId` + `address` — the escrow and its chain.
|
|
130
|
-
//
|
|
131
|
-
//
|
|
135
|
+
// - `chainId` + `address` — the escrow and its chain. Every registration gets
|
|
136
|
+
// a fresh escrow, so the pair identifies this one settlement; never fund it
|
|
137
|
+
// for another.
|
|
132
138
|
// - `token` + `amount` — the funding asset (native → `EVM_NATIVE_SENTINEL`)
|
|
133
139
|
// and the raw amount the escrow was sized from. The program transfers the
|
|
134
140
|
// amount realised at execution, which can differ when an upstream op
|
|
@@ -141,9 +147,8 @@ export const HexStringSchema = Schema.String.pipe(Schema.startsWith('0x'));
|
|
|
141
147
|
// - `refund` — where the escrow balance returns when the settlement expires.
|
|
142
148
|
// - `expiresAtMs` — when the settlement expires: the effective expiry the
|
|
143
149
|
// settlement service stores, which can be earlier than the authored
|
|
144
|
-
// `validity.expiresAtMs
|
|
145
|
-
//
|
|
146
|
-
// never filled and its balance is refunded.
|
|
150
|
+
// `validity.expiresAtMs`; after it the escrow is never filled and its
|
|
151
|
+
// balance is refunded.
|
|
147
152
|
const Phase1EscrowSchema = Schema.Struct({
|
|
148
153
|
chainId: ChainIdSchema,
|
|
149
154
|
address: HexStringSchema,
|
|
@@ -156,12 +161,34 @@ const Phase1EscrowSchema = Schema.Struct({
|
|
|
156
161
|
expiresAtMs: Schema.Number.pipe(Schema.int(), Schema.positive()),
|
|
157
162
|
});
|
|
158
163
|
|
|
159
|
-
//
|
|
160
|
-
//
|
|
161
|
-
// `
|
|
162
|
-
//
|
|
163
|
-
//
|
|
164
|
-
//
|
|
164
|
+
// The executor binding of an `exact` settle, disclosed on the `transaction`
|
|
165
|
+
// artifact and projected onto the wire as `settlements[nodeId].binding`.
|
|
166
|
+
// Absent unless the settle is `exact`. Every field is present whenever the
|
|
167
|
+
// record is. Mirrored by `SettlementBindingZod`.
|
|
168
|
+
//
|
|
169
|
+
// - `executionTarget` — the executor that runs the fill.
|
|
170
|
+
// - `payload` — the executor call the settlement service hashed into the
|
|
171
|
+
// escrow's execute constraint; a fill that runs anything else is rejected.
|
|
172
|
+
// - `payloadHash` — `keccak256(payload)`, the committed hash.
|
|
173
|
+
// - `calldata` — what the executor's proxy runs: the leg's compiled bytes.
|
|
174
|
+
// - `approvals` — the allowances the executor grants before it runs
|
|
175
|
+
// `calldata`.
|
|
176
|
+
const Phase1BindingSchema = Schema.Struct({
|
|
177
|
+
executionTarget: HexStringSchema,
|
|
178
|
+
payload: HexStringSchema,
|
|
179
|
+
payloadHash: HexStringSchema,
|
|
180
|
+
calldata: HexStringSchema,
|
|
181
|
+
approvals: Schema.Array(
|
|
182
|
+
Schema.Struct({ token: HexStringSchema, spender: HexStringSchema }),
|
|
183
|
+
),
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// Internal phase-1 artifact. The HTTP layer projects its `escrow` and
|
|
187
|
+
// `binding` onto `settlements` and publishes external-funding calldata and
|
|
188
|
+
// typed data through `ComposeActionsSchema`. The internal `transactionRequest`
|
|
189
|
+
// remains optional because inline funding does not produce a submittable
|
|
190
|
+
// transfer, and `delivered` funding (a bridge delivers into the escrow)
|
|
191
|
+
// produces none either.
|
|
165
192
|
export const Phase1ArtifactSchema = Schema.Union(
|
|
166
193
|
Schema.Struct({
|
|
167
194
|
kind: Schema.Literal('transaction'),
|
|
@@ -175,6 +202,7 @@ export const Phase1ArtifactSchema = Schema.Union(
|
|
|
175
202
|
}),
|
|
176
203
|
),
|
|
177
204
|
escrow: Schema.optional(Phase1EscrowSchema),
|
|
205
|
+
binding: Schema.optional(Phase1BindingSchema),
|
|
178
206
|
}),
|
|
179
207
|
Schema.Struct({
|
|
180
208
|
kind: Schema.Literal('signables'),
|
|
@@ -183,29 +211,36 @@ export const Phase1ArtifactSchema = Schema.Union(
|
|
|
183
211
|
Schema.Struct({ kind: Schema.Literal('none') }),
|
|
184
212
|
);
|
|
185
213
|
|
|
186
|
-
// The
|
|
187
|
-
//
|
|
188
|
-
//
|
|
214
|
+
// The members of `AssertionSpec` below: each is an absolute predicate over
|
|
215
|
+
// on-chain state that a derived validation program enforces at settlement.
|
|
216
|
+
// Every register operand of a member (an owner, a call argument, a threshold)
|
|
217
|
+
// becomes a committed validation param; the constants a member bakes into the
|
|
218
|
+
// program (a token, a call target, a function signature) are committed by the
|
|
219
|
+
// program hash. Amounts are decimal strings on the wire because JSON has no
|
|
220
|
+
// bigint.
|
|
189
221
|
//
|
|
190
222
|
// - `erc20BalanceGte` — `owner`'s balance of `token` on `chainId` is at least
|
|
191
223
|
// `minAmount`.
|
|
192
224
|
// - `nativeBalanceGte` — `owner`'s native balance on `chainId` is at least
|
|
193
225
|
// `minAmount`.
|
|
194
|
-
// - `call` — a
|
|
195
|
-
//
|
|
226
|
+
// - `call` — a static call to `to` on `chainId` of `signature` with `args`,
|
|
227
|
+
// whose `uint256` return compares against `threshold` using `comparator`.
|
|
196
228
|
//
|
|
197
|
-
// Addresses (`token`/`
|
|
198
|
-
// `
|
|
199
|
-
// take `IntegerString`, so a malformed value fails at
|
|
200
|
-
// lowering. Amounts are not positive-only: a persisted
|
|
201
|
-
// these members, and a zero threshold is well-formed
|
|
229
|
+
// Addresses (`token`/`to`) take `EVMAddressString`, `owner` takes
|
|
230
|
+
// `AssertionOwnerSchema` (below), and amounts
|
|
231
|
+
// (`minAmount`/`threshold`) take `IntegerString`, so a malformed value fails at
|
|
232
|
+
// decode instead of in lowering. Amounts are not positive-only: a persisted
|
|
233
|
+
// descriptor re-decodes these members, and a zero threshold is well-formed
|
|
234
|
+
// (just vacuous).
|
|
202
235
|
|
|
203
|
-
// A balance owner
|
|
204
|
-
//
|
|
205
|
-
//
|
|
206
|
-
//
|
|
207
|
-
//
|
|
208
|
-
//
|
|
236
|
+
// A balance owner: a concrete address, or one of the two symbolic owners
|
|
237
|
+
// `"escrow"` / `"delivery"`. The symbolic owners are thunk terms: a committed
|
|
238
|
+
// thunk carries one when it is assembled by hand (the uc1 fixtures) or echoed
|
|
239
|
+
// back from the commitment, and the derivation resolves each to a
|
|
240
|
+
// validator-injected register (see the verified-continuations derivation). An
|
|
241
|
+
// op's `asserts` hook cannot emit one: in compose-core its spec type is
|
|
242
|
+
// `AssertionSpecOf<H>`, so an owner is always an operand the hook received.
|
|
243
|
+
// The descriptor discloses the same values the program derives from.
|
|
209
244
|
export const AssertionOwnerSchema = Schema.Union(
|
|
210
245
|
EVMAddressString,
|
|
211
246
|
Schema.Literal('escrow', 'delivery'),
|
|
@@ -213,51 +248,49 @@ export const AssertionOwnerSchema = Schema.Union(
|
|
|
213
248
|
export type AssertionOwner = typeof AssertionOwnerSchema.Type;
|
|
214
249
|
|
|
215
250
|
// The three absolute members are exported by name so `AssertionSpecSchema` and
|
|
216
|
-
// the descriptor's predicate union
|
|
217
|
-
// shape. Their `owner` is hex-only: a captured invariant always resolves to a
|
|
218
|
-
// concrete address.
|
|
251
|
+
// the descriptor's predicate union share one declaration.
|
|
219
252
|
export const Erc20BalanceGteSpecSchema = Schema.Struct({
|
|
220
253
|
kind: Schema.Literal('erc20BalanceGte'),
|
|
221
254
|
chainId: ChainIdSchema,
|
|
222
255
|
token: EVMAddressString,
|
|
223
|
-
owner:
|
|
256
|
+
owner: AssertionOwnerSchema,
|
|
224
257
|
minAmount: IntegerString,
|
|
225
258
|
});
|
|
226
259
|
|
|
227
260
|
export const NativeBalanceGteSpecSchema = Schema.Struct({
|
|
228
261
|
kind: Schema.Literal('nativeBalanceGte'),
|
|
229
262
|
chainId: ChainIdSchema,
|
|
230
|
-
owner:
|
|
263
|
+
owner: AssertionOwnerSchema,
|
|
231
264
|
minAmount: IntegerString,
|
|
232
265
|
});
|
|
233
266
|
|
|
267
|
+
// `signature` is the ethers human-readable form, e.g.
|
|
268
|
+
// `function balanceOf(address) returns (uint256)`, with exactly one `uint256`
|
|
269
|
+
// return and only `address` / `uint256` parameters. `args` has one entry per
|
|
270
|
+
// parameter, each written as that parameter's canonical string (a 20-byte hex
|
|
271
|
+
// address, a decimal integer). The derivation parses the signature once and
|
|
272
|
+
// rejects anything else; this schema is a shape check only.
|
|
234
273
|
export const CallCheckSpecSchema = Schema.Struct({
|
|
235
274
|
kind: Schema.Literal('call'),
|
|
236
275
|
chainId: ChainIdSchema,
|
|
237
276
|
to: EVMAddressString,
|
|
238
|
-
|
|
277
|
+
signature: Schema.String,
|
|
278
|
+
args: Schema.Array(Schema.String),
|
|
239
279
|
comparator: Schema.Literal('gte', 'eq', 'lte'),
|
|
240
|
-
|
|
280
|
+
threshold: IntegerString,
|
|
241
281
|
});
|
|
242
282
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
// (`AssertionOwnerSchema.Type` collapses to `string`).
|
|
246
|
-
interface NativeBalanceGteLike {
|
|
247
|
-
readonly kind: 'nativeBalanceGte';
|
|
248
|
-
readonly chainId: number;
|
|
249
|
-
readonly owner: string;
|
|
250
|
-
readonly minAmount: string;
|
|
251
|
-
}
|
|
283
|
+
type Erc20BalanceGteSpec = typeof Erc20BalanceGteSpecSchema.Type;
|
|
284
|
+
type NativeBalanceGteSpec = typeof NativeBalanceGteSpecSchema.Type;
|
|
252
285
|
|
|
253
286
|
// The equivalent `erc20BalanceGte` of a `nativeBalanceGte` spec: `token` is
|
|
254
287
|
// the chain's stand-in ERC-20 (PathUSD on Tempo), every other field carried
|
|
255
288
|
// through.
|
|
256
289
|
const asErc20BalanceGteCheck = (
|
|
257
|
-
check:
|
|
290
|
+
check: NativeBalanceGteSpec,
|
|
258
291
|
token: `0x${string}`,
|
|
259
|
-
) => ({
|
|
260
|
-
kind: 'erc20BalanceGte'
|
|
292
|
+
): Erc20BalanceGteSpec => ({
|
|
293
|
+
kind: 'erc20BalanceGte',
|
|
261
294
|
chainId: check.chainId,
|
|
262
295
|
token,
|
|
263
296
|
owner: check.owner,
|
|
@@ -270,11 +303,11 @@ const asErc20BalanceGteCheck = (
|
|
|
270
303
|
// chain, and rejected on a `native-mirrored-erc20` chain. Used by the
|
|
271
304
|
// descriptor's `AssertedPredicateSchema` so the disclosed and the committed
|
|
272
305
|
// predicate derive the same program (authoring↔settlement hash parity).
|
|
273
|
-
export const decodeNativeBalanceGte =
|
|
274
|
-
check:
|
|
306
|
+
export const decodeNativeBalanceGte = (
|
|
307
|
+
check: NativeBalanceGteSpec,
|
|
275
308
|
ast: SchemaAST.AST,
|
|
276
309
|
): Effect.Effect<
|
|
277
|
-
|
|
310
|
+
NativeBalanceGteSpec | Erc20BalanceGteSpec,
|
|
278
311
|
ParseResult.ParseIssue
|
|
279
312
|
> => {
|
|
280
313
|
const policy = nativeCheckPolicy(check.chainId);
|
|
@@ -291,36 +324,11 @@ export const decodeNativeBalanceGte = <C extends NativeBalanceGteLike>(
|
|
|
291
324
|
// The derivation vocabulary (verified continuations, plan GD-1). An
|
|
292
325
|
// `AssertionSpec` is the structured, backend-neutral form of one invariant a
|
|
293
326
|
// derived validation program must enforce against the executor's re-quoted
|
|
294
|
-
// fill
|
|
295
|
-
// derivation-only members. Amounts stay decimal strings on the wire.
|
|
296
|
-
//
|
|
297
|
-
// - `erc20BalanceDeltaGte` / `nativeBalanceDeltaGte` — `owner`'s post-fill
|
|
298
|
-
// balance of `token` (native) on `chainId` must exceed its pre-fill balance
|
|
299
|
-
// by at least `minDelta`. The settlement validator already checks each
|
|
300
|
-
// committed outcome's floor itself, so the derivation lowers neither kind
|
|
301
|
-
// into a program and rejects them as an authored invariant; they stay in
|
|
302
|
-
// the vocabulary so a descriptor that carries one still decodes.
|
|
303
|
-
export const Erc20BalanceDeltaGteSpecSchema = Schema.Struct({
|
|
304
|
-
kind: Schema.Literal('erc20BalanceDeltaGte'),
|
|
305
|
-
chainId: ChainIdSchema,
|
|
306
|
-
token: EVMAddressString,
|
|
307
|
-
owner: AssertionOwnerSchema,
|
|
308
|
-
minDelta: IntegerString,
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
export const NativeBalanceDeltaGteSpecSchema = Schema.Struct({
|
|
312
|
-
kind: Schema.Literal('nativeBalanceDeltaGte'),
|
|
313
|
-
chainId: ChainIdSchema,
|
|
314
|
-
owner: AssertionOwnerSchema,
|
|
315
|
-
minDelta: IntegerString,
|
|
316
|
-
});
|
|
317
|
-
|
|
327
|
+
// fill: one of the three members above, reused verbatim.
|
|
318
328
|
export const AssertionSpecSchema = Schema.Union(
|
|
319
329
|
Erc20BalanceGteSpecSchema,
|
|
320
330
|
NativeBalanceGteSpecSchema,
|
|
321
331
|
CallCheckSpecSchema,
|
|
322
|
-
Erc20BalanceDeltaGteSpecSchema,
|
|
323
|
-
NativeBalanceDeltaGteSpecSchema,
|
|
324
332
|
);
|
|
325
333
|
|
|
326
334
|
export type ContinuationOutcome = typeof ContinuationOutcomeSchema.Type;
|
|
@@ -328,16 +336,19 @@ export type CommittedOutcome = typeof CommittedOutcomeSchema.Type;
|
|
|
328
336
|
export type ContinuationIntent = typeof ContinuationIntentSchema.Type;
|
|
329
337
|
export type Phase1Artifact = typeof Phase1ArtifactSchema.Type;
|
|
330
338
|
export type AssertionSpec = typeof AssertionSpecSchema.Type;
|
|
339
|
+
export type CallCheckSpec = typeof CallCheckSpecSchema.Type;
|
|
331
340
|
|
|
332
341
|
// The outcome a `continuation.settle` node's single `output` port stands for.
|
|
333
342
|
// The wire format admits several outcomes, but the op produces one resource,
|
|
334
343
|
// discloses one owner, and every shipped provider rejects a multi-outcome
|
|
335
|
-
// intent, so the first outcome is the settled one everywhere. `
|
|
336
|
-
//
|
|
337
|
-
//
|
|
338
|
-
//
|
|
344
|
+
// intent, so the first outcome is the settled one everywhere. `undefined`
|
|
345
|
+
// means a zero-outcome exact settle: the bound leg consumes the funding and
|
|
346
|
+
// delivers nothing, so the `output` port carries no resource. Keep this the
|
|
347
|
+
// only place that picks `[0]`: a multi-outcome design changes one accessor,
|
|
348
|
+
// not a scatter of `[0]`s. Generic over the intent so a `CommittedIntent`
|
|
349
|
+
// yields a `CommittedOutcome`.
|
|
339
350
|
export const settledOutcome = <
|
|
340
|
-
I extends { readonly outcomes: readonly
|
|
351
|
+
I extends { readonly outcomes: readonly unknown[] },
|
|
341
352
|
>(
|
|
342
353
|
intent: I,
|
|
343
|
-
): I['outcomes'][
|
|
354
|
+
): I['outcomes'][number] | undefined => intent.outcomes[0];
|
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,
|
|
@@ -260,6 +256,7 @@ export type {
|
|
|
260
256
|
Erc20BalanceRequirement,
|
|
261
257
|
NativeBalanceRequirement,
|
|
262
258
|
Erc20AllowanceRequirement,
|
|
259
|
+
Permit2AllowanceRequirement,
|
|
263
260
|
SlotFinderRequirement,
|
|
264
261
|
SimulateRequest,
|
|
265
262
|
SimulateBalanceEntry,
|
|
@@ -320,7 +317,6 @@ export {
|
|
|
320
317
|
GuardCompatibilityZod,
|
|
321
318
|
SettlementZod,
|
|
322
319
|
AssertionSpecZod,
|
|
323
|
-
AssertedPredicateZod,
|
|
324
320
|
VerificationDescriptorZod,
|
|
325
321
|
} from './zodSchemas.js';
|
|
326
322
|
export type {
|
|
@@ -328,7 +324,7 @@ export type {
|
|
|
328
324
|
StaticSolType,
|
|
329
325
|
SettlementWire,
|
|
330
326
|
SettlementEscrowWire,
|
|
327
|
+
SettlementBindingWire,
|
|
331
328
|
AssertionSpecWire,
|
|
332
|
-
AssertedPredicateWire,
|
|
333
329
|
VerificationDescriptorWire,
|
|
334
330
|
} 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
|
/**
|