@rootzero/contracts 0.6.2 → 0.7.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 (47) hide show
  1. package/Commands.sol +8 -16
  2. package/Core.sol +4 -2
  3. package/Cursors.sol +2 -2
  4. package/Events.sol +4 -2
  5. package/Queries.sol +10 -0
  6. package/blocks/Cursors.sol +168 -8
  7. package/blocks/Keys.sol +4 -1
  8. package/blocks/Schema.sol +32 -11
  9. package/blocks/Writers.sol +536 -95
  10. package/commands/Base.sol +20 -6
  11. package/commands/Provision.sol +5 -12
  12. package/commands/Stake.sol +1 -84
  13. package/commands/admin/AllowAssets.sol +7 -5
  14. package/commands/admin/DenyAssets.sol +7 -5
  15. package/commands/admin/Relocate.sol +2 -2
  16. package/core/Access.sol +2 -4
  17. package/core/CursorBase.sol +43 -0
  18. package/core/Host.sol +1 -1
  19. package/core/HostBound.sol +14 -0
  20. package/core/Operation.sol +41 -37
  21. package/events/Erc721.sol +20 -0
  22. package/events/Query.sol +20 -0
  23. package/events/Swap.sol +20 -0
  24. package/package.json +1 -1
  25. package/peer/AllowAssets.sol +4 -9
  26. package/peer/AssetPull.sol +41 -0
  27. package/peer/Base.sol +11 -0
  28. package/peer/DenyAssets.sol +4 -9
  29. package/peer/Pull.sol +8 -11
  30. package/peer/Push.sol +6 -3
  31. package/queries/Assets.sol +46 -0
  32. package/queries/Balances.sol +46 -0
  33. package/queries/Base.sol +34 -0
  34. package/queries/Positions.sol +49 -0
  35. package/utils/Ids.sol +68 -1
  36. package/utils/Layout.sol +2 -0
  37. package/commands/Borrow.sol +0 -89
  38. package/commands/Liquidate.sol +0 -99
  39. package/commands/Liquidity.sol +0 -180
  40. package/commands/Mint.sol +0 -54
  41. package/commands/Reclaim.sol +0 -55
  42. package/commands/Redeem.sol +0 -99
  43. package/commands/Repay.sol +0 -99
  44. package/commands/Swap.sol +0 -90
  45. package/commands/Unstake.sol +0 -58
  46. package/events/Quote.sol +0 -21
  47. /package/events/{HostAnnounced.sol → Host.sol} +0 -0
package/Commands.sol CHANGED
@@ -1,42 +1,34 @@
1
1
  // SPDX-License-Identifier: GPL-3.0-only
2
2
  pragma solidity ^0.8.33;
3
3
 
4
- // Aggregator: re-exports all command and peer abstractions.
5
- // Import this file to inherit from any command or peer base contract without managing individual paths.
4
+ // Aggregator: re-exports command, admin, and peer abstractions.
5
+ // Import this file to inherit from the full rootzero command surface without managing individual paths.
6
6
 
7
- import { CommandBase, CommandContext, CommandPayable } from "./commands/Base.sol";
7
+ import { CommandBase, CommandContext, CommandPayable, encodeCommandCall } from "./commands/Base.sol";
8
8
  import { State } from "./utils/State.sol";
9
- import { BorrowAgainstBalanceToBalance, BorrowAgainstCustodyToBalance } from "./commands/Borrow.sol";
10
9
  import { Burn } from "./commands/Burn.sol";
11
10
  import { Create } from "./commands/Create.sol";
12
11
  import { CreditAccount } from "./commands/Credit.sol";
13
12
  import { DebitAccount } from "./commands/Debit.sol";
14
13
  import { Deposit, DepositPayable } from "./commands/Deposit.sol";
15
14
  import { Remove } from "./commands/Remove.sol";
