@rootzero/contracts 1.13.0 → 1.15.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.
Files changed (86) hide show
  1. package/CHANGELOG.md +87 -3
  2. package/Codec.sol +21 -0
  3. package/Commands.sol +14 -0
  4. package/Core.sol +8 -6
  5. package/Endpoints.sol +2 -7
  6. package/Events.sol +1 -2
  7. package/README.md +70 -37
  8. package/Utils.sol +2 -4
  9. package/annotations/Action.sol +17 -0
  10. package/annotations/Label.sol +23 -0
  11. package/annotations/Schema.sol +53 -0
  12. package/codec/Blocks.sol +1643 -0
  13. package/codec/Buffers.sol +165 -0
  14. package/codec/Decoders.sol +570 -0
  15. package/codec/Descriptors.sol +124 -0
  16. package/{blocks → codec}/Keys.sol +10 -18
  17. package/codec/Readers.sol +114 -0
  18. package/{blocks → codec}/Schema.sol +43 -80
  19. package/codec/Specs.sol +240 -0
  20. package/codec/Writers.sol +485 -0
  21. package/commands/Allocate.sol +21 -20
  22. package/commands/Base.sol +83 -45
  23. package/commands/Burn.sol +23 -14
  24. package/commands/Credit.sol +21 -20
  25. package/commands/Debit.sol +25 -28
  26. package/commands/Deposit.sol +41 -36
  27. package/commands/Payout.sol +26 -16
  28. package/commands/Provision.sol +37 -38
  29. package/commands/Recover.sol +20 -19
  30. package/commands/Relay.sol +24 -22
  31. package/commands/Withdraw.sol +20 -19
  32. package/commands/admin/AllowAssets.sol +19 -16
  33. package/commands/admin/Allowance.sol +18 -13
  34. package/commands/admin/Annotate.sol +36 -0
  35. package/commands/admin/Appoint.sol +19 -16
  36. package/commands/admin/Authorize.sol +23 -14
  37. package/commands/admin/Base.sol +9 -2
  38. package/commands/admin/DenyAssets.sol +19 -16
  39. package/commands/admin/Dismiss.sol +19 -16
  40. package/commands/admin/Execute.sol +21 -19
  41. package/commands/admin/Unauthorize.sol +23 -14
  42. package/core/Access.sol +91 -49
  43. package/core/Calls.sol +30 -33
  44. package/core/Endpoint.sol +46 -143
  45. package/core/Host.sol +63 -21
  46. package/core/Pipeline.sol +16 -15
  47. package/core/Types.sol +1 -1
  48. package/docs/Schema.md +48 -31
  49. package/events/Annotation.sol +24 -0
  50. package/events/Endpoint.sol +2 -2
  51. package/events/Guardian.sol +2 -2
  52. package/events/Introduction.sol +3 -2
  53. package/execution/Budget.sol +40 -0
  54. package/execution/Execution.sol +1104 -0
  55. package/guards/Base.sol +11 -12
  56. package/guards/Revoke.sol +11 -9
  57. package/package.json +1 -1
  58. package/ports/AllowAssets.sol +12 -15
  59. package/ports/Allowance.sol +11 -9
  60. package/ports/Base.sol +35 -16
  61. package/ports/Credit.sol +11 -9
  62. package/ports/Debit.sol +11 -9
  63. package/ports/DenyAssets.sol +10 -13
  64. package/ports/Dispatch.sol +13 -15
  65. package/ports/Pipe.sol +14 -12
  66. package/ports/Redeem.sol +12 -9
  67. package/ports/Settle.sol +16 -10
  68. package/queries/Assets.sol +15 -15
  69. package/queries/Balances.sol +17 -17
  70. package/queries/Base.sol +26 -12
  71. package/utils/Accounts.sol +0 -23
  72. package/utils/Actions.sol +1 -0
  73. package/utils/Cursors.sol +367 -0
  74. package/utils/Lanes.sol +14 -0
  75. package/utils/Layout.sol +0 -2
  76. package/utils/Selectors.sol +2 -2
  77. package/utils/Utils.sol +46 -0
  78. package/Cursors.sol +0 -16
  79. package/blocks/Cursors.sol +0 -1529
  80. package/blocks/Writers.sol +0 -1036
  81. package/commands/admin/Label.sol +0 -32
  82. package/commands/admin/Schemas.sol +0 -32
  83. package/core/Payable.sol +0 -53
  84. package/events/Labeled.sol +0 -21
  85. package/events/Schema.sol +0 -23
  86. package/utils/Value.sol +0 -43
