@rootzero/contracts 1.21.0 → 1.23.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 (54) hide show
  1. package/CHANGELOG.md +125 -0
  2. package/Endpoints.sol +2 -3
  3. package/Events.sol +1 -1
  4. package/README.md +25 -19
  5. package/annotations/Action.sol +1 -1
  6. package/annotations/Label.sol +1 -1
  7. package/annotations/Schema.sol +36 -3
  8. package/codec/Blocks.sol +100 -29
  9. package/codec/Decoders.sol +62 -8
  10. package/codec/Readers.sol +39 -0
  11. package/codec/Schema.sol +44 -35
  12. package/codec/Writers.sol +8 -0
  13. package/commands/Allocate.sol +5 -8
  14. package/commands/Base.sol +29 -13
  15. package/commands/Burn.sol +5 -7
  16. package/commands/Credit.sol +5 -7
  17. package/commands/Debit.sol +5 -7
  18. package/commands/Deposit.sol +10 -14
  19. package/commands/Payout.sol +5 -8
  20. package/commands/Provision.sol +10 -14
  21. package/commands/Recover.sol +4 -6
  22. package/commands/Relay.sol +16 -22
  23. package/commands/Repay.sol +10 -14
  24. package/commands/Settle.sol +10 -14
  25. package/commands/Withdraw.sol +5 -7
  26. package/commands/admin/AllowAssets.sol +5 -7
  27. package/commands/admin/Allowance.sol +5 -7
  28. package/commands/admin/Annotate.sol +5 -7
  29. package/commands/admin/Appoint.sol +5 -7
  30. package/commands/admin/Authorize.sol +5 -7
  31. package/commands/admin/Base.sol +12 -3
  32. package/commands/admin/DenyAssets.sol +5 -7
  33. package/commands/admin/Dismiss.sol +5 -7
  34. package/commands/admin/Execute.sol +5 -7
  35. package/commands/admin/Unauthorize.sol +5 -7
  36. package/core/Calls.sol +72 -3
  37. package/core/Host.sol +7 -10
  38. package/core/Portal.sol +2 -2
  39. package/events/Dispatch.sol +1 -1
  40. package/events/Positioned.sol +22 -0
  41. package/events/Relay.sol +1 -1
  42. package/events/Route.sol +1 -1
  43. package/execution/Execution.sol +124 -4
  44. package/package.json +2 -3
  45. package/ports/Allowance.sol +22 -12
  46. package/ports/Assets.sol +99 -0
  47. package/ports/Dispatch.sol +2 -1
  48. package/utils/Cursors.sol +3 -3
  49. package/utils/Nodes.sol +1 -1
  50. package/utils/Utils.sol +31 -31
  51. package/docs/Schema.md +0 -427
  52. package/events/Commander.sol +0 -19
  53. package/ports/AllowAssets.sol +0 -34
  54. package/ports/DenyAssets.sol +0 -34
@@ -28,23 +28,20 @@ abstract contract Allocate is CommandBase, AllocateHook {
28
28
  }
29
29
 
30
30
  /// @notice Allocate BALANCE state blocks to matching NODE input blocks.
31
- /// @param state BALANCE block stream.
32
- /// @param input Matching NODE block stream.
31
+ /// @param context Command context carrying BALANCE state and matching NODE input.
33
32
  /// @return CUSTODY block stream matching the allocated balances.
34
33
  /// @return Empty transaction stream.
35
34
  function allocate(
36
- bytes32 account,
37
- bytes calldata state,
38
- bytes calldata input
35
+ bytes calldata context
39
36
  ) external onlyCommand returns (bytes memory, bytes memory) {
40
- Execution memory exec = openCommand(state, input, descriptor, 0);
37
+ Execution memory exec = openCommand(context, descriptor, 0);
41
38
 
42
39
  while (exec.more()) {
43
40
  HostAmount memory custody = exec.unpackBalanceForHost(Lanes.State, exec.unpackNode(Lanes.Input));
44
- allocate(account, custody);
41
+ allocate(exec.account, custody);
45
42
  exec.outputCustody(custody);
46
43
  }
47
44
 
48
- return close(exec, account);
45
+ return closeCommand(exec);
49
46
  }
