@rootzero/contracts 1.3.0 → 1.5.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.
Files changed (62) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/Endpoints.sol +4 -3
  3. package/Events.sol +3 -3
  4. package/README.md +58 -31
  5. package/Utils.sol +4 -3
  6. package/blocks/Cursors.sol +83 -143
  7. package/blocks/Keys.sol +15 -15
  8. package/blocks/Schema.sol +27 -28
  9. package/blocks/Writers.sol +26 -33
  10. package/commands/Base.sol +2 -2
  11. package/commands/Burn.sol +3 -4
  12. package/commands/Credit.sol +3 -4
  13. package/commands/Debit.sol +4 -5
  14. package/commands/Deposit.sol +8 -10
  15. package/commands/Payout.sol +3 -6
  16. package/commands/Withdraw.sol +3 -4
  17. package/commands/admin/AllowAssets.sol +5 -6
  18. package/commands/admin/Allowance.sol +3 -4
  19. package/commands/admin/DenyAssets.sol +5 -6
  20. package/commands/admin/Execute.sol +2 -2
  21. package/core/Access.sol +2 -2
  22. package/core/Balances.sol +10 -11
  23. package/core/Calls.sol +7 -7
  24. package/core/Host.sol +2 -2
  25. package/core/Runtime.sol +3 -3
  26. package/core/Types.sol +0 -14
  27. package/docs/Schema.md +29 -10
  28. package/events/Asset.sol +17 -3
  29. package/events/Balance.sol +2 -3
  30. package/events/Commander.sol +19 -0
  31. package/events/Labeled.sol +6 -6
  32. package/events/Locked.sol +2 -3
  33. package/events/Position.sol +2 -3
  34. package/events/Received.sol +2 -3
  35. package/events/Route.sol +18 -0
  36. package/events/Spent.sol +2 -3
  37. package/events/Unlocked.sol +2 -3
  38. package/guards/Base.sol +4 -4
  39. package/package.json +1 -1
  40. package/peer/AllowAssets.sol +3 -3
  41. package/peer/Allowance.sol +2 -2
  42. package/peer/Base.sol +4 -4
  43. package/peer/Credit.sol +10 -10
  44. package/peer/Debit.sol +10 -10
  45. package/peer/DenyAssets.sol +3 -3
  46. package/peer/Recover.sol +51 -0
  47. package/peer/Redeem.sol +48 -0
  48. package/peer/Settle.sol +3 -3
  49. package/queries/Assets.sol +7 -8
  50. package/queries/Balances.sol +8 -9
  51. package/queries/Base.sol +4 -4
  52. package/queries/Positions.sol +4 -6
  53. package/utils/Accounts.sol +76 -58
  54. package/utils/Actions.sol +1 -0
  55. package/utils/Assets.sol +55 -115
  56. package/utils/Ids.sol +33 -233
  57. package/utils/Layout.sol +11 -17
  58. package/utils/Nodes.sol +263 -0
  59. package/utils/Utils.sol +9 -24
  60. package/events/Chain.sol +0 -19
  61. package/events/Transfer.sol +0 -22
  62. package/peer/BalancePull.sol +0 -49
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, bytes32 meta }";
63
- string constant Amount = "#amount { bytes32 asset, bytes32 meta, uint amount }";
64
- string constant Balance = "#balance { bytes32 asset, bytes32 meta, uint amount }";
65
- string constant BalanceLimit = "#balanceLimit { bytes32 asset, bytes32 meta, uint min, uint max }";
66
- string constant Custody = "#custody { uint host, bytes32 asset, bytes32 meta, uint amount }";
67
- string constant CustodyLimit = "#custodyLimit { uint host, bytes32 asset, bytes32 meta, uint min, uint max }";
68
- string constant Allocation = "#allocation { uint host, bytes32 asset, bytes32 meta, uint amount }";
69
- string constant Allowance = "#allowance { uint host, bytes32 asset, bytes32 meta, uint amount }";
70
- string constant Transaction = "#transaction { bytes32 from, bytes32 to, bytes32 asset, bytes32 meta, uint amount }";
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, bytes32 meta, uint amount }";
94
- string constant AccountAsset = "#accountAsset { bytes32 account, bytes32 asset, bytes32 meta }";
95
- string constant AccountAmount = "#accountAmount { bytes32 account, bytes32 asset, bytes32 meta, uint amount }";
96
- string constant HostAmount = "#hostAmount { uint host, bytes32 asset, bytes32 meta, uint amount }";
97
- string constant HostAccountAsset = "#hostAccountAsset { uint host, bytes32 account, bytes32 asset, bytes32 meta }";
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 meta + 32 amount = 104 bytes
126
- uint constant Amount = B96;
127
- /// @dev BALANCE block: 8 header + 32 asset + 32 meta + 32 amount = 104 bytes
128
- uint constant Balance = B96;
129
- /// @dev BALANCE_LIMIT block: 8 header + 32 asset + 32 meta + 32 min + 32 max = 136 bytes
130
- uint constant BalanceLimit = B128;
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 meta + 32 amount = 136 bytes
136
- uint constant HostAmount = B128;
137
- /// @dev CUSTODY_LIMIT block: 8 header + 32 host + 32 asset + 32 meta + 32 min + 32 max = 168 bytes
138
- uint constant CustodyLimit = B160;
139
- /// @dev TRANSACTION block: 8 header + 32 from + 32 to + 32 asset + 32 meta + 32 amount = 168 bytes
140
- uint constant Transaction = B160;
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
  }
