@rootzero/contracts 0.9.5 → 0.9.6
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/Events.sol +5 -6
- package/Queries.sol +1 -1
- 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/core/Host.sol +3 -2
- package/docs/Schema.md +2 -2
- package/events/Access.sol +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/Introduction.sol +2 -2
- 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/package.json +1 -1
- package/peer/Pipe.sol +8 -8
- package/queries/Assets.sol +16 -16
- package/utils/Assets.sol +2 -0
- 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/Events.sol
CHANGED
|
@@ -6,21 +6,20 @@ pragma solidity ^0.8.33;
|
|
|
6
6
|
|
|
7
7
|
import { AccessEvent } from "./events/Access.sol";
|
|
8
8
|
import { AdminEvent } from "./events/Admin.sol";
|
|
9
|
-
import {
|
|
9
|
+
import { AssetStatusEvent } from "./events/Asset.sol";
|
|
10
10
|
import { BalanceEvent } from "./events/Balance.sol";
|
|
11
11
|
import { CollateralEvent } from "./events/Collateral.sol";
|
|
12
12
|
import { CommandEvent } from "./events/Command.sol";
|
|
13
|
+
import { Contexts } from "./events/Contexts.sol";
|
|
13
14
|
import { DebtEvent } from "./events/Debt.sol";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
15
|
+
import { PositionEvent } from "./events/Position.sol";
|
|
16
|
+
import { ReceivedEvent } from "./events/Received.sol";
|
|
16
17
|
import { EventEmitter } from "./events/Emitter.sol";
|
|
17
18
|
import { IntroductionEvent } from "./events/Introduction.sol";
|
|
18
|
-
import { ListingEvent } from "./events/Listing.sol";
|
|
19
19
|
import { PeerEvent } from "./events/Peer.sol";
|
|
20
20
|
import { QueryEvent } from "./events/Query.sol";
|
|
21
21
|
import { RootedEvent } from "./events/Rooted.sol";
|
|
22
|
-
import {
|
|
23
|
-
import { WithdrawalEvent } from "./events/Withdraw.sol";
|
|
22
|
+
import { SpentEvent } from "./events/Spent.sol";
|
|
24
23
|
|
|
25
24
|
|
|
26
25
|
|
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 {
|
|
7
|
+
import { AssetStatus, AssetStatusHook } from "./queries/Assets.sol";
|
|
8
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/blocks/Cursors.sol
CHANGED
|
@@ -531,21 +531,19 @@ library Cursors {
|
|
|
531
531
|
return createBlock(Keys.Context, bytes.concat(account, toBytesBlock(state), toBytesBlock(request)));
|
|
532
532
|
}
|
|
533
533
|
|
|
534
|
-
/// @notice Encode a
|
|
535
|
-
/// @param
|
|
536
|
-
/// @param value Native value assigned to the relay.
|
|
534
|
+
/// @notice Encode a PIPE block.
|
|
535
|
+
/// @param value Native value assigned to the pipe.
|
|
537
536
|
/// @param account Command account identifier.
|
|
538
537
|
/// @param state Embedded state block stream.
|
|
539
538
|
/// @param request Embedded request block stream.
|
|
540
|
-
/// @return Encoded
|
|
541
|
-
function
|
|
542
|
-
uint target,
|
|
539
|
+
/// @return Encoded PIPE block bytes.
|
|
540
|
+
function toPipeBlock(
|
|
543
541
|
uint value,
|
|
544
542
|
bytes32 account,
|
|
545
543
|
bytes memory state,
|
|
546
544
|
bytes memory request
|
|
547
545
|
) internal pure returns (bytes memory) {
|
|
548
|
-
return createBlock(Keys.
|
|
546
|
+
return createBlock(Keys.Pipe, bytes.concat(bytes32(value), toContextBlock(account, state, request)));
|
|
549
547
|
}
|
|
550
548
|
|
|
551
549
|
// -------------------------------------------------------------------------
|
|
@@ -1112,18 +1110,16 @@ library Cursors {
|
|
|
1112
1110
|
cur.exit(end);
|
|
1113
1111
|
}
|
|
1114
1112
|
|
|
1115
|
-
/// @notice Consume a
|
|
1113
|
+
/// @notice Consume a PIPE block and return its value and context fields.
|
|
1116
1114
|
/// @param cur Cursor; advanced past the block.
|
|
1117
|
-
/// @return
|
|
1118
|
-
/// @return value Native value assigned to the relay.
|
|
1115
|
+
/// @return value Native value assigned to the pipe.
|
|
1119
1116
|
/// @return account Command account identifier.
|
|
1120
1117
|
/// @return state Embedded state block stream.
|
|
1121
1118
|
/// @return request Embedded request block stream.
|
|
1122
|
-
function
|
|
1119
|
+
function unpackPipe(
|
|
1123
1120
|
Cur memory cur
|
|
1124
|
-
) internal pure returns (uint
|
|
1125
|
-
uint end = cur.enter(Keys.
|
|
1126
|
-
target = uint(cur.read32());
|
|
1121
|
+
) internal pure returns (uint value, bytes32 account, bytes calldata state, bytes calldata request) {
|
|
1122
|
+
uint end = cur.enter(Keys.Pipe, 32 + Sizes.Header + 32 + 2 * Sizes.Header, 0);
|
|
1127
1123
|
value = uint(cur.read32());
|
|
1128
1124
|
(account, state, request) = cur.unpackContext();
|
|
1129
1125
|
cur.exit(end);
|
package/blocks/Keys.sol
CHANGED
|
@@ -43,8 +43,8 @@ library Keys {
|
|
|
43
43
|
bytes4 constant Call = bytes4(keccak256("#call"));
|
|
44
44
|
/// @dev Command context transport - (bytes32 account, #bytes as state, #bytes as request)
|
|
45
45
|
bytes4 constant Context = bytes4(keccak256("#context"));
|
|
46
|
-
/// @dev Pipeline
|
|
47
|
-
bytes4 constant
|
|
46
|
+
/// @dev Pipeline invocation - (uint value, #context)
|
|
47
|
+
bytes4 constant Pipe = bytes4(keccak256("#pipe"));
|
|
48
48
|
/// @dev Authentication proof - (uint cid, uint deadline, #bytes as proof); must appear last in its segment
|
|
49
49
|
bytes4 constant Auth = bytes4(keccak256("#auth"));
|
|
50
50
|
/// @dev Asset descriptor without amount - (bytes32 asset, bytes32 meta)
|
|
@@ -54,7 +54,7 @@ library Keys {
|
|
|
54
54
|
/// @dev Relayer bounty - (uint amount, bytes32 relayer)
|
|
55
55
|
bytes4 constant Bounty = bytes4(keccak256("#bounty"));
|
|
56
56
|
|
|
57
|
-
/// @dev Structural status form - (
|
|
57
|
+
/// @dev Structural status form - (uint code)
|
|
58
58
|
bytes4 constant Status = bytes4(keccak256("#status"));
|
|
59
59
|
/// @dev Structural asset amount form - (bytes32 asset, bytes32 meta, uint amount)
|
|
60
60
|
bytes4 constant AssetAmount = bytes4(keccak256("#assetAmount"));
|
package/blocks/Schema.sol
CHANGED
|
@@ -60,7 +60,7 @@ library Schemas {
|
|
|
60
60
|
string constant Allowance = "#allowance { uint host, bytes32 asset, bytes32 meta, uint amount }";
|
|
61
61
|
string constant Transaction = "#transaction { bytes32 from, bytes32 to, bytes32 asset, bytes32 meta, uint amount }";
|
|
62
62
|
string constant Context = "#context { bytes32 account, #bytes as state, #bytes as request }";
|
|
63
|
-
string constant
|
|
63
|
+
string constant Pipe = "#pipe { uint value, #context { bytes32 account, #bytes as state, #bytes as request } }";
|
|
64
64
|
string constant Call = "#call { uint target, uint value, #bytes as payload }";
|
|
65
65
|
string constant Step = "#step { uint target, uint value, #bytes as request }";
|
|
66
66
|
string constant Bounty = "#bounty { uint amount, bytes32 relayer }";
|
|
@@ -76,7 +76,7 @@ library Schemas {
|
|
|
76
76
|
/// @notice Reusable structural block schemas for core tuple shapes.
|
|
77
77
|
/// These describe payload form without assigning command or query semantics.
|
|
78
78
|
library Forms {
|
|
79
|
-
string constant Status = "#status {
|
|
79
|
+
string constant Status = "#status { uint code }";
|
|
80
80
|
string constant AssetAmount = "#assetAmount { bytes32 asset, bytes32 meta, uint amount }";
|
|
81
81
|
string constant AccountAsset = "#accountAsset { bytes32 account, bytes32 asset, bytes32 meta }";
|
|
82
82
|
string constant AccountAmount = "#accountAmount { bytes32 account, bytes32 asset, bytes32 meta, uint amount }";
|
|
@@ -107,8 +107,8 @@ library Sizes {
|
|
|
107
107
|
uint constant Proof = 85;
|
|
108
108
|
/// @dev AUTH block: 8 header + 32 cid + 32 deadline + nested BYTES block with 85-byte proof = 165 bytes
|
|
109
109
|
uint constant Auth = B64 + Header + Proof;
|
|
110
|
-
/// @dev STATUS block: 8 header +
|
|
111
|
-
uint constant Status =
|
|
110
|
+
/// @dev STATUS block: 8 header + 32 status code = 40 bytes
|
|
111
|
+
uint constant Status = B32;
|
|
112
112
|
/// @dev AMOUNT block: 8 header + 32 asset + 32 meta + 32 amount = 104 bytes
|
|
113
113
|
uint constant Amount = B96;
|
|
114
114
|
/// @dev BALANCE block: 8 header + 32 asset + 32 meta + 32 amount = 104 bytes
|
package/blocks/Writers.sol
CHANGED
|
@@ -27,7 +27,7 @@ library Hints {
|
|
|
27
27
|
uint constant Step = 256;
|
|
28
28
|
uint constant Call = 256;
|
|
29
29
|
uint constant Context = 512;
|
|
30
|
-
uint constant
|
|
30
|
+
uint constant Pipe = 608;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/// @title Writers
|
|
@@ -224,12 +224,12 @@ library Writers {
|
|
|
224
224
|
return allocFromHint(count, Hints.Context);
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
-
/// @notice Allocate a writer for `count`
|
|
228
|
-
/// @dev The backing buffer expands automatically if encoded
|
|
229
|
-
/// @param count Number of
|
|
227
|
+
/// @notice Allocate a writer for `count` PIPE blocks using a per-block capacity hint.
|
|
228
|
+
/// @dev The backing buffer expands automatically if encoded pipes exceed the initial hint.
|
|
229
|
+
/// @param count Number of pipe blocks to allocate space for.
|
|
230
230
|
/// @return writer Allocated growable writer.
|
|
231
|
-
function
|
|
232
|
-
return allocFromHint(count, Hints.
|
|
231
|
+
function allocPipes(uint count) internal pure returns (Writer memory writer) {
|
|
232
|
+
return allocFromHint(count, Hints.Pipe);
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
// -------------------------------------------------------------------------
|
|
@@ -889,40 +889,37 @@ library Writers {
|
|
|
889
889
|
appendBlock32BytesBytes(writer, Keys.Context, account, state, request);
|
|
890
890
|
}
|
|
891
891
|
|
|
892
|
-
/// @notice Append a
|
|
893
|
-
/// @param writer Destination writer; `i` is advanced by the encoded
|
|
894
|
-
/// @param
|
|
895
|
-
/// @param value Native value assigned to the relay.
|
|
892
|
+
/// @notice Append a PIPE block with a nested CONTEXT block.
|
|
893
|
+
/// @param writer Destination writer; `i` is advanced by the encoded PIPE block length.
|
|
894
|
+
/// @param value Native value assigned to the pipe.
|
|
896
895
|
/// @param account Command account identifier.
|
|
897
896
|
/// @param state Raw nested state payload.
|
|
898
897
|
/// @param request Raw nested request payload.
|
|
899
|
-
function
|
|
898
|
+
function appendPipe(
|
|
900
899
|
Writer memory writer,
|
|
901
|
-
uint target,
|
|
902
900
|
uint value,
|
|
903
901
|
bytes32 account,
|
|
904
902
|
bytes memory state,
|
|
905
903
|
bytes memory request
|
|
906
904
|
) internal pure {
|
|
907
905
|
uint i = writer.i;
|
|
908
|
-
uint len =
|
|
906
|
+
uint len = 64 + 3 * Sizes.Header + state.length + request.length;
|
|
909
907
|
uint next = i + Sizes.Header + len;
|
|
910
908
|
i = reserve(writer, next, next);
|
|
911
909
|
|
|
912
|
-
uint p = writeHeader(writer.dst, i, Keys.
|
|
910
|
+
uint p = writeHeader(writer.dst, i, Keys.Pipe, uint32(max32(len)));
|
|
913
911
|
assembly ("memory-safe") {
|
|
914
|
-
mstore(add(p, 0x08),
|
|
915
|
-
mstore(add(p, 0x28), value)
|
|
912
|
+
mstore(add(p, 0x08), value)
|
|
916
913
|
}
|
|
917
914
|
|
|
918
|
-
writeBlock32BytesBytes(writer.dst, i + Sizes.Header +
|
|
915
|
+
writeBlock32BytesBytes(writer.dst, i + Sizes.Header + 32, Keys.Context, account, state, request);
|
|
919
916
|
}
|
|
920
917
|
|
|
921
918
|
/// @notice Append a STATUS form block.
|
|
922
919
|
/// @param writer Destination writer; `i` is advanced by `Sizes.Status`.
|
|
923
|
-
/// @param
|
|
924
|
-
function appendStatus(Writer memory writer,
|
|
925
|
-
appendBlock32(writer, Keys.Status,
|
|
920
|
+
/// @param code Status code to encode.
|
|
921
|
+
function appendStatus(Writer memory writer, uint code) internal pure {
|
|
922
|
+
appendBlock32(writer, Keys.Status, bytes32(code), 32);
|
|
926
923
|
}
|
|
927
924
|
|
|
928
925
|
/// @notice Append a BALANCE block using separate field values.
|
package/core/Host.sol
CHANGED
|
@@ -6,6 +6,7 @@ import {Authorize} from "../commands/admin/Authorize.sol";
|
|
|
6
6
|
import {Unauthorize} from "../commands/admin/Unauthorize.sol";
|
|
7
7
|
import {ExecutePayable} from "../commands/admin/Execute.sol";
|
|
8
8
|
import {IntroductionEvent} from "../events/Introduction.sol";
|
|
9
|
+
import {Ids} from "../utils/Ids.sol";
|
|
9
10
|
|
|
10
11
|
/// @title IHostIntroduction
|
|
11
12
|
/// @notice Interface implemented by hosts that accept introductions from other hosts.
|
|
@@ -35,13 +36,13 @@ abstract contract Host is Authorize, Unauthorize, ExecutePayable, IntroductionEv
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
/// @notice Record a host introduction claim.
|
|
38
|
-
/// @dev
|
|
39
|
+
/// @dev Validates that `peer` matches `msg.sender`; it does not authorize or trust the introduced host.
|
|
39
40
|
/// @param peer Host node ID being introduced.
|
|
40
41
|
/// @param blocknum Block number at which the host was deployed.
|
|
41
42
|
/// @param version Protocol version the host implements.
|
|
42
43
|
/// @param namespace Human-readable namespace string for the host.
|
|
43
44
|
function introduce(uint peer, uint blocknum, uint16 version, string calldata namespace) external {
|
|
44
|
-
emit Introduction(peer, blocknum, version, namespace);
|
|
45
|
+
emit Introduction(Ids.matchHost(peer, msg.sender), blocknum, version, namespace);
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
/// @notice Accept native ETH transfers (e.g. from command value flows).
|
package/docs/Schema.md
CHANGED
|
@@ -58,7 +58,7 @@ Once a child block appears, no more fixed fields may follow.
|
|
|
58
58
|
```txt
|
|
59
59
|
#call { uint target, uint value, #bytes as payload }
|
|
60
60
|
#context { bytes32 account, #bytes as state, #bytes as request }
|
|
61
|
-
#
|
|
61
|
+
#pipe { uint value, #context { bytes32 account, #bytes as state, #bytes as request } }
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
The tail is embedded directly as child block bytes. There is no wrapper around a
|
|
@@ -189,7 +189,7 @@ Common protocol schemas live in `contracts/blocks/Schema.sol`:
|
|
|
189
189
|
#call { uint target, uint value, #bytes as payload }
|
|
190
190
|
#step { uint target, uint value, #bytes as request }
|
|
191
191
|
#context { bytes32 account, #bytes as state, #bytes as request }
|
|
192
|
-
#
|
|
192
|
+
#pipe { uint value, #context { bytes32 account, #bytes as state, #bytes as request } }
|
|
193
193
|
#auth { uint cid, uint deadline, #bytes as proof }
|
|
194
194
|
```
|
|
195
195
|
|
package/events/Access.sol
CHANGED
|
@@ -3,10 +3,10 @@ pragma solidity ^0.8.33;
|
|
|
3
3
|
|
|
4
4
|
import { EventEmitter } from "./Emitter.sol";
|
|
5
5
|
|
|
6
|
-
string constant ABI = "event Access(uint indexed host, uint node, bool trusted)";
|
|
7
|
-
|
|
8
6
|
/// @notice Emitted when a node's authorization status changes on a host.
|
|
9
7
|
abstract contract AccessEvent is EventEmitter {
|
|
8
|
+
string private constant ABI = "event Access(uint indexed host, uint node, bool trusted)";
|
|
9
|
+
|
|
10
10
|
/// @param host Host node ID where the authorization change occurred.
|
|
11
11
|
/// @param node Node ID that was authorized or deauthorized.
|
|
12
12
|
/// @param trusted True if the node was authorized, false if deauthorized.
|
package/events/Admin.sol
CHANGED
|
@@ -3,11 +3,11 @@ pragma solidity ^0.8.33;
|
|
|
3
3
|
|
|
4
4
|
import { EventEmitter } from "./Emitter.sol";
|
|
5
5
|
|
|
6
|
-
string constant ABI =
|
|
7
|
-
"event Admin(uint indexed host, uint id, string name, bytes32 shape, string request, bytes4 state, bytes4 output, bool acceptsValue)";
|
|
8
|
-
|
|
9
6
|
/// @notice Emitted once per admin command during host deployment to publish its request schema and state keys.
|
|
10
7
|
abstract contract AdminEvent is EventEmitter {
|
|
8
|
+
string private constant ABI =
|
|
9
|
+
"event Admin(uint indexed host, uint id, string name, bytes32 shape, string request, bytes4 state, bytes4 output, bool acceptsValue)";
|
|
10
|
+
|
|
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.
|
package/events/Asset.sol
CHANGED
|
@@ -3,14 +3,15 @@ pragma solidity ^0.8.33;
|
|
|
3
3
|
|
|
4
4
|
import { EventEmitter } from "./Emitter.sol";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
/// @notice Emitted when an asset support status is updated on a host.
|
|
7
|
+
abstract contract AssetStatusEvent is EventEmitter {
|
|
8
|
+
string private constant ABI = "event AssetStatus(uint indexed host, bytes32 asset, bytes32 meta, uint status)";
|
|
7
9
|
|
|
8
|
-
/// @
|
|
9
|
-
|
|
10
|
-
/// @param
|
|
11
|
-
/// @param
|
|
12
|
-
|
|
13
|
-
event Asset(uint indexed host, bytes32 name, uint32 prefix);
|
|
10
|
+
/// @param host Host node ID that manages this listing.
|
|
11
|
+
/// @param asset Asset identifier.
|
|
12
|
+
/// @param meta Asset metadata slot.
|
|
13
|
+
/// @param status Asset support status. Zero means unsupported; nonzero means supported.
|
|
14
|
+
event AssetStatus(uint indexed host, bytes32 asset, bytes32 meta, uint status);
|
|
14
15
|
|
|
15
16
|
constructor() {
|
|
16
17
|
emit EventAbi(ABI);
|
package/events/Balance.sol
CHANGED
|
@@ -3,10 +3,10 @@ pragma solidity ^0.8.33;
|
|
|
3
3
|
|
|
4
4
|
import { EventEmitter } from "./Emitter.sol";
|
|
5
5
|
|
|
6
|
-
string constant ABI = "event Balance(bytes32 indexed account, bytes32 asset, bytes32 meta, uint balance, int change, uint access)";
|
|
7
|
-
|
|
8
6
|
/// @notice Emitted when an account balance changes.
|
|
9
7
|
abstract contract BalanceEvent is EventEmitter {
|
|
8
|
+
string private constant ABI = "event Balance(bytes32 indexed account, bytes32 asset, bytes32 meta, uint balance, int change, uint access)";
|
|
9
|
+
|
|
10
10
|
/// @param account Account identifier whose balance changed.
|
|
11
11
|
/// @param asset Asset identifier.
|
|
12
12
|
/// @param meta Asset metadata slot.
|
package/events/Collateral.sol
CHANGED
|
@@ -3,11 +3,11 @@ pragma solidity ^0.8.33;
|
|
|
3
3
|
|
|
4
4
|
import { EventEmitter } from "./Emitter.sol";
|
|
5
5
|
|
|
6
|
-
string constant ABI = "event Collateral(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint access)";
|
|
7
|
-
|
|
8
6
|
/// @notice Emitted when an account's collateral position changes.
|
|
9
7
|
/// Off-chain indexers should query the access command to retrieve the precise collateral details.
|
|
10
8
|
abstract contract CollateralEvent is EventEmitter {
|
|
9
|
+
string private constant ABI = "event Collateral(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint access)";
|
|
10
|
+
|
|
11
11
|
/// @param account Account identifier that holds the collateral.
|
|
12
12
|
/// @param asset Asset identifier of the collateral.
|
|
13
13
|
/// @param meta Asset metadata slot.
|
package/events/Command.sol
CHANGED
|
@@ -3,11 +3,11 @@ pragma solidity ^0.8.33;
|
|
|
3
3
|
|
|
4
4
|
import { EventEmitter } from "./Emitter.sol";
|
|
5
5
|
|
|
6
|
-
string constant ABI =
|
|
7
|
-
"event Command(uint indexed host, uint id, string name, bytes32 shape, string request, bytes4 state, bytes4 output, bool acceptsValue)";
|
|
8
|
-
|
|
9
6
|
/// @notice Emitted once per command during host deployment to publish its request schema and state keys.
|
|
10
7
|
abstract contract CommandEvent is EventEmitter {
|
|
8
|
+
string private constant ABI =
|
|
9
|
+
"event Command(uint indexed host, uint id, string name, bytes32 shape, string request, bytes4 state, bytes4 output, bool acceptsValue)";
|
|
10
|
+
|
|
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.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
/// @notice Standard context codes for generic asset activity events.
|
|
5
|
+
library Contexts {
|
|
6
|
+
uint constant Deposit = 1;
|
|
7
|
+
uint constant Withdraw = 2;
|
|
8
|
+
uint constant Fee = 3;
|
|
9
|
+
uint constant Mint = 4;
|
|
10
|
+
uint constant Burn = 5;
|
|
11
|
+
uint constant Swap = 6;
|
|
12
|
+
}
|
package/events/Debt.sol
CHANGED
|
@@ -3,11 +3,11 @@ pragma solidity ^0.8.33;
|
|
|
3
3
|
|
|
4
4
|
import { EventEmitter } from "./Emitter.sol";
|
|
5
5
|
|
|
6
|
-
string constant ABI = "event Debt(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint mode, uint access)";
|
|
7
|
-
|
|
8
6
|
/// @notice Emitted when an account's debt position changes.
|
|
9
7
|
/// Off-chain indexers should query the access command to retrieve precise debt details.
|
|
10
8
|
abstract contract DebtEvent is EventEmitter {
|
|
9
|
+
string private constant ABI = "event Debt(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint mode, uint access)";
|
|
10
|
+
|
|
11
11
|
/// @param account Account identifier that holds the debt.
|
|
12
12
|
/// @param asset Asset identifier of the debt.
|
|
13
13
|
/// @param meta Asset metadata slot.
|
package/events/Introduction.sol
CHANGED
|
@@ -3,10 +3,10 @@ pragma solidity ^0.8.33;
|
|
|
3
3
|
|
|
4
4
|
import { EventEmitter } from "./Emitter.sol";
|
|
5
5
|
|
|
6
|
-
string constant ABI = "event Introduction(uint indexed host, uint blocknum, uint16 version, string namespace)";
|
|
7
|
-
|
|
8
6
|
/// @notice Emitted when a host introduces itself to another host.
|
|
9
7
|
abstract contract IntroductionEvent is EventEmitter {
|
|
8
|
+
string private constant ABI = "event Introduction(uint indexed host, uint blocknum, uint16 version, string namespace)";
|
|
9
|
+
|
|
10
10
|
/// @param host Host node ID of the introducing contract.
|
|
11
11
|
/// @param blocknum Block number at which the host was deployed.
|
|
12
12
|
/// @param version Protocol version the host implements.
|
package/events/Peer.sol
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
string constant ABI =
|
|
7
|
-
"event Peer(uint indexed host, uint id, string name, bytes32 shape, string request, string response, bool acceptsValue)";
|
|
4
|
+
import {EventEmitter} from "./Emitter.sol";
|
|
8
5
|
|
|
9
6
|
/// @notice Emitted once per peer during host deployment to publish its request and response schemas.
|
|
10
7
|
abstract contract PeerEvent is EventEmitter {
|
|
8
|
+
string private constant ABI =
|
|
9
|
+
"event Peer(uint indexed host, uint id, string name, bytes32 shape, string request, string response, bool acceptsValue)";
|
|
10
|
+
|
|
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.
|
|
@@ -15,12 +15,17 @@ abstract contract PeerEvent is EventEmitter {
|
|
|
15
15
|
/// @param request Schema DSL string describing the peer request shape.
|
|
16
16
|
/// @param response Schema DSL string describing the peer response shape.
|
|
17
17
|
/// @param acceptsValue Whether the peer entrypoint accepts nonzero `msg.value`.
|
|
18
|
-
event Peer(
|
|
18
|
+
event Peer(
|
|
19
|
+
uint indexed host,
|
|
20
|
+
uint id,
|
|
21
|
+
string name,
|
|
22
|
+
bytes32 shape,
|
|
23
|
+
string request,
|
|
24
|
+
string response,
|
|
25
|
+
bool acceptsValue
|
|
26
|
+
);
|
|
19
27
|
|
|
20
28
|
constructor() {
|
|
21
29
|
emit EventAbi(ABI);
|
|
22
30
|
}
|
|
23
31
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
package/events/Position.sol
CHANGED
|
@@ -3,17 +3,17 @@ pragma solidity ^0.8.33;
|
|
|
3
3
|
|
|
4
4
|
import {EventEmitter} from "./Emitter.sol";
|
|
5
5
|
|
|
6
|
-
string constant ABI = "event AssetPosition(bytes32 indexed account, bytes32 asset, bytes32 meta, uint value, uint queryId)";
|
|
7
|
-
|
|
8
6
|
/// @notice Emitted when the reported value of an asset-backed position changes or is observed.
|
|
9
7
|
/// A value of 0 should be interpreted as a closed position.
|
|
10
|
-
abstract contract
|
|
8
|
+
abstract contract PositionEvent is EventEmitter {
|
|
9
|
+
string private constant ABI = "event Position(bytes32 indexed account, bytes32 asset, bytes32 meta, uint value, uint queryId)";
|
|
10
|
+
|
|
11
11
|
/// @param account Account identifier that owns or is associated with the position.
|
|
12
12
|
/// @param asset Asset identifier for the asset class.
|
|
13
13
|
/// @param meta Asset metadata slot carrying the position context.
|
|
14
14
|
/// @param value Context-specific position value; 0 indicates a closed position.
|
|
15
15
|
/// @param queryId Query ID associated with the position lookup or reporting context.
|
|
16
|
-
event
|
|
16
|
+
event Position(bytes32 indexed account, bytes32 asset, bytes32 meta, uint value, uint queryId);
|
|
17
17
|
|
|
18
18
|
constructor() {
|
|
19
19
|
emit EventAbi(ABI);
|
package/events/Query.sol
CHANGED
|
@@ -3,10 +3,10 @@ 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, bytes32 shape, string request, string response)";
|
|
7
|
-
|
|
8
6
|
/// @notice Emitted once per query during host deployment to publish its request and response schemas.
|
|
9
7
|
abstract contract QueryEvent is EventEmitter {
|
|
8
|
+
string private constant ABI = "event Query(uint indexed host, uint id, string name, bytes32 shape, string request, string response)";
|
|
9
|
+
|
|
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.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import { EventEmitter } from "./Emitter.sol";
|
|
5
|
+
|
|
6
|
+
/// @notice Emitted when an account receives an asset in a protocol operation.
|
|
7
|
+
abstract contract ReceivedEvent is EventEmitter {
|
|
8
|
+
string private constant ABI = "event Received(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint context)";
|
|
9
|
+
|
|
10
|
+
/// @param account Account identifier that received the asset.
|
|
11
|
+
/// @param asset Asset identifier.
|
|
12
|
+
/// @param meta Asset metadata slot.
|
|
13
|
+
/// @param amount Amount received.
|
|
14
|
+
/// @param context Operation context identifier associated with this receipt.
|
|
15
|
+
event Received(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint context);
|
|
16
|
+
|
|
17
|
+
constructor() {
|
|
18
|
+
emit EventAbi(ABI);
|
|
19
|
+
}
|
|
20
|
+
}
|
package/events/Rooted.sol
CHANGED
|
@@ -3,10 +3,10 @@ pragma solidity ^0.8.33;
|
|
|
3
3
|
|
|
4
4
|
import { EventEmitter } from "./Emitter.sol";
|
|
5
5
|
|
|
6
|
-
string constant ABI = "event Rooted(bytes32 indexed account, uint deadline, uint value)";
|
|
7
|
-
|
|
8
6
|
/// @notice Emitted for root-level protocol actions (e.g. governance or protocol-wide operations).
|
|
9
7
|
abstract contract RootedEvent is EventEmitter {
|
|
8
|
+
string private constant ABI = "event Rooted(bytes32 indexed account, uint deadline, uint value)";
|
|
9
|
+
|
|
10
10
|
/// @param account Account identifier associated with the action.
|
|
11
11
|
/// @param deadline Expiry timestamp of the action.
|
|
12
12
|
/// @param value Native value associated with the action.
|
package/events/Spent.sol
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import { EventEmitter } from "./Emitter.sol";
|
|
5
|
+
|
|
6
|
+
/// @notice Emitted when an account spends an asset in a protocol operation.
|
|
7
|
+
abstract contract SpentEvent is EventEmitter {
|
|
8
|
+
string private constant ABI = "event Spent(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint context)";
|
|
9
|
+
|
|
10
|
+
/// @param account Account identifier that spent the asset.
|
|
11
|
+
/// @param asset Asset identifier.
|
|
12
|
+
/// @param meta Asset metadata slot.
|
|
13
|
+
/// @param amount Amount spent.
|
|
14
|
+
/// @param context Operation context identifier associated with this spend.
|
|
15
|
+
event Spent(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint context);
|
|
16
|
+
|
|
17
|
+
constructor() {
|
|
18
|
+
emit EventAbi(ABI);
|
|
19
|
+
}
|
|
20
|
+
}
|
package/package.json
CHANGED
package/peer/Pipe.sol
CHANGED
|
@@ -9,26 +9,26 @@ import {Budget} from "../utils/Value.sol";
|
|
|
9
9
|
using Cursors for Cur;
|
|
10
10
|
|
|
11
11
|
/// @title PeerPipePayable
|
|
12
|
-
/// @notice Peer that consumes
|
|
13
|
-
/// Each
|
|
14
|
-
///
|
|
12
|
+
/// @notice Peer that consumes PIPE blocks and executes each context request as a STEP stream.
|
|
13
|
+
/// Each PIPE block carries a value budget plus a CONTEXT block; the nested
|
|
14
|
+
/// context request is passed to the shared pipeline as the step stream.
|
|
15
15
|
abstract contract PeerPipePayable is PeerBase, Pipeline {
|
|
16
16
|
string private constant NAME = "peerPipePayable";
|
|
17
17
|
uint internal immutable peerPipePayableId = peerId(NAME);
|
|
18
18
|
|
|
19
19
|
constructor() {
|
|
20
|
-
emit Peer(host, peerPipePayableId, NAME, "1:0", Schemas.
|
|
20
|
+
emit Peer(host, peerPipePayableId, NAME, "1:0", Schemas.Pipe, "", true);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
/// @notice Execute peer-supplied
|
|
24
|
-
/// @dev Each
|
|
25
|
-
/// `msg.value` not assigned to a
|
|
23
|
+
/// @notice Execute peer-supplied pipes through the shared payable pipe.
|
|
24
|
+
/// @dev Each pipe receives its own explicit value sub-budget. Any top-level
|
|
25
|
+
/// `msg.value` not assigned to a pipe remains on this host.
|
|
26
26
|
function peerPipePayable(bytes calldata request) external payable onlyPeer returns (bytes memory) {
|
|
27
27
|
(Cur memory input, ) = cursor(request, 1);
|
|
28
28
|
Budget memory budget = valueBudget();
|
|
29
29
|
|
|
30
30
|
while (input.i < input.bound) {
|
|
31
|
-
(
|
|
31
|
+
(uint value, bytes32 account, bytes calldata state, bytes calldata steps) = input.unpackPipe();
|
|
32
32
|
pipe(account, state, steps, allocateValue(budget, value));
|
|
33
33
|
}
|
|
34
34
|
|
package/queries/Assets.sol
CHANGED
|
@@ -8,38 +8,38 @@ import {QueryBase} from "./Base.sol";
|
|
|
8
8
|
using Cursors for Cur;
|
|
9
9
|
using Writers for Writer;
|
|
10
10
|
|
|
11
|
-
abstract contract
|
|
12
|
-
/// @notice Resolve
|
|
13
|
-
/// Concrete implementations define the
|
|
11
|
+
abstract contract AssetStatusHook {
|
|
12
|
+
/// @notice Resolve support status for one asset tuple.
|
|
13
|
+
/// Concrete implementations define the support policy and optional context codes.
|
|
14
14
|
/// @param asset Requested asset identifier.
|
|
15
15
|
/// @param meta Requested asset metadata slot.
|
|
16
|
-
/// @return
|
|
17
|
-
function
|
|
16
|
+
/// @return status Asset support status. Zero means unsupported; nonzero means supported.
|
|
17
|
+
function assetStatus(bytes32 asset, bytes32 meta) internal view virtual returns (uint status);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
/// @title
|
|
21
|
-
/// @notice Rootzero query that checks
|
|
20
|
+
/// @title AssetStatus
|
|
21
|
+
/// @notice Rootzero query that checks support status for one or more `(asset, meta)` tuples.
|
|
22
22
|
/// The request is a run of `ASSET` blocks.
|
|
23
23
|
/// The response returns one `STATUS` form block per query entry, preserving request order.
|
|
24
|
-
abstract contract
|
|
25
|
-
string private constant NAME = "
|
|
26
|
-
uint public immutable
|
|
24
|
+
abstract contract AssetStatus is QueryBase, AssetStatusHook {
|
|
25
|
+
string private constant NAME = "assetStatus";
|
|
26
|
+
uint public immutable assetStatusId = queryId(NAME);
|
|
27
27
|
|
|
28
28
|
constructor() {
|
|
29
|
-
emit Query(host,
|
|
29
|
+
emit Query(host, assetStatusId, NAME, "1:1", Schemas.Asset, Forms.Status);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
/// @notice Resolve
|
|
32
|
+
/// @notice Resolve asset support status for a run of requested `(asset, meta)` tuples.
|
|
33
33
|
/// @param request Block-stream request consisting of `#asset { bytes32 asset, bytes32 meta }` blocks.
|
|
34
|
-
/// @return Block-stream response containing one `#status {
|
|
35
|
-
function
|
|
34
|
+
/// @return Block-stream response containing one `#status { uint code }` per asset block.
|
|
35
|
+
function assetStatus(bytes calldata request) external view returns (bytes memory) {
|
|
36
36
|
(Cur memory query, uint groups) = cursor(request, 1);
|
|
37
37
|
Writer memory response = Writers.allocStatuses(groups);
|
|
38
38
|
|
|
39
39
|
while (query.i < query.bound) {
|
|
40
40
|
(bytes32 asset, bytes32 meta) = query.unpackAsset();
|
|
41
|
-
|
|
42
|
-
response.appendStatus(
|
|
41
|
+
uint status = assetStatus(asset, meta);
|
|
42
|
+
response.appendStatus(status);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
query.close();
|
package/utils/Assets.sol
CHANGED
|
@@ -17,6 +17,8 @@ import {matchesBase, toLocalBase} from "./Utils.sol";
|
|
|
17
17
|
library Assets {
|
|
18
18
|
/// @dev Thrown when an asset ID does not match the expected type or chain.
|
|
19
19
|
error InvalidAsset();
|
|
20
|
+
/// @dev Thrown when an asset is not authorized for the requested operation.
|
|
21
|
+
error UnauthorizedAsset();
|
|
20
22
|
|
|
21
23
|
/// @dev Full 4-byte type prefix for the native value asset.
|
|
22
24
|
uint32 constant Value = (uint32(Layout.Evm32) << 16) | (uint32(Layout.Asset) << 8) | uint32(Layout.Value);
|
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
|
-
|