@rootzero/contracts 0.9.5 → 0.9.7
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 → Endpoints.sol} +24 -9
- package/Events.sol +8 -7
- package/README.md +2 -3
- package/blocks/Cursors.sol +10 -14
- package/blocks/Keys.sol +3 -3
- package/blocks/Schema.sol +4 -4
- package/blocks/Writers.sol +17 -20
- package/commands/Base.sol +1 -9
- package/commands/admin/Appoint.sol +35 -0
- package/commands/admin/Authorize.sol +1 -1
- package/commands/admin/Dismiss.sol +35 -0
- package/commands/admin/Unauthorize.sol +1 -1
- package/core/Access.sol +35 -27
- package/core/Host.sol +6 -3
- package/docs/Schema.md +2 -2
- package/events/Admin.sol +3 -3
- package/events/Asset.sol +8 -7
- package/events/Balance.sol +2 -2
- package/events/Collateral.sol +2 -2
- package/events/Command.sol +3 -3
- package/events/Contexts.sol +12 -0
- package/events/Debt.sol +2 -2
- package/events/Guard.sol +19 -0
- package/events/Guardian.sol +18 -0
- package/events/Introduction.sol +2 -2
- package/events/Node.sol +18 -0
- package/events/Peer.sol +13 -8
- package/events/Position.sol +4 -4
- package/events/Query.sol +2 -2
- package/events/Received.sol +20 -0
- package/events/Rooted.sol +2 -2
- package/events/Spent.sol +20 -0
- package/guards/Base.sol +35 -0
- package/guards/Revoke.sol +31 -0
- package/package.json +1 -1
- package/peer/Pipe.sol +8 -8
- package/queries/Assets.sol +16 -16
- package/utils/Accounts.sol +49 -2
- package/utils/Assets.sol +2 -0
- package/utils/Ids.sol +57 -18
- package/utils/Layout.sol +6 -2
- package/Queries.sol +0 -10
- package/events/Access.sol +0 -21
- package/events/Deposit.sol +0 -22
- package/events/Listing.sol +0 -22
- package/events/Swap.sol +0 -20
- package/events/Withdraw.sol +0 -22
package/utils/Ids.sol
CHANGED
|
@@ -26,6 +26,8 @@ library Ids {
|
|
|
26
26
|
uint32 constant Peer = (uint32(Layout.Evm32) << 16) | (uint32(Layout.Node) << 8) | uint32(Layout.Peer);
|
|
27
27
|
/// @dev Full 4-byte type prefix for query nodes.
|
|
28
28
|
uint32 constant Query = (uint32(Layout.Evm32) << 16) | (uint32(Layout.Node) << 8) | uint32(Layout.Query);
|
|
29
|
+
/// @dev Full 4-byte type prefix for guard action nodes.
|
|
30
|
+
uint32 constant Guard = (uint32(Layout.Evm32) << 16) | (uint32(Layout.Node) << 8) | uint32(Layout.Guard);
|
|
29
31
|
|
|
30
32
|
/// @notice Return true if `id` is a host node ID.
|
|
31
33
|
function isHost(uint id) internal pure returns (bool) {
|
|
@@ -47,6 +49,11 @@ library Ids {
|
|
|
47
49
|
return uint32(id >> 224) == Query;
|
|
48
50
|
}
|
|
49
51
|
|
|
52
|
+
/// @notice Return true if `id` is a guard action node ID.
|
|
53
|
+
function isGuard(uint id) internal pure returns (bool) {
|
|
54
|
+
return uint32(id >> 224) == Guard;
|
|
55
|
+
}
|
|
56
|
+
|
|
50
57
|
/// @notice Return true if `id` is a local node ID for this contract.
|
|
51
58
|
function isLocalNode(uint id) internal view returns (bool) {
|
|
52
59
|
return isLocalFamily(id, Node) && address(uint160(id)) == address(this);
|
|
@@ -60,14 +67,6 @@ library Ids {
|
|
|
60
67
|
return id;
|
|
61
68
|
}
|
|
62
69
|
|
|
63
|
-
/// @notice Assert that `id` is a command ID and return its embedded ABI selector.
|
|
64
|
-
/// @param id Node ID to validate.
|
|
65
|
-
/// @return selector 4-byte command selector stored in bits [191:160].
|
|
66
|
-
function commandSelector(uint id) internal pure returns (bytes4 selector) {
|
|
67
|
-
if (!isCommand(id)) revert InvalidId();
|
|
68
|
-
return bytes4(uint32(id >> 160));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
70
|
/// @notice Assert that `id` is a peer ID and return it unchanged.
|
|
72
71
|
/// @param id Node ID to validate.
|
|
73
72
|
/// @return pid The same `id` value if it is a peer.
|
|
@@ -76,14 +75,6 @@ library Ids {
|
|
|
76
75
|
return id;
|
|
77
76
|
}
|
|
78
77
|
|
|
79
|
-
/// @notice Assert that `id` is a peer ID and return its embedded ABI selector.
|
|
80
|
-
/// @param id Node ID to validate.
|
|
81
|
-
/// @return selector 4-byte peer selector stored in bits [191:160].
|
|
82
|
-
function peerSelector(uint id) internal pure returns (bytes4 selector) {
|
|
83
|
-
if (!isPeer(id)) revert InvalidId();
|
|
84
|
-
return bytes4(uint32(id >> 160));
|
|
85
|
-
}
|
|
86
|
-
|
|
87
78
|
/// @notice Assert that `id` is a query ID and return it unchanged.
|
|
88
79
|
/// @param id Node ID to validate.
|
|
89
80
|
/// @return queryId The same `id` value if it is a query.
|
|
@@ -92,12 +83,40 @@ library Ids {
|
|
|
92
83
|
return id;
|
|
93
84
|
}
|
|
94
85
|
|
|
86
|
+
/// @notice Assert that `id` is a guard action ID and return it unchanged.
|
|
87
|
+
/// @param id Node ID to validate.
|
|
88
|
+
/// @return guardId The same `id` value if it is a guard action.
|
|
89
|
+
function guard(uint id) internal pure returns (uint guardId) {
|
|
90
|
+
if (!isGuard(id)) revert InvalidId();
|
|
91
|
+
return id;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/// @notice Assert that `id` is a command ID and return its embedded ABI selector.
|
|
95
|
+
/// @param id Node ID to validate.
|
|
96
|
+
/// @return selector 4-byte command selector stored in bits [191:160].
|
|
97
|
+
function commandSelector(uint id) internal pure returns (bytes4 selector) {
|
|
98
|
+
return bytes4(uint32(command(id) >> 160));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/// @notice Assert that `id` is a peer ID and return its embedded ABI selector.
|
|
102
|
+
/// @param id Node ID to validate.
|
|
103
|
+
/// @return selector 4-byte peer selector stored in bits [191:160].
|
|
104
|
+
function peerSelector(uint id) internal pure returns (bytes4 selector) {
|
|
105
|
+
return bytes4(uint32(peer(id) >> 160));
|
|
106
|
+
}
|
|
107
|
+
|
|
95
108
|
/// @notice Assert that `id` is a query ID and return its embedded ABI selector.
|
|
96
109
|
/// @param id Node ID to validate.
|
|
97
110
|
/// @return selector 4-byte query selector stored in bits [191:160].
|
|
98
111
|
function querySelector(uint id) internal pure returns (bytes4 selector) {
|
|
99
|
-
|
|
100
|
-
|
|
112
|
+
return bytes4(uint32(query(id) >> 160));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/// @notice Assert that `id` is a guard action ID and return its embedded ABI selector.
|
|
116
|
+
/// @param id Node ID to validate.
|
|
117
|
+
/// @return selector 4-byte guard selector stored in bits [191:160].
|
|
118
|
+
function guardSelector(uint id) internal pure returns (bytes4 selector) {
|
|
119
|
+
return bytes4(uint32(guard(id) >> 160));
|
|
101
120
|
}
|
|
102
121
|
|
|
103
122
|
/// @notice Assert that `id` is the host ID of `addr` on the current chain.
|
|
@@ -146,6 +165,16 @@ library Ids {
|
|
|
146
165
|
return id;
|
|
147
166
|
}
|
|
148
167
|
|
|
168
|
+
/// @notice Build a chain-local guard action ID for the given selector and contract.
|
|
169
|
+
/// @param selector 4-byte ABI selector of the guard action entry point.
|
|
170
|
+
/// @param target Guard action contract address.
|
|
171
|
+
/// @return Guard action node ID embedding both the selector and address.
|
|
172
|
+
function toGuard(bytes4 selector, address target) internal view returns (uint) {
|
|
173
|
+
uint id = toLocalBase(Guard) | uint(uint160(target));
|
|
174
|
+
id |= uint(uint32(selector)) << 160;
|
|
175
|
+
return id;
|
|
176
|
+
}
|
|
177
|
+
|
|
149
178
|
/// @notice Extract the contract address from any local node ID.
|
|
150
179
|
/// Reverts if `id` does not belong to the local node family.
|
|
151
180
|
/// @param id Node ID (host, command, or peer).
|
|
@@ -174,6 +203,8 @@ library Selectors {
|
|
|
174
203
|
string constant PeerArgs = "(bytes)";
|
|
175
204
|
/// @dev ABI argument encoding for query entry points: `(bytes)`.
|
|
176
205
|
string constant QueryArgs = "(bytes)";
|
|
206
|
+
/// @dev ABI argument encoding for guard action entry points: `(bytes)`.
|
|
207
|
+
string constant GuardArgs = "(bytes)";
|
|
177
208
|
|
|
178
209
|
/// @notice Derive the 4-byte ABI selector for a named command.
|
|
179
210
|
/// The selector is `keccak256(name ++ CommandArgs)[0:4]`.
|
|
@@ -198,4 +229,12 @@ library Selectors {
|
|
|
198
229
|
function query(string memory name) internal pure returns (bytes4) {
|
|
199
230
|
return bytes4(keccak256(bytes.concat(bytes(name), bytes(QueryArgs))));
|
|
200
231
|
}
|
|
232
|
+
|
|
233
|
+
/// @notice Derive the 4-byte ABI selector for a named guard action.
|
|
234
|
+
/// The selector is `keccak256(name ++ GuardArgs)[0:4]`.
|
|
235
|
+
/// @param name Guard action function name (without arguments).
|
|
236
|
+
/// @return 4-byte selector.
|
|
237
|
+
function guard(string memory name) internal pure returns (bytes4) {
|
|
238
|
+
return bytes4(keccak256(bytes.concat(bytes(name), bytes(GuardArgs))));
|
|
239
|
+
}
|
|
201
240
|
}
|
package/utils/Layout.sol
CHANGED
|
@@ -37,10 +37,12 @@ library Layout {
|
|
|
37
37
|
|
|
38
38
|
/// @dev Admin account — chain-local, backed by an EVM address.
|
|
39
39
|
uint8 constant Admin = 0x01;
|
|
40
|
+
/// @dev Guardian account — chain-local, backed by an EVM address.
|
|
41
|
+
uint8 constant Guardian = 0x02;
|
|
40
42
|
/// @dev User account — chain-agnostic, backed by an EVM address.
|
|
41
|
-
uint8 constant User =
|
|
43
|
+
uint8 constant User = 0x03;
|
|
42
44
|
/// @dev Keccak account — opaque 28-byte keccak commitment.
|
|
43
|
-
uint8 constant Keccak =
|
|
45
|
+
uint8 constant Keccak = 0x04;
|
|
44
46
|
|
|
45
47
|
// -------------------------------------------------------------------------
|
|
46
48
|
// Node subtype tags (uint8, fourth byte of the ID type field)
|
|
@@ -54,6 +56,8 @@ library Layout {
|
|
|
54
56
|
uint8 constant Peer = 0x03;
|
|
55
57
|
/// @dev Node is a query contract.
|
|
56
58
|
uint8 constant Query = 0x04;
|
|
59
|
+
/// @dev Node is a guardian-only direct action.
|
|
60
|
+
uint8 constant Guard = 0x05;
|
|
57
61
|
|
|
58
62
|
// -------------------------------------------------------------------------
|
|
59
63
|
// Asset subtype tags (uint8, fourth byte of the ID type field)
|
package/Queries.sol
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
// Aggregator: re-exports query abstractions and reusable query bases.
|
|
5
|
-
// Import this file to build rootzero query contracts without managing individual paths.
|
|
6
|
-
|
|
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
|
-
import { QueryBase, encodeQueryCall } from "./queries/Base.sol";
|
package/events/Access.sol
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { EventEmitter } from "./Emitter.sol";
|
|
5
|
-
|
|
6
|
-
string constant ABI = "event Access(uint indexed host, uint node, bool trusted)";
|
|
7
|
-
|
|
8
|
-
/// @notice Emitted when a node's authorization status changes on a host.
|
|
9
|
-
abstract contract AccessEvent is EventEmitter {
|
|
10
|
-
/// @param host Host node ID where the authorization change occurred.
|
|
11
|
-
/// @param node Node ID that was authorized or deauthorized.
|
|
12
|
-
/// @param trusted True if the node was authorized, false if deauthorized.
|
|
13
|
-
event Access(uint indexed host, uint node, bool trusted);
|
|
14
|
-
|
|
15
|
-
constructor() {
|
|
16
|
-
emit EventAbi(ABI);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
package/events/Deposit.sol
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { EventEmitter } from "./Emitter.sol";
|
|
5
|
-
|
|
6
|
-
string constant ABI = "event Deposit(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount)";
|
|
7
|
-
|
|
8
|
-
/// @notice Emitted when assets are deposited into an account.
|
|
9
|
-
abstract contract DepositEvent is EventEmitter {
|
|
10
|
-
/// @param account Destination account identifier.
|
|
11
|
-
/// @param asset Asset identifier.
|
|
12
|
-
/// @param meta Asset metadata slot.
|
|
13
|
-
/// @param amount Amount deposited.
|
|
14
|
-
event Deposit(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount);
|
|
15
|
-
|
|
16
|
-
constructor() {
|
|
17
|
-
emit EventAbi(ABI);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
package/events/Listing.sol
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { EventEmitter } from "./Emitter.sol";
|
|
5
|
-
|
|
6
|
-
string constant ABI = "event Listing(uint indexed host, bytes32 asset, bytes32 meta, bool active)";
|
|
7
|
-
|
|
8
|
-
/// @notice Emitted when an asset listing is updated on a host.
|
|
9
|
-
abstract contract ListingEvent is EventEmitter {
|
|
10
|
-
/// @param host Host node ID that manages this listing.
|
|
11
|
-
/// @param asset Asset identifier.
|
|
12
|
-
/// @param meta Asset metadata slot.
|
|
13
|
-
/// @param active True if the listing is currently active.
|
|
14
|
-
event Listing(uint indexed host, bytes32 asset, bytes32 meta, bool active);
|
|
15
|
-
|
|
16
|
-
constructor() {
|
|
17
|
-
emit EventAbi(ABI);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
package/events/Swap.sol
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { EventEmitter } from "./Emitter.sol";
|
|
5
|
-
|
|
6
|
-
string constant ABI = "event Swap(bytes32 indexed account, bytes32 assetIn, uint amountIn, bytes32 assetOut, uint amountOut)";
|
|
7
|
-
|
|
8
|
-
/// @notice Emitted when an account swaps one asset for another.
|
|
9
|
-
abstract contract SwapEvent is EventEmitter {
|
|
10
|
-
/// @param account Account identifier performing the swap.
|
|
11
|
-
/// @param assetIn Input asset identifier.
|
|
12
|
-
/// @param amountIn Input amount spent.
|
|
13
|
-
/// @param assetOut Output asset identifier.
|
|
14
|
-
/// @param amountOut Output amount received.
|
|
15
|
-
event Swap(bytes32 indexed account, bytes32 assetIn, uint amountIn, bytes32 assetOut, uint amountOut);
|
|
16
|
-
|
|
17
|
-
constructor() {
|
|
18
|
-
emit EventAbi(ABI);
|
|
19
|
-
}
|
|
20
|
-
}
|
package/events/Withdraw.sol
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { EventEmitter } from "./Emitter.sol";
|
|
5
|
-
|
|
6
|
-
string constant ABI = "event Withdrawal(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount)";
|
|
7
|
-
|
|
8
|
-
/// @notice Emitted when assets are withdrawn from an account.
|
|
9
|
-
abstract contract WithdrawalEvent is EventEmitter {
|
|
10
|
-
/// @param account Source account identifier.
|
|
11
|
-
/// @param asset Asset identifier.
|
|
12
|
-
/// @param meta Asset metadata slot.
|
|
13
|
-
/// @param amount Amount withdrawn.
|
|
14
|
-
event Withdrawal(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount);
|
|
15
|
-
|
|
16
|
-
constructor() {
|
|
17
|
-
emit EventAbi(ABI);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|