50
47
  }
package/commands/Base.sol CHANGED
@@ -70,40 +70,56 @@ abstract contract CommandBase is CallerAccess, EndpointBase, ReceivedEvent {
70
70
  published = endpoint(id, name, descriptor);
71
71
  }
72
72
 
73
- /// @notice Open and validate both command lanes, including lanes declared EMPTY.
73
+ /// @notice Decode the command ABI argument as exactly one complete CONTEXT block.
74
+ /// @dev Rejects empty input, trailing bytes, and additional context blocks.
75
+ function unpackCommandContext(
76
+ bytes calldata context
77
+ ) internal pure returns (bytes32 account, bytes calldata state, bytes calldata input) {
78
+ uint abs;
79
+ assembly ("memory-safe") {
80
+ abs := context.offset
81
+ }
82
+
83
+ uint end;
84
+ (account, state, input, end) = Blocks.unpackContext(abs);
85
+ if (end != abs + context.length) revert Blocks.InvalidBlock();
86
+ }
87
+
88
+ /// @notice Decode one command context and validate both lanes, including lanes declared EMPTY.
74
89
  /// Batches are derived from the input and state lanes. A non-empty stream for
75
90
  /// a lane whose descriptor has zero stride reverts instead of being ignored.
76
91
  /// Commands must account for the complete validated state by consuming it,
77
92
  /// transforming and returning it, forwarding it intact, or reverting.
78
- /// @param state Current command state block stream.
79
- /// @param input Command input block stream.
93
+ /// @param context Exactly one CONTEXT block carrying the account, state, and input.
80
94
  /// @param descriptor Packed command endpoint descriptor.
81
95
  /// @param batches Required batch count, or zero to reconcile the lane counts.
82
96
  /// @return exec Execution with its output buffer metadata initialized for the reconciled batch count.
83
97
  function openCommand(
84
- bytes calldata state,
85
- bytes calldata input,
98
+ bytes calldata context,
86
99
  uint descriptor,
87
100
  uint batches
88
101
  ) internal view returns (Execution memory exec) {
89
- return Executions.open(state, input, descriptor, batches);
102
+ bytes32 account;
103
+ bytes calldata state;
104
+ bytes calldata input;
105
+ (account, state, input) = unpackCommandContext(context);
106
+ exec = Executions.open(state, input, descriptor, batches);
107
+ exec.account = account;
90
108
  }
91
109
 
92
- /// @notice Close a command execution and refund unspent value to `account`.
110
+ /// @notice Close a command execution and refund unspent value to its account.
93
111
  /// @param exec Command execution to close.
94
- /// @param account Account that should receive any unspent value.
95
112
  /// @return output Final encoded output block stream.
96
113
  /// @return transactions Final encoded transaction block stream.
