@rootzero/contracts 1.4.0 → 1.6.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 +40 -0
- package/Core.sol +4 -2
- package/Endpoints.sol +5 -3
- package/Events.sol +2 -1
- package/README.md +58 -31
- package/Utils.sol +4 -3
- package/blocks/Cursors.sol +107 -143
- package/blocks/Keys.sol +15 -15
- package/blocks/Schema.sol +27 -28
- package/blocks/Writers.sol +26 -33
- package/commands/Base.sol +2 -2
- package/commands/Burn.sol +3 -4
- package/commands/Credit.sol +3 -4
- package/commands/Debit.sol +4 -5
- package/commands/Deposit.sol +8 -10
- package/commands/Payout.sol +3 -6
- package/commands/Withdraw.sol +3 -4
- package/commands/admin/AllowAssets.sol +7 -9
- package/commands/admin/Allowance.sol +5 -7
- package/commands/admin/Appoint.sol +2 -3
- package/commands/admin/Authorize.sol +2 -3
- package/commands/admin/Base.sol +9 -0
- package/commands/admin/DenyAssets.sol +7 -9
- package/commands/admin/Destroy.sol +2 -3
- package/commands/admin/Dismiss.sol +2 -3
- package/commands/admin/Execute.sol +4 -5
- package/commands/admin/Init.sol +2 -3
- package/commands/admin/Label.sol +2 -3
- package/commands/admin/Unauthorize.sol +2 -3
- package/core/Access.sol +2 -2
- package/core/Balances.sol +10 -11
- package/core/Calls.sol +7 -7
- package/core/Commitments.sol +19 -0
- package/core/Escrows.sol +34 -0
- package/core/Host.sol +2 -2
- package/core/Runtime.sol +11 -6
- package/core/Types.sol +0 -14
- package/docs/Schema.md +29 -10
- package/events/Asset.sol +17 -3
- package/events/Balance.sol +2 -3
- package/events/Commitment.sol +19 -0
- package/events/Locked.sol +2 -3
- package/events/Position.sol +2 -3
- package/events/Received.sol +2 -3
- package/events/Spent.sol +2 -3
- package/events/Unlocked.sol +2 -3
- package/guards/Base.sol +4 -4
- package/package.json +1 -1
- package/peer/AllowAssets.sol +3 -3
- package/peer/Allowance.sol +2 -2
- package/peer/Base.sol +4 -4
- package/peer/Credit.sol +10 -10
- package/peer/Debit.sol +10 -10
- package/peer/DenyAssets.sol +3 -3
- package/peer/Recover.sol +51 -0
- package/peer/Redeem.sol +48 -0
- package/peer/Settle.sol +3 -3
- package/queries/Assets.sol +7 -8
- package/queries/Balances.sol +8 -9
- package/queries/Base.sol +4 -4
- package/queries/Positions.sol +4 -6
- package/utils/Accounts.sol +76 -58
- package/utils/Assets.sol +55 -115
- package/utils/Ids.sol +33 -233
- package/utils/Layout.sol +11 -17
- package/utils/Nodes.sol +263 -0
- package/utils/Utils.sol +9 -24
- package/peer/BalancePull.sol +0 -49
package/blocks/Keys.sol
CHANGED
|
@@ -9,19 +9,19 @@ library Keys {
|
|
|
9
9
|
bytes4 constant Empty = bytes4(0);
|
|
10
10
|
/// @dev Wildcard key used in discovery when any block stream is accepted.
|
|
11
11
|
bytes4 constant Any = 0xffffffff;
|
|
12
|
-
/// @dev Input amount - (bytes32 asset,
|
|
12
|
+
/// @dev Input amount - (bytes32 asset, uint amount)
|
|
13
13
|
bytes4 constant Amount = bytes4(keccak256("#amount"));
|
|
14
|
-
/// @dev Ledger balance - (bytes32 asset,
|
|
14
|
+
/// @dev Ledger balance - (bytes32 asset, uint amount)
|
|
15
15
|
bytes4 constant Balance = bytes4(keccak256("#balance"));
|
|
16
|
-
/// @dev Balance constraint - (bytes32 asset,
|
|
16
|
+
/// @dev Balance constraint - (bytes32 asset, uint min, uint max)
|
|
17
17
|
bytes4 constant BalanceLimit = bytes4(keccak256("#balanceLimit"));
|
|
18
|
-
/// @dev Host-scoped request amount - (uint host, bytes32 asset,
|
|
18
|
+
/// @dev Host-scoped request amount - (uint host, bytes32 asset, uint amount)
|
|
19
19
|
bytes4 constant Allocation = bytes4(keccak256("#allocation"));
|
|
20
|
-
/// @dev Host-scoped allowance cap - (uint host, bytes32 asset,
|
|
20
|
+
/// @dev Host-scoped allowance cap - (uint host, bytes32 asset, uint amount)
|
|
21
21
|
bytes4 constant Allowance = bytes4(keccak256("#allowance"));
|
|
22
|
-
/// @dev Cross-host custody state - (uint host, bytes32 asset,
|
|
22
|
+
/// @dev Cross-host custody state - (uint host, bytes32 asset, uint amount)
|
|
23
23
|
bytes4 constant Custody = bytes4(keccak256("#custody"));
|
|
24
|
-
/// @dev Cross-host custody constraint - (uint host, bytes32 asset,
|
|
24
|
+
/// @dev Cross-host custody constraint - (uint host, bytes32 asset, uint min, uint max)
|
|
25
25
|
bytes4 constant CustodyLimit = bytes4(keccak256("#custodyLimit"));
|
|
26
26
|
/// @dev Fee amount - (uint amount)
|
|
27
27
|
bytes4 constant Fee = bytes4(keccak256("#fee"));
|
|
@@ -37,7 +37,7 @@ library Keys {
|
|
|
37
37
|
bytes4 constant String = bytes4(keccak256("#string"));
|
|
38
38
|
/// @dev Account identifier - (bytes32 account)
|
|
39
39
|
bytes4 constant Account = bytes4(keccak256("#account"));
|
|
40
|
-
/// @dev Transfer record passed through the pipeline - (bytes32 from, bytes32 to, bytes32 asset,
|
|
40
|
+
/// @dev Transfer record passed through the pipeline - (bytes32 from, bytes32 to, bytes32 asset, uint amount)
|
|
41
41
|
bytes4 constant Transaction = bytes4(keccak256("#transaction"));
|
|
42
42
|
/// @dev Sub-command invocation - (uint target, uint resources, #bytes as request)
|
|
43
43
|
bytes4 constant Step = bytes4(keccak256("#step"));
|
|
@@ -53,7 +53,7 @@ library Keys {
|
|
|
53
53
|
bytes4 constant Pipe = bytes4(keccak256("#pipe"));
|
|
54
54
|
/// @dev Authentication proof - (uint cid, uint deadline, #bytes as proof); must appear last in its segment
|
|
55
55
|
bytes4 constant Auth = bytes4(keccak256("#auth"));
|
|
56
|
-
/// @dev Asset descriptor without amount - (bytes32 asset
|
|
56
|
+
/// @dev Asset descriptor without amount - (bytes32 asset)
|
|
57
57
|
bytes4 constant Asset = bytes4(keccak256("#asset"));
|
|
58
58
|
/// @dev Node identifier - (uint id)
|
|
59
59
|
bytes4 constant Node = bytes4(keccak256("#node"));
|
|
@@ -64,16 +64,16 @@ library Keys {
|
|
|
64
64
|
|
|
65
65
|
/// @dev Structural status form - (uint code)
|
|
66
66
|
bytes4 constant Status = bytes4(keccak256("#status"));
|
|
67
|
-
/// @dev Structural asset amount form - (bytes32 asset,
|
|
67
|
+
/// @dev Structural asset amount form - (bytes32 asset, uint amount)
|
|
68
68
|
bytes4 constant AssetAmount = bytes4(keccak256("#assetAmount"));
|
|
69
|
-
/// @dev Structural account asset form - (bytes32 account, bytes32 asset
|
|
69
|
+
/// @dev Structural account asset form - (bytes32 account, bytes32 asset)
|
|
70
70
|
bytes4 constant AccountAsset = bytes4(keccak256("#accountAsset"));
|
|
71
|
-
/// @dev Structural account amount form - (bytes32 account, bytes32 asset,
|
|
71
|
+
/// @dev Structural account amount form - (bytes32 account, bytes32 asset, uint amount)
|
|
72
72
|
bytes4 constant AccountAmount = bytes4(keccak256("#accountAmount"));
|
|
73
|
-
/// @dev Structural host amount form - (uint host, bytes32 asset,
|
|
73
|
+
/// @dev Structural host amount form - (uint host, bytes32 asset, uint amount)
|
|
74
74
|
bytes4 constant HostAmount = bytes4(keccak256("#hostAmount"));
|
|
75
|
-
/// @dev Structural host account asset form - (uint host, bytes32 account, bytes32 asset
|
|
75
|
+
/// @dev Structural host account asset form - (uint host, bytes32 account, bytes32 asset)
|
|
76
76
|
bytes4 constant HostAccountAsset = bytes4(keccak256("#hostAccountAsset"));
|
|
77
|
-
/// @dev Structural host account amount form - (uint host, bytes32 account, bytes32 asset,
|
|
77
|
+
/// @dev Structural host account amount form - (uint host, bytes32 account, bytes32 asset, uint amount)
|
|
78
78
|
bytes4 constant HostAccountAmount = bytes4(keccak256("#hostAccountAmount"));
|
|
79
79
|
}
|
package/blocks/Schema.sol
CHANGED
|
@@ -59,15 +59,15 @@ library Schemas {
|
|
|
59
59
|
string constant Unit = "#unit";
|
|
60
60
|
string constant Node = "#node { uint id }";
|
|
61
61
|
string constant Account = "#account { bytes32 account }";
|
|
62
|
-
string constant Asset = "#asset { bytes32 asset
|
|
63
|
-
string constant Amount = "#amount { bytes32 asset,
|
|
64
|
-
string constant Balance = "#balance { bytes32 asset,
|
|
65
|
-
string constant BalanceLimit = "#balanceLimit { bytes32 asset,
|
|
66
|
-
string constant Custody = "#custody { uint host, bytes32 asset,
|
|
67
|
-
string constant CustodyLimit = "#custodyLimit { uint host, bytes32 asset,
|
|
68
|
-
string constant Allocation = "#allocation { uint host, bytes32 asset,
|
|
69
|
-
string constant Allowance = "#allowance { uint host, bytes32 asset,
|
|
70
|
-
string constant Transaction = "#transaction { bytes32 from, bytes32 to, bytes32 asset,
|
|
62
|
+
string constant Asset = "#asset { bytes32 asset }";
|
|
63
|
+
string constant Amount = "#amount { bytes32 asset, uint amount }";
|
|
64
|
+
string constant Balance = "#balance { bytes32 asset, uint amount }";
|
|
65
|
+
string constant BalanceLimit = "#balanceLimit { bytes32 asset, uint min, uint max }";
|
|
66
|
+
string constant Custody = "#custody { uint host, bytes32 asset, uint amount }";
|
|
67
|
+
string constant CustodyLimit = "#custodyLimit { uint host, bytes32 asset, uint min, uint max }";
|
|
68
|
+
string constant Allocation = "#allocation { uint host, bytes32 asset, uint amount }";
|
|
69
|
+
string constant Allowance = "#allowance { uint host, bytes32 asset, uint amount }";
|
|
70
|
+
string constant Transaction = "#transaction { bytes32 from, bytes32 to, bytes32 asset, uint amount }";
|
|
71
71
|
string constant Context = "#context { bytes32 account, #bytes as state, #bytes as request }";
|
|
72
72
|
string constant Pipe = "#pipe { uint resources, #context { bytes32 account, #bytes as state, #bytes as steps } }";
|
|
73
73
|
string constant Call = "#call { uint target, uint resources, #bytes as payload }";
|
|
@@ -90,13 +90,12 @@ library Schemas {
|
|
|
90
90
|
/// These describe payload form without assigning command or query semantics.
|
|
91
91
|
library Forms {
|
|
92
92
|
string constant Status = "#status { uint code }";
|
|
93
|
-
string constant AssetAmount = "#assetAmount { bytes32 asset,
|
|
94
|
-
string constant AccountAsset = "#accountAsset { bytes32 account, bytes32 asset
|
|
95
|
-
string constant AccountAmount = "#accountAmount { bytes32 account, bytes32 asset,
|
|
96
|
-
string constant HostAmount = "#hostAmount { uint host, bytes32 asset,
|
|
97
|
-
string constant HostAccountAsset = "#hostAccountAsset { uint host, bytes32 account, bytes32 asset
|
|
98
|
-
string constant HostAccountAmount =
|
|
99
|
-
"#hostAccountAmount { uint host, bytes32 account, bytes32 asset, bytes32 meta, uint amount }";
|
|
93
|
+
string constant AssetAmount = "#assetAmount { bytes32 asset, uint amount }";
|
|
94
|
+
string constant AccountAsset = "#accountAsset { bytes32 account, bytes32 asset }";
|
|
95
|
+
string constant AccountAmount = "#accountAmount { bytes32 account, bytes32 asset, uint amount }";
|
|
96
|
+
string constant HostAmount = "#hostAmount { uint host, bytes32 asset, uint amount }";
|
|
97
|
+
string constant HostAccountAsset = "#hostAccountAsset { uint host, bytes32 account, bytes32 asset }";
|
|
98
|
+
string constant HostAccountAmount = "#hostAccountAmount { uint host, bytes32 account, bytes32 asset, uint amount }";
|
|
100
99
|
}
|
|
101
100
|
|
|
102
101
|
/// @title Sizes
|
|
@@ -122,20 +121,20 @@ library Sizes {
|
|
|
122
121
|
uint constant Auth = B64 + Header + Proof;
|
|
123
122
|
/// @dev STATUS block: 8 header + 32 status code = 40 bytes
|
|
124
123
|
uint constant Status = B32;
|
|
125
|
-
/// @dev AMOUNT block: 8 header + 32 asset + 32
|
|
126
|
-
uint constant Amount =
|
|
127
|
-
/// @dev BALANCE block: 8 header + 32 asset + 32
|
|
128
|
-
uint constant Balance =
|
|
129
|
-
/// @dev BALANCE_LIMIT block: 8 header + 32 asset + 32
|
|
130
|
-
uint constant BalanceLimit =
|
|
124
|
+
/// @dev AMOUNT block: 8 header + 32 asset + 32 amount = 72 bytes
|
|
125
|
+
uint constant Amount = B64;
|
|
126
|
+
/// @dev BALANCE block: 8 header + 32 asset + 32 amount = 72 bytes
|
|
127
|
+
uint constant Balance = B64;
|
|
128
|
+
/// @dev BALANCE_LIMIT block: 8 header + 32 asset + 32 min + 32 max = 104 bytes
|
|
129
|
+
uint constant BalanceLimit = B96;
|
|
131
130
|
/// @dev FEE block: 8 header + 32 amount = 40 bytes
|
|
132
131
|
uint constant Fee = B32;
|
|
133
132
|
/// @dev BOUNTY block: 8 header + 32 amount + 32 relayer = 72 bytes
|
|
134
133
|
uint constant Bounty = B64;
|
|
135
|
-
/// @dev ALLOCATION/CUSTODY block: 8 header + 32 host + 32 asset + 32
|
|
136
|
-
uint constant HostAmount =
|
|
137
|
-
/// @dev CUSTODY_LIMIT block: 8 header + 32 host + 32 asset + 32
|
|
138
|
-
uint constant CustodyLimit =
|
|
139
|
-
/// @dev TRANSACTION block: 8 header + 32 from + 32 to + 32 asset + 32
|
|
140
|
-
uint constant Transaction =
|
|
134
|
+
/// @dev ALLOCATION/CUSTODY block: 8 header + 32 host + 32 asset + 32 amount = 104 bytes
|
|
135
|
+
uint constant HostAmount = B96;
|
|
136
|
+
/// @dev CUSTODY_LIMIT block: 8 header + 32 host + 32 asset + 32 min + 32 max = 136 bytes
|
|
137
|
+
uint constant CustodyLimit = B128;
|
|
138
|
+
/// @dev TRANSACTION block: 8 header + 32 from + 32 to + 32 asset + 32 amount = 136 bytes
|
|
139
|
+
uint constant Transaction = B128;
|
|
141
140
|
}
|
package/blocks/Writers.sol
CHANGED
|
@@ -171,42 +171,42 @@ library Writers {
|
|
|
171
171
|
/// @param count Number of asset blocks to allocate space for.
|
|
172
172
|
/// @return writer Allocated writer.
|
|
173
173
|
function allocAssets(uint count) internal pure returns (Writer memory writer) {
|
|
174
|
-
return
|
|
174
|
+
return alloc32s(count);
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
/// @notice Allocate a writer sized for exactly `count` AMOUNT blocks.
|
|
178
178
|
/// @param count Number of amount blocks to allocate space for.
|
|
179
179
|
/// @return writer Allocated writer.
|
|
180
180
|
function allocAmounts(uint count) internal pure returns (Writer memory writer) {
|
|
181
|
-
return
|
|
181
|
+
return alloc64s(count);
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
/// @notice Allocate a writer sized for exactly `count` BALANCE blocks.
|
|
185
185
|
/// @param count Number of balance blocks to allocate space for.
|
|
186
186
|
/// @return writer Allocated writer.
|
|
187
187
|
function allocBalances(uint count) internal pure returns (Writer memory writer) {
|
|
188
|
-
return
|
|
188
|
+
return alloc64s(count);
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
/// @notice Allocate a writer sized for exactly `count` ACCOUNT_AMOUNT form blocks.
|
|
192
192
|
/// @param count Number of account amount blocks to allocate space for.
|
|
193
193
|
/// @return writer Allocated writer.
|
|
194
194
|
function allocAccountAmounts(uint count) internal pure returns (Writer memory writer) {
|
|
195
|
-
return
|
|
195
|
+
return alloc96s(count);
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
/// @notice Allocate a writer sized for exactly `count` CUSTODY blocks.
|
|
199
199
|
/// @param count Number of custody blocks to allocate space for.
|
|
200
200
|
/// @return writer Allocated writer.
|
|
201
201
|
function allocCustodies(uint count) internal pure returns (Writer memory writer) {
|
|
202
|
-
return
|
|
202
|
+
return alloc96s(count);
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
/// @notice Allocate a writer sized for exactly `count` TRANSACTION blocks.
|
|
206
206
|
/// @param count Number of transaction blocks to allocate space for.
|
|
207
207
|
/// @return writer Allocated writer.
|
|
208
208
|
function allocTransactions(uint count) internal pure returns (Writer memory writer) {
|
|
209
|
-
return
|
|
209
|
+
return alloc128s(count);
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
/// @notice Allocate a writer for `count` STEP blocks using a per-block capacity hint.
|
|
@@ -939,66 +939,61 @@ library Writers {
|
|
|
939
939
|
}
|
|
940
940
|
|
|
941
941
|
/// @notice Append a BALANCE block using separate field values.
|
|
942
|
-
/// @param writer Destination writer; `i` is advanced by `Sizes.
|
|
942
|
+
/// @param writer Destination writer; `i` is advanced by `Sizes.Balance`.
|
|
943
943
|
/// @param asset Asset identifier.
|
|
944
|
-
/// @param meta Asset metadata slot.
|
|
945
944
|
/// @param amount Token amount.
|
|
946
|
-
function appendBalance(Writer memory writer, bytes32 asset,
|
|
947
|
-
|
|
945
|
+
function appendBalance(Writer memory writer, bytes32 asset, uint amount) internal pure {
|
|
946
|
+
appendBlock64(writer, Keys.Balance, asset, bytes32(amount), 32);
|
|
948
947
|
}
|
|
949
948
|
|
|
950
949
|
/// @notice Append a BALANCE block from a struct.
|
|
951
950
|
/// @param writer Destination writer; `i` is advanced by `Sizes.Balance`.
|
|
952
951
|
/// @param value Balance fields to encode.
|
|
953
952
|
function appendBalance(Writer memory writer, AssetAmount memory value) internal pure {
|
|
954
|
-
appendBalance(writer, value.asset, value.
|
|
953
|
+
appendBalance(writer, value.asset, value.amount);
|
|
955
954
|
}
|
|
956
955
|
|
|
957
956
|
/// @notice Append an AMOUNT block using separate field values.
|
|
958
957
|
/// @param writer Destination writer; `i` is advanced by `Sizes.Amount`.
|
|
959
958
|
/// @param asset Asset identifier.
|
|
960
|
-
/// @param meta Asset metadata slot.
|
|
961
959
|
/// @param amount Token amount.
|
|
962
|
-
function appendAmount(Writer memory writer, bytes32 asset,
|
|
963
|
-
|
|
960
|
+
function appendAmount(Writer memory writer, bytes32 asset, uint amount) internal pure {
|
|
961
|
+
appendBlock64(writer, Keys.Amount, asset, bytes32(amount), 32);
|
|
964
962
|
}
|
|
965
963
|
|
|
966
964
|
/// @notice Append an AMOUNT block from a struct.
|
|
967
|
-
/// @param writer Destination writer; `i` is advanced by `Sizes.
|
|
965
|
+
/// @param writer Destination writer; `i` is advanced by `Sizes.Amount`.
|
|
968
966
|
/// @param value Amount fields to encode.
|
|
969
967
|
function appendAmount(Writer memory writer, AssetAmount memory value) internal pure {
|
|
970
|
-
appendAmount(writer, value.asset, value.
|
|
968
|
+
appendAmount(writer, value.asset, value.amount);
|
|
971
969
|
}
|
|
972
970
|
|
|
973
971
|
/// @notice Append an ACCOUNT_AMOUNT form block using separate field values.
|
|
974
|
-
/// @param writer Destination writer; `i` is advanced by `Sizes.
|
|
972
|
+
/// @param writer Destination writer; `i` is advanced by `Sizes.B96`.
|
|
975
973
|
/// @param account Account identifier.
|
|
976
974
|
/// @param asset Asset identifier.
|
|
977
|
-
/// @param meta Asset metadata slot.
|
|
978
975
|
/// @param amount Token amount.
|
|
979
976
|
function appendAccountAmount(
|
|
980
977
|
Writer memory writer,
|
|
981
978
|
bytes32 account,
|
|
982
979
|
bytes32 asset,
|
|
983
|
-
bytes32 meta,
|
|
984
980
|
uint amount
|
|
985
981
|
) internal pure {
|
|
986
|
-
|
|
982
|
+
appendBlock96(writer, Keys.AccountAmount, account, asset, bytes32(amount), 32);
|
|
987
983
|
}
|
|
988
984
|
|
|
989
985
|
/// @notice Append an ACCOUNT_AMOUNT form block from a struct.
|
|
990
|
-
/// @param writer Destination writer; `i` is advanced by `Sizes.
|
|
986
|
+
/// @param writer Destination writer; `i` is advanced by `Sizes.B96`.
|
|
991
987
|
/// @param value Account amount fields to encode.
|
|
992
988
|
function appendAccountAmount(Writer memory writer, AccountAmount memory value) internal pure {
|
|
993
|
-
appendAccountAmount(writer, value.account, value.asset, value.
|
|
989
|
+
appendAccountAmount(writer, value.account, value.asset, value.amount);
|
|
994
990
|
}
|
|
995
991
|
|
|
996
992
|
/// @notice Append an ASSET block.
|
|
997
|
-
/// @param writer Destination writer; `i` is advanced by `Sizes.
|
|
993
|
+
/// @param writer Destination writer; `i` is advanced by `Sizes.B32`.
|
|
998
994
|
/// @param asset Asset identifier.
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
appendBlock64(writer, Keys.Asset, asset, meta, 32);
|
|
995
|
+
function appendAsset(Writer memory writer, bytes32 asset) internal pure {
|
|
996
|
+
appendBlock32(writer, Keys.Asset, asset, 32);
|
|
1002
997
|
}
|
|
1003
998
|
|
|
1004
999
|
/// @notice Append a BOUNTY block to the writer.
|
|
@@ -1013,10 +1008,9 @@ library Writers {
|
|
|
1013
1008
|
/// @param writer Destination writer; `i` is advanced by `Sizes.HostAmount`.
|
|
1014
1009
|
/// @param host Host node ID.
|
|
1015
1010
|
/// @param asset Asset identifier.
|
|
1016
|
-
/// @param meta Asset metadata slot.
|
|
1017
1011
|
/// @param amount Token amount.
|
|
1018
|
-
function appendCustody(Writer memory writer, uint host, bytes32 asset,
|
|
1019
|
-
|
|
1012
|
+
function appendCustody(Writer memory writer, uint host, bytes32 asset, uint amount) internal pure {
|
|
1013
|
+
appendBlock96(writer, Keys.Custody, bytes32(host), asset, bytes32(amount), 32);
|
|
1020
1014
|
}
|
|
1021
1015
|
|
|
1022
1016
|
/// @notice Append a CUSTODY block from a host and asset amount.
|
|
@@ -1024,27 +1018,26 @@ library Writers {
|
|
|
1024
1018
|
/// @param host Host node ID.
|
|
1025
1019
|
/// @param value Custody fields to encode.
|
|
1026
1020
|
function appendCustody(Writer memory writer, uint host, AssetAmount memory value) internal pure {
|
|
1027
|
-
appendCustody(writer, host, value.asset, value.
|
|
1021
|
+
appendCustody(writer, host, value.asset, value.amount);
|
|
1028
1022
|
}
|
|
1029
1023
|
|
|
1030
1024
|
/// @notice Append a CUSTODY block from a host amount struct.
|
|
1031
1025
|
/// @param writer Destination writer; `i` is advanced by `Sizes.HostAmount`.
|
|
1032
1026
|
/// @param value Custody fields to encode.
|
|
1033
1027
|
function appendCustody(Writer memory writer, HostAmount memory value) internal pure {
|
|
1034
|
-
appendCustody(writer, value.host, value.asset, value.
|
|
1028
|
+
appendCustody(writer, value.host, value.asset, value.amount);
|
|
1035
1029
|
}
|
|
1036
1030
|
|
|
1037
1031
|
/// @notice Append a TRANSACTION block from a struct.
|
|
1038
1032
|
/// @param writer Destination writer; `i` is advanced by `Sizes.Transaction`.
|
|
1039
1033
|
/// @param value Transfer record fields to encode.
|
|
1040
1034
|
function appendTransaction(Writer memory writer, Tx memory value) internal pure {
|
|
1041
|
-
|
|
1035
|
+
appendBlock128(
|
|
1042
1036
|
writer,
|
|
1043
1037
|
Keys.Transaction,
|
|
1044
1038
|
bytes32(value.from),
|
|
1045
1039
|
bytes32(value.to),
|
|
1046
1040
|
value.asset,
|
|
1047
|
-
value.meta,
|
|
1048
1041
|
bytes32(value.amount),
|
|
1049
1042
|
32
|
|
1050
1043
|
);
|
package/commands/Base.sol
CHANGED
|
@@ -5,7 +5,7 @@ import {NodeCalls} from "../core/Calls.sol";
|
|
|
5
5
|
import {CommandEvent} from "../events/Command.sol";
|
|
6
6
|
import {LabeledEvent} from "../events/Labeled.sol";
|
|
7
7
|
import {Keys} from "../blocks/Keys.sol";
|
|
8
|
-
import {
|
|
8
|
+
import {Nodes} from "../utils/Nodes.sol";
|
|
9
9
|
|
|
10
10
|
/// @notice Execution context passed to every command invocation.
|
|
11
11
|
struct CommandContext {
|
|
@@ -51,6 +51,6 @@ abstract contract CommandBase is NodeCalls, CommandEvent, LabeledEvent {
|
|
|
51
51
|
/// @param selector Command entrypoint selector.
|
|
52
52
|
/// @return Command node ID.
|
|
53
53
|
function commandId(bytes4 selector) internal view returns (uint) {
|
|
54
|
-
return
|
|
54
|
+
return Nodes.toCommand(selector, address(this));
|
|
55
55
|
}
|
|
56
56
|
}
|
package/commands/Burn.sol
CHANGED
|
@@ -10,10 +10,9 @@ abstract contract BurnHook {
|
|
|
10
10
|
/// Called once per BALANCE block in state.
|
|
11
11
|
/// @param account Caller's account identifier.
|
|
12
12
|
/// @param asset Asset identifier.
|
|
13
|
-
/// @param meta Asset metadata slot.
|
|
14
13
|
/// @param amount Amount to burn.
|
|
15
14
|
/// @return Amount actually burned (may differ from `amount` for partial burns).
|
|
16
|
-
function burn(bytes32 account, bytes32 asset,
|
|
15
|
+
function burn(bytes32 account, bytes32 asset, uint amount) internal virtual returns (uint);
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
/// @title Burn
|
|
@@ -34,8 +33,8 @@ abstract contract Burn is CommandBase, BurnHook {
|
|
|
34
33
|
(Cur memory state, , ) = Cursors.init(c.state, 1);
|
|
35
34
|
|
|
36
35
|
while (state.i < state.len) {
|
|
37
|
-
(bytes32 asset,
|
|
38
|
-
burn(c.account, asset,
|
|
36
|
+
(bytes32 asset, uint amount) = state.unpackBalance();
|
|
37
|
+
burn(c.account, asset, amount);
|
|
39
38
|
}
|
|
40
39
|
|
|
41
40
|
state.complete();
|
package/commands/Credit.sol
CHANGED
|
@@ -11,9 +11,8 @@ abstract contract CreditAccountHook {
|
|
|
11
11
|
/// Called once per BALANCE block in state.
|
|
12
12
|
/// @param account Destination account identifier.
|
|
13
13
|
/// @param asset Asset identifier.
|
|
14
|
-
/// @param meta Asset metadata slot.
|
|
15
14
|
/// @param amount Amount to credit.
|
|
16
|
-
function creditAccount(bytes32 account, bytes32 asset,
|
|
15
|
+
function creditAccount(bytes32 account, bytes32 asset, uint amount) internal virtual;
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
/// @title CreditAccount
|
|
@@ -36,8 +35,8 @@ abstract contract CreditAccount is CommandBase, CreditAccountHook {
|
|
|
36
35
|
(Cur memory state, , ) = Cursors.init(c.state, 1);
|
|
37
36
|
|
|
38
37
|
while (state.i < state.len) {
|
|
39
|
-
(bytes32 asset,
|
|
40
|
-
creditAccount(c.account, asset,
|
|
38
|
+
(bytes32 asset, uint amount) = state.unpackBalance();
|
|
39
|
+
creditAccount(c.account, asset, amount);
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
state.complete();
|
package/commands/Debit.sol
CHANGED
|
@@ -12,9 +12,8 @@ abstract contract DebitAccountHook {
|
|
|
12
12
|
/// Called once per AMOUNT block before a matching BALANCE is emitted.
|
|
13
13
|
/// @param account Source account identifier.
|
|
14
14
|
/// @param asset Asset identifier.
|
|
15
|
-
/// @param meta Asset metadata slot.
|
|
16
15
|
/// @param amount Amount to debit.
|
|
17
|
-
function debitAccount(bytes32 account, bytes32 asset,
|
|
16
|
+
function debitAccount(bytes32 account, bytes32 asset, uint amount) internal virtual;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
/// @title DebitAccount
|
|
@@ -37,9 +36,9 @@ abstract contract DebitAccount is CommandBase, DebitAccountHook {
|
|
|
37
36
|
Writer memory writer = Writers.allocBalances(groups);
|
|
38
37
|
|
|
39
38
|
while (input.i < input.len) {
|
|
40
|
-
(bytes32 asset,
|
|
41
|
-
debitAccount(account, asset,
|
|
42
|
-
writer.appendBalance(asset,
|
|
39
|
+
(bytes32 asset, uint amount) = input.unpackAmount();
|
|
40
|
+
debitAccount(account, asset, amount);
|
|
41
|
+
writer.appendBalance(asset, amount);
|
|
43
42
|
}
|
|
44
43
|
|
|
45
44
|
input.complete();
|
package/commands/Deposit.sol
CHANGED
|
@@ -15,9 +15,8 @@ abstract contract DepositHook {
|
|
|
15
15
|
/// output after each call.
|
|
16
16
|
/// @param account Destination account identifier.
|
|
17
17
|
/// @param asset Asset identifier.
|
|
18
|
-
/// @param meta Asset metadata slot.
|
|
19
18
|
/// @param amount Amount received.
|
|
20
|
-
function deposit(bytes32 account, bytes32 asset,
|
|
19
|
+
function deposit(bytes32 account, bytes32 asset, uint amount) internal virtual;
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
abstract contract DepositPayableHook {
|
|
@@ -26,10 +25,9 @@ abstract contract DepositPayableHook {
|
|
|
26
25
|
/// output after each call.
|
|
27
26
|
/// @param account Destination account identifier.
|
|
28
27
|
/// @param asset Asset identifier.
|
|
29
|
-
/// @param meta Asset metadata slot.
|
|
30
28
|
/// @param amount Amount received.
|
|
31
29
|
/// @param budget Mutable native-value budget drawn from `msg.value`.
|
|
32
|
-
function deposit(bytes32 account, bytes32 asset,
|
|
30
|
+
function deposit(bytes32 account, bytes32 asset, uint amount, Budget memory budget) internal virtual;
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
/// @title Deposit
|
|
@@ -54,9 +52,9 @@ abstract contract Deposit is CommandBase, DepositHook {
|
|
|
54
52
|
Writer memory writer = Writers.allocBalances(groups);
|
|
55
53
|
|
|
56
54
|
while (request.i < request.len) {
|
|
57
|
-
(bytes32 asset,
|
|
58
|
-
deposit(c.account, asset,
|
|
59
|
-
writer.appendBalance(asset,
|
|
55
|
+
(bytes32 asset, uint amount) = request.unpackAmount();
|
|
56
|
+
deposit(c.account, asset, amount);
|
|
57
|
+
writer.appendBalance(asset, amount);
|
|
60
58
|
}
|
|
61
59
|
|
|
62
60
|
request.complete();
|
|
@@ -86,9 +84,9 @@ abstract contract DepositPayable is CommandBase, Payable, DepositPayableHook {
|
|
|
86
84
|
Budget memory budget = valueBudget();
|
|
87
85
|
|
|
88
86
|
while (request.i < request.len) {
|
|
89
|
-
(bytes32 asset,
|
|
90
|
-
deposit(c.account, asset,
|
|
91
|
-
writer.appendBalance(asset,
|
|
87
|
+
(bytes32 asset, uint amount) = request.unpackAmount();
|
|
88
|
+
deposit(c.account, asset, amount, budget);
|
|
89
|
+
writer.appendBalance(asset, amount);
|
|
92
90
|
}
|
|
93
91
|
|
|
94
92
|
settleValue(c.account, budget);
|
package/commands/Payout.sol
CHANGED
|
@@ -3,7 +3,6 @@ pragma solidity ^0.8.33;
|
|
|
3
3
|
|
|
4
4
|
import {CommandContext, CommandBase, Keys} from "./Base.sol";
|
|
5
5
|
import {Cursors, Cur, Schemas} from "../Cursors.sol";
|
|
6
|
-
import {Accounts} from "../utils/Accounts.sol";
|
|
7
6
|
|
|
8
7
|
using Cursors for Cur;
|
|
9
8
|
|
|
@@ -13,9 +12,8 @@ abstract contract PayoutHook {
|
|
|
13
12
|
/// @param account Source account identifier.
|
|
14
13
|
/// @param to Destination account identifier.
|
|
15
14
|
/// @param asset Asset identifier.
|
|
16
|
-
/// @param meta Asset metadata slot.
|
|
17
15
|
/// @param amount Amount to pay out.
|
|
18
|
-
function payout(bytes32 account, bytes32 to, bytes32 asset,
|
|
16
|
+
function payout(bytes32 account, bytes32 to, bytes32 asset, uint amount) internal virtual;
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
/// @title Payout
|
|
@@ -37,9 +35,8 @@ abstract contract Payout is CommandBase, PayoutHook {
|
|
|
37
35
|
(Cur memory request, ) = Cursors.init(c.request, 1, groups);
|
|
38
36
|
|
|
39
37
|
while (state.i < state.len) {
|
|
40
|
-
(bytes32 asset,
|
|
41
|
-
|
|
42
|
-
payout(c.account, to, asset, meta, amount);
|
|
38
|
+
(bytes32 asset, uint amount) = state.unpackBalance();
|
|
39
|
+
payout(c.account, request.unpackAccount(), asset, amount);
|
|
43
40
|
}
|
|
44
41
|
|
|
45
42
|
state.complete();
|
package/commands/Withdraw.sol
CHANGED
|
@@ -10,9 +10,8 @@ abstract contract WithdrawHook {
|
|
|
10
10
|
/// Called once per BALANCE block in state.
|
|
11
11
|
/// @param account Destination account identifier.
|
|
12
12
|
/// @param asset Asset identifier.
|
|
13
|
-
/// @param meta Asset metadata slot.
|
|
14
13
|
/// @param amount Amount to deliver.
|
|
15
|
-
function withdraw(bytes32 account, bytes32 asset,
|
|
14
|
+
function withdraw(bytes32 account, bytes32 asset, uint amount) internal virtual;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
/// @title Withdraw
|
|
@@ -36,8 +35,8 @@ abstract contract Withdraw is CommandBase, WithdrawHook {
|
|
|
36
35
|
(Cur memory state, , ) = Cursors.init(c.state, 1);
|
|
37
36
|
|
|
38
37
|
while (state.i < state.len) {
|
|
39
|
-
(bytes32 asset,
|
|
40
|
-
withdraw(c.account, asset,
|
|
38
|
+
(bytes32 asset, uint amount) = state.unpackBalance();
|
|
39
|
+
withdraw(c.account, asset, amount);
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
state.complete();
|
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { AdminBase, CommandContext, Keys } from "./Base.sol";
|
|
5
5
|
import { Cursors, Cur, Schemas } from "../../Cursors.sol";
|
|
6
|
-
import { AdminEvent } from "../../events/Admin.sol";
|
|
7
6
|
using Cursors for Cur;
|
|
8
7
|
|
|
9
8
|
abstract contract AllowAssetsHook {
|
|
10
|
-
/// @dev Override to allow a single asset
|
|
9
|
+
/// @dev Override to allow a single asset.
|
|
11
10
|
/// Called once per ASSET block in the request.
|
|
12
11
|
/// @param asset Asset identifier.
|
|
13
|
-
|
|
14
|
-
function allowAsset(bytes32 asset, bytes32 meta) internal virtual;
|
|
12
|
+
function allowAsset(bytes32 asset) internal virtual;
|
|
15
13
|
}
|
|
16
14
|
|
|
17
15
|
/// @title AllowAssets
|
|
18
|
-
/// @notice Admin command that permits a list of
|
|
16
|
+
/// @notice Admin command that permits a list of assets via a virtual hook.
|
|
19
17
|
/// Each ASSET block in the request calls `allowAsset`. Only callable by the admin account.
|
|
20
|
-
abstract contract AllowAssets is
|
|
18
|
+
abstract contract AllowAssets is AdminBase, AllowAssetsHook {
|
|
21
19
|
uint internal immutable allowAssetsId = commandId(this.allowAssets.selector);
|
|
22
20
|
|
|
23
21
|
constructor() {
|
|
@@ -34,8 +32,8 @@ abstract contract AllowAssets is CommandBase, AdminEvent, AllowAssetsHook {
|
|
|
34
32
|
(Cur memory request, , ) = Cursors.init(c.request, 1);
|
|
35
33
|
|
|
36
34
|
while (request.i < request.len) {
|
|
37
|
-
|
|
38
|
-
allowAsset(asset
|
|
35
|
+
bytes32 asset = request.unpackAsset();
|
|
36
|
+
allowAsset(asset);
|
|
39
37
|
}
|
|
40
38
|
|
|
41
39
|
request.complete();
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {AdminBase, CommandContext, Keys} from "./Base.sol";
|
|
5
5
|
import {Cursors, Cur, Schemas} from "../../Cursors.sol";
|
|
6
|
-
import {AdminEvent} from "../../events/Admin.sol";
|
|
7
6
|
using Cursors for Cur;
|
|
8
7
|
|
|
9
8
|
abstract contract AllowanceHook {
|
|
@@ -13,15 +12,14 @@ abstract contract AllowanceHook {
|
|
|
13
12
|
/// or another host-specific authorization record.
|
|
14
13
|
/// @param peer Host node receiving the allowed cap.
|
|
15
14
|
/// @param asset Asset identifier.
|
|
16
|
-
/// @param meta Asset metadata slot.
|
|
17
15
|
/// @param amount Allowed cap amount.
|
|
18
|
-
function allowance(uint peer, bytes32 asset,
|
|
16
|
+
function allowance(uint peer, bytes32 asset, uint amount) internal virtual;
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
/// @title Allowance
|
|
22
20
|
/// @notice Admin command that applies cross-host allowance entries via a virtual hook.
|
|
23
21
|
/// Each ALLOWANCE block grants or updates a host-scoped asset cap. Only callable by the admin account.
|
|
24
|
-
abstract contract Allowance is
|
|
22
|
+
abstract contract Allowance is AdminBase, AllowanceHook {
|
|
25
23
|
uint internal immutable allowanceId = commandId(this.allowance.selector);
|
|
26
24
|
|
|
27
25
|
constructor() {
|
|
@@ -36,8 +34,8 @@ abstract contract Allowance is CommandBase, AdminEvent, AllowanceHook {
|
|
|
36
34
|
(Cur memory request, , ) = Cursors.init(c.request, 1);
|
|
37
35
|
|
|
38
36
|
while (request.i < request.len) {
|
|
39
|
-
(uint peer, bytes32 asset,
|
|
40
|
-
allowance(peer, asset,
|
|
37
|
+
(uint peer, bytes32 asset, uint amount) = request.unpackAllowance();
|
|
38
|
+
allowance(peer, asset, amount);
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
request.complete();
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { AdminBase, CommandContext, Keys } from "./Base.sol";
|
|
5
5
|
import { Cursors, Cur, Schemas } from "../../Cursors.sol";
|
|
6
|
-
import { AdminEvent } from "../../events/Admin.sol";
|
|
7
6
|
using Cursors for Cur;
|
|
8
7
|
|
|
9
8
|
/// @title Appoint
|
|
10
9
|
/// @notice Admin command that grants guardian status to a list of account IDs.
|
|
11
10
|
/// Each ACCOUNT block in the request is enabled as a guardian on the host.
|
|
12
11
|
/// Only callable by the admin account.
|
|
13
|
-
abstract contract Appoint is
|
|
12
|
+
abstract contract Appoint is AdminBase {
|
|
14
13
|
uint internal immutable appointId = commandId(this.appoint.selector);
|
|
15
14
|
|
|
16
15
|
constructor() {
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
2
|
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { AdminBase, CommandContext, Keys } from "./Base.sol";
|
|
5
5
|
import { Cursors, Cur, Schemas } from "../../Cursors.sol";
|
|
6
|
-
import { AdminEvent } from "../../events/Admin.sol";
|
|
7
6
|
using Cursors for Cur;
|
|
8
7
|
|
|
9
8
|
/// @title Authorize
|
|
10
9
|
/// @notice Admin command that grants authorization to a list of node IDs.
|
|
11
10
|
/// Each NODE block in the request is authorized on the host.
|
|
12
11
|
/// Only callable by the admin account.
|
|
13
|
-
abstract contract Authorize is
|
|
12
|
+
abstract contract Authorize is AdminBase {
|
|
14
13
|
uint internal immutable authorizeId = commandId(this.authorize.selector);
|
|
15
14
|
|
|
16
15
|
constructor() {
|