16
- import { AddLiquidityFromBalancesToBalances, AddLiquidityFromCustodiesToBalances, RemoveLiquidityFromBalanceToBalances, RemoveLiquidityFromCustodyToBalances } from "./commands/Liquidity.sol";
17
- import { LiquidateFromBalanceToBalances, LiquidateFromCustodyToBalances } from "./commands/Liquidate.sol";
18
- import { MintToBalances } from "./commands/Mint.sol";
19
15
  import { PipePayable } from "./commands/Pipe.sol";
20
16
  import { Provision, ProvisionPayable, ProvisionFromBalance } from "./commands/Provision.sol";
21
- import { ReclaimToBalances } from "./commands/Reclaim.sol";
22
- import { RedeemFromBalanceToBalances, RedeemFromCustodyToBalances } from "./commands/Redeem.sol";
23
- import { RepayFromBalanceToBalances, RepayFromCustodyToBalances } from "./commands/Repay.sol";
24
17
  import { Settle } from "./commands/Settle.sol";
25
- import { StakeBalanceToBalances, StakeCustodyToBalances, StakeCustodyToPosition } from "./commands/Stake.sol";
18
+ import { StakeCustodyToPosition } from "./commands/Stake.sol";
26
19
  import { Supply } from "./commands/Supply.sol";
27
- import { SwapExactBalanceToBalance, SwapExactCustodyToBalance } from "./commands/Swap.sol";
28
20
  import { Transfer } from "./commands/Transfer.sol";
29
- import { UnstakeBalanceToBalances } from "./commands/Unstake.sol";
30
21
  import { Withdraw } from "./commands/Withdraw.sol";
31
- import { AllowAssets } from "./commands/admin/AllowAssets.sol";
22
+ import { AllowAssets, AllowAssetsHook } from "./commands/admin/AllowAssets.sol";
32
23
  import { Destroy } from "./commands/admin/Destroy.sol";
33
24
  import { Authorize } from "./commands/admin/Authorize.sol";
34
- import { DenyAssets } from "./commands/admin/DenyAssets.sol";
25
+ import { DenyAssets, DenyAssetsHook } from "./commands/admin/DenyAssets.sol";
35
26
  import { Init } from "./commands/admin/Init.sol";
36
27
  import { RelocatePayable } from "./commands/admin/Relocate.sol";
37
28
  import { Allocate } from "./commands/admin/Allocate.sol";
38
29
  import { Unauthorize } from "./commands/admin/Unauthorize.sol";
39
- import { PeerBase } from "./peer/Base.sol";
30
+ import { PeerBase, encodePeerCall } from "./peer/Base.sol";
31
+ import { PeerAssetPull } from "./peer/AssetPull.sol";
40
32
  import { PeerAllowAssets } from "./peer/AllowAssets.sol";
41
33
  import { PeerDenyAssets } from "./peer/DenyAssets.sol";
42
34
  import { PeerPull } from "./peer/Pull.sol";
package/Core.sol CHANGED
@@ -1,12 +1,14 @@
1
1
  // SPDX-License-Identifier: GPL-3.0-only
2
2
  pragma solidity ^0.8.33;
3
3
 
4
- // Aggregator: re-exports all core protocol contracts (Access, Balances, Host, Operation, Validator).
5
- // Import this file to bring the full host base layer into scope.
4
+ // Aggregator: re-exports the core host, access, cursor, and validation layer.
5
+ // Import this file to bring the full rootzero host base layer into scope.
6
6
 
7
7
  import { AccessControl } from "./core/Access.sol";
8
8
  import { Balances } from "./core/Balances.sol";
9
+ import { CursorBase } from "./core/CursorBase.sol";
9
10
  import { Host } from "./core/Host.sol";
11
+ import { HostBound } from "./core/HostBound.sol";
10
12
  import { FailedCall, OperationBase } from "./core/Operation.sol";
11
13
  import { Validator } from "./core/Validator.sol";
12
14
  import { HostDiscovery } from "./core/Host.sol";
package/Cursors.sol CHANGED
@@ -1,10 +1,10 @@
1
1
  // SPDX-License-Identifier: GPL-3.0-only