@@ -1,12 +1,8 @@
1
1
  // SPDX-License-Identifier: GPL-3.0-only
2
2
  pragma solidity ^0.8.33;
3
3
 
4
- import {CommandContext, CommandBase, Keys} from "./Base.sol";
5
- import {Payable} from "../core/Payable.sol";
6
- import {HostAmount, Cursors, Cur, Writer, Writers} from "../Cursors.sol";
7
- import {Budget} from "../utils/Value.sol";
8
- using Cursors for Cur;
9
- using Writers for Writer;
4
+ import {Execution, Executions, CommandBase, HostAmount, Lanes, Specs} from "./Base.sol";
5
+ using Executions for Execution;
10
6
 
11
7
  /// @notice Shared provision hook used by `Provision`.
12
8
  abstract contract ProvisionHook {
@@ -25,67 +21,70 @@ abstract contract ProvisionPayableHook {
25
21
  /// side effect (e.g. transfer or record); output blocks are written by the caller.
26
22
  /// @param account Caller's account identifier.
27
23
  /// @param allocation Host-scoped amount to provision.
28
- /// @param budget Mutable native-value budget drawn from `msg.value`.
29
- function provision(bytes32 account, HostAmount memory allocation, Budget memory budget) internal virtual;
24
+ /// @param funds Mutable execution used only for its remaining native-value budget.
25
+ function provision(bytes32 account, HostAmount memory allocation, Execution memory funds) internal virtual;
30
26
  }
31
27
 
32
28
  /// @title Provision
33
- /// @notice Command that provisions assets to peer hosts from ALLOCATION request blocks.
34
- /// Each request block supplies the target host plus an asset amount; the output is a CUSTODY state stream.
29
+ /// @notice Command that provisions assets to peer hosts from ALLOCATION input blocks.
30
+ /// Each input block supplies the target host plus an asset amount; the output is a CUSTODY state stream.
35
31
  abstract contract Provision is CommandBase, ProvisionHook {
36
- bytes32 private immutable descriptor;
32
+ uint private immutable descriptor;
37
33
 
38
34
  constructor() {
39
- (, descriptor) = command("provision", Keys.Empty, Keys.Allocation, Keys.Custody, 0, false, false);
35
+ (, descriptor) = command("provision", Specs.Empty, Specs.Allocation, Specs.Custody, 0, false, false);
40
36
  }
41
37
 
42
- /// @notice Provision ALLOCATION request blocks and output matching CUSTODY state blocks.
43
- /// @param c Command context; `c.input` must contain ALLOCATION blocks.
38
+ /// @notice Provision ALLOCATION input blocks and output matching CUSTODY state blocks.
39
+ /// @param input ALLOCATION block stream.
44
40
  /// @return CUSTODY block stream matching the provisioned allocations.
45
41
  /// @return Empty transaction stream.
46
- function provision(CommandContext calldata c) external onlyCommand returns (bytes memory, bytes memory) {
47
- (Cur memory input, uint outputs) = openInput(c.input, descriptor);
48
- Writer memory output = Writers.allocCustodies(outputs);
42
+ function provision(
43
+ bytes32 account,
44
+ bytes calldata,
45
+ bytes calldata input
46
+ ) external onlyCommand returns (bytes memory, bytes memory) {
47
+ Execution memory exec = openInput(input, descriptor, 0);
49
48
 
50
- while (input.i < input.len) {
51
- HostAmount memory allocation = input.unpackAllocationValue();
52
- provision(c.account, allocation);
53
- output.appendCustody(allocation);
49
+ while (exec.more()) {
50
+ HostAmount memory allocation = exec.unpackAllocationValue(Lanes.Input);
51
+ provision(account, allocation);
52
+ exec.outputCustody(allocation);
54
53
  }
55
54
 
56
- return (output.finish(), "");
55
+ return close(exec, account);
57
56
  }
58
57
  }
59
58
 
60
59
  /// @title ProvisionPayable
61
- /// @notice Command that provisions assets to peer hosts from ALLOCATION request blocks.
62
- /// Each request block supplies the target host plus an asset amount; the output is a CUSTODY state stream.
60
+ /// @notice Command that provisions assets to peer hosts from ALLOCATION input blocks.
61
+ /// Each input block supplies the target host plus an asset amount; the output is a CUSTODY state stream.
63
62
  /// The hook receives a mutable native-value budget drawn from `msg.value`.
64
- abstract contract ProvisionPayable is CommandBase, Payable, ProvisionPayableHook {
65
- bytes32 private immutable descriptor;
63
+ abstract contract ProvisionPayable is CommandBase, ProvisionPayableHook {
64
+ uint private immutable descriptor;
66
65
 
67
66
  constructor() {
68
- (, descriptor) = command("provisionPayable", Keys.Empty, Keys.Allocation, Keys.Custody, 0, true, false);
67
+ (, descriptor) = command("provisionPayable", Specs.Empty, Specs.Allocation, Specs.Custody, 0, true, false);
69
68
  }
70
69
 
71
- /// @notice Provision ALLOCATION request blocks with access to a mutable native-value budget.
72
- /// @param c Command context; `c.input` must contain ALLOCATION blocks.
70
+ /// @notice Provision ALLOCATION input blocks with access to a mutable native-value budget.
71
+ /// @param input ALLOCATION block stream.
73
72
  /// @return CUSTODY block stream matching the provisioned allocations.
74
73
  /// @return Remaining native value as a refund transaction stream.
75
74
  function provisionPayable(
76
- CommandContext calldata c
75
+ bytes32 account,
76
+ bytes calldata,
77
+ bytes calldata input
77
78
  ) external payable onlyCommand returns (bytes memory, bytes memory) {
78
- (Cur memory input, uint outputs) = openInput(c.input, descriptor);
79
- Writer memory output = Writers.allocCustodies(outputs);
80
- Budget memory budget = openValue();
79
+ Execution memory exec = openInput(input, descriptor, 0);
81
80
 
82
- while (input.i < input.len) {
83
- HostAmount memory allocation = input.unpackAllocationValue();
84
- provision(c.account, allocation, budget);
85
- output.appendCustody(allocation);
81
+ while (exec.more()) {
82
+ HostAmount memory allocation = exec.unpackAllocationValue(Lanes.Input);
83
+ provision(account, allocation, exec);
84
+ exec.outputCustody(allocation);
86
85
  }
87
86
 
88
- return (output.finish(), closeValue(budget, c.account));
87
+ return close(exec, account);
89
88
  }
90
89
  }
91
90
 
@@ -1,13 +1,11 @@
1
1
  // SPDX-License-Identifier: GPL-3.0-only
2
2
  pragma solidity ^0.8.33;
3
3
 
4
- import {CommandBase, CommandContext, Keys} from "./Base.sol";
5
- import {Payable} from "../core/Payable.sol";
6
- import {Cursors, Cur} from "../Cursors.sol";
7
- import {Budget} from "../utils/Value.sol";
4
+ import {Execution, Executions, CommandBase, Lanes, Specs} from "./Base.sol";
8
5
 
9
- using Cursors for Cur;
6
+ using Executions for Execution;
10
7
 
8
+ /// @notice Hook implemented by hosts that recover previously undelivered payloads.
11
9
  abstract contract RecoverHook {
12
10
  /// @notice Override to recover a witness through `handler`.
13
11
  /// @param handler Port that should attempt recovery.
@@ -18,30 +16,33 @@ abstract contract RecoverHook {
18
16
  }
19
17
 
20
18
  /// @title RecoverPayable
21
- /// @notice Command that forwards recover request blocks to a virtual hook.
19
+ /// @notice Command that forwards recover input blocks to a virtual hook.
22
20
  /// Recovery is witness-driven: the command account pays and receives leftover
23
21
  /// value settlement, but the recovered subject is defined by each witness.
24
22
  /// Produces no output state.
25
- abstract contract RecoverPayable is CommandBase, Payable, RecoverHook {
26
- bytes32 private immutable descriptor;
23
+ abstract contract RecoverPayable is CommandBase, RecoverHook {
24
+ uint private immutable descriptor;
27
25
 
28
26
  constructor() {
29
- (, descriptor) = command("recoverPayable", Keys.Empty, Keys.Recover, Keys.Empty, 0, true, false);
27
+ (, descriptor) = command("recoverPayable", Specs.Empty, Specs.Recover, Specs.Empty, 0, true, false);
30
28
  }
31
29
 
32
- /// @notice Recover each recover block in the command request.
33
- /// @param c Command context; `c.input` must contain Recover blocks.
30
+ /// @notice Recover each recover block in the command input.
31
+ /// @param input RECOVER block stream.
34
32
  /// @return Empty output state.
35
33
  /// @return Remaining native value as a refund transaction stream.
36
- function recoverPayable(CommandContext calldata c) external payable onlyCommand returns (bytes memory, bytes memory) {
37
- (Cur memory input, ) = openInput(c.input, descriptor);
38
- Budget memory budget = openValue();
39
-
40
- while (input.i < input.len) {
41
- (uint handler, uint resources, bytes32 key, bytes calldata witness) = input.unpackRecover();
42
- recover(handler, key, witness, useValue(budget, resources));
34
+ function recoverPayable(
35
+ bytes32 account,
36
+ bytes calldata,
37
+ bytes calldata input
38
+ ) external payable onlyCommand returns (bytes memory, bytes memory) {
39
+ Execution memory exec = openInput(input, descriptor, 0);
40
+
41
+ while (exec.more()) {
42
+ (uint handler, uint resources, bytes32 key, bytes calldata witness) = exec.unpackRecover(Lanes.Input);
43
+ recover(handler, key, witness, exec.useValue(resources));
43
44
  }
44
45
 
45
- return ("", closeValue(budget, c.account));
46
+ return close(exec, account);
46
47
  }
47
48
  }
@@ -1,48 +1,50 @@
1
1
  // SPDX-License-Identifier: GPL-3.0-only
2
2
  pragma solidity ^0.8.33;
3
3
 
4
- import {CommandBase, CommandContext, Keys} from "./Base.sol";
5
- import {Lane} from "../core/Endpoint.sol";
6
- import {Payable} from "../core/Payable.sol";
7
- import {Cursors, Cur} from "../Cursors.sol";
8
- import {Budget} from "../utils/Value.sol";
4
+ import {Blocks, Execution, Executions, CommandBase, Lanes, Specs} from "./Base.sol";
9
5
 
10
- using Cursors for Cur;
6
+ using Executions for Execution;
11
7
 
8
+ /// @notice Hook implemented by hosts that route funded relay payloads.
12
9
  abstract contract RoutePayableHook {
13
10
  /// @notice Override to route an encoded payload through `portal`.
14
11
  /// @param portal Destination portal identifier, often the destination host ID.
15
12
  /// @param resources Chain-specific destination resources. EVM adapters
16
13
  /// may interpret this as packed execution gas and destination value.
17
14
  /// @param payload Encoded payload ready for the transport layer.
18
- /// @param budget Source native-value budget available for transport
15
+ /// @param funds Execution used only for source value available for transport
19
16
  /// fees and destination resource funding.
20
- function route(uint portal, uint resources, bytes memory payload, Budget memory budget) internal virtual;
17
+ function route(uint portal, uint resources, bytes memory payload, Execution memory funds) internal virtual;
21
18
  }
22
19
 
23
20
  /// @title RelayPayable
24
21
  /// @notice Command that forwards one RELAY block to a host-defined relay hook.
25
- /// Reverts unless the request contains exactly one RELAY block, preventing
22
+ /// Reverts unless the input contains exactly one RELAY block, preventing
26
23
  /// the same state from being duplicated across multiple relays.
27
24
  /// Produces no output state.
28
- abstract contract RelayPayable is CommandBase, Payable, RoutePayableHook {
29
- bytes32 private immutable descriptor;
25
+ abstract contract RelayPayable is CommandBase, RoutePayableHook {
26
+ uint private immutable descriptor;
30
27
 
31
28
  constructor() {
32
- (, descriptor) = command("relayPayable", Keys.Any, Keys.Relay, Keys.Empty, 0, true, false);
29
+ (, descriptor) = command("relayPayable", Specs.Any, Specs.Relay, Specs.Empty, 0, true, false);
33
30
  }
34
31
 
35
- /// @notice Relay one RELAY request block with the command account and current state.
36
- /// @param c Command context; `c.input` must contain exactly one RELAY block.
32
+ /// @notice Relay one RELAY input block with the command account and current state.
33
+ /// @param state State forwarded into the destination context.
34
+ /// @param input Exactly one RELAY block.
37
35
  /// @return Empty output state.
38
36
  /// @return Remaining native value as a refund transaction stream.
39
- function relayPayable(CommandContext calldata c) external payable onlyCommand returns (bytes memory, bytes memory) {
40
- (Cur memory input, , ) = openLane(c.input, descriptor, Lane.Input, 1);
41
- (uint portal, uint resources, bytes memory context) = input.relayToContext(c.account, c.state);
42
-
43
- Budget memory budget = openValue();
44
- route(portal, resources, context, budget);
45
-
46
- return ("", closeValue(budget, c.account));
37
+ function relayPayable(
38
+ bytes32 account,
39
+ bytes calldata state,
40
+ bytes calldata input
41
+ ) external payable onlyCommand returns (bytes memory, bytes memory) {
42
+ Execution memory exec = openInput(input, descriptor, 1);
43
+ (uint portal, uint resources, bytes calldata payload) = exec.unpackRelay(Lanes.Input);
44
+ bytes memory context = Blocks.context(account, bytes(state), bytes(payload));
45
+
46
+ route(portal, resources, context, exec);
47
+
48
+ return close(exec, account);
47
49
  }
48
50
  }
@@ -1,10 +1,12 @@
1
1
  // SPDX-License-Identifier: GPL-3.0-only
2
2
  pragma solidity ^0.8.33;
3
3
 
4
- import { CommandContext, CommandBase, Keys } from "./Base.sol";
5
- import { Cursors, Cur } from "../Cursors.sol";
6
- using Cursors for Cur;
4
+ import {Execution, Executions, CommandBase, Lanes, Specs} from "./Base.sol";
5
+ import {Action} from "../annotations/Action.sol";
6
+ import {Actions} from "../utils/Actions.sol";
7
+ using Executions for Execution;
7
8
 
9
+ /// @notice Hook implemented by hosts that withdraw account balances.
8
10
  abstract contract WithdrawHook {
9
11
  /// @notice Override to send funds to `account`.
10
12
  /// Called once per BALANCE block in state.
@@ -18,32 +20,31 @@ abstract contract WithdrawHook {
18
20
  /// @notice Command that delivers BALANCE state blocks to an external destination.
19
21
  /// Use `withdraw` for assets being sent outside the protocol (e.g. ERC-20 transfers, ETH sends).
20
22
  /// For internal balance credits, use `creditAccount` instead.
21
- abstract contract Withdraw is CommandBase, WithdrawHook {
22
- bytes32 private immutable descriptor;
23
+ abstract contract Withdraw is CommandBase, WithdrawHook, Action {
24
+ uint private immutable descriptor;
23
25
 
24
26
  constructor() {
25
- (, descriptor) = command("withdraw", Keys.Balance, Keys.Empty, Keys.Empty, 0, false, false);
27
+ uint id;
28
+ (id, descriptor) = command("withdraw", Specs.Balance, Specs.Empty, Specs.Empty, 0, false, false);
29
+ action(id, Actions.Withdraw);
26
30
  }
27
31
 
28
32
  /// @notice Withdraw each BALANCE block from the command state to the command account.
29
- /// @param c Command context; `c.state` must contain BALANCE blocks.
33
+ /// @param state BALANCE block stream.
30
34
  /// @return Empty output state.
31
35
  /// @return Empty transaction stream.
32
36
  function withdraw(
33
- CommandContext calldata c
37
+ bytes32 account,
38
+ bytes calldata state,
39
+ bytes calldata
34
40
  ) external onlyCommand returns (bytes memory, bytes memory) {
35
- (Cur memory state, ) = openState(c.state, descriptor);
41
+ Execution memory exec = openState(state, descriptor, 0);
36
42
 
37
- while (state.i < state.len) {
38
- (bytes32 asset, uint amount) = state.unpackBalance();
39
- withdraw(c.account, asset, amount);
43
+ while (exec.more()) {
44
+ (bytes32 asset, uint amount) = exec.unpackBalance(Lanes.State);
45
+ withdraw(account, asset, amount);
40
46
  }
41
- return ("", "");
47
+
48
+ return close(exec, account);
42
49
  }
43
50
  }
44
-
45
-
46
-
47
-
48
-
49
-
@@ -1,41 +1,44 @@
1
1
  // SPDX-License-Identifier: GPL-3.0-only
2
2
  pragma solidity ^0.8.33;
3
3
 
4
- import { AdminBase, CommandContext, Keys } from "./Base.sol";
5
- import { Cursors, Cur } from "../../Cursors.sol";
6
- using Cursors for Cur;
4
+ import { AdminBase, Execution, Executions, Lanes, Specs } from "./Base.sol";
5
+ using Executions for Execution;
7
6
 
7
+ /// @notice Hook implemented by hosts that allow assets.
8
8
  abstract contract AllowAssetsHook {
9
9
  /// @dev Override to allow a single asset.
10
- /// Called once per ASSET block in the request.
10
+ /// Called once per ASSET block in the input.
11
11
  /// @param asset Asset identifier.
12
12
  function allowAsset(bytes32 asset) internal virtual;
13
13
  }
14
14
 
15
15
  /// @title AllowAssets
16
16
  /// @notice Admin command that permits a list of assets via a virtual hook.
17
- /// Each ASSET block in the request calls `allowAsset`. Only callable by the admin account.
17
+ /// Each ASSET block in the input calls `allowAsset`. Only callable by the admin account.
18
18
  abstract contract AllowAssets is AdminBase, AllowAssetsHook {
19
- bytes32 private immutable descriptor;
19
+ uint private immutable descriptor;
20
20
 
21
21
  constructor() {
22
- (, descriptor) = command("allowAssets", Keys.Empty, Keys.Asset, Keys.Empty, 0, false, true);
22
+ (, descriptor) = command("allowAssets", Specs.Empty, Specs.Asset, Specs.Empty, 0, false, true);
23
23
  }
24
24
 
25
- /// @notice Allow each ASSET block in the admin request.
26
- /// @param c Admin command context; `c.input` must contain ASSET blocks.
25
+ /// @notice Allow each ASSET block in the admin input.
26
+ /// @param input ASSET block stream.
27
27
  /// @return Empty output state.
28
28
  /// @return Empty transaction stream.
29
29
  function allowAssets(
30
- CommandContext calldata c
31
- ) external onlyAdmin(c.account) returns (bytes memory, bytes memory) {
32
- (Cur memory input, ) = openInput(c.input, descriptor);
33
-
34
- while (input.i < input.len) {
35
- bytes32 asset = input.unpackAsset();
30
+ bytes32 account,
31
+ bytes calldata,
32
+ bytes calldata input
33
+ ) external onlyAdmin(account) returns (bytes memory, bytes memory) {
34
+ Execution memory exec = openInput(input, descriptor, 0);
35
+
36
+ while (exec.more()) {
37
+ bytes32 asset = exec.unpackAsset(Lanes.Input);
36
38
  allowAsset(asset);
37
39
  }
38
- return ("", "");
40
+
41
+ return close(exec, account);
39
42
  }
40
43
  }
41
44
 
@@ -1,13 +1,13 @@
1
1
  // SPDX-License-Identifier: GPL-3.0-only
2
2
  pragma solidity ^0.8.33;
3
3
 
4
- import {AdminBase, CommandContext, Keys} from "./Base.sol";
5
- import {Cursors, Cur} from "../../Cursors.sol";
6
- using Cursors for Cur;
4
+ import {AdminBase, Execution, Executions, Lanes, Specs} from "./Base.sol";
5
+ using Executions for Execution;
7
6
 
7
+ /// @notice Hook implemented by hosts that configure peer asset allowances.
8
8
  abstract contract AllowanceHook {
9
9
  /// @notice Apply or revoke one host-scoped allowance.
10
- /// Called once per ALLOWANCE block in the request. Implementations decide
10
+ /// Called once per ALLOWANCE block in the input. Implementations decide
11
11
  /// how the allowance is represented, e.g. ERC-20 approval, an internal cap,
12
12
  /// or another host-specific authorization record.
13
13
  /// @param peer Host node receiving the allowed cap.
@@ -20,23 +20,28 @@ abstract contract AllowanceHook {
20
20
  /// @notice Admin command that applies cross-host allowance entries via a virtual hook.
21
21
  /// Each ALLOWANCE block grants or updates a host-scoped asset cap. Only callable by the admin account.
22
22
  abstract contract Allowance is AdminBase, AllowanceHook {
23
- bytes32 private immutable descriptor;
23
+ uint private immutable descriptor;
24
24
 
25
25
  constructor() {
26
- (, descriptor) = command("allowance", Keys.Empty, Keys.Allowance, Keys.Empty, 0, false, true);
26
+ (, descriptor) = command("allowance", Specs.Empty, Specs.Allowance, Specs.Empty, 0, false, true);
27
27
  }
28
28
 
29
- /// @notice Apply each ALLOWANCE block in the admin request.
30
- /// @param c Admin command context; `c.input` must contain ALLOWANCE blocks.
29
+ /// @notice Apply each ALLOWANCE block in the admin input.
30
+ /// @param input ALLOWANCE block stream.
31
31
  /// @return Empty output state.
32
32
  /// @return Empty transaction stream.
33
- function allowance(CommandContext calldata c) external onlyAdmin(c.account) returns (bytes memory, bytes memory) {
34
- (Cur memory input, ) = openInput(c.input, descriptor);
33
+ function allowance(
34
+ bytes32 account,
35
+ bytes calldata,
36
+ bytes calldata input
37
+ ) external onlyAdmin(account) returns (bytes memory, bytes memory) {
38
+ Execution memory exec = openInput(input, descriptor, 0);
35
39
 
36
- while (input.i < input.len) {
37
- (uint peer, bytes32 asset, uint amount) = input.unpackAllowance();
40
+ while (exec.more()) {
41
+ (uint peer, bytes32 asset, uint amount) = exec.unpackAllowance(Lanes.Input);
38
42
  allowance(peer, asset, amount);
39
43
  }
40
- return ("", "");
44
+
45
+ return close(exec, account);
41
46
  }
42
47
  }
@@ -0,0 +1,36 @@
1
+ // SPDX-License-Identifier: GPL-3.0-only
2
+ pragma solidity ^0.8.33;
3
+
4
+ import {AdminBase, Execution, Executions, Lanes, Specs} from "./Base.sol";
5
+ using Executions for Execution;
6
+
7
+ /// @title Annotate
8
+ /// @notice Admin command that attaches encoded annotation block streams to entities.
9
+ /// Each ANNOTATION block in the input emits one `Annotation` event. Only callable
10
+ /// by the admin account.
11
+ abstract contract Annotate is AdminBase {
12
+ uint private immutable descriptor;
13
+
14
+ constructor() {
15
+ (, descriptor) = command("annotate", Specs.Empty, Specs.Annotation, Specs.Empty, 0, false, true);
16
+ }
17
+
18
+ /// @notice Publish each ANNOTATION block in the admin input.
19
+ /// @param input ANNOTATION block stream.
20
+ /// @return Empty output state.
21
+ /// @return Empty transaction stream.
22
+ function annotate(
23
+ bytes32 account,
24
+ bytes calldata,
25
+ bytes calldata input
26
+ ) external onlyAdmin(account) returns (bytes memory, bytes memory) {
27
+ Execution memory exec = openInput(input, descriptor, 0);
28
+
29
+ while (exec.more()) {
30
+ (uint entity, bytes calldata data) = exec.unpackAnnotation(Lanes.Input);
31
+ emit Annotation(entity, data);
32
+ }
33
+
34
+ return close(exec, account);
35
+ }
36
+ }
@@ -1,34 +1,37 @@
1
1
  // SPDX-License-Identifier: GPL-3.0-only
2
2
  pragma solidity ^0.8.33;
3
3
 
4
- import { AdminBase, CommandContext, Keys } from "./Base.sol";
5
- import { Cursors, Cur } from "../../Cursors.sol";
6
- using Cursors for Cur;
4
+ import { AdminBase, Execution, Executions, Lanes, Specs } from "./Base.sol";
5
+ import { GuardianAccess } from "../../core/Access.sol";
6
+ using Executions for Execution;
7
7
 
8
8
  /// @title Appoint
9
9
  /// @notice Admin command that grants guardian status to a list of account IDs.
10
- /// Each ACCOUNT block in the request is enabled as a guardian on the host.
10
+ /// Each USER ACCOUNT block in the input is assigned the guardian role on the host.
11
11
  /// Only callable by the admin account.
12
- abstract contract Appoint is AdminBase {
13
- bytes32 private immutable descriptor;
12
+ abstract contract Appoint is GuardianAccess, AdminBase {
13
+ uint private immutable descriptor;
14
14
 
15
15
  constructor() {
16
- (, descriptor) = command("appoint", Keys.Empty, Keys.Account, Keys.Empty, 0, false, true);
16
+ (, descriptor) = command("appoint", Specs.Empty, Specs.Account, Specs.Empty, 0, false, true);
17
17
  }
18
18
 
19
- /// @notice Appoint each ACCOUNT block in the admin request as a guardian.
20
- /// @param c Admin command context; `c.input` must contain ACCOUNT blocks.
19
+ /// @notice Appoint each user ACCOUNT block in the admin input as a guardian.
20
+ /// @param input ACCOUNT block stream.
21
21
  /// @return Empty output state.
22
22
  /// @return Empty transaction stream.
23
23
  function appoint(
24
- CommandContext calldata c
25
- ) external onlyAdmin(c.account) returns (bytes memory, bytes memory) {
26
- (Cur memory input, ) = openInput(c.input, descriptor);
24
+ bytes32 account,
25
+ bytes calldata,
26
+ bytes calldata input
27
+ ) external onlyAdmin(account) returns (bytes memory, bytes memory) {
28
+ Execution memory exec = openInput(input, descriptor, 0);
27
29
 
28
- while (input.i < input.len) {
29
- bytes32 account = input.unpackAccount();
30
- setGuardian(account, true);
30
+ while (exec.more()) {
31
+ bytes32 guardian = exec.unpackAccount(Lanes.Input);
32
+ setGuardian(guardian, true);
31
33
  }
32
- return ("", "");
34
+
35
+ return close(exec, account);
33
36
  }
34
37
  }
@@ -1,33 +1,42 @@
1
1
  // SPDX-License-Identifier: GPL-3.0-only
2
2
  pragma solidity ^0.8.33;
3
3
 
4
- import {AdminBase, CommandContext, Keys} from "./Base.sol";
5
- import {Cursors, Cur} from "../../Cursors.sol";
6
- using Cursors for Cur;
4
+ import {AdminBase, Execution, Executions, Lanes, Specs} from "./Base.sol";
5
+ using Executions for Execution;
7
6
 
8
7
  /// @title Authorize
9
8
  /// @notice Admin command that grants authorization to a list of node IDs.
10
- /// Each NODE block in the request is authorized on the host.
9
+ /// Each NODE block in the input is authorized on the host.
11
10
  /// Only callable by the admin account.
12
11
  abstract contract Authorize is AdminBase {
13
- bytes32 private immutable descriptor;
14
- uint internal immutable authorizeId;
12
+ uint private immutable descriptor;
13
+ uint private immutable id;
15
14
 
16
15
  constructor() {
17
- (authorizeId, descriptor) = command("authorize", Keys.Empty, Keys.Node, Keys.Empty, 0, false, true);
16
+ (id, descriptor) = command("authorize", Specs.Empty, Specs.Node, Specs.Empty, 0, false, true);
18
17
  }
19
18
 
20
- /// @notice Authorize each NODE block in the admin request.
21
- /// @param c Admin command context; `c.input` must contain NODE blocks.
19
+ /// @notice Return the registered AUTHORIZE command ID.
20
+ function authorizeId() internal view returns (uint) {
21
+ return id;
22
+ }
23
+
24
+ /// @notice Authorize each NODE block in the admin input.
25
+ /// @param input NODE block stream.
22
26
  /// @return Empty output state.
23
27
  /// @return Empty transaction stream.
24
- function authorize(CommandContext calldata c) external onlyAdmin(c.account) returns (bytes memory, bytes memory) {
25
- (Cur memory input, ) = openInput(c.input, descriptor);
28
+ function authorize(
29
+ bytes32 account,
30
+ bytes calldata,
31
+ bytes calldata input
32
+ ) external onlyAdmin(account) returns (bytes memory, bytes memory) {
33
+ Execution memory exec = openInput(input, descriptor, 0);
26
34
 
27
- while (input.i < input.len) {
28
- uint node = input.unpackNode();
35
+ while (exec.more()) {
36
+ uint node = exec.unpackNode(Lanes.Input);
29
37
  setNode(node, true);
30
38
  }
31
- return ("", "");
39
+
40
+ return close(exec, account);
32
41
  }
33
42
  }
@@ -1,8 +1,15 @@
1
1
  // SPDX-License-Identifier: GPL-3.0-only
2
2
  pragma solidity ^0.8.33;
3
3
 
4
- import {CommandBase, CommandContext, Keys} from "../Base.sol";
4
+ import {CommandBase, Execution, Executions, Lanes, Specs} from "../Base.sol";
5
+ import {NodeAccess} from "../../core/Access.sol";
5
6
 
6
7
  /// @title AdminBase
7
8
  /// @notice Shared base for admin commands.
8
- abstract contract AdminBase is CommandBase {}
9
+ abstract contract AdminBase is NodeAccess, CommandBase {
10
+ /// @dev Restrict execution to the commander using the host's admin account.
11
+ modifier onlyAdmin(bytes32 account) {
12
+ enforceAdmin(account, msg.sender);
13
+ _;
14
+ }
15
+ }