@rootzero/contracts 0.7.2 → 0.9.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 (71) hide show
  1. package/Commands.sol +15 -20
  2. package/Core.sol +3 -4
  3. package/Cursors.sol +3 -2
  4. package/Events.sol +1 -1
  5. package/Queries.sol +3 -3
  6. package/README.md +18 -19
  7. package/Utils.sol +3 -3
  8. package/blocks/Cursors.sol +937 -551
  9. package/blocks/Keys.sol +60 -34
  10. package/blocks/Schema.sol +112 -122
  11. package/blocks/Writers.sol +476 -301
  12. package/commands/Base.sol +32 -22
  13. package/commands/Burn.sol +14 -12
  14. package/commands/Credit.sol +16 -15
  15. package/commands/Debit.sol +14 -12
  16. package/commands/Deposit.sol +30 -37
  17. package/commands/Pipe.sol +14 -20
  18. package/commands/Provision.sol +19 -49
  19. package/commands/Transfer.sol +9 -18
  20. package/commands/Withdraw.sol +15 -14
  21. package/commands/admin/AllowAssets.sol +3 -3
  22. package/commands/admin/Allowance.sol +43 -0
  23. package/commands/admin/Authorize.sol +4 -4
  24. package/commands/admin/DenyAssets.sol +3 -3
  25. package/commands/admin/Destroy.sol +10 -8
  26. package/commands/admin/Execute.sol +38 -0
  27. package/commands/admin/Init.sol +10 -8
  28. package/commands/admin/Relocate.sol +5 -5
  29. package/commands/admin/Unauthorize.sol +4 -4
  30. package/core/Access.sol +38 -34
  31. package/core/Balances.sol +17 -18
  32. package/core/{Operation.sol → Calls.sol} +5 -8
  33. package/core/{CursorBase.sol → Context.sol} +11 -5
  34. package/core/Host.sol +11 -10
  35. package/core/Types.sol +86 -0
  36. package/docs/GETTING_STARTED.md +37 -29
  37. package/events/Asset.sol +1 -1
  38. package/events/Command.sol +10 -10
  39. package/events/Deposit.sol +3 -4
  40. package/events/Listing.sol +1 -1
  41. package/events/Peer.sol +3 -3
  42. package/events/Position.sol +21 -0
  43. package/events/Query.sol +3 -3
  44. package/events/Withdraw.sol +2 -3
  45. package/package.json +1 -1
  46. package/peer/AllowAssets.sol +1 -1
  47. package/peer/Allowance.sol +36 -0
  48. package/peer/AssetPull.sol +33 -31
  49. package/peer/Base.sol +8 -4
  50. package/peer/DenyAssets.sol +1 -1
  51. package/peer/Settle.sol +3 -4
  52. package/queries/Assets.sol +18 -16
  53. package/queries/Balances.sol +21 -19
  54. package/queries/Base.sol +2 -3
  55. package/queries/Positions.sol +32 -24
  56. package/utils/Accounts.sol +14 -13
  57. package/utils/Assets.sol +137 -62
  58. package/utils/Ids.sol +9 -9
  59. package/utils/Layout.sol +5 -3
  60. package/utils/Utils.sol +10 -0
  61. package/commands/Create.sol +0 -42
  62. package/commands/Remove.sol +0 -42
  63. package/commands/Settle.sol +0 -38
  64. package/commands/Stake.sol +0 -47
  65. package/commands/Supply.sol +0 -41
  66. package/commands/admin/Allocate.sol +0 -41
  67. package/core/HostBound.sol +0 -14
  68. package/events/Erc721.sol +0 -20
  69. package/peer/Pull.sol +0 -39
  70. package/peer/Push.sol +0 -45
  71. package/utils/State.sol +0 -22
package/Commands.sol CHANGED
@@ -5,34 +5,29 @@ pragma solidity ^0.8.33;
5
5
  // Import this file to inherit from the full rootzero command surface without managing individual paths.
6
6
 
7
7
  import { CommandBase, CommandContext, CommandPayable, encodeCommandCall } from "./commands/Base.sol";