97
- function close(
98
- Execution memory exec,
99
- bytes32 account
114
+ function closeCommand(
115
+ Execution memory exec
100
116
  ) internal returns (bytes memory output, bytes memory transactions) {
101
117
  if (exec.budget == 0 && Cursors.initial(exec.writers)) return ("", "");
102
118
 
103
119
  output = close(exec);
104
- uint amount = exec.refundValue(account, nativeAsset);
120
+ uint amount = exec.refundValue(exec.account, nativeAsset);
105
121
  if (amount != 0) {
106
- emit Received(account, nativeAsset, amount, Actions.Refund, 0);
122
+ emit Received(exec.account, nativeAsset, amount, Actions.Refund, 0);
107
123
  }
108
124
 
109
125
  transactions = exec.finishTransactions();
package/commands/Burn.sol CHANGED
@@ -30,22 +30,20 @@ abstract contract Burn is CommandBase, BurnHook, Action {
30
30
  }
31
31
 
32
32
  /// @notice Burn each BALANCE block from the command state.
33
- /// @param state BALANCE block stream.
33
+ /// @param context Command context carrying the BALANCE state stream.
34
34
  /// @return Empty output state.
35
35
  /// @return Empty transaction stream.
36
36
  function burn(
37
- bytes32 account,
38
- bytes calldata state,
39
- bytes calldata input
37
+ bytes calldata context
40
38
  ) external onlyCommand returns (bytes memory, bytes memory) {
41
- Execution memory exec = openCommand(state, input, descriptor, 0);
39
+ Execution memory exec = openCommand(context, descriptor, 0);
42
40
 
43
41
  while (exec.more()) {
44
42
  (bytes32 asset, uint amount) = exec.unpackBalance(Lanes.State);
45
- burn(account, asset, amount);
43
+ burn(exec.account, asset, amount);
46
44
  }
47
45
 
48
- return close(exec, account);
46
+ return closeCommand(exec);
49
47
  }
50
48
  }
51
49
 
@@ -26,22 +26,20 @@ abstract contract CreditAccount is CommandBase, CreditAccountHook {
26
26
  }
27
27
 
28
28
  /// @notice Credit each BALANCE block from the command state to the command account.
29
- /// @param state BALANCE block stream.
29
+ /// @param context Command context carrying the BALANCE state stream.
30
30
  /// @return Empty output state.
31
31
  /// @return Empty transaction stream.
32
32
  function creditAccount(
33
- bytes32 account,
34
- bytes calldata state,
35
- bytes calldata input
33
+ bytes calldata context
36
34
  ) external onlyCommand returns (bytes memory, bytes memory) {
37
- Execution memory exec = openCommand(state, input, descriptor, 0);
35
+ Execution memory exec = openCommand(context, descriptor, 0);
38
36
 
39
37
  while (exec.more()) {
40
38
  (bytes32 asset, uint amount) = exec.unpackBalance(Lanes.State);
41
- creditAccount(account, asset, amount);
39
+ creditAccount(exec.account, asset, amount);
42
40
  }
43
41
 
44
- return close(exec, account);
42
+ return closeCommand(exec);
45
43
  }
46
44
  }
47
45
 
@@ -29,23 +29,21 @@ abstract contract DebitAccount is CommandBase, DebitAccountHook {
29
29
  }
30
30
 
31
31
  /// @notice Debit AMOUNT input blocks from the command account and output matching BALANCE blocks.
32
- /// @param input AMOUNT block stream.
32
+ /// @param context Command context carrying the AMOUNT input stream.
33
33
  /// @return BALANCE block stream matching the debited amounts.
34
34
  /// @return Empty transaction stream.
35
35
  function debitAccount(
36
- bytes32 account,
37
- bytes calldata state,
38
- bytes calldata input
36
+ bytes calldata context
39
37
  ) external onlyCommand returns (bytes memory, bytes memory) {
40
- Execution memory exec = openCommand(state, input, descriptor, 0);
38
+ Execution memory exec = openCommand(context, descriptor, 0);
41
39
 
42
40
  while (exec.more()) {
43
41
  (bytes32 asset, uint amount) = exec.unpackAmount(Lanes.Input);
44
- debitAccount(account, asset, amount);
42
+ debitAccount(exec.account, asset, amount);
45
43
  exec.outputBalance(asset, amount);
46
44
  }
47
45
 
48
- return close(exec, account);
46
+ return closeCommand(exec);
49
47
  }
50
48
  }
51
49
 
@@ -44,23 +44,21 @@ abstract contract Deposit is CommandBase, DepositHook, Action {
44
44
  }
45
45
 
46
46
  /// @notice Deposit AMOUNT input blocks into the command account and output matching BALANCE blocks.
47
- /// @param input AMOUNT block stream.
47
+ /// @param context Command context carrying the AMOUNT input stream.
48
48
  /// @return BALANCE block stream matching the deposited amounts.