2
2
  pragma solidity ^0.8.33;
3
3
 
4
- // Aggregator: re-exports all block stream primitives (Cursors, Writers, Schema, Keys).
4
+ // Aggregator: re-exports all block stream primitives (Cursors, Writers, Schema, Keys, Sizes).
5
5
  // Import this file to get access to the full block encoding/decoding surface in one import.
6
6
 
7
- import { HostAmount, UserAmount, HostAsset, Tx, AssetAmount } from "./blocks/Schema.sol";
7
+ import { HostAmount, UserAmount, HostAsset, Tx, AssetAmount, Sizes } from "./blocks/Schema.sol";
8
8
  import { Keys } from "./blocks/Keys.sol";
9
9
  import { Schemas } from "./blocks/Schema.sol";
10
10
  import { Cursors, Cur } from "./blocks/Cursors.sol";
package/Events.sol CHANGED
@@ -11,13 +11,15 @@ import { CollateralEvent } from "./events/Collateral.sol";
11
11
  import { CommandEvent } from "./events/Command.sol";
12
12
  import { DebtEvent } from "./events/Debt.sol";
13
13
  import { DepositEvent } from "./events/Deposit.sol";
14
+ import { Erc721PositionEvent } from "./events/Erc721.sol";
14
15
  import { EventEmitter } from "./events/Emitter.sol";
15
16
  import { GovernedEvent } from "./events/Governed.sol";
16
- import { HostAnnouncedEvent } from "./events/HostAnnounced.sol";
17
+ import { HostAnnouncedEvent } from "./events/Host.sol";
17
18
  import { ListingEvent } from "./events/Listing.sol";
18
19
  import { PeerEvent } from "./events/Peer.sol";
19
- import { QuoteEvent } from "./events/Quote.sol";
20
+ import { QueryEvent } from "./events/Query.sol";
20
21
  import { RootZeroEvent } from "./events/RootZero.sol";
22
+ import { SwapEvent } from "./events/Swap.sol";
21
23
  import { WithdrawalEvent } from "./events/Withdraw.sol";
22
24
 
23
25
 
package/Queries.sol ADDED
@@ -0,0 +1,10 @@
1
+ // SPDX-License-Identifier: GPL-3.0-only
2
+ pragma solidity ^0.8.33;
3
+
4
+ // Aggregator: re-exports query abstractions and reusable query bases.
5
+ // Import this file to build rootzero query contracts without managing individual paths.
6
+
7
+ import { IsAllowedAsset } from "./queries/Assets.sol";
8
+ import { AssetPosition } from "./queries/Positions.sol";
9
+ import { GetBalances } from "./queries/Balances.sol";
10
+ import { QueryBase, encodeQueryCall } from "./queries/Base.sol";
@@ -222,6 +222,15 @@ library Cursors {
222
222
  return bytes.concat(key, bytes4(uint32(0x20)), value);
223
223
  }
224
224
 
225
+ /// @notice Encode a block with a 32-byte fixed head followed by a variable-length tail.
226
+ /// @param key Block type key.
227
+ /// @param head Fixed 32-byte head payload.
228
+ /// @param tail Variable-length payload bytes appended after the head.
229
+ /// @return Encoded block bytes.
230
+ function createHead32(bytes4 key, bytes32 head, bytes memory tail) internal pure returns (bytes memory) {
231
+ return bytes.concat(key, bytes4(uint32(0x20 + tail.length)), head, tail);
232
+ }
233
+
225
234
  /// @notice Encode a block with two 32-byte payload words (64-byte payload).
226
235
  /// @param key Block type key.
227
236
  /// @param a First payload word.
@@ -231,6 +240,16 @@ library Cursors {
231
240
  return bytes.concat(key, bytes4(uint32(0x40)), a, b);
232
241
  }
233
242
 
