@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/commands/Provision.sol
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
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
|
|
29
|
-
function provision(bytes32 account, HostAmount memory allocation,
|
|
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
|
|
34
|
-
/// Each
|
|
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
|
-
|
|
32
|
+
uint private immutable descriptor;
|
|
37
33
|
|
|
38
34
|
constructor() {
|
|
39
|
-
(, descriptor) = command("provision",
|
|
35
|
+
(, descriptor) = command("provision", Specs.Empty, Specs.Allocation, Specs.Custody, 0, false, false);
|
|
40
36
|
}
|
|
41
37
|
|
|
42
|
-
/// @notice Provision ALLOCATION
|
|
43
|
-
/// @param
|
|
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(
|
|
47
|
-
|
|
48
|
-
|
|
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 (
|
|
51
|
-
HostAmount memory allocation =
|
|
52
|
-
provision(
|
|
53
|
-
|
|
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 (
|
|
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
|
|
62
|
-
/// Each
|
|
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,
|
|
65
|
-
|
|
63
|
+
abstract contract ProvisionPayable is CommandBase, ProvisionPayableHook {
|
|
64
|
+
uint private immutable descriptor;
|
|
66
65
|
|
|
67
66
|
constructor() {
|
|
68
|
-
(, descriptor) = command("provisionPayable",
|
|
67
|
+
(, descriptor) = command("provisionPayable", Specs.Empty, Specs.Allocation, Specs.Custody, 0, true, false);
|
|
69
68
|
}
|
|
70
69
|
|
|
71
|
-
/// @notice Provision ALLOCATION
|
|
72
|
-
/// @param
|
|
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
|
-
|
|
75
|
+
bytes32 account,
|
|
76
|
+
bytes calldata,
|
|
77
|
+
bytes calldata input
|
|
77
78
|
) external payable onlyCommand returns (bytes memory, bytes memory) {
|
|
78
|
-
|
|
79
|
-
Writer memory output = Writers.allocCustodies(outputs);
|
|
80
|
-
Budget memory budget = openValue();
|
|
79
|
+
Execution memory exec = openInput(input, descriptor, 0);
|
|
81
80
|
|
|
82
|
-
while (
|
|
83
|
-
HostAmount memory allocation =
|
|
84
|
-
provision(
|
|
85
|
-
|
|
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 (
|
|
87
|
+
return close(exec, account);
|
|
89
88
|
}
|
|
90
89
|
}
|
|
91
90
|
|
package/commands/Recover.sol
CHANGED
|
@@ -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,
|
|
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
|
|
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
|
|
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,
|
|
26
|
-
|
|
23
|
+
abstract contract RecoverPayable is CommandBase, RecoverHook {
|
|
24
|
+
uint private immutable descriptor;
|
|
27
25
|
|
|
28
26
|
constructor() {
|
|
29
|
-
(, descriptor) = command("recoverPayable",
|
|
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
|
|
33
|
-
/// @param
|
|
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(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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 (
|
|
46
|
+
return close(exec, account);
|
|
46
47
|
}
|
|
47
48
|
}
|
package/commands/Relay.sol
CHANGED
|
@@ -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,
|
|
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
|
|
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
|
|
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,
|
|
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
|
|
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,
|
|
29
|
-
|
|
25
|
+
abstract contract RelayPayable is CommandBase, RoutePayableHook {
|
|
26
|
+
uint private immutable descriptor;
|
|
30
27
|
|
|
31
28
|
constructor() {
|
|
32
|
-
(, descriptor) = command("relayPayable",
|
|
29
|
+
(, descriptor) = command("relayPayable", Specs.Any, Specs.Relay, Specs.Empty, 0, true, false);
|
|
33
30
|
}
|
|
34
31
|
|
|
35
|
-
/// @notice Relay one RELAY
|
|
36
|
-
/// @param
|
|
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(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
}
|
package/commands/Withdraw.sol
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
using Cursors for Cur;
|
|
4
|
+
import {Execution, Executions, CommandBase, Lanes, Specs} from "./Base.sol";
|
|
5
|
+
using Executions for Execution;
|
|
7
6
|
|
|
7
|
+
/// @notice Hook implemented by hosts that withdraw account balances.
|
|
8
8
|
abstract contract WithdrawHook {
|
|
9
9
|
/// @notice Override to send funds to `account`.
|
|
10
10
|
/// Called once per BALANCE block in state.
|
|
@@ -19,31 +19,28 @@ abstract contract WithdrawHook {
|
|
|
19
19
|
/// Use `withdraw` for assets being sent outside the protocol (e.g. ERC-20 transfers, ETH sends).
|
|
20
20
|
/// For internal balance credits, use `creditAccount` instead.
|
|
21
21
|
abstract contract Withdraw is CommandBase, WithdrawHook {
|
|
22
|
-
|
|
22
|
+
uint private immutable descriptor;
|
|
23
23
|
|
|
24
24
|
constructor() {
|
|
25
|
-
(, descriptor) = command("withdraw",
|
|
25
|
+
(, descriptor) = command("withdraw", Specs.Balance, Specs.Empty, Specs.Empty, 0, false, false);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/// @notice Withdraw each BALANCE block from the command state to the command account.
|
|
29
|
-
/// @param
|
|
29
|
+
/// @param state BALANCE block stream.
|
|
30
30
|
/// @return Empty output state.
|
|
31
31
|
/// @return Empty transaction stream.
|
|
32
32
|
function withdraw(
|
|
33
|
-
|
|
33
|
+
bytes32 account,
|
|
34
|
+
bytes calldata state,
|
|
35
|
+
bytes calldata
|
|
34
36
|
) external onlyCommand returns (bytes memory, bytes memory) {
|
|
35
|
-
|
|
37
|
+
Execution memory exec = openState(state, descriptor, 0);
|
|
36
38
|
|
|
37
|
-
while (
|
|
38
|
-
(bytes32 asset, uint amount) =
|
|
39
|
-
withdraw(
|
|
39
|
+
while (exec.more()) {
|
|
40
|
+
(bytes32 asset, uint amount) = exec.unpackBalance(Lanes.State);
|
|
41
|
+
withdraw(account, asset, amount);
|
|
40
42
|
}
|
|
41
|
-
|
|
43
|
+
|
|
44
|
+
return close(exec, account);
|
|
42
45
|
}
|
|
43
46
|
}
|
|
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,
|
|
5
|
-
|
|
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
|
|
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
|
|
17
|
+
/// Each ASSET block in the input calls `allowAsset`. Only callable by the admin account.
|
|
18
18
|
abstract contract AllowAssets is AdminBase, AllowAssetsHook {
|
|
19
|
-
|
|
19
|
+
uint private immutable descriptor;
|
|
20
20
|
|
|
21
21
|
constructor() {
|
|
22
|
-
(, descriptor) = command("allowAssets",
|
|
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
|
|
26
|
-
/// @param
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
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,
|
|
5
|
-
|
|
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
|
|
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
|
-
|
|
23
|
+
uint private immutable descriptor;
|
|
24
24
|
|
|
25
25
|
constructor() {
|
|
26
|
-
(, descriptor) = command("allowance",
|
|
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
|
|
30
|
-
/// @param
|
|
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(
|
|
34
|
-
|
|
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 (
|
|
37
|
-
(uint peer, bytes32 asset, uint amount) =
|
|
40
|
+
while (exec.more()) {
|
|
41
|
+
(uint peer, bytes32 asset, uint amount) = exec.unpackAllowance(Lanes.Input);
|
|
38
42
|
allowance(peer, asset, amount);
|
|
39
43
|
}
|
|
40
|
-
|
|
44
|
+
|
|
45
|
+
return close(exec, account);
|
|
41
46
|
}
|
|
42
47
|
}
|
|
@@ -1,34 +1,36 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
|
-
import { AdminBase,
|
|
5
|
-
|
|
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 Appoint
|
|
9
8
|
/// @notice Admin command that grants guardian status to a list of account IDs.
|
|
10
|
-
/// Each ACCOUNT block in the
|
|
9
|
+
/// Each ACCOUNT block in the input is enabled as a guardian on the host.
|
|
11
10
|
/// Only callable by the admin account.
|
|
12
11
|
abstract contract Appoint is AdminBase {
|
|
13
|
-
|
|
12
|
+
uint private immutable descriptor;
|
|
14
13
|
|
|
15
14
|
constructor() {
|
|
16
|
-
(, descriptor) = command("appoint",
|
|
15
|
+
(, descriptor) = command("appoint", Specs.Empty, Specs.Account, Specs.Empty, 0, false, true);
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
/// @notice Appoint each ACCOUNT block in the admin
|
|
20
|
-
/// @param
|
|
18
|
+
/// @notice Appoint each ACCOUNT block in the admin input as a guardian.
|
|
19
|
+
/// @param input ACCOUNT block stream.
|
|
21
20
|
/// @return Empty output state.
|
|
22
21
|
/// @return Empty transaction stream.
|
|
23
22
|
function appoint(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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);
|
|
27
28
|
|
|
28
|
-
while (
|
|
29
|
-
bytes32
|
|
30
|
-
setGuardian(
|
|
29
|
+
while (exec.more()) {
|
|
30
|
+
bytes32 guardian = exec.unpackAccount(Lanes.Input);
|
|
31
|
+
setGuardian(guardian, true);
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
+
|
|
34
|
+
return close(exec, account);
|
|
33
35
|
}
|
|
34
36
|
}
|
|
@@ -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,
|
|
5
|
-
|
|
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
|
|
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
|
-
|
|
14
|
-
uint
|
|
12
|
+
uint private immutable descriptor;
|
|
13
|
+
uint private immutable id;
|
|
15
14
|
|
|
16
15
|
constructor() {
|
|
17
|
-
(
|
|
16
|
+
(id, descriptor) = command("authorize", Specs.Empty, Specs.Node, Specs.Empty, 0, false, true);
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
/// @notice
|
|
21
|
-
|
|
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(
|
|
25
|
-
|
|
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 (
|
|
28
|
-
uint node =
|
|
35
|
+
while (exec.more()) {
|
|
36
|
+
uint node = exec.unpackNode(Lanes.Input);
|
|
29
37
|
setNode(node, true);
|
|
30
38
|
}
|
|
31
|
-
|
|
39
|
+
|
|
40
|
+
return close(exec, account);
|
|
32
41
|
}
|
|
33
42
|
}
|
package/commands/admin/Base.sol
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
|
-
import {CommandBase,
|
|
4
|
+
import {CommandBase, Execution, Executions, Lanes, Specs} from "../Base.sol";
|
|
5
5
|
|
|
6
6
|
/// @title AdminBase
|
|
7
7
|
/// @notice Shared base for admin commands.
|
|
@@ -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,
|
|
5
|
-
|
|
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 deny assets.
|
|
8
8
|
abstract contract DenyAssetsHook {
|
|
9
9
|
/// @dev Override to deny a single asset.
|
|
10
|
-
/// Called once per ASSET block in the
|
|
10
|
+
/// Called once per ASSET block in the input.
|
|
11
11
|
/// @param asset Asset identifier.
|
|
12
12
|
function denyAsset(bytes32 asset) internal virtual;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/// @title DenyAssets
|
|
16
16
|
/// @notice Admin command that blocks a list of assets via a virtual hook.
|
|
17
|
-
/// Each ASSET block in the
|
|
17
|
+
/// Each ASSET block in the input calls `denyAsset`. Only callable by the admin account.
|
|
18
18
|
abstract contract DenyAssets is AdminBase, DenyAssetsHook {
|
|
19
|
-
|
|
19
|
+
uint private immutable descriptor;
|
|
20
20
|
|
|
21
21
|
constructor() {
|
|
22
|
-
(, descriptor) = command("denyAssets",
|
|
22
|
+
(, descriptor) = command("denyAssets", Specs.Empty, Specs.Asset, Specs.Empty, 0, false, true);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
/// @notice Deny each ASSET block in the admin
|
|
26
|
-
/// @param
|
|
25
|
+
/// @notice Deny 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 denyAssets(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
denyAsset(asset);
|
|
37
39
|
}
|
|
38
|
-
|
|
40
|
+
|
|
41
|
+
return close(exec, account);
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
|