8
- import { State } from "./utils/State.sol";
9
- import { Burn } from "./commands/Burn.sol";
10
- import { Create } from "./commands/Create.sol";
11
- import { CreditAccount } from "./commands/Credit.sol";
12
- import { DebitAccount } from "./commands/Debit.sol";
13
- import { Deposit, DepositPayable } from "./commands/Deposit.sol";
14
- import { Remove } from "./commands/Remove.sol";
15
- import { PipePayable } from "./commands/Pipe.sol";
16
- import { Provision, ProvisionPayable, ProvisionFromBalance } from "./commands/Provision.sol";
17
- import { Settle } from "./commands/Settle.sol";
18
- import { StakeCustodyToPosition } from "./commands/Stake.sol";
19
- import { Supply } from "./commands/Supply.sol";
20
- import { Transfer } from "./commands/Transfer.sol";
21
- import { Withdraw } from "./commands/Withdraw.sol";
8
+ import { Keys } from "./blocks/Keys.sol";
9
+ import { Burn, BurnHook } from "./commands/Burn.sol";
10
+ import { CreditAccount, CreditAccountHook } from "./commands/Credit.sol";
11
+ import { DebitAccount, DebitAccountHook } from "./commands/Debit.sol";
12
+ import { Deposit, DepositHook, DepositPayable, DepositPayableHook } from "./commands/Deposit.sol";
13
+ import { PipePayable, PipePayableHook } from "./commands/Pipe.sol";
14
+ import { Provision, ProvisionHook, ProvisionPayable, ProvisionPayableHook } from "./commands/Provision.sol";
15
+ import { Transfer, TransferHook } from "./commands/Transfer.sol";
16
+ import { Withdraw, WithdrawHook } from "./commands/Withdraw.sol";
22
17
  import { AllowAssets, AllowAssetsHook } from "./commands/admin/AllowAssets.sol";
23
- import { Destroy } from "./commands/admin/Destroy.sol";
18
+ import { Destroy, DestroyHook } from "./commands/admin/Destroy.sol";
19
+ import { ExecutePayable } from "./commands/admin/Execute.sol";
24
20
  import { Authorize } from "./commands/admin/Authorize.sol";
25
21
  import { DenyAssets, DenyAssetsHook } from "./commands/admin/DenyAssets.sol";
26
- import { Init } from "./commands/admin/Init.sol";
22
+ import { Init, InitHook } from "./commands/admin/Init.sol";
27
23
  import { RelocatePayable } from "./commands/admin/Relocate.sol";
28
- import { Allocate } from "./commands/admin/Allocate.sol";
24
+ import { Allowance, AllowanceHook } from "./commands/admin/Allowance.sol";
29
25
  import { Unauthorize } from "./commands/admin/Unauthorize.sol";
30
26
  import { PeerBase, encodePeerCall } from "./peer/Base.sol";
31
- import { PeerAssetPull } from "./peer/AssetPull.sol";
27
+ import { PeerAllowance } from "./peer/Allowance.sol";
28
+ import { PeerAssetPull, PeerAssetPullHook } from "./peer/AssetPull.sol";
32
29
  import { PeerAllowAssets } from "./peer/AllowAssets.sol";
33
30
  import { PeerDenyAssets } from "./peer/DenyAssets.sol";
34
- import { PeerPull } from "./peer/Pull.sol";
35
- import { PeerPush } from "./peer/Push.sol";
36
31
  import { PeerSettle } from "./peer/Settle.sol";
37
32
 
38
33
 
package/Core.sol CHANGED
@@ -1,15 +1,14 @@
1
1
  // SPDX-License-Identifier: GPL-3.0-only
2
2
  pragma solidity ^0.8.33;
3
3
 
4
- // Aggregator: re-exports the core host, access, cursor, and validation layer.
4
+ // Aggregator: re-exports the core host, context, access, node-call, and validation layer.
5
5
  // Import this file to bring the full rootzero host base layer into scope.
6
6
 
7
7
  import { AccessControl } from "./core/Access.sol";
8
8
  import { Balances } from "./core/Balances.sol";
9
- import { CursorBase } from "./core/CursorBase.sol";
9
+ import { RootZeroContext } from "./core/Context.sol";
10
10
  import { Host } from "./core/Host.sol";
11
- import { HostBound } from "./core/HostBound.sol";
12
- import { FailedCall, OperationBase } from "./core/Operation.sol";
11
+ import { FailedCall, NodeCalls } from "./core/Calls.sol";
13
12
  import { Validator } from "./core/Validator.sol";
14
13
  import { HostDiscovery } from "./core/Host.sol";
15
14
  import { IHostDiscovery } from "./interfaces/IHostDiscovery.sol";
package/Cursors.sol CHANGED
@@ -4,11 +4,12 @@ pragma solidity ^0.8.33;
4
4
  // Aggregator: re-exports all block stream primitives (Cursors, Writers, Schema, Keys, Sizes).
5
5
  // Import this file to get access to the full block encoding/decoding surface in one import.
6
6
 