243
+ /// @notice Encode a block with a 64-byte fixed head followed by a variable-length tail.
244
+ /// @param key Block type key.
245
+ /// @param a First fixed payload word.
246
+ /// @param b Second fixed payload word.
247
+ /// @param tail Variable-length payload bytes appended after the fixed head.
248
+ /// @return Encoded block bytes.
249
+ function createHead64(bytes4 key, bytes32 a, bytes32 b, bytes memory tail) internal pure returns (bytes memory) {
250
+ return bytes.concat(key, bytes4(uint32(0x40 + tail.length)), a, b, tail);
251
+ }
252
+
234
253
  /// @notice Encode a block with three 32-byte payload words (96-byte payload).
235
254
  /// @param key Block type key.
236
255
  /// @param a First payload word.
@@ -283,6 +302,15 @@ library Cursors {
283
302
  return create32(Keys.Fee, bytes32(amount));
284
303
  }
285
304
 
305
+ /// @notice Encode a STEP block.
306
+ /// @param target Command target identifier.
307
+ /// @param value Native value forwarded with the step.
308
+ /// @param request Variable-length nested request payload.
309
+ /// @return Encoded STEP block bytes.
310
+ function toStepBlock(uint target, uint value, bytes memory request) internal pure returns (bytes memory) {
311
+ return createHead64(Keys.Step, bytes32(target), bytes32(value), request);
312
+ }
313
+
286
314
  /// @notice Encode a BALANCE block.
287
315
  /// @param asset Asset identifier.
288
316
  /// @param meta Asset metadata slot.
@@ -487,14 +515,6 @@ library Cursors {
487
515
  account = bytes32(msg.data[abs:abs + 32]);
488
516
  }
489
517
 
490
- /// @notice Consume a PARTY block and return the account.
491
- /// @param cur Cursor; advanced past the block.
492
- /// @return account Counter-party account identifier.
493
- function unpackParty(Cur memory cur) internal pure returns (bytes32 account) {
494
- uint abs = consume(cur, Keys.Party, 32, 32);
495
- account = bytes32(msg.data[abs:abs + 32]);
496
- }
497
-
498
518
  /// @notice Consume a RATE block and return the value.
499
519
  /// @param cur Cursor; advanced past the block.
500
520
  /// @return value Encoded ratio or rate.
@@ -601,6 +621,26 @@ library Cursors {
601
621
  cur.i = next;
602
622
  }
603
623
 
624
+ /// @notice Consume a QUERY block and return the raw payload as a calldata slice.
625
+ /// The payload length is variable; the returned slice covers the entire payload.
626
+ /// @param cur Cursor; advanced past the block.
627
+ /// @return data Raw query payload bytes.
628
+ function unpackQuery(Cur memory cur) internal pure returns (bytes calldata data) {
629
+ (uint abs, uint next) = expect(cur, cur.i, Keys.Query, 0, 0);
630
+ data = msg.data[abs:cur.offset + next];
631
+ cur.i = next;
632
+ }
633
+
634
+ /// @notice Consume a RESPONSE block and return the raw payload as a calldata slice.
635
+ /// The payload length is variable; the returned slice covers the entire payload.
636
+ /// @param cur Cursor; advanced past the block.
637
+ /// @return data Raw response payload bytes.
638
+ function unpackResponse(Cur memory cur) internal pure returns (bytes calldata data) {
639
+ (uint abs, uint next) = expect(cur, cur.i, Keys.Response, 0, 0);
640
+ data = msg.data[abs:cur.offset + next];
641
+ cur.i = next;
642
+ }
643
+
604
644
  /// @notice Consume a PATH block and return the raw payload as a calldata slice.
605
645
  /// The payload length is variable; the returned slice covers the entire payload.
606
646
  /// @param cur Cursor; advanced past the block.
@@ -619,6 +659,22 @@ library Cursors {
619
659
  value = uint(bytes32(msg.data[abs:abs + 32]));
620
660
  }
621
661
 
