@rootzero/contracts 0.9.3 → 0.9.5

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 (49) hide show
  1. package/Commands.sol +3 -2
  2. package/Core.sol +4 -3
  3. package/Cursors.sol +1 -1
  4. package/Events.sol +2 -3
  5. package/README.md +18 -24
  6. package/blocks/Cursors.sol +316 -337
  7. package/blocks/Keys.sol +40 -57
  8. package/blocks/Schema.sol +57 -208
  9. package/blocks/Writers.sol +376 -135
  10. package/commands/Base.sol +6 -48
  11. package/commands/Burn.sol +2 -2
  12. package/commands/Credit.sol +3 -3
  13. package/commands/Debit.sol +3 -2
  14. package/commands/Deposit.sol +11 -8
  15. package/commands/Provision.sol +11 -8
  16. package/commands/Transfer.sol +2 -2
  17. package/commands/Withdraw.sol +3 -3
  18. package/commands/admin/AllowAssets.sol +1 -1
  19. package/commands/admin/Allowance.sol +1 -1
  20. package/commands/admin/Authorize.sol +1 -1
  21. package/commands/admin/DenyAssets.sol +1 -1
  22. package/commands/admin/Execute.sol +7 -6
  23. package/commands/admin/Unauthorize.sol +1 -1
  24. package/core/Access.sol +11 -0
  25. package/core/Calls.sol +5 -5
  26. package/core/Context.sol +3 -4
  27. package/core/Host.sol +25 -20
  28. package/core/Payable.sol +57 -0
  29. package/core/Pipeline.sol +55 -0
  30. package/docs/Schema.md +196 -0
  31. package/events/Command.sol +1 -2
  32. package/events/Introduction.sol +22 -0
  33. package/events/{Piped.sol → Rooted.sol} +3 -3
  34. package/package.json +2 -2
  35. package/peer/AllowAssets.sol +1 -1
  36. package/peer/Allowance.sol +1 -1
  37. package/peer/BalancePull.sol +1 -1
  38. package/peer/DenyAssets.sol +1 -1
  39. package/peer/Pipe.sol +38 -0
  40. package/peer/Settle.sol +1 -1
  41. package/queries/Assets.sol +4 -3
  42. package/queries/Balances.sol +2 -1
  43. package/queries/Positions.sol +12 -12
  44. package/utils/Value.sol +8 -14
  45. package/commands/Pipe.sol +0 -67
  46. package/docs/GETTING_STARTED.md +0 -294
  47. package/events/Governed.sol +0 -21
  48. package/events/Host.sol +0 -22
  49. package/interfaces/IHostDiscovery.sol +0 -16
package/Commands.sol CHANGED
@@ -4,13 +4,13 @@ pragma solidity ^0.8.33;
4
4
  // Aggregator: re-exports command, admin, and peer abstractions.
5
5
  // Import this file to inherit from the full rootzero command surface without managing individual paths.
6
6
 
7
- import { CommandBase, CommandContext, CommandPayable } from "./commands/Base.sol";
7
+ import { CommandBase, CommandContext } from "./commands/Base.sol";
8
+ import { Payable } from "./core/Payable.sol";
8
9
  import { Keys } from "./blocks/Keys.sol";
9
10
  import { Burn, BurnHook } from "./commands/Burn.sol";
10
11
  import { CreditAccount, CreditAccountHook } from "./commands/Credit.sol";
11
12
  import { DebitAccount, DebitAccountHook } from "./commands/Debit.sol";
12
13
  import { Deposit, DepositHook, DepositPayable, DepositPayableHook } from "./commands/Deposit.sol";
13
- import { PipePayable, PipePayableHook } from "./commands/Pipe.sol";
14
14
  import { Provision, ProvisionHook, ProvisionPayable, ProvisionPayableHook } from "./commands/Provision.sol";
15
15
  import { Transfer, TransferHook } from "./commands/Transfer.sol";
16
16
  import { Withdraw, WithdrawHook } from "./commands/Withdraw.sol";
