@rootzero/contracts 1.2.0 → 1.3.0
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/CHANGELOG.md +13 -0
- package/Endpoints.sol +9 -7
- package/README.md +300 -79
- package/blocks/Cursors.sol +10 -14
- package/blocks/Schema.sol +7 -4
- package/commands/Burn.sol +2 -2
- package/commands/Credit.sol +2 -2
- package/commands/Debit.sol +2 -2
- package/commands/Deposit.sol +4 -4
- package/commands/Payout.sol +3 -3
- package/commands/Provision.sol +4 -4
- package/commands/Relay.sol +2 -2
- package/commands/Withdraw.sol +2 -2
- package/commands/admin/AllowAssets.sol +2 -2
- package/commands/admin/Allowance.sol +2 -2
- package/commands/admin/Appoint.sol +2 -2
- package/commands/admin/Authorize.sol +2 -2
- package/commands/admin/DenyAssets.sol +2 -2
- package/commands/admin/Destroy.sol +1 -1
- package/commands/admin/Dismiss.sol +2 -2
- package/commands/admin/Execute.sol +2 -2
- package/commands/admin/Init.sol +1 -1
- package/commands/admin/Label.sol +2 -2
- package/commands/admin/Unauthorize.sol +2 -2
- package/core/Pipeline.sol +1 -1
- package/docs/Schema.md +59 -2
- package/events/Admin.sol +2 -6
- package/events/Command.sol +2 -6
- package/events/Labeled.sol +3 -0
- package/events/Transfer.sol +1 -1
- package/guards/Revoke.sol +1 -1
- package/package.json +1 -1
- package/peer/AllowAssets.sol +6 -2
- package/peer/Allowance.sol +6 -2
- package/peer/BalancePull.sol +6 -2
- package/peer/Credit.sol +39 -0
- package/peer/Debit.sol +39 -0
- package/peer/DenyAssets.sol +6 -2
- package/peer/Dispatch.sol +6 -2
- package/peer/Pipe.sol +6 -2
- package/peer/Settle.sol +6 -2
- package/queries/Assets.sol +1 -1
- package/queries/Balances.sol +1 -1
- package/queries/Positions.sol +1 -1
package/peer/Debit.sol
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import { PeerBase } from "./Base.sol";
|
|
5
|
+
import { DebitAccountHook } from "../commands/Debit.sol";
|
|
6
|
+
import { Cursors, Cur, Forms } from "../Cursors.sol";
|
|
7
|
+
|
|
8
|
+
using Cursors for Cur;
|
|
9
|
+
|
|
10
|
+
interface IPeerDebitFrom {
|
|
11
|
+
function peerDebitFrom(bytes calldata request) external returns (bytes memory);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/// @title PeerDebitFrom
|
|
15
|
+
/// @notice Peer that lets a trusted peer debit supplied accounts directly.
|
|
16
|
+
/// Each ACCOUNT_AMOUNT block calls `debitAccount` for its account.
|
|
17
|
+
abstract contract PeerDebitFrom is PeerBase, DebitAccountHook, IPeerDebitFrom {
|
|
18
|
+
uint internal immutable peerDebitFromId = peerId(this.peerDebitFrom.selector);
|
|
19
|
+
|
|
20
|
+
constructor() {
|
|
21
|
+
emit Peer(host, peerDebitFromId, "1:0", Forms.AccountAmount, "", false);
|
|
22
|
+
emit Labeled(peerDebitFromId, bytes32(0), "peerDebitFrom");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/// @notice Execute the peer-debit call.
|
|
26
|
+
/// @param request ACCOUNT_AMOUNT block stream supplied by the trusted peer.
|
|
27
|
+
/// @return Empty response bytes.
|
|
28
|
+
function peerDebitFrom(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
29
|
+
(Cur memory amounts, , ) = Cursors.init(request, 1);
|
|
30
|
+
|
|
31
|
+
while (amounts.i < amounts.len) {
|
|
32
|
+
(bytes32 account, bytes32 asset, bytes32 meta, uint amount) = amounts.unpackAccountAmount();
|
|
33
|
+
debitAccount(account, asset, meta, amount);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
amounts.complete();
|
|
37
|
+
return "";
|
|
38
|
+
}
|
|
39
|
+
}
|
package/peer/DenyAssets.sol
CHANGED
|
@@ -7,10 +7,14 @@ import {Cursors, Cur, Schemas} from "../Cursors.sol";
|
|
|
7
7
|
|
|
8
8
|
using Cursors for Cur;
|
|
9
9
|
|
|
10
|
+
interface IPeerDenyAssets {
|
|
11
|
+
function peerDenyAssets(bytes calldata request) external returns (bytes memory);
|
|
12
|
+
}
|
|
13
|
+
|
|
10
14
|
/// @title PeerDenyAssets
|
|
11
15
|
/// @notice Peer that blocks a list of (asset, meta) pairs on behalf of a peer host.
|
|
12
16
|
/// Each ASSET block in the request calls `denyAsset`. Restricted to trusted peers.
|
|
13
|
-
abstract contract PeerDenyAssets is PeerBase, DenyAssetsHook {
|
|
17
|
+
abstract contract PeerDenyAssets is PeerBase, DenyAssetsHook, IPeerDenyAssets {
|
|
14
18
|
uint internal immutable peerDenyAssetsId = peerId(this.peerDenyAssets.selector);
|
|
15
19
|
|
|
16
20
|
constructor() {
|
|
@@ -22,7 +26,7 @@ abstract contract PeerDenyAssets is PeerBase, DenyAssetsHook {
|
|
|
22
26
|
/// @param request ASSET block stream supplied by the trusted peer.
|
|
23
27
|
/// @return Empty response bytes.
|
|
24
28
|
function peerDenyAssets(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
25
|
-
(Cur memory assets, , ) = Cursors.init(request,
|
|
29
|
+
(Cur memory assets, , ) = Cursors.init(request, 1);
|
|
26
30
|
|
|
27
31
|
while (assets.i < assets.len) {
|
|
28
32
|
(bytes32 asset, bytes32 meta) = assets.unpackAsset();
|
package/peer/Dispatch.sol
CHANGED
|
@@ -9,9 +9,13 @@ import { Budget } from "../utils/Value.sol";
|
|
|
9
9
|
|
|
10
10
|
using Cursors for Cur;
|
|
11
11
|
|
|
12
|
+
interface IPeerDispatchPayable {
|
|
13
|
+
function peerDispatchPayable(bytes calldata request) external payable returns (bytes memory);
|
|
14
|
+
}
|
|
15
|
+
|
|
12
16
|
/// @title PeerDispatchPayable
|
|
13
17
|
/// @notice Peer endpoint that forwards DISPATCH blocks to a host-defined dispatch hook.
|
|
14
|
-
abstract contract PeerDispatchPayable is PeerBase, Payable, DispatchPayableHook {
|
|
18
|
+
abstract contract PeerDispatchPayable is PeerBase, Payable, DispatchPayableHook, IPeerDispatchPayable {
|
|
15
19
|
uint internal immutable peerDispatchPayableId = peerId(this.peerDispatchPayable.selector);
|
|
16
20
|
|
|
17
21
|
constructor() {
|
|
@@ -25,7 +29,7 @@ abstract contract PeerDispatchPayable is PeerBase, Payable, DispatchPayableHook
|
|
|
25
29
|
/// @param request DISPATCH block stream supplied by the trusted peer.
|
|
26
30
|
/// @return output Empty response bytes.
|
|
27
31
|
function peerDispatchPayable(bytes calldata request) external payable onlyPeer returns (bytes memory output) {
|
|
28
|
-
(Cur memory input, , ) = Cursors.init(request,
|
|
32
|
+
(Cur memory input, , ) = Cursors.init(request, 1);
|
|
29
33
|
Budget memory budget = valueBudget();
|
|
30
34
|
|
|
31
35
|
while (input.i < input.len) {
|
package/peer/Pipe.sol
CHANGED
|
@@ -8,11 +8,15 @@ import {Budget} from "../utils/Value.sol";
|
|
|
8
8
|
|
|
9
9
|
using Cursors for Cur;
|
|
10
10
|
|
|
11
|
+
interface IPeerPipePayable {
|
|
12
|
+
function peerPipePayable(bytes calldata request) external payable returns (bytes memory);
|
|
13
|
+
}
|
|
14
|
+
|
|
11
15
|
/// @title PeerPipePayable
|
|
12
16
|
/// @notice Peer that consumes PIPE blocks and executes each context step stream.
|
|
13
17
|
/// Each PIPE block carries chain resources plus a CONTEXT block; the nested
|
|
14
18
|
/// context steps are passed to the shared pipeline as the step stream.
|
|
15
|
-
abstract contract PeerPipePayable is PeerBase, Pipeline {
|
|
19
|
+
abstract contract PeerPipePayable is PeerBase, Pipeline, IPeerPipePayable {
|
|
16
20
|
uint internal immutable peerPipePayableId = peerId(this.peerPipePayable.selector);
|
|
17
21
|
|
|
18
22
|
constructor() {
|
|
@@ -26,7 +30,7 @@ abstract contract PeerPipePayable is PeerBase, Pipeline {
|
|
|
26
30
|
/// @param request PIPE block stream supplied by the trusted peer.
|
|
27
31
|
/// @return Empty response bytes.
|
|
28
32
|
function peerPipePayable(bytes calldata request) external payable onlyPeer returns (bytes memory) {
|
|
29
|
-
(Cur memory input, , ) = Cursors.init(request,
|
|
33
|
+
(Cur memory input, , ) = Cursors.init(request, 1);
|
|
30
34
|
Budget memory budget = valueBudget();
|
|
31
35
|
|
|
32
36
|
while (input.i < input.len) {
|
package/peer/Settle.sol
CHANGED
|
@@ -8,10 +8,14 @@ import { Cursors, Cur, Schemas } from "../Cursors.sol";
|
|
|
8
8
|
|
|
9
9
|
using Cursors for Cur;
|
|
10
10
|
|
|
11
|
+
interface IPeerSettle {
|
|
12
|
+
function peerSettle(bytes calldata request) external returns (bytes memory);
|
|
13
|
+
}
|
|
14
|
+
|
|
11
15
|
/// @title PeerSettle
|
|
12
16
|
/// @notice Peer that consumes peer-supplied TRANSACTION blocks through debit and credit hooks.
|
|
13
17
|
/// Each TRANSACTION block calls `debitAccount` for `from` and `creditAccount` for `to`.
|
|
14
|
-
abstract contract PeerSettle is PeerBase, DebitAccountHook, CreditAccountHook {
|
|
18
|
+
abstract contract PeerSettle is PeerBase, DebitAccountHook, CreditAccountHook, IPeerSettle {
|
|
15
19
|
uint internal immutable peerSettleId = peerId(this.peerSettle.selector);
|
|
16
20
|
|
|
17
21
|
constructor() {
|
|
@@ -23,7 +27,7 @@ abstract contract PeerSettle is PeerBase, DebitAccountHook, CreditAccountHook {
|
|
|
23
27
|
/// @param request TRANSACTION block stream supplied by the trusted peer.
|
|
24
28
|
/// @return Empty response bytes.
|
|
25
29
|
function peerSettle(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
26
|
-
(Cur memory state, , ) = Cursors.init(request,
|
|
30
|
+
(Cur memory state, , ) = Cursors.init(request, 1);
|
|
27
31
|
|
|
28
32
|
while (state.i < state.len) {
|
|
29
33
|
(bytes32 from, bytes32 to, bytes32 asset, bytes32 meta, uint amount) = state.unpackTransaction();
|
package/queries/Assets.sol
CHANGED
|
@@ -33,7 +33,7 @@ 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, ) = Cursors.init(request,
|
|
36
|
+
(Cur memory query, uint groups, ) = Cursors.init(request, 1);
|
|
37
37
|
Writer memory response = Writers.allocStatuses(groups);
|
|
38
38
|
|
|
39
39
|
while (query.i < query.len) {
|
package/queries/Balances.sol
CHANGED
|
@@ -33,7 +33,7 @@ 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, ) = Cursors.init(request,
|
|
36
|
+
(Cur memory query, uint groups, ) = Cursors.init(request, 1);
|
|
37
37
|
Writer memory response = Writers.allocAccountAmounts(groups);
|
|
38
38
|
|
|
39
39
|
while (query.i < query.len) {
|
package/queries/Positions.sol
CHANGED
|
@@ -41,7 +41,7 @@ abstract contract GetPosition is QueryBase, GetPositionHook {
|
|
|
41
41
|
/// @param request Block-stream request consisting of `accountAsset(account, asset, meta)*`.
|
|
42
42
|
/// @return Block-stream response containing one output-schema block per position block.
|
|
43
43
|
function getPosition(bytes calldata request) external view returns (bytes memory) {
|
|
44
|
-
(Cur memory query, uint groups, ) = Cursors.init(request,
|
|
44
|
+
(Cur memory query, uint groups, ) = Cursors.init(request, 1);
|
|
45
45
|
Writer memory response = Writers.allocAny(groups);
|
|
46
46
|
|
|
47
47
|
while (query.i < query.len) {
|