49
49
  /// @return Empty transaction stream.
50
50
  function deposit(
51
- bytes32 account,
52
- bytes calldata state,
53
- bytes calldata input
51
+ bytes calldata context
54
52
  ) external onlyCommand returns (bytes memory, bytes memory) {
55
- Execution memory exec = openCommand(state, input, descriptor, 0);
53
+ Execution memory exec = openCommand(context, descriptor, 0);
56
54
 
57
55
  while (exec.more()) {
58
56
  (bytes32 asset, uint amount) = exec.unpackAmount(Lanes.Input);
59
- deposit(account, asset, amount);
57
+ deposit(exec.account, asset, amount);
60
58
  exec.outputBalance(asset, amount);
61
59
  }
62
60
 
63
- return close(exec, account);
61
+ return closeCommand(exec);
64
62
  }
65
63
  }
66
64
 
@@ -77,22 +75,20 @@ abstract contract DepositPayable is CommandBase, DepositPayableHook, Action {
77
75
  }
78
76
 
79
77
  /// @notice Deposit AMOUNT input blocks with access to a mutable native-value budget.
80
- /// @param input AMOUNT block stream.
78
+ /// @param context Command context carrying the AMOUNT input stream.
81
79
  /// @return BALANCE block stream matching the deposited amounts.
82
80
  /// @return Remaining native value as a refund transaction stream.
83
81
  function depositPayable(
84
- bytes32 account,
85
- bytes calldata state,
86
- bytes calldata input
82
+ bytes calldata context
87
83
  ) external payable onlyCommand returns (bytes memory, bytes memory) {
88
- Execution memory exec = openCommand(state, input, descriptor, 0);
84
+ Execution memory exec = openCommand(context, descriptor, 0);
89
85
 
90
86
  while (exec.more()) {
91
87
  (bytes32 asset, uint amount) = exec.unpackAmount(Lanes.Input);
92
- deposit(account, asset, amount, exec);
88
+ deposit(exec.account, asset, amount, exec);
93
89
  exec.outputBalance(asset, amount);
94
90
  }
95
91
 
96
- return close(exec, account);
92
+ return closeCommand(exec);
97
93
  }
98
94
  }
@@ -31,22 +31,19 @@ abstract contract Payout is CommandBase, PayoutHook, Action {
31
31
  }
32
32
 
33
33
  /// @notice Pay out BALANCE state blocks to matching ACCOUNT input blocks.
34
- /// @param state BALANCE block stream.
35
- /// @param input Matching ACCOUNT block stream.
34
+ /// @param context Command context carrying BALANCE state and matching ACCOUNT input.
36
35
  /// @return Empty output state.
37
36
  /// @return Empty transaction stream.
38
37
  function payout(
39
- bytes32 account,
40
- bytes calldata state,
41
- bytes calldata input
38
+ bytes calldata context
42
39
  ) external onlyCommand returns (bytes memory, bytes memory) {
43
- Execution memory exec = openCommand(state, input, descriptor, 0);
40
+ Execution memory exec = openCommand(context, descriptor, 0);
44
41
 
45
42
  while (exec.more()) {
46
43
  (bytes32 asset, uint amount) = exec.unpackBalance(Lanes.State);
47
- payout(account, exec.unpackAccount(Lanes.Input), asset, amount);
44
+ payout(exec.account, exec.unpackAccount(Lanes.Input), asset, amount);
48
45
  }
49
46
 
50
- return close(exec, account);
47
+ return closeCommand(exec);
51
48
  }
52
49
  }
@@ -36,23 +36,21 @@ abstract contract Provision is CommandBase, ProvisionHook {
36
36
  }
37
37
 
38
38
  /// @notice Provision ALLOCATION input blocks and output matching CUSTODY state blocks.
39
- /// @param input ALLOCATION block stream.
39
+ /// @param context Command context carrying the ALLOCATION input stream.
40
40
  /// @return CUSTODY block stream matching the provisioned allocations.
