@rootzero/contracts 0.9.2 → 0.9.3
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 +1 -1
- package/Cursors.sol +1 -1
- package/blocks/Cursors.sol +51 -9
- package/blocks/Keys.sol +1 -1
- package/blocks/Schema.sol +98 -4
- package/blocks/Writers.sol +21 -125
- package/commands/Burn.sol +2 -2
- package/commands/Credit.sol +3 -2
- package/commands/Debit.sol +3 -3
- package/commands/Deposit.sol +6 -6
- package/commands/Pipe.sol +2 -2
- package/commands/Provision.sol +6 -6
- package/commands/Transfer.sol +2 -2
- package/commands/Withdraw.sol +3 -2
- package/commands/admin/AllowAssets.sol +2 -2
- package/commands/admin/Allowance.sol +2 -2
- package/commands/admin/Authorize.sol +2 -2
- package/commands/admin/DenyAssets.sol +2 -2
- package/commands/admin/Destroy.sol +1 -1
- package/commands/admin/Execute.sol +2 -2
- package/commands/admin/Init.sol +1 -1
- package/commands/admin/Unauthorize.sol +2 -2
- package/core/Context.sol +10 -11
- package/events/Admin.sol +5 -1
- package/events/Command.sol +7 -2
- package/events/Listing.sol +3 -4
- package/events/Peer.sol +5 -3
- package/events/Query.sol +5 -2
- package/package.json +1 -1
- package/peer/AllowAssets.sol +2 -2
- package/peer/Allowance.sol +2 -2
- package/peer/BalancePull.sol +43 -0
- package/peer/DenyAssets.sol +2 -2
- package/peer/Settle.sol +2 -2
- package/queries/Assets.sol +3 -3
- package/queries/Balances.sol +3 -3
- package/queries/Positions.sol +3 -3
- package/peer/AssetPull.sol +0 -43
package/commands/Deposit.sol
CHANGED
|
@@ -41,14 +41,14 @@ abstract contract Deposit is CommandBase, DepositHook {
|
|
|
41
41
|
uint internal immutable depositId = commandId(NAME);
|
|
42
42
|
|
|
43
43
|
constructor() {
|
|
44
|
-
emit Command(host, depositId, NAME, Schemas.Amount, Keys.Empty, Keys.Balance, false);
|
|
44
|
+
emit Command(host, depositId, NAME, "1:0:1", Schemas.Amount, Keys.Empty, Keys.Balance, false);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
function deposit(
|
|
48
48
|
CommandContext calldata c
|
|
49
49
|
) external onlyCommand(c.account) returns (bytes memory) {
|
|
50
|
-
(Cur memory request, uint
|
|
51
|
-
Writer memory writer = Writers.allocBalances(
|
|
50
|
+
(Cur memory request, uint groups) = cursor(c.request, 1);
|
|
51
|
+
Writer memory writer = Writers.allocBalances(groups);
|
|
52
52
|
|
|
53
53
|
while (request.i < request.bound) {
|
|
54
54
|
(bytes32 asset, bytes32 meta, uint amount) = request.unpackAmount();
|
|
@@ -69,14 +69,14 @@ abstract contract DepositPayable is CommandPayable, DepositPayableHook {
|
|
|
69
69
|
uint internal immutable depositPayableId = commandId(NAME);
|
|
70
70
|
|
|
71
71
|
constructor() {
|
|
72
|
-
emit Command(host, depositPayableId, NAME, Schemas.Amount, Keys.Empty, Keys.Balance, true);
|
|
72
|
+
emit Command(host, depositPayableId, NAME, "1:0:1", Schemas.Amount, Keys.Empty, Keys.Balance, true);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
function depositPayable(
|
|
76
76
|
CommandContext calldata c
|
|
77
77
|
) external payable onlyCommand(c.account) returns (bytes memory) {
|
|
78
|
-
(Cur memory request, uint
|
|
79
|
-
Writer memory writer = Writers.allocBalances(
|
|
78
|
+
(Cur memory request, uint groups) = cursor(c.request, 1);
|
|
79
|
+
Writer memory writer = Writers.allocBalances(groups);
|
|
80
80
|
Budget memory budget = Values.fromMsg();
|
|
81
81
|
|
|
82
82
|
while (request.i < request.bound) {
|
package/commands/Pipe.sol
CHANGED
|
@@ -38,7 +38,7 @@ abstract contract PipePayable is CommandPayable, PipePayableHook {
|
|
|
38
38
|
uint internal immutable pipePayableId = commandId(NAME);
|
|
39
39
|
|
|
40
40
|
constructor() {
|
|
41
|
-
emit Command(host, pipePayableId, NAME, Schemas.Step, Keys.Empty, Keys.Empty, true);
|
|
41
|
+
emit Command(host, pipePayableId, NAME, "1:0:0", Schemas.Step, Keys.Empty, Keys.Empty, true);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
function pipe(
|
|
@@ -47,7 +47,7 @@ abstract contract PipePayable is CommandPayable, PipePayableHook {
|
|
|
47
47
|
bytes calldata steps,
|
|
48
48
|
Budget memory budget
|
|
49
49
|
) internal returns (bytes memory) {
|
|
50
|
-
(Cur memory input,
|
|
50
|
+
(Cur memory input, ) = cursor(steps, 1);
|
|
51
51
|
|
|
52
52
|
while (input.i < input.bound) {
|
|
53
53
|
(uint target, uint value, bytes calldata request) = input.unpackStep();
|
package/commands/Provision.sol
CHANGED
|
@@ -37,12 +37,12 @@ abstract contract Provision is CommandBase, ProvisionHook {
|
|
|
37
37
|
uint internal immutable provisionId = commandId(NAME);
|
|
38
38
|
|
|
39
39
|
constructor() {
|
|
40
|
-
emit Command(host, provisionId, NAME, Schemas.Allocation, Keys.Empty, Keys.Custody, false);
|
|
40
|
+
emit Command(host, provisionId, NAME, "1:0:1", Schemas.Allocation, Keys.Empty, Keys.Custody, false);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
function provision(CommandContext calldata c) external onlyCommand(c.account) returns (bytes memory) {
|
|
44
|
-
(Cur memory request, uint
|
|
45
|
-
Writer memory writer = Writers.allocCustodies(
|
|
44
|
+
(Cur memory request, uint groups) = cursor(c.request, 1);
|
|
45
|
+
Writer memory writer = Writers.allocCustodies(groups);
|
|
46
46
|
|
|
47
47
|
while (request.i < request.bound) {
|
|
48
48
|
HostAmount memory allocation = request.unpackAllocationValue();
|
|
@@ -64,14 +64,14 @@ abstract contract ProvisionPayable is CommandPayable, ProvisionPayableHook {
|
|
|
64
64
|
uint internal immutable provisionPayableId = commandId(NAME);
|
|
65
65
|
|
|
66
66
|
constructor() {
|
|
67
|
-
emit Command(host, provisionPayableId, NAME, Schemas.Allocation, Keys.Empty, Keys.Custody, true);
|
|
67
|
+
emit Command(host, provisionPayableId, NAME, "1:0:1", Schemas.Allocation, Keys.Empty, Keys.Custody, true);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
function provisionPayable(
|
|
71
71
|
CommandContext calldata c
|
|
72
72
|
) external payable onlyCommand(c.account) returns (bytes memory) {
|
|
73
|
-
(Cur memory request, uint
|
|
74
|
-
Writer memory writer = Writers.allocCustodies(
|
|
73
|
+
(Cur memory request, uint groups) = cursor(c.request, 1);
|
|
74
|
+
Writer memory writer = Writers.allocCustodies(groups);
|
|
75
75
|
Budget memory budget = Values.fromMsg();
|
|
76
76
|
|
|
77
77
|
while (request.i < request.bound) {
|
package/commands/Transfer.sol
CHANGED
|
@@ -23,7 +23,7 @@ abstract contract Transfer is CommandBase, TransferHook {
|
|
|
23
23
|
uint internal immutable transferId = commandId(NAME);
|
|
24
24
|
|
|
25
25
|
constructor() {
|
|
26
|
-
emit Command(host, transferId, NAME, Schemas.Payout, Keys.Empty, Keys.Empty, false);
|
|
26
|
+
emit Command(host, transferId, NAME, "1:0:0", Schemas.Payout, Keys.Empty, Keys.Empty, false);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/// @notice Override to customize request parsing or batching for transfers.
|
|
@@ -32,7 +32,7 @@ abstract contract Transfer is CommandBase, TransferHook {
|
|
|
32
32
|
/// @param request Full request bytes.
|
|
33
33
|
/// @return Empty bytes (transfers produce no state output).
|
|
34
34
|
function transfer(bytes32 from, bytes calldata request) internal virtual returns (bytes memory) {
|
|
35
|
-
(Cur memory input,
|
|
35
|
+
(Cur memory input, ) = cursor(request, 1);
|
|
36
36
|
Tx memory value;
|
|
37
37
|
value.from = from;
|
|
38
38
|
|
package/commands/Withdraw.sol
CHANGED
|
@@ -21,17 +21,18 @@ abstract contract WithdrawHook {
|
|
|
21
21
|
/// For internal balance credits, use `creditAccount` instead.
|
|
22
22
|
abstract contract Withdraw is CommandBase, WithdrawHook {
|
|
23
23
|
string private constant NAME = "withdraw";
|
|
24
|
+
string private constant REQUEST = string.concat(Schemas.Empty, ";", Schemas.Account, "?");
|
|
24
25
|
|
|
25
26
|
uint internal immutable withdrawId = commandId(NAME);
|
|
26
27
|
|
|
27
28
|
constructor() {
|
|
28
|
-
emit Command(host, withdrawId, NAME,
|
|
29
|
+
emit Command(host, withdrawId, NAME, "0:1:0", REQUEST, Keys.Balance, Keys.Empty, false);
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
function withdraw(
|
|
32
33
|
CommandContext calldata c
|
|
33
34
|
) external onlyCommand(c.account) returns (bytes memory) {
|
|
34
|
-
(Cur memory state,
|
|
35
|
+
(Cur memory state, ) = cursor(c.state, 1);
|
|
35
36
|
bytes32 to = Cursors.resolveAccount(c.request, c.account);
|
|
36
37
|
|
|
37
38
|
while (state.i < state.bound) {
|
|
@@ -21,13 +21,13 @@ abstract contract AllowAssets is CommandBase, AdminEvent, AllowAssetsHook {
|
|
|
21
21
|
uint internal immutable allowAssetsId = commandId(NAME);
|
|
22
22
|
|
|
23
23
|
constructor() {
|
|
24
|
-
emit Admin(host, allowAssetsId, NAME, Schemas.Asset, Keys.Empty, Keys.Empty, false);
|
|
24
|
+
emit Admin(host, allowAssetsId, NAME, "1:0:0", Schemas.Asset, Keys.Empty, Keys.Empty, false);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
function allowAssets(
|
|
28
28
|
CommandContext calldata c
|
|
29
29
|
) external onlyAdmin(c.account) returns (bytes memory) {
|
|
30
|
-
(Cur memory request,
|
|
30
|
+
(Cur memory request, ) = cursor(c.request, 1);
|
|
31
31
|
|
|
32
32
|
while (request.i < request.bound) {
|
|
33
33
|
(bytes32 asset, bytes32 meta) = request.unpackAsset();
|
|
@@ -26,11 +26,11 @@ abstract contract Allowance is CommandBase, AdminEvent, AllowanceHook {
|
|
|
26
26
|
uint internal immutable allowanceId = commandId(NAME);
|
|
27
27
|
|
|
28
28
|
constructor() {
|
|
29
|
-
emit Admin(host, allowanceId, NAME, Schemas.Allowance, Keys.Empty, Keys.Empty, false);
|
|
29
|
+
emit Admin(host, allowanceId, NAME, "1:0:0", Schemas.Allowance, Keys.Empty, Keys.Empty, false);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
function allowance(CommandContext calldata c) external onlyAdmin(c.account) returns (bytes memory) {
|
|
33
|
-
(Cur memory request,
|
|
33
|
+
(Cur memory request, ) = cursor(c.request, 1);
|
|
34
34
|
|
|
35
35
|
while (request.i < request.bound) {
|
|
36
36
|
(uint peer, bytes32 asset, bytes32 meta, uint amount) = request.unpackAllowance();
|
|
@@ -16,13 +16,13 @@ abstract contract Authorize is CommandBase, AdminEvent {
|
|
|
16
16
|
uint internal immutable authorizeId = commandId(NAME);
|
|
17
17
|
|
|
18
18
|
constructor() {
|
|
19
|
-
emit Admin(host, authorizeId, NAME, Schemas.Node, Keys.Empty, Keys.Empty, false);
|
|
19
|
+
emit Admin(host, authorizeId, NAME, "1:0:0", Schemas.Node, Keys.Empty, Keys.Empty, false);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function authorize(
|
|
23
23
|
CommandContext calldata c
|
|
24
24
|
) external onlyAdmin(c.account) returns (bytes memory) {
|
|
25
|
-
(Cur memory request,
|
|
25
|
+
(Cur memory request, ) = cursor(c.request, 1);
|
|
26
26
|
|
|
27
27
|
while (request.i < request.bound) {
|
|
28
28
|
uint node = request.unpackNode();
|
|
@@ -21,13 +21,13 @@ abstract contract DenyAssets is CommandBase, AdminEvent, DenyAssetsHook {
|
|
|
21
21
|
uint internal immutable denyAssetsId = commandId(NAME);
|
|
22
22
|
|
|
23
23
|
constructor() {
|
|
24
|
-
emit Admin(host, denyAssetsId, NAME, Schemas.Asset, Keys.Empty, Keys.Empty, false);
|
|
24
|
+
emit Admin(host, denyAssetsId, NAME, "1:0:0", Schemas.Asset, Keys.Empty, Keys.Empty, false);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
function denyAssets(
|
|
28
28
|
CommandContext calldata c
|
|
29
29
|
) external onlyAdmin(c.account) returns (bytes memory) {
|
|
30
|
-
(Cur memory request,
|
|
30
|
+
(Cur memory request, ) = cursor(c.request, 1);
|
|
31
31
|
|
|
32
32
|
while (request.i < request.bound) {
|
|
33
33
|
(bytes32 asset, bytes32 meta) = request.unpackAsset();
|
|
@@ -22,7 +22,7 @@ abstract contract Destroy is CommandBase, AdminEvent, DestroyHook {
|
|
|
22
22
|
uint internal immutable destroyId = commandId(NAME);
|
|
23
23
|
|
|
24
24
|
constructor(string memory input) {
|
|
25
|
-
emit Admin(host, destroyId, NAME, input, Keys.Empty, Keys.Empty, false);
|
|
25
|
+
emit Admin(host, destroyId, NAME, "1:0:0", input, Keys.Empty, Keys.Empty, false);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
function destroy(
|
|
@@ -19,11 +19,11 @@ abstract contract ExecutePayable is CommandPayable, AdminEvent {
|
|
|
19
19
|
uint internal immutable executePayableId = commandId(NAME);
|
|
20
20
|
|
|
21
21
|
constructor() {
|
|
22
|
-
emit Admin(host, executePayableId, NAME, Schemas.Call, Keys.Empty, Keys.Empty, true);
|
|
22
|
+
emit Admin(host, executePayableId, NAME, "1:0:0", Schemas.Call, Keys.Empty, Keys.Empty, true);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
function executePayable(CommandContext calldata c) external payable onlyAdmin(c.account) returns (bytes memory) {
|
|
26
|
-
(Cur memory request,
|
|
26
|
+
(Cur memory request, ) = cursor(c.request, 1);
|
|
27
27
|
Budget memory budget = Values.fromMsg();
|
|
28
28
|
|
|
29
29
|
while (request.i < request.bound) {
|
package/commands/admin/Init.sol
CHANGED
|
@@ -22,7 +22,7 @@ abstract contract Init is CommandBase, AdminEvent, InitHook {
|
|
|
22
22
|
uint internal immutable initId = commandId(NAME);
|
|
23
23
|
|
|
24
24
|
constructor(string memory input) {
|
|
25
|
-
emit Admin(host, initId, NAME, input, Keys.Empty, Keys.Empty, false);
|
|
25
|
+
emit Admin(host, initId, NAME, "1:0:0", input, Keys.Empty, Keys.Empty, false);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
function init(
|
|
@@ -16,13 +16,13 @@ abstract contract Unauthorize is CommandBase, AdminEvent {
|
|
|
16
16
|
uint internal immutable unauthorizeId = commandId(NAME);
|
|
17
17
|
|
|
18
18
|
constructor() {
|
|
19
|
-
emit Admin(host, unauthorizeId, NAME, Schemas.Node, Keys.Empty, Keys.Empty, false);
|
|
19
|
+
emit Admin(host, unauthorizeId, NAME, "1:0:0", Schemas.Node, Keys.Empty, Keys.Empty, false);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function unauthorize(
|
|
23
23
|
CommandContext calldata c
|
|
24
24
|
) external onlyAdmin(c.account) returns (bytes memory) {
|
|
25
|
-
(Cur memory request,
|
|
25
|
+
(Cur memory request, ) = cursor(c.request, 1);
|
|
26
26
|
|
|
27
27
|
while (request.i < request.bound) {
|
|
28
28
|
uint node = request.unpackNode();
|
package/core/Context.sol
CHANGED
|
@@ -27,23 +27,22 @@ abstract contract RootZeroContext {
|
|
|
27
27
|
/// @param source Calldata slice to parse.
|
|
28
28
|
/// @param group Expected block group size (e.g. 1 for single, 2 for paired).
|
|
29
29
|
/// @return cur Cursor with `bound` set to the end of the first run.
|
|
30
|
-
/// @return
|
|
31
|
-
|
|
32
|
-
function cursor(bytes calldata source, uint group) internal pure returns (Cur memory cur, uint count, uint quotient) {
|
|
30
|
+
/// @return groups Number of block groups in the run (`prime block count / group`).
|
|
31
|
+
function cursor(bytes calldata source, uint group) internal pure returns (Cur memory cur, uint groups) {
|
|
33
32
|
cur = Cursors.open(source);
|
|
34
|
-
(,
|
|
33
|
+
(, , groups) = cur.primeRun(group);
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
/// @notice Open a cursor, prime it, and assert that its
|
|
38
|
-
/// Equivalent to `open(source)` followed by `primeRun(group)` and a direct
|
|
39
|
-
/// Reverts with `Cursors.BadRatio` when the
|
|
36
|
+
/// @notice Open a cursor, prime it, and assert that its group count matches `expectedGroups`.
|
|
37
|
+
/// Equivalent to `open(source)` followed by `primeRun(group)` and a direct group-count equality check.
|
|
38
|
+
/// Reverts with `Cursors.BadRatio` when the group count does not match.
|
|
40
39
|
/// @param source Calldata slice to parse.
|
|
41
40
|
/// @param group Expected block group size (e.g. 1 for single, 2 for paired).
|
|
42
|
-
/// @param
|
|
41
|
+
/// @param expectedGroups Required number of groups in the first run.
|
|
43
42
|
/// @return cur Cursor with `bound` set to the end of the first run.
|
|
44
|
-
function cursor(bytes calldata source, uint group, uint
|
|
43
|
+
function cursor(bytes calldata source, uint group, uint expectedGroups) internal pure returns (Cur memory cur) {
|
|
45
44
|
cur = Cursors.open(source);
|
|
46
|
-
(, , uint
|
|
47
|
-
if (
|
|
45
|
+
(, , uint groups) = cur.primeRun(group);
|
|
46
|
+
if (groups != expectedGroups) revert Cursors.BadRatio();
|
|
48
47
|
}
|
|
49
48
|
}
|
package/events/Admin.sol
CHANGED
|
@@ -4,13 +4,16 @@ pragma solidity ^0.8.33;
|
|
|
4
4
|
import { EventEmitter } from "./Emitter.sol";
|
|
5
5
|
|
|
6
6
|
string constant ABI =
|
|
7
|
-
"event Admin(uint indexed host, uint id, string name, string request, bytes4 state, bytes4 output, bool acceptsValue)";
|
|
7
|
+
"event Admin(uint indexed host, uint id, string name, bytes32 shape, string request, bytes4 state, bytes4 output, bool acceptsValue)";
|
|
8
8
|
|
|
9
9
|
/// @notice Emitted once per admin command during host deployment to publish its request schema and state keys.
|
|
10
10
|
abstract contract AdminEvent is EventEmitter {
|
|
11
11
|
/// @param host Host node ID that owns this admin command.
|
|
12
12
|
/// @param id Command node ID.
|
|
13
13
|
/// @param name Human-readable command name.
|
|
14
|
+
/// @param shape Per-operation prime block counts encoded as `request:state:output`.
|
|
15
|
+
/// Blocks outside the prime runs are global batch blocks and are excluded
|
|
16
|
+
/// from the counts.
|
|
14
17
|
/// @param request Schema DSL string describing the request shape.
|
|
15
18
|
/// @param state Block key expected for input state, or `Keys.Empty`.
|
|
16
19
|
/// @param output Block key produced for output state, or `Keys.Empty`.
|
|
@@ -19,6 +22,7 @@ abstract contract AdminEvent is EventEmitter {
|
|
|
19
22
|
uint indexed host,
|
|
20
23
|
uint id,
|
|
21
24
|
string name,
|
|
25
|
+
bytes32 shape,
|
|
22
26
|
string request,
|
|
23
27
|
bytes4 state,
|
|
24
28
|
bytes4 output,
|
package/events/Command.sol
CHANGED
|
@@ -4,14 +4,18 @@ pragma solidity ^0.8.33;
|
|
|
4
4
|
import { EventEmitter } from "./Emitter.sol";
|
|
5
5
|
|
|
6
6
|
string constant ABI =
|
|
7
|
-
"event Command(uint indexed host, uint id, string name, string request, bytes4 state, bytes4 output, bool acceptsValue)";
|
|
7
|
+
"event Command(uint indexed host, uint id, string name, bytes32 shape, string request, bytes4 state, bytes4 output, bool acceptsValue)";
|
|
8
8
|
|
|
9
9
|
/// @notice Emitted once per command during host deployment to publish its request schema and state keys.
|
|
10
10
|
abstract contract CommandEvent is EventEmitter {
|
|
11
11
|
/// @param host Host node ID that owns this command.
|
|
12
12
|
/// @param id Command node ID.
|
|
13
13
|
/// @param name Human-readable command name.
|
|
14
|
-
/// @param
|
|
14
|
+
/// @param shape Per-operation prime block counts encoded as `request:state:output`.
|
|
15
|
+
/// Blocks outside the prime runs are global batch blocks and are excluded
|
|
16
|
+
/// from the counts.
|
|
17
|
+
/// @param request Schema DSL string describing the request shape; use `empty;...`
|
|
18
|
+
/// when the request has global blocks but no prime blocks.
|
|
15
19
|
/// @param state Block key expected for input state, or `Keys.Empty`.
|
|
16
20
|
/// @param output Block key produced for output state, or `Keys.Empty`.
|
|
17
21
|
/// @param acceptsValue Whether the command entrypoint accepts nonzero `msg.value`.
|
|
@@ -19,6 +23,7 @@ abstract contract CommandEvent is EventEmitter {
|
|
|
19
23
|
uint indexed host,
|
|
20
24
|
uint id,
|
|
21
25
|
string name,
|
|
26
|
+
bytes32 shape,
|
|
22
27
|
string request,
|
|
23
28
|
bytes4 state,
|
|
24
29
|
bytes4 output,
|
package/events/Listing.sol
CHANGED
|
@@ -3,16 +3,15 @@ pragma solidity ^0.8.33;
|
|
|
3
3
|
|
|
4
4
|
import { EventEmitter } from "./Emitter.sol";
|
|
5
5
|
|
|
6
|
-
string constant ABI = "event Listing(uint indexed host, bytes32 asset, bytes32 meta, bool active
|
|
6
|
+
string constant ABI = "event Listing(uint indexed host, bytes32 asset, bytes32 meta, bool active)";
|
|
7
7
|
|
|
8
|
-
/// @notice Emitted when an asset listing is
|
|
8
|
+
/// @notice Emitted when an asset listing is updated on a host.
|
|
9
9
|
abstract contract ListingEvent is EventEmitter {
|
|
10
10
|
/// @param host Host node ID that manages this listing.
|
|
11
11
|
/// @param asset Asset identifier.
|
|
12
12
|
/// @param meta Asset metadata slot.
|
|
13
13
|
/// @param active True if the listing is currently active.
|
|
14
|
-
|
|
15
|
-
event Listing(uint indexed host, bytes32 asset, bytes32 meta, bool active, bool created);
|
|
14
|
+
event Listing(uint indexed host, bytes32 asset, bytes32 meta, bool active);
|
|
16
15
|
|
|
17
16
|
constructor() {
|
|
18
17
|
emit EventAbi(ABI);
|
package/events/Peer.sol
CHANGED
|
@@ -4,16 +4,18 @@ pragma solidity ^0.8.33;
|
|
|
4
4
|
import { EventEmitter } from "./Emitter.sol";
|
|
5
5
|
|
|
6
6
|
string constant ABI =
|
|
7
|
-
"event Peer(uint indexed host, uint id, string name, string request, bool acceptsValue)";
|
|
7
|
+
"event Peer(uint indexed host, uint id, string name, bytes32 shape, string request, string response, bool acceptsValue)";
|
|
8
8
|
|
|
9
|
-
/// @notice Emitted once per peer during host deployment to publish its request
|
|
9
|
+
/// @notice Emitted once per peer during host deployment to publish its request and response schemas.
|
|
10
10
|
abstract contract PeerEvent is EventEmitter {
|
|
11
11
|
/// @param host Host node ID that owns this peer.
|
|
12
12
|
/// @param id Peer node ID.
|
|
13
13
|
/// @param name Human-readable peer name.
|
|
14
|
+
/// @param shape Prime block counts as `request:response`; global blocks are excluded.
|
|
14
15
|
/// @param request Schema DSL string describing the peer request shape.
|
|
16
|
+
/// @param response Schema DSL string describing the peer response shape.
|
|
15
17
|
/// @param acceptsValue Whether the peer entrypoint accepts nonzero `msg.value`.
|
|
16
|
-
event Peer(uint indexed host, uint id, string name, string request, bool acceptsValue);
|
|
18
|
+
event Peer(uint indexed host, uint id, string name, bytes32 shape, string request, string response, bool acceptsValue);
|
|
17
19
|
|
|
18
20
|
constructor() {
|
|
19
21
|
emit EventAbi(ABI);
|
package/events/Query.sol
CHANGED
|
@@ -3,16 +3,19 @@ pragma solidity ^0.8.33;
|
|
|
3
3
|
|
|
4
4
|
import {EventEmitter} from "./Emitter.sol";
|
|
5
5
|
|
|
6
|
-
string constant ABI = "event Query(uint indexed host, uint id, string name, string request, string response)";
|
|
6
|
+
string constant ABI = "event Query(uint indexed host, uint id, string name, bytes32 shape, string request, string response)";
|
|
7
7
|
|
|
8
8
|
/// @notice Emitted once per query during host deployment to publish its request and response schemas.
|
|
9
9
|
abstract contract QueryEvent is EventEmitter {
|
|
10
10
|
/// @param host Host node ID that owns this query.
|
|
11
11
|
/// @param id Query node ID.
|
|
12
12
|
/// @param name Human-readable query name.
|
|
13
|
+
/// @param shape Per-operation prime block counts encoded as `request:response`.
|
|
14
|
+
/// Blocks outside the prime runs are global batch blocks and are excluded
|
|
15
|
+
/// from the counts.
|
|
13
16
|
/// @param request Schema DSL string describing the query request shape.
|
|
14
17
|
/// @param response Schema DSL string describing the query response shape.
|
|
15
|
-
event Query(uint indexed host, uint id, string name, string request, string response);
|
|
18
|
+
event Query(uint indexed host, uint id, string name, bytes32 shape, string request, string response);
|
|
16
19
|
|
|
17
20
|
constructor() {
|
|
18
21
|
emit EventAbi(ABI);
|
package/package.json
CHANGED
package/peer/AllowAssets.sol
CHANGED
|
@@ -15,12 +15,12 @@ abstract contract PeerAllowAssets is PeerBase, AllowAssetsHook {
|
|
|
15
15
|
uint internal immutable peerAllowAssetsId = peerId(NAME);
|
|
16
16
|
|
|
17
17
|
constructor() {
|
|
18
|
-
emit Peer(host, peerAllowAssetsId, NAME, Schemas.Asset, false);
|
|
18
|
+
emit Peer(host, peerAllowAssetsId, NAME, "1:0", Schemas.Asset, "", false);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/// @notice Execute the allow-assets peer call.
|
|
22
22
|
function peerAllowAssets(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
23
|
-
(Cur memory assets,
|
|
23
|
+
(Cur memory assets, ) = cursor(request, 1);
|
|
24
24
|
|
|
25
25
|
while (assets.i < assets.bound) {
|
|
26
26
|
(bytes32 asset, bytes32 meta) = assets.unpackAsset();
|
package/peer/Allowance.sol
CHANGED
|
@@ -16,12 +16,12 @@ abstract contract PeerAllowance is PeerBase, AllowanceHook {
|
|
|
16
16
|
uint internal immutable peerAllowanceId = peerId(NAME);
|
|
17
17
|
|
|
18
18
|
constructor() {
|
|
19
|
-
emit Peer(host, peerAllowanceId, NAME, Schemas.Amount, false);
|
|
19
|
+
emit Peer(host, peerAllowanceId, NAME, "1:0", Schemas.Amount, "", false);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/// @notice Execute the allowance peer call.
|
|
23
23
|
function peerAllowance(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
24
|
-
(Cur memory amounts,
|
|
24
|
+
(Cur memory amounts, ) = cursor(request, 1);
|
|
25
25
|
uint peer = caller();
|
|
26
26
|
|
|
27
27
|
while (amounts.i < amounts.bound) {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {PeerBase} from "./Base.sol";
|
|
5
|
+
import {Cursors, Cur, Schemas} from "../Cursors.sol";
|
|
6
|
+
|
|
7
|
+
using Cursors for Cur;
|
|
8
|
+
|
|
9
|
+
abstract contract BalancePullHook {
|
|
10
|
+
/// @notice Override to process one incoming balance-based pull request from a peer host.
|
|
11
|
+
/// @param peer Peer host node ID for this request.
|
|
12
|
+
/// @param asset Requested asset identifier.
|
|
13
|
+
/// @param meta Requested asset metadata slot.
|
|
14
|
+
/// @param amount Requested amount in the asset's native units.
|
|
15
|
+
function balancePull(uint peer, bytes32 asset, bytes32 meta, uint amount) internal virtual;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/// @title PeerBalancePull
|
|
19
|
+
/// @notice Peer that pulls requested balances from a peer host into this one.
|
|
20
|
+
/// Each BALANCE block in the request calls `balancePull(peer, asset, meta, amount)`.
|
|
21
|
+
/// Restricted to trusted peers.
|
|
22
|
+
abstract contract PeerBalancePull is PeerBase, BalancePullHook {
|
|
23
|
+
string private constant NAME = "peerBalancePull";
|
|
24
|
+
uint internal immutable peerBalancePullId = peerId(NAME);
|
|
25
|
+
|
|
26
|
+
constructor() {
|
|
27
|
+
emit Peer(host, peerBalancePullId, NAME, "1:0", Schemas.Balance, "", false);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/// @notice Execute the balance-pull peer call.
|
|
31
|
+
function peerBalancePull(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
32
|
+
(Cur memory input, ) = cursor(request, 1);
|
|
33
|
+
uint peer = caller();
|
|
34
|
+
|
|
35
|
+
while (input.i < input.bound) {
|
|
36
|
+
(bytes32 asset, bytes32 meta, uint amount) = input.unpackBalance();
|
|
37
|
+
balancePull(peer, asset, meta, amount);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
input.complete();
|
|
41
|
+
return "";
|
|
42
|
+
}
|
|
43
|
+
}
|
package/peer/DenyAssets.sol
CHANGED
|
@@ -15,12 +15,12 @@ abstract contract PeerDenyAssets is PeerBase, DenyAssetsHook {
|
|
|
15
15
|
uint internal immutable peerDenyAssetsId = peerId(NAME);
|
|
16
16
|
|
|
17
17
|
constructor() {
|
|
18
|
-
emit Peer(host, peerDenyAssetsId, NAME, Schemas.Asset, false);
|
|
18
|
+
emit Peer(host, peerDenyAssetsId, NAME, "1:0", Schemas.Asset, "", false);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/// @notice Execute the deny-assets peer call.
|
|
22
22
|
function peerDenyAssets(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
23
|
-
(Cur memory assets,
|
|
23
|
+
(Cur memory assets, ) = cursor(request, 1);
|
|
24
24
|
|
|
25
25
|
while (assets.i < assets.bound) {
|
|
26
26
|
(bytes32 asset, bytes32 meta) = assets.unpackAsset();
|
package/peer/Settle.sol
CHANGED
|
@@ -15,12 +15,12 @@ abstract contract PeerSettle is PeerBase, TransferHook {
|
|
|
15
15
|
uint internal immutable peerSettleId = peerId(NAME);
|
|
16
16
|
|
|
17
17
|
constructor() {
|
|
18
|
-
emit Peer(host, peerSettleId, NAME, Schemas.Transaction, false);
|
|
18
|
+
emit Peer(host, peerSettleId, NAME, "1:0", Schemas.Transaction, "", false);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/// @notice Execute the peer-settle call.
|
|
22
22
|
function peerSettle(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
23
|
-
(Cur memory state,
|
|
23
|
+
(Cur memory state, ) = cursor(request, 1);
|
|
24
24
|
|
|
25
25
|
while (state.i < state.bound) {
|
|
26
26
|
transfer(state.unpackTxValue());
|
package/queries/Assets.sol
CHANGED
|
@@ -26,15 +26,15 @@ abstract contract IsAllowedAsset is QueryBase, IsAllowedAssetHook {
|
|
|
26
26
|
uint public immutable isAllowedAssetId = queryId(NAME);
|
|
27
27
|
|
|
28
28
|
constructor() {
|
|
29
|
-
emit Query(host, isAllowedAssetId, NAME, Schemas.Asset, Forms.Status);
|
|
29
|
+
emit Query(host, isAllowedAssetId, NAME, "1:1", Schemas.Asset, Forms.Status);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/// @notice Resolve allowlist status for a run of requested `(asset, meta)` tuples.
|
|
33
33
|
/// @param request Block-stream request consisting of `asset(asset, meta)*`.
|
|
34
34
|
/// @return Block-stream response containing one `status(ok)` per asset block.
|
|
35
35
|
function isAllowedAsset(bytes calldata request) external view returns (bytes memory) {
|
|
36
|
-
(Cur memory query, uint
|
|
37
|
-
Writer memory response = Writers.allocStatuses(
|
|
36
|
+
(Cur memory query, uint groups) = cursor(request, 1);
|
|
37
|
+
Writer memory response = Writers.allocStatuses(groups);
|
|
38
38
|
|
|
39
39
|
while (query.i < query.bound) {
|
|
40
40
|
(bytes32 asset, bytes32 meta) = query.unpackAsset();
|
package/queries/Balances.sol
CHANGED
|
@@ -26,15 +26,15 @@ abstract contract GetBalances is QueryBase, GetBalancesHook {
|
|
|
26
26
|
uint public immutable getBalancesId = queryId(NAME);
|
|
27
27
|
|
|
28
28
|
constructor() {
|
|
29
|
-
emit Query(host, getBalancesId, NAME, Forms.AccountAsset, Forms.AccountAmount);
|
|
29
|
+
emit Query(host, getBalancesId, NAME, "1:1", Forms.AccountAsset, Forms.AccountAmount);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/// @notice Resolve balances for a run of requested `(account, asset, meta)` tuples.
|
|
33
33
|
/// @param request Block-stream request consisting of `accountAsset(account, asset, meta)*`.
|
|
34
34
|
/// @return Block-stream response containing one `accountAmount(account, asset, meta, amount)` block per request block.
|
|
35
35
|
function getBalances(bytes calldata request) external view returns (bytes memory) {
|
|
36
|
-
(Cur memory query, uint
|
|
37
|
-
Writer memory response = Writers.allocAccountAmounts(
|
|
36
|
+
(Cur memory query, uint groups) = cursor(request, 1);
|
|
37
|
+
Writer memory response = Writers.allocAccountAmounts(groups);
|
|
38
38
|
|
|
39
39
|
while (query.i < query.bound) {
|
|
40
40
|
(bytes32 account, bytes32 asset, bytes32 meta) = query.unpackAccountAsset();
|
package/queries/Positions.sol
CHANGED
|
@@ -34,7 +34,7 @@ abstract contract GetPosition is QueryBase, GetPositionHook {
|
|
|
34
34
|
|
|
35
35
|
constructor(string memory output, uint responseSize) {
|
|
36
36
|
positionResponseSize = responseSize;
|
|
37
|
-
emit Query(host, getPositionId, NAME, Forms.AccountAsset, output);
|
|
37
|
+
emit Query(host, getPositionId, NAME, "1:1", Forms.AccountAsset, output);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/// @notice Resolve positions for a run of requested `(account, asset, meta)` tuples.
|
|
@@ -43,8 +43,8 @@ abstract contract GetPosition is QueryBase, GetPositionHook {
|
|
|
43
43
|
/// @param request Block-stream request consisting of `accountAsset(account, asset, meta)*`.
|
|
44
44
|
/// @return Block-stream response containing one `response(bytes data)` block per position block.
|
|
45
45
|
function getPosition(bytes calldata request) external view returns (bytes memory) {
|
|
46
|
-
(Cur memory query, uint
|
|
47
|
-
Writer memory response = Writers.allocBytes(
|
|
46
|
+
(Cur memory query, uint groups) = cursor(request, 1);
|
|
47
|
+
Writer memory response = Writers.allocBytes(groups, positionResponseSize);
|
|
48
48
|
|
|
49
49
|
while (query.i < query.bound) {
|
|
50
50
|
(bytes32 account, bytes32 asset, bytes32 meta) = query.unpackAccountAsset();
|
package/peer/AssetPull.sol
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import {PeerBase} from "./Base.sol";
|
|
5
|
-
import {Cursors, Cur, Schemas} from "../Cursors.sol";
|
|
6
|
-
|
|
7
|
-
using Cursors for Cur;
|
|
8
|
-
|
|
9
|
-
abstract contract AssetPullHook {
|
|
10
|
-
/// @notice Override to process one incoming amount-based asset pull request from a peer host.
|
|
11
|
-
/// @param peer Peer host node ID for this request.
|
|
12
|
-
/// @param asset Requested asset identifier.
|
|
13
|
-
/// @param meta Requested asset metadata slot.
|
|
14
|
-
/// @param amount Requested amount in the asset's native units.
|
|
15
|
-
function assetPull(uint peer, bytes32 asset, bytes32 meta, uint amount) internal virtual;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/// @title PeerAssetPull
|
|
19
|
-
/// @notice Peer that pulls requested asset amounts from a peer host into this one.
|
|
20
|
-
/// Each AMOUNT block in the request calls `assetPull(peer, asset, meta, amount)`.
|
|
21
|
-
/// Restricted to trusted peers.
|
|
22
|
-
abstract contract PeerAssetPull is PeerBase, AssetPullHook {
|
|
23
|
-
string private constant NAME = "peerAssetPull";
|
|
24
|
-
uint internal immutable peerAssetPullId = peerId(NAME);
|
|
25
|
-
|
|
26
|
-
constructor() {
|
|
27
|
-
emit Peer(host, peerAssetPullId, NAME, Schemas.Amount, false);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/// @notice Execute the asset-pull peer call.
|
|
31
|
-
function peerAssetPull(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
32
|
-
(Cur memory assets, , ) = cursor(request, 1);
|
|
33
|
-
uint peer = caller();
|
|
34
|
-
|
|
35
|
-
while (assets.i < assets.bound) {
|
|
36
|
-
(bytes32 asset, bytes32 meta, uint amount) = assets.unpackAmount();
|
|
37
|
-
assetPull(peer, asset, meta, amount);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
assets.complete();
|
|
41
|
-
return "";
|
|
42
|
-
}
|
|
43
|
-
}
|