@@ -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 alloc64s(count);
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 alloc96s(count);
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 alloc96s(count);
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 alloc128s(count);
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 alloc128s(count);
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 alloc160s(count);
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.Amount`.
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, bytes32 meta, uint amount) internal pure {
947
- appendBlock96(writer, Keys.Balance, asset, meta, bytes32(amount), 32);
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.meta, value.amount);
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, bytes32 meta, uint amount) internal pure {
963
- appendBlock96(writer, Keys.Amount, asset, meta, bytes32(amount), 32);
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.Balance`.
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.meta, value.amount);
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.B128`.
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
- appendBlock128(writer, Keys.AccountAmount, account, asset, meta, bytes32(amount), 32);
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.B128`.
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.meta, value.amount);
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.B64`.
993
+ /// @param writer Destination writer; `i` is advanced by `Sizes.B32`.
998
994
  /// @param asset Asset identifier.
999
- /// @param meta Asset metadata slot.
1000
- function appendAsset(Writer memory writer, bytes32 asset, bytes32 meta) internal pure {
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, bytes32 meta, uint amount) internal pure {
1019
- appendBlock128(writer, Keys.Custody, bytes32(host), asset, meta, bytes32(amount), 32);
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.meta, value.amount);
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.meta, value.amount);
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
- appendBlock160(
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 {Ids} from "../utils/Ids.sol";
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 Ids.toCommand(selector, address(this));
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, bytes32 meta, uint amount) internal virtual returns (uint);
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, bytes32 meta, uint amount) = state.unpackBalance();
38
- burn(c.account, asset, meta, amount);
36
+ (bytes32 asset, uint amount) = state.unpackBalance();
37
+ burn(c.account, asset, amount);
39
38
  }
40
39
 
41
40
  state.complete();
@@ -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, bytes32 meta, uint amount) internal virtual;
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, bytes32 meta, uint amount) = state.unpackBalance();
40
- creditAccount(c.account, asset, meta, amount);
38
+ (bytes32 asset, uint amount) = state.unpackBalance();
39
+ creditAccount(c.account, asset, amount);
41
40
  }
42
41
 
43
42
  state.complete();
@@ -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, bytes32 meta, uint amount) internal virtual;
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, bytes32 meta, uint amount) = input.unpackAmount();
41
- debitAccount(account, asset, meta, amount);
42
- writer.appendBalance(asset, meta, amount);
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();
@@ -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, bytes32 meta, uint amount) internal virtual;
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, bytes32 meta, uint amount, Budget memory budget) internal virtual;
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, bytes32 meta, uint amount) = request.unpackAmount();
58
- deposit(c.account, asset, meta, amount);
59
- writer.appendBalance(asset, meta, amount);
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, bytes32 meta, uint amount) = request.unpackAmount();
90
- deposit(c.account, asset, meta, amount, budget);
91
- writer.appendBalance(asset, meta, amount);
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);
@@ -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, bytes32 meta, uint amount) internal virtual;
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, bytes32 meta, uint amount) = state.unpackBalance();
41
- bytes32 to = Accounts.ensure(request.unpackAccount());
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();
@@ -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, bytes32 meta, uint amount) internal virtual;
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, bytes32 meta, uint amount) = state.unpackBalance();
40
- withdraw(c.account, asset, meta, amount);
38
+ (bytes32 asset, uint amount) = state.unpackBalance();
39
+ withdraw(c.account, asset, amount);
41
40
  }
42
41
 
43
42
  state.complete();
@@ -7,15 +7,14 @@ import { AdminEvent } from "../../events/Admin.sol";
7
7
  using Cursors for Cur;
8
8
 
9
9
  abstract contract AllowAssetsHook {
10
- /// @dev Override to allow a single asset/meta pair.
10
+ /// @dev Override to allow a single asset.
11
11
  /// Called once per ASSET block in the request.
12
12
  /// @param asset Asset identifier.
13
- /// @param meta Asset metadata slot.
14
- function allowAsset(bytes32 asset, bytes32 meta) internal virtual;
13
+ function allowAsset(bytes32 asset) internal virtual;
15
14
  }
16
15
 
17
16
  /// @title AllowAssets
18
- /// @notice Admin command that permits a list of (asset, meta) pairs via a virtual hook.
17
+ /// @notice Admin command that permits a list of assets via a virtual hook.
19
18
  /// Each ASSET block in the request calls `allowAsset`. Only callable by the admin account.
20
19
  abstract contract AllowAssets is CommandBase, AdminEvent, AllowAssetsHook {
21
20
  uint internal immutable allowAssetsId = commandId(this.allowAssets.selector);
@@ -34,8 +33,8 @@ abstract contract AllowAssets is CommandBase, AdminEvent, AllowAssetsHook {
34
33
  (Cur memory request, , ) = Cursors.init(c.request, 1);
35
34
 
36
35
  while (request.i < request.len) {
37
- (bytes32 asset, bytes32 meta) = request.unpackAsset();
38
- allowAsset(asset, meta);
36
+ bytes32 asset = request.unpackAsset();
37
+ allowAsset(asset);
39
38
  }
40
39
 
41
40
  request.complete();
@@ -13,9 +13,8 @@ abstract contract AllowanceHook {
13
13
  /// or another host-specific authorization record.
14
14
  /// @param peer Host node receiving the allowed cap.
15
15
  /// @param asset Asset identifier.
16
- /// @param meta Asset metadata slot.
17
16
  /// @param amount Allowed cap amount.
18
- function allowance(uint peer, bytes32 asset, bytes32 meta, uint amount) internal virtual;
17
+ function allowance(uint peer, bytes32 asset, uint amount) internal virtual;
19
18
  }
20
19
 
21
20
  /// @title Allowance
@@ -36,8 +35,8 @@ abstract contract Allowance is CommandBase, AdminEvent, AllowanceHook {
36
35
  (Cur memory request, , ) = Cursors.init(c.request, 1);
37
36
 
38
37
  while (request.i < request.len) {
39
- (uint peer, bytes32 asset, bytes32 meta, uint amount) = request.unpackAllowance();
40
- allowance(peer, asset, meta, amount);
38
+ (uint peer, bytes32 asset, uint amount) = request.unpackAllowance();
39
+ allowance(peer, asset, amount);
41
40
  }
42
41
 
43
42
  request.complete();
@@ -7,15 +7,14 @@ import { AdminEvent } from "../../events/Admin.sol";
7
7
  using Cursors for Cur;
8
8
 
9
9
  abstract contract DenyAssetsHook {
10
- /// @dev Override to deny a single asset/meta pair.
10
+ /// @dev Override to deny a single asset.
11
11
  /// Called once per ASSET block in the request.
12
12
  /// @param asset Asset identifier.
13
- /// @param meta Asset metadata slot.
14
- function denyAsset(bytes32 asset, bytes32 meta) internal virtual;
13
+ function denyAsset(bytes32 asset) internal virtual;
15
14
  }
16
15
 
17
16
  /// @title DenyAssets
18
- /// @notice Admin command that blocks a list of (asset, meta) pairs via a virtual hook.
17
+ /// @notice Admin command that blocks a list of assets via a virtual hook.
19
18
  /// Each ASSET block in the request calls `denyAsset`. Only callable by the admin account.
20
19
  abstract contract DenyAssets is CommandBase, AdminEvent, DenyAssetsHook {
21
20
  uint internal immutable denyAssetsId = commandId(this.denyAssets.selector);
@@ -34,8 +33,8 @@ abstract contract DenyAssets is CommandBase, AdminEvent, DenyAssetsHook {
34
33
  (Cur memory request, , ) = Cursors.init(c.request, 1);
35
34
 
36
35
  while (request.i < request.len) {
37
- (bytes32 asset, bytes32 meta) = request.unpackAsset();
38
- denyAsset(asset, meta);
36
+ bytes32 asset = request.unpackAsset();
37
+ denyAsset(asset);
39
38
  }
40
39
 
41
40
  request.complete();
@@ -6,7 +6,7 @@ import {Payable} from "../../core/Payable.sol";
6
6
  import {Cursors, Cur, Schemas} from "../../Cursors.sol";
7
7
  import {AdminEvent} from "../../events/Admin.sol";
8
8
  import {Budget} from "../../utils/Value.sol";
9
- import {Ids} from "../../utils/Ids.sol";
9
+ import {Nodes} from "../../utils/Nodes.sol";
10
10
 
11
11
  using Cursors for Cur;
12
12
 
@@ -32,7 +32,7 @@ abstract contract ExecutePayable is CommandBase, Payable, AdminEvent {
32
32
 
33
33
  while (request.i < request.len) {
34
34
  (uint target, uint resources, bytes calldata data) = request.unpackCall();
35
- address addr = Ids.nodeAddr(target);
35
+ address addr = Nodes.addr(target);
36
36
  callAddr(addr, useValue(budget, resources), data);
37
37
  }
38
38
 
package/core/Access.sol CHANGED
@@ -5,7 +5,7 @@ import {NodeEvent} from "../events/Node.sol";
5
5
  import {GuardianEvent} from "../events/Guardian.sol";
6
6
  import {Runtime} from "./Runtime.sol";
7
7
  import {Accounts} from "../utils/Accounts.sol";
8
- import {Ids} from "../utils/Ids.sol";
8
+ import {Nodes} from "../utils/Nodes.sol";
9
9
  import {addrOr} from "../utils/Utils.sol";
10
10
 
11
11
  /// @title AccessControl
@@ -63,7 +63,7 @@ abstract contract AccessControl is Runtime, NodeEvent, GuardianEvent {
63
63
  /// whose host ID has been explicitly authorized.
64
64
  /// @param caller Address to check.
65
65
  function isTrusted(address caller) internal view returns (bool) {
66
- return caller == commander || caller == address(this) || nodes[Ids.toHost(caller)];
66
+ return caller == commander || caller == address(this) || nodes[Nodes.toHost(caller)];
67
67
  }
68
68
 
69
69
  /// @notice Assert that `node` is in the trusted set and return it.
package/core/Balances.sol CHANGED
@@ -7,33 +7,32 @@ import {BalanceEvent} from "../events/Balance.sol";
7
7
  error InsufficientFunds();
8
8
 
9
9
  /// @title Balances
10
- /// @notice On-chain ledger for per-account, per-slot balances.
11
- /// Higher-level modules decide how slots are derived and validated.
10
+ /// @notice On-chain ledger for per-account, per-asset balances.
12
11
  abstract contract Balances is BalanceEvent {
13
- /// @dev account -> slot -> balance.
14
- mapping(bytes32 account => mapping(bytes32 slot => uint amount)) internal balances;
12
+ /// @dev account -> asset -> balance.
13
+ mapping(bytes32 account => mapping(bytes32 asset => uint amount)) internal balances;
15
14
 
16
15
  /// @notice Add `amount` to an account balance and return the new balance.
17
16
  /// @param account Account identifier.
18
- /// @param slot Storage slot for the position being credited.
17
+ /// @param asset Unique asset identifier for the position being credited.
19
18
  /// @param amount Amount to credit.
20
19
  /// @return balance New balance after the credit.
21
- function creditTo(bytes32 account, bytes32 slot, uint amount) internal returns (uint balance) {
22
- balance = balances[account][slot] += amount;
20
+ function creditTo(bytes32 account, bytes32 asset, uint amount) internal returns (uint balance) {
21
+ balance = balances[account][asset] += amount;
23
22
  }
24
23
 
25
24
  /// @notice Deduct `amount` from an account balance and return the new balance.
26
25
  /// Reverts with `InsufficientFunds` if the current balance is less than `amount`.
27
26
  /// @param account Account identifier.
28
- /// @param slot Storage slot for the position being debited.
27
+ /// @param asset Unique asset identifier for the position being debited.
29
28
  /// @param amount Amount to deduct.
30
29
  /// @return balance New balance after the debit.
31
- function debitFrom(bytes32 account, bytes32 slot, uint amount) internal returns (uint balance) {
32
- balance = balances[account][slot];
30
+ function debitFrom(bytes32 account, bytes32 asset, uint amount) internal returns (uint balance) {
31
+ balance = balances[account][asset];
33
32
  if (balance < amount) revert InsufficientFunds();
34
33
  unchecked {
35
34
  balance -= amount;
36
35
  }
37
- balances[account][slot] = balance;
36
+ balances[account][asset] = balance;
38
37
  }
39
38
  }