41
41
  /// @return Empty transaction stream.
42
42
  function provision(
43
- bytes32 account,
44
- bytes calldata state,
45
- bytes calldata input
43
+ bytes calldata context
46
44
  ) external onlyCommand returns (bytes memory, bytes memory) {
47
- Execution memory exec = openCommand(state, input, descriptor, 0);
45
+ Execution memory exec = openCommand(context, descriptor, 0);
48
46
 
49
47
  while (exec.more()) {
50
48
  HostAmount memory allocation = exec.unpackAllocationValue(Lanes.Input);
51
- provision(account, allocation);
49
+ provision(exec.account, allocation);
52
50
  exec.outputCustody(allocation);
53
51
  }
54
52
 
55
- return close(exec, account);
53
+ return closeCommand(exec);
56
54
  }
57
55
  }
58
56
 
@@ -68,23 +66,21 @@ abstract contract ProvisionPayable is CommandBase, ProvisionPayableHook {
68
66
  }
69
67
 
70
68
  /// @notice Provision ALLOCATION input blocks with access to a mutable native-value budget.
71
- /// @param input ALLOCATION block stream.
69
+ /// @param context Command context carrying the ALLOCATION input stream.
72
70
  /// @return CUSTODY block stream matching the provisioned allocations.
73
71
  /// @return Remaining native value as a refund transaction stream.
74
72
  function provisionPayable(
75
- bytes32 account,
76
- bytes calldata state,
77
- bytes calldata input
73
+ bytes calldata context
78
74
  ) external payable onlyCommand returns (bytes memory, bytes memory) {
79
- Execution memory exec = openCommand(state, input, descriptor, 0);
75
+ Execution memory exec = openCommand(context, descriptor, 0);
80
76
 
81
77
  while (exec.more()) {
82
78
  HostAmount memory allocation = exec.unpackAllocationValue(Lanes.Input);
83
- provision(account, allocation, exec);
79
+ provision(exec.account, allocation, exec);
84
80
  exec.outputCustody(allocation);
85
81
  }
86
82
 
87
- return close(exec, account);
83
+ return closeCommand(exec);
88
84
  }
89
85
  }
90
86
 
@@ -35,21 +35,19 @@ abstract contract RecoverPayable is CommandBase, RecoverPayableHook {
35
35
  }
36
36
 
37
37
  /// @notice Recover each recover block in the command input.
38
- /// @param input RECOVER block stream.
38
+ /// @param context Command context carrying the RECOVER input stream.
39
39
  /// @return Empty output state.
40
40
  /// @return Remaining native value as a refund transaction stream.
41
41
  function recoverPayable(
42
- bytes32 account,
43
- bytes calldata state,
44
- bytes calldata input
42
+ bytes calldata context
45
43
  ) external payable onlyCommand returns (bytes memory, bytes memory) {
46
- Execution memory exec = openCommand(state, input, descriptor, 0);
44
+ Execution memory exec = openCommand(context, descriptor, 0);
47
45
 
48
46
  while (exec.more()) {
49
47
  (uint handler, uint resources, bytes32 key, bytes calldata witness) = exec.unpackRecover(Lanes.Input);
50
48
  recover(handler, resources, key, witness, exec);
51
49
  }
52
50
 
53
- return close(exec, account);
51
+ return closeCommand(exec);
54
52
  }
55
53
  }
@@ -8,21 +8,20 @@ using Executions for Execution;
8
8
  /// @notice Hook implemented by hosts that relay command contexts.
