@rootzero/contracts 1.2.0 → 1.4.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 (49) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/Endpoints.sol +9 -7
  3. package/Events.sol +2 -2
  4. package/README.md +300 -79
  5. package/blocks/Cursors.sol +10 -14
  6. package/blocks/Schema.sol +7 -4
  7. package/commands/Burn.sol +2 -2
  8. package/commands/Credit.sol +2 -2
  9. package/commands/Debit.sol +2 -2
  10. package/commands/Deposit.sol +4 -4
  11. package/commands/Payout.sol +3 -3
  12. package/commands/Provision.sol +4 -4
  13. package/commands/Relay.sol +2 -2
  14. package/commands/Withdraw.sol +2 -2
  15. package/commands/admin/AllowAssets.sol +2 -2
  16. package/commands/admin/Allowance.sol +2 -2
  17. package/commands/admin/Appoint.sol +2 -2
  18. package/commands/admin/Authorize.sol +2 -2
  19. package/commands/admin/DenyAssets.sol +2 -2
  20. package/commands/admin/Destroy.sol +1 -1
  21. package/commands/admin/Dismiss.sol +2 -2
  22. package/commands/admin/Execute.sol +2 -2
  23. package/commands/admin/Init.sol +1 -1
  24. package/commands/admin/Label.sol +2 -2
  25. package/commands/admin/Unauthorize.sol +2 -2
  26. package/core/Pipeline.sol +1 -1
  27. package/docs/Schema.md +59 -2
  28. package/events/Admin.sol +2 -6
  29. package/events/Command.sol +2 -6
  30. package/events/Commander.sol +19 -0
  31. package/events/Labeled.sol +7 -4
  32. package/events/Route.sol +18 -0
  33. package/guards/Revoke.sol +1 -1
  34. package/package.json +1 -1
  35. package/peer/AllowAssets.sol +6 -2
  36. package/peer/Allowance.sol +6 -2
  37. package/peer/BalancePull.sol +6 -2
  38. package/peer/Credit.sol +39 -0
  39. package/peer/Debit.sol +39 -0
  40. package/peer/DenyAssets.sol +6 -2
  41. package/peer/Dispatch.sol +6 -2
  42. package/peer/Pipe.sol +6 -2
  43. package/peer/Settle.sol +6 -2
  44. package/queries/Assets.sol +1 -1
  45. package/queries/Balances.sol +1 -1
  46. package/queries/Positions.sol +1 -1
  47. package/utils/Actions.sol +1 -0
  48. package/events/Chain.sol +0 -19
  49. package/events/Transfer.sol +0 -22
