@rootzero/contracts 0.9.7 → 0.9.9
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/Core.sol +3 -3
- package/Endpoints.sol +1 -1
- package/Events.sol +4 -3
- package/Utils.sol +2 -1
- package/blocks/Cursors.sol +117 -155
- package/blocks/Keys.sol +4 -6
- package/blocks/Schema.sol +14 -8
- package/commands/Burn.sol +4 -4
- package/commands/Credit.sol +6 -9
- package/commands/Debit.sol +4 -4
- package/commands/Deposit.sol +8 -8
- package/commands/Payout.sol +45 -0
- package/commands/Provision.sol +8 -8
- package/commands/Withdraw.sol +7 -9
- package/commands/admin/AllowAssets.sol +4 -4
- package/commands/admin/Allowance.sol +4 -4
- package/commands/admin/Appoint.sol +4 -4
- package/commands/admin/Authorize.sol +4 -4
- package/commands/admin/DenyAssets.sol +4 -4
- package/commands/admin/Destroy.sol +2 -2
- package/commands/admin/Dismiss.sol +4 -4
- package/commands/admin/Execute.sol +4 -4
- package/commands/admin/Init.sol +2 -2
- package/commands/admin/Unauthorize.sol +4 -4
- package/core/Access.sol +2 -2
- package/core/Host.sol +4 -2
- package/core/Pipeline.sol +3 -3
- package/core/Runtime.sol +14 -0
- package/core/Types.sol +1 -1
- package/docs/Schema.md +0 -1
- package/events/Admin.sol +10 -7
- package/events/Command.sol +10 -7
- package/events/Locked.sol +21 -0
- package/events/Peer.sol +5 -5
- package/events/Position.sol +4 -2
- package/events/Query.sol +2 -4
- package/events/Received.sol +4 -3
- package/events/Spent.sol +4 -3
- package/events/Transfer.sol +22 -0
- package/events/Unlocked.sol +21 -0
- package/guards/Revoke.sol +3 -3
- package/package.json +1 -1
- package/peer/AllowAssets.sol +3 -3
- package/peer/Allowance.sol +3 -3
- package/peer/BalancePull.sol +3 -3
- package/peer/DenyAssets.sol +3 -3
- package/peer/Pipe.sol +3 -3
- package/peer/Settle.sol +11 -8
- package/queries/Assets.sol +3 -3
- package/queries/Balances.sol +3 -3
- package/queries/Base.sol +2 -2
- package/queries/Positions.sol +3 -3
- package/utils/Accounts.sol +8 -0
- package/utils/Actions.sol +18 -0
- package/commands/Transfer.sol +0 -54
- package/core/Context.sol +0 -47
- package/events/Collateral.sol +0 -24
- package/events/Contexts.sol +0 -12
- package/events/Debt.sol +0 -25
package/events/Peer.sol
CHANGED
|
@@ -6,15 +6,15 @@ import {EventEmitter} from "./Emitter.sol";
|
|
|
6
6
|
/// @notice Emitted once per peer during host deployment to publish its request and response schemas.
|
|
7
7
|
abstract contract PeerEvent is EventEmitter {
|
|
8
8
|
string private constant ABI =
|
|
9
|
-
"event Peer(uint indexed host, uint id, string name, bytes32 shape, string request, string response, bool
|
|
9
|
+
"event Peer(uint indexed host, uint id, string name, bytes32 shape, string request, string response, bool funded)";
|
|
10
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.
|
|
14
|
-
/// @param shape
|
|
15
|
-
/// @param request Schema DSL string describing the
|
|
14
|
+
/// @param shape Per-operation block counts encoded as `request:response`.
|
|
15
|
+
/// @param request Schema DSL string describing the input request run, or empty if none.
|
|
16
16
|
/// @param response Schema DSL string describing the peer response shape.
|
|
17
|
-
/// @param
|
|
17
|
+
/// @param funded Whether the peer entrypoint accepts nonzero `msg.value`.
|
|
18
18
|
event Peer(
|
|
19
19
|
uint indexed host,
|
|
20
20
|
uint id,
|
|
@@ -22,7 +22,7 @@ abstract contract PeerEvent is EventEmitter {
|
|
|
22
22
|
bytes32 shape,
|
|
23
23
|
string request,
|
|
24
24
|
string response,
|
|
25
|
-
bool
|
|
25
|
+
bool funded
|
|
26
26
|
);
|
|
27
27
|
|
|
28
28
|
constructor() {
|
package/events/Position.sol
CHANGED
|
@@ -6,14 +6,16 @@ import {EventEmitter} from "./Emitter.sol";
|
|
|
6
6
|
/// @notice Emitted when the reported value of an asset-backed position changes or is observed.
|
|
7
7
|
/// A value of 0 should be interpreted as a closed position.
|
|
8
8
|
abstract contract PositionEvent is EventEmitter {
|
|
9
|
-
string private constant ABI = "event Position(bytes32 indexed account, bytes32 asset, bytes32 meta, uint value, uint queryId)";
|
|
9
|
+
string private constant ABI = "event Position(bytes32 indexed account, bytes32 asset, bytes32 meta, uint value, uint32 action, uint context, uint queryId)";
|
|
10
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
|
+
/// @param action Primary operation hint from `Actions`.
|
|
16
|
+
/// @param context Reserved context value for future use.
|
|
15
17
|
/// @param queryId Query ID associated with the position lookup or reporting context.
|
|
16
|
-
event Position(bytes32 indexed account, bytes32 asset, bytes32 meta, uint value, uint queryId);
|
|
18
|
+
event Position(bytes32 indexed account, bytes32 asset, bytes32 meta, uint value, uint32 action, uint context, uint queryId);
|
|
17
19
|
|
|
18
20
|
constructor() {
|
|
19
21
|
emit EventAbi(ABI);
|
package/events/Query.sol
CHANGED
|
@@ -10,10 +10,8 @@ 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
|
|
14
|
-
///
|
|
15
|
-
/// from the counts.
|
|
16
|
-
/// @param request Schema DSL string describing the query request shape.
|
|
13
|
+
/// @param shape Per-operation block counts encoded as `request:response`.
|
|
14
|
+
/// @param request Schema DSL string describing the input request run, or empty if none.
|
|
17
15
|
/// @param response Schema DSL string describing the query response shape.
|
|
18
16
|
event Query(uint indexed host, uint id, string name, bytes32 shape, string request, string response);
|
|
19
17
|
|
package/events/Received.sol
CHANGED
|
@@ -5,14 +5,15 @@ import { EventEmitter } from "./Emitter.sol";
|
|
|
5
5
|
|
|
6
6
|
/// @notice Emitted when an account receives an asset in a protocol operation.
|
|
7
7
|
abstract contract ReceivedEvent is EventEmitter {
|
|
8
|
-
string private constant ABI = "event Received(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint context)";
|
|
8
|
+
string private constant ABI = "event Received(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint32 action, uint context)";
|
|
9
9
|
|
|
10
10
|
/// @param account Account identifier that received the asset.
|
|
11
11
|
/// @param asset Asset identifier.
|
|
12
12
|
/// @param meta Asset metadata slot.
|
|
13
13
|
/// @param amount Amount received.
|
|
14
|
-
/// @param
|
|
15
|
-
|
|
14
|
+
/// @param action Primary operation hint from `Actions`.
|
|
15
|
+
/// @param context Reserved context value for future use.
|
|
16
|
+
event Received(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint32 action, uint context);
|
|
16
17
|
|
|
17
18
|
constructor() {
|
|
18
19
|
emit EventAbi(ABI);
|
package/events/Spent.sol
CHANGED
|
@@ -5,14 +5,15 @@ import { EventEmitter } from "./Emitter.sol";
|
|
|
5
5
|
|
|
6
6
|
/// @notice Emitted when an account spends an asset in a protocol operation.
|
|
7
7
|
abstract contract SpentEvent is EventEmitter {
|
|
8
|
-
string private constant ABI = "event Spent(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint context)";
|
|
8
|
+
string private constant ABI = "event Spent(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint32 action, uint context)";
|
|
9
9
|
|
|
10
10
|
/// @param account Account identifier that spent the asset.
|
|
11
11
|
/// @param asset Asset identifier.
|
|
12
12
|
/// @param meta Asset metadata slot.
|
|
13
13
|
/// @param amount Amount spent.
|
|
14
|
-
/// @param
|
|
15
|
-
|
|
14
|
+
/// @param action Primary operation hint from `Actions`.
|
|
15
|
+
/// @param context Reserved context value for future use.
|
|
16
|
+
event Spent(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint32 action, uint context);
|
|
16
17
|
|
|
17
18
|
constructor() {
|
|
18
19
|
emit EventAbi(ABI);
|
|
@@ -0,0 +1,22 @@
|
|
|
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 asset moves from one account to another.
|
|
7
|
+
abstract contract TransferEvent is EventEmitter {
|
|
8
|
+
string private constant ABI = "event Transfer(bytes32 indexed from, bytes32 to, bytes32 asset, bytes32 meta, uint amount, uint32 action, uint context)";
|
|
9
|
+
|
|
10
|
+
/// @param account Source account identifier.
|
|
11
|
+
/// @param to Destination account identifier.
|
|
12
|
+
/// @param asset Asset identifier.
|
|
13
|
+
/// @param meta Asset metadata slot.
|
|
14
|
+
/// @param amount Amount transferred.
|
|
15
|
+
/// @param action Primary operation hint from `Actions`.
|
|
16
|
+
/// @param context Reserved context value for future use.
|
|
17
|
+
event Transfer(bytes32 indexed account, bytes32 to, bytes32 asset, bytes32 meta, uint amount, uint32 action, uint context);
|
|
18
|
+
|
|
19
|
+
constructor() {
|
|
20
|
+
emit EventAbi(ABI);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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 unlocks an asset in a protocol operation.
|
|
7
|
+
abstract contract UnlockedEvent is EventEmitter {
|
|
8
|
+
string private constant ABI = "event Unlocked(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint32 action, uint context)";
|
|
9
|
+
|
|
10
|
+
/// @param account Account identifier that unlocked the asset.
|
|
11
|
+
/// @param asset Asset identifier.
|
|
12
|
+
/// @param meta Asset metadata slot.
|
|
13
|
+
/// @param amount Amount unlocked.
|
|
14
|
+
/// @param action Primary operation hint from `Actions`.
|
|
15
|
+
/// @param context Reserved context value for future use.
|
|
16
|
+
event Unlocked(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint32 action, uint context);
|
|
17
|
+
|
|
18
|
+
constructor() {
|
|
19
|
+
emit EventAbi(ABI);
|
|
20
|
+
}
|
|
21
|
+
}
|
package/guards/Revoke.sol
CHANGED
|
@@ -19,13 +19,13 @@ abstract contract Revoke is GuardBase {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
function revoke(bytes calldata request) external onlyGuardian {
|
|
22
|
-
(Cur memory input, ) =
|
|
22
|
+
(Cur memory input, ) = Cursors.first(request, 1);
|
|
23
23
|
|
|
24
|
-
while (input.i < input.
|
|
24
|
+
while (input.i < input.len) {
|
|
25
25
|
uint node = input.unpackNode();
|
|
26
26
|
setNode(node, false);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
input.
|
|
29
|
+
input.complete();
|
|
30
30
|
}
|
|
31
31
|
}
|
package/package.json
CHANGED
package/peer/AllowAssets.sol
CHANGED
|
@@ -20,14 +20,14 @@ abstract contract PeerAllowAssets is PeerBase, AllowAssetsHook {
|
|
|
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, ) = Cursors.first(request, 1);
|
|
24
24
|
|
|
25
|
-
while (assets.i < assets.
|
|
25
|
+
while (assets.i < assets.len) {
|
|
26
26
|
(bytes32 asset, bytes32 meta) = assets.unpackAsset();
|
|
27
27
|
allowAsset(asset, meta);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
assets.
|
|
30
|
+
assets.complete();
|
|
31
31
|
return "";
|
|
32
32
|
}
|
|
33
33
|
}
|
package/peer/Allowance.sol
CHANGED
|
@@ -21,15 +21,15 @@ abstract contract PeerAllowance is PeerBase, AllowanceHook {
|
|
|
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, ) = Cursors.first(request, 1);
|
|
25
25
|
uint peer = caller();
|
|
26
26
|
|
|
27
|
-
while (amounts.i < amounts.
|
|
27
|
+
while (amounts.i < amounts.len) {
|
|
28
28
|
(bytes32 asset, bytes32 meta, uint amount) = amounts.unpackAmount();
|
|
29
29
|
allowance(peer, asset, meta, amount);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
amounts.
|
|
32
|
+
amounts.complete();
|
|
33
33
|
return "";
|
|
34
34
|
}
|
|
35
35
|
}
|
package/peer/BalancePull.sol
CHANGED
|
@@ -29,15 +29,15 @@ abstract contract PeerBalancePull is PeerBase, BalancePullHook {
|
|
|
29
29
|
|
|
30
30
|
/// @notice Execute the balance-pull peer call.
|
|
31
31
|
function peerBalancePull(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
32
|
-
(Cur memory input, ) =
|
|
32
|
+
(Cur memory input, ) = Cursors.first(request, 1);
|
|
33
33
|
uint peer = caller();
|
|
34
34
|
|
|
35
|
-
while (input.i < input.
|
|
35
|
+
while (input.i < input.len) {
|
|
36
36
|
(bytes32 asset, bytes32 meta, uint amount) = input.unpackBalance();
|
|
37
37
|
balancePull(peer, asset, meta, amount);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
input.
|
|
40
|
+
input.complete();
|
|
41
41
|
return "";
|
|
42
42
|
}
|
|
43
43
|
}
|
package/peer/DenyAssets.sol
CHANGED
|
@@ -20,14 +20,14 @@ abstract contract PeerDenyAssets is PeerBase, DenyAssetsHook {
|
|
|
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, ) = Cursors.first(request, 1);
|
|
24
24
|
|
|
25
|
-
while (assets.i < assets.
|
|
25
|
+
while (assets.i < assets.len) {
|
|
26
26
|
(bytes32 asset, bytes32 meta) = assets.unpackAsset();
|
|
27
27
|
denyAsset(asset, meta);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
assets.
|
|
30
|
+
assets.complete();
|
|
31
31
|
return "";
|
|
32
32
|
}
|
|
33
33
|
}
|
package/peer/Pipe.sol
CHANGED
|
@@ -24,15 +24,15 @@ abstract contract PeerPipePayable is PeerBase, Pipeline {
|
|
|
24
24
|
/// @dev Each pipe receives its own explicit value sub-budget. Any top-level
|
|
25
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
|
-
(Cur memory input, ) =
|
|
27
|
+
(Cur memory input, ) = Cursors.first(request, 1);
|
|
28
28
|
Budget memory budget = valueBudget();
|
|
29
29
|
|
|
30
|
-
while (input.i < input.
|
|
30
|
+
while (input.i < input.len) {
|
|
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
|
|
|
35
|
-
input.
|
|
35
|
+
input.complete();
|
|
36
36
|
return "";
|
|
37
37
|
}
|
|
38
38
|
}
|
package/peer/Settle.sol
CHANGED
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
4
|
import { PeerBase } from "./Base.sol";
|
|
5
|
-
import {
|
|
5
|
+
import { CreditAccountHook } from "../commands/Credit.sol";
|
|
6
|
+
import { DebitAccountHook } from "../commands/Debit.sol";
|
|
6
7
|
import { Cursors, Cur, Schemas } from "../Cursors.sol";
|
|
7
8
|
|
|
8
9
|
using Cursors for Cur;
|
|
9
10
|
|
|
10
11
|
/// @title PeerSettle
|
|
11
|
-
/// @notice Peer that consumes peer-supplied TRANSACTION blocks through
|
|
12
|
-
/// Each TRANSACTION block
|
|
13
|
-
abstract contract PeerSettle is PeerBase,
|
|
12
|
+
/// @notice Peer that consumes peer-supplied TRANSACTION blocks through debit and credit hooks.
|
|
13
|
+
/// Each TRANSACTION block calls `debitAccount` for `from` and `creditAccount` for `to`.
|
|
14
|
+
abstract contract PeerSettle is PeerBase, DebitAccountHook, CreditAccountHook {
|
|
14
15
|
string private constant NAME = "peerSettle";
|
|
15
16
|
uint internal immutable peerSettleId = peerId(NAME);
|
|
16
17
|
|
|
@@ -20,13 +21,15 @@ abstract contract PeerSettle is PeerBase, TransferHook {
|
|
|
20
21
|
|
|
21
22
|
/// @notice Execute the peer-settle call.
|
|
22
23
|
function peerSettle(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
23
|
-
(Cur memory state, ) =
|
|
24
|
+
(Cur memory state, ) = Cursors.first(request, 1);
|
|
24
25
|
|
|
25
|
-
while (state.i < state.
|
|
26
|
-
|
|
26
|
+
while (state.i < state.len) {
|
|
27
|
+
(bytes32 from, bytes32 to, bytes32 asset, bytes32 meta, uint amount) = state.unpackTransaction();
|
|
28
|
+
if (from != 0) debitAccount(from, asset, meta, amount);
|
|
29
|
+
if (to != 0) creditAccount(to, asset, meta, amount);
|
|
27
30
|
}
|
|
28
31
|
|
|
29
|
-
state.
|
|
32
|
+
state.complete();
|
|
30
33
|
return "";
|
|
31
34
|
}
|
|
32
35
|
}
|
package/queries/Assets.sol
CHANGED
|
@@ -33,16 +33,16 @@ abstract contract AssetStatus is QueryBase, AssetStatusHook {
|
|
|
33
33
|
/// @param request Block-stream request consisting of `#asset { bytes32 asset, bytes32 meta }` blocks.
|
|
34
34
|
/// @return Block-stream response containing one `#status { uint code }` per asset block.
|
|
35
35
|
function assetStatus(bytes calldata request) external view returns (bytes memory) {
|
|
36
|
-
(Cur memory query, uint groups) =
|
|
36
|
+
(Cur memory query, uint groups) = Cursors.first(request, 1);
|
|
37
37
|
Writer memory response = Writers.allocStatuses(groups);
|
|
38
38
|
|
|
39
|
-
while (query.i < query.
|
|
39
|
+
while (query.i < query.len) {
|
|
40
40
|
(bytes32 asset, bytes32 meta) = query.unpackAsset();
|
|
41
41
|
uint status = assetStatus(asset, meta);
|
|
42
42
|
response.appendStatus(status);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
query.
|
|
45
|
+
query.complete();
|
|
46
46
|
return response.finish();
|
|
47
47
|
}
|
|
48
48
|
}
|
package/queries/Balances.sol
CHANGED
|
@@ -33,16 +33,16 @@ abstract contract GetBalances is QueryBase, GetBalancesHook {
|
|
|
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 groups) =
|
|
36
|
+
(Cur memory query, uint groups) = Cursors.first(request, 1);
|
|
37
37
|
Writer memory response = Writers.allocAccountAmounts(groups);
|
|
38
38
|
|
|
39
|
-
while (query.i < query.
|
|
39
|
+
while (query.i < query.len) {
|
|
40
40
|
(bytes32 account, bytes32 asset, bytes32 meta) = query.unpackAccountAsset();
|
|
41
41
|
uint amount = getBalance(account, asset, meta);
|
|
42
42
|
response.appendAccountAmount(account, asset, meta, amount);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
query.
|
|
45
|
+
query.complete();
|
|
46
46
|
return response.finish();
|
|
47
47
|
}
|
|
48
48
|
}
|
package/queries/Base.sol
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { Runtime } from "../core/Runtime.sol";
|
|
5
5
|
import { QueryEvent } from "../events/Query.sol";
|
|
6
6
|
import { Ids, Selectors } from "../utils/Ids.sol";
|
|
7
7
|
|
|
@@ -20,7 +20,7 @@ function encodeQueryCall(uint target, bytes calldata request) pure returns (byte
|
|
|
20
20
|
/// @notice Abstract base for rootzero query contracts.
|
|
21
21
|
/// Queries are view-only entry points that consume a block-stream request and
|
|
22
22
|
/// return a block-stream response.
|
|
23
|
-
abstract contract QueryBase is
|
|
23
|
+
abstract contract QueryBase is Runtime, QueryEvent {
|
|
24
24
|
|
|
25
25
|
/// @notice Derive the deterministic node ID for a named query on this contract.
|
|
26
26
|
/// The ID encodes the ABI selector of `name(bytes)` and `address(this)`,
|
package/queries/Positions.sol
CHANGED
|
@@ -42,15 +42,15 @@ abstract contract GetPosition is QueryBase, GetPositionHook {
|
|
|
42
42
|
/// @param request Block-stream request consisting of `accountAsset(account, asset, meta)*`.
|
|
43
43
|
/// @return Block-stream response containing one output-schema block per position block.
|
|
44
44
|
function getPosition(bytes calldata request) external view returns (bytes memory) {
|
|
45
|
-
(Cur memory query, uint groups) =
|
|
45
|
+
(Cur memory query, uint groups) = Cursors.first(request, 1);
|
|
46
46
|
Writer memory response = Writers.allocAny(groups);
|
|
47
47
|
|
|
48
|
-
while (query.i < query.
|
|
48
|
+
while (query.i < query.len) {
|
|
49
49
|
(bytes32 account, bytes32 asset, bytes32 meta) = query.unpackAccountAsset();
|
|
50
50
|
appendPosition(account, asset, meta, response);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
query.
|
|
53
|
+
query.complete();
|
|
54
54
|
return response.finish();
|
|
55
55
|
}
|
|
56
56
|
}
|
package/utils/Accounts.sol
CHANGED
|
@@ -57,6 +57,14 @@ library Accounts {
|
|
|
57
57
|
return prefix(account) == Keccak;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
/// @notice Assert that `input` is an account and return it unchanged.
|
|
61
|
+
/// @param input Account identifier to validate.
|
|
62
|
+
/// @return account The same `input` if it is an account.
|
|
63
|
+
function any(bytes32 input) internal pure returns (bytes32 account) {
|
|
64
|
+
if (!isAccount(input)) revert InvalidAccount();
|
|
65
|
+
return input;
|
|
66
|
+
}
|
|
67
|
+
|
|
60
68
|
/// @notice Assert that `input` is an admin account and return it unchanged.
|
|
61
69
|
/// @param input Account identifier to validate.
|
|
62
70
|
/// @return account The same `input` if it is an admin account.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
library Actions {
|
|
5
|
+
uint32 constant None = 0;
|
|
6
|
+
uint32 constant Transfer = 1;
|
|
7
|
+
uint32 constant Payout = 2;
|
|
8
|
+
uint32 constant Settle = 3;
|
|
9
|
+
uint32 constant Deposit = 4;
|
|
10
|
+
uint32 constant Withdraw = 5;
|
|
11
|
+
uint32 constant Fee = 6;
|
|
12
|
+
uint32 constant Mint = 7;
|
|
13
|
+
uint32 constant Burn = 8;
|
|
14
|
+
uint32 constant Swap = 9;
|
|
15
|
+
uint32 constant Borrow = 10;
|
|
16
|
+
uint32 constant Repay = 11;
|
|
17
|
+
uint32 constant Liquidate = 12;
|
|
18
|
+
}
|
package/commands/Transfer.sol
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { CommandContext, CommandBase, Keys } from "./Base.sol";
|
|
5
|
-
import { Cursors, Cur, Schemas, Tx } from "../Cursors.sol";
|
|
6
|
-
import { Accounts } from "../utils/Accounts.sol";
|
|
7
|
-
using Cursors for Cur;
|
|
8
|
-
|
|
9
|
-
abstract contract TransferHook {
|
|
10
|
-
/// @notice Override to execute a single transfer record from the request pipeline.
|
|
11
|
-
/// Called once per PAYOUT block in the request.
|
|
12
|
-
/// @param value Decoded transfer record (from, to, asset, meta, amount).
|
|
13
|
-
function transfer(Tx memory value) internal virtual;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/// @title Transfer
|
|
17
|
-
/// @notice Command that transfers assets from a caller to recipients specified in
|
|
18
|
-
/// PAYOUT request blocks. Produces no state output.
|
|
19
|
-
/// The virtual `transfer(value)` hook is called once per entry.
|
|
20
|
-
abstract contract Transfer is CommandBase, TransferHook {
|
|
21
|
-
string private constant NAME = "transfer";
|
|
22
|
-
|
|
23
|
-
uint internal immutable transferId = commandId(NAME);
|
|
24
|
-
|
|
25
|
-
constructor() {
|
|
26
|
-
emit Command(host, transferId, NAME, "1:0:0", Schemas.Payout, Keys.Empty, Keys.Empty, false);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/// @notice Override to customize request parsing or batching for transfers.
|
|
30
|
-
/// The default implementation iterates entry blocks and calls `transfer(value)` for each.
|
|
31
|
-
/// @param from Source account identifier.
|
|
32
|
-
/// @param request Full request bytes.
|
|
33
|
-
/// @return Empty bytes (transfers produce no state output).
|
|
34
|
-
function transfer(bytes32 from, bytes calldata request) internal virtual returns (bytes memory) {
|
|
35
|
-
(Cur memory input, ) = cursor(request, 1);
|
|
36
|
-
Tx memory value;
|
|
37
|
-
value.from = from;
|
|
38
|
-
|
|
39
|
-
while (input.i < input.bound) {
|
|
40
|
-
(value.to, value.asset, value.meta, value.amount) = input.unpackPayout();
|
|
41
|
-
Accounts.ensure(value.to);
|
|
42
|
-
transfer(value);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
input.close();
|
|
46
|
-
return "";
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function transfer(
|
|
50
|
-
CommandContext calldata c
|
|
51
|
-
) external onlyCommand returns (bytes memory) {
|
|
52
|
-
return transfer(c.account, c.request);
|
|
53
|
-
}
|
|
54
|
-
}
|
package/core/Context.sol
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import {Cur, Cursors} from "../Cursors.sol";
|
|
5
|
-
import {Assets} from "../utils/Assets.sol";
|
|
6
|
-
import {Ids} from "../utils/Ids.sol";
|
|
7
|
-
|
|
8
|
-
using Cursors for Cur;
|
|
9
|
-
|
|
10
|
-
/// @title RootZeroContext
|
|
11
|
-
/// @notice Shared rootzero contract context for host identity, native value identity, and block-stream cursors.
|
|
12
|
-
abstract contract RootZeroContext {
|
|
13
|
-
/// @dev This contract's host node ID, set to `Ids.toHost(address(this))` at construction.
|
|
14
|
-
uint public immutable host = Ids.toHost(address(this));
|
|
15
|
-
/// @dev Asset ID for the native chain value (ETH), bound to the current chain at deployment.
|
|
16
|
-
bytes32 internal immutable valueAsset = Assets.toValue();
|
|
17
|
-
|
|
18
|
-
/// @notice Open a cursor over a calldata block stream.
|
|
19
|
-
/// @param source Calldata slice to parse.
|
|
20
|
-
/// @return cur Cursor positioned at the beginning of `source`.
|
|
21
|
-
function cursor(bytes calldata source) internal pure returns (Cur memory cur) {
|
|
22
|
-
return Cursors.open(source);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/// @notice Open a cursor and prime it for a grouped iteration pass in one call.
|
|
26
|
-
/// Equivalent to `open(source)` followed by `primeRun(group)`.
|
|
27
|
-
/// @param source Calldata slice to parse.
|
|
28
|
-
/// @param group Expected block group size (e.g. 1 for single, 2 for paired).
|
|
29
|
-
/// @return cur Cursor with `bound` set to the end of the first run.
|
|
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) {
|
|
32
|
-
return Cursors.init(source, group);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/// @notice Open a cursor, prime it, and assert that its group count matches `expectedGroups`.
|
|
36
|
-
/// Equivalent to `open(source)` followed by `primeRun(group)` and a direct group-count equality check.
|
|
37
|
-
/// Reverts with `Cursors.BadRatio` when the group count does not match.
|
|
38
|
-
/// @param source Calldata slice to parse.
|
|
39
|
-
/// @param group Expected block group size (e.g. 1 for single, 2 for paired).
|
|
40
|
-
/// @param expectedGroups Required number of groups in the first run.
|
|
41
|
-
/// @return cur Cursor with `bound` set to the end of the first run.
|
|
42
|
-
function cursor(bytes calldata source, uint group, uint expectedGroups) internal pure returns (Cur memory cur) {
|
|
43
|
-
uint groups;
|
|
44
|
-
(cur, groups) = Cursors.init(source, group);
|
|
45
|
-
if (groups != expectedGroups) revert Cursors.BadRatio();
|
|
46
|
-
}
|
|
47
|
-
}
|
package/events/Collateral.sol
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { EventEmitter } from "./Emitter.sol";
|
|
5
|
-
|
|
6
|
-
/// @notice Emitted when an account's collateral position changes.
|
|
7
|
-
/// Off-chain indexers should query the access command to retrieve the precise collateral details.
|
|
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
|
-
/// @param account Account identifier that holds the collateral.
|
|
12
|
-
/// @param asset Asset identifier of the collateral.
|
|
13
|
-
/// @param meta Asset metadata slot.
|
|
14
|
-
/// @param amount Current collateral amount.
|
|
15
|
-
/// @param access Command ID or context identifier associated with this change.
|
|
16
|
-
event Collateral(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint access);
|
|
17
|
-
|
|
18
|
-
constructor() {
|
|
19
|
-
emit EventAbi(ABI);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
package/events/Contexts.sol
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { EventEmitter } from "./Emitter.sol";
|
|
5
|
-
|
|
6
|
-
/// @notice Emitted when an account's debt position changes.
|
|
7
|
-
/// Off-chain indexers should query the access command to retrieve precise debt details.
|
|
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
|
-
/// @param account Account identifier that holds the debt.
|
|
12
|
-
/// @param asset Asset identifier of the debt.
|
|
13
|
-
/// @param meta Asset metadata slot.
|
|
14
|
-
/// @param amount Current debt amount.
|
|
15
|
-
/// @param mode Debt mode or type discriminant (implementation-defined).
|
|
16
|
-
/// @param access Command ID or context identifier associated with this change.
|
|
17
|
-
event Debt(bytes32 indexed account, bytes32 asset, bytes32 meta, uint amount, uint mode, uint access);
|
|
18
|
-
|
|
19
|
-
constructor() {
|
|
20
|
-
emit EventAbi(ABI);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|