662
+ /// @notice Consume a QUERY block with a single uint payload.
663
+ /// @param cur Cursor; advanced past the block.
664
+ /// @return value Decoded uint value.
665
+ function unpackQueryUint(Cur memory cur) internal pure returns (uint value) {
666
+ uint abs = consume(cur, Keys.Query, 32, 32);
667
+ value = uint(bytes32(msg.data[abs:abs + 32]));
668
+ }
669
+
670
+ /// @notice Consume a RESPONSE block with a single uint payload.
671
+ /// @param cur Cursor; advanced past the block.
672
+ /// @return value Decoded uint value.
673
+ function unpackResponseUint(Cur memory cur) internal pure returns (uint value) {
674
+ uint abs = consume(cur, Keys.Response, 32, 32);
675
+ value = uint(bytes32(msg.data[abs:abs + 32]));
676
+ }
677
+
622
678
  /// @notice Consume a ROUTE block with two uint payload words.
623
679
  /// @param cur Cursor; advanced past the block.
624
680
  /// @return a First decoded uint.
@@ -629,6 +685,26 @@ library Cursors {
629
685
  b = uint(bytes32(msg.data[abs + 32:abs + 64]));
630
686
  }
631
687
 
688
+ /// @notice Consume a QUERY block with two uint payload words.
689
+ /// @param cur Cursor; advanced past the block.
690
+ /// @return a First decoded uint.
691
+ /// @return b Second decoded uint.
692
+ function unpackQuery2Uint(Cur memory cur) internal pure returns (uint a, uint b) {
693
+ uint abs = consume(cur, Keys.Query, 64, 64);
694
+ a = uint(bytes32(msg.data[abs:abs + 32]));
695
+ b = uint(bytes32(msg.data[abs + 32:abs + 64]));
696
+ }
697
+
698
+ /// @notice Consume a RESPONSE block with two uint payload words.
699
+ /// @param cur Cursor; advanced past the block.
700
+ /// @return a First decoded uint.
701
+ /// @return b Second decoded uint.
702
+ function unpackResponse2Uint(Cur memory cur) internal pure returns (uint a, uint b) {
703
+ uint abs = consume(cur, Keys.Response, 64, 64);
704
+ a = uint(bytes32(msg.data[abs:abs + 32]));
705
+ b = uint(bytes32(msg.data[abs + 32:abs + 64]));
706
+ }
707
+
632
708
  /// @notice Consume a ROUTE block with three uint payload words.
633
709
  /// @param cur Cursor; advanced past the block.
634
710
  /// @return a First decoded uint.
@@ -641,6 +717,30 @@ library Cursors {
641
717
  c = uint(bytes32(msg.data[abs + 64:abs + 96]));
642
718
  }
643
719
 
720
+ /// @notice Consume a QUERY block with three uint payload words.
721
+ /// @param cur Cursor; advanced past the block.
722
+ /// @return a First decoded uint.
723
+ /// @return b Second decoded uint.
724
+ /// @return c Third decoded uint.
725
+ function unpackQuery3Uint(Cur memory cur) internal pure returns (uint a, uint b, uint c) {
726
+ uint abs = consume(cur, Keys.Query, 96, 96);
727
+ a = uint(bytes32(msg.data[abs:abs + 32]));
728
+ b = uint(bytes32(msg.data[abs + 32:abs + 64]));
729
+ c = uint(bytes32(msg.data[abs + 64:abs + 96]));
730
+ }
731
+
732
+ /// @notice Consume a RESPONSE block with three uint payload words.
733
+ /// @param cur Cursor; advanced past the block.
734
+ /// @return a First decoded uint.
735
+ /// @return b Second decoded uint.
736
+ /// @return c Third decoded uint.
737
+ function unpackResponse3Uint(Cur memory cur) internal pure returns (uint a, uint b, uint c) {
738
+ uint abs = consume(cur, Keys.Response, 96, 96);
739
+ a = uint(bytes32(msg.data[abs:abs + 32]));
740
+ b = uint(bytes32(msg.data[abs + 32:abs + 64]));
741
+ c = uint(bytes32(msg.data[abs + 64:abs + 96]));
742
+ }
743
+
644
744
  /// @notice Consume a ROUTE block with a single bytes32 payload.