9
9
  abstract contract RelayPayableHook {
10
10
  /// @notice Override to relay a command context to `portal`.
11
- /// @param portal Destination portal identifier, often the destination host ID.
11
+ /// @param portal Destination portal implementation's host ID. Implementations
12
+ /// may validate or resolve it for their transport.
12
13
  /// @param resources Chain-specific destination resources. EVM adapters
13
14
  /// may interpret this as packed execution gas and destination value.
14
15
  /// @param account Destination command account.
15
- /// @param state State forwarded into the destination context.
16
16
  /// @param input Input forwarded into the destination context.
17
- /// @param funds Execution used for source value available for transport fees
18
- /// and destination resource funding.
17
+ /// @param exec Execution carrying the source state and value available for
18
+ /// transport fees and destination resource funding.
19
19
  function relay(
20
20
  uint portal,
21
21
  uint resources,
22
22
  bytes32 account,
23
- bytes calldata state,
24
23
  bytes calldata input,
25
- Execution memory funds
24
+ Execution memory exec
26
25
  ) internal virtual;
27
26
  }
28
27
 
@@ -37,15 +36,13 @@ abstract contract RelayPayable is CommandBase, RelayPayableHook {
37
36
 
38
37
  /// @notice Relay one RELAY input block with the command account and empty state.
39
38
  function relayPayable(
40
- bytes32 account,
41
- bytes calldata state,
42
- bytes calldata input
39
+ bytes calldata context
43
40
  ) external payable onlyCommand returns (bytes memory, bytes memory) {
44
- Execution memory exec = openCommand(state, input, descriptor, 1);
45
- (uint portal, uint resources, bytes calldata relayInput) = exec.unpackRelay(Lanes.Input);
46
- relay(portal, resources, account, state, relayInput, exec);
41
+ Execution memory exec = openCommand(context, descriptor, 1);
42
+ (uint portal, uint resources, bytes calldata input) = exec.unpackRelay(Lanes.Input);
43
+ relay(portal, resources, exec.account, input, exec);
47
44
 
48
- return close(exec, account);
45
+ return closeCommand(exec);
49
46
  }
50
47
  }
51
48
 
@@ -62,19 +59,16 @@ abstract contract RelayBalancePayable is CommandBase, RelayPayableHook {
62
59
  }
63
60
 
64
61
  /// @notice Relay one RELAY input block with the command account and current state.
65
- /// @param state State forwarded into the destination context.
66
- /// @param input Exactly one RELAY block.
62
+ /// @param context Command context carrying state and exactly one RELAY input block.
67
63
  /// @return Empty output state.
68
64
  /// @return Remaining native value as a refund transaction stream.
69
65
  function relayBalancePayable(
70
- bytes32 account,
71
- bytes calldata state,
72
- bytes calldata input
66
+ bytes calldata context
73
67
  ) external payable onlyCommand returns (bytes memory, bytes memory) {
74
- Execution memory exec = openCommand(state, input, descriptor, 1);
75
- (uint portal, uint resources, bytes calldata relayInput) = exec.unpackRelay(Lanes.Input);
76
- relay(portal, resources, account, state, relayInput, exec);
68
+ Execution memory exec = openCommand(context, descriptor, 1);
69
+ (uint portal, uint resources, bytes calldata input) = exec.unpackRelay(Lanes.Input);
70
+ relay(portal, resources, exec.account, input, exec);
77
71
 
78
- return close(exec, account);
72
+ return closeCommand(exec);
79
73
  }
80
74
  }
@@ -30,23 +30,21 @@ abstract contract Repay is CommandBase, RepayHook, Action {
30
30
  }
31
31
 
32
32
  /// @notice Repay each POSITION liability and return its asset as BALANCE state.
33
- /// @param state POSITION block stream.
33
+ /// @param context Command context carrying the POSITION state stream.
34
34
  /// @return BALANCE output state containing each released asset side.
35
35
  /// @return Empty transaction stream.
