@rootzero/contracts 0.7.2 → 0.9.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 (71) hide show
  1. package/Commands.sol +15 -20
  2. package/Core.sol +3 -4
  3. package/Cursors.sol +3 -2
  4. package/Events.sol +1 -1
  5. package/Queries.sol +3 -3
  6. package/README.md +18 -19
  7. package/Utils.sol +3 -3
  8. package/blocks/Cursors.sol +937 -551
  9. package/blocks/Keys.sol +60 -34
  10. package/blocks/Schema.sol +112 -122
  11. package/blocks/Writers.sol +476 -301
  12. package/commands/Base.sol +32 -22
  13. package/commands/Burn.sol +14 -12
  14. package/commands/Credit.sol +16 -15
  15. package/commands/Debit.sol +14 -12
  16. package/commands/Deposit.sol +30 -37
  17. package/commands/Pipe.sol +14 -20
  18. package/commands/Provision.sol +19 -49
  19. package/commands/Transfer.sol +9 -18
  20. package/commands/Withdraw.sol +15 -14
  21. package/commands/admin/AllowAssets.sol +3 -3
  22. package/commands/admin/Allowance.sol +43 -0
  23. package/commands/admin/Authorize.sol +4 -4
  24. package/commands/admin/DenyAssets.sol +3 -3
  25. package/commands/admin/Destroy.sol +10 -8
  26. package/commands/admin/Execute.sol +38 -0
  27. package/commands/admin/Init.sol +10 -8
  28. package/commands/admin/Relocate.sol +5 -5
  29. package/commands/admin/Unauthorize.sol +4 -4
  30. package/core/Access.sol +38 -34
  31. package/core/Balances.sol +17 -18
  32. package/core/{Operation.sol → Calls.sol} +5 -8
  33. package/core/{CursorBase.sol → Context.sol} +11 -5
  34. package/core/Host.sol +11 -10
  35. package/core/Types.sol +86 -0
  36. package/docs/GETTING_STARTED.md +37 -29
  37. package/events/Asset.sol +1 -1
  38. package/events/Command.sol +10 -10
  39. package/events/Deposit.sol +3 -4
  40. package/events/Listing.sol +1 -1
  41. package/events/Peer.sol +3 -3
  42. package/events/Position.sol +21 -0
  43. package/events/Query.sol +3 -3
  44. package/events/Withdraw.sol +2 -3
  45. package/package.json +1 -1
  46. package/peer/AllowAssets.sol +1 -1
  47. package/peer/Allowance.sol +36 -0
  48. package/peer/AssetPull.sol +33 -31
  49. package/peer/Base.sol +8 -4
  50. package/peer/DenyAssets.sol +1 -1
  51. package/peer/Settle.sol +3 -4
  52. package/queries/Assets.sol +18 -16
  53. package/queries/Balances.sol +21 -19
  54. package/queries/Base.sol +2 -3
  55. package/queries/Positions.sol +32 -24
  56. package/utils/Accounts.sol +14 -13
  57. package/utils/Assets.sol +137 -62
  58. package/utils/Ids.sol +9 -9
  59. package/utils/Layout.sol +5 -3
  60. package/utils/Utils.sol +10 -0
  61. package/commands/Create.sol +0 -42
  62. package/commands/Remove.sol +0 -42
  63. package/commands/Settle.sol +0 -38
  64. package/commands/Stake.sol +0 -47
  65. package/commands/Supply.sol +0 -41
  66. package/commands/admin/Allocate.sol +0 -41
  67. package/core/HostBound.sol +0 -14
  68. package/events/Erc721.sol +0 -20
  69. package/peer/Pull.sol +0 -39
  70. package/peer/Push.sol +0 -45
  71. package/utils/State.sol +0 -22
