@rootzero/contracts 0.9.8 → 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 +1 -1
- package/Endpoints.sol +1 -1
- package/Events.sol +1 -0
- 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/Pipeline.sol +3 -3
- package/core/Runtime.sol +1 -34
- 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/Peer.sol +5 -5
- package/events/Query.sol +2 -4
- package/events/Transfer.sol +22 -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/Positions.sol +3 -3
- package/utils/Accounts.sol +8 -0
- package/utils/Actions.sol +11 -9
- package/commands/Transfer.sol +0 -54
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
|
|
|
@@ -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
|
+
}
|
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/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.
|
package/utils/Actions.sol
CHANGED
|
@@ -4,13 +4,15 @@ pragma solidity ^0.8.33;
|
|
|
4
4
|
library Actions {
|
|
5
5
|
uint32 constant None = 0;
|
|
6
6
|
uint32 constant Transfer = 1;
|
|
7
|
-
uint32 constant
|
|
8
|
-
uint32 constant
|
|
9
|
-
uint32 constant
|
|
10
|
-
uint32 constant
|
|
11
|
-
uint32 constant
|
|
12
|
-
uint32 constant
|
|
13
|
-
uint32 constant
|
|
14
|
-
uint32 constant
|
|
15
|
-
uint32 constant
|
|
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;
|
|
16
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
|
-
}
|