645
745
  /// @param cur Cursor; advanced past the block.
646
746
  /// @return value Decoded bytes32.
@@ -649,6 +749,22 @@ library Cursors {
649
749
  value = bytes32(msg.data[abs:abs + 32]);
650
750
  }
651
751
 
752
+ /// @notice Consume a QUERY block with a single bytes32 payload.
753
+ /// @param cur Cursor; advanced past the block.
754
+ /// @return value Decoded bytes32.
755
+ function unpackQuery32(Cur memory cur) internal pure returns (bytes32 value) {
756
+ uint abs = consume(cur, Keys.Query, 32, 32);
757
+ value = bytes32(msg.data[abs:abs + 32]);
758
+ }
759
+
760
+ /// @notice Consume a RESPONSE block with a single bytes32 payload.
761
+ /// @param cur Cursor; advanced past the block.
762
+ /// @return value Decoded bytes32.
763
+ function unpackResponse32(Cur memory cur) internal pure returns (bytes32 value) {
764
+ uint abs = consume(cur, Keys.Response, 32, 32);
765
+ value = bytes32(msg.data[abs:abs + 32]);
766
+ }
767
+
652
768
  /// @notice Consume a ROUTE block with two bytes32 payload words.
653
769
  /// @param cur Cursor; advanced past the block.
654
770
  /// @return a First decoded bytes32.
@@ -659,6 +775,26 @@ library Cursors {
659
775
  b = bytes32(msg.data[abs + 32:abs + 64]);
660
776
  }
661
777
 
778
+ /// @notice Consume a QUERY block with two bytes32 payload words.
779
+ /// @param cur Cursor; advanced past the block.
780
+ /// @return a First decoded bytes32.
781
+ /// @return b Second decoded bytes32.
782
+ function unpackQuery64(Cur memory cur) internal pure returns (bytes32 a, bytes32 b) {
783
+ uint abs = consume(cur, Keys.Query, 64, 64);
784
+ a = bytes32(msg.data[abs:abs + 32]);
785
+ b = bytes32(msg.data[abs + 32:abs + 64]);
786
+ }
787
+
788
+ /// @notice Consume a RESPONSE block with two bytes32 payload words.
789
+ /// @param cur Cursor; advanced past the block.
790
+ /// @return a First decoded bytes32.
791
+ /// @return b Second decoded bytes32.
792
+ function unpackResponse64(Cur memory cur) internal pure returns (bytes32 a, bytes32 b) {
793
+ uint abs = consume(cur, Keys.Response, 64, 64);
794
+ a = bytes32(msg.data[abs:abs + 32]);
795
+ b = bytes32(msg.data[abs + 32:abs + 64]);
796
+ }
797
+
662
798
  /// @notice Consume a ROUTE block with three bytes32 payload words.
663
799
  /// @param cur Cursor; advanced past the block.
664
800
  /// @return a First decoded bytes32.
@@ -671,6 +807,30 @@ library Cursors {
671
807
  c = bytes32(msg.data[abs + 64:abs + 96]);
672
808
  }
673
809
 
