@rootzero/contracts 0.8.0 → 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.
- package/Commands.sol +5 -10
- package/Core.sol +3 -4
- package/Cursors.sol +4 -6
- package/Events.sol +1 -1
- package/Queries.sol +1 -1
- package/README.md +18 -19
- package/Utils.sol +3 -3
- package/blocks/Cursors.sol +1437 -0
- package/blocks/Keys.sol +59 -34
- package/blocks/Schema.sol +109 -126
- package/blocks/Writers.sol +476 -301
- package/commands/Base.sol +32 -22
- package/commands/Burn.sol +3 -3
- package/commands/Credit.sol +6 -7
- package/commands/Debit.sol +3 -3
- package/commands/Deposit.sol +7 -7
- package/commands/Pipe.sol +3 -3
- package/commands/Provision.sol +19 -49
- package/commands/Transfer.sol +9 -19
- package/commands/Withdraw.sol +5 -6
- package/commands/admin/AllowAssets.sol +3 -3
- package/commands/admin/Allowance.sol +43 -0
- package/commands/admin/Authorize.sol +4 -4
- package/commands/admin/DenyAssets.sol +3 -3
- package/commands/admin/Destroy.sol +3 -3
- package/commands/admin/Execute.sol +38 -0
- package/commands/admin/Init.sol +3 -3
- package/commands/admin/Relocate.sol +5 -5
- package/commands/admin/Unauthorize.sol +4 -4
- package/core/Access.sol +38 -34
- package/core/Balances.sol +17 -18
- package/core/{Operation.sol → Calls.sol} +5 -8
- package/core/{CursorBase.sol → Context.sol} +11 -5
- package/core/Host.sol +10 -9
- package/core/Types.sol +86 -0
- package/docs/GETTING_STARTED.md +37 -29
- package/events/Asset.sol +1 -1
- package/events/Command.sol +10 -10
- package/events/Deposit.sol +3 -4
- package/events/Listing.sol +1 -1
- package/events/Peer.sol +3 -3
- package/events/Position.sol +21 -0
- package/events/Query.sol +3 -3
- package/events/Withdraw.sol +2 -3
- package/package.json +1 -1
- package/peer/AllowAssets.sol +1 -1
- package/peer/Allowance.sol +36 -0
- package/peer/AssetPull.sol +1 -1
- package/peer/Base.sol +8 -4
- package/peer/DenyAssets.sol +1 -1
- package/peer/Settle.sol +3 -4
- package/queries/Assets.sol +8 -8
- package/queries/Balances.sol +11 -11
- package/queries/Base.sol +2 -3
- package/queries/Positions.sol +25 -19
- package/utils/Accounts.sol +14 -13
- package/utils/Assets.sol +77 -57
- package/utils/Ids.sol +4 -4
- package/utils/Layout.sol +1 -1
- package/utils/Utils.sol +10 -0
- package/blocks/cursors/Core.sol +0 -1121
- package/blocks/cursors/Erc1155.sol +0 -149
- package/blocks/cursors/Erc20.sol +0 -130
- package/blocks/cursors/Erc721.sol +0 -66
- package/commands/Create.sol +0 -44
- package/commands/Remove.sol +0 -44
- package/commands/Settle.sol +0 -38
- package/commands/Stake.sol +0 -49
- package/commands/Supply.sol +0 -43
- package/commands/admin/Allocate.sol +0 -43
- package/core/HostBound.sol +0 -14
- package/events/Erc721.sol +0 -20
- package/peer/Pull.sol +0 -41
- package/peer/Push.sol +0 -47
- 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 {
|
|
8
|
+
import { Keys } from "./blocks/Keys.sol";
|
|
9
9
|
import { Burn, BurnHook } from "./commands/Burn.sol";
|
|
10
|
-
import { Create, CreateHook } from "./commands/Create.sol";
|
|
11
10
|
import { CreditAccount, CreditAccountHook } from "./commands/Credit.sol";
|
|
12
11
|
import { DebitAccount, DebitAccountHook } from "./commands/Debit.sol";
|
|
13
12
|
import { Deposit, DepositHook, DepositPayable, DepositPayableHook } from "./commands/Deposit.sol";
|
|
14
|
-
import { Remove, RemoveHook } from "./commands/Remove.sol";
|
|
15
13
|
import { PipePayable, PipePayableHook } from "./commands/Pipe.sol";
|
|
16
|
-
import { Provision, ProvisionHook, ProvisionPayable, ProvisionPayableHook
|
|
17
|
-
import { Settle } from "./commands/Settle.sol";
|
|
18
|
-
import { StakeCustodyToPosition, StakeCustodyToPositionHook } from "./commands/Stake.sol";
|
|
19
|
-
import { Supply, SupplyHook } from "./commands/Supply.sol";
|
|
14
|
+
import { Provision, ProvisionHook, ProvisionPayable, ProvisionPayableHook } from "./commands/Provision.sol";
|
|
20
15
|
import { Transfer, TransferHook } from "./commands/Transfer.sol";
|
|
21
16
|
import { Withdraw, WithdrawHook } from "./commands/Withdraw.sol";
|
|
22
17
|
import { AllowAssets, AllowAssetsHook } from "./commands/admin/AllowAssets.sol";
|
|
23
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
22
|
import { Init, InitHook } from "./commands/admin/Init.sol";
|
|
27
23
|
import { RelocatePayable } from "./commands/admin/Relocate.sol";
|
|
28
|
-
import {
|
|
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";
|
|
27
|
+
import { PeerAllowance } from "./peer/Allowance.sol";
|
|
31
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, PeerPullHook } from "./peer/Pull.sol";
|
|
35
|
-
import { PeerPush, PeerPushHook } 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,
|
|
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 {
|
|
9
|
+
import { RootZeroContext } from "./core/Context.sol";
|
|
10
10
|
import { Host } from "./core/Host.sol";
|
|
11
|
-
import {
|
|
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,14 +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 {
|
|
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
|
-
import { Cursors, Cur } from "./blocks/
|
|
11
|
-
import {
|
|
12
|
-
import { Erc1155Cursors } from "./blocks/cursors/Erc1155.sol";
|
|
13
|
-
import { Erc721Cursors } from "./blocks/cursors/Erc721.sol";
|
|
14
|
-
import { Writer, Writers } from "./blocks/Writers.sol";
|
|
11
|
+
import { Cursors, Cur } from "./blocks/Cursors.sol";
|
|
12
|
+
import { ALLOC_SCALE, Writer, Writers } from "./blocks/Writers.sol";
|
|
15
13
|
|
|
16
14
|
|
|
17
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 {
|
|
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
|
@@ -5,6 +5,6 @@ pragma solidity ^0.8.33;
|
|
|
5
5
|
// Import this file to build rootzero query contracts without managing individual paths.
|
|
6
6
|
|
|
7
7
|
import { IsAllowedAsset, IsAllowedAssetHook } from "./queries/Assets.sol";
|
|
8
|
-
import {
|
|
8
|
+
import { GetPosition, GetPositionHook } from "./queries/Positions.sol";
|
|
9
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/
|
|
14
|
-
- `@rootzero/contracts/
|
|
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
|
|
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
|
|
41
|
+
## Schemas, Forms, And State
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
Protocol blocks use schema strings and four-byte keys:
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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,
|
|
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
|
|
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`),
|
|
114
|
-
- `contracts/utils` — shared encoding helpers: IDs, assets, accounts,
|
|
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 (
|
|
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 {
|
|
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
|
|