@rootzero/contracts 1.25.0 → 1.27.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/CHANGELOG.md +125 -0
- package/Codec.sol +1 -2
- package/Endpoints.sol +2 -0
- package/README.md +73 -51
- package/Utils.sol +2 -1
- package/codec/Blocks.sol +276 -88
- package/codec/Buffers.sol +24 -20
- package/codec/Decoders.sol +35 -37
- package/codec/Descriptors.sol +75 -72
- package/codec/Keys.sol +5 -1
- package/codec/Schema.sol +7 -1
- package/codec/Specs.sol +19 -9
- package/codec/Writers.sol +14 -19
- package/commands/Allocate.sol +8 -7
- package/commands/Base.sol +14 -49
- package/commands/Bootstrap.sol +81 -0
- package/commands/Burn.sol +7 -7
- package/commands/Cashout.sol +86 -0
- package/commands/Credit.sol +20 -17
- package/commands/Debit.sol +25 -20
- package/commands/Deposit.sol +13 -13
- package/commands/Payout.sol +8 -8
- package/commands/Provision.sol +13 -13
- package/commands/Recover.sol +7 -7
- package/commands/Relay.sol +22 -23
- package/commands/Repay.sol +38 -35
- package/commands/Settle.sol +26 -23
- package/commands/Withdraw.sol +7 -7
- package/commands/admin/AllowAssets.sol +7 -7
- package/commands/admin/Allowance.sol +7 -7
- package/commands/admin/Annotate.sol +7 -7
- package/commands/admin/Appoint.sol +7 -7
- package/commands/admin/Authorize.sol +7 -7
- package/commands/admin/Base.sol +5 -8
- package/commands/admin/DenyAssets.sol +7 -7
- package/commands/admin/Dismiss.sol +7 -7
- package/commands/admin/Execute.sol +8 -8
- package/commands/admin/Unauthorize.sol +7 -7
- package/core/Access.sol +1 -0
- package/core/Calls.sol +3 -3
- package/core/Endpoint.sol +7 -7
- package/core/Pipeline.sol +19 -23
- package/core/Settlement.sol +2 -1
- package/core/Types.sol +1 -0
- package/execution/Budget.sol +2 -3
- package/execution/Execution.sol +270 -511
- package/guards/Base.sol +1 -1
- package/guards/Revoke.sol +7 -7
- package/package.json +1 -1
- package/ports/Allowance.sol +3 -3
- package/ports/Assets.sol +7 -7
- package/ports/Base.sol +1 -1
- package/ports/Credit.sol +3 -3
- package/ports/Debit.sol +3 -3
- package/ports/Dispatch.sol +3 -3
- package/ports/Pipe.sol +3 -3
- package/ports/Post.sol +3 -3
- package/ports/Redeem.sol +3 -3
- package/queries/Assets.sol +3 -3
- package/queries/Balances.sol +3 -3
- package/queries/Base.sol +1 -1
- package/utils/Accounts.sol +17 -10
- package/utils/Actions.sol +2 -0
- package/utils/Assets.sol +1 -10
- package/utils/Cursors.sol +60 -116
- package/utils/Errors.sol +56 -0
- package/utils/Ids.sol +2 -5
- package/utils/Lanes.sol +0 -2
- package/utils/Nodes.sol +1 -3
- package/utils/Utils.sol +2 -9
- package/codec/Readers.sol +0 -190
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,131 @@ sections are immutable and must continue to describe the tagged release.
|
|
|
8
8
|
|
|
9
9
|
## Unreleased
|
|
10
10
|
|
|
11
|
+
## 1.27.0
|
|
12
|
+
|
|
13
|
+
### Breaking Changes
|
|
14
|
+
|
|
15
|
+
- Removed `BootstrapBudgetHook`. Bootstrap budget contributions now debit the
|
|
16
|
+
account's local native asset through the standard `DebitAccountHook`.
|
|
17
|
+
- Removed the external `bootstrap` endpoint and `BootstrapInternal`. Bootstrap
|
|
18
|
+
is now a pipeline-local command implemented directly by `Bootstrap` while
|
|
19
|
+
retaining its registered command ID and descriptor metadata.
|
|
20
|
+
- Replaced the codec-specific `Executions.ZeroStride` error with global
|
|
21
|
+
`UnexpectedState` and `UnexpectedInput` errors for pipeline-local lane
|
|
22
|
+
violations.
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
|
|
26
|
+
- Node authorization and revocation now reject foreign-chain and opaque node
|
|
27
|
+
IDs, keeping the trusted-node set local to the host chain.
|
|
28
|
+
- Asserting EVM, admin, and user account helpers now require a nonzero embedded
|
|
29
|
+
address while continuing to return the original account ID.
|
|
30
|
+
- Documented that either side of a position may be absent, using a zero
|
|
31
|
+
identifier and quantity like an omitted transaction endpoint.
|
|
32
|
+
- Bootstrap uses assigned step value before debiting any remaining native-asset
|
|
33
|
+
amount from the account and returns unused value as credit.
|
|
34
|
+
|
|
35
|
+
## 1.26.0
|
|
36
|
+
|
|
37
|
+
### Breaking Changes
|
|
38
|
+
|
|
39
|
+
- STEP blocks now encode `uint128 value` directly instead of a full-width
|
|
40
|
+
chain-specific `uint resources` word. The fixed STEP prefix is 16 bytes
|
|
41
|
+
smaller, and pipeline dispatch no longer truncates or interprets resource bits.
|
|
42
|
+
- Commands now return `(bytes state, uint credit)` instead of separate state
|
|
43
|
+
and transaction block streams. Pipelines trust the scalar return and add it
|
|
44
|
+
to the shared value budget, allowing later commands to spend it before the
|
|
45
|
+
enclosing entrypoint settles the final budget once. Transaction blocks remain
|
|
46
|
+
available for explicit posting through ports.
|
|
47
|
+
- Removed transaction writer metadata from endpoint descriptors and execution
|
|
48
|
+
writer lanes.
|
|
49
|
+
- Removed descriptor checks, eager lane scans, group reconciliation, and the
|
|
50
|
+
expected batch argument from execution opening. State/input keys and strides
|
|
51
|
+
remain descriptor metadata; command decoding and loops define their runtime
|
|
52
|
+
semantics, while finalization rejects unread state or input bytes.
|
|
53
|
+
- Removed the generic memory-backed `Reader` and `Readers` API from
|
|
54
|
+
`Codec.sol`. Fixed homogeneous memory streams now use absolute-position
|
|
55
|
+
`Memory` unpackers.
|
|
56
|
+
- Removed `Decoders.wrap` and the scanning `Decoders.batch` constructor.
|
|
57
|
+
`Decoders.open` now wraps any calldata source without initial checks,
|
|
58
|
+
including empty sources; explicit decoding defines structure and cardinality.
|
|
59
|
+
- Removed the unused `Cursors.pair`, `locate`, and `before` helpers. Cursor
|
|
60
|
+
pairs are packed directly where execution needs them.
|
|
61
|
+
- Replaced the cross-chain-ambiguous `#budget` block with the command-specific
|
|
62
|
+
`#cashout { uint amount }` block.
|
|
63
|
+
|
|
64
|
+
### Added
|
|
65
|
+
|
|
66
|
+
- Added the standard
|
|
67
|
+
`#bootstrap { bytes32 asset, uint amount, uint budget }` input block and
|
|
68
|
+
`Bootstrap` command. It uses the standard `DebitAccountHook` for each initial
|
|
69
|
+
balance and a dedicated `BootstrapBudgetHook` for native-value contributions,
|
|
70
|
+
including zero contributions. `BootstrapInternal` provides direct local
|
|
71
|
+
pipeline dispatch without a self-call.
|
|
72
|
+
- Added `Cashout`, its dedicated native-withdrawal hook, optimized
|
|
73
|
+
`CashoutInternal` dispatch, and the canonical `Actions.Cashout` annotation.
|
|
74
|
+
Added `Actions.Cashin` as its native-deposit counterpart.
|
|
75
|
+
- Added `utils/Errors.sol` as the canonical declaration source for all
|
|
76
|
+
utility-layer errors, preserving their existing signatures and selectors.
|
|
77
|
+
- Added hint-only `Blocks.runCount`, a minimal assembly scan that counts complete
|
|
78
|
+
consecutive keyed blocks without treating the result as structural validation.
|
|
79
|
+
- Added `Executions.takeRawState` for forwarding an intact state lane while
|
|
80
|
+
marking it consumed.
|
|
81
|
+
- Added symmetric `Executions.takeRawInput` for forwarding and consuming an
|
|
82
|
+
intact input lane.
|
|
83
|
+
- Added `Decoders.close` to reject unread bytes explicitly. Execution `finish`
|
|
84
|
+
and `close` apply the same invariant automatically.
|
|
85
|
+
- Added `Execution.close(extraCredit)` to combine trusted command-produced
|
|
86
|
+
credit with the execution's remaining value budget during finalization.
|
|
87
|
+
- Added `Memory.bounds` and specialized `unpackBalance`, `unpackDebt`,
|
|
88
|
+
`unpackPosition`, and `unpackTransaction` helpers for fixed-stride memory
|
|
89
|
+
block streams.
|
|
90
|
+
|
|
91
|
+
### Changed
|
|
92
|
+
|
|
93
|
+
- Replaced the unused checked `Cursors.wrap(source, flags, tag)` with the
|
|
94
|
+
two-argument packed calldata wrapper used by generic decoders. Removed the
|
|
95
|
+
duplicate private execution `openDecoder` implementation.
|
|
96
|
+
- Replaced the unused cursor item-count metadata with an optional one-byte
|
|
97
|
+
block stride. `Descriptors` now fully opens single or paired decoder cursors,
|
|
98
|
+
selects the active lane, derives the output allocation hint, and initializes
|
|
99
|
+
the writer cursor. Removed descriptor field accessors so packed layout
|
|
100
|
+
interpretation remains internal to the codec. Endpoint and command helpers
|
|
101
|
+
now construct `Execution` directly with the returned cursors and `msg.value`;
|
|
102
|
+
removed the descriptor-backed `Executions.open*` wrappers.
|
|
103
|
+
- Execution output writers now derive their initial capacity from an optimized
|
|
104
|
+
hint-only scan of the selected low decoder lane and grow as needed. Output
|
|
105
|
+
strides and size hints no longer impose a hard precomputed batch capacity.
|
|
106
|
+
- All buffers now grow beyond their initial capacity. Removed the `Growable`
|
|
107
|
+
cursor flag and the growth-policy booleans from buffer, writer, specification,
|
|
108
|
+
and descriptor allocation APIs.
|
|
109
|
+
- `Execution` now stores its sole output writer as a direct untagged cursor;
|
|
110
|
+
output reservation and finalization no longer perform lane selection.
|
|
111
|
+
- Execution traversal and unpack helpers now consume the active low decoder
|
|
112
|
+
lane without a lane argument. Mixed-lane commands select explicitly with
|
|
113
|
+
chainable `onstate()` and `oninput()` helpers. Paired executions use descriptor
|
|
114
|
+
metadata to place state low for state-only commands, which decode directly.
|
|
115
|
+
Relay commands select input explicitly before decoding their forwarded block.
|
|
116
|
+
- `Execution.close()` now finalizes output and drains the remaining budget as
|
|
117
|
+
`(bytes output, uint credit)`; commands return it directly without the former
|
|
118
|
+
`CommandBase.closeCommand` wrapper. Budget draining is inlined in `close()`.
|
|
119
|
+
- Internal debit processing now validates its fixed calldata stride once and
|
|
120
|
+
decodes each amount directly. Internal credit, settlement, repayment, and
|
|
121
|
+
pipeline transaction processing do the equivalent for memory streams.
|
|
122
|
+
- Pipeline step value is now checked and deducted directly from the scalar
|
|
123
|
+
budget, avoiding the generic budget-helper call in the dispatch loop. The
|
|
124
|
+
loop now also traverses absolute calldata bounds and unpacks STEP blocks
|
|
125
|
+
directly without allocating a decoder cursor.
|
|
126
|
+
- `Cursors` now performs packed construction, bounds, navigation, selection,
|
|
127
|
+
and consumption directly in each helper, avoiding nested internal-call
|
|
128
|
+
overhead across low-level decoding paths.
|
|
129
|
+
- `Blocks.expectKey` and the specialized dynamic leaf unpackers now validate
|
|
130
|
+
their headers directly, reducing composite decoding overhead.
|
|
131
|
+
- `Specs` and `Descriptors` now calculate hot-path counts and writer allocation
|
|
132
|
+
directly from their packed fields.
|
|
133
|
+
- Buffer reservation/finalization, fixed-size writer reservation, and execution
|
|
134
|
+
opening/output paths now operate directly on validated packed cursors.
|
|
135
|
+
|
|
11
136
|
## 1.25.0
|
|
12
137
|
|
|
13
138
|
### Breaking Changes
|
package/Codec.sol
CHANGED
|
@@ -11,8 +11,7 @@ import { Descriptors, Flags } from "./codec/Descriptors.sol";
|
|
|
11
11
|
import { Schemas } from "./codec/Schema.sol";
|
|
12
12
|
import { Decoders } from "./codec/Decoders.sol";
|
|
13
13
|
import { Cursors, Cur } from "./utils/Cursors.sol";
|
|
14
|
-
import {
|
|
15
|
-
import { Blocks } from "./codec/Blocks.sol";
|
|
14
|
+
import { Blocks, Memory } from "./codec/Blocks.sol";
|
|
16
15
|
import { Buffers } from "./codec/Buffers.sol";
|
|
17
16
|
import { Writer, Writers } from "./codec/Writers.sol";
|
|
18
17
|
|
package/Endpoints.sol
CHANGED
|
@@ -13,6 +13,8 @@ import {CreditAccountHook, DebitAccountHook, PostHook, RepayHook, SettleHook} fr
|
|
|
13
13
|
import {CommandBase} from "./commands/Base.sol";
|
|
14
14
|
import {Allocate, AllocateHook} from "./commands/Allocate.sol";
|
|
15
15
|
import {Burn, BurnHook} from "./commands/Burn.sol";
|
|
16
|
+
import {Bootstrap} from "./commands/Bootstrap.sol";
|
|
17
|
+
import {Cashout, CashoutHook, CashoutInternal} from "./commands/Cashout.sol";
|
|
16
18
|
import {CreditAccount, CreditAccountInternal} from "./commands/Credit.sol";
|
|
17
19
|
import {DebitAccount, DebitAccountInternal} from "./commands/Debit.sol";
|
|
18
20
|
import {Deposit, DepositHook, DepositPayable, DepositPayableHook} from "./commands/Deposit.sol";
|
package/README.md
CHANGED
|
@@ -135,8 +135,8 @@ A input is not a single struct; it is a run of blocks. One `#amount` block
|
|
|
135
135
|
asks for one deposit, five blocks ask for five, and the code path is identical
|
|
136
136
|
— every endpoint parses with a cursor and loops until the stream is exhausted.
|
|
137
137
|
The descriptor lane key is the prime item: it is the block type that may repeat
|
|
138
|
-
for batching.
|
|
139
|
-
is non-empty.
|
|
138
|
+
for batching. Descriptor decoding interprets a zero group byte as group size 1
|
|
139
|
+
when the lane is non-empty.
|
|
140
140
|
|
|
141
141
|
Off-chain, building a batch is concatenation. Using the reference encoders from
|
|
142
142
|
[`test/helpers/blocks.ts`](test/helpers/blocks.ts):
|
|
@@ -149,13 +149,12 @@ const input = concat([
|
|
|
149
149
|
encodeAmountBlock(usdc, 250_000_000n),
|
|
150
150
|
encodeAmountBlock(dai, 250n * 10n ** 18n),
|
|
151
151
|
]);
|
|
152
|
-
// deposit(input) returns two #balance blocks
|
|
153
|
-
// empty transaction output
|
|
152
|
+
// deposit(input) returns two #balance blocks and zero native budget credit
|
|
154
153
|
```
|
|
155
154
|
|
|
156
155
|
Everything downstream keeps this shape: commands loop over input blocks,
|
|
157
|
-
posting
|
|
158
|
-
never a special case.
|
|
156
|
+
posting ports loop over transactions, and pipelines loop over steps. Batching
|
|
157
|
+
is never a special case.
|
|
159
158
|
|
|
160
159
|
## IDs, Accounts, Assets, and Nodes
|
|
161
160
|
|
|
@@ -254,17 +253,19 @@ struct CommandContext {
|
|
|
254
253
|
}
|
|
255
254
|
```
|
|
256
255
|
|
|
257
|
-
Every command returns
|
|
258
|
-
next pipeline step,
|
|
259
|
-
|
|
260
|
-
|
|
256
|
+
Every command returns a `state` block stream and a trusted native `credit`.
|
|
257
|
+
State is threaded into the next pipeline step, while credit replenishes the
|
|
258
|
+
shared pipeline budget without validation against forwarded call value.
|
|
259
|
+
Command trust is the authority boundary.
|
|
261
260
|
|
|
262
261
|
State is linear, not optional ambient context. A command is responsible for
|
|
263
262
|
the entire state stream it receives: it must validate and consume it, transform
|
|
264
263
|
and return it, forward it intact, or revert. A command must never succeed while
|
|
265
|
-
silently ignoring or dropping supplied state.
|
|
266
|
-
|
|
267
|
-
|
|
264
|
+
silently ignoring or dropping supplied state. Descriptor schemas remain
|
|
265
|
+
discovery metadata; the command's decoding and loop implementation defines its
|
|
266
|
+
runtime lane semantics. A command that does not consume supplied state rejects
|
|
267
|
+
it when closing, while `takeRawState` explicitly consumes an intact forwarded
|
|
268
|
+
state lane.
|
|
268
269
|
This is especially important for `#debt` and `#position`, because dropping
|
|
269
270
|
either could silently discard an outstanding debt requirement.
|
|
270
271
|
|
|
@@ -275,6 +276,14 @@ next. Balance carries `{ asset, amount }`, debt carries `{ liability, debt }`,
|
|
|
275
276
|
and position carries their flat combination
|
|
276
277
|
`{ asset, amount, liability, debt }`.
|
|
277
278
|
|
|
279
|
+
Either side of a position may be absent. An absent asset side is encoded as
|
|
280
|
+
`asset = 0, amount = 0`; an absent liability side is encoded as
|
|
281
|
+
`liability = 0, debt = 0`. This mirrors transaction blocks, where a zero `from`
|
|
282
|
+
or `to` omits that side of the transfer. A one-sided position remains useful
|
|
283
|
+
when a command must preserve position-shaped state for later composition;
|
|
284
|
+
otherwise the narrower `#balance` or `#debt` block expresses the same live
|
|
285
|
+
value more directly.
|
|
286
|
+
|
|
278
287
|
`#debt` and `#position` are general live state rather than persisted
|
|
279
288
|
lending-specific debt records. Debt carries value owed or required; position
|
|
280
289
|
pairs that liability with value acquired or controlled. A command may preserve
|
|
@@ -285,22 +294,22 @@ claims, fees, netting, and other multi-step operations. Debt and position are
|
|
|
285
294
|
transient representations and do not themselves create or erase an obligation
|
|
286
295
|
recorded by an external system.
|
|
287
296
|
|
|
288
|
-
The standard `Deposit` mixin shows the canonical shape: open
|
|
289
|
-
|
|
297
|
+
The standard `Deposit` mixin shows the canonical shape: open the execution,
|
|
298
|
+
decode its active input lane, call the hook, and write the output run:
|
|
290
299
|
|
|
291
300
|
```solidity
|
|
292
301
|
function deposit(
|
|
293
302
|
bytes calldata context
|
|
294
|
-
) external onlyCommand returns (bytes memory,
|
|
295
|
-
Execution memory exec = openCommand(context, descriptor
|
|
303
|
+
) external onlyCommand returns (bytes memory, uint) {
|
|
304
|
+
Execution memory exec = openCommand(context, descriptor);
|
|
296
305
|
|
|
297
306
|
while (exec.more()) {
|
|
298
|
-
(bytes32 asset, uint amount) = exec.unpackAmount(
|
|
307
|
+
(bytes32 asset, uint amount) = exec.unpackAmount();
|
|
299
308
|
deposit(exec.account, asset, amount); // host policy hook
|
|
300
309
|
exec.outputBalance(asset, amount);
|
|
301
310
|
}
|
|
302
311
|
|
|
303
|
-
return
|
|
312
|
+
return exec.close();
|
|
304
313
|
}
|
|
305
314
|
```
|
|
306
315
|
|
|
@@ -313,19 +322,19 @@ abstract contract MyCommand is CommandBase {
|
|
|
313
322
|
uint private immutable descriptor;
|
|
314
323
|
|
|
315
324
|
constructor() {
|
|
316
|
-
(, descriptor) = command("myCommand", Specs.Empty, Specs.Amount, Specs.Balance, 0
|
|
325
|
+
(, descriptor) = command("myCommand", Specs.Empty, Specs.Amount, Specs.Balance, 0);
|
|
317
326
|
}
|
|
318
327
|
|
|
319
328
|
function myCommand(
|
|
320
329
|
bytes calldata context
|
|
321
|
-
) external onlyCommand returns (bytes memory,
|
|
322
|
-
Execution memory exec = openCommand(context, descriptor
|
|
330
|
+
) external onlyCommand returns (bytes memory, uint) {
|
|
331
|
+
Execution memory exec = openCommand(context, descriptor);
|
|
323
332
|
while (exec.more()) {
|
|
324
|
-
(bytes32 asset, uint amount) = exec.unpackAmount(
|
|
333
|
+
(bytes32 asset, uint amount) = exec.unpackAmount();
|
|
325
334
|
// Apply command-specific behavior for this group.
|
|
326
335
|
exec.outputBalance(asset, amount);
|
|
327
336
|
}
|
|
328
|
-
return
|
|
337
|
+
return exec.close();
|
|
329
338
|
}
|
|
330
339
|
}
|
|
331
340
|
```
|
|
@@ -336,7 +345,9 @@ or compose values such as `Flags.Funded`, `Flags.Admin`, and
|
|
|
336
345
|
and 7 are reserved for endpoint-defined custom flags. Bits 2 through 5 remain
|
|
337
346
|
reserved for future protocol flags.
|
|
338
347
|
|
|
339
|
-
The standard commands cover the common ledger movements: `
|
|
348
|
+
The standard commands cover the common ledger movements: `bootstrap` (source
|
|
349
|
+
an initial balance and native-value budget), `cashout` (withdraw a requested
|
|
350
|
+
native-asset amount), `deposit` and
|
|
340
351
|
`depositPayable` (external funds in), `settlePayable` (funded settlement),
|
|
341
352
|
`withdraw` and `burn` (funds out),
|
|
342
353
|
`debitAccount` and `creditAccount` (internal movements), `payout` (deliver
|
|
@@ -354,53 +365,64 @@ A single command is rarely the whole story. A pipeline is a run of `#step`
|
|
|
354
365
|
blocks executed in order within one transaction:
|
|
355
366
|
|
|
356
367
|
```txt
|
|
357
|
-
step { uint cmd,
|
|
368
|
+
step { uint cmd, uint128 value, #bytes as input }
|
|
358
369
|
```
|
|
359
370
|
|
|
360
|
-
Each step names a command, the
|
|
371
|
+
Each step names a command, the native value it may spend, and its input.
|
|
361
372
|
The returned state threads into the next command and the final state must be
|
|
362
|
-
empty.
|
|
363
|
-
|
|
364
|
-
|
|
373
|
+
empty. Each returned native credit replenishes the budget before running the
|
|
374
|
+
next step, allowing one command to fund later commands. The standard
|
|
375
|
+
`bootstrap` command consumes a stream of
|
|
376
|
+
`#bootstrap { bytes32 asset, uint amount, uint budget }` requests and atomically
|
|
377
|
+
debits each asset through the standard account hook, introduces matching
|
|
378
|
+
`#balance` state, and debits each nonzero budget contribution from the account's
|
|
379
|
+
native asset through the same hook. Its pipeline-local implementation uses assigned step value first when
|
|
380
|
+
bootstrapping the native asset, debits any remainder from the account, and
|
|
381
|
+
returns unused assigned value as credit. Bootstrap is registered with command
|
|
382
|
+
metadata but is only executable through local pipeline dispatch. This is the core of
|
|
383
|
+
`Pipeline.pipe`:
|
|
365
384
|
|
|
366
385
|
```solidity
|
|
367
386
|
while (cur.more()) {
|
|
368
|
-
(uint cmd,
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
(state,
|
|
387
|
+
(uint cmd, uint128 value, bytes calldata input) = cur.unpackStep();
|
|
388
|
+
if (budget < value) revert InsufficientValue();
|
|
389
|
+
unchecked { budget -= value; }
|
|
390
|
+
uint credit;
|
|
391
|
+
(state, credit) = dispatch(
|
|
373
392
|
cmd,
|
|
374
393
|
account,
|
|
375
394
|
state,
|
|
376
395
|
input,
|
|
377
396
|
value
|
|
378
397
|
);
|
|
379
|
-
|
|
380
|
-
(bytes32 from, bytes32 to, bytes32 asset, uint amount) = transactions.unpackTransaction();
|
|
381
|
-
post(from, to, asset, amount);
|
|
382
|
-
}
|
|
398
|
+
budget += credit;
|
|
383
399
|
}
|
|
384
400
|
if (state.length != 0) revert UnexpectedState();
|
|
385
401
|
```
|
|
386
402
|
|
|
387
403
|
`Pipeline.pipe` takes the available native-value budget as a `uint` and returns
|
|
388
|
-
the remaining budget after every step has executed.
|
|
404
|
+
the remaining budget after every step has executed. The enclosing entrypoint
|
|
405
|
+
settles that final value once.
|
|
389
406
|
|
|
390
407
|
A transfer, for instance, is a two-step pipeline: `debitAccount` turns an
|
|
391
408
|
`#amount` input into `#balance` state, and `payout` consumes that state
|
|
392
409
|
toward a recipient. Because a pipeline is just blocks, it is also the unit of
|
|
393
|
-
command batching
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
Hosts that implement a pipeline locally can inherit `
|
|
398
|
-
`
|
|
399
|
-
|
|
410
|
+
command batching. A step's `uint128 value` is drawn directly from the shared
|
|
411
|
+
native-value budget. Transport envelopes retain separate chain-specific
|
|
412
|
+
`resources` fields for adapters that also need gas or runtime parameters.
|
|
413
|
+
|
|
414
|
+
Hosts that implement a pipeline locally can inherit `Bootstrap`,
|
|
415
|
+
`CashoutInternal`, `DebitAccountInternal`, `CreditAccountInternal`,
|
|
416
|
+
`SettleInternal`, and
|
|
417
|
+
`RepayInternal` to register canonical command metadata while routing
|
|
418
|
+
their local command IDs through `executeBootstrap`, `executeCashout`,
|
|
400
419
|
`executeDebitAccount`, `executeCreditAccount`, `executeSettle`, and
|
|
401
|
-
`executeRepay`.
|
|
402
|
-
|
|
403
|
-
|
|
420
|
+
`executeRepay`. The bootstrap, cashout, and debit adapters decode fixed-stride
|
|
421
|
+
calldata input directly; the other three
|
|
422
|
+
decode memory-backed pipeline state. All avoid an external self-call. Pass the
|
|
423
|
+
step value into each adapter. Bootstrap is pipeline-local rather than an
|
|
424
|
+
externally callable command and may consume value for native-asset balance;
|
|
425
|
+
the other five reject nonzero value because those commands are non-funded.
|
|
404
426
|
|
|
405
427
|
Positions also support backward-composed pipelines. In an exact-output route,
|
|
406
428
|
the asset side can represent the desired result while the liability side
|
|
@@ -493,7 +515,7 @@ Import from the package entry points rather than deep paths:
|
|
|
493
515
|
- `@rootzero/contracts/Endpoints.sol` — command, admin, port, guard, and query
|
|
494
516
|
mixins, their hooks (including `PipeHook`), and `Flags`
|
|
495
517
|
- `@rootzero/contracts/Codec.sol` — `Blocks`, calldata `Cur`/`Cursors`, memory
|
|
496
|
-
`
|
|
518
|
+
`Memory`, `Writers`, `Schemas`, `Descriptors`, `Flags`, `Keys`, and
|
|
497
519
|
`Specs`
|
|
498
520
|
- `@rootzero/contracts/Utils.sol` — `Ids`, `Nodes`, `Assets`, `Accounts`,
|
|
499
521
|
layout and value helpers
|
package/Utils.sol
CHANGED
|
@@ -12,7 +12,8 @@ import { ECDSA } from "./utils/ECDSA.sol";
|
|
|
12
12
|
import { Ids } from "./utils/Ids.sol";
|
|
13
13
|
import { Nodes } from "./utils/Nodes.sol";
|
|
14
14
|
import { Layout } from "./utils/Layout.sol";
|
|
15
|
-
import {
|
|
15
|
+
import { BadAmount, InsufficientValue, InvalidAccount, InvalidAsset, InvalidContract, InvalidId, InvalidPreimage, MissingCursor, NotDivisible, OutOfBounds, UnauthorizedAsset, UnconsumedData, UnexpectedPosition, ValueOverflow, ZeroAddress, ZeroAmount} from "./utils/Errors.sol";
|
|
16
|
+
import { addrOr, applyBps, beforeBps, bytes32ToInt, bytes32ToString, clear8, clear16, clear32, clear64, divisible, ensureAddr, ensureContract, hash32, intToBytes32, isFamily, matchesBase, MAX_BPS, max8, max16, max24, max32, max40, max64, max96, max128, max160, replace8, replace16, replace32, replace64, retryTicket, toLocalBase, toUnspecifiedBase } from "./utils/Utils.sol";
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
|