36
36
  function repay(
37
- bytes32 account,
38
- bytes calldata state,
39
- bytes calldata input
37
+ bytes calldata context
40
38
  ) external onlyCommand returns (bytes memory, bytes memory) {
41
- Execution memory exec = openCommand(state, input, descriptor, 0);
39
+ Execution memory exec = openCommand(context, descriptor, 0);
42
40
 
43
41
  while (exec.more()) {
44
42
  (bytes32 asset, uint amount, bytes32 liability, uint debt) = exec.unpackPosition(Lanes.State);
45
- repay(account, liability, debt);
43
+ repay(exec.account, liability, debt);
46
44
  exec.outputBalance(asset, amount);
47
45
  }
48
46
 
49
- return close(exec, account);
47
+ return closeCommand(exec);
50
48
  }
51
49
  }
52
50
 
@@ -62,22 +60,20 @@ abstract contract RepayPayable is CommandBase, RepayPayableHook, Action {
62
60
  }
63
61
 
64
62
  /// @notice Repay each POSITION liability and return its asset as BALANCE state.
65
- /// @param state POSITION block stream.
63
+ /// @param context Command context carrying the POSITION state stream.
66
64
  /// @return BALANCE output state containing each released asset side.
67
65
  /// @return Remaining native value as a refund transaction stream.
68
66
  function repayPayable(
69
- bytes32 account,
70
- bytes calldata state,
71
- bytes calldata input
67
+ bytes calldata context
72
68
  ) external payable onlyCommand returns (bytes memory, bytes memory) {
73
- Execution memory exec = openCommand(state, input, descriptor, 0);
69
+ Execution memory exec = openCommand(context, descriptor, 0);
74
70
 
75
71
  while (exec.more()) {
76
72
  (bytes32 asset, uint amount, bytes32 liability, uint debt) = exec.unpackPosition(Lanes.State);
77
- repay(account, liability, debt, exec);
73
+ repay(exec.account, liability, debt, exec);
78
74
  exec.outputBalance(asset, amount);
79
75
  }
80
76
 
81
- return close(exec, account);
77
+ return closeCommand(exec);
82
78
  }
83
79
  }
@@ -47,22 +47,20 @@ abstract contract Settle is CommandBase, SettleHook, Action {
47
47
  }
48
48
 
49
49
  /// @notice Settle each POSITION block from the command state.
50
- /// @param state POSITION block stream.
50
+ /// @param context Command context carrying the POSITION state stream.
51
51
  /// @return Empty output state.
52
52
  /// @return Empty transaction stream.
53
53
  function settle(
54
- bytes32 account,
55
- bytes calldata state,
56
- bytes calldata input
54
+ bytes calldata context
57
55
  ) external onlyCommand returns (bytes memory, bytes memory) {
58
- Execution memory exec = openCommand(state, input, descriptor, 0);
56
+ Execution memory exec = openCommand(context, descriptor, 0);
59
57
 
60
58
  while (exec.more()) {
61
59
  (bytes32 asset, uint amount, bytes32 liability, uint debt) = exec.unpackPosition(Lanes.State);
62
- settle(account, asset, amount, liability, debt);
60
+ settle(exec.account, asset, amount, liability, debt);
63
61
  }
64
62
 
65
- return close(exec, account);
63
+ return closeCommand(exec);
66
64
  }
67
65
  }
68
66
 
@@ -78,22 +76,20 @@ abstract contract SettlePayable is CommandBase, SettlePayableHook, Action {
78
76
  }
79
77
 
80
78
  /// @notice Settle each POSITION block with access to a shared native-value budget.
81
- /// @param state POSITION block stream.
79
+ /// @param context Command context carrying the POSITION state stream.
82
80
  /// @return Empty output state.
83
81
  /// @return Remaining native value as a refund transaction stream.
84
82
  function settlePayable(
85
- bytes32 account,
86
- bytes calldata state,
87
- bytes calldata input
83
+ bytes calldata context
88
84
  ) external payable onlyCommand returns (bytes memory, bytes memory) {
89
- Execution memory exec = openCommand(state, input, descriptor, 0);
85
+ Execution memory exec = openCommand(context, descriptor, 0);
90
86
 
91
87
  while (exec.more()) {
92
88
  (bytes32 asset, uint amount, bytes32 liability, uint debt) = exec.unpackPosition(Lanes.State);
93
- settle(account, asset, amount, liability, debt, exec);
89
+ settle(exec.account, asset, amount, liability, debt, exec);
94
90
  }
95
91
 
96
- return close(exec, account);
92
+ return closeCommand(exec);
97
93
  }