7
- import { HostAmount, UserAmount, HostAsset, Tx, AssetAmount, Sizes } from "./blocks/Schema.sol";
7
+ import { AssetAmount, AccountAsset, AccountAmount, HostAmount, HostAccountAsset, HostAccountAmount, Tx } from "./core/Types.sol";
8
+ import { Forms, Sizes } from "./blocks/Schema.sol";
8
9
  import { Keys } from "./blocks/Keys.sol";
9
10
  import { Schemas } from "./blocks/Schema.sol";
10
11
  import { Cursors, Cur } from "./blocks/Cursors.sol";
11
- import { Writer, Writers } from "./blocks/Writers.sol";
12
+ import { ALLOC_SCALE, Writer, Writers } from "./blocks/Writers.sol";
12
13
 
13
14
 
14
15
 
package/Events.sol CHANGED
@@ -11,7 +11,7 @@ import { CollateralEvent } from "./events/Collateral.sol";
11
11
  import { CommandEvent } from "./events/Command.sol";
12
12
  import { DebtEvent } from "./events/Debt.sol";
13
13
  import { DepositEvent } from "./events/Deposit.sol";
14
- import { Erc721PositionEvent } from "./events/Erc721.sol";
14
+ import { AssetPositionEvent } from "./events/Position.sol";
15
15
  import { EventEmitter } from "./events/Emitter.sol";
16
16
  import { GovernedEvent } from "./events/Governed.sol";
17
17
  import { HostAnnouncedEvent } from "./events/Host.sol";
package/Queries.sol CHANGED
@@ -4,7 +4,7 @@ pragma solidity ^0.8.33;
4
4
  // Aggregator: re-exports query abstractions and reusable query bases.
5
5
  // Import this file to build rootzero query contracts without managing individual paths.
6
6
 
7
- import { IsAllowedAsset } from "./queries/Assets.sol";
8
- import { AssetPosition } from "./queries/Positions.sol";
9
- import { GetBalances } from "./queries/Balances.sol";
7
+ import { IsAllowedAsset, IsAllowedAssetHook } from "./queries/Assets.sol";
8
+ import { GetPosition, GetPositionHook } from "./queries/Positions.sol";
9
+ import { GetBalances, GetBalancesHook } from "./queries/Balances.sol";
10
10
  import { QueryBase, encodeQueryCall } from "./queries/Base.sol";
package/README.md CHANGED
@@ -10,8 +10,9 @@ Most consumers should start from the package root entry points:
10
10
 
11
11
  - `@rootzero/contracts/Core.sol` — host, access control, balances, and validator building blocks
12
12
  - `@rootzero/contracts/Commands.sol` — command and peer base contracts plus all standard command mixins
13
- - `@rootzero/contracts/Cursors.sol` — cursor reader (`Cur`), block schemas, key constants, memory refs, and writers
14
- - `@rootzero/contracts/Utils.sol` — IDs, assets, accounts, state discriminants, layout, and value helpers
13
+ - `@rootzero/contracts/Queries.sol` — query base contracts plus standard query mixins
14
+ - `@rootzero/contracts/Cursors.sol` — cursor reader (`Cur`), block schemas, key constants, typed block helpers, and writers
15
+ - `@rootzero/contracts/Utils.sol` — IDs, assets, accounts, layout, and value helpers
15
16
  - `@rootzero/contracts/Events.sol` — reusable event emitters and event contracts
16
17
 
17
18
  ## Start Here
@@ -35,20 +36,19 @@ All request and response data is encoded as a binary block stream. Each block is
35
36
  [bytes4 key][bytes4 payloadLen][payload]
36
37
  ```
37
38
 
38
- `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; `Mem` parses in-memory streams for composed responses.
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.
39
40
 
40
- ## State Discriminants
41
+ ## Schemas, Forms, And State
41
42
 
42
- Every command declares its input and output state shape using constants from the `State` library:
43
+ Protocol blocks use schema strings and four-byte keys:
43
44
 
44
- | Constant | Meaning |
45
- |----------------------|-----------------------------------|
46
- | `State.Empty` | No state (empty stream) |
47
- | `State.Steps` | STEP blocks (sub-command pipeline)|
48
- | `State.Balances` | BALANCE blocks |
49
- | `State.Transactions` | TRANSACTION blocks |
50
- | `State.Custodies` | CUSTODY blocks |
51
- | `State.Claims` | Claim records |
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.
48
+
49
+ 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
+
51
+ The active command pipeline state is intentionally narrow: `BALANCE` and `CUSTODY` blocks are live value owned by the active account while execution is in-flight. `TRANSACTION` remains a block type for settlement messages, but it is not command pipeline state.
52
52
 
53
53
  ## Typical Usage
54
54
 
