@rootzero/contracts 1.10.0 → 1.12.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 (60) hide show
  1. package/CHANGELOG.md +46 -1
  2. package/Core.sol +1 -0
  3. package/Endpoints.sol +2 -3
  4. package/Events.sol +2 -5
  5. package/README.md +38 -36
  6. package/Utils.sol +2 -1
  7. package/blocks/Cursors.sol +39 -75
  8. package/blocks/Keys.sol +18 -4
  9. package/blocks/Schema.sol +53 -47
  10. package/commands/Base.sol +43 -13
  11. package/commands/Burn.sol +3 -6
  12. package/commands/Credit.sol +4 -6
  13. package/commands/Debit.sol +10 -11
  14. package/commands/Deposit.sol +19 -23
  15. package/commands/Payout.sol +6 -10
  16. package/commands/Provision.sol +19 -23
  17. package/commands/Recover.sol +7 -9
  18. package/commands/Relay.sol +10 -11
  19. package/commands/Withdraw.sol +3 -6
  20. package/commands/admin/AllowAssets.sol +7 -10
  21. package/commands/admin/Allowance.sol +7 -10
  22. package/commands/admin/Appoint.sol +7 -10
  23. package/commands/admin/Authorize.sol +10 -19
  24. package/commands/admin/Base.sol +1 -2
  25. package/commands/admin/DenyAssets.sol +7 -10
  26. package/commands/admin/Dismiss.sol +7 -10
  27. package/commands/admin/Execute.sol +7 -10
  28. package/commands/admin/Label.sol +8 -11
  29. package/commands/admin/Schemas.sol +31 -0
  30. package/commands/admin/Unauthorize.sol +10 -19
  31. package/core/Endpoint.sol +160 -0
  32. package/core/Host.sol +1 -1
  33. package/docs/Schema.md +124 -86
  34. package/events/Endpoint.sol +19 -0
  35. package/events/Schema.sol +23 -0
  36. package/guards/Base.sol +17 -8
  37. package/guards/Revoke.sol +4 -6
  38. package/package.json +1 -1
  39. package/ports/AllowAssets.sol +6 -9
  40. package/ports/Allowance.sol +6 -9
  41. package/ports/Base.sol +21 -8
  42. package/ports/Credit.sol +6 -9
  43. package/ports/Debit.sol +6 -9
  44. package/ports/DenyAssets.sol +6 -9
  45. package/ports/Dispatch.sol +6 -9
  46. package/ports/Pipe.sol +4 -7
  47. package/ports/Redeem.sol +4 -7
  48. package/ports/Settle.sol +6 -9
  49. package/queries/Assets.sol +9 -12
  50. package/queries/Balances.sol +7 -9
  51. package/queries/Base.sol +19 -11
  52. package/utils/Selectors.sol +49 -0
  53. package/commands/admin/Destroy.sol +0 -43
  54. package/commands/admin/Init.sol +0 -43
  55. package/events/Admin.sol +0 -32
  56. package/events/Command.sol +0 -32
  57. package/events/Guard.sol +0 -18
  58. package/events/Port.sol +0 -22
  59. package/events/Query.sol +0 -20
  60. package/queries/Positions.sol +0 -54
