@rootzero/contracts 0.7.2 → 0.8.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/Commands.sol +18 -18
- package/Cursors.sol +4 -1
- package/Queries.sol +3 -3
- package/blocks/Keys.sol +1 -0
- package/blocks/Schema.sol +8 -1
- package/blocks/{Cursors.sol → cursors/Core.sol} +83 -13
- package/blocks/cursors/Erc1155.sol +149 -0
- package/blocks/cursors/Erc20.sol +130 -0
- package/blocks/cursors/Erc721.sol +66 -0
- package/commands/Burn.sol +12 -10
- package/commands/Create.sol +7 -5
- package/commands/Credit.sol +11 -9
- package/commands/Debit.sol +11 -9
- package/commands/Deposit.sol +25 -32
- package/commands/Pipe.sol +11 -17
- package/commands/Remove.sol +7 -5
- package/commands/Stake.sol +7 -5
- package/commands/Supply.sol +9 -7
- package/commands/Transfer.sol +4 -3
- package/commands/Withdraw.sol +11 -9
- package/commands/admin/Allocate.sol +7 -5
- package/commands/admin/Destroy.sol +7 -5
- package/commands/admin/Init.sol +7 -5
- package/core/Host.sol +1 -1
- package/package.json +1 -1
- package/peer/AssetPull.sol +33 -31
- package/peer/Pull.sol +8 -6
- package/peer/Push.sol +8 -6
- package/queries/Assets.sol +10 -8
- package/queries/Balances.sol +11 -9
- package/queries/Positions.sol +11 -9
- package/utils/Assets.sol +69 -14
- package/utils/Ids.sol +5 -5
- package/utils/Layout.sol +4 -2
package/commands/Create.sol
CHANGED
|
@@ -8,21 +8,23 @@ string constant NAME = "create";
|
|
|
8
8
|
|
|
9
9
|
using Cursors for Cur;
|
|
10
10
|
|
|
11
|
+
abstract contract CreateHook {
|
|
12
|
+
/// @dev Override to create or initialize an object described by `input`.
|
|
13
|
+
/// Called once per top-level request item.
|
|
14
|
+
function create(bytes32 account, Cur memory input) internal virtual;
|
|
15
|
+
}
|
|
16
|
+
|
|
11
17
|
/// @title Create
|
|
12
18
|
/// @notice Generic command that creates or initializes objects via a virtual hook.
|
|
13
19
|
/// The request schema is constructor-defined; `create` is called once per top-level group.
|
|
14
20
|
/// Produces no output state.
|
|
15
|
-
abstract contract Create is CommandBase {
|
|
21
|
+
abstract contract Create is CommandBase, CreateHook {
|
|
16
22
|
uint internal immutable createId = commandId(NAME);
|
|
17
23
|
|
|
18
24
|
constructor(string memory input) {
|
|
19
25
|
emit Command(host, NAME, input, createId, State.Empty, State.Empty, false);
|
|
20
26
|
}
|
|
21
27
|
|
|
22
|
-
/// @dev Override to create or initialize an object described by `input`.
|
|
23
|
-
/// Called once per top-level request item.
|
|
24
|
-
function create(bytes32 account, Cur memory input) internal virtual;
|
|
25
|
-
|
|
26
28
|
function create(CommandContext calldata c) external onlyCommand(createId, c.target) returns (bytes memory) {
|
|
27
29
|
(Cur memory request, , ) = cursor(c.request, 1);
|
|
28
30
|
|
package/commands/Credit.sol
CHANGED
|
@@ -7,25 +7,27 @@ string constant NAME = "creditAccount";
|
|
|
7
7
|
|
|
8
8
|
using Cursors for Cur;
|
|
9
9
|
|
|
10
|
+
abstract contract CreditAccountHook {
|
|
11
|
+
/// @notice Override to credit externally managed funds to `account`.
|
|
12
|
+
/// Called once per BALANCE block in state.
|
|
13
|
+
/// @param account Recipient account identifier.
|
|
14
|
+
/// @param asset Asset identifier.
|
|
15
|
+
/// @param meta Asset metadata slot.
|
|
16
|
+
/// @param amount Amount to credit.
|
|
17
|
+
function creditAccount(bytes32 account, bytes32 asset, bytes32 meta, uint amount) internal virtual;
|
|
18
|
+
}
|
|
19
|
+
|
|
10
20
|
/// @title CreditAccount
|
|
11
21
|
/// @notice Command that delivers BALANCE state blocks to an account via a virtual hook.
|
|
12
22
|
/// Use for internally recording credits that have already been settled externally.
|
|
13
23
|
/// An optional RECIPIENT block in the request overrides the default `c.account` destination.
|
|
14
|
-
abstract contract CreditAccount is CommandBase {
|
|
24
|
+
abstract contract CreditAccount is CommandBase, CreditAccountHook {
|
|
15
25
|
uint internal immutable creditAccountId = commandId(NAME);
|
|
16
26
|
|
|
17
27
|
constructor() {
|
|
18
28
|
emit Command(host, NAME, Schemas.Recipient, creditAccountId, State.Balances, State.Empty, false);
|
|
19
29
|
}
|
|
20
30
|
|
|
21
|
-
/// @notice Override to credit externally managed funds to `account`.
|
|
22
|
-
/// Called once per BALANCE block in state.
|
|
23
|
-
/// @param account Recipient account identifier.
|
|
24
|
-
/// @param asset Asset identifier.
|
|
25
|
-
/// @param meta Asset metadata slot.
|
|
26
|
-
/// @param amount Amount to credit.
|
|
27
|
-
function creditAccount(bytes32 account, bytes32 asset, bytes32 meta, uint amount) internal virtual;
|
|
28
|
-
|
|
29
31
|
function creditAccount(
|
|
30
32
|
CommandContext calldata c
|
|
31
33
|
) external onlyCommand(creditAccountId, c.target) returns (bytes memory) {
|
package/commands/Debit.sol
CHANGED
|
@@ -9,25 +9,27 @@ string constant NAME = "debitAccount";
|
|
|
9
9
|
using Cursors for Cur;
|
|
10
10
|
using Writers for Writer;
|
|
11
11
|
|
|
12
|
+
abstract contract DebitAccountHook {
|
|
13
|
+
/// @notice Override to debit externally managed funds from `account`.
|
|
14
|
+
/// Called once per AMOUNT block before a matching BALANCE is emitted.
|
|
15
|
+
/// @param account Source account identifier.
|
|
16
|
+
/// @param asset Asset identifier.
|
|
17
|
+
/// @param meta Asset metadata slot.
|
|
18
|
+
/// @param amount Amount to debit.
|
|
19
|
+
function debitAccount(bytes32 account, bytes32 asset, bytes32 meta, uint amount) internal virtual;
|
|
20
|
+
}
|
|
21
|
+
|
|
12
22
|
/// @title DebitAccount
|
|
13
23
|
/// @notice Command that deducts AMOUNT blocks from an account and emits matching BALANCE state.
|
|
14
24
|
/// Use for internally recording debits. The virtual `debitAccount` hook is called once per
|
|
15
25
|
/// AMOUNT block; the default batch implementation handles the full request loop.
|
|
16
|
-
abstract contract DebitAccount is CommandBase {
|
|
26
|
+
abstract contract DebitAccount is CommandBase, DebitAccountHook {
|
|
17
27
|
uint internal immutable debitAccountId = commandId(NAME);
|
|
18
28
|
|
|
19
29
|
constructor() {
|
|
20
30
|
emit Command(host, NAME, Schemas.Amount, debitAccountId, State.Empty, State.Balances, false);
|
|
21
31
|
}
|
|
22
32
|
|
|
23
|
-
/// @notice Override to debit externally managed funds from `account`.
|
|
24
|
-
/// Called once per AMOUNT block before a matching BALANCE is emitted.
|
|
25
|
-
/// @param account Source account identifier.
|
|
26
|
-
/// @param asset Asset identifier.
|
|
27
|
-
/// @param meta Asset metadata slot.
|
|
28
|
-
/// @param amount Amount to debit.
|
|
29
|
-
function debitAccount(bytes32 account, bytes32 asset, bytes32 meta, uint amount) internal virtual;
|
|
30
|
-
|
|
31
33
|
/// @notice Override to customize request parsing or batching for debits.
|
|
32
34
|
/// The default implementation iterates AMOUNT blocks, calls
|
|
33
35
|
/// `debitAccount`, and emits matching BALANCE blocks.
|
package/commands/Deposit.sol
CHANGED
|
@@ -11,31 +11,40 @@ string constant DEPOSIT_PAYABLE = "depositPayable";
|
|
|
11
11
|
using Cursors for Cur;
|
|
12
12
|
using Writers for Writer;
|
|
13
13
|
|
|
14
|
+
abstract contract DepositHook {
|
|
15
|
+
/// @notice Override to receive externally sourced funds for `account`.
|
|
16
|
+
/// Called once per AMOUNT block. A matching BALANCE block is appended to the
|
|
17
|
+
/// output after each call.
|
|
18
|
+
/// @param account Recipient account identifier.
|
|
19
|
+
/// @param asset Asset identifier.
|
|
20
|
+
/// @param meta Asset metadata slot.
|
|
21
|
+
/// @param amount Amount received.
|
|
22
|
+
function deposit(bytes32 account, bytes32 asset, bytes32 meta, uint amount) internal virtual;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
abstract contract DepositPayableHook {
|
|
26
|
+
/// @notice Override to receive externally sourced funds for `account`.
|
|
27
|
+
/// Called once per AMOUNT block. A matching BALANCE block is appended to the
|
|
28
|
+
/// output after each call.
|
|
29
|
+
/// @param account Recipient account identifier.
|
|
30
|
+
/// @param asset Asset identifier.
|
|
31
|
+
/// @param meta Asset metadata slot.
|
|
32
|
+
/// @param amount Amount received.
|
|
33
|
+
/// @param budget Mutable native-value budget drawn from `msg.value`.
|
|
34
|
+
function deposit(bytes32 account, bytes32 asset, bytes32 meta, uint amount, Budget memory budget) internal virtual;
|
|
35
|
+
}
|
|
36
|
+
|
|
14
37
|
/// @title Deposit
|
|
15
38
|
/// @notice Command that receives externally sourced assets and records them as BALANCE state.
|
|
16
39
|
/// Use `deposit` for assets arriving from outside the protocol (e.g. ERC-20 transfers, ETH).
|
|
17
40
|
/// For internal balance deductions, use `debitAccount` instead.
|
|
18
|
-
abstract contract Deposit is CommandBase {
|
|
41
|
+
abstract contract Deposit is CommandBase, DepositHook {
|
|
19
42
|
uint internal immutable depositId = commandId(DEPOSIT);
|
|
20
43
|
|
|
21
44
|
constructor() {
|
|
22
45
|
emit Command(host, DEPOSIT, Schemas.Amount, depositId, State.Empty, State.Balances, false);
|
|
23
46
|
}
|
|
24
47
|
|
|
25
|
-
/// @notice Override to receive externally sourced funds for `account`.
|
|
26
|
-
/// Called once per AMOUNT block. A matching BALANCE block is appended to the
|
|
27
|
-
/// output after each call.
|
|
28
|
-
/// @param account Recipient account identifier.
|
|
29
|
-
/// @param asset Asset identifier.
|
|
30
|
-
/// @param meta Asset metadata slot.
|
|
31
|
-
/// @param amount Amount received.
|
|
32
|
-
function deposit(
|
|
33
|
-
bytes32 account,
|
|
34
|
-
bytes32 asset,
|
|
35
|
-
bytes32 meta,
|
|
36
|
-
uint amount
|
|
37
|
-
) internal virtual;
|
|
38
|
-
|
|
39
48
|
function deposit(
|
|
40
49
|
CommandContext calldata c
|
|
41
50
|
) external onlyCommand(depositId, c.target) returns (bytes memory) {
|
|
@@ -55,29 +64,13 @@ abstract contract Deposit is CommandBase {
|
|
|
55
64
|
/// @title DepositPayable
|
|
56
65
|
/// @notice Command that receives externally sourced assets and records them as BALANCE state.
|
|
57
66
|
/// Use `depositPayable` when the hook needs tracked access to `msg.value` via a mutable budget.
|
|
58
|
-
abstract contract DepositPayable is CommandPayable {
|
|
67
|
+
abstract contract DepositPayable is CommandPayable, DepositPayableHook {
|
|
59
68
|
uint internal immutable depositPayableId = commandId(DEPOSIT_PAYABLE);
|
|
60
69
|
|
|
61
70
|
constructor() {
|
|
62
71
|
emit Command(host, DEPOSIT_PAYABLE, Schemas.Amount, depositPayableId, State.Empty, State.Balances, true);
|
|
63
72
|
}
|
|
64
73
|
|
|
65
|
-
/// @notice Override to receive externally sourced funds for `account`.
|
|
66
|
-
/// Called once per AMOUNT block. A matching BALANCE block is appended to the
|
|
67
|
-
/// output after each call.
|
|
68
|
-
/// @param account Recipient account identifier.
|
|
69
|
-
/// @param asset Asset identifier.
|
|
70
|
-
/// @param meta Asset metadata slot.
|
|
71
|
-
/// @param amount Amount received.
|
|
72
|
-
/// @param budget Mutable native-value budget drawn from `msg.value`.
|
|
73
|
-
function deposit(
|
|
74
|
-
bytes32 account,
|
|
75
|
-
bytes32 asset,
|
|
76
|
-
bytes32 meta,
|
|
77
|
-
uint amount,
|
|
78
|
-
Budget memory budget
|
|
79
|
-
) internal virtual;
|
|
80
|
-
|
|
81
74
|
function depositPayable(
|
|
82
75
|
CommandContext calldata c
|
|
83
76
|
) external payable onlyCommand(depositPayableId, c.target) returns (bytes memory) {
|
package/commands/Pipe.sol
CHANGED
|
@@ -10,34 +10,28 @@ using Cursors for Cur;
|
|
|
10
10
|
|
|
11
11
|
string constant NAME = "pipePayable";
|
|
12
12
|
|
|
13
|
+
abstract contract PipePayableHook {
|
|
14
|
+
function dispatchStep(
|
|
15
|
+
uint target,
|
|
16
|
+
bytes32 account,
|
|
17
|
+
bytes memory state,
|
|
18
|
+
bytes calldata request,
|
|
19
|
+
uint value
|
|
20
|
+
) internal virtual returns (bytes memory);
|
|
21
|
+
}
|
|
22
|
+
|
|
13
23
|
/// @title PipePayable
|
|
14
24
|
/// @notice Command that sequences multiple sub-command STEP invocations in a single transaction.
|
|
15
25
|
/// Each STEP block carries a target node, native value to forward, and an embedded request.
|
|
16
26
|
/// State threads through the steps: each step's output becomes the next step's state.
|
|
17
27
|
/// Admin accounts are not permitted to use `pipePayable`.
|
|
18
|
-
abstract contract PipePayable is CommandPayable {
|
|
28
|
+
abstract contract PipePayable is CommandPayable, PipePayableHook {
|
|
19
29
|
uint internal immutable pipePayableId = commandId(NAME);
|
|
20
30
|
|
|
21
31
|
constructor() {
|
|
22
32
|
emit Command(host, NAME, Schemas.Step, pipePayableId, 0, 0, true);
|
|
23
33
|
}
|
|
24
34
|
|
|
25
|
-
/// @notice Override to execute a single STEP and return the resulting state.
|
|
26
|
-
/// The returned state is passed as the `state` argument of the next STEP.
|
|
27
|
-
/// @param target Destination command node ID from the STEP block.
|
|
28
|
-
/// @param account Caller's account identifier.
|
|
29
|
-
/// @param state Current threaded state from the previous step.
|
|
30
|
-
/// @param request Embedded request bytes from the STEP block.
|
|
31
|
-
/// @param value Native value forwarded with this step.
|
|
32
|
-
/// @return Next state to thread into the following step.
|
|
33
|
-
function dispatchStep(
|
|
34
|
-
uint target,
|
|
35
|
-
bytes32 account,
|
|
36
|
-
bytes memory state,
|
|
37
|
-
bytes calldata request,
|
|
38
|
-
uint value
|
|
39
|
-
) internal virtual returns (bytes memory);
|
|
40
|
-
|
|
41
35
|
function pipe(
|
|
42
36
|
bytes32 account,
|
|
43
37
|
bytes memory state,
|
package/commands/Remove.sol
CHANGED
|
@@ -8,21 +8,23 @@ string constant NAME = "remove";
|
|
|
8
8
|
|
|
9
9
|
using Cursors for Cur;
|
|
10
10
|
|
|
11
|
+
abstract contract RemoveHook {
|
|
12
|
+
/// @dev Override to remove or dismantle an object described by `input`.
|
|
13
|
+
/// Called once per top-level request item.
|
|
14
|
+
function remove(bytes32 account, Cur memory input) internal virtual;
|
|
15
|
+
}
|
|
16
|
+
|
|
11
17
|
/// @title Remove
|
|
12
18
|
/// @notice Generic command that removes or dismantles objects via a virtual hook.
|
|
13
19
|
/// The request schema is constructor-defined; `remove` is called once per top-level group.
|
|
14
20
|
/// Produces no output state.
|
|
15
|
-
abstract contract Remove is CommandBase {
|
|
21
|
+
abstract contract Remove is CommandBase, RemoveHook {
|
|
16
22
|
uint internal immutable removeId = commandId(NAME);
|
|
17
23
|
|
|
18
24
|
constructor(string memory input) {
|
|
19
25
|
emit Command(host, NAME, input, removeId, State.Empty, State.Empty, false);
|
|
20
26
|
}
|
|
21
27
|
|
|
22
|
-
/// @dev Override to remove or dismantle an object described by `input`.
|
|
23
|
-
/// Called once per top-level request item.
|
|
24
|
-
function remove(bytes32 account, Cur memory input) internal virtual;
|
|
25
|
-
|
|
26
28
|
function remove(CommandContext calldata c) external onlyCommand(removeId, c.target) returns (bytes memory) {
|
|
27
29
|
(Cur memory request, , ) = cursor(c.request, 1);
|
|
28
30
|
|
package/commands/Stake.sol
CHANGED
|
@@ -8,20 +8,22 @@ string constant SCTP = "stakeCustodyToPosition";
|
|
|
8
8
|
|
|
9
9
|
using Cursors for Cur;
|
|
10
10
|
|
|
11
|
+
abstract contract StakeCustodyToPositionHook {
|
|
12
|
+
/// @dev Override to stake a custody position into a non-balance setup
|
|
13
|
+
/// target described by `request`.
|
|
14
|
+
function stakeCustodyToPosition(bytes32 account, HostAmount memory custody, Cur memory request) internal virtual;
|
|
15
|
+
}
|
|
16
|
+
|
|
11
17
|
/// @title StakeCustodyToPosition
|
|
12
18
|
/// @notice Command that stakes CUSTODY state positions into a non-balance target
|
|
13
19
|
/// described by the request stream. Produces no output state.
|
|
14
|
-
abstract contract StakeCustodyToPosition is CommandBase {
|
|
20
|
+
abstract contract StakeCustodyToPosition is CommandBase, StakeCustodyToPositionHook {
|
|
15
21
|
uint internal immutable stakeCustodyToPositionId = commandId(SCTP);
|
|
16
22
|
|
|
17
23
|
constructor(string memory input) {
|
|
18
24
|
emit Command(host, SCTP, input, stakeCustodyToPositionId, State.Custodies, State.Empty, false);
|
|
19
25
|
}
|
|
20
26
|
|
|
21
|
-
/// @dev Override to stake a custody position into a non-balance setup
|
|
22
|
-
/// target described by `request`.
|
|
23
|
-
function stakeCustodyToPosition(bytes32 account, HostAmount memory custody, Cur memory request) internal virtual;
|
|
24
|
-
|
|
25
27
|
function stakeCustodyToPosition(
|
|
26
28
|
CommandContext calldata c
|
|
27
29
|
) external onlyCommand(stakeCustodyToPositionId, c.target) returns (bytes memory) {
|
package/commands/Supply.sol
CHANGED
|
@@ -7,23 +7,25 @@ string constant NAME = "supply";
|
|
|
7
7
|
|
|
8
8
|
using Cursors for Cur;
|
|
9
9
|
|
|
10
|
+
abstract contract SupplyHook {
|
|
11
|
+
/// @notice Override to consume or supply a single custody position.
|
|
12
|
+
/// Called once per CUSTODY block in state.
|
|
13
|
+
/// @param account Caller's account identifier.
|
|
14
|
+
/// @param value Decoded custody position (host, asset, meta, amount).
|
|
15
|
+
function supply(bytes32 account, HostAmount memory value) internal virtual;
|
|
16
|
+
}
|
|
17
|
+
|
|
10
18
|
/// @title Supply
|
|
11
19
|
/// @notice Command that processes each CUSTODY state block through a virtual hook.
|
|
12
20
|
/// Used to move assets out of cross-host custody positions (e.g. to settle or redeem them).
|
|
13
21
|
/// Produces no output state.
|
|
14
|
-
abstract contract Supply is CommandBase {
|
|
22
|
+
abstract contract Supply is CommandBase, SupplyHook {
|
|
15
23
|
uint internal immutable supplyId = commandId(NAME);
|
|
16
24
|
|
|
17
25
|
constructor() {
|
|
18
26
|
emit Command(host, NAME, "", supplyId, State.Custodies, State.Empty, false);
|
|
19
27
|
}
|
|
20
28
|
|
|
21
|
-
/// @notice Override to consume or supply a single custody position.
|
|
22
|
-
/// Called once per CUSTODY block in state.
|
|
23
|
-
/// @param account Caller's account identifier.
|
|
24
|
-
/// @param value Decoded custody position (host, asset, meta, amount).
|
|
25
|
-
function supply(bytes32 account, HostAmount memory value) internal virtual;
|
|
26
|
-
|
|
27
29
|
/// @notice Execute the supply command.
|
|
28
30
|
function supply(CommandContext calldata c) external onlyCommand(supplyId, c.target) returns (bytes memory) {
|
|
29
31
|
(Cur memory state, , ) = cursor(c.state, 1);
|
package/commands/Transfer.sol
CHANGED
|
@@ -38,10 +38,11 @@ abstract contract Transfer is CommandBase, TransferHook {
|
|
|
38
38
|
value.from = from;
|
|
39
39
|
|
|
40
40
|
while (input.i < input.bound) {
|
|
41
|
-
|
|
42
|
-
(value.asset, value.meta, value.amount) =
|
|
43
|
-
value.to = Accounts.ensure(
|
|
41
|
+
uint next = input.bundle();
|
|
42
|
+
(value.asset, value.meta, value.amount) = input.unpackAmount();
|
|
43
|
+
value.to = Accounts.ensure(input.unpackRecipient());
|
|
44
44
|
transfer(value);
|
|
45
|
+
input.ensure(next);
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
input.complete();
|
package/commands/Withdraw.sol
CHANGED
|
@@ -7,25 +7,27 @@ using Cursors for Cur;
|
|
|
7
7
|
|
|
8
8
|
string constant NAME = "withdraw";
|
|
9
9
|
|
|
10
|
+
abstract contract WithdrawHook {
|
|
11
|
+
/// @notice Override to send funds to `account`.
|
|
12
|
+
/// Called once per BALANCE block in state.
|
|
13
|
+
/// @param account Destination account identifier (resolved from RECIPIENT block or caller).
|
|
14
|
+
/// @param asset Asset identifier.
|
|
15
|
+
/// @param meta Asset metadata slot.
|
|
16
|
+
/// @param amount Amount to deliver.
|
|
17
|
+
function withdraw(bytes32 account, bytes32 asset, bytes32 meta, uint amount) internal virtual;
|
|
18
|
+
}
|
|
19
|
+
|
|
10
20
|
/// @title Withdraw
|
|
11
21
|
/// @notice Command that delivers BALANCE state blocks to an external destination.
|
|
12
22
|
/// Use `withdraw` for assets being sent outside the protocol (e.g. ERC-20 transfers, ETH sends).
|
|
13
23
|
/// For internal balance credits, use `creditAccount` instead.
|
|
14
|
-
abstract contract Withdraw is CommandBase {
|
|
24
|
+
abstract contract Withdraw is CommandBase, WithdrawHook {
|
|
15
25
|
uint internal immutable withdrawId = commandId(NAME);
|
|
16
26
|
|
|
17
27
|
constructor() {
|
|
18
28
|
emit Command(host, NAME, Schemas.Recipient, withdrawId, State.Balances, State.Empty, false);
|
|
19
29
|
}
|
|
20
30
|
|
|
21
|
-
/// @notice Override to send funds to `account`.
|
|
22
|
-
/// Called once per BALANCE block in state.
|
|
23
|
-
/// @param account Destination account identifier (resolved from RECIPIENT block or caller).
|
|
24
|
-
/// @param asset Asset identifier.
|
|
25
|
-
/// @param meta Asset metadata slot.
|
|
26
|
-
/// @param amount Amount to deliver.
|
|
27
|
-
function withdraw(bytes32 account, bytes32 asset, bytes32 meta, uint amount) internal virtual;
|
|
28
|
-
|
|
29
31
|
function withdraw(
|
|
30
32
|
CommandContext calldata c
|
|
31
33
|
) external onlyCommand(withdrawId, c.target) returns (bytes memory) {
|
|
@@ -7,20 +7,22 @@ using Cursors for Cur;
|
|
|
7
7
|
|
|
8
8
|
string constant NAME = "allocate";
|
|
9
9
|
|
|
10
|
+
abstract contract AllocateHook {
|
|
11
|
+
/// @dev Override to apply a single allocation entry.
|
|
12
|
+
/// Called once per ALLOCATION block in the request.
|
|
13
|
+
function allocate(uint host, bytes32 asset, bytes32 meta, uint amount) internal virtual;
|
|
14
|
+
}
|
|
15
|
+
|
|
10
16
|
/// @title Allocate
|
|
11
17
|
/// @notice Admin command that applies cross-host allocation entries via a virtual hook.
|
|
12
18
|
/// Each ALLOCATION block in the request calls `allocate`. Only callable by the admin account.
|
|
13
|
-
abstract contract Allocate is CommandBase {
|
|
19
|
+
abstract contract Allocate is CommandBase, AllocateHook {
|
|
14
20
|
uint internal immutable allocateId = commandId(NAME);
|
|
15
21
|
|
|
16
22
|
constructor() {
|
|
17
23
|
emit Command(host, NAME, Schemas.Allocation, allocateId, State.Empty, State.Empty, false);
|
|
18
24
|
}
|
|
19
25
|
|
|
20
|
-
/// @dev Override to apply a single allocation entry.
|
|
21
|
-
/// Called once per ALLOCATION block in the request.
|
|
22
|
-
function allocate(uint host, bytes32 asset, bytes32 meta, uint amount) internal virtual;
|
|
23
|
-
|
|
24
26
|
function allocate(CommandContext calldata c) external onlyAdmin(c.account) onlyCommand(allocateId, c.target) returns (bytes memory) {
|
|
25
27
|
(Cur memory request, , ) = cursor(c.request, 1);
|
|
26
28
|
|
|
@@ -8,20 +8,22 @@ string constant NAME = "destroy";
|
|
|
8
8
|
|
|
9
9
|
using Cursors for Cur;
|
|
10
10
|
|
|
11
|
+
abstract contract DestroyHook {
|
|
12
|
+
/// @notice Override to run host teardown or destruction logic.
|
|
13
|
+
/// @param input Cursor over the full request byte stream.
|
|
14
|
+
function destroy(Cur memory input) internal virtual;
|
|
15
|
+
}
|
|
16
|
+
|
|
11
17
|
/// @title Destroy
|
|
12
18
|
/// @notice Admin command that runs host teardown logic via a virtual hook.
|
|
13
19
|
/// The full request is passed to `destroy` as a cursor. Only callable by the admin account.
|
|
14
|
-
abstract contract Destroy is CommandBase {
|
|
20
|
+
abstract contract Destroy is CommandBase, DestroyHook {
|
|
15
21
|
uint internal immutable destroyId = commandId(NAME);
|
|
16
22
|
|
|
17
23
|
constructor(string memory input) {
|
|
18
24
|
emit Command(host, NAME, input, destroyId, State.Empty, State.Empty, false);
|
|
19
25
|
}
|
|
20
26
|
|
|
21
|
-
/// @notice Override to run host teardown or destruction logic.
|
|
22
|
-
/// @param input Cursor over the full request byte stream.
|
|
23
|
-
function destroy(Cur memory input) internal virtual;
|
|
24
|
-
|
|
25
27
|
function destroy(
|
|
26
28
|
CommandContext calldata c
|
|
27
29
|
) external onlyAdmin(c.account) onlyCommand(destroyId, c.target) returns (bytes memory) {
|
package/commands/admin/Init.sol
CHANGED
|
@@ -8,20 +8,22 @@ string constant NAME = "init";
|
|
|
8
8
|
|
|
9
9
|
using Cursors for Cur;
|
|
10
10
|
|
|
11
|
+
abstract contract InitHook {
|
|
12
|
+
/// @notice Override to run host initialization logic.
|
|
13
|
+
/// @param input Cursor over the full request byte stream.
|
|
14
|
+
function init(Cur memory input) internal virtual;
|
|
15
|
+
}
|
|
16
|
+
|
|
11
17
|
/// @title Init
|
|
12
18
|
/// @notice Admin command that runs host initialization logic via a virtual hook.
|
|
13
19
|
/// The full request is passed to `init` as a cursor. Only callable by the admin account.
|
|
14
|
-
abstract contract Init is CommandBase {
|
|
20
|
+
abstract contract Init is CommandBase, InitHook {
|
|
15
21
|
uint internal immutable initId = commandId(NAME);
|
|
16
22
|
|
|
17
23
|
constructor(string memory input) {
|
|
18
24
|
emit Command(host, NAME, input, initId, State.Empty, State.Empty, false);
|
|
19
25
|
}
|
|
20
26
|
|
|
21
|
-
/// @notice Override to run host initialization logic.
|
|
22
|
-
/// @param input Cursor over the full request byte stream.
|
|
23
|
-
function init(Cur memory input) internal virtual;
|
|
24
|
-
|
|
25
27
|
function init(
|
|
26
28
|
CommandContext calldata c
|
|
27
29
|
) external onlyAdmin(c.account) onlyCommand(initId, c.target) returns (bytes memory) {
|
package/core/Host.sol
CHANGED
|
@@ -19,7 +19,7 @@ abstract contract HostDiscovery is HostAnnouncedEvent, IHostDiscovery {
|
|
|
19
19
|
/// @param version Protocol version the host implements.
|
|
20
20
|
/// @param namespace Human-readable namespace string for the host.
|
|
21
21
|
function announceHost(uint id, uint blocknum, uint16 version, string calldata namespace) external {
|
|
22
|
-
emit HostAnnounced(Ids.
|
|
22
|
+
emit HostAnnounced(Ids.matchHost(id, msg.sender), blocknum, version, namespace);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
package/package.json
CHANGED
package/peer/AssetPull.sol
CHANGED
|
@@ -8,35 +8,37 @@ string constant NAME = "peerAssetPull";
|
|
|
8
8
|
|
|
9
9
|
using Cursors for Cur;
|
|
10
10
|
|
|
11
|
+
abstract contract PeerAssetPullHook {
|
|
12
|
+
/// @notice Override to process one incoming amount-based asset pull request from a remote host.
|
|
13
|
+
/// @param peer Host node ID derived from the caller address.
|
|
14
|
+
/// @param asset Requested asset identifier.
|
|
15
|
+
/// @param meta Requested asset metadata slot.
|
|
16
|
+
/// @param amount Requested amount in the asset's native units.
|
|
17
|
+
function peerAssetPull(uint peer, bytes32 asset, bytes32 meta, uint amount) internal virtual;
|
|
18
|
+
}
|
|
19
|
+
|
|
11
20
|
/// @title PeerAssetPull
|
|
12
|
-
/// @notice Peer that pulls requested asset amounts from a remote host into this one.
|
|
13
|
-
/// Each AMOUNT block in the request calls `peerAssetPull(peer, asset, meta, amount)`, where `peer`
|
|
14
|
-
/// is derived from `msg.sender`. Restricted to trusted peers.
|
|
15
|
-
abstract contract PeerAssetPull is PeerBase {
|
|
16
|
-
uint internal immutable peerAssetPullId = peerId(NAME);
|
|
17
|
-
|
|
18
|
-
constructor() {
|
|
19
|
-
emit Peer(host, NAME, Schemas.Amount, peerAssetPullId, false);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/// @notice
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
peerAssetPull(peer, asset, meta, amount);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
assets.complete();
|
|
40
|
-
return "";
|
|
41
|
-
}
|
|
42
|
-
}
|
|
21
|
+
/// @notice Peer that pulls requested asset amounts from a remote host into this one.
|
|
22
|
+
/// Each AMOUNT block in the request calls `peerAssetPull(peer, asset, meta, amount)`, where `peer`
|
|
23
|
+
/// is derived from `msg.sender`. Restricted to trusted peers.
|
|
24
|
+
abstract contract PeerAssetPull is PeerBase, PeerAssetPullHook {
|
|
25
|
+
uint internal immutable peerAssetPullId = peerId(NAME);
|
|
26
|
+
|
|
27
|
+
constructor() {
|
|
28
|
+
emit Peer(host, NAME, Schemas.Amount, peerAssetPullId, false);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/// @notice Execute the asset-pull peer call.
|
|
32
|
+
function peerAssetPull(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
33
|
+
(Cur memory assets, , ) = cursor(request, 1);
|
|
34
|
+
uint peer = caller();
|
|
35
|
+
|
|
36
|
+
while (assets.i < assets.bound) {
|
|
37
|
+
(bytes32 asset, bytes32 meta, uint amount) = assets.unpackAmount();
|
|
38
|
+
peerAssetPull(peer, asset, meta, amount);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
assets.complete();
|
|
42
|
+
return "";
|
|
43
|
+
}
|
|
44
|
+
}
|
package/peer/Pull.sol
CHANGED
|
@@ -8,22 +8,24 @@ string constant NAME = "peerPull";
|
|
|
8
8
|
|
|
9
9
|
using Cursors for Cur;
|
|
10
10
|
|
|
11
|
+
abstract contract PeerPullHook {
|
|
12
|
+
/// @notice Override to process a single incoming block from the pull request.
|
|
13
|
+
/// @param peer Host node ID derived from the caller address.
|
|
14
|
+
/// @param input Cursor positioned at the current input block; advance it before returning.
|
|
15
|
+
function peerPull(uint peer, Cur memory input) internal virtual;
|
|
16
|
+
}
|
|
17
|
+
|
|
11
18
|
/// @title PeerPull
|
|
12
19
|
/// @notice Peer that pulls assets from a remote host into this one.
|
|
13
20
|
/// Each block in the request is dispatched to `peerPull(peer, input)`, where `peer`
|
|
14
21
|
/// is derived from `msg.sender`. Restricted to trusted peers.
|
|
15
|
-
abstract contract PeerPull is PeerBase {
|
|
22
|
+
abstract contract PeerPull is PeerBase, PeerPullHook {
|
|
16
23
|
uint internal immutable peerPullId = peerId(NAME);
|
|
17
24
|
|
|
18
25
|
constructor(string memory input) {
|
|
19
26
|
emit Peer(host, NAME, input, peerPullId, false);
|
|
20
27
|
}
|
|
21
28
|
|
|
22
|
-
/// @notice Override to process a single incoming block from the pull request.
|
|
23
|
-
/// @param peer Host node ID derived from the caller address.
|
|
24
|
-
/// @param input Cursor positioned at the current input block; advance it before returning.
|
|
25
|
-
function peerPull(uint peer, Cur memory input) internal virtual;
|
|
26
|
-
|
|
27
29
|
/// @notice Execute the pull peer call.
|
|
28
30
|
function peerPull(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
29
31
|
(Cur memory input, , ) = cursor(request, 1);
|
package/peer/Push.sol
CHANGED
|
@@ -8,22 +8,24 @@ string constant NAME = "peerPush";
|
|
|
8
8
|
|
|
9
9
|
using Cursors for Cur;
|
|
10
10
|
|
|
11
|
+
abstract contract PeerPushHook {
|
|
12
|
+
/// @notice Override to process a single incoming block from the push request.
|
|
13
|
+
/// @param peer Host node ID derived from the caller address.
|
|
14
|
+
/// @param input Cursor positioned at the current input block; advance it before returning.
|
|
15
|
+
function peerPush(uint peer, Cur memory input) internal virtual;
|
|
16
|
+
}
|
|
17
|
+
|
|
11
18
|
/// @title PeerPush
|
|
12
19
|
/// @notice Peer that receives assets pushed from a remote host into this one.
|
|
13
20
|
/// Each block in the request is dispatched to `peerPush(peer, input)`, where `peer`
|
|
14
21
|
/// is derived from `msg.sender`. Restricted to trusted peers.
|
|
15
|
-
abstract contract PeerPush is PeerBase {
|
|
22
|
+
abstract contract PeerPush is PeerBase, PeerPushHook {
|
|
16
23
|
uint internal immutable peerPushId = peerId(NAME);
|
|
17
24
|
|
|
18
25
|
constructor(string memory input) {
|
|
19
26
|
emit Peer(host, NAME, input, peerPushId, false);
|
|
20
27
|
}
|
|
21
28
|
|
|
22
|
-
/// @notice Override to process a single incoming block from the push request.
|
|
23
|
-
/// @param peer Host node ID derived from the caller address.
|
|
24
|
-
/// @param input Cursor positioned at the current input block; advance it before returning.
|
|
25
|
-
function peerPush(uint peer, Cur memory input) internal virtual;
|
|
26
|
-
|
|
27
29
|
/// @notice Execute the push peer call.
|
|
28
30
|
function peerPush(bytes calldata request) external onlyPeer returns (bytes memory) {
|
|
29
31
|
(Cur memory input, , ) = cursor(request, 1);
|