98
94
  }
99
95
 
@@ -30,21 +30,19 @@ abstract contract Withdraw is CommandBase, WithdrawHook, Action {
30
30
  }
31
31
 
32
32
  /// @notice Withdraw each BALANCE block from the command state to the command account.
33
- /// @param state BALANCE block stream.
33
+ /// @param context Command context carrying the BALANCE state stream.
34
34
  /// @return Empty output state.
35
35
  /// @return Empty transaction stream.
36
36
  function withdraw(
37
- bytes32 account,
38
- bytes calldata state,
39
- bytes calldata input
37
+ bytes calldata context
40
38
  ) external onlyCommand returns (bytes memory, bytes memory) {
41
- Execution memory exec = openCommand(state, input, descriptor, 0);
39
+ Execution memory exec = openCommand(context, descriptor, 0);
42
40
 
43
41
  while (exec.more()) {
44
42
  (bytes32 asset, uint amount) = exec.unpackBalance(Lanes.State);
45
- withdraw(account, asset, amount);
43
+ withdraw(exec.account, asset, amount);
46
44
  }
47
45
 
48
- return close(exec, account);
46
+ return closeCommand(exec);
49
47
  }
50
48
  }
@@ -23,22 +23,20 @@ abstract contract AllowAssets is AdminBase, AllowAssetsHook {
23
23
  }
24
24
 
25
25
  /// @notice Allow each ASSET block in the admin input.
26
- /// @param input ASSET block stream.
26
+ /// @param context Admin command context carrying the ASSET input stream.
27
27
  /// @return Empty output state.
28
28
  /// @return Empty transaction stream.
29
29
  function allowAssets(
30
- bytes32 account,
31
- bytes calldata state,
32
- bytes calldata input
33
- ) external onlyAdmin(account) returns (bytes memory, bytes memory) {
34
- Execution memory exec = openCommand(state, input, descriptor, 0);
30
+ bytes calldata context
31
+ ) external returns (bytes memory, bytes memory) {
32
+ Execution memory exec = openAdminCommand(context, descriptor, 0);
35
33
 
36
34
  while (exec.more()) {
37
35
  bytes32 asset = exec.unpackAsset(Lanes.Input);
38
36
  allowAsset(asset);
39
37
  }
40
38
 
41
- return close(exec, account);
39
+ return closeCommand(exec);
42
40
  }
43
41
  }
44
42
 
@@ -27,21 +27,19 @@ abstract contract Allowance is AdminBase, AllowanceHook {
27
27
  }
28
28
 
29
29
  /// @notice Apply each ALLOWANCE block in the admin input.
30
- /// @param input ALLOWANCE block stream.
30
+ /// @param context Admin command context carrying the ALLOWANCE input stream.
31
31
  /// @return Empty output state.
32
32
  /// @return Empty transaction stream.
33
33
  function allowance(
34
- bytes32 account,
35
- bytes calldata state,
36
- bytes calldata input
37
- ) external onlyAdmin(account) returns (bytes memory, bytes memory) {
38
- Execution memory exec = openCommand(state, input, descriptor, 0);
34
+ bytes calldata context
35
+ ) external returns (bytes memory, bytes memory) {
36
+ Execution memory exec = openAdminCommand(context, descriptor, 0);
39
37
 
40
38
  while (exec.more()) {
41
39
  (uint peer, bytes32 asset, uint amount) = exec.unpackAllowance(Lanes.Input);
42
40
  allowance(peer, asset, amount);
43
41
  }
44
42
 
45
- return close(exec, account);
43
+ return closeCommand(exec);
46
44
  }
47
45
  }