@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,32 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import {AdminBase, CommandContext, Keys} from "./Base.sol";
5
- import {Cursors, Cur} from "../../Cursors.sol";
6
- using Cursors for Cur;
7
-
8
- /// @title Label
9
- /// @notice Admin command that publishes namespaced labels for node IDs.
10
- /// Each LABEL block in the request emits one `Labeled` event. Only callable by
11
- /// the admin account.
12
- abstract contract Label is AdminBase {
13
- bytes32 private immutable descriptor;
14
-
15
- constructor() {
16
- (, descriptor) = command("label", Keys.Empty, Keys.Label, Keys.Empty, 0, false, true);
17
- }
18
-
19
- /// @notice Publish each LABEL block in the admin request.
20
- /// @param c Admin command context; `c.input` must contain LABEL blocks.
21
- /// @return Empty output state.
22
- /// @return Empty transaction stream.
23
- function label(CommandContext calldata c) external onlyAdmin(c.account) returns (bytes memory, bytes memory) {
24
- (Cur memory input, ) = openInput(c.input, descriptor);
25
-
26
- while (input.i < input.len) {
27
- (uint node, bytes32 namespace, string memory name) = input.unpackLabel();
28
- emit Labeled(node, namespace, name);
29
- }
30
- return ("", "");
31
- }
32
- }
@@ -1,32 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import {AdminBase, CommandContext, Keys} from "./Base.sol";
5
- import {Cursors, Cur} from "../../Cursors.sol";
6
- using Cursors for Cur;
7
-
8
- /// @title PublishSchema
9
- /// @notice Admin command that publishes block schemas for keys.
10
- /// Each SCHEMA block in the request emits one `Schema` event. Only callable by
11
- /// the admin account.
12
- abstract contract PublishSchema is AdminBase {
13
- bytes32 private immutable descriptor;
14
-
15
- constructor() {
16
- (, descriptor) = command("publishSchema", Keys.Empty, Keys.Schema, Keys.Empty, 0, false, true);
17
- }
18
-
19
- /// @notice Publish each SCHEMA block in the admin request.
20
- /// @param c Admin command context; `c.input` must contain SCHEMA blocks.
21
- /// @return Empty output state.
22
- /// @return Empty transaction stream.
23
- function publishSchema(CommandContext calldata c) external onlyAdmin(c.account) returns (bytes memory, bytes memory) {
24
- (Cur memory input, ) = openInput(c.input, descriptor);
25
-
26
- while (input.i < input.len) {
27
- (bytes4 key, string memory body, bytes32 name) = input.unpackSchema();
28
- emit Schema(host, key, body, name);
29
- }
30
- return ("", "");
31
- }
32
- }
package/core/Payable.sol DELETED
@@ -1,53 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import {Budget, Values} from "../utils/Value.sol";
5
- import {Cursors} from "../Cursors.sol";
6
- import {ReceivedEvent} from "../events/Received.sol";
7
- import {Actions} from "../utils/Actions.sol";
8
- import {NativeAsset} from "./Runtime.sol";
9
- import {max128} from "../utils/Utils.sol";
10
-
11
- /// @title Payable
12
- /// @notice Abstract mixin for entrypoints that accept native value (`msg.value`).
13
- /// Provides shared helpers for mutable native-value budgets.
14
- abstract contract Payable is NativeAsset, ReceivedEvent {
15
- /// @notice Open a native-value budget from the current call's `msg.value`.
16
- /// @return Budget initialized with the full `msg.value`.
17
- function openValue() internal view returns (Budget memory) {
18
- return Budget({remaining: msg.value});
19
- }
20
-
21
- /// @notice Return the current call's native value as a checked uint128.
22
- /// @return value Current `msg.value` in wei.
23
- function msgValue() internal view returns (uint128 value) {
24
- return uint128(max128(msg.value));
25
- }
26
-
27
- /// @notice Deduct the EVM value lane from a packed resource word and return it.
28
- /// @dev EVM resources use the low 128 bits as native value/endowment.
29
- /// @param budget Mutable budget to deduct from.
30
- /// @param resources Packed resources.
31
- /// @return value Native value to forward in wei.
32
- function useValue(Budget memory budget, uint resources) internal pure returns (uint128 value) {
33
- value = uint128(resources);
34
- Values.use(budget, value);
35
- }
36
-
37
- /// @notice Drain a native-value budget into a credit-only TRANSACTION block.
38
- /// @dev Emits `Received` with `Actions.Refund` when a transaction is created.
39
- /// @param budget Mutable budget whose remaining value is drained.
40
- /// @param account Destination account to credit with the remaining native value.
41
- /// @return transaction Encoded TRANSACTION block, or empty bytes when the budget is empty.
42
- function closeValue(
43
- Budget memory budget,
44
- bytes32 account
45
- ) internal returns (bytes memory transaction) {
46
- uint amount = Values.drain(budget);
47
- if (amount == 0) return "";
48
-
49
- transaction = Cursors.toTransactionBlock(bytes32(0), account, nativeAsset, amount);
50
- emit Received(account, nativeAsset, amount, Actions.Refund, 0);
51
- }
52
-
53
- }
@@ -1,21 +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
- /// @notice Emitted to attach a human-readable namespaced label to an entity.
7
- /// @dev Labels are claims by the emitting contract. Any contract may emit a
8
- /// label for any entity, so off-chain indexers must decide which emitters are
9
- /// trusted for each labeled entity or namespace.
10
- abstract contract LabeledEvent is EventEmitter {
11
- string private constant ABI = "event Labeled(uint indexed entity, bytes32 namespace, string name)";
12
-
13
- /// @param entity Entity being labeled.
14
- /// @param namespace Label namespace.
15
- /// @param name Human-readable name within the namespace.
16
- event Labeled(uint indexed entity, bytes32 namespace, string name);
17
-
18
- constructor() {
19
- emit EventAbi(ABI);
20
- }
21
- }
package/events/Schema.sol DELETED
@@ -1,23 +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
- /// @title SchemaEvent
7
- /// @notice Emitted during host deployment to publish a block key and payload schema.
8
- /// Block keys are opaque `bytes4` tags. Standard protocol blocks use
9
- /// keccak-derived keys by convention, but custom block keys only need to be
10
- /// unique within the publishing host/schema context.
11
- abstract contract SchemaEvent is EventEmitter {
12
- string private constant ABI = "event Schema(uint indexed host, bytes4 key, string schema, bytes32 name)";
13
-
14
- /// @param host Host node ID that publishes this block schema.
15
- /// @param key Block type key being defined by `host`.
16
- /// @param schema Schema DSL string describing the block payload body.
17
- /// @param name Optional block alias used by endpoint descriptors and nested schemas.
18
- event Schema(uint indexed host, bytes4 key, string schema, bytes32 name);
19
-
20
- constructor() {
21
- emit EventAbi(ABI);
22
- }
23
- }
package/utils/Value.sol DELETED
@@ -1,43 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- /// @notice Mutable native-value budget drawn down as sub-calls consume ETH.
5
- struct Budget {
6
- /// @dev Remaining unspent native value in wei.
7
- uint remaining;
8
- }
9
-
10
- /// @title Values
11
- /// @notice Native-value budget mutation helpers.
12
- library Values {
13
- /// @dev Thrown when a call attempts to spend more native value than remains in the budget.
14
- error InsufficientValue();
15
-
16
- /// @notice Deduct `amount` from the budget and return it.
17
- /// Reverts if `amount` exceeds `budget.remaining`.
18
- /// @param budget Mutable budget to deduct from.
19
- /// @param amount Native value to spend in wei.
20
- /// @return The same `amount`, ready to forward to a callee.
21
- function use(Budget memory budget, uint amount) internal pure returns (uint) {
22
- if (amount > budget.remaining) revert InsufficientValue();
23
- budget.remaining -= amount;
24
- return amount;
25
- }
26
-
27
- /// @notice Drain the remaining native value from `budget` and return it.
28
- /// @param budget Mutable budget to drain.
29
- /// @return value Native value removed from the budget, in wei.
30
- function drain(Budget memory budget) internal pure returns (uint value) {
31
- value = budget.remaining;
32
- budget.remaining = 0;
33
- }
34
-
35
- /// @notice Deduct `amount` from the budget and return it as a new sub-budget.
36
- /// Reverts if `amount` exceeds `budget.remaining`.
37
- /// @param budget Mutable parent budget to deduct from.
38
- /// @param amount Native value to assign to the sub-budget, in wei.
39
- /// @return A new budget with `amount` remaining.
40
- function allocate(Budget memory budget, uint amount) internal pure returns (Budget memory) {
41
- return Budget({remaining: use(budget, amount)});
42
- }
43
- }