@@ -79,9 +79,8 @@ Extend `CommandBase` to define a command mixin that runs inside the protocol's t
79
79
  // SPDX-License-Identifier: GPL-3.0-only
80
80
  pragma solidity ^0.8.33;
81
81
 
82
- import { CommandBase, CommandContext } from "@rootzero/contracts/Commands.sol";
82
+ import { CommandBase, CommandContext, Keys } from "@rootzero/contracts/Commands.sol";
83
83
  import { Cursors, Cur, Schemas } from "@rootzero/contracts/Cursors.sol";
84
- import { State } from "@rootzero/contracts/Utils.sol";
85
84
 
86
85
  using Cursors for Cur;
87
86
 
@@ -91,12 +90,12 @@ abstract contract ExampleCommand is CommandBase {
91
90
  uint internal immutable myCommandId = commandId(NAME);
92
91
 
93
92
  constructor() {
94
- emit Command(host, NAME, Schemas.Amount, myCommandId, State.Empty, State.Balances);
93
+ emit Command(host, myCommandId, NAME, Schemas.Amount, Keys.Empty, Keys.Balance, false);
95
94
  }
96
95
 
97
96
  function myCommand(
98
97
  CommandContext calldata c
99
- ) external payable onlyCommand(myCommandId, c.target) returns (bytes memory) {
98
+ ) external onlyCommand(c.account) returns (bytes memory) {
100
99
  (Cur memory input, , ) = cursor(c.request, 1);
101
100
  (bytes32 asset, bytes32 meta, uint amount) = input.unpackAmount();
102
101
  input.complete();
@@ -110,8 +109,8 @@ abstract contract ExampleCommand is CommandBase {
110
109
  - `contracts/core` — host, access control, balances, operation base, and signature validation
111
110
  - `contracts/commands` — standard command building blocks and admin commands
112
111
  - `contracts/peer` — peer protocol surfaces for inter-host asset flows and asset allow/deny
113
- - `contracts/blocks` — block stream schema (`Schema`), cursor parsing (`Cursors`), memory refs (`Mem`), and writers (`Writers`)
114
- - `contracts/utils` — shared encoding helpers: IDs, assets, accounts, state discriminants, layout, ECDSA
112
+ - `contracts/blocks` — block stream schema (`Schema`), cursor parsing (`Cursors`), and writers (`Writers`)
113
+ - `contracts/utils` — shared encoding helpers: IDs, assets, accounts, layout, ECDSA
115
114
  - `contracts/events` — protocol event contracts and emitters
116
115
  - `contracts/interfaces` — discovery interfaces and shared external protocol surfaces
117
116
  - `docs` — introductory documentation
package/Utils.sol CHANGED
@@ -1,17 +1,17 @@
1
1
  // SPDX-License-Identifier: GPL-3.0-only
2
2
  pragma solidity ^0.8.33;
3
3
 
4
- // Aggregator: re-exports all utility libraries (State, Accounts, Assets, ECDSA, Ids, Layout, Utils, Value).
4
+ // Aggregator: re-exports all utility libraries (Keys, Accounts, Assets, ECDSA, Ids, Layout, Utils, Value).
5
5
  // Import this file to access the full utility surface without managing individual paths.
6
6
 
7
- import { State } from "./utils/State.sol";
7
+ import { Keys } from "./blocks/Keys.sol";
8
8
  import { Accounts } from "./utils/Accounts.sol";
9
9
  import { Amounts, Assets } from "./utils/Assets.sol";
10
10
  import { ECDSA } from "./utils/ECDSA.sol";
11
11
  import { Ids, Selectors } from "./utils/Ids.sol";
12
12
  import { Layout } from "./utils/Layout.sol";
13
13
  import { Schemas } from "./blocks/Schema.sol";
14
- import { addrOr, applyBps, beforeBps, bytes32ToString, divisible, isFamily, isLocal, isLocalFamily, matchesBase, MAX_BPS, max8, max16, max24, max32, max40, max64, max96, max128, max160, NotDivisible, retryTicket, toLocalBase, toLocalFamily, toUnspecifiedBase, ValueOverflow } from "./utils/Utils.sol";
14
+ import { addrOr, applyBps, beforeBps, bytes32ToInt, bytes32ToString, divisible, hash32, intToBytes32, isFamily, isLocal, isLocalFamily, matchesBase, MAX_BPS, max8, max16, max24, max32, max40, max64, max96, max128, max160, NotDivisible, retryTicket, toLocalBase, toLocalFamily, toUnspecifiedBase, ValueOverflow } from "./utils/Utils.sol";
15
15
  import { Budget, Values } from "./utils/Value.sol";
16
16
 
17
17