@rootzero/contracts 0.9.2 → 0.9.4
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 +4 -3
- package/Core.sol +3 -0
- package/Cursors.sol +1 -1
- package/README.md +18 -24
- package/blocks/Cursors.sol +332 -335
- package/blocks/Keys.sol +38 -57
- package/blocks/Schema.sol +55 -114
- package/blocks/Writers.sol +361 -255
- package/commands/Base.sol +6 -48
- package/commands/Burn.sol +4 -4
- package/commands/Credit.sol +5 -4
- package/commands/Debit.sol +6 -5
- package/commands/Deposit.sol +17 -14
- package/commands/Provision.sol +17 -14
- package/commands/Transfer.sol +4 -4
- package/commands/Withdraw.sol +5 -4
- package/commands/admin/AllowAssets.sol +3 -3
- package/commands/admin/Allowance.sol +3 -3
- package/commands/admin/Authorize.sol +3 -3
- package/commands/admin/DenyAssets.sol +3 -3
- package/commands/admin/Destroy.sol +1 -1
- package/commands/admin/Execute.sol +9 -8
- package/commands/admin/Init.sol +1 -1
- package/commands/admin/Unauthorize.sol +3 -3
- package/core/Access.sol +11 -0
- package/core/Context.sol +11 -13
- package/core/Payable.sol +57 -0
- package/core/Pipeline.sol +55 -0
- package/docs/Schema.md +194 -0
- package/events/Admin.sol +5 -1
- package/events/Command.sol +6 -2
- package/events/Listing.sol +3 -4
- package/events/Peer.sol +5 -3
- package/events/Query.sol +5 -2
- package/package.json +2 -2
- package/peer/AllowAssets.sol +3 -3
- package/peer/Allowance.sol +3 -3
- package/peer/BalancePull.sol +43 -0
- package/peer/DenyAssets.sol +3 -3
- package/peer/Pipe.sol +38 -0
- package/peer/Settle.sol +3 -3
- package/queries/Assets.sol +7 -6
- package/queries/Balances.sol +5 -4
- package/queries/Positions.sol +14 -14
- package/utils/Value.sol +8 -14
- package/commands/Pipe.sol +0 -67
- package/docs/GETTING_STARTED.md +0 -294
- package/peer/AssetPull.sol +0 -43
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
|
|
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";
|
|
@@ -24,9 +24,10 @@ import { Allowance, AllowanceHook } from "./commands/admin/Allowance.sol";
|
|
|
24
24
|
import { Unauthorize } from "./commands/admin/Unauthorize.sol";
|
|
25
25
|
import { PeerBase, encodePeerCall } from "./peer/Base.sol";
|
|
26
26
|
import { PeerAllowance } from "./peer/Allowance.sol";
|
|
27
|
-
import {
|
|
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
|
@@ -9,6 +9,9 @@ import { Balances } from "./core/Balances.sol";
|
|
|
9
9
|
import { RootZeroContext } from "./core/Context.sol";
|
|
10
10
|
import { Host } 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
16
|
import { HostDiscovery } from "./core/Host.sol";
|
|
14
17
|
import { IHostDiscovery } from "./interfaces/IHostDiscovery.sol";
|
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 {
|
|
12
|
+
import { Writer, Writers, Hints } from "./blocks/Writers.sol";
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
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(
|
|
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
|
|
46
|
-
- `Forms` describes reusable structural blocks such as
|
|
47
|
-
- `Keys` contains the runtime `bytes4` keys derived from
|
|
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
|
|
99
|
-
(Cur memory
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
```
|