810
+ /// @notice Consume a QUERY block with three bytes32 payload words.
811
+ /// @param cur Cursor; advanced past the block.
812
+ /// @return a First decoded bytes32.
813
+ /// @return b Second decoded bytes32.
814
+ /// @return c Third decoded bytes32.
815
+ function unpackQuery96(Cur memory cur) internal pure returns (bytes32 a, bytes32 b, bytes32 c) {
816
+ uint abs = consume(cur, Keys.Query, 96, 96);
817
+ a = bytes32(msg.data[abs:abs + 32]);
818
+ b = bytes32(msg.data[abs + 32:abs + 64]);
819
+ c = bytes32(msg.data[abs + 64:abs + 96]);
820
+ }
821
+
822
+ /// @notice Consume a RESPONSE block with three bytes32 payload words.
823
+ /// @param cur Cursor; advanced past the block.
824
+ /// @return a First decoded bytes32.
825
+ /// @return b Second decoded bytes32.
826
+ /// @return c Third decoded bytes32.
827
+ function unpackResponse96(Cur memory cur) internal pure returns (bytes32 a, bytes32 b, bytes32 c) {
828
+ uint abs = consume(cur, Keys.Response, 96, 96);
829
+ a = bytes32(msg.data[abs:abs + 32]);
830
+ b = bytes32(msg.data[abs + 32:abs + 64]);
831
+ c = bytes32(msg.data[abs + 64:abs + 96]);
832
+ }
833
+
674
834
  /// @notice Consume a CUSTODY block and return its fields as a struct.
675
835
  /// @param cur Cursor; advanced past the block.
676
836
  /// @return value Decoded host, asset, meta, and amount.
