@rootzero/contracts 0.8.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 (82) hide show
  1. package/Commands.sol +17 -23
  2. package/Core.sol +3 -4
  3. package/Cursors.sol +4 -6
  4. package/Events.sol +3 -2
  5. package/Queries.sol +1 -1
  6. package/README.md +18 -19
  7. package/Utils.sol +3 -3
  8. package/blocks/Cursors.sol +1398 -0
  9. package/blocks/Keys.sol +57 -34
  10. package/blocks/Schema.sol +108 -126
  11. package/blocks/Writers.sol +476 -301
  12. package/commands/Base.sol +32 -22
  13. package/commands/Burn.sol +5 -5
  14. package/commands/Credit.sol +8 -8
  15. package/commands/Debit.sol +5 -5
  16. package/commands/Deposit.sol +13 -12
  17. package/commands/Pipe.sol +5 -5
  18. package/commands/Provision.sol +25 -54
  19. package/commands/Transfer.sol +11 -21
  20. package/commands/Withdraw.sol +7 -8
  21. package/commands/{admin → control}/AllowAssets.sol +9 -8
  22. package/commands/control/Allowance.sol +43 -0
  23. package/commands/{admin → control}/Authorize.sol +9 -8
  24. package/commands/{admin → control}/DenyAssets.sol +9 -8
  25. package/commands/{admin → control}/Destroy.sol +8 -7
  26. package/commands/control/Execute.sol +39 -0
  27. package/commands/{admin → control}/Init.sol +8 -7
  28. package/commands/{admin → control}/Unauthorize.sol +9 -8
  29. package/core/Access.sol +40 -36
  30. package/core/Balances.sol +17 -18
  31. package/core/{Operation.sol → Calls.sol} +5 -8
  32. package/core/{CursorBase.sol → Context.sol} +11 -5
  33. package/core/Host.sol +9 -9
  34. package/core/Types.sol +86 -0
  35. package/docs/GETTING_STARTED.md +37 -29
  36. package/events/Asset.sol +1 -1
  37. package/events/Command.sol +10 -10
  38. package/events/Control.sol +31 -0
  39. package/events/Deposit.sol +3 -4
  40. package/events/Listing.sol +1 -1
  41. package/events/Position.sol +21 -0
  42. package/events/Query.sol +5 -5
  43. package/events/Remote.sol +24 -0
  44. package/events/Withdraw.sol +2 -3
  45. package/package.json +1 -1
  46. package/queries/Assets.sol +8 -8
  47. package/queries/Balances.sol +11 -11
  48. package/queries/Base.sol +2 -3
  49. package/queries/Positions.sol +25 -19
  50. package/remote/AllowAssets.sol +39 -0
  51. package/remote/Allowance.sol +36 -0
  52. package/remote/AssetPull.sol +44 -0
  53. package/remote/Base.sol +40 -0
  54. package/remote/DenyAssets.sol +39 -0
  55. package/remote/Settle.sol +33 -0
  56. package/utils/Accounts.sol +14 -13
  57. package/utils/Assets.sol +77 -57
  58. package/utils/Ids.sol +34 -34
  59. package/utils/Layout.sol +4 -4
  60. package/utils/Utils.sol +10 -0
  61. package/blocks/cursors/Core.sol +0 -1121
  62. package/blocks/cursors/Erc1155.sol +0 -149
  63. package/blocks/cursors/Erc20.sol +0 -130
  64. package/blocks/cursors/Erc721.sol +0 -66
  65. package/commands/Create.sol +0 -44
  66. package/commands/Remove.sol +0 -44
  67. package/commands/Settle.sol +0 -38
  68. package/commands/Stake.sol +0 -49
  69. package/commands/Supply.sol +0 -43
  70. package/commands/admin/Allocate.sol +0 -43
  71. package/commands/admin/Relocate.sol +0 -43
  72. package/core/HostBound.sol +0 -14
  73. package/events/Erc721.sol +0 -20
  74. package/events/Peer.sol +0 -24
  75. package/peer/AllowAssets.sol +0 -39
  76. package/peer/AssetPull.sol +0 -44
  77. package/peer/Base.sol +0 -36
  78. package/peer/DenyAssets.sol +0 -39
  79. package/peer/Pull.sol +0 -41
  80. package/peer/Push.sol +0 -47
  81. package/peer/Settle.sol +0 -34
  82. package/utils/State.sol +0 -22