@@ -27,6 +27,7 @@ import { PeerAllowance } from "./peer/Allowance.sol";
27
27
  import { PeerBalancePull, BalancePullHook } from "./peer/BalancePull.sol";
28
28
  import { PeerAllowAssets } from "./peer/AllowAssets.sol";
29
29
  import { PeerDenyAssets } from "./peer/DenyAssets.sol";
30
+ import { PeerPipePayable } from "./peer/Pipe.sol";
30
31
  import { PeerSettle } from "./peer/Settle.sol";
31
32
 
32
33
 
package/Core.sol CHANGED
@@ -7,11 +7,12 @@ pragma solidity ^0.8.33;
7
7
  import { AccessControl } from "./core/Access.sol";
8
8
  import { Balances } from "./core/Balances.sol";
9
9
  import { RootZeroContext } from "./core/Context.sol";
10
- import { Host } from "./core/Host.sol";
10
+ import { Host, IHostIntroduction } from "./core/Host.sol";
11
11
  import { FailedCall, NodeCalls } from "./core/Calls.sol";
12
+ import { Payable } from "./core/Payable.sol";
13
+ import { Pipeline } from "./core/Pipeline.sol";
14
+ import { AssetAmount, AccountAsset, AccountAmount, HostAmount, HostAccountAsset, HostAccountAmount, Tx } from "./core/Types.sol";
12
15
  import { Validator } from "./core/Validator.sol";
13
- import { HostDiscovery } from "./core/Host.sol";
14
- import { IHostDiscovery } from "./interfaces/IHostDiscovery.sol";
15
16
 
16
17
 
17
18
 
package/Cursors.sol CHANGED
@@ -9,7 +9,7 @@ import { Forms, Sizes } from "./blocks/Schema.sol";
9
9
  import { Keys } from "./blocks/Keys.sol";
10
10
  import { Schemas } from "./blocks/Schema.sol";
11
11
  import { Cursors, Cur } from "./blocks/Cursors.sol";
12
- import { Writer, Writers } from "./blocks/Writers.sol";
12
+ import { Writer, Writers, Hints } from "./blocks/Writers.sol";
13
13
 
14
14
 
15
15
 
package/Events.sol CHANGED
@@ -14,12 +14,11 @@ import { DebtEvent } from "./events/Debt.sol";
14
14
  import { DepositEvent } from "./events/Deposit.sol";
15
15
  import { AssetPositionEvent } from "./events/Position.sol";
16
16
  import { EventEmitter } from "./events/Emitter.sol";
17
- import { GovernedEvent } from "./events/Governed.sol";
18
- import { HostAnnouncedEvent } from "./events/Host.sol";
17
+ import { IntroductionEvent } from "./events/Introduction.sol";
19
18
  import { ListingEvent } from "./events/Listing.sol";
20
19
  import { PeerEvent } from "./events/Peer.sol";
21
20
  import { QueryEvent } from "./events/Query.sol";
22
- import { PipedEvent } from "./events/Piped.sol";
21
+ import { RootedEvent } from "./events/Rooted.sol";
23
22
  import { SwapEvent } from "./events/Swap.sol";
24
23
  import { WithdrawalEvent } from "./events/Withdraw.sol";
25
24
 
package/README.md CHANGED
@@ -15,19 +15,6 @@ Most consumers should start from the package root entry points:
15
15
  - `@rootzero/contracts/Utils.sol` — IDs, assets, accounts, layout, and value helpers
16
16
  - `@rootzero/contracts/Events.sol` — reusable event emitters and event contracts
17
17
 
18
- ## Start Here
19
-
20
- If you are new to rootzero, read [`docs/GETTING_STARTED.md`](docs/GETTING_STARTED.md) first.
21
-
22
- It walks through:
23
-
24
- - the host and command mental model
25
- - which built-in commands expect `request` vs `state`
26
- - a minimal host example
27
- - a built-in command example
28
- - a custom command example
29
- - simple TypeScript request encoding
30
-
31
18
  ## Block Wire Format