package/blocks/Keys.sol CHANGED
@@ -30,6 +30,10 @@ library Keys {
30
30
  bytes4 constant Bundle = bytes4(keccak256("bundle(bytes data)"));
31
31
  /// @dev Extensible routing field — (bytes data); layout is command-defined
32
32
  bytes4 constant Route = bytes4(keccak256("route(bytes data)"));
33
+ /// @dev Extensible query field - (bytes data); layout is query-defined, key is always `Keys.Query`
34
+ bytes4 constant Query = bytes4(keccak256("query(bytes data)"));
35
+ /// @dev Extensible response field - (bytes data); layout is response-defined, key is always `Keys.Response`
36
+ bytes4 constant Response = bytes4(keccak256("response(bytes data)"));
33
37
  /// @dev Opaque path payload — (bytes data); e.g. a Uniswap path encoding
34
38
  bytes4 constant Path = bytes4(keccak256("path(bytes data)"));
35
39
  /// @dev Plain scalar amount — (uint amount)
@@ -37,7 +41,6 @@ library Keys {
37
41
  /// @dev Ratio or rate value — (uint value)
38
42
  bytes4 constant Rate = bytes4(keccak256("rate(uint value)"));
39
43
  /// @dev Counter-party account — (bytes32 account)
40
- bytes4 constant Party = bytes4(keccak256("party(bytes32 account)"));
41
44
  /// @dev Destination account — (bytes32 account)
42
45
  bytes4 constant Recipient = bytes4(keccak256("recipient(bytes32 account)"));
43
46
  /// @dev Transfer record passed through the pipeline — (bytes32 from, bytes32 to, bytes32 asset, bytes32 meta, uint amount)
package/blocks/Schema.sol CHANGED
@@ -19,11 +19,12 @@ library Schemas {
19
19
  string constant Fee = "fee(uint amount)";
20
20
  string constant Break = "break()";
21
21
  string constant Route = "route(bytes data)";
22
+ string constant Query = "query(bytes data)";
23
+ string constant Response = "response(bytes data)";
22
24
  string constant Path = "path(bytes data)";
23
25
  string constant RouteEmpty = "route()";
24
26
  string constant Quantity = "quantity(uint amount)";
25
27
  string constant Rate = "rate(uint value)";
26
- string constant Party = "party(bytes32 account)";
27
28
  string constant Recipient = "recipient(bytes32 account)";
28
29
  string constant Transaction = "tx(bytes32 from, bytes32 to, bytes32 asset, bytes32 meta, uint amount)";
29
30
  string constant Step = "step(uint target, uint value, bytes request)";
@@ -72,7 +73,11 @@ library Schemas {
72
73
  // - `->` separates request and response shapes, appears at most once, and is omitted when no output is modeled
73
74
  // - top-level blocks of the same type should be grouped together
74
75
  // - primary / driving blocks should appear before auxiliary blocks
75
- // - `route(<fields...>)` is a reserved extensible schema form whose key is always `Keys.Route`
76
+ // - `route(<fields...>)`, `query(<fields...>)`, and `response(<fields...>)` are reserved
77
+ // extensible schema forms whose keys are always `Keys.Route`, `Keys.Query`, and
78
+ // `Keys.Response` respectively
79
+ // - these extensible forms work like dynamic `bytes` blocks: they may carry arbitrary
80
+ // payload bytes while keeping one fixed key per semantic block type
76
81
  // - `&` compiles to a `Keys.Bundle` block whose self payload is the bundled member block stream
77
82
  // - canonical blocks are `amount(...)` for request amounts, `balance(...)` for state balances,
78
83
  // `minimum(...)` for result floors, `maximum(...)` for spend ceilings, and `quantity(...)`
@@ -90,26 +95,42 @@ library Schemas {
90
95
  /// @title Sizes
91
96
  /// @notice Total byte sizes for fixed-width block types, including the 8-byte header (4-byte key + 4-byte payloadLen).
92
97
  library Sizes {
98
+ /// @dev Shared block header size: 4-byte key + 4-byte payload length.
99
+ uint constant Header = 8;
100
+ /// @dev One fixed-width payload word.
101
+ uint constant Word = 32;
102
+ /// @dev 8 header + 32 payload = 40 bytes total.
103
+ uint constant B32 = Header + Word;
104
+ /// @dev 8 header + 64 payload = 72 bytes total.
105
+ uint constant B64 = Header + 2 * Word;
106
+ /// @dev 8 header + 96 payload = 104 bytes total.
107
+ uint constant B96 = Header + 3 * Word;
108
+ /// @dev 8 header + 128 payload = 136 bytes total.
109
+ uint constant B128 = Header + 4 * Word;
110
+ /// @dev 8 header + 160 payload = 168 bytes total.
111
+ uint constant B160 = Header + 5 * Word;
93
112
  /// @dev AUTH proof segment only: 20-byte signer + 65-byte signature = 85 bytes
94
113
  uint constant Proof = 85;
95
114
  /// @dev AUTH block: 8 header + 32 cid + 32 deadline + 85 proof = 157 bytes
96
- uint constant Auth = 157;
115
+ uint constant Auth = B64 + Proof;
116
+ /// @dev AMOUNT block: 8 header + 32 asset + 32 meta + 32 amount = 104 bytes
117
+ uint constant Amount = B96;
97
118
  /// @dev BALANCE block: 8 header + 32 asset + 32 meta + 32 amount = 104 bytes
98
- uint constant Balance = 104;
119
+ uint constant Balance = B96;
99
120
  /// @dev MINIMUMS block: 8 header + 32 a + 32 b = 72 bytes
100
- uint constant Minimums = 72;
121
+ uint constant Minimums = B64;
101
122
  /// @dev MAXIMUMS block: 8 header + 32 a + 32 b = 72 bytes
102
- uint constant Maximums = 72;
123
+ uint constant Maximums = B64;
103
124
  /// @dev BOUNDS block: 8 header + 32 min + 32 max = 72 bytes
104
- uint constant Bounds = 72;
125
+ uint constant Bounds = B64;
105
126
  /// @dev FEE block: 8 header + 32 amount = 40 bytes
106
- uint constant Fee = 40;
127
+ uint constant Fee = B32;
107
128
  /// @dev BOUNTY block: 8 header + 32 amount + 32 relayer = 72 bytes
108
- uint constant Bounty = 72;
129
+ uint constant Bounty = B64;
109
130
  /// @dev CUSTODY block: 8 header + 32 host + 32 asset + 32 meta + 32 amount = 136 bytes
110
- uint constant Custody = 136;
131
+ uint constant Custody = B128;
111
132
  /// @dev TRANSACTION block: 8 header + 32 from + 32 to + 32 asset + 32 meta + 32 amount = 168 bytes
112
- uint constant Transaction = 168;
133
+ uint constant Transaction = B160;
113
134
  }
114
135
 
115
136
  /// @notice Asset and amount pair; used for balance and amount blocks.