@rootzero/contracts 0.9.0 → 0.9.1

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 (44) hide show
  1. package/Commands.sol +15 -16
  2. package/Events.sol +2 -1
  3. package/blocks/Cursors.sol +25 -64
  4. package/blocks/Keys.sol +0 -2
  5. package/blocks/Schema.sol +0 -1
  6. package/commands/Burn.sol +2 -2
  7. package/commands/Credit.sol +2 -1
  8. package/commands/Debit.sol +2 -2
  9. package/commands/Deposit.sol +8 -7
  10. package/commands/Pipe.sol +2 -2
  11. package/commands/Provision.sol +8 -7
  12. package/commands/Transfer.sol +2 -2
  13. package/commands/Withdraw.sol +2 -2
  14. package/commands/{admin → control}/AllowAssets.sol +7 -6
  15. package/commands/{admin → control}/Allowance.sol +11 -11
  16. package/commands/{admin → control}/Authorize.sol +6 -5
  17. package/commands/{admin → control}/DenyAssets.sol +7 -6
  18. package/commands/{admin → control}/Destroy.sol +6 -5
  19. package/commands/{admin → control}/Execute.sol +6 -5
  20. package/commands/{admin → control}/Init.sol +6 -5
  21. package/commands/{admin → control}/Unauthorize.sol +6 -5
  22. package/core/Access.sol +2 -2
  23. package/core/Host.sol +5 -6
  24. package/core/Types.sol +1 -1
  25. package/events/Control.sol +31 -0
  26. package/events/Query.sol +4 -4
  27. package/events/Remote.sol +24 -0
  28. package/package.json +1 -1
  29. package/remote/AllowAssets.sol +39 -0
  30. package/remote/Allowance.sol +36 -0
  31. package/remote/AssetPull.sol +44 -0
  32. package/remote/Base.sol +40 -0
  33. package/remote/DenyAssets.sol +39 -0
  34. package/remote/Settle.sol +33 -0
  35. package/utils/Ids.sol +30 -30
  36. package/utils/Layout.sol +3 -3
  37. package/commands/admin/Relocate.sol +0 -43
  38. package/events/Peer.sol +0 -24
  39. package/peer/AllowAssets.sol +0 -39
  40. package/peer/Allowance.sol +0 -36
  41. package/peer/AssetPull.sol +0 -44
  42. package/peer/Base.sol +0 -40
  43. package/peer/DenyAssets.sol +0 -39
  44. package/peer/Settle.sol +0 -33