@@ -1,42 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import { CommandBase, CommandContext, State } from "./Base.sol";
5
- import { Cursors, Cur } from "../Cursors.sol";
6
-
7
- string constant NAME = "create";
8
-
9
- using Cursors for Cur;
10
-
11
- /// @title Create
12
- /// @notice Generic command that creates or initializes objects via a virtual hook.
13
- /// The request schema is constructor-defined; `create` is called once per top-level group.
14
- /// Produces no output state.
15
- abstract contract Create is CommandBase {
16
- uint internal immutable createId = commandId(NAME);
17
-
18
- constructor(string memory input) {
19
- emit Command(host, NAME, input, createId, State.Empty, State.Empty, false);
20
- }
21
-
22
- /// @dev Override to create or initialize an object described by `input`.
23
- /// Called once per top-level request item.
24
- function create(bytes32 account, Cur memory input) internal virtual;
25
-
26
- function create(CommandContext calldata c) external onlyCommand(createId, c.target) returns (bytes memory) {
27
- (Cur memory request, , ) = cursor(c.request, 1);
28
-
29
- while (request.i < request.bound) {
30
- create(c.account, request);
31
- }
32
-
33
- request.complete();
34
- return "";
35
- }
36
- }
37
-
38
-
39
-
40
-
41
-
42
-
@@ -1,42 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import { CommandBase, CommandContext, State } from "./Base.sol";
5
- import { Cursors, Cur } from "../Cursors.sol";
6
-
7
- string constant NAME = "remove";
8
-
9
- using Cursors for Cur;
10
-
11
- /// @title Remove
12
- /// @notice Generic command that removes or dismantles objects via a virtual hook.
13
- /// The request schema is constructor-defined; `remove` is called once per top-level group.
14
- /// Produces no output state.
15
- abstract contract Remove is CommandBase {
16
- uint internal immutable removeId = commandId(NAME);
17
-
18
- constructor(string memory input) {
19
- emit Command(host, NAME, input, removeId, State.Empty, State.Empty, false);
20
- }
21
-
22
- /// @dev Override to remove or dismantle an object described by `input`.
23
- /// Called once per top-level request item.
24
- function remove(bytes32 account, Cur memory input) internal virtual;
25
-
26
- function remove(CommandContext calldata c) external onlyCommand(removeId, c.target) returns (bytes memory) {
27
- (Cur memory request, , ) = cursor(c.request, 1);
28
-
29
- while (request.i < request.bound) {
30
- remove(c.account, request);
31
- }
32
-
33
- request.complete();
34
- return "";
35
- }
36
- }
37
-
38
-
39
-
40
-
41
-
42
-
@@ -1,38 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import { CommandContext, CommandBase, State } from "./Base.sol";
5
- import { Cursors, Cur, Tx } from "../Cursors.sol";
6
- import { TransferHook } from "./Transfer.sol";
7
- using Cursors for Cur;
8
-
9
- string constant NAME = "settle";
10
-
11
- /// @title Settle
12
- /// @notice Command that consumes each TRANSACTION state block and settles it through the shared transfer hook.
13
- /// Produces no output state.
14
- abstract contract Settle is CommandBase, TransferHook {
15
- uint internal immutable settleId = commandId(NAME);
16
-
17
- constructor() {
18
- emit Command(host, NAME, "", settleId, State.Transactions, State.Empty, false);
19
- }
20
-
21
- function settle(CommandContext calldata c) external onlyCommand(settleId, c.target) returns (bytes memory) {
22
- (Cur memory state, , ) = cursor(c.state, 1);
23
-
24
- while (state.i < state.bound) {
25
- Tx memory value = state.unpackTxValue();
26
- transfer(value);
27
- }
28
-
29
- state.complete();
30
- return "";
31
- }
32
- }
33
-
34
-
35
-
36
-
37
-
38
-
@@ -1,47 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import { CommandContext, CommandBase, State } from "./Base.sol";
5
- import { HostAmount, Cur, Cursors } from "../Cursors.sol";
6
-
7
- string constant SCTP = "stakeCustodyToPosition";
8
-
9
- using Cursors for Cur;
10
-
11
- /// @title StakeCustodyToPosition
12
- /// @notice Command that stakes CUSTODY state positions into a non-balance target
13
- /// described by the request stream. Produces no output state.
14
- abstract contract StakeCustodyToPosition is CommandBase {
15
- uint internal immutable stakeCustodyToPositionId = commandId(SCTP);
16
-
17
- constructor(string memory input) {
18
- emit Command(host, SCTP, input, stakeCustodyToPositionId, State.Custodies, State.Empty, false);
19
- }
20
-
21
- /// @dev Override to stake a custody position into a non-balance setup
22
- /// target described by `request`.
23
- function stakeCustodyToPosition(bytes32 account, HostAmount memory custody, Cur memory request) internal virtual;
24
-
25
- function stakeCustodyToPosition(
26
- CommandContext calldata c
27
- ) external onlyCommand(stakeCustodyToPositionId, c.target) returns (bytes memory) {
28
- (Cur memory state, , ) = cursor(c.state, 1);
29
- Cur memory request = cursor(c.request);
30
-
31
- while (state.i < state.bound) {
32
- HostAmount memory custody = state.unpackCustodyValue();
33
- stakeCustodyToPosition(c.account, custody, request);
34
- }
35
-
36
- state.complete();
37
- return "";
38
- }
39
- }
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
@@ -1,41 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import {CommandBase, CommandContext, State} from "./Base.sol";
5
- import {Cursors, Cur, HostAmount} from "../Cursors.sol";
6
- string constant NAME = "supply";
7
-
8
- using Cursors for Cur;
9
-
10
- /// @title Supply
11
- /// @notice Command that processes each CUSTODY state block through a virtual hook.
12
- /// Used to move assets out of cross-host custody positions (e.g. to settle or redeem them).
13
- /// Produces no output state.
14
- abstract contract Supply is CommandBase {
15
- uint internal immutable supplyId = commandId(NAME);
16
-
17
- constructor() {
18
- emit Command(host, NAME, "", supplyId, State.Custodies, State.Empty, false);
19
- }
20
-
21
- /// @notice Override to consume or supply a single custody position.
22
- /// Called once per CUSTODY block in state.
23
- /// @param account Caller's account identifier.
24
- /// @param value Decoded custody position (host, asset, meta, amount).
25
- function supply(bytes32 account, HostAmount memory value) internal virtual;
26
-
27
- /// @notice Execute the supply command.
28
- function supply(CommandContext calldata c) external onlyCommand(supplyId, c.target) returns (bytes memory) {
29
- (Cur memory state, , ) = cursor(c.state, 1);
30
-
31
- while (state.i < state.bound) {
32
- HostAmount memory value = state.unpackCustodyValue();
33
- supply(c.account, value);
34
- }
35
-
36
- state.complete();
37
- return "";
38
- }
39
- }
40
-
41
-
@@ -1,41 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import { CommandBase, CommandContext, State } from "../Base.sol";
5
- import { Cursors, Cur, Schemas } from "../../Cursors.sol";
6
- using Cursors for Cur;
7
-
8
- string constant NAME = "allocate";
9
-
10
- /// @title Allocate
11
- /// @notice Admin command that applies cross-host allocation entries via a virtual hook.
12
- /// Each ALLOCATION block in the request calls `allocate`. Only callable by the admin account.
13
- abstract contract Allocate is CommandBase {
14
- uint internal immutable allocateId = commandId(NAME);
15
-
16
- constructor() {
17
- emit Command(host, NAME, Schemas.Allocation, allocateId, State.Empty, State.Empty, false);
18
- }
19
-
20
- /// @dev Override to apply a single allocation entry.
21
- /// Called once per ALLOCATION block in the request.
22
- function allocate(uint host, bytes32 asset, bytes32 meta, uint amount) internal virtual;
23
-
24
- function allocate(CommandContext calldata c) external onlyAdmin(c.account) onlyCommand(allocateId, c.target) returns (bytes memory) {
25
- (Cur memory request, , ) = cursor(c.request, 1);
26
-
27
- while (request.i < request.bound) {
28
- (uint host, bytes32 asset, bytes32 meta, uint amount) = request.unpackAllocation();
29
- allocate(host, asset, meta, amount);
30
- }
31
-
32
- request.complete();
33
- return "";
34
- }
35
- }
36
-
37
-
38
-
39
-
40
-
41
-
@@ -1,14 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import {Assets} from "../utils/Assets.sol";
5
- import {Ids} from "../utils/Ids.sol";
6
-
7
- /// @title HostBound
8
- /// @notice Minimal base for contracts that need host-scoped identity constants.
9
- abstract contract HostBound {
10
- /// @dev This contract's host node ID, set to `Ids.toHost(address(this))` at construction.
11
- uint public immutable host = Ids.toHost(address(this));
12
- /// @dev Asset ID for the native chain value (ETH), bound to the current chain at deployment.
13
- bytes32 internal immutable valueAsset = Assets.toValue();
14
- }
package/events/Erc721.sol DELETED
@@ -1,20 +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
- string constant ABI = "event Erc721Position(bytes32 indexed account, bytes32 asset, bytes32 meta, uint position, uint qid)";
7
-
8
- /// @notice Emitted when the lifecycle state of an ERC-721-backed position changes.
9
- abstract contract Erc721PositionEvent is EventEmitter {
10
- /// @param account Account identifier that owns or is associated with the position.
11
- /// @param asset Asset identifier for the ERC-721 class.
12
- /// @param meta Asset metadata slot, typically carrying the token-specific position context.
13
- /// @param position Context-specific position value; positive means active and 0 means closed.
14
- /// @param qid Query ID associated with the position lookup or reporting context.
15
- event Erc721Position(bytes32 indexed account, bytes32 asset, bytes32 meta, uint position, uint qid);
16
-
17
- constructor() {
18
- emit EventAbi(ABI);
19
- }
20
- }
package/peer/Pull.sol DELETED
@@ -1,39 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import {PeerBase} from "./Base.sol";
5
- import {Cursors, Cur} from "../Cursors.sol";
6
-
7
- string constant NAME = "peerPull";
8
-
9
- using Cursors for Cur;
10
-
11
- /// @title PeerPull
12
- /// @notice Peer that pulls assets from a remote host into this one.
13
- /// Each block in the request is dispatched to `peerPull(peer, input)`, where `peer`
14
- /// is derived from `msg.sender`. Restricted to trusted peers.
15
- abstract contract PeerPull is PeerBase {
16
- uint internal immutable peerPullId = peerId(NAME);
17
-
18
- constructor(string memory input) {
19
- emit Peer(host, NAME, input, peerPullId, false);
20
- }
21
-
22
- /// @notice Override to process a single incoming block from the pull request.
23
- /// @param peer Host node ID derived from the caller address.
24
- /// @param input Cursor positioned at the current input block; advance it before returning.
25
- function peerPull(uint peer, Cur memory input) internal virtual;
26
-
27
- /// @notice Execute the pull peer call.
28
- function peerPull(bytes calldata request) external onlyPeer returns (bytes memory) {
29
- (Cur memory input, , ) = cursor(request, 1);
30
- uint peer = caller();
31
-
32
- while (input.i < input.bound) {
33
- peerPull(peer, input);
34
- }
35
-
36
- input.complete();
37
- return "";
38
- }
39
- }
package/peer/Push.sol DELETED
@@ -1,45 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- import { PeerBase } from "./Base.sol";
5
- import { Cursors, Cur } from "../Cursors.sol";
6
-
7
- string constant NAME = "peerPush";
8
-
9
- using Cursors for Cur;
10
-
11
- /// @title PeerPush
12
- /// @notice Peer that receives assets pushed from a remote host into this one.
13
- /// Each block in the request is dispatched to `peerPush(peer, input)`, where `peer`
14
- /// is derived from `msg.sender`. Restricted to trusted peers.
15
- abstract contract PeerPush is PeerBase {
16
- uint internal immutable peerPushId = peerId(NAME);
17
-
18
- constructor(string memory input) {
19
- emit Peer(host, NAME, input, peerPushId, false);
20
- }
21
-
22
- /// @notice Override to process a single incoming block from the push request.
23
- /// @param peer Host node ID derived from the caller address.
24
- /// @param input Cursor positioned at the current input block; advance it before returning.
25
- function peerPush(uint peer, Cur memory input) internal virtual;
26
-
27
- /// @notice Execute the push peer call.
28
- function peerPush(bytes calldata request) external onlyPeer returns (bytes memory) {
29
- (Cur memory input, , ) = cursor(request, 1);
30
- uint peer = caller();
31
-
32
- while (input.i < input.bound) {
33
- peerPush(peer, input);
34
- }
35
-
36
- input.complete();
37
- return "";
38
- }
39
- }
40
-
41
-
42
-
43
-
44
-
45
-
package/utils/State.sol DELETED
@@ -1,22 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- /// @title State
5
- /// @notice Command state type discriminants.
6
- /// Each constant tags the shape of the encoded state block stream stored
7
- /// in a command's metadata slot, allowing commands to select the correct
8
- /// decode path without inspecting the raw bytes.
9
- library State {
10
- /// @dev No state; the command produces or expects an empty state stream.
11
- uint8 constant Empty = 0x0001;
12
- /// @dev State stream contains STEP blocks (sub-command invocations).
13
- uint8 constant Steps = 0x0002;
14
- /// @dev State stream contains BALANCE blocks.
15
- uint8 constant Balances = 0x0003;
16
- /// @dev State stream contains TRANSACTION blocks.
17
- uint8 constant Transactions = 0x0004;
18
- /// @dev State stream contains CUSTODY blocks.
19
- uint8 constant Custodies = 0x0005;
20
- /// @dev State stream contains claim records.
21
- uint8 constant Claims = 0x0006;
22
- }