package/events/Erc721.sol DELETED
@@ -1,20 +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 = "event Erc721Position(bytes32 indexed account, bytes32 asset, bytes32 meta, uint position, uint qid)";
7
-
8
- /// @notice Emitted when the lifecycle state of an ERC-721-backed position changes.
9
- abstract contract Erc721PositionEvent is EventEmitter {
10
- /// @param account Account identifier that owns or is associated with the position.
11
- /// @param asset Asset identifier for the ERC-721 class.
12
- /// @param meta Asset metadata slot, typically carrying the token-specific position context.
13
- /// @param position Context-specific position value; positive means active and 0 means closed.
14
- /// @param qid Query ID associated with the position lookup or reporting context.
15
- event Erc721Position(bytes32 indexed account, bytes32 asset, bytes32 meta, uint position, uint qid);
16
-
17
- constructor() {
18
- emit EventAbi(ABI);
19
- }
20
- }
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, string name, string schema, uint pid, 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 name Human-readable peer name.
13
- /// @param schema Schema DSL string describing the peer request shape.
14
- /// @param pid Peer node ID.
15
- /// @param acceptsValue Whether the peer entrypoint accepts nonzero `msg.value`.
16
- event Peer(uint indexed host, string name, string schema, uint pid, 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, NAME, Schemas.Asset, peerAllowAssetsId, 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,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, NAME, Schemas.Amount, peerAssetPullId, 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,36 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import { OperationBase } from "../core/Operation.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 asset flows (push/pull) and asset allow/deny management
22
- /// between cooperating hosts. Access is restricted to trusted callers via `onlyPeer`.
23
- abstract contract PeerBase is OperationBase, PeerEvent {
24
- /// @dev Restrict execution to trusted callers (authorized hosts or the commander).
25
- modifier onlyPeer() {
26
- enforceCaller(msg.sender);
27
- _;
28
- }
29
-
30
- /// @notice Derive the deterministic node ID for a named peer on this contract.
31
- /// @param name Peer function name (without argument list).
32
- /// @return Peer node ID.
33
- function peerId(string memory name) internal view returns (uint) {
34
- return Ids.toPeer(Selectors.peer(name), address(this));
35
- }
36
- }
@@ -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, NAME, Schemas.Asset, peerDenyAssetsId, 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/Pull.sol DELETED
@@ -1,41 +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} from "../Cursors.sol";
6
-
7
- string constant NAME = "peerPull";
8
-
9
- using Cursors for Cur;
10
-
11
- abstract contract PeerPullHook {
12
- /// @notice Override to process a single incoming block from the pull request.
13
- /// @param peer Host node ID derived from the caller address.
14
- /// @param input Cursor positioned at the current input block; advance it before returning.
15
- function peerPull(uint peer, Cur memory input) internal virtual;
16
- }
17
-
18
- /// @title PeerPull
19
- /// @notice Peer that pulls assets from a remote host into this one.
20
- /// Each block in the request is dispatched to `peerPull(peer, input)`, where `peer`
21
- /// is derived from `msg.sender`. Restricted to trusted peers.
22
- abstract contract PeerPull is PeerBase, PeerPullHook {
23
- uint internal immutable peerPullId = peerId(NAME);
24
-
25
- constructor(string memory input) {
26
- emit Peer(host, NAME, input, peerPullId, false);
27
- }
28
-
29
- /// @notice Execute the pull peer call.
30
- function peerPull(bytes calldata request) external onlyPeer returns (bytes memory) {
31
- (Cur memory input, , ) = cursor(request, 1);
32
- uint peer = caller();
33
-
34
- while (input.i < input.bound) {
35
- peerPull(peer, input);
36
- }
37
-
38
- input.complete();
39
- return "";
40
- }
41
- }
package/peer/Push.sol DELETED
@@ -1,47 +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 } from "../Cursors.sol";
6
-
7
- string constant NAME = "peerPush";
8
-
9
- using Cursors for Cur;
10
-
11
- abstract contract PeerPushHook {
12
- /// @notice Override to process a single incoming block from the push request.
13
- /// @param peer Host node ID derived from the caller address.
14
- /// @param input Cursor positioned at the current input block; advance it before returning.
15
- function peerPush(uint peer, Cur memory input) internal virtual;
16
- }
17
-
18
- /// @title PeerPush
19
- /// @notice Peer that receives assets pushed from a remote host into this one.
20
- /// Each block in the request is dispatched to `peerPush(peer, input)`, where `peer`
21
- /// is derived from `msg.sender`. Restricted to trusted peers.
22
- abstract contract PeerPush is PeerBase, PeerPushHook {
23
- uint internal immutable peerPushId = peerId(NAME);
24
-
25
- constructor(string memory input) {
26
- emit Peer(host, NAME, input, peerPushId, false);
27
- }
28
-
29
- /// @notice Execute the push peer call.
30
- function peerPush(bytes calldata request) external onlyPeer returns (bytes memory) {
31
- (Cur memory input, , ) = cursor(request, 1);
32
- uint peer = caller();
33
-
34
- while (input.i < input.bound) {
35
- peerPush(peer, input);
36
- }
37
-
38
- input.complete();
39
- return "";
40
- }
41
- }
42
-
43
-
44
-
45
-
46
-
47
-
package/peer/Settle.sol DELETED
@@ -1,34 +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, Tx, 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, NAME, Schemas.Transaction, peerSettleId, 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
- Tx memory value = state.unpackTxValue();
28
- transfer(value);
29
- }
30
-
31
- state.complete();
32
- return "";
33
- }
34
- }
package/utils/State.sol DELETED
@@ -1,22 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- /// @title State
5
- /// @notice Command state type discriminants.
6
- /// Each constant tags the shape of the encoded state block stream stored
7
- /// in a command's metadata slot, allowing commands to select the correct
8
- /// decode path without inspecting the raw bytes.
9
- library State {
10
- /// @dev No state; the command produces or expects an empty state stream.
11
- uint8 constant Empty = 0x0001;
12
- /// @dev State stream contains STEP blocks (sub-command invocations).
13
- uint8 constant Steps = 0x0002;
14
- /// @dev State stream contains BALANCE blocks.
15
- uint8 constant Balances = 0x0003;
16
- /// @dev State stream contains TRANSACTION blocks.
17
- uint8 constant Transactions = 0x0004;
18
- /// @dev State stream contains CUSTODY blocks.
19
- uint8 constant Custodies = 0x0005;
20
- /// @dev State stream contains claim records.
21
- uint8 constant Claims = 0x0006;
22
- }