@@ -1,43 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import { CommandContext, CommandPayable, Keys } from "../Base.sol";
5
- import { Cursors, Cur, Schemas } from "../../Cursors.sol";
6
- import { Budget, Values } from "../../utils/Value.sol";
7
- using Cursors for Cur;
8
-
9
- string constant NAME = "relocatePayable";
10
-
11
- /// @title RelocatePayable
12
- /// @notice Admin command that forwards native value (ETH) to one or more destination hosts.
13
- /// Each RELOCATION block in the request specifies a target host node ID and an amount to forward.
14
- /// Only callable by the admin account.
15
- abstract contract RelocatePayable is CommandPayable {
16
- uint internal immutable relocatePayableId = commandId(NAME);
17
-
18
- constructor() {
19
- emit Command(host, relocatePayableId, NAME, Schemas.Relocation, Keys.Empty, Keys.Empty, true);
20
- }
21
-
22
- function relocatePayable(
23
- CommandContext calldata c
24
- ) external payable onlyAdmin(c.account) returns (bytes memory) {
25
- (Cur memory request, , ) = cursor(c.request, 1);
26
- Budget memory budget = Values.fromMsg();
27
-
28
- while (request.i < request.bound) {
29
- (uint peer, uint amount) = request.unpackRelocation();
30
- callTo(peer, Values.use(budget, amount), "");
31
- }
32
-
33
- request.complete();
34
- settleValue(c.account, budget);
35
- return "";
36
- }
37
- }
38
-
39
-
40
-
41
-
42
-
43
-
package/events/Peer.sol DELETED
@@ -1,24 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import { EventEmitter } from "./Emitter.sol";
5
-
6
- string constant ABI =
7
- "event Peer(uint indexed host, uint id, string name, string schema, bool acceptsValue)";
8
-
9
- /// @notice Emitted once per peer during host deployment to publish its schema.
10
- abstract contract PeerEvent is EventEmitter {
11
- /// @param host Host node ID that owns this peer.
12
- /// @param id Peer node ID.
13
- /// @param name Human-readable peer name.
14
- /// @param schema Schema DSL string describing the peer request shape.
15
- /// @param acceptsValue Whether the peer entrypoint accepts nonzero `msg.value`.
16
- event Peer(uint indexed host, uint id, string name, string schema, bool acceptsValue);
17
-
18
- constructor() {
19
- emit EventAbi(ABI);
20
- }
21
- }
22
-
23
-
24
-
@@ -1,39 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import { PeerBase } from "./Base.sol";
5
- import { AllowAssetsHook } from "../commands/admin/AllowAssets.sol";
6
- import { Cursors, Cur, Schemas } from "../Cursors.sol";
7
-
8
- using Cursors for Cur;
9
-
10
- string constant NAME = "peerAllowAssets";
11
-
12
- /// @title PeerAllowAssets
13
- /// @notice Peer that permits a list of (asset, meta) pairs on behalf of a remote host.
14
- /// Each ASSET block in the request calls `allowAsset`. Restricted to trusted peers.
15
- abstract contract PeerAllowAssets is PeerBase, AllowAssetsHook {
16
- uint internal immutable peerAllowAssetsId = peerId(NAME);
17
-
18
- constructor() {
19
- emit Peer(host, peerAllowAssetsId, NAME, Schemas.Asset, false);
20
- }
21
-
22
- /// @notice Execute the allow-assets peer call.
23
- function peerAllowAssets(bytes calldata request) external onlyPeer returns (bytes memory) {
24
- (Cur memory assets, , ) = cursor(request, 1);
25
-
26
- while (assets.i < assets.bound) {
27
- (bytes32 asset, bytes32 meta) = assets.unpackAsset();
28
- allowAsset(asset, meta);
29
- }
30
-
31
- assets.complete();
32
- return "";
33
- }
34
- }
35
-
36
-
37
-
38
-
39
-
@@ -1,36 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import {PeerBase} from "./Base.sol";
5
- import {AllowanceHook} from "../commands/admin/Allowance.sol";
6
- import {Cursors, Cur, Schemas} from "../Cursors.sol";
7
-
8
- using Cursors for Cur;
9
-
10
- string constant NAME = "peerAllowance";
11
-
12
- /// @title PeerAllowance
13
- /// @notice Peer that lets a trusted remote host request or refresh its own allowance.
14
- /// Each AMOUNT block in the request is scoped to `caller()` and passed to the shared
15
- /// allowance hook as a host-scoped allowance. Restricted to trusted peers.
16
- abstract contract PeerAllowance is PeerBase, AllowanceHook {
17
- uint internal immutable peerAllowanceId = peerId(NAME);
18
-
19
- constructor() {
20
- emit Peer(host, peerAllowanceId, NAME, Schemas.Amount, false);
21
- }
22
-
23
- /// @notice Execute the allowance peer call.
24
- function peerAllowance(bytes calldata request) external onlyPeer returns (bytes memory) {
25
- (Cur memory amounts, , ) = cursor(request, 1);
26
- uint peer = caller();
27
-
28
- while (amounts.i < amounts.bound) {
29
- (bytes32 asset, bytes32 meta, uint amount) = amounts.unpackAmount();
30
- allowance(peer, asset, meta, amount);
31
- }
32
-
33
- amounts.complete();
34
- return "";
35
- }
36
- }
@@ -1,44 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import {PeerBase} from "./Base.sol";
5
- import {Cursors, Cur, Schemas} from "../Cursors.sol";
6
-
7
- string constant NAME = "peerAssetPull";
8
-
9
- using Cursors for Cur;
10
-
11
- abstract contract PeerAssetPullHook {
12
- /// @notice Override to process one incoming amount-based asset pull request from a remote host.
13
- /// @param peer Host node ID derived from the caller address.
14
- /// @param asset Requested asset identifier.
15
- /// @param meta Requested asset metadata slot.
16
- /// @param amount Requested amount in the asset's native units.
17
- function peerAssetPull(uint peer, bytes32 asset, bytes32 meta, uint amount) internal virtual;
18
- }
19
-
20
- /// @title PeerAssetPull
21
- /// @notice Peer that pulls requested asset amounts from a remote host into this one.
22
- /// Each AMOUNT block in the request calls `peerAssetPull(peer, asset, meta, amount)`, where `peer`
23
- /// is derived from `msg.sender`. Restricted to trusted peers.
24
- abstract contract PeerAssetPull is PeerBase, PeerAssetPullHook {
25
- uint internal immutable peerAssetPullId = peerId(NAME);
26
-
27
- constructor() {
28
- emit Peer(host, peerAssetPullId, NAME, Schemas.Amount, false);
29
- }
30
-
31
- /// @notice Execute the asset-pull peer call.
32
- function peerAssetPull(bytes calldata request) external onlyPeer returns (bytes memory) {
33
- (Cur memory assets, , ) = cursor(request, 1);
34
- uint peer = caller();
35
-
36
- while (assets.i < assets.bound) {
37
- (bytes32 asset, bytes32 meta, uint amount) = assets.unpackAmount();
38
- peerAssetPull(peer, asset, meta, amount);
39
- }
40
-
41
- assets.complete();
42
- return "";
43
- }
44
- }
package/peer/Base.sol DELETED
@@ -1,40 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import { NodeCalls } from "../core/Calls.sol";
5
- import { PeerEvent } from "../events/Peer.sol";
6
- import { Ids, Selectors } from "../utils/Ids.sol";
7
-
8
- /// @notice ABI-encode a peer call from a target peer ID and request block stream.
9
- /// @dev Derives the function selector from `target` via `Ids.peerSelector(target)`.
10
- /// Reverts if `target` is not a valid peer ID.
11
- /// @param target Destination peer node ID embedding the target selector.
12
- /// @param request Input block stream for the peer invocation.
13
- /// @return ABI-encoded calldata for the peer entry point.
14
- function encodePeerCall(uint target, bytes calldata request) pure returns (bytes memory) {
15
- bytes4 selector = Ids.peerSelector(target);
16
- return abi.encodeWithSelector(selector, request);
17
- }
18
-
19
- /// @title PeerBase
20
- /// @notice Abstract base for all rootzero peer contracts.
21
- /// Peers handle inter-host operations and asset allow/deny management
22
- /// between cooperating hosts. Access is restricted to trusted callers via `onlyPeer`.
23
- abstract contract PeerBase is NodeCalls, PeerEvent {
24
- /// @dev Thrown when the commander attempts to call a peer entrypoint directly.
25
- error CommanderNotAllowed();
26
-
27
- /// @dev Restrict execution to trusted callers, excluding the commander.
28
- modifier onlyPeer() {
29
- if (msg.sender == commander) revert CommanderNotAllowed();
30
- enforceCaller(msg.sender);
31
- _;
32
- }
33
-
34
- /// @notice Derive the deterministic node ID for a named peer on this contract.
35
- /// @param name Peer function name (without argument list).
36
- /// @return Peer node ID.
37
- function peerId(string memory name) internal view returns (uint) {
38
- return Ids.toPeer(Selectors.peer(name), address(this));
39
- }
40
- }
@@ -1,39 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import {PeerBase} from "./Base.sol";
5
- import {DenyAssetsHook} from "../commands/admin/DenyAssets.sol";
6
- import {Cursors, Cur, Schemas} from "../Cursors.sol";
7
-
8
- using Cursors for Cur;
9
-
10
- string constant NAME = "peerDenyAssets";
11
-
12
- /// @title PeerDenyAssets
13
- /// @notice Peer that blocks a list of (asset, meta) pairs on behalf of a remote host.
14
- /// Each ASSET block in the request calls `denyAsset`. Restricted to trusted peers.
15
- abstract contract PeerDenyAssets is PeerBase, DenyAssetsHook {
16
- uint internal immutable peerDenyAssetsId = peerId(NAME);
17
-
18
- constructor() {
19
- emit Peer(host, peerDenyAssetsId, NAME, Schemas.Asset, false);
20
- }
21
-
22
- /// @notice Execute the deny-assets peer call.
23
- function peerDenyAssets(bytes calldata request) external onlyPeer returns (bytes memory) {
24
- (Cur memory assets, , ) = cursor(request, 1);
25
-
26
- while (assets.i < assets.bound) {
27
- (bytes32 asset, bytes32 meta) = assets.unpackAsset();
28
- denyAsset(asset, meta);
29
- }
30
-
31
- assets.complete();
32
- return "";
33
- }
34
- }
35
-
36
-
37
-
38
-
39
-
package/peer/Settle.sol DELETED
@@ -1,33 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import { PeerBase } from "./Base.sol";
5
- import { TransferHook } from "../commands/Transfer.sol";
6
- import { Cursors, Cur, Schemas } from "../Cursors.sol";
7
-
8
- using Cursors for Cur;
9
-
10
- string constant NAME = "peerSettle";
11
-
12
- /// @title PeerSettle
13
- /// @notice Peer that consumes peer-supplied TRANSACTION blocks through the shared transfer hook.
14
- /// Each TRANSACTION block in the request calls `transfer(value)`. Restricted to trusted peers.
15
- abstract contract PeerSettle is PeerBase, TransferHook {
16
- uint internal immutable peerSettleId = peerId(NAME);
17
-
18
- constructor() {
19
- emit Peer(host, peerSettleId, NAME, Schemas.Transaction, false);
20
- }
21
-
22
- /// @notice Execute the peer-settle call.
23
- function peerSettle(bytes calldata request) external onlyPeer returns (bytes memory) {
24
- (Cur memory state, , ) = cursor(request, 1);
25
-
26
- while (state.i < state.bound) {
27
- transfer(state.unpackTxValue());
28
- }
29
-
30
- state.complete();
31
- return "";
32
- }
33
- }