@rootzero/contracts 0.8.0 → 0.9.1
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 +17 -23
- package/Core.sol +3 -4
- package/Cursors.sol +4 -6
- package/Events.sol +3 -2
- package/Queries.sol +1 -1
- package/README.md +18 -19
- package/Utils.sol +3 -3
- package/blocks/Cursors.sol +1398 -0
- package/blocks/Keys.sol +57 -34
- package/blocks/Schema.sol +108 -126
- package/blocks/Writers.sol +476 -301
- package/commands/Base.sol +32 -22
- package/commands/Burn.sol +5 -5
- package/commands/Credit.sol +8 -8
- package/commands/Debit.sol +5 -5
- package/commands/Deposit.sol +13 -12
- package/commands/Pipe.sol +5 -5
- package/commands/Provision.sol +25 -54
- package/commands/Transfer.sol +11 -21
- package/commands/Withdraw.sol +7 -8
- package/commands/{admin → control}/AllowAssets.sol +9 -8
- package/commands/control/Allowance.sol +43 -0
- package/commands/{admin → control}/Authorize.sol +9 -8
- package/commands/{admin → control}/DenyAssets.sol +9 -8
- package/commands/{admin → control}/Destroy.sol +8 -7
- package/commands/control/Execute.sol +39 -0
- package/commands/{admin → control}/Init.sol +8 -7
- package/commands/{admin → control}/Unauthorize.sol +9 -8
- package/core/Access.sol +40 -36
- package/core/Balances.sol +17 -18
- package/core/{Operation.sol → Calls.sol} +5 -8
- package/core/{CursorBase.sol → Context.sol} +11 -5
- package/core/Host.sol +9 -9
- package/core/Types.sol +86 -0
- package/docs/GETTING_STARTED.md +37 -29
- package/events/Asset.sol +1 -1
- package/events/Command.sol +10 -10
- package/events/Control.sol +31 -0
- package/events/Deposit.sol +3 -4
- package/events/Listing.sol +1 -1
- package/events/Position.sol +21 -0
- package/events/Query.sol +5 -5
- package/events/Remote.sol +24 -0
- package/events/Withdraw.sol +2 -3
- package/package.json +1 -1
- package/queries/Assets.sol +8 -8
- package/queries/Balances.sol +11 -11
- package/queries/Base.sol +2 -3
- package/queries/Positions.sol +25 -19
- package/remote/AllowAssets.sol +39 -0
- package/remote/Allowance.sol +36 -0
- package/remote/AssetPull.sol +44 -0
- package/remote/Base.sol +40 -0
- package/remote/DenyAssets.sol +39 -0
- package/remote/Settle.sol +33 -0
- package/utils/Accounts.sol +14 -13
- package/utils/Assets.sol +77 -57
- package/utils/Ids.sol +34 -34
- package/utils/Layout.sol +4 -4
- package/utils/Utils.sol +10 -0
- package/blocks/cursors/Core.sol +0 -1121
- package/blocks/cursors/Erc1155.sol +0 -149
- package/blocks/cursors/Erc20.sol +0 -130
- package/blocks/cursors/Erc721.sol +0 -66
- package/commands/Create.sol +0 -44
- package/commands/Remove.sol +0 -44
- package/commands/Settle.sol +0 -38
- package/commands/Stake.sol +0 -49
- package/commands/Supply.sol +0 -43
- package/commands/admin/Allocate.sol +0 -43
- package/commands/admin/Relocate.sol +0 -43
- package/core/HostBound.sol +0 -14
- package/events/Erc721.sol +0 -20
- package/events/Peer.sol +0 -24
- package/peer/AllowAssets.sol +0 -39
- package/peer/AssetPull.sol +0 -44
- package/peer/Base.sol +0 -36
- package/peer/DenyAssets.sol +0 -39
- package/peer/Pull.sol +0 -41
- package/peer/Push.sol +0 -47
- package/peer/Settle.sol +0 -34
- package/utils/State.sol +0 -22
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { Cur, Cursors } from "./Core.sol";
|
|
5
|
-
import { Keys } from "../Keys.sol";
|
|
6
|
-
import { Assets } from "../../utils/Assets.sol";
|
|
7
|
-
|
|
8
|
-
using Assets for bytes32;
|
|
9
|
-
|
|
10
|
-
/// @title Erc1155Cursors
|
|
11
|
-
/// @notice ERC-1155-aware cursor helpers layered on top of generic block parsing.
|
|
12
|
-
library Erc1155Cursors {
|
|
13
|
-
/// @notice Validate an AMOUNT block for a specific local ERC-1155 collection and return its token id and amount.
|
|
14
|
-
/// Reverts if the block is not AMOUNT, the asset is not a local ERC-1155, or the collection differs.
|
|
15
|
-
/// @param cur Source cursor.
|
|
16
|
-
/// @param i Byte offset of the AMOUNT block.
|
|
17
|
-
/// @param collection Expected local ERC-1155 collection.
|
|
18
|
-
/// @return meta Asset metadata slot from the block.
|
|
19
|
-
/// @return amount Amount from the block.
|
|
20
|
-
function expectErc1155Amount(Cur memory cur, uint i, address collection) internal view returns (bytes32 meta, uint amount) {
|
|
21
|
-
(uint abs, ) = Cursors.expect(cur, i, Keys.Amount, 96, 96);
|
|
22
|
-
bytes32(msg.data[abs:abs + 32]).matchErc1155(collection);
|
|
23
|
-
meta = bytes32(msg.data[abs + 32:abs + 64]);
|
|
24
|
-
amount = uint(bytes32(msg.data[abs + 64:abs + 96]));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/// @notice Validate a BALANCE block for a specific local ERC-1155 collection and return its token id and amount.
|
|
28
|
-
/// Reverts if the block is not BALANCE, the asset is not a local ERC-1155, or the collection differs.
|
|
29
|
-
/// @param cur Source cursor.
|
|
30
|
-
/// @param i Byte offset of the BALANCE block.
|
|
31
|
-
/// @param collection Expected local ERC-1155 collection.
|
|
32
|
-
/// @return meta Asset metadata slot from the block.
|
|
33
|
-
/// @return amount Balance amount from the block.
|
|
34
|
-
function expectErc1155Balance(Cur memory cur, uint i, address collection) internal view returns (bytes32 meta, uint amount) {
|
|
35
|
-
(uint abs, ) = Cursors.expect(cur, i, Keys.Balance, 96, 96);
|
|
36
|
-
bytes32(msg.data[abs:abs + 32]).matchErc1155(collection);
|
|
37
|
-
meta = bytes32(msg.data[abs + 32:abs + 64]);
|
|
38
|
-
amount = uint(bytes32(msg.data[abs + 64:abs + 96]));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/// @notice Validate a MINIMUM block for a specific local ERC-1155 collection and return its token id and amount.
|
|
42
|
-
/// Reverts if the block is not MINIMUM, the asset is not a local ERC-1155, or the collection differs.
|
|
43
|
-
/// @param cur Source cursor.
|
|
44
|
-
/// @param i Byte offset of the MINIMUM block.
|
|
45
|
-
/// @param collection Expected local ERC-1155 collection.
|
|
46
|
-
/// @return meta Asset metadata slot from the block.
|
|
47
|
-
/// @return amount Minimum amount from the block.
|
|
48
|
-
function expectErc1155Minimum(Cur memory cur, uint i, address collection) internal view returns (bytes32 meta, uint amount) {
|
|
49
|
-
(uint abs, ) = Cursors.expect(cur, i, Keys.Minimum, 96, 96);
|
|
50
|
-
bytes32(msg.data[abs:abs + 32]).matchErc1155(collection);
|
|
51
|
-
meta = bytes32(msg.data[abs + 32:abs + 64]);
|
|
52
|
-
amount = uint(bytes32(msg.data[abs + 64:abs + 96]));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/// @notice Validate a MAXIMUM block for a specific local ERC-1155 collection and return its token id and amount.
|
|
56
|
-
/// Reverts if the block is not MAXIMUM, the asset is not a local ERC-1155, or the collection differs.
|
|
57
|
-
/// @param cur Source cursor.
|
|
58
|
-
/// @param i Byte offset of the MAXIMUM block.
|
|
59
|
-
/// @param collection Expected local ERC-1155 collection.
|
|
60
|
-
/// @return meta Asset metadata slot from the block.
|
|
61
|
-
/// @return amount Maximum amount from the block.
|
|
62
|
-
function expectErc1155Maximum(Cur memory cur, uint i, address collection) internal view returns (bytes32 meta, uint amount) {
|
|
63
|
-
(uint abs, ) = Cursors.expect(cur, i, Keys.Maximum, 96, 96);
|
|
64
|
-
bytes32(msg.data[abs:abs + 32]).matchErc1155(collection);
|
|
65
|
-
meta = bytes32(msg.data[abs + 32:abs + 64]);
|
|
66
|
-
amount = uint(bytes32(msg.data[abs + 64:abs + 96]));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/// @notice Validate a CUSTODY block for a specific local ERC-1155 collection and return its token id and amount.
|
|
70
|
-
/// Reverts if the block is not CUSTODY, the host differs, the asset is not a local ERC-1155, or the collection differs.
|
|
71
|
-
/// @param cur Source cursor.
|
|
72
|
-
/// @param i Byte offset of the CUSTODY block.
|
|
73
|
-
/// @param host Expected host node ID from the block.
|
|
74
|
-
/// @param collection Expected local ERC-1155 collection.
|
|
75
|
-
/// @return meta Asset metadata slot from the block.
|
|
76
|
-
/// @return amount Custodied amount from the block.
|
|
77
|
-
function expectErc1155Custody(
|
|
78
|
-
Cur memory cur,
|
|
79
|
-
uint i,
|
|
80
|
-
uint host,
|
|
81
|
-
address collection
|
|
82
|
-
) internal view returns (bytes32 meta, uint amount) {
|
|
83
|
-
(uint abs, ) = Cursors.expect(cur, i, Keys.Custody, 128, 128);
|
|
84
|
-
if (uint(bytes32(msg.data[abs:abs + 32])) != host) revert Cursors.UnexpectedValue();
|
|
85
|
-
bytes32(msg.data[abs + 32:abs + 64]).matchErc1155(collection);
|
|
86
|
-
meta = bytes32(msg.data[abs + 64:abs + 96]);
|
|
87
|
-
amount = uint(bytes32(msg.data[abs + 96:abs + 128]));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/// @notice Consume an AMOUNT block for a specific local ERC-1155 collection and return its token id and amount.
|
|
91
|
-
/// Reverts if the current block is not AMOUNT, the asset is not a local ERC-1155, or the collection differs.
|
|
92
|
-
/// @param cur Cursor; advanced past the block.
|
|
93
|
-
/// @param collection Expected local ERC-1155 collection.
|
|
94
|
-
/// @return meta Asset metadata slot from the block.
|
|
95
|
-
/// @return amount Amount from the block.
|
|
96
|
-
function requireErc1155Amount(Cur memory cur, address collection) internal view returns (bytes32 meta, uint amount) {
|
|
97
|
-
(meta, amount) = expectErc1155Amount(cur, cur.i, collection);
|
|
98
|
-
cur.i += 104;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/// @notice Consume a BALANCE block for a specific local ERC-1155 collection and return its token id and amount.
|
|
102
|
-
/// Reverts if the current block is not BALANCE, the asset is not a local ERC-1155, or the collection differs.
|
|
103
|
-
/// @param cur Cursor; advanced past the block.
|
|
104
|
-
/// @param collection Expected local ERC-1155 collection.
|
|
105
|
-
/// @return meta Asset metadata slot from the block.
|
|
106
|
-
/// @return amount Balance amount from the block.
|
|
107
|
-
function requireErc1155Balance(Cur memory cur, address collection) internal view returns (bytes32 meta, uint amount) {
|
|
108
|
-
(meta, amount) = expectErc1155Balance(cur, cur.i, collection);
|
|
109
|
-
cur.i += 104;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/// @notice Consume a MINIMUM block for a specific local ERC-1155 collection and return its token id and amount.
|
|
113
|
-
/// Reverts if the current block is not MINIMUM, the asset is not a local ERC-1155, or the collection differs.
|
|
114
|
-
/// @param cur Cursor; advanced past the block.
|
|
115
|
-
/// @param collection Expected local ERC-1155 collection.
|
|
116
|
-
/// @return meta Asset metadata slot from the block.
|
|
117
|
-
/// @return amount Minimum amount from the block.
|
|
118
|
-
function requireErc1155Minimum(Cur memory cur, address collection) internal view returns (bytes32 meta, uint amount) {
|
|
119
|
-
(meta, amount) = expectErc1155Minimum(cur, cur.i, collection);
|
|
120
|
-
cur.i += 104;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/// @notice Consume a MAXIMUM block for a specific local ERC-1155 collection and return its token id and amount.
|
|
124
|
-
/// Reverts if the current block is not MAXIMUM, the asset is not a local ERC-1155, or the collection differs.
|
|
125
|
-
/// @param cur Cursor; advanced past the block.
|
|
126
|
-
/// @param collection Expected local ERC-1155 collection.
|
|
127
|
-
/// @return meta Asset metadata slot from the block.
|
|
128
|
-
/// @return amount Maximum amount from the block.
|
|
129
|
-
function requireErc1155Maximum(Cur memory cur, address collection) internal view returns (bytes32 meta, uint amount) {
|
|
130
|
-
(meta, amount) = expectErc1155Maximum(cur, cur.i, collection);
|
|
131
|
-
cur.i += 104;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/// @notice Consume a CUSTODY block for a specific local ERC-1155 collection and return its token id and amount.
|
|
135
|
-
/// Reverts if the current block is not CUSTODY, the host differs, the asset is not a local ERC-1155, or the collection differs.
|
|
136
|
-
/// @param cur Cursor; advanced past the block.
|
|
137
|
-
/// @param host Expected host node ID from the block.
|
|
138
|
-
/// @param collection Expected local ERC-1155 collection.
|
|
139
|
-
/// @return meta Asset metadata slot from the block.
|
|
140
|
-
/// @return amount Custodied amount from the block.
|
|
141
|
-
function requireErc1155Custody(
|
|
142
|
-
Cur memory cur,
|
|
143
|
-
uint host,
|
|
144
|
-
address collection
|
|
145
|
-
) internal view returns (bytes32 meta, uint amount) {
|
|
146
|
-
(meta, amount) = expectErc1155Custody(cur, cur.i, host, collection);
|
|
147
|
-
cur.i += 136;
|
|
148
|
-
}
|
|
149
|
-
}
|
package/blocks/cursors/Erc20.sol
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { Cur, Cursors } from "./Core.sol";
|
|
5
|
-
import { Keys } from "../Keys.sol";
|
|
6
|
-
import { Assets } from "../../utils/Assets.sol";
|
|
7
|
-
|
|
8
|
-
using Assets for bytes32;
|
|
9
|
-
|
|
10
|
-
/// @title Erc20Cursors
|
|
11
|
-
/// @notice ERC-20-aware cursor helpers layered on top of generic block parsing.
|
|
12
|
-
library Erc20Cursors {
|
|
13
|
-
function erc20AddrAt(uint abs) private view returns (address) {
|
|
14
|
-
return Assets.erc20Addr(bytes32(msg.data[abs:abs + 32]));
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/// @notice Validate an AMOUNT block for any local ERC-20 token and return it.
|
|
18
|
-
/// Reverts if the block is not AMOUNT or the asset is not a local ERC-20.
|
|
19
|
-
/// @param cur Source cursor.
|
|
20
|
-
/// @param i Byte offset of the AMOUNT block.
|
|
21
|
-
/// @return token Local ERC-20 token address extracted from the asset identifier.
|
|
22
|
-
/// @return amount Amount from the block.
|
|
23
|
-
function expectErc20Amount(Cur memory cur, uint i) internal view returns (address token, uint amount) {
|
|
24
|
-
(uint abs, ) = Cursors.expect(cur, i, Keys.Amount, 96, 96);
|
|
25
|
-
token = erc20AddrAt(abs);
|
|
26
|
-
amount = uint(bytes32(msg.data[abs + 64:abs + 96]));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/// @notice Validate a BALANCE block for any local ERC-20 token and return it.
|
|
30
|
-
/// Reverts if the block is not BALANCE or the asset is not a local ERC-20.
|
|
31
|
-
/// @param cur Source cursor.
|
|
32
|
-
/// @param i Byte offset of the BALANCE block.
|
|
33
|
-
/// @return token Local ERC-20 token address extracted from the asset identifier.
|
|
34
|
-
/// @return amount Balance amount from the block.
|
|
35
|
-
function expectErc20Balance(Cur memory cur, uint i) internal view returns (address token, uint amount) {
|
|
36
|
-
(uint abs, ) = Cursors.expect(cur, i, Keys.Balance, 96, 96);
|
|
37
|
-
token = erc20AddrAt(abs);
|
|
38
|
-
amount = uint(bytes32(msg.data[abs + 64:abs + 96]));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/// @notice Validate a MINIMUM block for any local ERC-20 token and return it.
|
|
42
|
-
/// Reverts if the block is not MINIMUM or the asset is not a local ERC-20.
|
|
43
|
-
/// @param cur Source cursor.
|
|
44
|
-
/// @param i Byte offset of the MINIMUM block.
|
|
45
|
-
/// @return token Local ERC-20 token address extracted from the asset identifier.
|
|
46
|
-
/// @return amount Minimum amount from the block.
|
|
47
|
-
function expectErc20Minimum(Cur memory cur, uint i) internal view returns (address token, uint amount) {
|
|
48
|
-
(uint abs, ) = Cursors.expect(cur, i, Keys.Minimum, 96, 96);
|
|
49
|
-
token = erc20AddrAt(abs);
|
|
50
|
-
amount = uint(bytes32(msg.data[abs + 64:abs + 96]));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/// @notice Consume a MINIMUM block for any local ERC-20 token and return it.
|
|
54
|
-
/// Reverts if the current block is not MINIMUM or the asset is not a local ERC-20.
|
|
55
|
-
/// @param cur Cursor; advanced past the block.
|
|
56
|
-
/// @return token Local ERC-20 token address extracted from the asset identifier.
|
|
57
|
-
/// @return amount Minimum amount from the block.
|
|
58
|
-
function requireErc20Minimum(Cur memory cur) internal view returns (address token, uint amount) {
|
|
59
|
-
(token, amount) = expectErc20Minimum(cur, cur.i);
|
|
60
|
-
cur.i += 104;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/// @notice Validate a MAXIMUM block for any local ERC-20 token and return it.
|
|
64
|
-
/// Reverts if the block is not MAXIMUM or the asset is not a local ERC-20.
|
|
65
|
-
/// @param cur Source cursor.
|
|
66
|
-
/// @param i Byte offset of the MAXIMUM block.
|
|
67
|
-
/// @return token Local ERC-20 token address extracted from the asset identifier.
|
|
68
|
-
/// @return amount Maximum amount from the block.
|
|
69
|
-
function expectErc20Maximum(Cur memory cur, uint i) internal view returns (address token, uint amount) {
|
|
70
|
-
(uint abs, ) = Cursors.expect(cur, i, Keys.Maximum, 96, 96);
|
|
71
|
-
token = erc20AddrAt(abs);
|
|
72
|
-
amount = uint(bytes32(msg.data[abs + 64:abs + 96]));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/// @notice Validate a CUSTODY block for any local ERC-20 token and return it.
|
|
76
|
-
/// Reverts if the block is not CUSTODY or the asset is not a local ERC-20.
|
|
77
|
-
/// @param cur Source cursor.
|
|
78
|
-
/// @param i Byte offset of the CUSTODY block.
|
|
79
|
-
/// @param host Expected host node ID from the block.
|
|
80
|
-
/// @return token Local ERC-20 token address extracted from the asset identifier.
|
|
81
|
-
/// @return amount Custodied amount from the block.
|
|
82
|
-
function expectErc20Custody(Cur memory cur, uint i, uint host) internal view returns (address token, uint amount) {
|
|
83
|
-
(uint abs, ) = Cursors.expect(cur, i, Keys.Custody, 128, 128);
|
|
84
|
-
if (uint(bytes32(msg.data[abs:abs + 32])) != host) revert Cursors.UnexpectedValue();
|
|
85
|
-
token = erc20AddrAt(abs + 32);
|
|
86
|
-
amount = uint(bytes32(msg.data[abs + 96:abs + 128]));
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/// @notice Consume an AMOUNT block for any local ERC-20 token and return it.
|
|
90
|
-
/// Reverts if the current block is not AMOUNT or the asset is not a local ERC-20.
|
|
91
|
-
/// @param cur Cursor; advanced past the block.
|
|
92
|
-
/// @return token Local ERC-20 token address extracted from the asset identifier.
|
|
93
|
-
/// @return amount Amount from the block.
|
|
94
|
-
function requireErc20Amount(Cur memory cur) internal view returns (address token, uint amount) {
|
|
95
|
-
(token, amount) = expectErc20Amount(cur, cur.i);
|
|
96
|
-
cur.i += 104;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/// @notice Consume a BALANCE block for any local ERC-20 token and return it.
|
|
100
|
-
/// Reverts if the current block is not BALANCE or the asset is not a local ERC-20.
|
|
101
|
-
/// @param cur Cursor; advanced past the block.
|
|
102
|
-
/// @return token Local ERC-20 token address extracted from the asset identifier.
|
|
103
|
-
/// @return amount Balance amount from the block.
|
|
104
|
-
function requireErc20Balance(Cur memory cur) internal view returns (address token, uint amount) {
|
|
105
|
-
(token, amount) = expectErc20Balance(cur, cur.i);
|
|
106
|
-
cur.i += 104;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/// @notice Consume a MAXIMUM block for any local ERC-20 token and return it.
|
|
110
|
-
/// Reverts if the current block is not MAXIMUM or the asset is not a local ERC-20.
|
|
111
|
-
/// @param cur Cursor; advanced past the block.
|
|
112
|
-
/// @return token Local ERC-20 token address extracted from the asset identifier.
|
|
113
|
-
/// @return amount Maximum amount from the block.
|
|
114
|
-
function requireErc20Maximum(Cur memory cur) internal view returns (address token, uint amount) {
|
|
115
|
-
(token, amount) = expectErc20Maximum(cur, cur.i);
|
|
116
|
-
cur.i += 104;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/// @notice Consume a CUSTODY block for any local ERC-20 token and return it.
|
|
120
|
-
/// Reverts if the current block is not CUSTODY or the asset is not a local ERC-20.
|
|
121
|
-
/// @param cur Cursor; advanced past the block.
|
|
122
|
-
/// @param host Expected host node ID from the block.
|
|
123
|
-
/// @return token Local ERC-20 token address extracted from the asset identifier.
|
|
124
|
-
/// @return amount Custodied amount from the block.
|
|
125
|
-
function requireErc20Custody(Cur memory cur, uint host) internal view returns (address token, uint amount) {
|
|
126
|
-
(token, amount) = expectErc20Custody(cur, cur.i, host);
|
|
127
|
-
cur.i += 136;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { Cur, Cursors } from "./Core.sol";
|
|
5
|
-
import { Keys } from "../Keys.sol";
|
|
6
|
-
import { Assets } from "../../utils/Assets.sol";
|
|
7
|
-
|
|
8
|
-
using Assets for bytes32;
|
|
9
|
-
|
|
10
|
-
/// @title Erc721Cursors
|
|
11
|
-
/// @notice ERC-721-aware cursor helpers layered on top of generic block parsing.
|
|
12
|
-
library Erc721Cursors {
|
|
13
|
-
/// @notice Validate a BALANCE block for a specific local ERC-721 collection and return its metadata.
|
|
14
|
-
/// Reverts if the block is not BALANCE, the asset is not a local ERC-721, the collection differs, or the amount is not 1.
|
|
15
|
-
/// @param cur Source cursor.
|
|
16
|
-
/// @param i Byte offset of the BALANCE block.
|
|
17
|
-
/// @param collection Expected local ERC-721 collection.
|
|
18
|
-
/// @return meta Asset metadata slot from the block.
|
|
19
|
-
function expectErc721Balance(Cur memory cur, uint i, address collection) internal view returns (bytes32 meta) {
|
|
20
|
-
(uint abs, ) = Cursors.expect(cur, i, Keys.Balance, 96, 96);
|
|
21
|
-
bytes32(msg.data[abs:abs + 32]).matchErc721(collection);
|
|
22
|
-
meta = bytes32(msg.data[abs + 32:abs + 64]);
|
|
23
|
-
if (uint(bytes32(msg.data[abs + 64:abs + 96])) != 1) revert Cursors.UnexpectedValue();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/// @notice Validate a CUSTODY block for a specific local ERC-721 collection and return its metadata.
|
|
27
|
-
/// Reverts if the block is not CUSTODY, the host differs, the asset is not a local ERC-721, the collection differs, or the amount is not 1.
|
|
28
|
-
/// @param cur Source cursor.
|
|
29
|
-
/// @param i Byte offset of the CUSTODY block.
|
|
30
|
-
/// @param host Expected host node ID from the block.
|
|
31
|
-
/// @param collection Expected local ERC-721 collection.
|
|
32
|
-
/// @return meta Asset metadata slot from the block.
|
|
33
|
-
function expectErc721Custody(
|
|
34
|
-
Cur memory cur,
|
|
35
|
-
uint i,
|
|
36
|
-
uint host,
|
|
37
|
-
address collection
|
|
38
|
-
) internal view returns (bytes32 meta) {
|
|
39
|
-
(uint abs, ) = Cursors.expect(cur, i, Keys.Custody, 128, 128);
|
|
40
|
-
if (uint(bytes32(msg.data[abs:abs + 32])) != host) revert Cursors.UnexpectedValue();
|
|
41
|
-
bytes32(msg.data[abs + 32:abs + 64]).matchErc721(collection);
|
|
42
|
-
meta = bytes32(msg.data[abs + 64:abs + 96]);
|
|
43
|
-
if (uint(bytes32(msg.data[abs + 96:abs + 128])) != 1) revert Cursors.UnexpectedValue();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/// @notice Consume a BALANCE block for a specific local ERC-721 collection and return its metadata.
|
|
47
|
-
/// Reverts if the current block is not BALANCE, the asset is not a local ERC-721, the collection differs, or the amount is not 1.
|
|
48
|
-
/// @param cur Cursor; advanced past the block.
|
|
49
|
-
/// @param collection Expected local ERC-721 collection.
|
|
50
|
-
/// @return meta Asset metadata slot from the block.
|
|
51
|
-
function requireErc721Balance(Cur memory cur, address collection) internal view returns (bytes32 meta) {
|
|
52
|
-
meta = expectErc721Balance(cur, cur.i, collection);
|
|
53
|
-
cur.i += 104;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/// @notice Consume a CUSTODY block for a specific local ERC-721 collection and return its metadata.
|
|
57
|
-
/// Reverts if the current block is not CUSTODY, the host differs, the asset is not a local ERC-721, the collection differs, or the amount is not 1.
|
|
58
|
-
/// @param cur Cursor; advanced past the block.
|
|
59
|
-
/// @param host Expected host node ID from the block.
|
|
60
|
-
/// @param collection Expected local ERC-721 collection.
|
|
61
|
-
/// @return meta Asset metadata slot from the block.
|
|
62
|
-
function requireErc721Custody(Cur memory cur, uint host, address collection) internal view returns (bytes32 meta) {
|
|
63
|
-
meta = expectErc721Custody(cur, cur.i, host, collection);
|
|
64
|
-
cur.i += 136;
|
|
65
|
-
}
|
|
66
|
-
}
|
package/commands/Create.sol
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { CommandBase, CommandContext, State } from "./Base.sol";
|
|
5
|
-
import { Cursors, Cur } from "../Cursors.sol";
|
|
6
|
-
|
|
7
|
-
string constant NAME = "create";
|
|
8
|
-
|
|
9
|
-
using Cursors for Cur;
|
|
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
|
-
|
|
17
|
-
/// @title Create
|
|
18
|
-
/// @notice Generic command that creates or initializes objects via a virtual hook.
|
|
19
|
-
/// The request schema is constructor-defined; `create` is called once per top-level group.
|
|
20
|
-
/// Produces no output state.
|
|
21
|
-
abstract contract Create is CommandBase, CreateHook {
|
|
22
|
-
uint internal immutable createId = commandId(NAME);
|
|
23
|
-
|
|
24
|
-
constructor(string memory input) {
|
|
25
|
-
emit Command(host, NAME, input, createId, State.Empty, State.Empty, false);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function create(CommandContext calldata c) external onlyCommand(createId, c.target) returns (bytes memory) {
|
|
29
|
-
(Cur memory request, , ) = cursor(c.request, 1);
|
|
30
|
-
|
|
31
|
-
while (request.i < request.bound) {
|
|
32
|
-
create(c.account, request);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
request.complete();
|
|
36
|
-
return "";
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
package/commands/Remove.sol
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { CommandBase, CommandContext, State } from "./Base.sol";
|
|
5
|
-
import { Cursors, Cur } from "../Cursors.sol";
|
|
6
|
-
|
|
7
|
-
string constant NAME = "remove";
|
|
8
|
-
|
|
9
|
-
using Cursors for Cur;
|
|
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
|
-
|
|
17
|
-
/// @title Remove
|
|
18
|
-
/// @notice Generic command that removes or dismantles objects via a virtual hook.
|
|
19
|
-
/// The request schema is constructor-defined; `remove` is called once per top-level group.
|
|
20
|
-
/// Produces no output state.
|
|
21
|
-
abstract contract Remove is CommandBase, RemoveHook {
|
|
22
|
-
uint internal immutable removeId = commandId(NAME);
|
|
23
|
-
|
|
24
|
-
constructor(string memory input) {
|
|
25
|
-
emit Command(host, NAME, input, removeId, State.Empty, State.Empty, false);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function remove(CommandContext calldata c) external onlyCommand(removeId, c.target) returns (bytes memory) {
|
|
29
|
-
(Cur memory request, , ) = cursor(c.request, 1);
|
|
30
|
-
|
|
31
|
-
while (request.i < request.bound) {
|
|
32
|
-
remove(c.account, request);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
request.complete();
|
|
36
|
-
return "";
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
package/commands/Settle.sol
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { CommandContext, CommandBase, State } from "./Base.sol";
|
|
5
|
-
import { Cursors, Cur, Tx } from "../Cursors.sol";
|
|
6
|
-
import { TransferHook } from "./Transfer.sol";
|
|
7
|
-
using Cursors for Cur;
|
|
8
|
-
|
|
9
|
-
string constant NAME = "settle";
|
|
10
|
-
|
|
11
|
-
/// @title Settle
|
|
12
|
-
/// @notice Command that consumes each TRANSACTION state block and settles it through the shared transfer hook.
|
|
13
|
-
/// Produces no output state.
|
|
14
|
-
abstract contract Settle is CommandBase, TransferHook {
|
|
15
|
-
uint internal immutable settleId = commandId(NAME);
|
|
16
|
-
|
|
17
|
-
constructor() {
|
|
18
|
-
emit Command(host, NAME, "", settleId, State.Transactions, State.Empty, false);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function settle(CommandContext calldata c) external onlyCommand(settleId, c.target) returns (bytes memory) {
|
|
22
|
-
(Cur memory state, , ) = cursor(c.state, 1);
|
|
23
|
-
|
|
24
|
-
while (state.i < state.bound) {
|
|
25
|
-
Tx memory value = state.unpackTxValue();
|
|
26
|
-
transfer(value);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
state.complete();
|
|
30
|
-
return "";
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
package/commands/Stake.sol
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { CommandContext, CommandBase, State } from "./Base.sol";
|
|
5
|
-
import { HostAmount, Cur, Cursors } from "../Cursors.sol";
|
|
6
|
-
|
|
7
|
-
string constant SCTP = "stakeCustodyToPosition";
|
|
8
|
-
|
|
9
|
-
using Cursors for Cur;
|
|
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
|
-
|
|
17
|
-
/// @title StakeCustodyToPosition
|
|
18
|
-
/// @notice Command that stakes CUSTODY state positions into a non-balance target
|
|
19
|
-
/// described by the request stream. Produces no output state.
|
|
20
|
-
abstract contract StakeCustodyToPosition is CommandBase, StakeCustodyToPositionHook {
|
|
21
|
-
uint internal immutable stakeCustodyToPositionId = commandId(SCTP);
|
|
22
|
-
|
|
23
|
-
constructor(string memory input) {
|
|
24
|
-
emit Command(host, SCTP, input, stakeCustodyToPositionId, State.Custodies, State.Empty, false);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function stakeCustodyToPosition(
|
|
28
|
-
CommandContext calldata c
|
|
29
|
-
) external onlyCommand(stakeCustodyToPositionId, c.target) returns (bytes memory) {
|
|
30
|
-
(Cur memory state, , ) = cursor(c.state, 1);
|
|
31
|
-
Cur memory request = cursor(c.request);
|
|
32
|
-
|
|
33
|
-
while (state.i < state.bound) {
|
|
34
|
-
HostAmount memory custody = state.unpackCustodyValue();
|
|
35
|
-
stakeCustodyToPosition(c.account, custody, request);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
state.complete();
|
|
39
|
-
return "";
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
package/commands/Supply.sol
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import {CommandBase, CommandContext, State} from "./Base.sol";
|
|
5
|
-
import {Cursors, Cur, HostAmount} from "../Cursors.sol";
|
|
6
|
-
string constant NAME = "supply";
|
|
7
|
-
|
|
8
|
-
using Cursors for Cur;
|
|
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
|
-
|
|
18
|
-
/// @title Supply
|
|
19
|
-
/// @notice Command that processes each CUSTODY state block through a virtual hook.
|
|
20
|
-
/// Used to move assets out of cross-host custody positions (e.g. to settle or redeem them).
|
|
21
|
-
/// Produces no output state.
|
|
22
|
-
abstract contract Supply is CommandBase, SupplyHook {
|
|
23
|
-
uint internal immutable supplyId = commandId(NAME);
|
|
24
|
-
|
|
25
|
-
constructor() {
|
|
26
|
-
emit Command(host, NAME, "", supplyId, State.Custodies, State.Empty, false);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/// @notice Execute the supply command.
|
|
30
|
-
function supply(CommandContext calldata c) external onlyCommand(supplyId, c.target) returns (bytes memory) {
|
|
31
|
-
(Cur memory state, , ) = cursor(c.state, 1);
|
|
32
|
-
|
|
33
|
-
while (state.i < state.bound) {
|
|
34
|
-
HostAmount memory value = state.unpackCustodyValue();
|
|
35
|
-
supply(c.account, value);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
state.complete();
|
|
39
|
-
return "";
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { CommandBase, CommandContext, State } from "../Base.sol";
|
|
5
|
-
import { Cursors, Cur, Schemas } from "../../Cursors.sol";
|
|
6
|
-
using Cursors for Cur;
|
|
7
|
-
|
|
8
|
-
string constant NAME = "allocate";
|
|
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
|
-
|
|
16
|
-
/// @title Allocate
|
|
17
|
-
/// @notice Admin command that applies cross-host allocation entries via a virtual hook.
|
|
18
|
-
/// Each ALLOCATION block in the request calls `allocate`. Only callable by the admin account.
|
|
19
|
-
abstract contract Allocate is CommandBase, AllocateHook {
|
|
20
|
-
uint internal immutable allocateId = commandId(NAME);
|
|
21
|
-
|
|
22
|
-
constructor() {
|
|
23
|
-
emit Command(host, NAME, Schemas.Allocation, allocateId, State.Empty, State.Empty, false);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function allocate(CommandContext calldata c) external onlyAdmin(c.account) onlyCommand(allocateId, c.target) returns (bytes memory) {
|
|
27
|
-
(Cur memory request, , ) = cursor(c.request, 1);
|
|
28
|
-
|
|
29
|
-
while (request.i < request.bound) {
|
|
30
|
-
(uint host, bytes32 asset, bytes32 meta, uint amount) = request.unpackAllocation();
|
|
31
|
-
allocate(host, asset, meta, amount);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
request.complete();
|
|
35
|
-
return "";
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import { CommandContext, CommandPayable, State } from "../Base.sol";
|
|
5
|
-
import { Cursors, Cur, Schemas } from "../../Cursors.sol";
|
|
6
|
-
import { Budget, Values } from "../../utils/Value.sol";
|
|
7
|
-
using Cursors for Cur;
|
|
8
|
-
|
|
9
|
-
string constant NAME = "relocatePayable";
|
|
10
|
-
|
|
11
|
-
/// @title RelocatePayable
|
|
12
|
-
/// @notice Admin command that forwards native value (ETH) to one or more destination hosts.
|
|
13
|
-
/// Each FUNDING block in the request specifies a target host node ID and an amount to forward.
|
|
14
|
-
/// Only callable by the admin account.
|
|
15
|
-
abstract contract RelocatePayable is CommandPayable {
|
|
16
|
-
uint internal immutable relocatePayableId = commandId(NAME);
|
|
17
|
-
|
|
18
|
-
constructor() {
|
|
19
|
-
emit Command(host, NAME, Schemas.Funding, relocatePayableId, State.Empty, State.Empty, true);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function relocatePayable(
|
|
23
|
-
CommandContext calldata c
|
|
24
|
-
) external payable onlyAdmin(c.account) onlyCommand(relocatePayableId, c.target) returns (bytes memory) {
|
|
25
|
-
(Cur memory request, , ) = cursor(c.request, 1);
|
|
26
|
-
Budget memory budget = Values.fromMsg();
|
|
27
|
-
|
|
28
|
-
while (request.i < request.bound) {
|
|
29
|
-
(uint peer, uint amount) = request.unpackFunding();
|
|
30
|
-
callTo(peer, Values.use(budget, amount), "");
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
request.complete();
|
|
34
|
-
settleValue(c.account, budget);
|
|
35
|
-
return "";
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
package/core/HostBound.sol
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
-
pragma solidity ^0.8.33;
|
|
3
|
-
|
|
4
|
-
import {Assets} from "../utils/Assets.sol";
|
|
5
|
-
import {Ids} from "../utils/Ids.sol";
|
|
6
|
-
|
|
7
|
-
/// @title HostBound
|
|
8
|
-
/// @notice Minimal base for contracts that need host-scoped identity constants.
|
|
9
|
-
abstract contract HostBound {
|
|
10
|
-
/// @dev This contract's host node ID, set to `Ids.toHost(address(this))` at construction.
|
|
11
|
-
uint public immutable host = Ids.toHost(address(this));
|
|
12
|
-
/// @dev Asset ID for the native chain value (ETH), bound to the current chain at deployment.
|
|
13
|
-
bytes32 internal immutable valueAsset = Assets.toValue();
|
|
14
|
-
}
|