@rootzero/contracts 1.9.0 → 1.11.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 (63) hide show
  1. package/CHANGELOG.md +40 -2
  2. package/Core.sol +3 -1
  3. package/Endpoints.sol +3 -6
  4. package/Events.sol +3 -6
  5. package/README.md +35 -33
  6. package/Utils.sol +2 -1
  7. package/blocks/Cursors.sol +39 -88
  8. package/blocks/Keys.sol +14 -4
  9. package/blocks/Schema.sol +49 -44
  10. package/commands/Base.sol +43 -13
  11. package/commands/Burn.sol +3 -6
  12. package/commands/Credit.sol +9 -6
  13. package/commands/Debit.sol +15 -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 +16 -10
  18. package/commands/Relay.sol +21 -12
  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 +7 -10
  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/Unauthorize.sol +7 -10
  30. package/core/Endpoint.sol +153 -0
  31. package/core/Payable.sol +7 -0
  32. package/core/Pipeline.sol +1 -1
  33. package/core/Portal.sol +19 -48
  34. package/docs/Schema.md +114 -82
  35. package/events/Endpoint.sol +19 -0
  36. package/events/Recovered.sol +17 -0
  37. package/events/Schema.sol +23 -0
  38. package/guards/Base.sol +17 -8
  39. package/guards/Revoke.sol +4 -6
  40. package/package.json +1 -1
  41. package/ports/AllowAssets.sol +6 -9
  42. package/ports/Allowance.sol +6 -9
  43. package/ports/Base.sol +21 -8
  44. package/ports/Credit.sol +6 -9
  45. package/ports/Debit.sol +6 -9
  46. package/ports/DenyAssets.sol +6 -9
  47. package/ports/Dispatch.sol +7 -10
  48. package/ports/Pipe.sol +4 -7
  49. package/ports/Redeem.sol +4 -7
  50. package/ports/Settle.sol +6 -9
  51. package/queries/Assets.sol +9 -12
  52. package/queries/Balances.sol +7 -9
  53. package/queries/Base.sol +19 -11
  54. package/utils/Selectors.sol +49 -0
  55. package/commands/admin/Destroy.sol +0 -43
  56. package/commands/admin/Init.sol +0 -43
  57. package/events/Admin.sol +0 -32
  58. package/events/Command.sol +0 -32
  59. package/events/Guard.sol +0 -18
  60. package/events/Port.sol +0 -22
  61. package/events/Query.sol +0 -20
  62. package/events/Resolved.sol +0 -17
  63. package/queries/Positions.sol +0 -54
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,17 +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 when a host resolves a previously recorded key.
7
- abstract contract ResolvedEvent is EventEmitter {
8
- string private constant ABI = "event Resolved(uint indexed host, bytes32 key)";
9
-
10
- /// @param host Host node ID that owns the resolved key.
11
- /// @param key Resolution lookup key.
12
- event Resolved(uint indexed host, bytes32 key);
13
-
14
- constructor() {
15
- emit EventAbi(ABI);
16
- }
17
- }
@@ -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
- }