@@ -1,43 +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
-
7
- using Cursors for Cur;
8
-
9
- abstract contract InitHook {
10
- /// @notice Override to run host initialization logic.
11
- /// @param input Cursor over the full request byte stream.
12
- function init(Cur memory input) internal virtual;
13
- }
14
-
15
- /// @title Init
16
- /// @notice Admin command that runs host initialization logic via a virtual hook.
17
- /// The full request is passed to `init` as a cursor. Only callable by the admin account.
18
- abstract contract Init is AdminBase, InitHook {
19
- uint internal immutable initId = commandId(this.init.selector);
20
-
21
- /// @param input Request schema advertised for initialization input.
22
- constructor(string memory input) {
23
- emit Admin(host, initId, "1:0:0", input, Keys.Empty, Keys.Empty, false);
24
- emit Labeled(initId, bytes32(0), "init");
25
- }
26
-
27
- /// @notice Run host initialization logic over the full admin request.
28
- /// @param c Admin command context; `c.request` is passed through as a cursor.
29
- /// @return Empty output state.
30
- function init(
31
- CommandContext calldata c
32
- ) external onlyAdmin(c.account) returns (bytes memory) {
33
- init(Cursors.open(c.request));
34
- return "";
35
- }
36
- }
37
-
38
-
39
-
40
-
41
-
42
-
43
-
package/events/Admin.sol DELETED
@@ -1,32 +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 once per admin command during host deployment to publish its request schema and state keys.
7
- abstract contract AdminEvent is EventEmitter {
8
- string private constant ABI =
9
- "event Admin(uint indexed host, uint id, bytes32 shape, string request, bytes4 state, bytes4 output, bool funded)";
10
-
11
- /// @param host Host node ID that owns this admin command.
12
- /// @param id Command node ID.
13
- /// @param shape Per-operation block counts encoded as `request:state:output`.
14
- /// Request and state are each a single run of blocks under the current command convention.
15
- /// @param request Schema DSL string describing the input request run, or empty if none.
16
- /// @param state Block key expected for input state, `Keys.Empty`, or `Keys.Any`.
17
- /// @param output Block key produced for output state, or `Keys.Empty`.
18
- /// @param funded Whether the command entrypoint accepts nonzero `msg.value`.
19
- event Admin(
20
- uint indexed host,
21
- uint id,
22
- bytes32 shape,
23
- string request,
24
- bytes4 state,
25
- bytes4 output,
26
- bool funded
27
- );
28
-
29
- constructor() {
30
- emit EventAbi(ABI);
31
- }
32
- }
@@ -1,32 +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 once per command during host deployment to publish its request schema and state keys.
7
- abstract contract CommandEvent is EventEmitter {
8
- string private constant ABI =
9
- "event Command(uint indexed host, uint id, bytes32 shape, string request, bytes4 state, bytes4 output, bool funded)";
10
-
11
- /// @param host Host node ID that owns this command.
12
- /// @param id Command node ID.
13
- /// @param shape Per-operation block counts encoded as `request:state:output`.
14
- /// Request and state are each a single run of blocks under the current command convention.
15
- /// @param request Schema string describing the input request run, or empty if none.
16
- /// @param state Block key expected for input state, `Keys.Empty`, or `Keys.Any`.
17
- /// @param output Block key produced for output state, or `Keys.Empty`.
18
- /// @param funded Whether the command entrypoint accepts nonzero `msg.value`.
19
- event Command(
20
- uint indexed host,
21
- uint id,
22
- bytes32 shape,
23
- string request,
24
- bytes4 state,
25
- bytes4 output,
26
- bool funded
27
- );
28
-
29
- constructor() {
30
- emit EventAbi(ABI);
31
- }
32
- }
package/events/Guard.sol DELETED
@@ -1,18 +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 once per guard action during host deployment to publish its request schema.
7
- abstract contract GuardEvent is EventEmitter {
8
- string private constant ABI = "event Guard(uint indexed host, uint id, string request)";
9
-
10
- /// @param host Host node ID that owns this guard action.
11
- /// @param id Guard action node ID.
12
- /// @param request Schema DSL string describing the guard action request shape.
13
- event Guard(uint indexed host, uint id, string request);
14
-
15
- constructor() {
16
- emit EventAbi(ABI);
17
- }
18
- }
package/events/Port.sol DELETED
@@ -1,22 +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 by hosts to advertise callable peer-facing ports.
7
- abstract contract PortEvent is EventEmitter {
8
- string private constant ABI =
9
- "event Port(uint indexed host, uint id, bytes32 shape, string request, string response, bool funded)";
10
-
11
- /// @param host Host node ID that exposes the port.
12
- /// @param id Port node ID.
13
- /// @param shape Block shape/version descriptor.
14
- /// @param request Human-readable request schema.
15
- /// @param response Human-readable response schema.
16
- /// @param funded True if the port accepts native value.
17
- event Port(uint indexed host, uint id, bytes32 shape, string request, string response, bool funded);
18
-
19
- constructor() {
20
- emit EventAbi(ABI);
21
- }
22
- }
package/events/Query.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
- /// @notice Emitted once per query during host deployment to publish its request and response schemas.
7
- abstract contract QueryEvent is EventEmitter {
8
- string private constant ABI = "event Query(uint indexed host, uint id, bytes32 shape, string request, string response)";
9
-
10
- /// @param host Host node ID that owns this query.
11
- /// @param id Query node ID.
12
- /// @param shape Per-operation block counts encoded as `request:response`.
13
- /// @param request Schema DSL string describing the input request run, or empty if none.
14
- /// @param response Schema DSL string describing the query response shape.
15
- event Query(uint indexed host, uint id, bytes32 shape, string request, string response);
16
-
17
- constructor() {
18
- emit EventAbi(ABI);
19
- }
20
- }
@@ -1,54 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import {Cur, Cursors, Writer, Writers} from "../Cursors.sol";
5
- import {Forms} from "../blocks/Schema.sol";
6
- import {QueryBase} from "./Base.sol";
7
-
8
- using Cursors for Cur;
9
- using Writers for Writer;
10
-
11
- abstract contract GetPositionHook {
12
- /// @notice Append the position response for one requested position.
13
- /// Concrete implementations must append exactly one response block matching
14
- /// the query output schema.
15
- /// @param account Requested account identifier.
16
- /// @param asset Requested asset identifier.
17
- /// @param response Destination writer for the response stream.
18
- function appendPosition(
19
- bytes32 account,
20
- bytes32 asset,
21
- Writer memory response
22
- ) internal view virtual;
23
- }
24
-
25
- /// @title GetPosition
26
- /// @notice Rootzero query that resolves one dynamic position response for each requested position.
27
- /// The request is a run of `ACCOUNT_ASSET` form blocks.
28
- /// The response returns one output-schema block per position entry, preserving request order.
29
- abstract contract GetPosition is QueryBase, GetPositionHook {
30
- uint public immutable getPositionId = queryId(this.getPosition.selector);
31
-
32
- /// @param output Response schema advertised for each position output block.
33
- constructor(string memory output) {
34
- emit Query(host, getPositionId, "1:1", Forms.AccountAsset, output);
35
- emit Labeled(getPositionId, bytes32(0), "getPosition");
36
- }
37
-
38
- /// @notice Resolve positions for a run of requested `(account, asset)` tuples.
39
- /// @dev Allocates from a per-block capacity hint and grows when position outputs exceed it.
40
- /// @param request Block-stream request consisting of `accountAsset(account, asset)*`.
41
- /// @return Block-stream response containing one output-schema block per position block.
42
- function getPosition(bytes calldata request) external view returns (bytes memory) {
43
- (Cur memory query, uint groups) = Cursors.init(request, 1);
44
- Writer memory response = Writers.allocAny(groups);
45
-
46
- while (query.i < query.len) {
47
- (bytes32 account, bytes32 asset) = query.unpackAccountAsset();
48
- appendPosition(account, asset, response);
49
- }
50
-
51
- query.complete();
52
- return response.finish();
53
- }
54
- }