32
19
 
33
20
  All request and response data is encoded as a binary block stream. Each block is:
@@ -36,15 +23,15 @@ All request and response data is encoded as a binary block stream. Each block is
36
23
  [bytes4 key][bytes4 payloadLen][payload]
37
24
  ```
38
25
 
39
- `key` is `bytes4(keccak256(schemaString))` see `Keys` for the full set. `Cursors` parses calldata streams zero-copy via the `Cur` struct; `Writers` builds response streams into pre-allocated memory.
26
+ `key` is `bytes4(keccak256("#name"))`; see `Keys` for the full set and [`docs/Schema.md`](docs/Schema.md) for the schema format. `Cursors` parses calldata streams zero-copy via the `Cur` struct; `Writers` builds response streams into pre-allocated memory.
40
27
 
41
28
  ## Schemas, Forms, And State
42
29
 
43
30
  Protocol blocks use schema strings and four-byte keys:
44
31
 
45
- - `Schemas` describes semantic protocol blocks such as `amount(...)`, `balance(...)`, `custody(...)`, and `payout(...)`.
46
- - `Forms` describes reusable structural blocks such as `accountAsset(...)` and `accountAmount(...)`, mostly used by queries.
47
- - `Keys` contains the runtime `bytes4` keys derived from those schema/form strings.
32
+ - `Schemas` describes semantic protocol blocks such as `#amount`, `#balance`, `#custody`, and `#payout`.
33
+ - `Forms` describes reusable structural blocks such as `#accountAsset` and `#accountAmount`, mostly used by queries.
34
+ - `Keys` contains the runtime `bytes4` keys derived from block names.
48
35
 
49
36
  Every command declares its input and output pipeline state with block keys in the `Command` event. Use `Keys.Empty` when a command expects or returns no state.
50
37
 
@@ -80,9 +67,10 @@ Extend `CommandBase` to define a command mixin that runs inside the protocol's t
80
67
  pragma solidity ^0.8.33;
81
68
 
82
69
  import { CommandBase, CommandContext, Keys } from "@rootzero/contracts/Commands.sol";
83
- import { Cursors, Cur, Schemas } from "@rootzero/contracts/Cursors.sol";
70
+ import { Cursors, Cur, Schemas, Writer, Writers } from "@rootzero/contracts/Cursors.sol";
84
71
 
85
72
  using Cursors for Cur;
73
+ using Writers for Writer;
86
74
 
87
75
  string constant NAME = "myCommand";
88
76
 
@@ -90,16 +78,22 @@ abstract contract ExampleCommand is CommandBase {
90
78
  uint internal immutable myCommandId = commandId(NAME);
91
79
 
92
80
  constructor() {
93
- emit Command(host, myCommandId, NAME, Schemas.Amount, Keys.Empty, Keys.Balance, false);
81
+ emit Command(host, myCommandId, NAME, "1:0:1", Schemas.Amount, Keys.Empty, Keys.Balance, false);
94
82
  }
95
83
 
96
84
  function myCommand(
97
85
  CommandContext calldata c
98
- ) external onlyCommand(c.account) returns (bytes memory) {
99
- (Cur memory input, , ) = cursor(c.request, 1);
100
- (bytes32 asset, bytes32 meta, uint amount) = input.unpackAmount();
101
- input.complete();
102
- return Cursors.toBalanceBlock(asset, meta, amount);
86
+ ) external onlyCommand returns (bytes memory) {
87
+ (Cur memory request, uint groups) = cursor(c.request, 1);
88
+ Writer memory writer = Writers.allocBalances(groups);
89
+
90
+ while (request.i < request.bound) {
91
+ (bytes32 asset, bytes32 meta, uint amount) = request.unpackAmount();
92
+ writer.appendBalance(asset, meta, amount);
93
+ }
94
+
95
+ request.close();
96
+ return writer.finish();
103
97
  }
104
98
  }
105
99
  ```