@rootzero/contracts 1.13.0 → 1.14.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 +45 -3
- package/Codec.sol +21 -0
- package/Commands.sol +14 -0
- package/Core.sol +2 -3
- package/Endpoints.sol +1 -5
- package/README.md +34 -30
- package/Utils.sol +2 -4
- package/codec/Blocks.sol +1606 -0
- package/codec/Buffers.sol +165 -0
- package/codec/Decoders.sol +558 -0
- package/codec/Descriptors.sol +124 -0
- package/{blocks → codec}/Keys.sol +4 -16
- package/codec/Readers.sol +114 -0
- package/{blocks → codec}/Schema.sol +38 -80
- package/codec/Specs.sol +218 -0
- package/codec/Writers.sol +487 -0
- package/commands/Allocate.sol +21 -20
- package/commands/Base.sol +71 -37
- package/commands/Burn.sol +18 -13
- package/commands/Credit.sol +21 -20
- package/commands/Debit.sol +25 -28
- package/commands/Deposit.sol +34 -35
- package/commands/Payout.sol +21 -15
- package/commands/Provision.sol +37 -38
- package/commands/Recover.sol +20 -19
- package/commands/Relay.sol +24 -22
- package/commands/Withdraw.sol +15 -18
- package/commands/admin/AllowAssets.sol +19 -16
- package/commands/admin/Allowance.sol +18 -13
- package/commands/admin/Appoint.sol +17 -15
- package/commands/admin/Authorize.sol +23 -14
- package/commands/admin/Base.sol +1 -1
- package/commands/admin/DenyAssets.sol +19 -16
- package/commands/admin/Dismiss.sol +17 -15
- package/commands/admin/Execute.sol +20 -19
- package/commands/admin/Label.sol +17 -13
- package/commands/admin/Schemas.sol +18 -14
- package/commands/admin/Unauthorize.sol +23 -14
- package/core/Calls.sol +3 -11
- package/core/Endpoint.sol +42 -127
- package/core/Pipeline.sol +16 -15
- package/core/Types.sol +1 -1
- package/docs/Schema.md +35 -29
- package/events/Endpoint.sol +2 -2
- package/events/Schema.sol +5 -5
- package/execution/Budget.sol +40 -0
- package/execution/Execution.sol +1083 -0
- package/guards/Base.sol +8 -9
- package/guards/Revoke.sol +11 -9
- package/package.json +1 -1
- package/ports/AllowAssets.sol +12 -15
- package/ports/Allowance.sol +11 -9
- package/ports/Base.sol +18 -11
- package/ports/Credit.sol +11 -9
- package/ports/Debit.sol +11 -9
- package/ports/DenyAssets.sol +10 -13
- package/ports/Dispatch.sol +13 -15
- package/ports/Pipe.sol +14 -12
- package/ports/Redeem.sol +12 -9
- package/ports/Settle.sol +11 -9
- package/queries/Assets.sol +15 -15
- package/queries/Balances.sol +17 -17
- package/queries/Base.sol +11 -12
- package/utils/Actions.sol +1 -0
- package/utils/Cursors.sol +308 -0
- package/utils/Lanes.sol +14 -0
- package/utils/Selectors.sol +2 -2
- package/utils/Utils.sol +46 -0
- package/Cursors.sol +0 -16
- package/blocks/Cursors.sol +0 -1529
- package/blocks/Writers.sol +0 -1036
- package/core/Payable.sol +0 -53
- package/utils/Value.sol +0 -43
package/docs/Schema.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Schema
|
|
2
2
|
|
|
3
|
-
Rootzero
|
|
3
|
+
Rootzero input and response data is encoded as a stream of typed blocks. A
|
|
4
4
|
schema string describes the payload body for discovery events and tooling; the
|
|
5
5
|
runtime block key is the compact type tag that identifies that payload layout in
|
|
6
6
|
the active schema context. The block alias is published separately from the
|
|
@@ -30,7 +30,7 @@ are opaque `bytes4` tags and only need to be unique in the context where they ar
|
|
|
30
30
|
used. A host can publish the meaning of a custom key with:
|
|
31
31
|
|
|
32
32
|
```solidity
|
|
33
|
-
event Schema(uint indexed host,
|
|
33
|
+
event Schema(uint indexed host, uint spec, string body, bytes32 name);
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
For example, a host-specific payment block can use a small literal, the command
|
|
@@ -50,7 +50,7 @@ schema: { bytes32 asset, uint amount }
|
|
|
50
50
|
A block body can reference another block alias as a child item with `#`:
|
|
51
51
|
|
|
52
52
|
```txt
|
|
53
|
-
{ bytes32 account, #bytes as state, #bytes as
|
|
53
|
+
{ bytes32 account, #bytes as state, #bytes as input }
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
The empty schema string `""` means the block has no structured payload. This is
|
|
@@ -72,8 +72,8 @@ length, fixed fields may appear before, after, or between child blocks.
|
|
|
72
72
|
|
|
73
73
|
```txt
|
|
74
74
|
{ uint target, uint resources, #bytes as payload }
|
|
75
|
-
{ bytes32 account, #bytes as state, #bytes as
|
|
76
|
-
{
|
|
75
|
+
{ bytes32 account, #bytes as state, #bytes as input }
|
|
76
|
+
{ uint spec, #string as body, bytes32 name }
|
|
77
77
|
{ #bytes as left, uint op, #bytes as right }
|
|
78
78
|
```
|
|
79
79
|
|
|
@@ -108,24 +108,30 @@ generic list block; it does not repeat the item in place.
|
|
|
108
108
|
## Endpoint Lanes
|
|
109
109
|
|
|
110
110
|
Endpoint descriptors identify each lane with a block key and group size. In
|
|
111
|
-
Solidity, endpoint definition helpers accept
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
has no blocks in that lane. Use
|
|
116
|
-
`group(lane, size)` when a lane needs an explicit group size other than 1.
|
|
111
|
+
Solidity, endpoint definition helpers accept block specs such as `Specs.Amount`.
|
|
112
|
+
A zero group is interpreted as group size 1, while `Specs.Empty` means the
|
|
113
|
+
endpoint has no blocks in that lane. Use `group(spec, size)` when a lane needs
|
|
114
|
+
an explicit group size other than 1.
|
|
117
115
|
|
|
118
|
-
The packed descriptor
|
|
116
|
+
The packed descriptor uses these lane layouts:
|
|
119
117
|
|
|
120
118
|
```txt
|
|
121
|
-
[key
|
|
119
|
+
state [key:4][group:1]
|
|
120
|
+
input [key:4][item:4][group:1]
|
|
121
|
+
output [key:4][min:4][max:4][hint:4][group:1]
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
contained
|
|
128
|
-
with
|
|
124
|
+
Containers are exclusive to input. A plain input spec is compressed into
|
|
125
|
+
`[spec.key][0]`. A spec with a nonzero container is compressed into
|
|
126
|
+
`[spec.container][spec.key]`: the container is the top-level wire key and the
|
|
127
|
+
item is its contained block key. The built-in `many(spec)` helper annotates the
|
|
128
|
+
spec with `Specs.List` as its container, matching the DSL form `many #item`.
|
|
129
|
+
Output lanes retain their size bounds and allocation hint so execution can
|
|
130
|
+
reconstruct the output spec and initialize its writer directly. The Solidity
|
|
131
|
+
output decoder returns this as a left-aligned, writer-ready spec that retains
|
|
132
|
+
its encoded group. Its container and reserved fields are cleared. `Specs.group`
|
|
133
|
+
returns the effective group, interpreting an encoded zero as one for a
|
|
134
|
+
non-empty spec.
|
|
129
135
|
|
|
130
136
|
Any non-empty lane resolves its key to a block alias and schema body through the
|
|
131
137
|
active schema context. If the item slot is nonzero, tooling also resolves that
|
|
@@ -299,33 +305,33 @@ invalid in any path segment.
|
|
|
299
305
|
- `#string`: UTF-8 string bytes, written without a body
|
|
300
306
|
- `#list`: generic list wrapper emitted by `many`
|
|
301
307
|
|
|
302
|
-
Custom input shapes should define their own context-local block
|
|
303
|
-
|
|
304
|
-
that
|
|
308
|
+
Custom input shapes should define their own context-local block spec and publish
|
|
309
|
+
it with a `Schema` event. Endpoint contracts can use `schema(...)` to construct
|
|
310
|
+
and publish that spec:
|
|
305
311
|
|
|
306
312
|
```solidity
|
|
307
|
-
|
|
313
|
+
uint input = schema(1, 64, 64, 64, "{ bytes32 asset, uint amount }", bytes32(0));
|
|
308
314
|
```
|
|
309
315
|
|
|
310
316
|
Use different numeric keys when a host needs more than one local block key. The
|
|
311
317
|
key can also be a selector or any other `bytes4` value that is unique in the
|
|
312
|
-
context where it is used. The
|
|
313
|
-
|
|
318
|
+
context where it is used. The numeric arguments after the key are the minimum,
|
|
319
|
+
maximum, and allocation hint payload sizes. The alias names the block; the
|
|
320
|
+
schema string describes only the payload body.
|
|
314
321
|
|
|
315
322
|
## Standard Blocks
|
|
316
323
|
|
|
317
|
-
Common protocol schemas live in `contracts/
|
|
324
|
+
Common protocol schemas live in `contracts/codec/Schema.sol`:
|
|
318
325
|
|
|
319
326
|
```txt
|
|
320
327
|
amount { bytes32 asset, uint amount }
|
|
321
328
|
balance { bytes32 asset, uint amount }
|
|
322
329
|
custody { uint host, bytes32 asset, uint amount }
|
|
323
330
|
call { uint target, uint resources, #bytes as payload }
|
|
324
|
-
step { uint
|
|
325
|
-
context { bytes32 account, #bytes as state, #bytes as
|
|
331
|
+
step { uint cmd, uint resources, #bytes as input }
|
|
332
|
+
context { bytes32 account, #bytes as state, #bytes as input }
|
|
326
333
|
recover { uint handler, uint resources, bytes32 key, #bytes as witness }
|
|
327
|
-
|
|
328
|
-
schema { bytes4 key, #string as body, bytes32 name }
|
|
334
|
+
schema { uint spec, #string as body, bytes32 name }
|
|
329
335
|
```
|
|
330
336
|
|
|
331
337
|
`Keys.sol` contains the corresponding standard runtime keys.
|
package/events/Endpoint.sol
CHANGED
|
@@ -6,12 +6,12 @@ import {EventEmitter} from "./Emitter.sol";
|
|
|
6
6
|
/// @title EndpointEvent
|
|
7
7
|
/// @notice Emitted during host deployment to publish a callable endpoint descriptor.
|
|
8
8
|
abstract contract EndpointEvent is EventEmitter {
|
|
9
|
-
string private constant ABI = "event Endpoint(uint indexed host, uint id,
|
|
9
|
+
string private constant ABI = "event Endpoint(uint indexed host, uint id, uint descriptor)";
|
|
10
10
|
|
|
11
11
|
/// @param host Host node ID that exposes the endpoint.
|
|
12
12
|
/// @param id Endpoint node ID.
|
|
13
13
|
/// @param descriptor Packed endpoint lane metadata and flags.
|
|
14
|
-
event Endpoint(uint indexed host, uint id,
|
|
14
|
+
event Endpoint(uint indexed host, uint id, uint descriptor);
|
|
15
15
|
|
|
16
16
|
constructor() {
|
|
17
17
|
emit EventAbi(ABI);
|
package/events/Schema.sol
CHANGED
|
@@ -4,18 +4,18 @@ pragma solidity ^0.8.33;
|
|
|
4
4
|
import {EventEmitter} from "./Emitter.sol";
|
|
5
5
|
|
|
6
6
|
/// @title SchemaEvent
|
|
7
|
-
/// @notice Emitted during host deployment to publish a block
|
|
7
|
+
/// @notice Emitted during host deployment to publish a block spec and payload schema.
|
|
8
8
|
/// Block keys are opaque `bytes4` tags. Standard protocol blocks use
|
|
9
9
|
/// keccak-derived keys by convention, but custom block keys only need to be
|
|
10
10
|
/// unique within the publishing host/schema context.
|
|
11
11
|
abstract contract SchemaEvent is EventEmitter {
|
|
12
|
-
string private constant ABI = "event Schema(uint indexed host,
|
|
12
|
+
string private constant ABI = "event Schema(uint indexed host, uint spec, string body, bytes32 name)";
|
|
13
13
|
|
|
14
14
|
/// @param host Host node ID that publishes this block schema.
|
|
15
|
-
/// @param
|
|
16
|
-
/// @param
|
|
15
|
+
/// @param spec Block specification being defined by `host`.
|
|
16
|
+
/// @param body Schema DSL string describing the block payload body.
|
|
17
17
|
/// @param name Optional block alias used by endpoint descriptors and nested schemas.
|
|
18
|
-
event Schema(uint indexed host,
|
|
18
|
+
event Schema(uint indexed host, uint spec, string body, bytes32 name);
|
|
19
19
|
|
|
20
20
|
constructor() {
|
|
21
21
|
emit EventAbi(ABI);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
/// @notice Mutable native-value budget shared across internal calls.
|
|
5
|
+
struct Budget {
|
|
6
|
+
/// @dev Remaining unspent native value in wei.
|
|
7
|
+
uint remaining;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/// @title Budgets
|
|
11
|
+
/// @notice Opening and mutation helpers for standalone native-value budgets.
|
|
12
|
+
library Budgets {
|
|
13
|
+
/// @dev Thrown when an operation attempts to spend more value than remains.
|
|
14
|
+
error InsufficientValue();
|
|
15
|
+
|
|
16
|
+
/// @notice Open a standalone budget containing the current call value.
|
|
17
|
+
/// @return budget Budget initialized with `msg.value`.
|
|
18
|
+
function open() internal view returns (Budget memory budget) {
|
|
19
|
+
budget.remaining = msg.value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/// @notice Deduct the EVM value lane of `resources` from `budget`.
|
|
23
|
+
/// @dev EVM resources use the low 128 bits as native value/endowment.
|
|
24
|
+
/// @param budget Mutable budget to debit.
|
|
25
|
+
/// @param resources Packed resources whose low 128 bits contain native value.
|
|
26
|
+
/// @return value Native value to forward in wei.
|
|
27
|
+
function use(Budget memory budget, uint resources) internal pure returns (uint128 value) {
|
|
28
|
+
value = uint128(resources);
|
|
29
|
+
if (value > budget.remaining) revert InsufficientValue();
|
|
30
|
+
budget.remaining -= value;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/// @notice Remove and return all remaining value from `budget`.
|
|
34
|
+
/// @param budget Mutable budget to drain.
|
|
35
|
+
/// @return value Native value removed from the budget.
|
|
36
|
+
function drain(Budget memory budget) internal pure returns (uint value) {
|
|
37
|
+
value = budget.remaining;
|
|
38
|
+
budget.remaining = 0;
|
|
39
|
+
}
|
|
40
|
+
}
|