@@ -0,0 +1,39 @@
1
+ // SPDX-License-Identifier: GPL-3.0-only
2
+ pragma solidity ^0.8.33;
3
+
4
+ import { PeerBase } from "./Base.sol";
5
+ import { CreditAccountHook } from "../commands/Credit.sol";
6
+ import { Cursors, Cur, Forms } from "../Cursors.sol";
7
+
8
+ using Cursors for Cur;
9
+
10
+ interface IPeerCreditTo {
11
+ function peerCreditTo(bytes calldata request) external returns (bytes memory);
12
+ }
13
+
14
+ /// @title PeerCreditTo
15
+ /// @notice Peer that lets a trusted peer credit supplied accounts directly.
16
+ /// Each ACCOUNT_AMOUNT block calls `creditAccount` for its account.
17
+ abstract contract PeerCreditTo is PeerBase, CreditAccountHook, IPeerCreditTo {
18
+ uint internal immutable peerCreditToId = peerId(this.peerCreditTo.selector);
19
+
20
+ constructor() {
21
+ emit Peer(host, peerCreditToId, "1:0", Forms.AccountAmount, "", false);
22
+ emit Labeled(peerCreditToId, bytes32(0), "peerCreditTo");
23
+ }
24
+
25
+ /// @notice Execute the peer-credit call.
26
+ /// @param request ACCOUNT_AMOUNT block stream supplied by the trusted peer.
27
+ /// @return Empty response bytes.
28
+ function peerCreditTo(bytes calldata request) external onlyPeer returns (bytes memory) {
29
+ (Cur memory amounts, , ) = Cursors.init(request, 1);
30
+
31
+ while (amounts.i < amounts.len) {
32
+ (bytes32 account, bytes32 asset, bytes32 meta, uint amount) = amounts.unpackAccountAmount();
33
+ creditAccount(account, asset, meta, amount);
34
+ }
35
+
36
+ amounts.complete();
37
+ return "";
38
+ }
39
+ }
package/peer/Debit.sol ADDED
@@ -0,0 +1,39 @@
1
+ // SPDX-License-Identifier: GPL-3.0-only
2
+ pragma solidity ^0.8.33;
3
+
4
+ import { PeerBase } from "./Base.sol";
5
+ import { DebitAccountHook } from "../commands/Debit.sol";
6
+ import { Cursors, Cur, Forms } from "../Cursors.sol";
7
+
8
+ using Cursors for Cur;
9
+
10
+ interface IPeerDebitFrom {
11
+ function peerDebitFrom(bytes calldata request) external returns (bytes memory);
12
+ }
13
+
14
+ /// @title PeerDebitFrom
15
+ /// @notice Peer that lets a trusted peer debit supplied accounts directly.
16
+ /// Each ACCOUNT_AMOUNT block calls `debitAccount` for its account.
17
+ abstract contract PeerDebitFrom is PeerBase, DebitAccountHook, IPeerDebitFrom {
18
+ uint internal immutable peerDebitFromId = peerId(this.peerDebitFrom.selector);
19
+
20
+ constructor() {
21
+ emit Peer(host, peerDebitFromId, "1:0", Forms.AccountAmount, "", false);
22
+ emit Labeled(peerDebitFromId, bytes32(0), "peerDebitFrom");
23
+ }
24
+
25
+ /// @notice Execute the peer-debit call.
26
+ /// @param request ACCOUNT_AMOUNT block stream supplied by the trusted peer.
27
+ /// @return Empty response bytes.
28
+ function peerDebitFrom(bytes calldata request) external onlyPeer returns (bytes memory) {
29
+ (Cur memory amounts, , ) = Cursors.init(request, 1);
30
+
31
+ while (amounts.i < amounts.len) {
32
+ (bytes32 account, bytes32 asset, bytes32 meta, uint amount) = amounts.unpackAccountAmount();
33
+ debitAccount(account, asset, meta, amount);
34
+ }
35
+
36
+ amounts.complete();
37
+ return "";
38
+ }
39
+ }
@@ -7,10 +7,14 @@ import {Cursors, Cur, Schemas} from "../Cursors.sol";
7
7
 
8
8
  using Cursors for Cur;
9
9
 
10
+ interface IPeerDenyAssets {
11
+ function peerDenyAssets(bytes calldata request) external returns (bytes memory);
12
+ }
13
+
10
14
  /// @title PeerDenyAssets
11
15
  /// @notice Peer that blocks a list of (asset, meta) pairs on behalf of a peer host.
12
16
  /// Each ASSET block in the request calls `denyAsset`. Restricted to trusted peers.
13
- abstract contract PeerDenyAssets is PeerBase, DenyAssetsHook {
17
+ abstract contract PeerDenyAssets is PeerBase, DenyAssetsHook, IPeerDenyAssets {
14
18
  uint internal immutable peerDenyAssetsId = peerId(this.peerDenyAssets.selector);
15
19
 
16
20
  constructor() {
@@ -22,7 +26,7 @@ abstract contract PeerDenyAssets is PeerBase, DenyAssetsHook {
22
26
  /// @param request ASSET block stream supplied by the trusted peer.
23
27
  /// @return Empty response bytes.
24
28
  function peerDenyAssets(bytes calldata request) external onlyPeer returns (bytes memory) {
25
- (Cur memory assets, , ) = Cursors.init(request, 0, 1);
29
+ (Cur memory assets, , ) = Cursors.init(request, 1);
26
30
 
27
31
  while (assets.i < assets.len) {
28
32
  (bytes32 asset, bytes32 meta) = assets.unpackAsset();
package/peer/Dispatch.sol CHANGED
@@ -9,9 +9,13 @@ import { Budget } from "../utils/Value.sol";
9
9
 
10
10
  using Cursors for Cur;
11
11
 
12
+ interface IPeerDispatchPayable {
13
+ function peerDispatchPayable(bytes calldata request) external payable returns (bytes memory);
14
+ }
15
+
12
16
  /// @title PeerDispatchPayable
13
17
  /// @notice Peer endpoint that forwards DISPATCH blocks to a host-defined dispatch hook.
14
- abstract contract PeerDispatchPayable is PeerBase, Payable, DispatchPayableHook {
18
+ abstract contract PeerDispatchPayable is PeerBase, Payable, DispatchPayableHook, IPeerDispatchPayable {
15
19
  uint internal immutable peerDispatchPayableId = peerId(this.peerDispatchPayable.selector);
16
20
 
17
21
  constructor() {
@@ -25,7 +29,7 @@ abstract contract PeerDispatchPayable is PeerBase, Payable, DispatchPayableHook
25
29
  /// @param request DISPATCH block stream supplied by the trusted peer.
26
30
  /// @return output Empty response bytes.
27
31
  function peerDispatchPayable(bytes calldata request) external payable onlyPeer returns (bytes memory output) {
28
- (Cur memory input, , ) = Cursors.init(request, 0, 1);
32
+ (Cur memory input, , ) = Cursors.init(request, 1);
29
33
  Budget memory budget = valueBudget();
30
34
 
31
35
  while (input.i < input.len) {
package/peer/Pipe.sol CHANGED
@@ -8,11 +8,15 @@ import {Budget} from "../utils/Value.sol";
8
8
 
9
9
  using Cursors for Cur;
10
10
 
11
+ interface IPeerPipePayable {
12
+ function peerPipePayable(bytes calldata request) external payable returns (bytes memory);
13
+ }
14
+
11
15
  /// @title PeerPipePayable
12
16
  /// @notice Peer that consumes PIPE blocks and executes each context step stream.
13
17
  /// Each PIPE block carries chain resources plus a CONTEXT block; the nested
14
18
  /// context steps are passed to the shared pipeline as the step stream.
15
- abstract contract PeerPipePayable is PeerBase, Pipeline {
19
+ abstract contract PeerPipePayable is PeerBase, Pipeline, IPeerPipePayable {
16
20
  uint internal immutable peerPipePayableId = peerId(this.peerPipePayable.selector);
17
21
 
18
22
  constructor() {
@@ -26,7 +30,7 @@ abstract contract PeerPipePayable is PeerBase, Pipeline {
26
30
  /// @param request PIPE block stream supplied by the trusted peer.
27
31
  /// @return Empty response bytes.
28
32
  function peerPipePayable(bytes calldata request) external payable onlyPeer returns (bytes memory) {
29
- (Cur memory input, , ) = Cursors.init(request, 0, 1);
33
+ (Cur memory input, , ) = Cursors.init(request, 1);
30
34
  Budget memory budget = valueBudget();
31
35
 
32
36
  while (input.i < input.len) {
package/peer/Settle.sol CHANGED
@@ -8,10 +8,14 @@ import { Cursors, Cur, Schemas } from "../Cursors.sol";
8
8
 
9
9
  using Cursors for Cur;
10
10
 
11
+ interface IPeerSettle {
12
+ function peerSettle(bytes calldata request) external returns (bytes memory);
13
+ }
14
+
11
15
  /// @title PeerSettle
12
16
  /// @notice Peer that consumes peer-supplied TRANSACTION blocks through debit and credit hooks.
13
17
  /// Each TRANSACTION block calls `debitAccount` for `from` and `creditAccount` for `to`.
14
- abstract contract PeerSettle is PeerBase, DebitAccountHook, CreditAccountHook {
18
+ abstract contract PeerSettle is PeerBase, DebitAccountHook, CreditAccountHook, IPeerSettle {
15
19
  uint internal immutable peerSettleId = peerId(this.peerSettle.selector);
16
20
 
17
21
  constructor() {
@@ -23,7 +27,7 @@ abstract contract PeerSettle is PeerBase, DebitAccountHook, CreditAccountHook {
23
27
  /// @param request TRANSACTION block stream supplied by the trusted peer.
24
28
  /// @return Empty response bytes.
25
29
  function peerSettle(bytes calldata request) external onlyPeer returns (bytes memory) {
26
- (Cur memory state, , ) = Cursors.init(request, 0, 1);
30
+ (Cur memory state, , ) = Cursors.init(request, 1);
27
31
 
28
32
  while (state.i < state.len) {
29
33
  (bytes32 from, bytes32 to, bytes32 asset, bytes32 meta, uint amount) = state.unpackTransaction();
@@ -33,7 +33,7 @@ abstract contract AssetStatus is QueryBase, AssetStatusHook {
33
33
  /// @param request Block-stream request consisting of `#asset { bytes32 asset, bytes32 meta }` blocks.
34
34
  /// @return Block-stream response containing one `#status { uint code }` per asset block.
35
35
  function assetStatus(bytes calldata request) external view returns (bytes memory) {
36
- (Cur memory query, uint groups, ) = Cursors.init(request, 0, 1);
36
+ (Cur memory query, uint groups, ) = Cursors.init(request, 1);
37
37
  Writer memory response = Writers.allocStatuses(groups);
38
38
 
39
39
  while (query.i < query.len) {
@@ -33,7 +33,7 @@ abstract contract GetBalances is QueryBase, GetBalancesHook {
33
33
  /// @param request Block-stream request consisting of `accountAsset(account, asset, meta)*`.
34
34
  /// @return Block-stream response containing one `accountAmount(account, asset, meta, amount)` block per request block.
35
35
  function getBalances(bytes calldata request) external view returns (bytes memory) {
36
- (Cur memory query, uint groups, ) = Cursors.init(request, 0, 1);
36
+ (Cur memory query, uint groups, ) = Cursors.init(request, 1);
37
37
  Writer memory response = Writers.allocAccountAmounts(groups);
38
38
 
39
39
  while (query.i < query.len) {
@@ -41,7 +41,7 @@ abstract contract GetPosition is QueryBase, GetPositionHook {
41
41
  /// @param request Block-stream request consisting of `accountAsset(account, asset, meta)*`.
42
42
  /// @return Block-stream response containing one output-schema block per position block.
43
43
  function getPosition(bytes calldata request) external view returns (bytes memory) {
44
- (Cur memory query, uint groups, ) = Cursors.init(request, 0, 1);
44
+ (Cur memory query, uint groups, ) = Cursors.init(request, 1);
45
45
  Writer memory response = Writers.allocAny(groups);
46
46
 
47
47
  while (query.i < query.len) {
package/utils/Actions.sol CHANGED
@@ -15,4 +15,5 @@ library Actions {
15
15
  uint32 constant Borrow = 10;
16
16
  uint32 constant Repay = 11;
17
17
  uint32 constant Liquidate = 12;
18
+ uint32 constant Refund = 13;
18
19
  }
package/events/Chain.sol DELETED
@@ -1,19 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import {EventEmitter} from "./Emitter.sol";
5
-
6
- /// @notice Emitted when a chain/domain node is announced.
7
- abstract contract ChainEvent is EventEmitter {
8
- string private constant ABI = "event Chain(uint indexed chain, bytes32 native, uint commander, bytes32 admin)";
9
-
10
- /// @param chain Chain node ID.
11
- /// @param native Native asset ID for the chain.
12
- /// @param commander Commander host node ID for the chain.
13
- /// @param admin Admin account for the commander host on the chain.
14
- event Chain(uint indexed chain, bytes32 native, uint commander, bytes32 admin);
15
-
16
- constructor() {
17
- emit EventAbi(ABI);
18
- }
19
- }
@@ -1,22 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import { EventEmitter } from "./Emitter.sol";
5
-
6
- /// @notice Emitted when an asset moves from one account to another.
7
- abstract contract TransferEvent is EventEmitter {
8
- string private constant ABI = "event Transfer(bytes32 indexed from, bytes32 to, bytes32 asset, bytes32 meta, uint amount, uint32 action, uint context)";
9
-
10
- /// @param account Source account identifier.
11
- /// @param to Destination account identifier.
12
- /// @param asset Asset identifier.
13
- /// @param meta Asset metadata slot.
14
- /// @param amount Amount transferred.
15
- /// @param action Primary operation hint from `Actions`.
16
- /// @param context Reserved context value for future use.
17
- event Transfer(bytes32 indexed account, bytes32 to, bytes32 asset, bytes32 meta, uint amount, uint32 action, uint context);
18
-
19
- constructor() {
20
- emit EventAbi(ABI);
21
- }
22
- }